Expand description
High-level einsum with N-ary contraction tree optimization.
This crate provides:
- String notation:
"ij,jk->ik"(NumPy/PyTorch compatible) - Parenthesized notation:
"ij,(jk,kl)->il"respects user-specified contraction order viaNestedEinsum - Integer label notation: using
u32labels - Repeated labels:
"ii->i"extracts diagonals,"ii->"traces, and"i->ii"embeds a vector on a diagonal - N-ary contraction: Automatic or manual optimization of pairwise
contraction order via
ContractionTree - Tensordot sugar: NumPy-style axis-pair contraction extension methods, implemented as contraction sugar rather than as linear algebra APIs.
- Extension runtime: traced einsum lowers to a registered tenferro extension runtime, keeping core op definitions small.
- Tensor extension traits: graph-building helpers are available as
methods on
GraphCompiler, eager input slices, and tensor receivers.
§Examples
use tenferro_einsum::{ContractionTree, Subscripts};
let subs = Subscripts::parse("ij,jk->ik").unwrap();
let tree = ContractionTree::optimize(&subs, &[&[2, 3], &[3, 4]]).unwrap();
assert_eq!(tree.step_count(), 1);use tenferro_einsum::Subscripts;
let trace = Subscripts::parse("ii->").unwrap();
let diagonal = Subscripts::parse("ii->i").unwrap();
let embedded = Subscripts::parse("i->ii").unwrap();
let higher_rank = Subscripts::parse("iij->ij").unwrap();
assert!(trace.output.is_empty());
assert_eq!(diagonal.output, vec![b'i' as u32]);
assert_eq!(embedded.output, vec![b'i' as u32, b'i' as u32]);
assert_eq!(higher_rank.inputs[0], vec![b'i' as u32, b'i' as u32, b'j' as u32]);Modules§
- lowering
- Read-only einsum lowering plans.
Structs§
- Contraction
Optimizer Options - Public options for automatic contraction-path optimization.
- Contraction
Tree - Contraction tree determining pairwise contraction order for N-ary einsum.
- Einsum
Subscripts - Canonical N-ary einsum subscripts using integer labels.
- Subscripts
- Einsum subscripts using integer labels (omeinsum-rs compatible).
Enums§
- Einsum
Optimize - Controls how the contraction path is determined for N-ary einsum.
- Error
- Errors produced while parsing, planning, or lowering einsum expressions.
- Nested
Einsum - Recursive einsum tree that preserves parenthesized grouping.
- Tensor
DotAxes - Axis specification for
TracedTensorEinsumExt::tensordotcontraction sugar.
Constants§
- EINSUM_
EXTENSION_ FAMILY_ ID - Stable family identifier for the standard tenferro einsum extension.
Traits§
- Eager
Einsum Ext - Eager einsum extension methods for slices or arrays of
EagerTensorrefs. - Eager
Tensor Einsum Ext - Eager tensor contraction-sugar methods.
- Graph
Compiler Einsum Ext - Traced einsum extension methods for
GraphCompiler. - Traced
Tensor Einsum Ext - Traced tensor contraction-sugar methods.
Functions§
- ad_
rules - Return the explicit einsum extension AD rule set.
- parse_
einsum_ subscripts - Parse string einsum notation into canonical integer labels.
- register_
runtime
Type Aliases§
- Result
- Result type alias for einsum parsing, planning, and lowering.