Oddities with loop with dummy variable in Tullio

With Tullio alone, ideally it should notice that b in 1:q has a literal 1, and hence can be made OneTo(q). Failing that, it ought to notice that OffsetArrays is not loaded, and hence it can’t make an array with UnitRange axis, so it should insert something like first(1:b)==1 ? OneTo(b) : error("you really need OffsetArrays"), but it also seems to miss that check.

I think that’s a bug. The work-around is to define b_range = axes(wdelta,3) and write b in b_range.

julia> function mytest_tullio(wdelta,probnew)
           q = size(wdelta,3)
           @tullio mat[a,b,j] := wdelta[j,m,a] * probnew[m,a] (b in 1:q)  verbose=true
       end
...

julia> a = rand(2,3,4); b= rand(3,4); mytest_tullio(a,b)
┌ Info: left index ranges
│   a = Base.OneTo(4)
│   b = 1:4
└   j = Base.OneTo(2)
┌ Info: reduction index ranges
└   m = Base.OneTo(3)
ERROR: MethodError: no method matching similar(::Array{Float64, 3}, ::Type{Float64}, ::Tuple{Base.OneTo{Int64}, UnitRange{Int64}, Base.OneTo{Int64}})

The error with LoopVectorization is separate. It ought to be possible to reproduce this without Tullio by writing out the loops; calling the macro with verbose=2 will print everything including the generated loops.

1 Like