flopscope.

flopscope.accounting.matrix_power_cost

flopscope.accounting.matrix_power_cost(n, k)[flopscope source]

Weighted FLOP cost of matrix power ``A**k``.

Weighted FLOP cost of matrix power A**k.

Parameters

n:int

Number of columns in the input matrix.

k:int

Target rank or number of singular components to estimate.

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.

Uses exponentiation by repeated squaring. For k < 0, adds matmul_cost(n, n, n) for the initial matrix inversion (LU-based). Per-matmul cost is delegated to matmul_cost(n, n, n) so this formula tracks fnp.matmul's convention automatically (issue #69; the FMA=2 unification of 2026-05-20 previously left this wrapper undercounting by ~2x).