Jutho / TensorOperations.jl

Julia package for tensor contractions and related operations
https://jutho.github.io/TensorOperations.jl/stable/
Other
443 stars 56 forks source link

Unintended contraction throws error. #118

Closed whilo closed 1 year ago

whilo commented 2 years ago

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.

mcabbott commented 2 years ago

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.

Jutho commented 1 year ago

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.