pub enum NestedEinsum {
Leaf(usize),
Node {
subscripts: Subscripts,
children: Vec<NestedEinsum>,
},
}Expand description
Recursive einsum tree that preserves parenthesized grouping.
NestedEinsum mirrors OMEinsum.jl’s NestedEinsum: each internal node
holds Subscripts describing how its children are contracted, and leaf
nodes reference an original input tensor by index.
§Construction
Use NestedEinsum::parse to build a tree from parenthesized string
notation such as "(ij,jk),kl->il". Without parentheses the result is
a flat root node whose children are all leaves.
§Examples
use tenferro_einsum::NestedEinsum;
// Flat (no grouping): root with two leaves
let flat = NestedEinsum::parse("ij,jk->ik").unwrap();
assert!(matches!(flat, NestedEinsum::Node { .. }));
// Grouped: contract first two operands, then with third
let grouped = NestedEinsum::parse("(ij,jk),kl->il").unwrap();
assert!(matches!(grouped, NestedEinsum::Node { .. }));Variants§
Leaf(usize)
A leaf referencing one of the original input tensors by index.
Node
An internal node that contracts its children according to subscripts.
Fields
subscripts: SubscriptsThe subscripts for this contraction: one input per child, plus output.
children: Vec<NestedEinsum>Child sub-expressions (leaves or further nodes).
Implementations§
Source§impl NestedEinsum
impl NestedEinsum
Sourcepub fn count_leaves(&self) -> usize
pub fn count_leaves(&self) -> usize
Count the total number of leaf operands in the tree.
Sourcepub fn parse(notation: &str) -> Result<Self>
pub fn parse(notation: &str) -> Result<Self>
Parse parenthesized einsum notation into a recursive tree.
Notation follows the standard "inputs->output" format with optional
parentheses to specify contraction order. Each parenthesized group
becomes an internal NestedEinsum::Node; bare operands become
NestedEinsum::Leaf nodes.
§Examples
use tenferro_einsum::NestedEinsum;
let nested = NestedEinsum::parse("(ij,jk),kl->il").unwrap();
// Root has two children: a group node and a leaf
match &nested {
NestedEinsum::Node { children, .. } => assert_eq!(children.len(), 2),
_ => panic!("expected Node"),
}§Errors
Returns an error if parentheses are mismatched or the notation is otherwise malformed.
Trait Implementations§
Source§impl Clone for NestedEinsum
impl Clone for NestedEinsum
Source§fn clone(&self) -> NestedEinsum
fn clone(&self) -> NestedEinsum
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for NestedEinsum
impl RefUnwindSafe for NestedEinsum
impl Send for NestedEinsum
impl Sync for NestedEinsum
impl Unpin for NestedEinsum
impl UnwindSafe for NestedEinsum
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more