Skip to content

Commit 2866f49

Browse files
committed
break up docs
1 parent fd6a675 commit 2866f49

5 files changed

Lines changed: 39 additions & 29 deletions

File tree

docs/make.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ makedocs(
1616
authors="Lyndon White and other contributors",
1717
pages=[
1818
"Introduction" => "index.md",
19+
"Examples of making AD systems" => [
20+
"Forward Mode" => "examples/forward_mode.md",
21+
"Reverse Mode" => "examples/reverse_mode.md",
22+
],
1923
"API" => "api.md",
2024
],
2125
strict=true,

docs/src/examples/forward_mode.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# ForwardDiffZero
2+
This is a fairly standard operator overloading-based forward mode AD system.
3+
It defines a `Dual` part which holds both the primal value, paired with the partial deriviative.
4+
It doesn't handle chunked-mode, or perturbation confusion.
5+
The overload generation hook in this example is: `define_dual_overload`.
6+
7+
````@eval
8+
using Markdown
9+
Markdown.parse("""
10+
```julia
11+
$(read(joinpath(@__DIR__,"../../../test/demos/forwarddiffzero.jl"), String))
12+
```
13+
""")
14+
````
15+

docs/src/examples/reverse_mode.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
# ReverseDiffZero
3+
This is a fairly standard operator overloading based reverse mode AD system.
4+
It defines a `Tracked` type which carries the primal value as well as a reference to the tape which is it using, a partially accumulated partial derivative and a `propagate` function that propagates it's partial back to its input.
5+
A perhaps unusual thing about it is how little it carries around it's creating operator's inputs.
6+
That information is all entirely wrapped up in the `propagate` function.
7+
The overload generation hook in this example is: `define_tracked_overload`.
8+
9+
````@eval
10+
using Markdown
11+
Markdown.parse("""
12+
```julia
13+
$(read(joinpath(@__DIR__,"../../../test/demos/reversediffzero.jl"), String))
14+
```
15+
""")
16+
````

docs/src/index.md

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,4 @@ When the rules are refreshed (automatically or manually), the hooks are only tri
5757
`clear_new_rule_hooks!`(@ref) clears all registered hooks.
5858
It is useful to undo [`on_new_rule`] hook registration if you are iteratively developing your overload generation function.
5959

60-
## Examples
61-
Here we define two fairly simplistic operator overloading based AD Systems to demonstrate how this is used.
6260

63-
### ForwardDiffZero
64-
The overload generation hook in this example is: `define_dual_overload`.
65-
66-
````@eval
67-
using Markdown
68-
Markdown.parse("""
69-
```julia
70-
$(read(joinpath(@__DIR__,"../../test/demos/forwarddiffzero.jl"), String))
71-
```
72-
""")
73-
````
74-
75-
### ReverseDiffZero
76-
The overload generation hook in this example is: `define_tracked_overload`.
77-
78-
````@eval
79-
using Markdown
80-
Markdown.parse("""
81-
```julia
82-
$(read(joinpath(@__DIR__,"../../test/demos/reversediffzero.jl"), String))
83-
```
84-
""")
85-
````

test/demos/reversediffzero.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct Tracked{F} <: Real
1919
propagate::F
2020
primal::Float64
2121
tape::Vector{Tracked} # a reference to a shared tape
22-
partial::Base.RefValue{Float64} # current accumulated sensitivity
22+
partial::Base.RefValue{Float64} # current accumulated sensitivity
2323
end
2424

2525
"An intermediate value, a Branch in Nabla terms."
@@ -29,15 +29,15 @@ function Tracked(propagate, primal, tape)
2929
return v
3030
end
3131

32-
"Marker for inputs (leaves) that don't need to propagate."
33-
struct NoPropagate end
34-
3532
"An input, a Leaf in Nabla terms. No inputs of its own to propagate to."
3633
function Tracked(primal, tape)
3734
# don't actually need to put these on the tape, since they don't need to propagate
3835
return Tracked(NoPropagate(), primal, tape, Ref(zero(primal)))
3936
end
4037

38+
"Marker for inputs (leaves) that don't need to propagate."
39+
struct NoPropagate end
40+
4141
primal(d::Tracked) = d.primal
4242
primal(d) = d
4343

0 commit comments

Comments
 (0)