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

Pt Logical Not

Flip a mask so True becomes False

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

The unary one in the logical family. Pt Logical Not takes a single tensor and inverts every element: True becomes False, False becomes True. It's torch.logical_not, and it's the node you reach for when you have a mask for what you don't want and the rest of your workflow needs what you do.

How it works

One required input, tens_a; one boolean TENSOR output. The implementation is torch.logical_not(tens_a), element-wise, same shape out. As with the other logical nodes, numeric inputs get treated as truthy - zero is false, anything nonzero is true - so you can invert a 0/1 mask directly without casting it to bool first.

Where it fits

It's the complement operation in mask algebra. You've built a mask for "bad samples" with a comparison node; invert it with Pt Logical Not and now you have "good samples," ready to feed Pt Masked Select. Combined with Pt Logical And and Pt Logical Or you can express any boolean formula over tensors: "keep everything that's good OR (rare AND cheap)." That's the whole toolkit, and Not is the piece that lets you say "everything except."

The other pattern is chaining: not (a AND b) builds up the way you'd expect, and since every logical node outputs a bool tensor, they compose freely. You can invert an inverted mask all day without issue.

Gotchas

Honestly few. The output is bool-typed, so cast before float math if that's next in the pipeline. And remember element-wise semantics - a mask with a True anywhere produces a tensor with a False there, which is what you want when you invert a per-element mask, but it's not "negate the whole decision." For that you'd AND with a scalar.

Installing

Pt Logical Not rides in the HowToSD/ComfyUI-Pt-Wrapper pack, under the "Data Analysis" menu - one install gets all ~200 nodes. ComfyUI Manager: search ComfyUI-Pt-Wrapper, install, restart. Manual:

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

Heavy requirements (transformers, peft, accelerate…) exist for the training side; this node needs only PyTorch, already present. Skip the pip line for math-only work. No models to download.

Pack-wide reminder: everything uses the custom TENSOR type, not ComfyUI's IMAGE/LATENT - convert with Pt From Image (Pt From Image Transpose for (b, c, h, w)) and Pt To Image.

CategoryData Analysis

Inputs (1)

NameTypeDefaultDescription
tens_aTENSOR

Outputs (1)

NameTypeDescription
TENSORTENSOR