flopscope.

flopscope.accounting.polyfit_cost

flopscope.accounting.polyfit_cost(m, deg, ncols=1)[flopscope source]

Cost for polyfit: Vandermonde build + lstsq solve.

flops.polyfit builds an (m, deg+1) Vandermonde matrix from x and solves it against y with flops.linalg.lstsq (an SVD-based least-squares solve). The billed cost is therefore the Vandermonde build plus lstsq_cost(m, deg+1, ncols) -- the identical solve linalg.lstsq itself would charge for the same shape -- rather than a standalone normal-equations-shaped estimate. The prior 2*m*(deg+1)^2*ncols formula billed 3-13x cheaper than routing the same solve through lstsq directly, so a least-squares solve could dodge its true price by going through polyfit instead.

The SVD factorization inside lstsq_cost is shared across every right-hand-side column -- only the final back-substitution scales with ncols -- so this cost grows sublinearly in ncols, unlike the old formula, which scaled every term linearly with ncols.

Parameters

m:int

Number of rows in the input matrix.

deg:int

Argument forwarded to the analytical polyfit cost formula.

ncols:int, optional

Argument forwarded to the analytical polyfit cost formula. Defaults to 1.

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.