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) FREE (3-arg where)ddmod - dd— elementwise subtract (ph_correct)abs(dd)— elementwise absolute value< discont— elementwise comparecopyto/select— conditional write (small-jump zeroing) FREE (3-arg where)cumsum — 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 11 non-free 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) are pure data
movement (selecting by a given mask) and are therefore free per the
cost-model rule introduced with the where-arity branching (Task 4,
2026-06-15). Prior value was 13 * numel (included 2 free selects);
before that it was 7 * numel (Audit-completion Task 4, 2026-06-12).