Skip to content

Commit

Permalink
improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
oxinabox committed Jan 25, 2024
1 parent 34e54ca commit f9ade6e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/src/rule_author/superpowers/mutation_support.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ There are a few key points to follow:
- There must be a mutable tangent input for every mutated primal input
- When the primal value is changed, the corresponding change must be made to its tangent partner
- When a value is returned, return its partnered tangent.

- If two primals alias, then their tangents must also alias.

### Example
For example, consider the primal function with:
Expand All @@ -61,14 +61,14 @@ end

The frule for this would be:
```julia
function ChainRulesCore.frule((ȧ, ḃ), ::typeof(foo!), a::Base.RefValue, b::Base.RefValue)
function ChainRulesCore.frule((_, ȧ, ḃ), ::typeof(foo!), a::Base.RefValue, b::Base.RefValue)
@assertisa MutableTangent{typeof(a)}
@assertisa MutableTangent{typeof(b)}

a[] *= 2
.x *= 2 # `.x` is the field that lives behind RefValues

b[]=5.0
b[] = 5.0
.x = zero_tangent(5.0) # or since we know that the zero for a Float64 is zero could write `ḃ.x = 0.0`

return a, ȧ
Expand Down

0 comments on commit f9ade6e

Please sign in to comment.