From dea437ff33f0bd357a09b3a5d73392741e05b7e4 Mon Sep 17 00:00:00 2001 From: Isaac Wheeler Date: Fri, 24 Jan 2025 16:26:48 +0100 Subject: [PATCH] Make constant interpolation dimensionally consistent --- src/derivatives.jl | 14 +++++++------- src/interpolation_utils.jl | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/derivatives.jl b/src/derivatives.jl index 271a8419..0787c3f6 100644 --- a/src/derivatives.jl +++ b/src/derivatives.jl @@ -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) : @@ -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) : @@ -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 diff --git a/src/interpolation_utils.jl b/src/interpolation_utils.jl index 37ca265c..5ef3b065 100644 --- a/src/interpolation_utils.jl +++ b/src/interpolation_utils.jl @@ -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)