flopscope.accounting.unwrap_cost
flopscope.accounting.unwrap_cost(shape)[flopscope source]
Weighted FLOP cost of phase unwrapping.
Parameters
- shape:tuple[int, ...]
Shape of the array passed to the analytical cost formula.
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.
NumPy's unwrap (flops.lib._function_base_impl.unwrap) performs 13
one-FLOP ufunc passes over the N-1 element dd = diff(p) array, then
one final add of the cumulative correction into the output. Counting
each named ufunc call as one pass:
diff — subtract adjacent elements (N-1 elements)
dd - low— subtract scalarinterval_lowfrom ddmod(..., period)— elementwise modulo+ interval_low— add scalar backddmod == low— elementwise compare (boundary check)dd > 0— elementwise compare``& `` — bitwise-and of two bool arrays
system_message<string>:14: (WARNING/2) Inline literal start-string without end-string.copyto/select— conditional write (boundary fix), 3-arg whereddmod - dd— elementwise subtract (ph_correct)abs(dd)— elementwise absolute value< discont— elementwise comparecopyto/select— conditional write (small-jump zeroing), 3-arg wherecumsum — prefix-sum scan
The p[slice1] + ph_correct.cumsum(axis) expression (final output
materialization) involves one add pass but is treated as part of the
output-write cost — following the convention that the output buffer
fill is attributed to the issuing op. Charging all 13 op-passes against
numel(input) rather than N-1 avoids tracking the edge-element
correction (one extra element) and gives a clean formula.
Steps 8 and 12 (copyto/select via 3-arg where) were treated as
free data movement (selecting by a given mask) from the where-arity
branching (Task 4, 2026-06-15) through the select-class rework (Task 6,
2026-07-17), which discounted this formula to 11 * numel for that
window. Task 6 also fixed 3-arg where itself to charge
4 * numel(broadcast output) (it derives no selector, but does scan
and write every output element), so the discount those two steps relied
on no longer holds; this formula reverts to charging all 13 passes,
matching the original value from Audit-completion Task 4 (2026-06-12).