Nodes/ComfyUI-Pt-Wrapper/Pt Logical And
ComfyUI Node

Pt Logical And

The AND that makes masks composable

By HowToSD·Created about a year ago·Updated about a year ago· 7
Pt Logical And
  • tens_a
  • tens_b
  • TENSOR

Boolean logic doesn't usually need its own node - until your boolean data lives inside tensors, at which point "just use Python" stops being an option. Pt Logical And is torch.logical_and in a box: two tensors in, one boolean tensor out, True only where both inputs are true. It's the connective tissue that turns single comparisons into compound conditions.

How it works

Both inputs are required TENSORs (tens_a, tens_b), and the node returns torch.logical_and(tens_a, tens_b) - element-wise, broadcasting like all torch ops. If you feed it boolean tensors (the output of a comparison node like Pt Le or Pt Lt), you get exactly the set intersection you'd expect. Feed it numbers instead and it still works: any nonzero value counts as true, zero as false, which can be handy but is easy to forget.

The typical chain

This is where the pack's comparison nodes earn their keep. The pattern:

  • Pt Le (or Pt Lt/Pt Ge) builds a mask: "where is the score under 0.5?"
  • A second comparison builds another mask: "where is this other thing true?"
  • Pt Logical And combines them into: "where is both true?"
  • Pt Masked Select pulls out exactly those elements.

That's a threshold filter with two conditions, built entirely from nodes. And it's not just filtering - boolean masks multiply nicely into attention patterns and gating logic if you're building a model, which is precisely what this pack is for.

Gotchas

The output is torch.bool, so don't feed it straight into float arithmetic without casting. And it's element-wise: if you're thinking "AND these two conditions" in the sense of combining whole tensors, remember the shapes have to be broadcastable, not identical. That's a feature, not a bug - it lets a scalar true/false combine with a big mask.

Installing

Part of the HowToSD/ComfyUI-Pt-Wrapper pack, under the "Data Analysis" menu - install the pack once, get ~200 nodes. ComfyUI Manager: search ComfyUI-Pt-Wrapper, install, restart. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper

The pack's requirements are heavy (transformers, peft, accelerate…), but only the training side needs them; a logical op uses PyTorch alone, which you already have. Skip the pip line for math-only use. No model downloads.

And the standing pack rule: its TENSOR type is not ComfyUI's IMAGE or LATENT - convert images in with Pt From Image, back out with Pt To Image, or the wires won't connect.

CategoryData Analysis

Inputs (2)

NameTypeDefaultDescription
tens_aTENSOR
tens_bTENSOR

Outputs (1)

NameTypeDescription
TENSORTENSOR