flopscope.

flopscope.accounting.multi_dot_cost

flopscope.accounting.multi_dot_cost(shapes)[flopscope source]

Weighted FLOP cost of optimal matrix chain multiplication.

Parameters

shapes:Sequence[Sequence[int]]

Operand shapes in the same order as the einsum operands.

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 dynamic programming for optimal parenthesization.

Each binary matmul step (m x k) @ (k x n) is delegated to matmul_cost(m, k, n) (= 2*m*k*n - m*n), matching fnp.matmul and matrix_power_cost (issue #69 precedent).

A two-array call with a 0-d operand is priced separately, below, rather than through the chain model: flops.linalg.multi_dot of exactly two arrays delegates straight to flops.dot, and a 0-d operand there is a scalar multiply with no axis to contract -- not a case the dims chain (which assumes every operand contributes one dimension) can represent. Three-or-more arrays with a 0-d operand are NOT special-cased: real flops.linalg.multi_dot itself refuses that case (LinAlgError), so this module refusing it too -- via the same IndexError the dims line below already raised -- is correct; only the concrete exception type differs, which this library does not guarantee.