Pt Logical Xor
The 'exactly one' operator
- tens_a
- tens_b
- TENSOR
The logical family's contrarian. Pt Logical Xor is torch.logical_xor: True exactly where one input is true and the other isn't. AND gives you "both," OR gives you "at least one," XOR gives you "precisely one" - and that difference is what makes it the node for change detection and toggling rather than plain filtering.
How it works
Required inputs tens_a and tens_b, both TENSOR, output a single boolean TENSOR. Element-wise, broadcasting like the rest of the family. Numeric inputs count as truthy (nonzero = true), so 0/1 masks work directly. Under the hood it's a one-line torch.logical_xor(tens_a, tens_b).
Where XOR actually earns its keep
Two places, mostly. First, difference detection: take two masks from different pipeline stages and XOR them, and you get a mask of everywhere they disagree. That's genuinely useful for debugging - "where did the earlier mask and the later mask diverge?" - and for detecting changes between two tensor states.
Second, the toggle semantics. XOR with a constant true flips every bit; XOR with a constant false leaves things alone. So if you ever need to invert a mask conditionally inside a larger graph, XOR with a 1-element true tensor is the mechanism. It's the one operator in the family that has an "identity" the others don't.
Gotchas
Same rules as its siblings: output is bool-typed, cast before float math, and it's element-wise so shapes must broadcast. The usual trap with XOR specifically is reaching for it when you actually want OR - "either this or that" in casual speech usually means OR, not XOR. If you want "both true" to be allowed, that's OR. XOR is strictly the exclusive version.
Installing
Part of the HowToSD/ComfyUI-Pt-Wrapper pack under the "Data Analysis" menu - one install, ~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 heavy requirements.txt (transformers, peft, accelerate…) serves the training side; logical ops need only PyTorch, already installed. Skip the pip line for math-only work. No models to download.
Pack-wide note: the TENSOR type is separate from ComfyUI's IMAGE/LATENT - convert with Pt From Image (Pt From Image Transpose for (b, c, h, w)) and Pt To Image.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| tens_a | TENSOR | — | |
| tens_b | TENSOR | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| TENSOR | TENSOR | — |