[][src]Struct ndarray_einsum_beta::SizedContraction

pub struct SizedContraction {
    pub contraction: Contraction,
    pub output_size: HashMap<char, usize>,
}

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).

let m1: Array2<f64> = Array::zeros((2, 3));
let m2: Array2<f64> = Array::zeros((3, 4));
let sc = validate_and_size("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);

Fields

contraction: Contractionoutput_size: HashMap<char, usize>

Methods

impl SizedContraction[src]

pub fn subset(
    &self,
    new_operand_indices: &[Vec<char>],
    new_output_indices: &[char]
) -> Result<Self, &'static str>
[src]

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.

fn from_contraction_and_shapes(
    contraction: &Contraction,
    operand_shapes: &[Vec<usize>]
) -> Result<Self, &'static str>
[src]

pub fn from_contraction_and_operands<A>(
    contraction: &Contraction,
    operands: &[&dyn ArrayLike<A>]
) -> Result<Self, &'static str>
[src]

Create a SizedContraction from an already-created Contraction and a list of operands.

pub fn from_string_and_shapes(
    input_string: &str,
    operand_shapes: &[Vec<usize>]
) -> Result<Self, &'static str>
[src]

Create a SizedContraction from an already-created Contraction and a slice of Vec<usize>s containing the shapes of each operand.

pub fn new<A>(
    input_string: &str,
    operands: &[&dyn ArrayLike<A>]
) -> Result<Self, &'static str>
[src]

Create a SizedContraction from an einsum-formatted input string and a list of operands.

pub fn contract_operands<A: Clone + LinalgScalar>(
    &self,
    operands: &[&dyn ArrayLike<A>]
) -> ArrayD<A>
[src]

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);

Trait Implementations

impl Clone for SizedContraction[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for SizedContraction[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]