ComfyUI Node

sum

Add up a set — and get the answer twice, once as int, once as float

By StableLlama·Created about a year ago·Updated 4 days ago· 48
sum
  • set
  • sum_int
  • sum_float
start0

sum adds up every element in a set and returns the total - plus a second output that gives you the same total as a float. It's Python's sum() as a node, with an oddity worth understanding: two outputs, sum_int and sum_float, that usually hold the same number.

When do you actually need to sum a set? Any time you're aggregating a pool of unique numeric values - total cost across a set of prices, total strength across a set of denoise values, total count across a set of per-item contributions. The uniqueness guarantee doesn't hurt here; it just means you're summing distinct values, which is usually what you want when the pool came from a dedupe.

How it works

The mechanism is sum(set, start), where start is an optional integer that seeds the total (default 0). Then it returns the result twice: once as whatever type it naturally is, and once forced to float.

That's where the two-output design reveals itself as a convenience rather than a lie, but there's a caveat in it:

  • If your set holds integers, sum_int is a real int and sum_float is its float twin.
  • If your set holds floats, sum() returns a float - and that float gets labeled sum_int even though it isn't one. So the sum_int output is best read as "the natural result," not "guaranteed integer."

Worth a beat because it will bite someone: the node's own docs note that all elements need to support addition. Throw a string in a numeric set and sum() raises. Sets built from mixed types are asking for it.

Inputs and output

  • set (SET) - the set to sum.
  • start (INT, optional, default 0) - initial value added to the total. Mostly useful for offsetting a count.
  • sum_int (INT, output) - the total, in its natural type.
  • sum_float (FLOAT, output) - the same total forced to float, handy when the downstream node insists on a float input.

Installing

It's in Basic data handling by StableLlama. ComfyUI Manager - search "Basic data handling", install, restart - is fastest. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling

Restart after cloning. Zero dependencies and no model downloads, consistent with this pack's no-fuss install.

Common issues

The float-in-the-int-slot surprise above is the main one - if your totals look "wrong," check whether the set held floats. The other failure is type mixing: summing a set that contains non-numeric values will error, because Python won't add a string to a number. Build your set with a type-specific creator (create SET from INTs or from FLOATs) and you sidestep it entirely.

CategoryBasic/SET

Inputs (2)

NameTypeDefaultDescription
setSET
startoptINT0

Outputs (2)

NameTypeDescription
sum_intINT
sum_floatFLOAT