Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add illustration of ∂self in the maths/propagators section #640

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading