flopscope.accounting.lstsq_cost
flopscope.accounting.lstsq_cost(m, n, b_cols=1, b_ndim=1)[flopscope source]
Weighted FLOP cost of least-squares via SVD.
Parameters
- m:int
Number of rows in the input matrix.
- n:int
Number of columns in the input matrix.
- b_cols:int, optional
Argument forwarded to the analytical linalg.lstsq cost formula. Defaults to
1.- b_ndim:int, optional
Argument forwarded to the analytical linalg.lstsq 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.
NumPy uses LAPACK gelsd (SVD-based). Cost decomposition:
svd(m,n) + ut_b + k*c + reconstruction where k = min(m, n)
and c = b_cols.
Both 1-D and 2-D RHS branches use matmul_cost:
ut_b = matmul_cost(k, m, b_cols) and
reconstruction = matmul_cost(n, k, b_cols).
Issue #69 (was previously just svd_cost ignoring the
back-substitution).
The SVD term uses with_vectors=True (the reconstruction needs U/V); the 4.0 linalg weight is gone, so this composed value is exactly what is charged.