flopscope.accounting.einsum_cost
flopscope.accounting.einsum_cost(subscripts, shapes, operand_symmetries=None)[flopscope source]
Weighted FLOP cost of an einsum operation.
Delegates to contract_path from opt_einsum, which uses flop_count
with op_factor (FMA = 1 FLOP; see _cost_model.FMA_COST).
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.
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