Skip to content

Commit e957f4a

Browse files
committed
move multi-line story later in readme
1 parent 88b4a0f commit e957f4a

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,7 @@ The macro also tries to provide a gradient for use with [Tracker](https://github
3434

3535
* The option `grad=Dual` uses instead [ForwardDiff](https://github.com/JuliaDiff/ForwardDiff.jl) to differentiate the right hand side (only for reductions over `+`). This allows for more complicated expressions.
3636

37-
The expression need not be just one line, for example:
38-
39-
```julia
40-
@tullio out[x, y] := @inbounds(begin # sum over k
41-
a,b = off[k]
42-
mat[mod(x+a), mod(y+b)]
43-
end) (x in axes(mat,1), y in axes(mat,2)) grad=Dual nograd=off
44-
```
45-
46-
Here the macro cannot infer the range of the output's indices `x,y`, so they must be provided explicitly.
47-
(If writing into an existing array, with `out[x,y] = begin ...` or `+=`, then ranges would be taken from there.)
48-
Because it sees assignment being made, it does not attempt to sum over `a,b`, and it assumes that indices could go out of bounds so does not add `@inbounds` for you.
49-
(Although in fact `mod(x+a) == mod(x+a, axes(mat,1))` is safe.)
50-
It will also not be able to take a symbolic derivative, but dual numbers will work fine.
51-
37+
The entire right hand side is summed over the full possible range of any indices not appearing on the left.
5238
Pipe operators `|>` or `<|` indicate functions to be performed *outside* the sum, for example:
5339

5440
```julia
@@ -267,6 +253,22 @@ Some warnings are in order:
267253
</details>
268254
<details><summary><b>Larger expressions</b></summary>
269255

256+
The expression need not be just one line, for example:
257+
258+
```julia
259+
@tullio out[x, y] := @inbounds(begin # sum over k
260+
a,b = off[k]
261+
mat[mod(x+a), mod(y+b)]
262+
end) (x in axes(mat,1), y in axes(mat,2)) grad=Dual nograd=off
263+
```
264+
Here the macro cannot infer the range of the output's indices `x,y`, so they must be provided explicitly.
265+
(If writing into an existing array, with `out[x,y] = begin ...` or `+=`, then ranges would be taken from there.)
266+
Because it sees assignment being made, it does not attempt to sum over `a,b`, and it assumes that indices could go out of bounds so does not add `@inbounds` for you.
267+
(Although in fact `mod(x+a) == mod(x+a, axes(mat,1))` is safe.)
268+
It will also not be able to take a symbolic derivative, but dual numbers will work fine.
269+
270+
More examples:
271+
270272
```julia
271273
using Tullio, OffsetArrays
272274

0 commit comments

Comments
 (0)