Nodes/Basic data handling/Tensor Unary Op
ComfyUI Node

Tensor Unary Op

Tensor Unary Op — one tensor in, one tensor out, a whole toolbox of math

By StableLlama·Created about a year ago·Updated 4 days ago· 48
Tensor Unary Op
  • input
  • *
operationabs

Tensor Unary Op takes a single tensor and applies a math function to every element, one at a time. Where the pack's Tensor Binary Op combines two tensors, this one transforms one - and the dropdown gives you nine transformations ranging from the boring (absolute value) to the ML-familiar (sigmoid, relu) to the occasionally destructive (exp, log).

It's part of Basic data handling by StableLlama, a dependency-free utility pack that wraps everyday Python and PyTorch into ComfyUI nodes. If you've already met Tensor Binary Op, this is its one-argument sibling.

How it works

The input is coerced to a tensor if needed, then one of nine torch functions runs element-wise:

  • abs, neg - absolute value, sign flip
  • exp, log - exponential, natural logarithm
  • sin, cos - trigonometry
  • sqrt - square root
  • sigmoid, relu - the two you'll recognize from neural networks

Every one of these is a plain PyTorch call (torch.abs, torch.sigmoid, …), so the semantics are exactly PyTorch's semantics. No approximations, no hidden preprocessing.

The inputs that matter

Two inputs, and only one is interesting:

  • input (wildcard *) - the tensor you're transforming. A scalar works too, in which case you're really just computing a function on one number.
  • operation (dropdown, default abs) - pick your function.

One wildcard output, same shape as the input.

Where you'd actually use it

The practical winners here are sigmoid and relu. Sigmoid squashes every value into a clean [0, 1] range - the exact range ComfyUI expects for masks and alpha channels, which makes it a handy normalizer when some node hands you raw logits or unbounded values. Relu zeroes out anything negative, which is useful for filtering noise or clamping the low end of a signal. Abs is the one you'll reach for when you only care about magnitude - say, comparing two frames and ignoring direction.

The rest (exp, log, sin, cos) are more for people who genuinely need those functions, usually in experiments or data pipelines, not for everyday image work. Worth knowing they exist; not worth forcing them into a workflow.

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

The pack has no dependencies beyond torch (already in ComfyUI) and downloads no models.

Where people get burned

Log and sqrt hate negatives. torch.log of a negative number gives you nan (with a warning), and sqrt of a negative does the same. If your data can dip below zero - and a lot of raw signals can - hit it with abs or relu first, or expect NaNs that will silently wreck everything downstream.

Exp overflows fast. exp of a moderately large number becomes inf in a hurry. It's fine for values near zero; it's a trap for anything big. Again, you usually want sigmoid instead of raw exp when you're building a smooth curve.

Dtype matters. These ops are happiest on float tensors. Feeding an int tensor into exp or sigmoid either errors or produces garbage; if your tensor came from a Tensor Create node with plain integer lists, convert to floats first.

And the usual wildcard warning: this node does tensor math, so wiring a string into it is a runtime error you'll get to diagnose the hard way.

CategoryBasic/tensor

Inputs (2)

NameTypeDefaultDescription
input*
operationCOMBOabs9 options: abs, neg, exp, log, sin, cos, +3

Outputs (1)

NameTypeDescription
**