module Num::Einsum

Extended Modules

Defined in:

einsum/contractors/pair.cr
einsum/optimizers.cr
einsum/strategies.cr
einsum/validation.cr

Instance Method Summary

Instance Method Detail

def einsum(input_string : String, operands : Array(Tensor(U, CPU(U)))) forall U #

Evaluates the Einstein summation convention on the operands.

The Einstein summation convention can be used to compute many multi-dimensional, linear algebraic array operations. einsum provides a succinct way of representing these.

A non-exhaustive list of these operations, which can be computed by einsum, is shown below:

Trace of an array
Return a diagonal
Array axis summations
Transpositions and permutations
Matrix multiplication and dot product
Vector inner and outer products
Broadcasting, element-wise and scalar multiplication
Tensor contractions

The subscripts string is a comma-separated list of subscript labels, where each label refers to a dimension of the corresponding operand. Whenever a label is repeated it is summed, so Num::Einsum.einsum("i,i", a, b) is equivalent to an inner operation. If a label appears only once, it is not summed, so Num::Einsum.einsum("i", a) produces a view of a with no changes. A further example Num::Einsum.einsum("ij,jk", a, b) describes traditional matrix multiplication and is equivalent to a.matmul(b). Repeated subscript labels in one operand take the diagonal. For example, Num::Einsum.einsum("ii", a) gets the trace of a matrix


[View source]
def einsum(input_string : String, *operands : Tensor(U, CPU(U))) forall U #

Evaluates the Einstein summation convention on the operands.

The Einstein summation convention can be used to compute many multi-dimensional, linear algebraic array operations. einsum provides a succinct way of representing these.

A non-exhaustive list of these operations, which can be computed by einsum, is shown below:

Trace of an array
Return a diagonal
Array axis summations
Transpositions and permutations
Matrix multiplication and dot product
Vector inner and outer products
Broadcasting, element-wise and scalar multiplication
Tensor contractions

The subscripts string is a comma-separated list of subscript labels, where each label refers to a dimension of the corresponding operand. Whenever a label is repeated it is summed, so Num::Einsum.einsum("i,i", a, b) is equivalent to an inner operation. If a label appears only once, it is not summed, so Num::Einsum.einsum("i", a) produces a view of a with no changes. A further example Num::Einsum.einsum("ij,jk", a, b) describes traditional matrix multiplication and is equivalent to a.matmul(b). Repeated subscript labels in one operand take the diagonal. For example, Num::Einsum.einsum("ii", a) gets the trace of a matrix


[View source]