Jutho / TensorOperations.jl

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

tracing a 1X1 tensor throws BoundsError #60

Closed orialb closed 5 years ago

orialb commented 5 years ago

Hi, first of all let me thank you for this great package that I find really useful. I encountered an issue with v1.0.3 that didn't occur in v0.7.1 where trying to trace a 1X1 tensor produces an error. minimal example to reproduce:

M = rand(1,1)
@tensor M[] := M[a,a]

this results in the following error:

ERROR: BoundsError: attempt to access ()
  at index [0]
Stacktrace:
 [1] getindex(::Tuple{}, ::Int64) at ./tuple.jl:24
 [2] stride( :Strided.UnsafeStridedView{Float64,0,Float64,typeof(identity)}, ::Int64) at /home/user/.julia/packages/Strided/89nTo/src/unsafestridedview.jl:31
[3] #72 at /home/user/.julia/packages/Strided/89nTo/src/broadcast.jl:66 [inlined]
 [4] ntuple at ./tuple.jl:156 [inlined]
 [5] promoteshape1 at /home/user/.julia/packages/Strided/89nTo/src/broadcast.jl:64 [inlined]
 [6] promoteshape at /home/user/.julia/packages/Strided/89nTo/src/broadcast.jl:49 [inlined]
 [7] _mapreducedim! at /home/user/.julia/packages/Strided/89nTo/src/mapreduce.jl:74 [inlined]
 [8] _trace!(::Int64, ::Strided.UnsafeStridedView{Float64,2,Float64,typeof(identity)}, ::Bool, 
::Strided.UnsafeStridedView{Float64,0,Float64,typeof(identity)}, ::Tuple{}, ::Tuple{Int64}, ::Tuple{Int64}) at /home/user/.julia/packages/TensorOperations/RSY9n/src/implementation/stridedarray.jl:220
 [9] trace!(::Int64, ::Array{Float64,2}, ::Symbol, ::Bool, ::Array{Float64,0}, ::Tuple{}, ::Tuple{Int64}, ::Tuple{Int64}) at ./gcutils.jl:87
 [10] trace!(::Int64, ::Array{Float64,2}, ::Symbol, ::Bool, ::Array{Float64,0}, ::Tuple{}, ::Tuple{}, ::Tuple{Int64}, ::Tuple{Int64}) at /home/user/.julia/packages/TensorOperations/RSY9n/src/implementation/stridedarray.jl:62
 [11] top-level scope at /home/user/.julia/packages/TensorOperations/RSY9n/src/indexnotation/tensormacro.jl:352

I'm on Julia 1.0.3 .

Jutho commented 5 years ago

Nice catch; should be fixed when v0.2.6 of the package Strided is registered in METADATA; shouldn't take too long.

Your syntax invocation is a bit strange though, you overwrite the rank 2 array M with a rank zero array, i.e. M. If you just want the trace as a scalar, you could also do

M = randn(1,1)
@tensor t = M[a,a]
orialb commented 5 years ago

should be fixed when v0.2.6 of the package Strided is registered in METADATA; shouldn't take too long.

cool, thanks for the quick reply!

Your syntax invocation is a bit strange though, you overwrite the rank 2 array M with a rank zero array, i.e. M. If you just want the trace as a scalar, you could also do ...

Oh I didn't know that's possible, thanks for the tip.

Jutho commented 5 years ago

Can you try pkg> update and see whether the problem persists or is solved?

orialb commented 5 years ago

The issue seems to be solved after the update of Strided.jl to v0.2.6. Thanks!