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

Unable to infer range of index which occurs two times

Open roflmaostc opened this issue 4 years ago • 1 comments

# works
function bin(x, Δ=0::Int)
    @tullio res[i] := x[i + 0] + x[i + Δ + 1]
end

# does not
function bin2(x, Δ=0::Int)
    @tullio res[i] := x[i + Δ + 0] + x[i + Δ + 1]
end

Is that a fundamental thing?

Thanks,

Felix

roflmaostc avatar Oct 13 '21 01:10 roflmaostc

The second of these seems to be doing what's intended. Since there isn't a unique solution, it won't guess how much of the range of x's index is taken by i and how much by Δ:

julia> using Tullio

julia> x = 1:10;

julia> @tullio res[_,i] := x[i + Δ] + x[i + Δ + 1]  i in 1:9  verbose=true
┌ Info: reduction index ranges
└   Δ = 0:1
1×9 Matrix{Int64}:
 8  12  16  20  24  28  32  36  40
 
 julia> @tullio res[_,i] := x[i + Δ] + x[i + Δ + 1]  i in 1:3  verbose=true
┌ Info: reduction index ranges
└   Δ = 0:7
1×3 Matrix{Int64}:
 80  96  112

But I'm a little puzzled by the first, in fact. Why is the range of i fixed, when I can vary it?

julia> @tullio res[_,i] := x[i] + x[i + Δ + 1]  verbose=true  # Δ cannot vary at all?
┌ Info: left index ranges
└   i = Base.OneTo(10)
┌ Info: reduction index ranges
└   Δ = -1:-1
1×10 Matrix{Int64}:
 2  4  6  8  10  12  14  16  18  20

julia> @tullio res[_,i] := x[i] + x[i + Δ + 1]  i in 1:3  verbose=true
┌ Info: left index ranges
└   i = Base.OneTo(3)
┌ Info: reduction index ranges
└   Δ = -1:6
1×3 Matrix{Int64}:
 44  60  76

You had an explicit i+0 there, but I believe the x[i + Δ + 1] is enough to make i be treated as intersection not equality: if it wasn't, the above would error, like this does:

julia> @tullio res[_,i] := x[i]  i in 1:3   # no shifts on i, hence strict mode
ERROR: "range of index i must agree"

julia> @tullio res[_,i] := x[i+0]  i in 1:3  # some shifts, hence intersect mode
1×3 Matrix{Int64}:
 1  2  3

mcabbott avatar Oct 13 '21 03:10 mcabbott