Skip to content

Commit 3ae6449

Browse files
committed
update thunk docstring
1 parent 62d3be3 commit 3ae6449

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/differentials.jl

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ A thunk is a deferred computation.
201201
It wraps a zero argument closure that when invoked returns a differential.
202202
`@thunk(v)` is a macro that expands into `Thunk(()->v)`.
203203
204-
205204
Calling a thunk, calls the wrapped closure.
206205
`extern`ing thunks applies recursively, it also externs the differial that the closure returns.
207206
If you do not want that, then simply call the thunk
@@ -222,19 +221,19 @@ julia> t()()
222221
223222
### When to `@thunk`?
224223
When writing `rrule`s (and to a lesser exent `frule`s), it is important to `@thunk`
225-
appropriately. Propagation rule's that return multiple deriviatives are able to not
226-
do all the work of computing all of them only to have just one used.
227-
By `@thunk`ing the work required for each, they can only be computed when needed.
224+
appropriately.
225+
Propagation rule's that return multiple derivatives are not able to do all the computing themselves.
226+
By `@thunk`ing the work required for each, they then compute only what is needed.
228227
229228
#### So why not thunk everything?
230-
`@thunk` creates a closure over the expression, which is basically a struct with a
231-
field for each variable used in the expression (closed over), and call overloaded.
232-
If this would be equal or more work than actually evaluating the expression then don't do
233-
it. An example would be if the expression itself is just wrapping something in a struct.
234-
Such as `Adjoint(x)` or `Diagonal(x)`. Or if the expression is a constant, or is
235-
itself a `Thunk`.
236-
If you got the expression from another `rrule` (or `frule`), you don't need to
237-
`@thunk` it since it will have been thunked if required, by the defining rule.
229+
`@thunk` creates a closure over the expression, which (effectively) creates a `struct`
230+
with a field for each variable used in the expression, and call overloaded.
231+
232+
Do not use `@thunk` if this would be equal or more work than actually evaluating the expression itself. Examples being:
233+
- The expression wrapping something in a `struct`, such as `Adjoint(x)` or `Diagonal(x)`
234+
- The expression being a constant
235+
- The expression being itself a `thunk`
236+
- The expression being from another `rrule` or `frule` (it would be `@thunk`ed if required by the defining rule already)
238237
"""
239238
struct Thunk{F} <: AbstractThunk
240239
f::F

0 commit comments

Comments
 (0)