TensorOperations.jl icon indicating copy to clipboard operation
TensorOperations.jl copied to clipboard

Unintended contraction throws error.

Open whilo opened this issue 3 years ago • 1 comments

As a disclaimer, there might be a simple way to achieve this, I am not an expert in tensor contractions or TensorOperations.jl, but I could not find a solution easily. The following code

    R = rand(2, 3) 
    M = rand(2, 5)

    @tensor begin
        C[t,n,m] := R[t,n]*M[t,m]
    end

throws an error with "non-matching indices between left and right hand side: ..." here. The intention here is to not contract t on the right hand side (which is what I found the parser decides to do after inspecting its error condition), but to rather iterate over all t and expand it in C. torch.einsum can handle this example as can Tullio.

whilo avatar Apr 23 '22 20:04 whilo

I don't think this is supported.

It's just broadcasting, C = R .* reshape(M, 2, 1, 5), which if you like index notation, TensorCast.jl will write for you. For simple things this is a relatively lightweight option, and complementary to TensorOperations.jl.

mcabbott avatar May 14 '22 00:05 mcabbott

As indeed indicated by @mcabbott , this behaviour is not supported with TensorOperations.jl, which is more strict in the index notation it supports as compared to einsum and Tullio. As I don't think this will change in the short run, I will close this issue.

Jutho avatar Apr 18 '23 22:04 Jutho