Struct ndarray_einsum_beta::validation::SizedContraction [−][src]
A SizedContraction
contains a Contraction
as well as a HashMap<char, usize>
specifying the axis lengths for each index in the contraction.
Note that output_size is a misnomer (to be changed); it contains all the axis lengths, including the ones that will be contracted (i.e. not just the ones in contraction.output_indices).
Fields
contraction: Contraction
output_size: HashMap<char, usize>
Implementations
impl SizedContraction
[src]
pub fn subset(
&self,
new_operand_indices: &[Vec<char>],
new_output_indices: &[char]
) -> Result<Self, &'static str>
[src]
&self,
new_operand_indices: &[Vec<char>],
new_output_indices: &[char]
) -> Result<Self, &'static str>
Creates a new SizedContraction based on a subset of the operand indices and/or output indices. Not intended for general use; used internally in the crate when compiling a multi-tensor contraction into a set of tensor simplifications (a.k.a. singleton contractions) and pairwise contractions.
let m1: Array3<f64> = Array::zeros((2, 2, 3)); let m2: Array2<f64> = Array::zeros((3, 4)); let sc = SizedContraction::new("iij,jk->ik", &[&m1, &m2]).unwrap(); let lhs_simplification = sc.subset(&[vec!['i','i','j']], &['i','j']).unwrap(); let diagonalized_m1 = lhs_simplification.contract_operands(&[&m1]); assert_eq!(diagonalized_m1.shape(), &[2, 3]);
fn from_contraction_and_shapes(
contraction: &Contraction,
operand_shapes: &[Vec<usize>]
) -> Result<Self, &'static str>
[src]
contraction: &Contraction,
operand_shapes: &[Vec<usize>]
) -> Result<Self, &'static str>
pub fn from_contraction_and_operands<A>(
contraction: &Contraction,
operands: &[&dyn ArrayLike<A>]
) -> Result<Self, &'static str>
[src]
contraction: &Contraction,
operands: &[&dyn ArrayLike<A>]
) -> Result<Self, &'static str>
Create a SizedContraction from an already-created Contraction and a list of operands.
let m1: Array2<f64> = Array::zeros((2, 3)); let m2: Array2<f64> = Array::zeros((3, 4)); let c = Contraction::new("ij,jk->ik").unwrap(); let sc = SizedContraction::from_contraction_and_operands(&c, &[&m1, &m2]).unwrap(); assert_eq!(sc.output_size[&'i'], 2); assert_eq!(sc.output_size[&'k'], 4); assert_eq!(sc.output_size[&'j'], 3);
pub fn from_string_and_shapes(
input_string: &str,
operand_shapes: &[Vec<usize>]
) -> Result<Self, &'static str>
[src]
input_string: &str,
operand_shapes: &[Vec<usize>]
) -> Result<Self, &'static str>
Create a SizedContraction from an einsum
-formatted input string and a slice
of Vec<usize>
s containing the shapes of each operand.
let sc = SizedContraction::from_string_and_shapes( "ij,jk->ik", &[vec![2, 3], vec![3, 4]] ).unwrap(); assert_eq!(sc.output_size[&'i'], 2); assert_eq!(sc.output_size[&'k'], 4); assert_eq!(sc.output_size[&'j'], 3);
pub fn new<A>(
input_string: &str,
operands: &[&dyn ArrayLike<A>]
) -> Result<Self, &'static str>
[src]
input_string: &str,
operands: &[&dyn ArrayLike<A>]
) -> Result<Self, &'static str>
Create a SizedContraction from an einsum
-formatted input string and a list
of operands.
let m1: Array2<f64> = Array::zeros((2, 3)); let m2: Array2<f64> = Array::zeros((3, 4)); let sc = SizedContraction::new("ij,jk->ik", &[&m1, &m2]).unwrap(); assert_eq!(sc.output_size[&'i'], 2); assert_eq!(sc.output_size[&'k'], 4); assert_eq!(sc.output_size[&'j'], 3);
pub fn contract_operands<A: Clone + LinalgScalar>(
&self,
operands: &[&dyn ArrayLike<A>]
) -> ArrayD<A>
[src]
&self,
operands: &[&dyn ArrayLike<A>]
) -> ArrayD<A>
Perform the contraction on a set of operands.
let m1: Array2<f64> = Array::zeros((2, 3)); let m2: Array2<f64> = Array::zeros((3, 4)); let out: ArrayD<f64> = Array::zeros((2, 4)).into_dyn(); let sc = validate_and_size("ij,jk->ik", &[&m1, &m2]).unwrap(); assert_eq!(sc.contract_operands(&[&m1, &m2]), out);
pub fn as_einsum_string(&self) -> String
[src]
Show as an einsum
-formatted string.
let m1: Array2<f64> = Array::zeros((2, 3)); let m2: Array2<f64> = Array::zeros((3, 4)); let sc = validate_and_size("ij,jk", &[&m1, &m2]).unwrap(); assert_eq!(sc.as_einsum_string(), "ij,jk->ik");
Trait Implementations
impl Clone for SizedContraction
[src]
fn clone(&self) -> SizedContraction
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for SizedContraction
[src]
Auto Trait Implementations
impl RefUnwindSafe for SizedContraction
impl Send for SizedContraction
impl Sync for SizedContraction
impl Unpin for SizedContraction
impl UnwindSafe for SizedContraction
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,