Skip to content
Get started Guides Reference

Types and stability modes

Core aliases live in extended_einsum.language.types.

Shape = tuple[int, ...]
TensorFormat = Literal["dense", "sparse"]
Backend = Literal["torch", "numpy", "jax"]
StabilityMode = Literal[
"unstable",
"scaled_min",
"scaled_sum",
"logspace_min",
"logspace_max",
]
  • HasShape: exposes .shape -> Shape.
  • HasBackend: exposes .backend -> Backend.
  • HasFormat: exposes .format -> TensorFormat.
  • Array: combines all three.

TArray is a type variable bounded by Array.

The frontend records "dense" or "sparse" on every SSA value. Unary operators preserve the input format. Elementwise binary operators and einsums currently require consistent operand formats. This metadata gives preprocessing and future lowering passes a place to make format-aware decisions; it is not by itself a sparse storage conversion.

One direct backend call per IR instruction. This is the only mode intended for unrestricted signed intermediates.

Represent positive values as normalized tensors plus broadcastable log scales. The suffix chooses the last-axis fiber normalizer. Normalizers and common scales are passed through stop_gradient because their represented-value derivative cancels.

Keep eligible values in log space, shifting contractions by a reference reduction before exponentiation. Parameter-derived inputs remain linear in the contraction where possible.