@@ -153,13 +153,13 @@ function FiniteDifferenceMethod(grid::AbstractVector{Int}, q::Int; kw_args...)
153
153
end
154
154
155
155
"""
156
- (m::FiniteDifferenceMethod)(f::Function , x::T) where T<:AbstractFloat
156
+ (m::FiniteDifferenceMethod)(f, x::T) where T<:AbstractFloat
157
157
158
158
Estimate the derivative of `f` at `x` using the finite differencing method `m` and an
159
159
automatically determined step size.
160
160
161
161
# Arguments
162
- - `f::Function `: Function to estimate derivative of.
162
+ - `f`: Function to estimate derivative of.
163
163
- `x::T`: Input to estimate derivative at.
164
164
165
165
# Returns
@@ -188,12 +188,12 @@ julia> FiniteDifferences.estimate_step(fdm, sin, 1.0) # Computes step size and
188
188
# We loop over all concrete subtypes of `FiniteDifferenceMethod` for Julia v1.0 compatibility.
189
189
for T in (UnadaptedFiniteDifferenceMethod, AdaptedFiniteDifferenceMethod)
190
190
@eval begin
191
- function (m:: $T )(f:: TF , x:: Real ) where TF<: Function
191
+ function (m:: $T )(f:: TF , x:: Real ) where TF
192
192
x = float (x) # Assume that converting to float is desired, if it isn't already.
193
193
step = first (estimate_step (m, f, x))
194
194
return m (f, x, step)
195
195
end
196
- function (m:: $T{P,0} )(f:: TF , x:: Real ) where {P,TF<: Function }
196
+ function (m:: $T{P,0} )(f:: TF , x:: Real ) where {P,TF}
197
197
# The automatic step size calculation fails if `Q == 0`, so handle that edge
198
198
# case.
199
199
return f (x)
@@ -202,13 +202,13 @@ for T in (UnadaptedFiniteDifferenceMethod, AdaptedFiniteDifferenceMethod)
202
202
end
203
203
204
204
"""
205
- (m::FiniteDifferenceMethod)(f::Function , x::T, step::Real) where T<:AbstractFloat
205
+ (m::FiniteDifferenceMethod)(f, x::T, step::Real) where T<:AbstractFloat
206
206
207
207
Estimate the derivative of `f` at `x` using the finite differencing method `m` and a given
208
208
step size.
209
209
210
210
# Arguments
211
- - `f::Function `: Function to estimate derivative of.
211
+ - `f`: Function to estimate derivative of.
212
212
- `x::T`: Input to estimate derivative at.
213
213
- `step::Real`: Step size.
214
214
@@ -235,7 +235,7 @@ julia> fdm(sin, 1, 1e-3) - cos(1) # Check the error.
235
235
# We loop over all concrete subtypes of `FiniteDifferenceMethod` for 1.0 compatibility.
236
236
for T in (UnadaptedFiniteDifferenceMethod, AdaptedFiniteDifferenceMethod)
237
237
@eval begin
238
- function (m:: $T{P,Q} )(f:: TF , x:: Real , step:: Real ) where {P,Q,TF<: Function }
238
+ function (m:: $T{P,Q} )(f:: TF , x:: Real , step:: Real ) where {P,Q,TF}
239
239
x = float (x) # Assume that converting to float is desired, if it isn't already.
240
240
fs = _eval_function (m, f, x, step)
241
241
return _compute_estimate (m, fs, x, step, m. coefs)
245
245
246
246
function _eval_function (
247
247
m:: FiniteDifferenceMethod , f:: TF , x:: T , step:: Real ,
248
- ) where {TF<: Function ,T<: AbstractFloat }
248
+ ) where {TF,T<: AbstractFloat }
249
249
return f .(x .+ T (step) .* m. grid)
250
250
end
251
251
336
336
"""
337
337
function estimate_step(
338
338
m::FiniteDifferenceMethod,
339
- f::Function ,
339
+ f,
340
340
x::T
341
341
) where T<:AbstractFloat
342
342
@@ -345,7 +345,7 @@ estimate of the derivative.
345
345
346
346
# Arguments
347
347
- `m::FiniteDifferenceMethod`: Finite difference method to estimate the step size for.
348
- - `f::Function `: Function to evaluate the derivative of.
348
+ - `f`: Function to evaluate the derivative of.
349
349
- `x::T`: Point to estimate the derivative at.
350
350
351
351
# Returns
@@ -355,13 +355,13 @@ estimate of the derivative.
355
355
"""
356
356
function estimate_step (
357
357
m:: UnadaptedFiniteDifferenceMethod , f:: TF , x:: T ,
358
- ) where {TF<: Function ,T<: AbstractFloat }
358
+ ) where {TF,T<: AbstractFloat }
359
359
step, acc = _compute_step_acc_default (m, x)
360
360
return _limit_step (m, x, step, acc)
361
361
end
362
362
function estimate_step (
363
363
m:: AdaptedFiniteDifferenceMethod{P,Q} , f:: TF , x:: T ,
364
- ) where {P,Q,TF<: Function ,T<: AbstractFloat }
364
+ ) where {P,Q,TF,T<: AbstractFloat }
365
365
∇f_magnitude, f_magnitude = _estimate_magnitudes (m. bound_estimator, f, x)
366
366
if ∇f_magnitude == 0.0 || f_magnitude == 0.0
367
367
step, acc = _compute_step_acc_default (m, x)
373
373
374
374
function _estimate_magnitudes (
375
375
m:: FiniteDifferenceMethod{P,Q} , f:: TF , x:: T ,
376
- ) where {P,Q,TF<: Function ,T<: AbstractFloat }
376
+ ) where {P,Q,TF,T<: AbstractFloat }
377
377
step = first (estimate_step (m, f, x))
378
378
fs = _eval_function (m, f, x, step)
379
379
# Estimate magnitude of `∇f` in a neighbourhood of `x`.
551
551
"""
552
552
extrapolate_fdm(
553
553
m::FiniteDifferenceMethod,
554
- f::Function ,
554
+ f,
555
555
x::Real,
556
556
initial_step::Real=10,
557
557
power::Int=1,
@@ -567,7 +567,7 @@ automatically sets `power = 2` if `m` is symmetric and `power = 1`. Moreover, it
567
567
568
568
# Arguments
569
569
- `m::FiniteDifferenceMethod`: Finite difference method to estimate the step size for.
570
- - `f::Function `: Function to evaluate the derivative of.
570
+ - `f`: Function to evaluate the derivative of.
571
571
- `x::Real`: Point to estimate the derivative at.
572
572
- `initial_step::Real=10`: Initial step size.
573
573
@@ -576,7 +576,7 @@ automatically sets `power = 2` if `m` is symmetric and `power = 1`. Moreover, it
576
576
"""
577
577
function extrapolate_fdm (
578
578
m:: FiniteDifferenceMethod ,
579
- f:: Function ,
579
+ f,
580
580
x:: Real ,
581
581
initial_step:: Real = 10 ;
582
582
power:: Int = 1 ,
0 commit comments