You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/writing_good_rules.md
+80Lines changed: 80 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -229,6 +229,86 @@ Note that the function does not have to be $\mathbb{R} \rightarrow \mathbb{R}$.
229
229
In fact, any number of scalar arguments is supported, as is returning a tuple of scalars.
230
230
231
231
See docstrings for the comprehensive usage instructions.
232
+
233
+
234
+
### Be careful about pullbacks closures calling other methods of themselves
235
+
236
+
Due to [JuliaLang/Julia#40990](https://github.com/JuliaLang/julia/issues/40990), a closure calling another (or the same) method of itself often comes out uninferable (and thus effectively type-unstable).
237
+
This can be avoided by moving the pullback outside the function.
238
+
For example:
239
+
240
+
```julia
241
+
double_it(x::AbstractArray) =2.* x
242
+
243
+
function ChainRulesCore.rrule(::typeof(double_it), x)
This can be solved by moving the pullbacks outside the function so they are not closures, and thus to not run into this upstream issue.
274
+
In this case that is fairly simple, since this example doesn't close over anything (if it did then would need a closure calling an outside function that calls itself).
0 commit comments