Skip to content

Commit

Permalink
Merge pull request #640 from ablaom/docs-give-example-of-partial-self
Browse files Browse the repository at this point in the history
Add illustration of `∂self` in the maths/propagators section
  • Loading branch information
oxinabox authored Dec 8, 2023
2 parents 26b7748 + b4664d0 commit cb1aa6b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/src/maths/propagators.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,25 @@ 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{Multiplier}(; x = Δproduct * y')
∂y = m.x' * Δproduct
return ∂self, ∂y
end
return product, pullback
end
```

### Pushforward / Pullback summary

Expand Down

0 comments on commit cb1aa6b

Please sign in to comment.