Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/derivatives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ function _derivative(A::ConstantInterpolation, t::Number, iguess)
end

function _derivative(A::ConstantInterpolation{<:AbstractVector}, t::Number, iguess)
return isempty(searchsorted(A.t, t)) ? zero(A.u[1]) : eltype(A.u)(NaN)
return isempty(searchsorted(A.t, t)) ? zero(A.u[1]) : typed_nan(A.u)
end

function _derivative(A::ConstantInterpolation{<:AbstractMatrix}, t::Number, iguess)
return isempty(searchsorted(A.t, t)) ? zero(A.u[:, 1]) : eltype(A.u)(NaN) .* A.u[:, 1]
return isempty(searchsorted(A.t, t)) ? zero(A.u[:, 1]) : typed_nan(A.u) .* A.u[:, 1]
end

# QuadraticSpline Interpolation
Expand Down
4 changes: 2 additions & 2 deletions src/interpolation_methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function _extrapolate_left(A, t)
throw(LeftExtrapolationError())
elseif extrapolation_left == ExtrapolationType.Constant
slope = derivative(A, first(A.t))
first(A.u) + slope * zero(t)
first(A.u) + zero(slope * t)
elseif extrapolation_left == ExtrapolationType.Linear
slope = derivative(A, first(A.t))
first(A.u) + slope * (t - first(A.t))
Expand All @@ -36,7 +36,7 @@ function _extrapolate_right(A, t)
throw(RightExtrapolationError())
elseif extrapolation_right == ExtrapolationType.Constant
slope = derivative(A, last(A.t))
last(A.u) + slope * zero(t)
last(A.u) + zero(slope * t)
elseif extrapolation_right == ExtrapolationType.Linear
slope = derivative(A, last(A.t))
last(A.u) + slope * (t - last(A.t))
Expand Down
3 changes: 3 additions & 0 deletions src/interpolation_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,6 @@ function transformation_reflective(A, t)
(n > 0) && (n -= 1)
t_, n
end

typed_nan(::AbstractArray{T}) where {T <: AbstractFloat} = T(NaN)
typed_nan(::AbstractArray{T}) where {T <: Integer} = zero(T)
4 changes: 4 additions & 0 deletions test/interpolation_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,10 @@ end
A = ConstantInterpolation(u, t; extrapolation = ExtrapolationType.Extension)
@test A(Inf) == last(u)
@test A(-Inf) == first(u)

# Test extrapolation of integer output
itp = ConstantInterpolation([2], [0.0]; extrapolation = ExtrapolationType.Constant)
@test itp(1.0) == 2
end

@testset "QuadraticSpline Interpolation" begin
Expand Down
Loading