flopscope.accounting.reduction_cost
flopscope.accounting.reduction_cost(op_name: 'str', *, input_shape: 'tuple[int, ...]', axis: 'int | None' = None, symmetry: 'SymmetryGroup | None' = None) -> 'int'[flopscope source]
Weighted FLOP cost of a reduction operation.
Parameters
- op_name:str
Operation name used for weight lookup, e.g.
"sum"or"max".- input_shape:tuple of int
Shape of the reduction input.
- axis:int or None, optional
Reduction axis. Accepted for API consistency with the analytical helper.
- symmetry:SymmetryGroup or None, optional
If provided, only unique elements are counted analytically before the operation weight is applied.
Returns
- :int
Weighted public cost estimate, floored to match runtime accounting.
Notes
This helper multiplies the analytical reduction count by the active weight
for op_name and then floors with int(...) to match runtime budget
accounting.
Examples
>>> import flopscope as flops
>>> cost = flops.accounting.reduction_cost(
... "sum",
... input_shape=(4, 5),
... axis=1,
... )
>>> isinstance(cost, int)
True