Module pair_contractors

Module pair_contractors 

Source
Expand description

Contains the specific implementations of PairContractor that represent the base-case ways to contract two simplified tensors.

A tensor is simplified with respect to another tensor and a set of output indices if two conditions are met:

  1. Each index in the tensor is present in either the other tensor or in the output indices.
  2. Each index in the tensor appears only once.

Examples of einsum strings with two simplified tensors:

  1. ijk,jkl->il
  2. ijk,jkl->ijkl
  3. ijk,ijk->

Examples of einsum strings with two tensors that are NOT simplified:

  1. iijk,jkl->il Not simplified because i appears twice in the LHS tensor
  2. ijk,jkl->i Not simplified because l only appears in the RHS tensor

If the two input tensors are both simplified, all instances of tensor contraction can be expressed as one of a small number of cases. Note that there may be more than one way to express the same contraction; some preliminary benchmarking has been done to identify the faster choice.

Structsยง

BroadcastProductGeneral
Permutes the axes of the LHS and RHS tensor, broadcasts into the output shape, and then computes the element-wise product of the two broadcast tensors.
HadamardProduct
Computes the Hadamard (element-wise) product of two tensors.
HadamardProductGeneral
Permutes the axes of the LHS and RHS tensors to the order in which those axes appear in the output before computing the Hadamard (element-wise) product.
MatrixScalarProduct
Multiplies every element of the LHS tensor by the single scalar in the 0-d RHS tensor.
MatrixScalarProductGeneral
Permutes the axes of the LHS tensor to the output order and multiply all elements by the single scalar in the 0-d RHS tensor.
ScalarMatrixProduct
Multiplies every element of the RHS tensor by the single scalar in the 0-d LHS tensor.
ScalarMatrixProductGeneral
Permutes the axes of the RHS tensor to the output order and multiply all elements by the single scalar in the 0-d LHS tensor.
StackedTensordotGeneral
Repeatedly computes the tensor dot of subviews of the two tensors, iterating over indices which appear in the LHS, RHS, and output.
TensordotFixedPosition
Performs tensor dot product for two tensors where no permutation needs to be performed, e.g. ijk,jkl->il or ijk,klm->ijlm.
TensordotGeneral
Computes the tensor dot product of two tensors, with individual permutations of the LHS and RHS performed as necessary, as well as a final permutation of the output.

Functionsยง

find_outputs_in_inputs_unique ๐Ÿ”’
maybe_find_outputs_in_inputs_unique ๐Ÿ”’
Helper function used throughout this module to find the positions of one set of indices in a second set of indices. The most common case is generating a permutation to be supplied to permuted_axes.