Skip to content

Commit 7af1dd6

Browse files
committed
Update method signatures in docstrings
Use consistent spacing and alignment for type annotations and default values
1 parent fc614fd commit 7af1dd6

File tree

5 files changed

+95
-102
lines changed

5 files changed

+95
-102
lines changed

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: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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
"""

src/jacobians.jl

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ end
8181

8282
"""
8383
FiniteDiff.JacobianCache(
84-
x1 ,
85-
fx ,
84+
x1,
85+
fx,
8686
fx1,
8787
fdtype :: Type{T1} = Val{:central},
88-
returntype :: Type{T2} = eltype(fx),
88+
returntype :: Type{T2} = eltype(fx);
8989
colorvec = 1:length(x1),
9090
sparsity = nothing)
9191
@@ -189,16 +189,16 @@ end
189189
"""
190190
FiniteDiff.finite_difference_jacobian(
191191
f,
192-
x::AbstractArray{<:Number},
193-
fdtype::Type{T1}=Val{:forward},
194-
returntype::Type{T2}=eltype(x),
195-
f_in=nothing;
196-
relstep=default_relstep(fdtype, eltype(x)),
197-
absstep=relstep,
198-
colorvec=1:length(x),
199-
sparsity=nothing,
200-
jac_prototype=nothing,
201-
dir=true)
192+
x :: AbstractArray{<:Number},
193+
fdtype :: Type{T1} = Val{:forward},
194+
returntype :: Type{T2} = eltype(x),
195+
f_in = nothing;
196+
relstep = default_relstep(fdtype, eltype(x)),
197+
absstep = relstep,
198+
colorvec = 1:length(x),
199+
sparsity = nothing,
200+
jac_prototype = nothing,
201+
dir = true)
202202
203203
Compute the Jacobian matrix of function `f` at point `x` using finite differences.
204204
@@ -265,12 +265,12 @@ void_setindex!(args...) = (setindex!(args...); return)
265265
f,
266266
x,
267267
cache::JacobianCache;
268-
relstep=default_relstep(fdtype, eltype(x)),
269-
absstep=relstep,
270-
colorvec = cache.colorvec,
271-
sparsity = cache.sparsity,
268+
relstep = default_relstep(fdtype, eltype(x)),
269+
absstep = relstep,
270+
colorvec = cache.colorvec,
271+
sparsity = cache.sparsity,
272272
jac_prototype = nothing,
273-
dir=true)
273+
dir = true)
274274
275275
Cached.
276276
"""
@@ -421,14 +421,14 @@ end
421421

422422
"""
423423
finite_difference_jacobian!(
424-
J::AbstractMatrix,
424+
J :: AbstractMatrix,
425425
f,
426-
x::AbstractArray{<:Number},
427-
fdtype :: Type{T1}=Val{:forward},
428-
returntype :: Type{T2}=eltype(x),
426+
x :: AbstractArray{<:Number},
427+
fdtype :: Type{T1} = Val{:forward},
428+
returntype :: Type{T2} = eltype(x),
429429
f_in :: Union{T2,Nothing}=nothing;
430-
relstep=default_relstep(fdtype, eltype(x)),
431-
absstep=relstep,
430+
relstep = default_relstep(fdtype, eltype(x)),
431+
absstep = relstep,
432432
colorvec = 1:length(x),
433433
sparsity = ArrayInterfaceCore.has_sparsestruct(J) ? J : nothing)
434434
@@ -480,15 +480,15 @@ end
480480

481481
"""
482482
FiniteDiff.finite_difference_jacobian!(
483-
J::AbstractMatrix{<:Number},
483+
J :: AbstractMatrix{<:Number},
484484
f,
485-
x::AbstractArray{<:Number},
486-
cache::JacobianCache;
487-
relstep=default_relstep(fdtype, eltype(x)),
488-
absstep=relstep,
485+
x :: AbstractArray{<:Number},
486+
cache :: JacobianCache;
487+
relstep = default_relstep(fdtype, eltype(x)),
488+
absstep = relstep,
489489
colorvec = cache.colorvec,
490490
sparsity = cache.sparsity,
491-
dir=true)
491+
dir = true)
492492
493493
Cached.
494494
"""

src/jvp.jl

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ mutable struct JVPCache{X1, FX1, FDType}
1717
end
1818

1919
"""
20-
FiniteDiff.JVPCache(
21-
x,
22-
fdtype::Type{T1} = Val{:forward})
20+
FiniteDiff.JVPCache(x, fdtype::Type{T1} = Val{:forward})
2321
2422
Allocating cache constructor for Jacobian-vector product computations.
2523
@@ -47,10 +45,7 @@ function JVPCache(
4745
end
4846

4947
"""
50-
FiniteDiff.JVPCache(
51-
x,
52-
fx1,
53-
fdtype::Type{T1} = Val{:forward})
48+
FiniteDiff.JVPCache(x, fx1, fdtype::Type{T1} = Val{:forward})
5449
5550
Non-allocating cache constructor for Jacobian-vector product computations.
5651
@@ -87,12 +82,12 @@ end
8782
"""
8883
FiniteDiff.finite_difference_jvp(
8984
f,
90-
x::AbstractArray{<:Number},
91-
v::AbstractArray{<:Number},
92-
fdtype::Type{T1}=Val{:forward},
93-
f_in=nothing;
94-
relstep=default_relstep(fdtype, eltype(x)),
95-
absstep=relstep)
85+
x :: AbstractArray{<:Number},
86+
v :: AbstractArray{<:Number},
87+
fdtype :: Type{T1} = Val{:forward},
88+
f_in = nothing;
89+
relstep = default_relstep(fdtype, eltype(x)),
90+
absstep = relstep)
9691
9792
Compute the Jacobian-vector product `J(x) * v` using finite differences.
9893
@@ -156,8 +151,8 @@ end
156151
x,
157152
v,
158153
cache::JVPCache;
159-
relstep=default_relstep(fdtype, eltype(x)),
160-
absstep=relstep,
154+
relstep = default_relstep(fdtype, eltype(x)),
155+
absstep = relstep)
161156
162157
Cached.
163158
"""
@@ -195,15 +190,15 @@ end
195190

196191
"""
197192
finite_difference_jvp!(
198-
jvp::AbstractArray{<:Number},
193+
jvp :: AbstractArray{<:Number},
199194
f,
200-
x::AbstractArray{<:Number},
201-
v::AbstractArray{<:Number},
202-
fdtype :: Type{T1}=Val{:forward},
203-
returntype :: Type{T2}=eltype(x),
204-
f_in :: Union{T2,Nothing}=nothing;
205-
relstep=default_relstep(fdtype, eltype(x)),
206-
absstep=relstep)
195+
x :: AbstractArray{<:Number},
196+
v :: AbstractArray{<:Number},
197+
fdtype :: Type{T1} = Val{:forward},
198+
returntype :: Type{T2} = eltype(x),
199+
f_in :: Union{T2,Nothing} = nothing;
200+
relstep = default_relstep(fdtype, eltype(x)),
201+
absstep = relstep)
207202
208203
Cache-less.
209204
"""
@@ -229,14 +224,14 @@ end
229224

230225
"""
231226
FiniteDiff.finite_difference_jvp!(
232-
jvp::AbstractArray{<:Number},
227+
jvp :: AbstractArray{<:Number},
233228
f,
234-
x::AbstractArray{<:Number},
235-
v::AbstractArray{<:Number},
236-
cache::JVPCache;
237-
relstep=default_relstep(fdtype, eltype(x)),
238-
absstep=relstep,
239-
dir=true)
229+
x :: AbstractArray{<:Number},
230+
v :: AbstractArray{<:Number},
231+
cache :: JVPCache;
232+
relstep = default_relstep(fdtype, eltype(x)),
233+
absstep = relstep,
234+
dir = true)
240235
241236
Cached.
242237
"""

0 commit comments

Comments
 (0)