pub struct Subscripts {
pub inputs: Vec<Vec<u32>>,
pub output: Vec<u32>,
}Expand description
Einsum subscripts using integer labels (omeinsum-rs compatible).
Each dimension is represented by a u32 label. Labels shared across
multiple input tensors are contracted (summed over). Repeated labels within
one input select a diagonal before any reduction; if the repeated label is
absent from the output, the diagonal is reduced. Repeated labels in the
output embed the input on a diagonal.
§Examples
use tenferro_einsum::Subscripts;
// Matrix multiplication: C_{ik} = Σ_j A_{ij} * B_{jk}
let subs = Subscripts::new(&[&[0, 1], &[1, 2]], &[0, 2]);
assert_eq!(subs.inputs.len(), 2);
assert_eq!(subs.output, vec![0, 2]);use tenferro_einsum::Subscripts;
// Parse from string notation
let subs = Subscripts::parse("ij,jk->ik").unwrap();
assert_eq!(subs.inputs.len(), 2);use tenferro_einsum::Subscripts;
let trace = Subscripts::parse("ii->").unwrap();
let diagonal = Subscripts::parse("ii->i").unwrap();
let embed = 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!(embed.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]);Fields§
§inputs: Vec<Vec<u32>>Index labels for each input tensor.
output: Vec<u32>Index labels for the output tensor.
Implementations§
Source§impl Subscripts
impl Subscripts
Sourcepub fn new(inputs: &[&[u32]], output: &[u32]) -> Self
pub fn new(inputs: &[&[u32]], output: &[u32]) -> Self
Create subscripts from integer label arrays.
§Arguments
inputs— Index labels for each input tensoroutput— Index labels for the output tensor
Sourcepub fn parse(notation: &str) -> Result<Self>
pub fn parse(notation: &str) -> Result<Self>
Parse subscripts from NumPy/PyTorch-style string notation.
Each Unicode alphanumeric character represents a dimension label.
Labels are mapped to integer IDs via Unicode scalar values (char as u32).
Input tensors are separated by commas, and -> separates inputs
from the output.
Parentheses are rejected by this flat parser. Use
crate::NestedEinsum::parse when notation specifies a parenthesized
contraction order.
§Examples
"ij,jk->ik"— matrix multiplication"ii->"— diagonal extraction followed by reduction (trace)"ii->i"— diagonal extraction"i->ii"— diagonal embedding"iij->ij"— higher-rank diagonal extraction"ijk->"— full contraction (scalar result)
§Errors
Returns an error if the notation is malformed or contains parenthesized contraction order.
Trait Implementations§
Source§impl Clone for Subscripts
impl Clone for Subscripts
Source§fn clone(&self) -> Subscripts
fn clone(&self) -> Subscripts
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Subscripts
impl Debug for Subscripts
Source§impl From<&EinsumSubscripts> for Subscripts
impl From<&EinsumSubscripts> for Subscripts
Source§fn from(subscripts: &EinsumSubscripts) -> Self
fn from(subscripts: &EinsumSubscripts) -> Self
Source§impl From<&Subscripts> for EinsumSubscripts
impl From<&Subscripts> for EinsumSubscripts
Source§fn from(subscripts: &Subscripts) -> Self
fn from(subscripts: &Subscripts) -> Self
Source§impl From<EinsumSubscripts> for Subscripts
impl From<EinsumSubscripts> for Subscripts
Source§fn from(subscripts: EinsumSubscripts) -> Self
fn from(subscripts: EinsumSubscripts) -> Self
Source§impl From<Subscripts> for EinsumSubscripts
impl From<Subscripts> for EinsumSubscripts
Source§fn from(subscripts: Subscripts) -> Self
fn from(subscripts: Subscripts) -> Self
Source§impl Hash for Subscripts
impl Hash for Subscripts
Source§impl PartialEq for Subscripts
impl PartialEq for Subscripts
impl Eq for Subscripts
impl StructuralPartialEq for Subscripts
Auto Trait Implementations§
impl Freeze for Subscripts
impl RefUnwindSafe for Subscripts
impl Send for Subscripts
impl Sync for Subscripts
impl Unpin for Subscripts
impl UnsafeUnpin for Subscripts
impl UnwindSafe for Subscripts
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>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
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