Skip to content

Commit

Permalink
add illustration of ∂self in the maths/propagators section
Browse files Browse the repository at this point in the history
  • Loading branch information
ablaom committed Dec 5, 2023
1 parent 26b7748 commit b72df42
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/src/maths/propagators.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,24 @@ So every `pushforward` takes in an extra argument, which is ignored unless the o
It is common to write `function foo_pushforward(_, Δargs...)` in the case when `foo` does not have fields.
Similarly every `pullback` returns an extra `∂self`, which for things without fields is `NoTangent()`, indicating there are no fields within the function itself.

Here's an example showing how to define `∂self` in an `rrule` when the primal function has
internal fields (implicit arguments):

```julia
struct Multiplier{T}
x::T
end
(m::Multiplier)(y) = m.x * y

function ChainRulesCore.rrule(m::Multiplier, y)
product = m(y)
function pullback(Δproduct)
∂self = Tangent{typeof(m)}(; x = Δproduct * y')
∂y = m.x' * Δproduct
return ∂self, ∂y
return product, pullback
end
```

### Pushforward / Pullback summary

Expand Down

0 comments on commit b72df42

Please sign in to comment.