Skip to content

Commit 17a83d4

Browse files
authored
Merge pull request #652 from sathvikbhagavan/sb/docs
docs: align a few misaligned code blocks
2 parents 83366a5 + 388315c commit 17a83d4

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

docs/src/rule_author/example.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,36 +58,36 @@ Read more about writing rules for constructors and callable objects [here](@ref
5858
The `rrule` returns the primal result `y`, and the pullback function.
5959
It is a _very_ good idea to name your pullback function, so that they are helpful when appearing in the stacktrace.
6060
```julia
61-
y = foo_mul(foo, b)
61+
y = foo_mul(foo, b)
6262
```
6363
Computes the primal result.
6464
It is possible to change the primal computation so that work can be shared between the primal and the pullback.
6565
See e.g. [the rule for `sort`](https://github.com/JuliaDiff/ChainRules.jl/blob/a75193768775975fac5578c89d1e5f50d7f358c2/src/rulesets/Base/sort.jl#L19-L35), where the sorting is done only once.
6666
```julia
67-
function foo_mul_pullback(ȳ)
68-
...
69-
return f̄, f̄oo, b̄
70-
end
67+
function foo_mul_pullback(ȳ)
68+
...
69+
return f̄, f̄oo, b̄
70+
end
7171
```
7272
The pullback function takes in the tangent of the primal output (``) and returns the tangents of the primal inputs.
7373
Note that it returns a tangent for the primal function in addition to the tangents of primal arguments.
7474

7575
Finally, computing the tangents of primal inputs:
7676
```julia
77-
= NoTangent()
77+
= NoTangent()
7878
```
7979
The function `foo_mul` has no fields (i.e. it is not a closure) and can not be perturbed.
8080
Therefore its tangent (``) is a `NoTangent`.
8181
```julia
82-
f̄oo = Tangent{Foo}(; A=* b', c=ZeroTangent())
82+
f̄oo = Tangent{Foo}(; A=* b', c=ZeroTangent())
8383
```
8484
The struct `foo::Foo` gets a `Tangent{Foo}` structural tangent, which stores the tangents of fields of `foo`.
8585

8686
The tangent of the field `A` is `ȳ * b'`,
8787

8888
The tangent of the field `c` is `ZeroTangent()`, because `c` can be perturbed but has no effect on the primal output.
8989
```julia
90-
= @thunk(foo.A' * ȳ)
90+
= @thunk(foo.A' * ȳ)
9191
```
9292
The tangent of `b` is `foo.A' * ȳ`, but we have wrapped it into a `Thunk`, a tangent type that represents delayed computation.
9393
The idea is that in case the tangent is not used anywhere, the computation never happens.

0 commit comments

Comments
 (0)