ComfyUI Node

Pt Logical Or

Union of two masks, element-wise

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

Pt Logical Or is torch.logical_or: two tensors in, one boolean tensor out, True wherever either input is true. In mask terms it's the union operator - combine two conditions and keep the elements that satisfy at least one of them. It's the OR that makes multi-condition filters expressible in the graph.

How it works

Required inputs tens_a and tens_b, both TENSOR; the node returns torch.logical_or(tens_a, tens_b) element-wise, with torch's usual broadcasting. Boolean tensors in, boolean tensor out. Numeric inputs are interpreted as truthy - nonzero is true, zero is false - so a 0/1 mask works without a cast.

The pattern it belongs to

Say you've built two masks with comparison nodes: one for "score above 0.8" and one for "score below 0.2." On their own each selects a tail of the distribution. Wire both into Pt Logical Or and you get "unusually confident either way" - a union filter you can hand to Pt Masked Select to pull out exactly those elements. Swap in Pt Logical And and you get the intersection instead. Together with Pt Logical Not, these four nodes are the complete boolean toolkit; Or is the half you need whenever "any of these" is the question.

One nice property of OR: it's the natural way to set defaults or fill gaps. A mask that's sparse can be OR'd with a fallback mask so every element is covered.

Gotchas

Output is bool-typed, so cast before float arithmetic. And OR is per-element - a single true somewhere doesn't make the whole tensor true. If you want "does this mask have any true at all," that's a reduction, not this node.

Installing

Ships in the HowToSD/ComfyUI-Pt-Wrapper pack under "Data Analysis" - install the pack, get ~200 nodes including this one. ComfyUI Manager: search ComfyUI-Pt-Wrapper, install, restart. Manual:

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

The requirements.txt is heavy (transformers, datasets, peft, accelerate…) but that's the training side; a logical op only needs PyTorch, which you already have. Skip the pip line for math-only usage. No models to download.

Pack-wide: the TENSOR type isn't ComfyUI's IMAGE/LATENT - bring images in with Pt From Image (Pt From Image Transpose for (b, c, h, w)), back out with Pt To Image.

CategoryData Analysis

Inputs (2)

NameTypeDefaultDescription
tens_aTENSOR
tens_bTENSOR

Outputs (1)

NameTypeDescription
TENSORTENSOR