flopscope.accounting.svd_cost
flopscope.accounting.svd_cost(m: 'int', n: 'int', k: 'int | None' = None, *, with_vectors: 'bool' = False, full_matrices: 'bool' = False) -> 'int'[flopscope source]
Weighted FLOP cost of an SVD (FMA=2, leading order).
- Full decomposition (
k is None), with a = max(m, n), b = min(m, n): values only (with_vectors=False): 2*a*b^2 + 2*b^3 thin U, V (full_matrices=False): 6*a*b^2 + 20*b^3 full U (full_matrices=True and m != n): 4*a^2*b + 22*b^3
<string>:5: (WARNING/2) Definition list ends without a blank line; unexpected unindent.Constants from the 2026-06 evidence audit (LAPACK dgesdd + G&VL 4e §8.6); see docs/reference/cost-model.md.
- Top-k truncated SVD (
1 <= k < min(m, n)): min(4*m*n*k, economy)
<string>:10: (WARNING/2) Definition list ends without a blank line; unexpected unindent.4*m*n*k is the verified leading-order cost of a rank-k randomized SVD
(Halko-Martinsson-Tropp; two passes over A, Theta(m*n*k)). flopscope bills
this standard truncated-algorithm cost even though the reference
implementation computes the full economy SVD and slices — it bills the
textbook cost of the operation (like matmul), not literal BLAS work.
Values-only is NOT leading-order cheaper for the truncated case (unlike the
full case). k >= min(m, n) bills the economy cost; the full_matrices
full-U premium applies only to the full decomposition (k is None).
See docs/reference/cost-model.md.
Parameters
- m:int
Number of rows in the input matrix.
- n:int
Number of columns in the input matrix.
- k:int | None, optional
Target rank or number of singular components to estimate. Defaults to
None.- with_vectors:bool, optional
Argument forwarded to the analytical linalg.svd cost formula. Defaults to
False.- full_matrices:bool, optional
Argument forwarded to the analytical linalg.svd cost formula. Defaults to
False.
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.
Examples
>>> import flopscope as flops
>>> cost = flops.accounting.svd_cost(128, 64)
>>> cost_topk = flops.accounting.svd_cost(128, 64, k=8) # min(4*128*64*8, economy)
>>> isinstance(cost, int)
True