Jutho / TensorOperations.jl

Julia package for tensor contractions and related operations
https://jutho.github.io/TensorOperations.jl/stable/
Other
481 stars 57 forks source link
einstein-summation index-notation tensor tensor-contraction tensor-operations tensor-permutation tensor-trace tensor-transposition

TensorOperations.jl

Fast tensor operations using a convenient Einstein index notation.

Documentation Digital Object Identifier Downloads
DOI TensorOperations Downloads
Build Status PkgEval Coverage Quality assurance
[CI][ci-url] PkgEval ![Codecov][codecov-img] Aqua QA

[ci-url]: https://github.com/Jutho/TensorOperations.jl/actions?query=workflow%3ACI

[codecov-img]: https://codecov.io/gh/Jutho/TensorOperations.jl/branch/master/graph/badge.svg

What's new in v5

What's new in v4

WARNING: TensorOperations 4.0 contains several breaking changes and cannot generally be expected to be compatible with previous versions.

Code example

TensorOperations.jl is mostly used through the @tensor macro which allows one to express a given operation in terms of index notation format, a.k.a. Einstein notation (using Einstein's summation convention).

using TensorOperations
α = randn()
A = randn(5, 5, 5, 5, 5, 5)
B = randn(5, 5, 5)
C = randn(5, 5, 5)
D = zeros(5, 5, 5)
@tensor begin
    D[a, b, c] = A[a, e, f, c, f, g] * B[g, b, e] + α * C[c, a, b]
    E[a, b, c] := A[a, e, f, c, f, g] * B[g, b, e] + α * C[c, a, b]
end

In the second to last line, the result of the operation will be stored in the preallocated array D, whereas the last line uses a different assignment operator := in order to define and allocate a new array E of the correct size. The contents of D and E will be equal.

For more detailed information, please see the documentation.

Citing

See CITATION.bib for the relevant reference(s).