ComfyUI Node

Pt Floor Div

Division that rounds down, on purpose

By HowToSD·Created about a year ago·Updated about a year ago· 7
Pt Floor Div
  • tens_a
  • tens_b
  • TENSOR

Pt Floor Div is the arithmetic node that answers "how many whole times does this divide into that?" It's element-wise floor division between two tensors - the PyTorch version of // in Python. Where plain division gives you 7 / 2 = 3.5, floor division gives you 3. No fractions, no rounding to nearest, just round down toward negative infinity. It's the kind of operation you don't think about until you're computing indices, chunk sizes, or grid coordinates and discover that // is exactly the tool.

How it works

The implementation is a one-liner: torch.floor_divide(tens_a, tens_b). That's it - the two input tensors are divided element-wise, and each result is floored. Because it's the element-wise op, standard broadcasting rules apply: you can divide a tensor by a scalar tensor, divide a big tensor by a small one along matching trailing dimensions, or divide two same-shaped tensors position by position.

One subtlety worth internalizing: floor division rounds toward negative infinity, not toward zero. So -7 // 2 is -4 in floor terms, while the truncation you might expect (and that torch.div with truncation gives you) would be -3. If you're porting math from a language where integer division truncates, this distinction will bite you exactly once.

Inputs and output

  • tens_a - the dividend tensor.
  • tens_b - the divisor tensor. Any shape that broadcasts against tens_a.
  • Output is a single TENSOR of the same (broadcast) shape.

There are no other knobs - this is a pure math node. Wire the result into whatever wants it: Pt From Latent output shapes, batch-size math in a training workflow, or just to sanity-check a tensor before feeding it to a model node.

Where people get burned

  • Division by zero produces inf (or NaN for 0 // 0) rather than an error. The node won't stop you; downstream loss computations will quietly turn into NaN. Check your tensors before you floor-divide by something that can be zero.
  • Float floor division is still float - torch.floor_divide on float tensors returns floats, just floored. If you need integer indices, cast or use integer tensors.
  • The negative-number floor vs. truncation trap above.

Installing it

Part of ComfyUI-Pt-Wrapper, so:

  • ComfyUI Manager → search "ComfyUI-Pt-Wrapper" → Install → restart.
  • Or cd ComfyUI/custom_nodes && git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper and restart.

The pack brings a heavy dependency list (transformers, datasets, peft, accelerate, scikit-learn, scipy, gensim, sentencepiece...), and the first boot after installing takes a while. No model files required for this node. It's a small education-focused pack by a solo author with barely any Reddit footprint - for problems, check the repo's docs/reference/ first, then open an issue (the README accepts issues but closes unsolicited PRs).

CategoryData Analysis

Inputs (2)

NameTypeDefaultDescription
tens_aTENSOR
tens_bTENSOR

Outputs (1)

NameTypeDescription
TENSORTENSOR