I’m looking after a way of doing the following operation. Here is an attempt using TensorCast.jl:
using TensorCast
# dummy data to simplify the example
n = 7
D = rand(n, n)
G = rand(7, 7, 7, 7)
@cast P[μ, ν] := D[λ, σ] * (G[μ, ν, σ, λ] - G[μ, λ, σ, ν] / 2)
# => ERROR: LoadError: can't find index λ on the left
I might be doing something wrong, but how could I make it work (possibly using another package)? I would like to have support of:
arbitrary AbstractArrays (the G in my code is actually a custom type that wraps a matrix to deal with symmetries, so it is not contiguous in memory)
as @cast fairly literally only does broadcasting, it won’t ever call sum without being asked to. (Maybe the error message should say this, though!) Tullio (and Einsum and TensorOperations and OMEinsum) do automatically reduce over indices not shown on the left.
This ought to work with Hermitian, but it won’t exploit it to do things more efficiently.