Module contractors

Module contractors 

Source
Expand description

Implementations of the base-case singleton and pair contractors for different types of contractions.

This module defines the SingletonViewer, SingletonContractor, and PairContractor traits as well as the generic “container” objects EinsumPath, SingletonContraction, and PairContraction that hold Boxed trait objects of the specific cases determined at runtime to be most appropriate for the requested contraction.

The specific singleton and pair contractors defined in the singleton_contractors and pair_contractors submodules implement the relevant traits defined here. The six specific singleton contractors defined in singleton_contractors perform some combination of permutation of the input axes (e.g. ijk->jki), diagonalization across repeated but un-summed axes (e.g. ii->i), and summation across axes not present in the output index list (e.g. ijk->j). Not all of the nine pair contractors defined in pair_contractors are currently used as some appear to be slower than others.

Each struct implementing one of the *Contractor traits performs all the “setup work” required to perform the actual contraction. For example, HadamardProductGeneral permutes the input and output tensors and then computes the element-wise product of the two tensors. Given a SizedContraction (but no actual tensors), HadamardProductGeneral::new() figures out the permutation orders that will be needed so that contract_pair can simply execute the two permutations and then produce the element-wise product. This can be thought of as a way of compiling the einsum string into a set of instructions and the EinsumPath object can be thought of as an AST that is ready to compute a contraction when supplied with an actual set of operands to contract.

Re-exports§

pub use pair_contractors::TensordotGeneral;

Modules§

pair_contractors 🔒
Contains the specific implementations of PairContractor that represent the base-case ways to contract two simplified tensors.
singleton_contractors 🔒
Contains the specific implementations of SingletonContractor and SingletonViewer that represent the base-case ways to contract or simplify a single tensor.
strategies 🔒
This module contains the “strategy choice” logic for which specific contractor should be used for a given mini-contraction.

Structs§

EinsumPath
An EinsumPath, returned by einsum_path, represents a fully-prepared plan to perform a tensor contraction.
PairContraction
Holds a Boxed PairContractor trait object and two Option<Box>ed simplifications for the LHS and RHS tensors.
SimplificationMethodAndOutput 🔒
Holds an Box<dyn SingletonContractor<A>> and the resulting simplified indices.
SingletonContraction
Holds a Boxed SingletonContractor trait object.

Enums§

EinsumPathSteps
Either a singleton contraction, in the case of a single input operand, or a list of pair contractions, given two or more input operands

Traits§

PairContractor
let new_array = obj.contract_pair(lhs_view, rhs_view);
SingletonContractor
let new_array = obj.contract_singleton(tensor_view);
SingletonViewer
let new_view = obj.view_singleton(tensor_view);