Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected DimensionMismatch (v4.0.2 -> v4.0.3) #148

Closed
m1ka05 opened this issue Sep 13, 2023 · 3 comments
Closed

Unexpected DimensionMismatch (v4.0.2 -> v4.0.3) #148

m1ka05 opened this issue Sep 13, 2023 · 3 comments

Comments

@m1ka05
Copy link

m1ka05 commented Sep 13, 2023

Hi there,
a recent patch (v4.0.2 -> v4.0.3) seems to introduce an issue. Here is a minimal working example:

# 5 x 6
A = [ 3.0 2.0 5.0 2.0 4.0 3.0;
      1.0 5.0 3.0 3.0 8.0 4.0;
      5.0 1.0 1.0 2.0 3.0 3.0;
      7.0 1.0 3.0 3.0 1.0 1.0;
      8.0 1.0 4.0 1.0 1.0 8.0 ]

# 3 x 4
B = [ 2.0 2.0 1.0 4.0;
      3.0 2.0 3.0 3.0;
      3.0 3.0 3.0 1.0 ]

# 6 x 4
X = [ 2.0 3.0 3.0 5.0;
      1.0 2.0 1.0 2.0;
      5.0 5.0 4.0 2.0;
      1.0 2.0 3.0 7.0;
      7.0 9.0 1.0 1.0;
      6.0 7.0 3.0 2.0 ]

E = zeros(5,3)

@tensor begin
    E[i_1, i_2] = X[j_1, j_2] * A[i_1, j_1] * B[i_2, j_2]
end

Output:

TensorOperations@v4.0.2
=======================
5×3 Matrix{Float64}:
 622.0  750.0  743.0
 759.0  904.0  922.0
 508.0  589.0  559.0
 527.0  600.0  526.0
 777.0  934.0  899.0


TensorOperations@v4.0.3
=======================
ERROR: DimensionMismatch: 
Stacktrace:
 [1] _threaded_blas_mul!(C::StridedViews.StridedView{Float64, 2, Matrix{Float64}, typeof(identity)}, A::StridedViews.StridedView{Float64, 2, Matrix{Float64}, typeof(identity)}, B::StridedViews.StridedView{Float64, 2, Matrix{Float64}, typeof(identity)}, α::VectorInterface.One, β::VectorInterface.Zero, nthreads::Int64)
   @ Strided ~/.julia/packages/Strided/l1vm3/src/linalg.jl:101
 [2] _mul!
   @ ~/.julia/packages/Strided/l1vm3/src/linalg.jl:91 [inlined]
 [3] mul!(C::StridedViews.StridedView{Float64, 2, Matrix{Float64}, typeof(identity)}, A::StridedViews.StridedView{Float64, 2, Matrix{Float64}, typeof(identity)}, B::StridedViews.StridedView{Float64, 2, Matrix{Float64}, typeof(identity)}, α::VectorInterface.One, β::VectorInterface.Zero)
   @ Strided ~/.julia/packages/Strided/l1vm3/src/linalg.jl:60
 [4] tensorcontract!(C::StridedViews.StridedView{Float64, 2, Matrix{Float64}, typeof(identity)}, pC::Tuple{Tuple{Int64}, Tuple{Int64}}, A::StridedViews.StridedView{Float64, 2, Matrix{Float64}, typeof(identity)}, pA::Tuple{Tuple{Int64}, Tuple{Int64}}, conjA::Symbol, B::StridedViews.StridedView{Float64, 2, Matrix{Float64}, typeof(identity)}, pB::Tuple{Tuple{Int64}, Tuple{Int64}}, conjB::Symbol, α::VectorInterface.One, β::VectorInterface.Zero, backend::TensorOperations.Backend{:StridedBLAS})
   @ TensorOperations ~/.julia/packages/TensorOperations/19xy5/src/implementation/strided.jl:90
 [5] tensorcontract!(C::Matrix{Float64}, pC::Tuple{Tuple{Int64}, Tuple{Int64}}, A::Matrix{Float64}, pA::Tuple{Tuple{Int64}, Tuple{Int64}}, conjA::Symbol, B::Matrix{Float64}, pB::Tuple{Tuple{Int64}, Tuple{Int64}}, conjB::Symbol, α::VectorInterface.One, β::VectorInterface.Zero, #unused#::TensorOperations.Backend{:StridedBLAS})
   @ TensorOperations ~/.julia/packages/TensorOperations/19xy5/src/implementation/abstractarray.jl:63
 [6] tensorcontract!(C::Matrix{Float64}, pC::Tuple{Tuple{Int64}, Tuple{Int64}}, A::Matrix{Float64}, pA::Tuple{Tuple{Int64}, Tuple{Int64}}, conjA::Symbol, B::Matrix{Float64}, pB::Tuple{Tuple{Int64}, Tuple{Int64}}, conjB::Symbol, α::VectorInterface.One, β::VectorInterface.Zero)
   @ TensorOperations ~/.julia/packages/TensorOperations/19xy5/src/implementation/abstractarray.jl:35
 [7] top-level scope
   @ REPL[7]:1
@Jutho
Copy link
Owner

Jutho commented Sep 13, 2023

Thanks for the report; seems to be a bug in the underlying Strided implementation (which was also updated). We will try to fix asap.

@Jutho
Copy link
Owner

Jutho commented Sep 13, 2023

On second thought, it still is probably in TensorOperations, just before being lowered into Strided. Anyway, a fix will be on its way soon.

@Jutho
Copy link
Owner

Jutho commented Sep 15, 2023

This has been fixed in v4.0.4, so I am closing this issue

@Jutho Jutho closed this as completed Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants