Skip to content

Commit ef8905b

Browse files
authored
Merge pull request #633 from JuliaDiff/gd/nothing_warning
Add explanation of `nothing` errors
2 parents 02d455e + 4b98781 commit ef8905b

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

docs/src/FAQ.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ For example, in `fst(x, y) = x`, the derivative of `fst` with respect to `y` is
5858
For example, in `access(xs, n) = xs[n]`, the derivative of `access` with respect to `n` is `NoTangent()`.
5959
`access([10, 20, 30], 2) == 20`, but if we add `0.1` to `2` we get `access([10, 20, 30], 2.1)` which errors as indexing can't be applied at fractional indexes.
6060

61+
## Why do I get an error involving `nothing`?
62+
63+
When no custom `frule` or `rrule` exists, if you try to call one of those, it will return `nothing` by default.
64+
As a result, you may encounter errors like
65+
66+
```julia
67+
MethodError: no method matching iterate(::Nothing)
68+
```
69+
70+
Sometimes you think you have implemented the right rule, but it is called with a slightly different set of arguments than you expected.
71+
You can use [Cthulhu.jl](https://github.com/JuliaDebug/Cthulhu.jl) to dive into the call stack and figure out which method you are missing.
72+
73+
An alternative is to call back into AD: read the documentation on [rule configuration](@ref config) to know more.
6174

6275
## When to use ChainRules vs ChainRulesCore?
6376

0 commit comments

Comments
 (0)