flopscope.accounting.einsum_cost
flopscope.accounting.einsum_cost(subscripts, shapes, operand_symmetries=None, identity_pattern=None)[flopscope source]
Weighted FLOP cost of an einsum operation.
Uses the whole-expression direct-event accumulation model: total = (k-1) * prod(M) + prod(alpha), where M is the number of unique output elements and alpha is the number of unique output+ reduction-axis combinations. FMA = 2 (textbook): the α/M formula counts multiplies and adds separately by construction.
Parameters
- subscripts:str
Einstein summation expression that defines the contraction.
- shapes:list[tuple[int, ...]]
Operand shapes in the same order as the einsum operands.
- operand_symmetries:list[SymmetryGroup | None] | None, optional
Optional symmetry metadata for each einsum operand. Defaults to
None.- identity_pattern:tuple[tuple[int, ...], ...] | None, optional
Argument forwarded to the analytical einsum cost formula. Defaults to
None.
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.einsum_cost(
... "ij,jk->ik",
... [(8, 16), (16, 4)],
... )
>>> isinstance(cost, int)
True