Why is this @tullio example failing with a range error?

I am experimenting with Tullio in order to write fast nested loops. I have arrays on which I perform computations on a subset. I do not know why this is failing, as all indices get a range provided.

using Tullio

itot = 100; jtot = 100; ktot = 100

a = rand(itot, jtot, ktot)
b = rand(itot, jtot, ktot)

is = 10; ie = 20; js = 10; je = 20; ks = 10; ke = 20

c = 0.5

# This fails with: range of index j must agree
@tullio b[i, j, k] += c*a[i, j, k] (i in is:ie, j in js:je, k in ks:ke)

Iā€™m not sure this is very well documented, but every index is in one of two modes. It either demands equality of all ranges, or takes the intersection of them. And the switch is that if it ever appears with a shift, then it is in the second mode.

So @tullio b[i, j, k] += c*a[i+0, j+0, k+0] (i in is:ie, j in js:je, k in ks:ke) will probably do what you want. Be warned that the ranges provided afterwards have no special priority, the are just intersected with the others.

2 Likes

This works indeed. Are there any side effects of also adding the +0 in the lefthand side?