Clarify the use multiline @tullio
In the README, looking at the following snippet:
@tullio out[x, y] := @inbounds(begin # sum over k
a,b = off[k]
mat[mod(x+a), mod(y+b)]
end) (x in axes(mat,1), y in axes(mat,2)) grad=Dual nograd=off
I struggled in my code until I made sure that:
- The first
:=afterout[x, y]can either be:=or=as described above the snippet. - However, within the
begin ... end, only=can be used. This is not mentioned anywhere.
I wanted to change that with a PR. But I want to confirm first.
Is that correct?
Sorry this package really needs a manual, but I got busy.
@tullio out[x, y] = right evaluates right and writes into out, possibly summing. @tullio out[x, y] := right makes a new array. The macro completely rewrites how this looks.
But what appears within the expression on the right isn't processed much, and at some point I allowed it to take an arbitrary block of code. The code is read (to figure out what indices appear, etc.) but evaluated as it stands. So = has no special meaning, it's just a normal block of code, and the last statement is its value, as usual.
The option verbose=2 will print everything, and the main loop here looks like this:
β for y = πΆπy
β for x = πΆπx
β ππΈπΈ = if β»οΈ === nothing
β zero(π―)
β else
β β[x, y] # this is part of how it handles memory blocking, allows a re-start
β end
β for k = πΆπk # this is the sum loop
β ππΈπΈ = ππΈπΈ + @inbounds(begin # this is the block of code provided, untouched
β (a, b) = off[k]
β mat[mod(x + a), mod(y + b)]
β end)
β end
β β[x, y] = ππΈπΈ # writing into an output array, created outside this function
β end
β end