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 - N-ary contraction: Automatic or manual optimization of pairwise
contraction order via
ContractionTree - v2 builder:
build_einsum_fragmentlowers einsum into a compute graph fragment usingDotGeneral,ReduceSum,Transpose, etc.
§Examples
ⓘ
use computegraph::fragment::FragmentBuilder;
use computegraph::types::ValRef;
use tenferro_ops::input_key::TensorInputKey;
use tenferro_ops::std_tensor_op::StdTensorOp;
use tenferro_einsum::{ContractionTree, Subscripts, build_einsum_fragment};
let subs = Subscripts::parse("ij,jk->ik").unwrap();
let tree = ContractionTree::optimize(&subs, &[&[2, 3], &[3, 4]]).unwrap();
let mut builder = FragmentBuilder::<StdTensorOp>::new();
let a = builder.add_input(TensorInputKey::User { id: 0 });
let b = builder.add_input(TensorInputKey::User { id: 1 });
let result = build_einsum_fragment(
&mut builder,
&tree,
&[ValRef::Local(a), ValRef::Local(b)],
&[vec![2, 3], vec![3, 4]],
);Re-exports§
pub use builder::build_einsum_fragment;
Modules§
Structs§
- Contraction
Optimizer Options - Public options for automatic contraction-path optimization.
- Contraction
Tree - Contraction tree determining pairwise contraction order for N-ary einsum.
- Subscripts
- Einsum subscripts using integer labels (omeinsum-rs compatible).
Enums§
- Nested
Einsum - Recursive einsum tree that preserves parenthesized grouping.
Functions§
- build_
size_ dict - Build a label -> size mapping from subscripts and input shapes.
- compute_
output_ shape - Compute output shape from output subscripts and size dictionary.
- eager_
einsum - Eager N-ary einsum on concrete
Tensorvalues. - typed_
eager_ einsum - Execute eager einsum over typed tensors and return a typed result.