Skip to content

Commit d794c2c

Browse files
committed
Use lower functions for extrapolation
1 parent 437284f commit d794c2c

File tree

3 files changed

+35
-20
lines changed

3 files changed

+35
-20
lines changed

src/derivatives.jl

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,28 @@ function _extrapolate_derivative_left(A, t, order)
2020
elseif extrapolation_left == ExtrapolationType.Constant
2121
zero(first(A.u) / one(A.t[1]))
2222
elseif extrapolation_left == ExtrapolationType.Linear
23-
(order == 1) ? derivative(A, first(A.t)) : zero(first(A.u) / one(A.t[1]))
23+
_derivative(A, first(A.t), 1)
24+
zero(first(A.u) / one(A.t[1]))
25+
(order == 1) ? _derivative(A, first(A.t), 1) : zero(first(A.u) / one(A.t[1]))
2426
elseif extrapolation_left == ExtrapolationType.Extension
25-
iguess = A.iguesser
26-
(order == 1) ? _derivative(A, t, iguess) :
27+
(order == 1) ? _derivative(A, t, length(A.t)) :
2728
ForwardDiff.derivative(t -> begin
28-
_derivative(A, t, iguess)
29+
_derivative(A, t, length(A.t))
2930
end, t)
3031
elseif extrapolation_left == ExtrapolationType.Periodic
3132
t_, _ = transformation_periodic(A, t)
32-
derivative(A, t_, order)
33+
(order == 1) ? _derivative(A, t_, A.iguesser) :
34+
ForwardDiff.derivative(t -> begin
35+
_derivative(A, t, A.iguesser)
36+
end, t_)
3337
else
3438
# extrapolation_left == ExtrapolationType.Reflective
3539
t_, n = transformation_reflective(A, t)
36-
isodd(n) ? -derivative(A, t_, order) : derivative(A, t_, order)
40+
sign = isodd(n) ? -1 : 1
41+
(order == 1) ? sign * _derivative(A, t_, A.iguesser) :
42+
ForwardDiff.derivative(t -> begin
43+
sign * _derivative(A, t, A.iguesser)
44+
end, t_)
3745
end
3846
end
3947

@@ -44,20 +52,27 @@ function _extrapolate_derivative_right(A, t, order)
4452
elseif extrapolation_right == ExtrapolationType.Constant
4553
zero(first(A.u) / one(A.t[1]))
4654
elseif extrapolation_right == ExtrapolationType.Linear
47-
(order == 1) ? derivative(A, last(A.t)) : zero(first(A.u) / one(A.t[1]))
55+
(order == 1) ? _derivative(A, last(A.t), length(A.t)) :
56+
zero(first(A.u) / one(A.t[1]))
4857
elseif extrapolation_right == ExtrapolationType.Extension
49-
iguess = A.iguesser
50-
(order == 1) ? _derivative(A, t, iguess) :
58+
(order == 1) ? _derivative(A, t, length(A.t)) :
5159
ForwardDiff.derivative(t -> begin
52-
_derivative(A, t, iguess)
60+
_derivative(A, t, length(A.t))
5361
end, t)
5462
elseif extrapolation_right == ExtrapolationType.Periodic
5563
t_, _ = transformation_periodic(A, t)
56-
derivative(A, t_, order)
64+
(order == 1) ? _derivative(A, t_, A.iguesser) :
65+
ForwardDiff.derivative(t -> begin
66+
_derivative(A, t, A.iguesser)
67+
end, t_)
5768
else
58-
# extrapolation_right == ExtrapolationType.Reflective
69+
# extrapolation_left == ExtrapolationType.Reflective
5970
t_, n = transformation_reflective(A, t)
60-
iseven(n) ? -derivative(A, t_, order) : derivative(A, t_, order)
71+
sign = iseven(n) ? -1 : 1
72+
(order == 1) ? sign * _derivative(A, t_, A.iguesser) :
73+
ForwardDiff.derivative(t -> begin
74+
sign * _derivative(A, t, A.iguesser)
75+
end, t_)
6176
end
6277
end
6378

src/integral_inverses.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ Creates the inverted integral interpolation object from the given interpolation.
1313
1414
- `A`: interpolation object satisfying the above requirements
1515
"""
16-
invert_integral(A::AbstractInterpolation) = throw(IntegralInverseNotFoundError())
16+
invert_integral(::AbstractInterpolation) = throw(IntegralInverseNotFoundError())
1717

18-
_integral(A::AbstractIntegralInverseInterpolation, idx, t) = throw(IntegralNotFoundError())
18+
_integral(::AbstractIntegralInverseInterpolation, idx, t) = throw(IntegralNotFoundError())
1919

2020
function _derivative(A::AbstractIntegralInverseInterpolation, t::Number, iguess)
21-
inv(A.itp(A(t)))
21+
inv(A.itp(_interpolate(A, t, iguess)))
2222
end
2323

2424
"""

src/interpolation_methods.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ function _extrapolate_left(A, t)
1313
if extrapolation_left == ExtrapolationType.None
1414
throw(LeftExtrapolationError())
1515
elseif extrapolation_left == ExtrapolationType.Constant
16-
slope = derivative(A, first(A.t))
16+
slope = _derivative(A, first(A.t), 1)
1717
first(A.u) + zero(slope * t)
1818
elseif extrapolation_left == ExtrapolationType.Linear
19-
slope = derivative(A, first(A.t))
19+
slope = _derivative(A, first(A.t), 1)
2020
first(A.u) + slope * (t - first(A.t))
2121
else
2222
_extrapolate_other(A, t, extrapolation_left)
@@ -28,10 +28,10 @@ function _extrapolate_right(A, t)
2828
if extrapolation_right == ExtrapolationType.None
2929
throw(RightExtrapolationError())
3030
elseif extrapolation_right == ExtrapolationType.Constant
31-
slope = derivative(A, last(A.t))
31+
slope = _derivative(A, last(A.t), length(A.t))
3232
last(A.u) + zero(slope * t)
3333
elseif extrapolation_right == ExtrapolationType.Linear
34-
slope = derivative(A, last(A.t))
34+
slope = _derivative(A, last(A.t), length(A.t))
3535
last(A.u) + slope * (t - last(A.t))
3636
else
3737
_extrapolate_other(A, t, extrapolation_right)

0 commit comments

Comments
 (0)