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

**URL:** <https://discourse.julialang.org/t/why-is-this-tullio-example-failing-with-a-range-error/68748>\
**Category:** Performance\
**Tags:** tullio\
**Created:** [September 25, 2021, 11:46am UTC](https://discourse.julialang.org/t/why-is-this-tullio-example-failing-with-a-range-error/68748 "2021-09-25T11:46:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chiil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chiil/32/27474_2.png) [@Chiil](https://discourse.julialang.org/u/Chiil)\
**Post date:** [September 25, 2021, 11:46am UTC](https://discourse.julialang.org/t/why-is-this-tullio-example-failing-with-a-range-error/68748/1 "2021-09-25T11:46:18Z")

</div>

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.

```julia
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)

```

---

<div class="post-metadata">

**Author:** ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)\
**Post date:** [September 25, 2021, 8:34pm UTC](https://discourse.julialang.org/t/why-is-this-tullio-example-failing-with-a-range-error/68748/2 "2021-09-25T20:34:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Chiil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chiil/32/27474_2.png) [@Chiil](https://discourse.julialang.org/u/Chiil)\
**Post date:** [September 26, 2021, 7:52pm UTC](https://discourse.julialang.org/t/why-is-this-tullio-example-failing-with-a-range-error/68748/3 "2021-09-26T19:52:25Z")

</div>

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