Skip to content

Commit 71258ec

Browse files
authored
Update documentation formatting and infrastructure (#792)
* Update documentation steps in ci.yml - Give steps names - Use `shell:` option for cleaner command specificatiosn * Update syntax highlight tags in code blocks `julia` → `julia-repl` * Update code output in example block * Add LaTeX `align*` blocks to math formulae in how_it_works.md Make multi-line formulae appear as intended * Use `[sources]` section in docs/Project.toml to manage self-dep * Make simple docs step into one-line in ci.yml Signed-off-by: abhro <5664668+abhro@users.noreply.github.com> --------- Signed-off-by: abhro <5664668+abhro@users.noreply.github.com>
1 parent e1eb522 commit 71258ec

File tree

5 files changed

+47
-40
lines changed

5 files changed

+47
-40
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,16 @@ jobs:
6161
with:
6262
version: '1'
6363
- uses: julia-actions/cache@v2
64-
- run: |
65-
julia --project=docs -e '
66-
using Pkg
67-
Pkg.develop(PackageSpec(path=pwd()))
68-
Pkg.instantiate()'
69-
- run: |
70-
julia --project=docs -e '
71-
using Documenter: doctest
72-
using ForwardDiff
73-
doctest(ForwardDiff)'
74-
- run: julia --project=docs docs/make.jl
64+
- name: Set up environment
65+
run: julia --project=docs -e 'using Pkg; Pkg.instantiate()'
66+
- name: Run doctests
67+
shell: julia --project=docs {0}
68+
run: |
69+
using Documenter: doctest
70+
using ForwardDiff
71+
doctest(ForwardDiff)
72+
- name: Build and deploy documentation
73+
run: julia --project=docs docs/make.jl
7574
env:
7675
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7776
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}

docs/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
44

55
[compat]
66
Documenter = "1"
7+
8+
[sources]
9+
ForwardDiff = {path = ".."}

docs/src/dev/how_it_works.md

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,30 +97,35 @@ examine the case where the input vector size is 4 and the chunk size is 2. It th
9797
two calls to ``f`` to evaluate the gradient:
9898

9999
```math
100-
\vec{x} = \begin{bmatrix}
100+
\begin{align*}
101+
\vec{x} &= \begin{bmatrix}
101102
x_1 \\
102103
x_2 \\
103104
x_3 \\
104105
x_4
105106
\end{bmatrix}
106107
107-
\vec{x}_{\epsilon} = \begin{bmatrix}
108-
x_1 + \epsilon_1 \\
109-
x_2 + \epsilon_2 \\
110-
x_3 \\
111-
x_4
112-
\end{bmatrix}
108+
\\
109+
110+
\vec{x}_{\epsilon} &= \begin{bmatrix}
111+
x_1 + \epsilon_1 \\
112+
x_2 + \epsilon_2 \\
113+
x_3 \\
114+
x_4
115+
\end{bmatrix}
113116
\to
114117
f(\vec{x}_{\epsilon}) = f(\vec{x}) + \frac{\delta f(\vec{x})}{\delta x_1} \epsilon_1 + \frac{\delta f(\vec{x})}{\delta x_2} \epsilon_2
115-
116-
\vec{x}_{\epsilon} = \begin{bmatrix}
117-
x_1 \\
118-
x_2 \\
119-
x_3 + \epsilon_1 \\
120-
x_4 + \epsilon_2
121-
\end{bmatrix}
118+
\\
119+
120+
\vec{x}_{\epsilon} &= \begin{bmatrix}
121+
x_1 \\
122+
x_2 \\
123+
x_3 + \epsilon_1 \\
124+
x_4 + \epsilon_2
125+
\end{bmatrix}
122126
\to
123127
f(\vec{x}_{\epsilon}) = f(\vec{x}) + \frac{\delta f(\vec{x})}{\delta x_3} \epsilon_1 + \frac{\delta f(\vec{x})}{\delta x_4} \epsilon_2
128+
\end{align*}
124129
```
125130

126131
This seeding process is similar for Jacobians, so we won't rehash it here.

docs/src/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ While performance can vary depending on the functions you evaluate, the algorith
88

99
ForwardDiff is a registered Julia package, so it can be installed by running:
1010

11-
```julia
11+
```julia-repl
1212
julia> Pkg.add("ForwardDiff")
1313
```
1414

1515
Here's a simple example showing the package in action:
1616

17-
```julia
17+
```julia-repl
1818
julia> using ForwardDiff
1919
2020
julia> f(x::Vector) = sin(x[1]) + prod(x[2:end]); # returns a scalar
@@ -45,7 +45,7 @@ Functions like `f` which map a vector to a scalar are the best case for reverse-
4545
but ForwardDiff may still be a good choice if `x` is not too large, as it is much simpler.
4646
The best case for forward-mode differentiation is a function which maps a scalar to a vector, like this `g`:
4747

48-
```julia
48+
```julia-repl
4949
julia> g(y::Real) = [sin(y), cos(y), tan(y)]; # returns a vector
5050
5151
julia> ForwardDiff.derivative(g, pi/4)

docs/src/user/advanced.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ bandwidth.
2929

3030
For example:
3131

32-
```julia
32+
```julia-repl
3333
julia> using ForwardDiff: GradientConfig, Chunk, gradient!
3434
3535
# let's use a Rosenbrock function as our target function
@@ -75,7 +75,7 @@ julia> @time gradient!(out, rosenbrock, x, cfg10);
7575
If you do not explicitly provide a chunk size, ForwardDiff will try to guess one for you
7676
based on your input vector:
7777

78-
```julia
78+
```julia-repl
7979
# The GradientConfig constructor will automatically select a
8080
# chunk size in one is not explicitly provided
8181
julia> cfg = ForwardDiff.GradientConfig(rosenbrock, x);
@@ -125,7 +125,7 @@ usually the correct thing to do, but in some cases can erroneously "poison" valu
125125
aren't sensitive to the input and thus cause ForwardDiff to incorrectly return `NaN` or
126126
`Inf` derivatives. For example:
127127

128-
```julia
128+
```julia-repl
129129
# the dual number's perturbation component is zero, so this
130130
# variable should not propagate derivative information
131131
julia> log(ForwardDiff.Dual{:tag}(0.0, 0.0))
@@ -148,7 +148,7 @@ ForwardDiff's `NaN`-safe mode by using the
148148
[Preferences.jl](https://github.com/JuliaPackaging/Preferences.jl) API to set
149149
the `nansafe_mode` preference to true, for example via:
150150

151-
```julia
151+
```julia-repl
152152
julia> using ForwardDiff, Preferences
153153
154154
julia> set_preferences!(ForwardDiff, "nansafe_mode" => true)
@@ -159,7 +159,7 @@ this preference.
159159

160160
Alternatively, you can set the preference before loading ForwardDiff, for example via:
161161

162-
```julia
162+
```julia-repl
163163
julia> using Preferences, UUIDs
164164
165165
julia> set_preferences!(UUID("f6369f11-7733-5829-9624-2563aa707210"), "nansafe_mode" => true)
@@ -180,9 +180,9 @@ While ForwardDiff does not have a built-in function for taking Hessians of vecto
180180
functions, you can easily compose calls to `ForwardDiff.jacobian` to accomplish this.
181181
For example:
182182

183-
```julia
183+
```julia-repl
184184
julia> ForwardDiff.jacobian(x -> ForwardDiff.jacobian(cumprod, x), [1,2,3])
185-
9×3 Array{Int64,2}:
185+
9×3 Matrix{Int64}:
186186
0 0 0
187187
0 1 0
188188
0 3 2
@@ -200,12 +200,12 @@ example, if you require the shape of the output to be a tensor rather than a blo
200200
you can do so with a `reshape` (note that `reshape` does not copy data, so it's not an
201201
expensive operation):
202202

203-
```julia
203+
```julia-repl
204204
julia> function vector_hessian(f, x)
205-
n = length(x)
206-
out = ForwardDiff.jacobian(x -> ForwardDiff.jacobian(f, x), x)
207-
return reshape(out, n, n, n)
208-
end
205+
n = length(x)
206+
out = ForwardDiff.jacobian(x -> ForwardDiff.jacobian(f, x), x)
207+
return reshape(out, n, n, n)
208+
end
209209
vector_hessian (generic function with 1 method)
210210
211211
julia> vector_hessian(cumprod, [1, 2, 3])

0 commit comments

Comments
 (0)