flopscope.accounting.norm_cost
flopscope.accounting.norm_cost(shape, ord=None)[flopscope source]
Weighted FLOP cost of matrix or vector norm.
Parameters
- shape:tuple
Shape of the array passed to the analytical cost formula.
- ord:object, optional
Argument forwarded to the analytical linalg.norm cost formula. Defaults to
None.
Returns
- :int
Weighted public cost estimate, floored to match runtime accounting.
Notes
This helper multiplies the analytical FLOP count by the active weight from flopscope._weights and then applies int(...) so public estimates match budget deductions.
Cost depends on the ord parameter and input dimensionality.
Elementwise norms (Frobenius, L1, Linf, etc.):
2 * numel(FMA=2, weight=1 baked in).SVD-based norms (2-norm, nuclear norm): values-only SVD cost
2*a*b^2 + 2*b^3where a=max(m,n), b=min(m,n).General-p vector norms (ord not in {None, 0, 1, 2, inf, -inf}):
18 * numel + 16(abs + pow per elem + sum-reduce + root pow).