Skip to content

Commit ff841bb

Browse files
Merge pull request #205 from abhro/update-docs
Update documentation infrastructure and minor formatting
2 parents 9d2d9a7 + 7af1dd6 commit ff841bb

File tree

10 files changed

+134
-130
lines changed

10 files changed

+134
-130
lines changed

docs/Project.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
33
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
44

55
[compat]
6-
Documenter = "0.27"
6+
Documenter = "1"
7+
8+
[sources]
9+
FiniteDiff = {path = ".."}

docs/make.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ open(joinpath(@__DIR__, "src", "index.md"), "w") do io
2323
for line in eachline(joinpath(dirname(@__DIR__), "README.md"))
2424
println(io, line)
2525
end
26-
26+
2727
for line in eachline(joinpath(@__DIR__, "src", "reproducibility.md"))
2828
println(io, line)
2929
end
@@ -38,6 +38,7 @@ makedocs(sitename="FiniteDiff.jl",
3838
doctest=false,
3939
format=Documenter.HTML(assets=["assets/favicon.ico"],
4040
canonical="https://docs.sciml.ai/FiniteDiff/stable/"),
41+
warnonly=[:missing_docs],
4142
pages=pages)
4243

4344
deploydocs(repo="github.com/JuliaDiff/FiniteDiff.jl.git"; push_preview=true)

docs/src/assets/Project.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
33
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
44

55
[compat]
6-
Documenter = "0.27"
6+
Documenter = "1"
7+
8+
[sources]
9+
FiniteDiff = {path = ".."}

docs/src/reproducibility.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,22 @@ You can also download the
3535
<a href="
3636
```
3737
```@eval
38-
using TOML
38+
using TOML, Markdown
3939
version = TOML.parse(read("../../Project.toml",String))["version"]
4040
name = TOML.parse(read("../../Project.toml",String))["name"]
4141
link = "https://github.com/SciML/"*name*".jl/tree/gh-pages/v"*version*"/assets/Manifest.toml"
42+
Markdown.MD(link)
4243
```
4344
```@raw html
4445
">manifest</a> file and the
4546
<a href="
4647
```
4748
```@eval
48-
using TOML
49+
using TOML, Markdown
4950
version = TOML.parse(read("../../Project.toml",String))["version"]
5051
name = TOML.parse(read("../../Project.toml",String))["name"]
5152
link = "https://github.com/SciML/"*name*".jl/tree/gh-pages/v"*version*"/assets/Project.toml"
53+
Markdown.MD(link)
5254
```
5355
```@raw html
5456
">project</a> file.

docs/src/tutorials.md

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ using FiniteDiff, StaticArrays
1010

1111
fcalls = 0
1212
function f(dx,x) # in-place
13-
global fcalls += 1
14-
for i in 2:length(x)-1
15-
dx[i] = x[i-1] - 2x[i] + x[i+1]
16-
end
17-
dx[1] = -2x[1] + x[2]
18-
dx[end] = x[end-1] - 2x[end]
19-
nothing
13+
global fcalls += 1
14+
for i in 2:length(x)-1
15+
dx[i] = x[i-1] - 2x[i] + x[i+1]
16+
end
17+
dx[1] = -2x[1] + x[2]
18+
dx[end] = x[end-1] - 2x[end]
19+
nothing
2020
end
2121

2222
const N = 10
2323
handleleft(x,i) = i==1 ? zero(eltype(x)) : x[i-1]
2424
handleright(x,i) = i==length(x) ? zero(eltype(x)) : x[i+1]
2525
function g(x) # out-of-place
26-
global fcalls += 1
27-
@SVector [handleleft(x,i) - 2x[i] + handleright(x,i) for i in 1:N]
26+
global fcalls += 1
27+
@SVector [handleleft(x,i) - 2x[i] + handleright(x,i) for i in 1:N]
2828
end
2929
```
3030

@@ -37,7 +37,7 @@ x = @SVector rand(N)
3737
FiniteDiff.finite_difference_jacobian(g,x)
3838

3939
#=
40-
10×10 SArray{Tuple{10,10},Float64,2,100} with indices SOneTo(10)×SOneTo(10):
40+
10×10 SMatrix{10, 10, Float64, 100} with indices SOneTo(10)×SOneTo(10):
4141
-2.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
4242
1.0 -2.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
4343
0.0 1.0 -2.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0
@@ -65,7 +65,7 @@ FiniteDiff.finite_difference_jacobian!(output,f,x)
6565
output
6666

6767
#=
68-
10×10 Array{Float64,2}:
68+
10×10 Matrix{Float64}:
6969
-2.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
7070
1.0 -2.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
7171
0.0 1.0 -2.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0
@@ -175,8 +175,8 @@ we get the analytical solution to the optimal matrix colors for our structured
175175
Jacobian. Now we can use this in our differencing routines:
176176

177177
```julia
178-
tridiagcache = FiniteDiff.JacobianCache(x,colorvec=colors,sparsity=tridiagjac)
179-
FiniteDiff.finite_difference_jacobian!(tridiagjac,f,x,tridiagcache)
178+
tridiagcache = FiniteDiff.JacobianCache(x, colorvec=colors, sparsity=tridiagjac)
179+
FiniteDiff.finite_difference_jacobian!(tridiagjac, f, x, tridiagcache)
180180
```
181181

182182
It'll use a special iteration scheme dependent on the matrix type to accelerate
@@ -189,14 +189,16 @@ differential equations, with a function like:
189189

190190
```julia
191191
function pde(out, x)
192-
x = reshape(x, 100, 100)
193-
out = reshape(out, 100, 100)
194-
for i in 1:100
195-
for j in 1:100
196-
out[i, j] = x[i, j] + x[max(i -1, 1), j] + x[min(i+1, size(x, 1)), j] + x[i, max(j-1, 1)] + x[i, min(j+1, size(x, 2))]
197-
end
198-
end
199-
return vec(out)
192+
x = reshape(x, 100, 100)
193+
out = reshape(out, 100, 100)
194+
m = size(x, 1)
195+
n = size(x, 2)
196+
for i in 1:100
197+
for j in 1:100
198+
out[i, j] = x[i, j] + x[max(i-1, 1), j] + x[min(i+1, m), j] + x[i, max(j-1, 1)] + x[i, min(j+1, n)]
199+
end
200+
end
201+
return vec(out)
200202
end
201203
x = rand(10000)
202204
```
@@ -212,4 +214,4 @@ bbbcache = FiniteDiff.JacobianCache(x,colorvec=colorsbbb,sparsity=Jbbb)
212214
FiniteDiff.finite_difference_jacobian!(Jbbb, pde, x, bbbcache)
213215
```
214216

215-
And boom, a fast Jacobian filling algorithm on your special matrix.
217+
And boom, a fast Jacobian filling algorithm on your special matrix.

src/derivatives.jl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""
22
FiniteDiff.finite_difference_derivative(
3-
f, x::T,
4-
fdtype::Type{T1}=Val{:central},
5-
returntype::Type{T2}=eltype(x),
6-
f_x::Union{Nothing,T}=nothing)
3+
f,
4+
x :: T,
5+
fdtype :: Type{T1} = Val{:central},
6+
returntype :: Type{T2} = eltype(x),
7+
f_x :: Union{Nothing,T} = nothing)
78
89
Single-point derivative of scalar->scalar maps.
910
"""
@@ -43,7 +44,7 @@ end
4344
FiniteDiff.DerivativeCache(
4445
x :: AbstractArray{<:Number},
4546
fx :: Union{Nothing,AbstractArray{<:Number}} = nothing,
46-
epsilon :: Union{Nothing,AbstractArray{<:Real}} = nothing,
47+
epsilon :: Union{Nothing,AbstractArray{<:Real}} = nothing,
4748
fdtype :: Type{T1} = Val{:central},
4849
returntype :: Type{T2} = eltype(x))
4950
@@ -146,14 +147,14 @@ end
146147

147148
"""
148149
FiniteDiff.finite_difference_derivative!(
149-
df::AbstractArray{<:Number},
150+
df :: AbstractArray{<:Number},
150151
f,
151-
x::AbstractArray{<:Number},
152-
cache::DerivativeCache{T1,T2,fdtype,returntype};
153-
relstep=default_relstep(fdtype, eltype(x)),
154-
absstep=relstep,
155-
dir=true)
156-
152+
x :: AbstractArray{<:Number},
153+
cache :: DerivativeCache{T1,T2,fdtype,returntype};
154+
relstep = default_relstep(fdtype, eltype(x)),
155+
absstep = relstep,
156+
dir = true)
157+
157158
Compute the derivative `df` of a scalar-valued map `f` at a collection of points `x`.
158159
159160
Cached.

src/gradients.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Non-Allocating Cache Constructor
8585
# Output
8686
The output is a [`GradientCache`](@ref) struct.
8787
88-
```julia
88+
```julia-repl
8989
julia> x = [1.0, 3.0]
9090
2-element Vector{Float64}:
9191
1.0
@@ -116,12 +116,12 @@ end
116116
FiniteDiff.finite_difference_gradient(
117117
f,
118118
x,
119-
fdtype::Type{T1}=Val{:central},
120-
returntype::Type{T2}=eltype(x),
121-
inplace::Type{Val{T3}}=Val{true};
122-
relstep=default_relstep(fdtype, eltype(x)),
123-
absstep=relstep,
124-
dir=true)
119+
fdtype :: Type{T1} = Val{:central},
120+
returntype :: Type{T2} = eltype(x),
121+
inplace :: Type{Val{T3}} = Val{true};
122+
relstep = default_relstep(fdtype, eltype(x)),
123+
absstep = relstep,
124+
dir = true)
125125
126126
Compute the gradient of function `f` at point `x` using finite differences.
127127
@@ -235,13 +235,13 @@ end
235235

236236
"""
237237
FiniteDiff.finite_difference_gradient!(
238-
df::AbstractArray{<:Number},
238+
df :: AbstractArray{<:Number},
239239
f,
240-
x::AbstractArray{<:Number},
241-
cache::GradientCache;
242-
relstep=default_relstep(fdtype, eltype(x)),
243-
absstep=relstep
244-
dir=true)
240+
x :: AbstractArray{<:Number},
241+
cache :: GradientCache;
242+
relstep = default_relstep(fdtype, eltype(x)),
243+
absstep = relstep
244+
dir = true)
245245
246246
Gradients are either a vector->scalar map `f(x)`, or a scalar->vector map `f(fx,x)` if `inplace=Val{true}` and `fx=f(x)` if `inplace=Val{false}`.
247247

src/hessians.jl

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,9 @@ end
5858

5959
"""
6060
HessianCache(
61-
xpp,
62-
xpm,
63-
xmp,
64-
xmm,
65-
fdtype::Type{T1}=Val{:hcentral},
66-
inplace::Type{Val{T2}} = x isa StaticArray ? Val{true} : Val{false})
61+
xpp, xpm, xmp, xmm,
62+
fdtype :: Type{T1} = Val{:hcentral},
63+
inplace :: Type{Val{T2}} = x isa StaticArray ? Val{true} : Val{false})
6764
6865
Non-allocating cache constructor.
6966
"""
@@ -78,8 +75,8 @@ end
7875
"""
7976
HessianCache(
8077
x,
81-
fdtype::Type{T1}=Val{:hcentral},
82-
inplace::Type{Val{T2}} = x isa StaticArray ? Val{true} : Val{false})
78+
fdtype :: Type{T1} = Val{:hcentral},
79+
inplace :: Type{Val{T2}} = x isa StaticArray ? Val{true} : Val{false})
8380
8481
Allocating cache constructor.
8582
"""
@@ -94,11 +91,11 @@ end
9491
"""
9592
finite_difference_hessian(
9693
f,
97-
x::AbstractArray{<:Number},
98-
fdtype::Type{T1}=Val{:hcentral},
99-
inplace::Type{Val{T2}} = x isa StaticArray ? Val{true} : Val{false};
100-
relstep=default_relstep(fdtype, eltype(x)),
101-
absstep=relstep)
94+
x :: AbstractArray{<:Number},
95+
fdtype :: Type{T1} = Val{:hcentral},
96+
inplace :: Type{Val{T2}} = x isa StaticArray ? Val{true} : Val{false};
97+
relstep = default_relstep(fdtype, eltype(x)),
98+
absstep = relstep)
10299
103100
Compute the Hessian matrix of scalar function `f` at point `x` using finite differences.
104101
@@ -171,13 +168,13 @@ end
171168

172169
"""
173170
finite_difference_hessian!(
174-
H::AbstractMatrix,
171+
H :: AbstractMatrix,
175172
f,
176-
x::AbstractArray{<:Number},
177-
fdtype :: Type{T1}=Val{:hcentral},
173+
x :: AbstractArray{<:Number},
174+
fdtype :: Type{T1} = Val{:hcentral},
178175
inplace :: Type{Val{T2}} = x isa StaticArray ? Val{true} : Val{false};
179-
relstep=default_relstep(fdtype, eltype(x)),
180-
absstep=relstep)
176+
relstep = default_relstep(fdtype, eltype(x)),
177+
absstep = relstep)
181178
182179
Cache-less.
183180
"""

0 commit comments

Comments
 (0)