flopscope.

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:

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).