Tensor Binary Op
Tensor Binary Op — add, multiply, and otherwise math your tensors
- a
- b
- *
Tensor Binary Op is where the tensor section of this pack starts doing actual math. You give it two things - two tensors, or a tensor and a plain number - pick an operation from a dropdown, and it applies that operation element-by-element across the whole tensor. It's the "everyone's first arithmetic node" for anyone who needs to manipulate images, masks, or latents numerically instead of relying on whatever pre-built node happens to exist.
It's part of Basic data handling by StableLlama, a dependency-free utility pack that wraps everyday Python and PyTorch into ComfyUI nodes. The tensor corner has create, this binary-op node, a unary-op node, and the reshape/slice/permute/join family.
How it works
Under the hood each input gets coerced to a tensor if it isn't one already (torch.tensor() for scalars, passthrough for real tensors), then the chosen operation runs element-wise. The dropdown offers seven:
- add, subtract, multiply, divide - the basic four
- power - raise the first input to the power of the second
- remainder - modulo, the
%operator - floor_divide - integer-style division that rounds down, the
//operator
These are the familiar PyTorch operators, not approximations - torch.add, torch.pow, //, and so on.
The inputs that matter
Three inputs, two of which are the actual operands:
a(wildcard*) - first tensor or scalar.b(wildcard*) - second tensor or scalar. Note thataandbdon't have to be the same type: a tensor and a scalar work fine, which is how you'd do "multiply every pixel by 1.2" in one step.operation(dropdown, defaultadd) - pick your math.
One wildcard output, ready to wire into anything that wants tensor data.
Where you'd actually use it
This is a workhorse for people doing numerical work on images and masks. Multiply an image tensor by a brightness factor. Add two images to blend them. Subtract a mask from another mask to carve out a region. It's also how you'd experiment with latent-space tweaks that no dedicated node covers - because if an operation is expressible as tensor math, this node can do it.
Installing it
# ComfyUI Manager (recommended): search "Basic data handling", install, restart.
# or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
# restart ComfyUI
No dependencies, no model downloads. If your ComfyUI runs, this runs.
Where people get burned
Three classic traps, all grounded in how the underlying operators behave:
Integer division. If both operands are int tensors, divide does true division and can throw on a zero divisor, while floor_divide truncates silently. If you want fractional results, make sure at least one side is a float - images and latents already are.
Divide by zero. Floats give you inf/nan (which then quietly poison everything downstream); integers throw outright. Either way it's a "check your math" moment, not a node bug.
Shape mismatch. Element-wise ops require matching shapes (or a scalar on one side). If your two images have different heights or widths, PyTorch will refuse with a broadcast error - which is a good error, telling you your data isn't aligned before you've baked in a subtle bug.
One more honest note: with a wildcard input, nothing stops you from wiring in a string, and the resulting error will be cryptic. This node does tensor math; feed it tensors and numbers.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| a | * | — | |
| b | * | — | |
| operation | COMBO | add | 7 options: add, subtract, multiply, divide, power, remainder, +1 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| * | * | — |