Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make constant interpolation dimensionally consistent #381

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 7 additions & 7 deletions src/derivatives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ function _extrapolate_derivative_left(A, t, order)
if extrapolation_left == ExtrapolationType.None
throw(LeftExtrapolationError())
elseif extrapolation_left == ExtrapolationType.Constant
zero(first(A.u) / one(A.t[1]))
zero(first(A.u) /t)
elseif extrapolation_left == ExtrapolationType.Linear
(order == 1) ? derivative(A, first(A.t)) : zero(first(A.u) / one(A.t[1]))
(order == 1) ? derivative(A, first(A.t)) : zero(first(A.u) / t^2)
elseif extrapolation_left == ExtrapolationType.Extension
iguess = A.iguesser
(order == 1) ? _derivative(A, t, iguess) :
Expand All @@ -42,9 +42,9 @@ function _extrapolate_derivative_right(A, t, order)
if extrapolation_right == ExtrapolationType.None
throw(RightExtrapolationError())
elseif extrapolation_right == ExtrapolationType.Constant
zero(first(A.u) / one(A.t[1]))
zero(first(A.u) / t)
elseif extrapolation_right == ExtrapolationType.Linear
(order == 1) ? derivative(A, last(A.t)) : zero(first(A.u) / one(A.t[1]))
(order == 1) ? derivative(A, last(A.t)) : zero(first(A.u) / t^2)
elseif extrapolation_right == ExtrapolationType.Extension
iguess = A.iguesser
(order == 1) ? _derivative(A, t, iguess) :
Expand Down Expand Up @@ -155,15 +155,15 @@ function _derivative(A::AkimaInterpolation{<:AbstractVector}, t::Number, iguess)
end

function _derivative(A::ConstantInterpolation, t::Number, iguess)
return zero(first(A.u))
return zero(first(A.u)/t)
end

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

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

# QuadraticSpline Interpolation
Expand Down
2 changes: 1 addition & 1 deletion src/interpolation_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -328,5 +328,5 @@ function transformation_reflective(A, t)
t_, n
end

typed_nan(::AbstractArray{T}) where {T <: AbstractFloat} = T(NaN)
typed_nan(::AbstractArray{T}) where {T <: Number} = T(NaN)
typed_nan(::AbstractArray{T}) where {T <: Integer} = zero(T)
Loading