diff --git a/docs/src/extrapolation_methods.md b/docs/src/extrapolation_methods.md index 488746e8..7344b9fe 100644 --- a/docs/src/extrapolation_methods.md +++ b/docs/src/extrapolation_methods.md @@ -15,44 +15,44 @@ plot(A) Extrapolation behavior can be set left and right of the data simultaneously with the `extension` keyword, or left and right separately with the `extrapolation_left` and `extrapolation_right` keywords respectively. -## `ExtrapolationType.none` +## `ExtrapolationType.None` This extrapolation type will throw an error when the input `t` is beyond the data in the specified direction. -## `ExtrapolationType.constant` +## `ExtrapolationType.Constant` This extrapolation type extends the interpolation with the boundary values of the data `u`. ```@example tutorial -A = QuadraticSpline(u, t; extrapolation = ExtrapolationType.constant) +A = QuadraticSpline(u, t; extrapolation = ExtrapolationType.Constant) plot(A) plot!(t_eval_left, A.(t_eval_left); label = "extrapolation left") plot!(t_eval_right, A.(t_eval_right); label = "extrapolation right") ``` -## `ExtrapolationType.linear` +## `ExtrapolationType.Linear` This extrapolation type extends the interpolation with a linear continuation of the interpolation, making it $C^1$ smooth at the data boundaries. ```@example tutorial -A = QuadraticSpline(u, t; extrapolation = ExtrapolationType.linear) +A = QuadraticSpline(u, t; extrapolation = ExtrapolationType.Linear) plot(A) plot!(t_eval_left, A.(t_eval_left); label = "extrapolation left") plot!(t_eval_right, A.(t_eval_right); label = "extrapolation right") ``` -## `ExtrapolationType.extension` +## `ExtrapolationType.Extension` This extrapolation type extends the interpolation with a continuation of the expression for the interpolation at the boundary intervals for maximum smoothness. ```@example tutorial -A = QuadraticSpline(u, t; extrapolation = ExtrapolationType.extension) +A = QuadraticSpline(u, t; extrapolation = ExtrapolationType.Extension) plot(A) plot!(t_eval_left, A.(t_eval_left); label = "extrapolation down") plot!(t_eval_right, A.(t_eval_right); label = "extrapolation up") ``` -## `ExtrapolationType.periodic` +## `ExtrapolationType.Periodic` this extrapolation type extends the interpolation such that `A(t + T) == A(t)` for all `t`, where the period is given by `T = last(A.t) - first(A.t)`. @@ -60,18 +60,18 @@ this extrapolation type extends the interpolation such that `A(t + T) == A(t)` f T = last(A.t) - first(A.t) t_eval_left = range(first(t) - 2T, first(t), length = 100) t_eval_right = range(last(t), last(t) + 2T, length = 100) -A = QuadraticSpline(u, t; extrapolation = ExtrapolationType.periodic) +A = QuadraticSpline(u, t; extrapolation = ExtrapolationType.Periodic) plot(A) plot!(t_eval_left, A.(t_eval_left); label = "extrapolation down") plot!(t_eval_right, A.(t_eval_right); label = "extrapolation up") ``` -## `ExtrapolationType.reflective` +## `ExtrapolationType.Reflective` this extrapolation type extends the interpolation such that `A(t_ + t) == A(t_ - t)` for all `t_, t` such that `(t_ - first(A.t)) % T == 0` and `0 < t < T`, where `T = last(A.t) - first(A.t)`. ```@example tutorial -A = QuadraticSpline(u, t; extrapolation = ExtrapolationType.reflective) +A = QuadraticSpline(u, t; extrapolation = ExtrapolationType.Reflective) plot(A) plot!(t_eval_left, A.(t_eval_left); label = "extrapolation down") plot!(t_eval_right, A.(t_eval_right); label = "extrapolation up") @@ -82,8 +82,8 @@ plot!(t_eval_right, A.(t_eval_right); label = "extrapolation up") You can also have different extrapolation types left and right of the data. ```@example tutorial -A = QuadraticSpline(u, t; extrapolation_left = ExtrapolationType.reflective, - extrapolation_right = ExtrapolationType.periodic) +A = QuadraticSpline(u, t; extrapolation_left = ExtrapolationType.Reflective, + extrapolation_right = ExtrapolationType.Periodic) plot(A) plot!(t_eval_left, A.(t_eval_left); label = "extrapolation left") plot!(t_eval_right, A.(t_eval_right); label = "extrapolation right") diff --git a/docs/src/interface.md b/docs/src/interface.md index 21bfd27a..738287ee 100644 --- a/docs/src/interface.md +++ b/docs/src/interface.md @@ -17,7 +17,7 @@ t = [0.0, 62.25, 109.66, 162.66, 205.8, 252.3] All interpolation methods return an object from which we can compute the value of the dependent variable at any time point. -We will use the `CubicSpline` method for demonstration, but the API is the same for all the methods. We can also pass the `extrapolation = ExtrapolationType.extension` keyword if we want to allow the interpolation to go beyond the range of the timepoints in the positive `t` direction. The default value is `extrapolation = ExtrapolationType.none`. For more information on extrapolation see [Extrapolation methods](extrapolation_methods.md). +We will use the `CubicSpline` method for demonstration, but the API is the same for all the methods. We can also pass the `extrapolation = ExtrapolationType.Extension` keyword if we want to allow the interpolation to go beyond the range of the timepoints in the positive `t` direction. The default value is `extrapolation = ExtrapolationType.None`. For more information on extrapolation see [Extrapolation methods](extrapolation_methods.md). ```@example interface A1 = CubicSpline(u, t) @@ -25,7 +25,7 @@ A1 = CubicSpline(u, t) # For interpolation do, A(t) A1(100.0) -A2 = CubicSpline(u, t; extrapolation = ExtrapolationType.extension) +A2 = CubicSpline(u, t; extrapolation = ExtrapolationType.Extension) # Extrapolation A2(300.0) diff --git a/ext/DataInterpolationsRegularizationToolsExt.jl b/ext/DataInterpolationsRegularizationToolsExt.jl index 84693c49..cf0e1de3 100644 --- a/ext/DataInterpolationsRegularizationToolsExt.jl +++ b/ext/DataInterpolationsRegularizationToolsExt.jl @@ -70,8 +70,8 @@ A = RegularizationSmooth(u, t, t̂, wls, wr, d; λ = 1.0, alg = :gcv_svd) function RegularizationSmooth(u::AbstractVector, t::AbstractVector, t̂::AbstractVector, wls::AbstractVector, wr::AbstractVector, d::Int = 2; λ::Real = 1.0, alg::Symbol = :gcv_svd, - extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none) + extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None) u, t = munge_data(u, t) M = _mapping_matrix(t̂, t) Wls½ = LA.diagm(sqrt.(wls)) @@ -90,8 +90,8 @@ A = RegularizationSmooth(u, t, d; λ = 1.0, alg = :gcv_svd, extrapolate = false) """ function RegularizationSmooth(u::AbstractVector, t::AbstractVector, d::Int = 2; λ::Real = 1.0, - alg::Symbol = :gcv_svd, extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none) + alg::Symbol = :gcv_svd, extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None) u, t = munge_data(u, t) t̂ = t N = length(t) @@ -122,8 +122,8 @@ A = RegularizationSmooth(u, t, t̂, d; λ = 1.0, alg = :gcv_svd, extrapolate = f """ function RegularizationSmooth(u::AbstractVector, t::AbstractVector, t̂::AbstractVector, d::Int = 2; λ::Real = 1.0, alg::Symbol = :gcv_svd, - extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none) + extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None) u, t = munge_data(u, t) N, N̂ = length(t), length(t̂) M = _mapping_matrix(t̂, t) @@ -153,8 +153,8 @@ A = RegularizationSmooth(u, t, t̂, wls, d; λ = 1.0, alg = :gcv_svd, extrapolat """ function RegularizationSmooth(u::AbstractVector, t::AbstractVector, t̂::AbstractVector, wls::AbstractVector, d::Int = 2; λ::Real = 1.0, - alg::Symbol = :gcv_svd, extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none) + alg::Symbol = :gcv_svd, extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None) u, t = munge_data(u, t) N, N̂ = length(t), length(t̂) M = _mapping_matrix(t̂, t) @@ -185,8 +185,8 @@ A = RegularizationSmooth( """ function RegularizationSmooth(u::AbstractVector, t::AbstractVector, t̂::Nothing, wls::AbstractVector, d::Int = 2; λ::Real = 1.0, - alg::Symbol = :gcv_svd, extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none) + alg::Symbol = :gcv_svd, extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None) u, t = munge_data(u, t) t̂ = t N = length(t) @@ -219,8 +219,8 @@ A = RegularizationSmooth( function RegularizationSmooth(u::AbstractVector, t::AbstractVector, t̂::Nothing, wls::AbstractVector, wr::AbstractVector, d::Int = 2; λ::Real = 1.0, alg::Symbol = :gcv_svd, - extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none) + extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None) u, t = munge_data(u, t) t̂ = t N = length(t) @@ -252,8 +252,8 @@ A = RegularizationSmooth( """ function RegularizationSmooth(u::AbstractVector, t::AbstractVector, t̂::Nothing, wls::Symbol, d::Int = 2; λ::Real = 1.0, alg::Symbol = :gcv_svd, - extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none) + extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None) u, t = munge_data(u, t) t̂ = t N = length(t) diff --git a/src/DataInterpolations.jl b/src/DataInterpolations.jl index e04ad136..22dc7345 100644 --- a/src/DataInterpolations.jl +++ b/src/DataInterpolations.jl @@ -11,7 +11,7 @@ using EnumX import FindFirstFunctions: searchsortedfirstcorrelated, searchsortedlastcorrelated, Guesser -@enumx ExtrapolationType none constant linear extension periodic reflective +@enumx ExtrapolationType None Constant Linear Extension Periodic Reflective include("parameter_caches.jl") include("interpolation_caches.jl") @@ -64,13 +64,13 @@ function Base.showerror(io::IO, ::ExtrapolationError) print(io, EXTRAPOLATION_ERROR) end -const LEFT_EXTRAPOLATION_ERROR = "Cannot extrapolate for t < first(A.t) as the `extrapolation_left` kwarg passed was `ExtrapolationType.none`" +const LEFT_EXTRAPOLATION_ERROR = "Cannot extrapolate for t < first(A.t) as the `extrapolation_left` kwarg passed was `ExtrapolationType.None`" struct LeftExtrapolationError <: Exception end function Base.showerror(io::IO, ::LeftExtrapolationError) print(io, LEFT_EXTRAPOLATION_ERROR) end -const RIGHT_EXTRAPOLATION_ERROR = "Cannot extrapolate for t > last(A.t) as the `extrapolation_tight` kwarg passed was `ExtrapolationType.none`" +const RIGHT_EXTRAPOLATION_ERROR = "Cannot extrapolate for t > last(A.t) as the `extrapolation_tight` kwarg passed was `ExtrapolationType.None`" struct RightExtrapolationError <: Exception end function Base.showerror(io::IO, ::RightExtrapolationError) print(io, RIGHT_EXTRAPOLATION_ERROR) diff --git a/src/derivatives.jl b/src/derivatives.jl index 800077a3..a81ef368 100644 --- a/src/derivatives.jl +++ b/src/derivatives.jl @@ -15,23 +15,23 @@ end function _extrapolate_derivative_left(A, t, order) (; extrapolation_left) = A - if extrapolation_left == ExtrapolationType.none + if extrapolation_left == ExtrapolationType.None throw(LeftExtrapolationError()) - elseif extrapolation_left == ExtrapolationType.constant + elseif extrapolation_left == ExtrapolationType.Constant zero(first(A.u) / one(A.t[1])) - elseif extrapolation_left == ExtrapolationType.linear + elseif extrapolation_left == ExtrapolationType.Linear (order == 1) ? derivative(A, first(A.t)) : zero(first(A.u) / one(A.t[1])) - elseif extrapolation_left == ExtrapolationType.extension + elseif extrapolation_left == ExtrapolationType.Extension iguess = A.iguesser (order == 1) ? _derivative(A, t, iguess) : ForwardDiff.derivative(t -> begin _derivative(A, t, iguess) end, t) - elseif extrapolation_left == ExtrapolationType.periodic + elseif extrapolation_left == ExtrapolationType.Periodic t_, _ = transformation_periodic(A, t) derivative(A, t_, order) else - # extrapolation_left == ExtrapolationType.reflective + # extrapolation_left == ExtrapolationType.Reflective t_, n = transformation_reflective(A, t) isodd(n) ? -derivative(A, t_, order) : derivative(A, t_, order) end @@ -39,23 +39,23 @@ end function _extrapolate_derivative_right(A, t, order) (; extrapolation_right) = A - if extrapolation_right == ExtrapolationType.none + if extrapolation_right == ExtrapolationType.None throw(RightExtrapolationError()) - elseif extrapolation_right == ExtrapolationType.constant + elseif extrapolation_right == ExtrapolationType.Constant zero(first(A.u) / one(A.t[1])) - elseif extrapolation_right == ExtrapolationType.linear + elseif extrapolation_right == ExtrapolationType.Linear (order == 1) ? derivative(A, last(A.t)) : zero(first(A.u) / one(A.t[1])) - elseif extrapolation_right == ExtrapolationType.extension + elseif extrapolation_right == ExtrapolationType.Extension iguess = A.iguesser (order == 1) ? _derivative(A, t, iguess) : ForwardDiff.derivative(t -> begin _derivative(A, t, iguess) end, t) - elseif extrapolation_right == ExtrapolationType.periodic + elseif extrapolation_right == ExtrapolationType.Periodic t_, _ = transformation_periodic(A, t) derivative(A, t_, order) else - # extrapolation_right == ExtrapolationType.reflective + # extrapolation_right == ExtrapolationType.Reflective t_, n = transformation_reflective(A, t) iseven(n) ? -derivative(A, t_, order) : derivative(A, t_, order) end diff --git a/src/integrals.jl b/src/integrals.jl index baabc634..41e52e4a 100644 --- a/src/integrals.jl +++ b/src/integrals.jl @@ -67,17 +67,17 @@ end function _extrapolate_integral_left(A, t) (; extrapolation_left) = A - if extrapolation_left == ExtrapolationType.none + if extrapolation_left == ExtrapolationType.None throw(LeftExtrapolationError()) - elseif extrapolation_left == ExtrapolationType.constant + elseif extrapolation_left == ExtrapolationType.Constant first(A.u) * (first(A.t) - t) - elseif extrapolation_left == ExtrapolationType.linear + elseif extrapolation_left == ExtrapolationType.Linear slope = derivative(A, first(A.t)) Δt = first(A.t) - t (first(A.u) - slope * Δt / 2) * Δt - elseif extrapolation_left == ExtrapolationType.extension + elseif extrapolation_left == ExtrapolationType.Extension _integral(A, 1, t, first(A.t)) - elseif extrapolation_left == ExtrapolationType.periodic + elseif extrapolation_left == ExtrapolationType.Periodic t_, n = transformation_periodic(A, t) out = -integral(A, t_) if !iszero(n) @@ -85,7 +85,7 @@ function _extrapolate_integral_left(A, t) end out else - # extrapolation_left == ExtrapolationType.reflective + # extrapolation_left == ExtrapolationType.Reflective t_, n = transformation_reflective(A, t) out = if isodd(n) -integral(A, t_, last(A.t)) @@ -101,17 +101,17 @@ end function _extrapolate_integral_right(A, t) (; extrapolation_right) = A - if extrapolation_right == ExtrapolationType.none + if extrapolation_right == ExtrapolationType.None throw(RightExtrapolationError()) - elseif extrapolation_right == ExtrapolationType.constant + elseif extrapolation_right == ExtrapolationType.Constant last(A.u) * (t - last(A.t)) - elseif extrapolation_right == ExtrapolationType.linear + elseif extrapolation_right == ExtrapolationType.Linear slope = derivative(A, last(A.t)) Δt = t - last(A.t) (last(A.u) + slope * Δt / 2) * Δt - elseif extrapolation_right == ExtrapolationType.extension + elseif extrapolation_right == ExtrapolationType.Extension _integral(A, length(A.t) - 1, last(A.t), t) - elseif extrapolation_right == ExtrapolationType.periodic + elseif extrapolation_right == ExtrapolationType.Periodic t_, n = transformation_periodic(A, t) out = integral(A, first(A.t), t_) if !iszero(n) @@ -119,7 +119,7 @@ function _extrapolate_integral_right(A, t) end out else - # extrapolation_right == ExtrapolationType.reflective + # extrapolation_right == ExtrapolationType.Reflective t_, n = transformation_reflective(A, t) out = if iseven(n) integral(A, t_, last(A.t)) diff --git a/src/interpolation_caches.jl b/src/interpolation_caches.jl index faeec06a..ad2e1eb0 100644 --- a/src/interpolation_caches.jl +++ b/src/interpolation_caches.jl @@ -1,6 +1,6 @@ """ - LinearInterpolation(u, t; extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation::ExtrapolationType.T = ExtrapolationType.none, extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, + LinearInterpolation(u, t; extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation::ExtrapolationType.T = ExtrapolationType.None, extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false) It is the method of interpolating between the data points using a linear polynomial. For any point, two data points one each side are chosen and connected with a line. @@ -14,8 +14,8 @@ Extrapolation extends the last linear polynomial on each side. ## Keyword Arguments - `extrapolation`: The extrapolation type applied left and right of the data. Possible options - are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, - `ExtrapolationType.linear` and `ExtrapolationType.extension`. + are `ExtrapolationType.None` (default), `ExtrapolationType.Constant`, `ExtrapolationType.Linear` + `ExtrapolationType.Extension`, `ExtrapolationType.Periodic` and `ExtrapolationType.Reflective`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for @@ -48,9 +48,9 @@ struct LinearInterpolation{uType, tType, IType, pType, T, N} <: AbstractInterpol end function LinearInterpolation( - u, t; extrapolation::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, cache_parameters = false, assume_linear_t = 1e-2) + u, t; extrapolation::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false, assume_linear_t = 1e-2) extrapolation_left, extrapolation_right = munge_extrapolation( extrapolation, extrapolation_left, extrapolation_right) u, t = munge_data(u, t) @@ -65,8 +65,8 @@ function LinearInterpolation( end """ - QuadraticInterpolation(u, t, mode = :Forward; extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation::ExtrapolationType.T = ExtrapolationType.none, extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, + QuadraticInterpolation(u, t, mode = :Forward; extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation::ExtrapolationType.T = ExtrapolationType.None, extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false) It is the method of interpolating between the data points using quadratic polynomials. For any point, three data points nearby are taken to fit a quadratic polynomial. @@ -81,8 +81,8 @@ Extrapolation extends the last quadratic polynomial on each side. ## Keyword Arguments - `extrapolation`: The extrapolation type applied left and right of the data. Possible options - are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, - `ExtrapolationType.linear` and `ExtrapolationType.extension`. + are `ExtrapolationType.None` (default), `ExtrapolationType.Constant`, `ExtrapolationType.Linear` + `ExtrapolationType.Extension`, `ExtrapolationType.Periodic` and `ExtrapolationType.Reflective`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for @@ -119,9 +119,9 @@ struct QuadraticInterpolation{uType, tType, IType, pType, T, N} <: end function QuadraticInterpolation( - u, t, mode; extrapolation::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, cache_parameters = false, assume_linear_t = 1e-2) + u, t, mode; extrapolation::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false, assume_linear_t = 1e-2) extrapolation_left, extrapolation_right = munge_extrapolation( extrapolation, extrapolation_left, extrapolation_right) u, t = munge_data(u, t) @@ -140,8 +140,8 @@ function QuadraticInterpolation(u, t; kwargs...) end """ - LagrangeInterpolation(u, t, n = length(t) - 1; extrapolation::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, extrapolation_right::ExtrapolationType.T = ExtrapolationType.none) + LagrangeInterpolation(u, t, n = length(t) - 1; extrapolation::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, extrapolation_right::ExtrapolationType.T = ExtrapolationType.None) It is the method of interpolation using Lagrange polynomials of (k-1)th order passing through all the data points where k is the number of data points. @@ -154,8 +154,8 @@ It is the method of interpolation using Lagrange polynomials of (k-1)th order pa ## Keyword Arguments - `extrapolation`: The extrapolation type applied left and right of the data. Possible options - are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, - `ExtrapolationType.linear` and `ExtrapolationType.extension`. + are `ExtrapolationType.None` (default), `ExtrapolationType.Constant`, `ExtrapolationType.Linear` + `ExtrapolationType.Extension`, `ExtrapolationType.Periodic` and `ExtrapolationType.Reflective`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for @@ -190,9 +190,9 @@ end function LagrangeInterpolation( u, t, n = length(t) - 1; - extrapolation::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none) + extrapolation::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None) extrapolation_left, extrapolation_right = munge_extrapolation( extrapolation, extrapolation_left, extrapolation_right) u, t = munge_data(u, t) @@ -203,8 +203,8 @@ function LagrangeInterpolation( end """ - AkimaInterpolation(u, t; extrapolation::ExtrapolationType.T = ExtrapolationType.none, extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, cache_parameters = false) + AkimaInterpolation(u, t; extrapolation::ExtrapolationType.T = ExtrapolationType.None, extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false) It is a spline interpolation built from cubic polynomials. It forms a continuously differentiable function. For more details, refer: [https://en.wikipedia.org/wiki/Akima_spline](https://en.wikipedia.org/wiki/Akima_spline). Extrapolation extends the last cubic polynomial on each side. @@ -217,8 +217,8 @@ Extrapolation extends the last cubic polynomial on each side. ## Keyword Arguments - `extrapolation`: The extrapolation type applied left and right of the data. Possible options - are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, - `ExtrapolationType.linear` and `ExtrapolationType.extension`. + are `ExtrapolationType.None` (default), `ExtrapolationType.Constant`, `ExtrapolationType.Linear` + `ExtrapolationType.Extension`, `ExtrapolationType.Periodic` and `ExtrapolationType.Reflective`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for @@ -264,9 +264,9 @@ struct AkimaInterpolation{uType, tType, IType, bType, cType, dType, T, N} <: end function AkimaInterpolation( - u, t; extrapolation::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, cache_parameters = false, assume_linear_t = 1e-2) + u, t; extrapolation::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false, assume_linear_t = 1e-2) extrapolation_left, extrapolation_right = munge_extrapolation( extrapolation, extrapolation_left, extrapolation_right) u, t = munge_data(u, t) @@ -300,8 +300,8 @@ function AkimaInterpolation( end """ - ConstantInterpolation(u, t; dir = :left, extrapolation::ExtrapolationType.T = ExtrapolationType.none, extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, cache_parameters = false) + ConstantInterpolation(u, t; dir = :left, extrapolation::ExtrapolationType.T = ExtrapolationType.None, extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false) It is the method of interpolating using a constant polynomial. For any point, two adjacent data points are found on either side (left and right). The value at that point depends on `dir`. If it is `:left`, then the value at the left point is chosen and if it is `:right`, the value at the right point is chosen. @@ -316,8 +316,8 @@ Extrapolation extends the last constant polynomial at the end points on each sid - `dir`: indicates which value should be used for interpolation (`:left` or `:right`). - `extrapolation`: The extrapolation type applied left and right of the data. Possible options - are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, - `ExtrapolationType.linear` and `ExtrapolationType.extension`. + are `ExtrapolationType.None` (default), `ExtrapolationType.Constant`, `ExtrapolationType.Linear` + `ExtrapolationType.Extension`, `ExtrapolationType.Periodic` and `ExtrapolationType.Reflective`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for @@ -351,9 +351,9 @@ struct ConstantInterpolation{uType, tType, IType, T, N} <: AbstractInterpolation end function ConstantInterpolation( - u, t; dir = :left, extrapolation::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, + u, t; dir = :left, extrapolation::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false, assume_linear_t = 1e-2) extrapolation_left, extrapolation_right = munge_extrapolation( extrapolation, extrapolation_left, extrapolation_right) @@ -367,8 +367,8 @@ function ConstantInterpolation( end """ - QuadraticSpline(u, t; extrapolation::ExtrapolationType.T = ExtrapolationType.none, extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, cache_parameters = false) + QuadraticSpline(u, t; extrapolation::ExtrapolationType.T = ExtrapolationType.None, extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false) It is a spline interpolation using piecewise quadratic polynomials between each pair of data points. Its first derivative is also continuous. Extrapolation extends the last quadratic polynomial on each side. @@ -381,8 +381,8 @@ Extrapolation extends the last quadratic polynomial on each side. ## Keyword Arguments - `extrapolation`: The extrapolation type applied left and right of the data. Possible options - are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, - `ExtrapolationType.linear` and `ExtrapolationType.extension`. + are `ExtrapolationType.None` (default), `ExtrapolationType.Constant`, `ExtrapolationType.Linear` + `ExtrapolationType.Extension`, `ExtrapolationType.Periodic` and `ExtrapolationType.Reflective`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for @@ -430,9 +430,9 @@ struct QuadraticSpline{uType, tType, IType, pType, kType, cType, scType, T, N} < end function QuadraticSpline( - u::uType, t; extrapolation::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, + u::uType, t; extrapolation::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false, assume_linear_t = 1e-2) where {uType <: AbstractVector{<:Number}} extrapolation_left, extrapolation_right = munge_extrapolation( @@ -455,9 +455,9 @@ function QuadraticSpline( end function QuadraticSpline( - u::uType, t; extrapolation::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, cache_parameters = false, + u::uType, t; extrapolation::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false, assume_linear_t = 1e-2) where {uType <: AbstractVector} extrapolation_left, extrapolation_right = munge_extrapolation( @@ -490,8 +490,8 @@ function QuadraticSpline( end """ - CubicSpline(u, t; extrapolation::ExtrapolationType.T = ExtrapolationType.none, extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, cache_parameters = false) + CubicSpline(u, t; extrapolation::ExtrapolationType.T = ExtrapolationType.None, extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false) It is a spline interpolation using piecewise cubic polynomials between each pair of data points. Its first and second derivative is also continuous. Second derivative on both ends are zero, which are also called "natural" boundary conditions. Extrapolation extends the last cubic polynomial on each side. @@ -504,8 +504,8 @@ Second derivative on both ends are zero, which are also called "natural" boundar ## Keyword Arguments - `extrapolation`: The extrapolation type applied left and right of the data. Possible options - are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, - `ExtrapolationType.linear` and `ExtrapolationType.extension`. + are `ExtrapolationType.None` (default), `ExtrapolationType.Constant`, `ExtrapolationType.Linear` + `ExtrapolationType.Extension`, `ExtrapolationType.Periodic` and `ExtrapolationType.Reflective`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for @@ -551,9 +551,9 @@ struct CubicSpline{uType, tType, IType, pType, hType, zType, T, N} <: end function CubicSpline(u::uType, - t; extrapolation::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, cache_parameters = false, + t; extrapolation::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false, assume_linear_t = 1e-2) where {uType <: AbstractVector{<:Number}} extrapolation_left, extrapolation_right = munge_extrapolation( @@ -587,8 +587,8 @@ end function CubicSpline(u::uType, t; - extrapolation::ExtrapolationType.T = ExtrapolationType.none, extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, cache_parameters = false, + extrapolation::ExtrapolationType.T = ExtrapolationType.None, extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false, assume_linear_t = 1e-2) where {uType <: AbstractArray{T, N}} where {T, N} extrapolation_left, extrapolation_right = munge_extrapolation( @@ -625,9 +625,9 @@ function CubicSpline(u::uType, end function CubicSpline( - u::uType, t; extrapolation::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, cache_parameters = false, + u::uType, t; extrapolation::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false, assume_linear_t = 1e-2) where {uType <: AbstractVector} extrapolation_left, extrapolation_right = munge_extrapolation( @@ -657,8 +657,8 @@ function CubicSpline( end """ - BSplineInterpolation(u, t, d, pVecType, knotVecType; extrapolation::ExtrapolationType.T = ExtrapolationType.none, extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none) + BSplineInterpolation(u, t, d, pVecType, knotVecType; extrapolation::ExtrapolationType.T = ExtrapolationType.None, extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None) It is a curve defined by the linear combination of `n` basis functions of degree `d` where `n` is the number of data points. For more information, refer [https://pages.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/B-spline/bspline-curve.html](https://pages.mtu.edu/%7Eshene/COURSES/cs3621/NOTES/spline/B-spline/bspline-curve.html). Extrapolation is a constant polynomial of the end points on each side. @@ -674,8 +674,8 @@ Extrapolation is a constant polynomial of the end points on each side. ## Keyword Arguments - `extrapolation`: The extrapolation type applied left and right of the data. Possible options - are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, - `ExtrapolationType.linear` and `ExtrapolationType.extension`. + are `ExtrapolationType.None` (default), `ExtrapolationType.Constant`, `ExtrapolationType.Linear` + `ExtrapolationType.Extension`, `ExtrapolationType.Periodic` and `ExtrapolationType.Reflective`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for @@ -734,9 +734,9 @@ end function BSplineInterpolation( u::AbstractVector, t, d, pVecType, knotVecType; - extrapolation::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, assume_linear_t = 1e-2) + extrapolation::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, assume_linear_t = 1e-2) extrapolation_left, extrapolation_right = munge_extrapolation( extrapolation, extrapolation_left, extrapolation_right) u, t = munge_data(u, t) @@ -809,9 +809,9 @@ end function BSplineInterpolation( u::AbstractArray{T, N}, t, d, pVecType, knotVecType; - extrapolation::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, + extrapolation::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, assume_linear_t = 1e-2) where {T, N} extrapolation_left, extrapolation_right = munge_extrapolation( extrapolation, extrapolation_left, extrapolation_right) @@ -887,8 +887,8 @@ function BSplineInterpolation( end """ - BSplineApprox(u, t, d, h, pVecType, knotVecType; extrapolation::ExtrapolationType.T = ExtrapolationType.none, extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none) + BSplineApprox(u, t, d, h, pVecType, knotVecType; extrapolation::ExtrapolationType.T = ExtrapolationType.None, extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None) It is a regression based B-spline. The argument choices are the same as the `BSplineInterpolation`, with the additional parameter `h < length(t)` which is the number of control points to use, with smaller `h` indicating more smoothing. For more information, refer [http://www.cad.zju.edu.cn/home/zhx/GM/009/00-bsia.pdf](http://www.cad.zju.edu.cn/home/zhx/GM/009/00-bsia.pdf). @@ -906,8 +906,8 @@ Extrapolation is a constant polynomial of the end points on each side. ## Keyword Arguments - `extrapolation`: The extrapolation type applied left and right of the data. Possible options - are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, - `ExtrapolationType.linear` and `ExtrapolationType.extension`. + are `ExtrapolationType.None` (default), `ExtrapolationType.Constant`, `ExtrapolationType.Linear` + `ExtrapolationType.Extension`, `ExtrapolationType.Periodic` and `ExtrapolationType.Reflective`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for @@ -970,9 +970,9 @@ end function BSplineApprox( u::AbstractVector, t, d, h, pVecType, knotVecType; - extrapolation::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, assume_linear_t = 1e-2) + extrapolation::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, assume_linear_t = 1e-2) extrapolation_left, extrapolation_right = munge_extrapolation( extrapolation, extrapolation_left, extrapolation_right) u, t = munge_data(u, t) @@ -1066,9 +1066,9 @@ end function BSplineApprox( u::AbstractArray{T, N}, t, d, h, pVecType, knotVecType; - extrapolation::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, + extrapolation::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, assume_linear_t = 1e-2) where {T, N} extrapolation_left, extrapolation_right = munge_extrapolation( extrapolation, extrapolation_left, extrapolation_right) @@ -1166,8 +1166,8 @@ function BSplineApprox( extrapolation_left, extrapolation_right, assume_linear_t) end """ - CubicHermiteSpline(du, u, t; extrapolation::ExtrapolationType.T = ExtrapolationType.none, extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, cache_parameters = false) + CubicHermiteSpline(du, u, t; extrapolation::ExtrapolationType.T = ExtrapolationType.None, extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false) It is a Cubic Hermite interpolation, which is a piece-wise third degree polynomial such that the value and the first derivative are equal to given values in the data points. @@ -1180,8 +1180,8 @@ It is a Cubic Hermite interpolation, which is a piece-wise third degree polynomi ## Keyword Arguments - `extrapolation`: The extrapolation type applied left and right of the data. Possible options - are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, - `ExtrapolationType.linear` and `ExtrapolationType.extension`. + are `ExtrapolationType.None` (default), `ExtrapolationType.Constant`, `ExtrapolationType.Linear` + `ExtrapolationType.Extension`, `ExtrapolationType.Periodic` and `ExtrapolationType.Reflective`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for @@ -1216,9 +1216,9 @@ struct CubicHermiteSpline{uType, tType, IType, duType, pType, T, N} <: end function CubicHermiteSpline( - du, u, t; extrapolation::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, cache_parameters = false, assume_linear_t = 1e-2) + du, u, t; extrapolation::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false, assume_linear_t = 1e-2) @assert length(u)==length(du) "Length of `u` is not equal to length of `du`." extrapolation_left, extrapolation_right = munge_extrapolation( extrapolation, extrapolation_left, extrapolation_right) @@ -1234,8 +1234,8 @@ function CubicHermiteSpline( end """ - PCHIPInterpolation(u, t; extrapolation::ExtrapolationType.T = ExtrapolationType.none, extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none) + PCHIPInterpolation(u, t; extrapolation::ExtrapolationType.T = ExtrapolationType.None, extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None) It is a PCHIP Interpolation, which is a type of [`CubicHermiteSpline`](@ref) where the derivative values `du` are derived from the input data in such a way that the interpolation never overshoots the data. See [here](https://www.mathworks.com/content/dam/mathworks/mathworks-dot-com/moler/interp.pdf), @@ -1249,8 +1249,8 @@ section 3.4 for more details. ## Keyword Arguments - `extrapolation`: The extrapolation type applied left and right of the data. Possible options - are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, - `ExtrapolationType.linear` and `ExtrapolationType.extension`. + are `ExtrapolationType.None` (default), `ExtrapolationType.Constant`, `ExtrapolationType.Linear` + `ExtrapolationType.Extension`, `ExtrapolationType.Periodic` and `ExtrapolationType.Reflective`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for @@ -1268,8 +1268,8 @@ function PCHIPInterpolation(u, t; kwargs...) end """ - QuinticHermiteSpline(ddu, du, u, t; extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none) + QuinticHermiteSpline(ddu, du, u, t; extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None) It is a Quintic Hermite interpolation, which is a piece-wise fifth degree polynomial such that the value and the first and second derivative are equal to given values in the data points. @@ -1283,8 +1283,8 @@ It is a Quintic Hermite interpolation, which is a piece-wise fifth degree polyno ## Keyword Arguments - `extrapolation`: The extrapolation type applied left and right of the data. Possible options - are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, - `ExtrapolationType.linear` and `ExtrapolationType.extension`. + are `ExtrapolationType.None` (default), `ExtrapolationType.Constant`, `ExtrapolationType.Linear` + `ExtrapolationType.Extension`, `ExtrapolationType.Periodic` and `ExtrapolationType.Reflective`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for @@ -1321,9 +1321,9 @@ struct QuinticHermiteSpline{uType, tType, IType, duType, dduType, pType, T, N} < end function QuinticHermiteSpline( - ddu, du, u, t; extrapolation::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, + ddu, du, u, t; extrapolation::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_left::ExtrapolationType.T = ExtrapolationType.None, + extrapolation_right::ExtrapolationType.T = ExtrapolationType.None, cache_parameters = false, assume_linear_t = 1e-2) @assert length(u)==length(du)==length(ddu) "Length of `u` is not equal to length of `du` or `ddu`." extrapolation_left, extrapolation_right = munge_extrapolation( diff --git a/src/interpolation_methods.jl b/src/interpolation_methods.jl index d7cab62a..71a2db3c 100644 --- a/src/interpolation_methods.jl +++ b/src/interpolation_methods.jl @@ -10,21 +10,21 @@ end function _extrapolate_left(A, t) (; extrapolation_left) = A - if extrapolation_left == ExtrapolationType.none + if extrapolation_left == ExtrapolationType.None throw(LeftExtrapolationError()) - elseif extrapolation_left == ExtrapolationType.constant + elseif extrapolation_left == ExtrapolationType.Constant slope = derivative(A, first(A.t)) first(A.u) + slope * zero(t) - elseif extrapolation_left == ExtrapolationType.linear + elseif extrapolation_left == ExtrapolationType.Linear slope = derivative(A, first(A.t)) first(A.u) + slope * (t - first(A.t)) - elseif extrapolation_left == ExtrapolationType.extension + elseif extrapolation_left == ExtrapolationType.Extension _interpolate(A, t, A.iguesser) - elseif extrapolation_left == ExtrapolationType.periodic + elseif extrapolation_left == ExtrapolationType.Periodic t_, _ = transformation_periodic(A, t) _interpolate(A, t_, A.iguesser) else - # extrapolation_left == ExtrapolationType.reflective + # extrapolation_left == ExtrapolationType.Reflective t_, _ = transformation_reflective(A, t) _interpolate(A, t_, A.iguesser) end @@ -32,21 +32,21 @@ end function _extrapolate_right(A, t) (; extrapolation_right) = A - if extrapolation_right == ExtrapolationType.none + if extrapolation_right == ExtrapolationType.None throw(RightExtrapolationError()) - elseif extrapolation_right == ExtrapolationType.constant + elseif extrapolation_right == ExtrapolationType.Constant slope = derivative(A, last(A.t)) last(A.u) + slope * zero(t) - elseif extrapolation_right == ExtrapolationType.linear + elseif extrapolation_right == ExtrapolationType.Linear slope = derivative(A, last(A.t)) last(A.u) + slope * (t - last(A.t)) - elseif extrapolation_right == ExtrapolationType.extension + elseif extrapolation_right == ExtrapolationType.Extension _interpolate(A, t, A.iguesser) - elseif extrapolation_right == ExtrapolationType.periodic + elseif extrapolation_right == ExtrapolationType.Periodic t_, _ = transformation_periodic(A, t) _interpolate(A, t_, A.iguesser) else - # extrapolation_right == ExtrapolationType.reflective + # extrapolation_right == ExtrapolationType.Reflective t_, _ = transformation_reflective(A, t) _interpolate(A, t_, A.iguesser) end diff --git a/src/interpolation_utils.jl b/src/interpolation_utils.jl index 3f1e9682..1a0aaef4 100644 --- a/src/interpolation_utils.jl +++ b/src/interpolation_utils.jl @@ -305,7 +305,7 @@ function integrate_quintic_polynomial(t1, t2, offset, a, b, c, d, e, f) end function munge_extrapolation(extrapolation, extrapolation_left, extrapolation_right) - if extrapolation == ExtrapolationType.none + if extrapolation == ExtrapolationType.None extrapolation_left, extrapolation_right else extrapolation, extrapolation diff --git a/test/derivative_tests.jl b/test/derivative_tests.jl index e9e33328..376b3310 100644 --- a/test/derivative_tests.jl +++ b/test/derivative_tests.jl @@ -11,8 +11,8 @@ using ForwardDiff function test_derivatives(method; args = [], kwargs = [], name::String) kwargs_extrapolation = (method == Curvefit) ? [:extrapolate => true] : - [:extrapolation_right => ExtrapolationType.extension, - :extrapolation_left => ExtrapolationType.extension] + [:extrapolation_right => ExtrapolationType.Extension, + :extrapolation_left => ExtrapolationType.Extension] func = method(args...; kwargs..., kwargs_extrapolation...) (; t) = func trange = collect(range(minimum(t) - 5.0, maximum(t) + 5.0, step = 0.1)) @@ -242,7 +242,7 @@ end t = [0.0, 62.25, 109.66, 162.66, 205.8, 252.3] test_derivatives(CubicHermiteSpline; args = [du, u, t], name = "Cubic Hermite Spline") - A = CubicHermiteSpline(du, u, t; extrapolation = ExtrapolationType.extension) + A = CubicHermiteSpline(du, u, t; extrapolation = ExtrapolationType.Extension) @test derivative.(Ref(A), t) ≈ du @test derivative(A, 100.0)≈0.0105409 rtol=1e-5 @test derivative(A, 300.0)≈-0.0806717 rtol=1e-5 @@ -255,7 +255,7 @@ end t = [0.0, 62.25, 109.66, 162.66, 205.8, 252.3] test_derivatives(QuinticHermiteSpline; args = [ddu, du, u, t], name = "Quintic Hermite Spline") - A = QuinticHermiteSpline(ddu, du, u, t; extrapolation = ExtrapolationType.extension) + A = QuinticHermiteSpline(ddu, du, u, t; extrapolation = ExtrapolationType.Extension) @test derivative.(Ref(A), t) ≈ du @test derivative.(Ref(A), t, 2) ≈ ddu @test derivative(A, 100.0)≈0.0103916 rtol=1e-5 @@ -334,7 +334,7 @@ end @testset "Jacobian tests" begin u = rand(5) t = 0:4 - interp = LinearInterpolation(u, t, extrapolation = ExtrapolationType.extension) + interp = LinearInterpolation(u, t, extrapolation = ExtrapolationType.Extension) grad1 = ForwardDiff.derivative(interp, 2.4) myvec = rand(20) .* 4.0 diff --git a/test/extrapolation_tests.jl b/test/extrapolation_tests.jl index 12f7b2bb..ad37fc0d 100644 --- a/test/extrapolation_tests.jl +++ b/test/extrapolation_tests.jl @@ -5,8 +5,8 @@ using QuadGK function test_extrapolation(method, u, t) @testset "Extrapolation errors" begin A = method(u, t) - @test A.extrapolation_right == ExtrapolationType.none - @test A.extrapolation_left == ExtrapolationType.none + @test A.extrapolation_right == ExtrapolationType.None + @test A.extrapolation_left == ExtrapolationType.None for (error_type, t_eval) in zip( (DataInterpolations.LeftExtrapolationError, DataInterpolations.RightExtrapolationError), @@ -22,7 +22,7 @@ function test_extrapolation(method, u, t) end for extrapolation_type in instances(ExtrapolationType.T) - (extrapolation_type == ExtrapolationType.none) && continue + (extrapolation_type == ExtrapolationType.None) && continue @testset "extrapolation type $extrapolation_type" begin A = method(u, t; extrapolation = extrapolation_type) @@ -49,7 +49,7 @@ end test_extrapolation(LinearInterpolation, u, t) - for extrapolation_type in [ExtrapolationType.linear, ExtrapolationType.extension] + for extrapolation_type in [ExtrapolationType.Linear, ExtrapolationType.Extension] # Left extrapolation A = LinearInterpolation(u, t; extrapolation_left = extrapolation_type) t_eval = 0.0 @@ -77,7 +77,7 @@ end test_extrapolation(QuadraticInterpolation, u, t) # Linear left extrapolation - A = QuadraticInterpolation(u, t; extrapolation_left = ExtrapolationType.linear) + A = QuadraticInterpolation(u, t; extrapolation_left = ExtrapolationType.Linear) t_eval = 0.0 @test A(t_eval) ≈ -2.5 @test DataInterpolations.derivative(A, t_eval) == 3.5 @@ -85,7 +85,7 @@ end @test DataInterpolations.integral(A, t_eval) ≈ 0.75 # Linear right extrapolation - A = QuadraticInterpolation(u, t; extrapolation_right = ExtrapolationType.linear) + A = QuadraticInterpolation(u, t; extrapolation_right = ExtrapolationType.Linear) t_eval = 4.0 @test A(t_eval) ≈ -0.5 @test DataInterpolations.derivative(A, t_eval) == -2.5 @@ -95,7 +95,7 @@ end # Extension left extrapolation f = t -> (-3t^2 + 13t - 8) / 2 df = t -> (-6t + 13) / 2 - A = QuadraticInterpolation(u, t; extrapolation_left = ExtrapolationType.extension) + A = QuadraticInterpolation(u, t; extrapolation_left = ExtrapolationType.Extension) t_eval = 0.0 @test A(t_eval) ≈ -4.0 @test DataInterpolations.derivative(A, t_eval) == df(t_eval) @@ -103,7 +103,7 @@ end @test DataInterpolations.integral(A, t_eval) ≈ 1.25 # Extension right extrapolation - A = QuadraticInterpolation(u, t; extrapolation_right = ExtrapolationType.extension) + A = QuadraticInterpolation(u, t; extrapolation_right = ExtrapolationType.Extension) t_eval = 4.0 @test A(t_eval) ≈ -2.0 @test DataInterpolations.derivative(A, t_eval) == df(t_eval) diff --git a/test/integral_inverse_tests.jl b/test/integral_inverse_tests.jl index 9ba0b158..494e4943 100644 --- a/test/integral_inverse_tests.jl +++ b/test/integral_inverse_tests.jl @@ -3,7 +3,7 @@ using DataInterpolations: integral, derivative, invert_integral using FiniteDifferences function test_integral_inverses(method; args = [], kwargs = []) - A = method(args...; kwargs..., extrapolation = ExtrapolationType.extension) + A = method(args...; kwargs..., extrapolation = ExtrapolationType.Extension) @test hasfield(typeof(A), :I) A_intinv = invert_integral(A) @test A_intinv isa DataInterpolations.AbstractIntegralInverseInterpolation diff --git a/test/integral_tests.jl b/test/integral_tests.jl index 09ba655b..283b8dce 100644 --- a/test/integral_tests.jl +++ b/test/integral_tests.jl @@ -6,8 +6,8 @@ using RegularizationTools using StableRNGs function test_integral(method; args = [], kwargs = [], name::String) - func = method(args...; kwargs..., extrapolation_left = ExtrapolationType.extension, - extrapolation_right = ExtrapolationType.extension) + func = method(args...; kwargs..., extrapolation_left = ExtrapolationType.Extension, + extrapolation_right = ExtrapolationType.Extension) (; t) = func t1 = minimum(t) t2 = maximum(t) diff --git a/test/interface.jl b/test/interface.jl index 29f6864d..b0e48d06 100644 --- a/test/interface.jl +++ b/test/interface.jl @@ -18,8 +18,8 @@ end @testset "Symbolics" begin u = 2.0collect(1:10) t = 1.0collect(1:10) - A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.extension) - B = LinearInterpolation(u .^ 2, t; extrapolation = ExtrapolationType.extension) + A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.Extension) + B = LinearInterpolation(u .^ 2, t; extrapolation = ExtrapolationType.Extension) @variables t x(t) substitute(A(t), Dict(t => x)) t_val = 2.7 diff --git a/test/interpolation_tests.jl b/test/interpolation_tests.jl index 83a0bef1..08d8fb3f 100644 --- a/test/interpolation_tests.jl +++ b/test/interpolation_tests.jl @@ -31,7 +31,7 @@ end for t in (1.0:10.0, 1.0collect(1:10)) u = 2.0collect(1:10) #t = 1.0collect(1:10) - A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.Extension) for (_t, _u) in zip(t, u) @test A(_t) == _u @@ -41,7 +41,7 @@ end @test A(11) == 22 u = vcat(2.0collect(1:10)', 3.0collect(1:10)') - A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.Extension) for (_t, _u) in zip(t, eachcol(u)) @test A(_t) == _u @@ -54,7 +54,7 @@ end y = 2:4 u_ = x' .* y u = [u_[:, i] for i in 1:size(u_, 2)] - A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.Extension) @test A(0) == [0.0, 0.0, 0.0] @test A(5.5) == [11.0, 16.5, 22.0] @test A(11) == [22.0, 33.0, 44.0] @@ -65,7 +65,7 @@ end u_ = x' .* y u = [u_[:, i:(i + 1)] for i in 1:2:10] t = 1.0collect(2:2:10) - A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.Extension) @test A(0) == [-2.0 0.0; -3.0 0.0; -4.0 0.0] @test A(3) == [4.0 6.0; 6.0 9.0; 8.0 12.0] @@ -75,7 +75,7 @@ end # with NaNs (#113) u = [NaN, 1.0, 2.0, 3.0] t = 1:4 - A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.Extension) @test isnan(A(1.0)) @test A(2.0) == 1.0 @test A(2.5) == 1.5 @@ -83,7 +83,7 @@ end @test A(4.0) == 3.0 u = [0.0, NaN, 2.0, 3.0] - A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.Extension) @test A(1.0) == 0.0 @test isnan(A(2.0)) @test isnan(A(2.5)) @@ -91,7 +91,7 @@ end @test A(4.0) == 3.0 u = [0.0, 1.0, NaN, 3.0] - A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.Extension) @test A(1.0) == 0.0 @test A(2.0) == 1.0 @test isnan(A(2.5)) @@ -99,7 +99,7 @@ end @test A(4.0) == 3.0 u = [0.0, 1.0, 2.0, NaN] - A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.Extension) @test A(1.0) == 0.0 @test A(2.0) == 1.0 @test A(3.0) == 2.0 @@ -109,16 +109,16 @@ end # Test type stability u = Float32.(1:5) t = Float32.(1:5) - A1 = LinearInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A1 = LinearInterpolation(u, t; extrapolation = ExtrapolationType.Extension) u = 1:5 t = 1:5 - A2 = LinearInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A2 = LinearInterpolation(u, t; extrapolation = ExtrapolationType.Extension) u = [1 // i for i in 1:5] t = (1:5) - A3 = LinearInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A3 = LinearInterpolation(u, t; extrapolation = ExtrapolationType.Extension) u = [1 // i for i in 1:5] t = [1 // (6 - i) for i in 1:5] - A4 = LinearInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A4 = LinearInterpolation(u, t; extrapolation = ExtrapolationType.Extension) F32 = Float32(1) F64 = Float64(1) @@ -138,13 +138,13 @@ end # Nan time value: t = 0.0:3 # Floats u = [0, -2, -1, -2] - A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.Extension) dA = t -> ForwardDiff.derivative(A, t) @test isnan(dA(NaN)) t = 0:3 # Integers u = [0, -2, -1, -2] - A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.Extension) dA = t -> ForwardDiff.derivative(A, t) @test isnan(dA(NaN)) @@ -157,7 +157,7 @@ end # Test array-valued interpolation u = collect.(2.0collect(1:10)) t = 1.0collect(1:10) - A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.Extension) @test A(0) == fill(0.0) @test A(5.5) == fill(11.0) @test A(11) == fill(22) @@ -172,7 +172,7 @@ end # Test extrapolation u = 2.0collect(1:10) t = 1.0collect(1:10) - A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A = LinearInterpolation(u, t; extrapolation = ExtrapolationType.Extension) @test A(-1.0) == -2.0 @test A(11.0) == 22.0 A = LinearInterpolation(u, t) @@ -186,7 +186,7 @@ end u = [1.0, 4.0, 9.0, 16.0] t = [1.0, 2.0, 3.0, 4.0] - A = QuadraticInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A = QuadraticInterpolation(u, t; extrapolation = ExtrapolationType.Extension) for (_t, _u) in zip(t, u) @test A(_t) == _u @@ -202,7 +202,7 @@ end u = [1.0, 4.0, 9.0, 16.0] t = [1.0, 2.0, 3.0, 4.0] A = QuadraticInterpolation( - u, t, :Backward; extrapolation = ExtrapolationType.extension) + u, t, :Backward; extrapolation = ExtrapolationType.Extension) for (_t, _u) in zip(t, u) @test A(_t) == _u @@ -240,7 +240,7 @@ end # Matrix interpolation test u = [1.0 4.0 9.0 16.0; 1.0 4.0 9.0 16.0] - A = QuadraticInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A = QuadraticInterpolation(u, t; extrapolation = ExtrapolationType.Extension) for (_t, _u) in zip(t, eachcol(u)) @test A(_t) == _u @@ -253,7 +253,7 @@ end u_ = [1.0, 4.0, 9.0, 16.0]' .* ones(5) u = [u_[:, i] for i in 1:size(u_, 2)] - A = QuadraticInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A = QuadraticInterpolation(u, t; extrapolation = ExtrapolationType.Extension) @test A(0) == zeros(5) @test A(1.5) == 2.25 * ones(5) @test A(2.5) == 6.25 * ones(5) @@ -261,7 +261,7 @@ end @test A(5.0) == 25.0 * ones(5) u = [repeat(u[i], 1, 3) for i in 1:4] - A = QuadraticInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A = QuadraticInterpolation(u, t; extrapolation = ExtrapolationType.Extension) @test A(0) == zeros(5, 3) @test A(1.5) == 2.25 * ones(5, 3) @test A(2.5) == 6.25 * ones(5, 3) @@ -271,7 +271,7 @@ end # Test extrapolation u = [1.0, 4.5, 6.0, 2.0] t = [1.0, 2.0, 3.0, 4.0] - A = QuadraticInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A = QuadraticInterpolation(u, t; extrapolation = ExtrapolationType.Extension) @test A(0.0) == -4.5 @test A(5.0) == -7.5 A = QuadraticInterpolation(u, t) @@ -331,7 +331,7 @@ end # Test extrapolation u = [1.0, 4.0, 9.0] t = [1.0, 2.0, 3.0] - A = LagrangeInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A = LagrangeInterpolation(u, t; extrapolation = ExtrapolationType.Extension) @test A(0.0) == 0.0 @test A(4.0) == 16.0 A = LagrangeInterpolation(u, t) @@ -362,7 +362,7 @@ end test_cached_index(A) # Test extrapolation - A = AkimaInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A = AkimaInterpolation(u, t; extrapolation = ExtrapolationType.Extension) @test A(-1.0) ≈ -5.0 @test A(11.0) ≈ -3.924742268041234 A = AkimaInterpolation(u, t) @@ -377,7 +377,7 @@ end @testset "Vector case" for u in [[1.0, 2.0, 0.0, 1.0], ["B", "C", "A", "B"]] A = ConstantInterpolation( - u, t, dir = :right; extrapolation = ExtrapolationType.extension) + u, t, dir = :right; extrapolation = ExtrapolationType.Extension) @test A(0.5) == u[1] @test A(1.0) == u[1] @test A(1.5) == u[2] @@ -389,7 +389,7 @@ end @test A(4.5) == u[1] test_cached_index(A) - A = ConstantInterpolation(u, t; extrapolation = ExtrapolationType.extension) # dir=:left is default + A = ConstantInterpolation(u, t; extrapolation = ExtrapolationType.Extension) # dir=:left is default @test A(0.5) == u[1] @test A(1.0) == u[1] @test A(1.5) == u[1] @@ -407,7 +407,7 @@ end ["B" "C" "A" "B"; "B" "C" "A" "B"] ] A = ConstantInterpolation( - u, t, dir = :right; extrapolation = ExtrapolationType.extension) + u, t, dir = :right; extrapolation = ExtrapolationType.Extension) @test A(0.5) == u[:, 1] @test A(1.0) == u[:, 1] @test A(1.5) == u[:, 2] @@ -419,7 +419,7 @@ end @test A(4.5) == u[:, 1] test_cached_index(A) - A = ConstantInterpolation(u, t; extrapolation = ExtrapolationType.extension) # dir=:left is default + A = ConstantInterpolation(u, t; extrapolation = ExtrapolationType.Extension) # dir=:left is default @test A(0.5) == u[:, 1] @test A(1.0) == u[:, 1] @test A(1.5) == u[:, 1] @@ -436,7 +436,7 @@ end [[1.0, 2.0], [0.0, 1.0], [1.0, 2.0], [0.0, 1.0]], [["B", "C"], ["A", "B"], ["B", "C"], ["A", "B"]]] A = ConstantInterpolation( - u, t, dir = :right; extrapolation = ExtrapolationType.extension) + u, t, dir = :right; extrapolation = ExtrapolationType.Extension) @test A(0.5) == u[1] @test A(1.0) == u[1] @test A(1.5) == u[2] @@ -448,7 +448,7 @@ end @test A(4.5) == u[4] test_cached_index(A) - A = ConstantInterpolation(u, t; extrapolation = ExtrapolationType.extension) # dir=:left is default + A = ConstantInterpolation(u, t; extrapolation = ExtrapolationType.Extension) # dir=:left is default @test A(0.5) == u[1] @test A(1.0) == u[1] @test A(1.5) == u[1] @@ -465,7 +465,7 @@ end [[1.0 2.0; 1.0 2.0], [0.0 1.0; 0.0 1.0], [1.0 2.0; 1.0 2.0], [0.0 1.0; 0.0 1.0]], [["B" "C"; "B" "C"], ["A" "B"; "A" "B"], ["B" "C"; "B" "C"], ["A" "B"; "A" "B"]]] A = ConstantInterpolation( - u, t, dir = :right; extrapolation = ExtrapolationType.extension) + u, t, dir = :right; extrapolation = ExtrapolationType.Extension) @test A(0.5) == u[1] @test A(1.0) == u[1] @test A(1.5) == u[2] @@ -477,7 +477,7 @@ end @test A(4.5) == u[4] test_cached_index(A) - A = ConstantInterpolation(u, t; extrapolation = ExtrapolationType.extension) # dir=:left is default + A = ConstantInterpolation(u, t; extrapolation = ExtrapolationType.Extension) # dir=:left is default @test A(0.5) == u[1] @test A(1.0) == u[1] @test A(1.5) == u[1] @@ -492,7 +492,7 @@ end # Test extrapolation u = [1.0, 2.0, 0.0, 1.0] - A = ConstantInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A = ConstantInterpolation(u, t; extrapolation = ExtrapolationType.Extension) @test A(-1.0) == 1.0 @test A(11.0) == 1.0 A = ConstantInterpolation(u, t) @@ -502,7 +502,7 @@ end # Test extrapolation with infs with regularly spaced t u = [1.67e7, 1.6867e7, 1.7034e7, 1.7201e7, 1.7368e7] t = [0.0, 0.1, 0.2, 0.3, 0.4] - A = ConstantInterpolation(u, t; extrapolation = ExtrapolationType.extension) + A = ConstantInterpolation(u, t; extrapolation = ExtrapolationType.Extension) @test A(Inf) == last(u) @test A(-Inf) == first(u) end @@ -513,7 +513,7 @@ end u = [0.0, 1.0, 3.0] t = [-1.0, 0.0, 1.0] - A = QuadraticSpline(u, t; extrapolation = ExtrapolationType.extension) + A = QuadraticSpline(u, t; extrapolation = ExtrapolationType.Extension) # Solution P₁ = x -> 0.5 * (x + 1) * (x + 2) @@ -529,14 +529,14 @@ end u_ = [0.0, 1.0, 3.0]' .* ones(4) u = [u_[:, i] for i in 1:size(u_, 2)] - A = QuadraticSpline(u, t; extrapolation = ExtrapolationType.extension) + A = QuadraticSpline(u, t; extrapolation = ExtrapolationType.Extension) @test A(-2.0) == P₁(-2.0) * ones(4) @test A(-0.5) == P₁(-0.5) * ones(4) @test A(0.7) == P₁(0.7) * ones(4) @test A(2.0) == P₁(2.0) * ones(4) u = [repeat(u[i], 1, 3) for i in 1:3] - A = QuadraticSpline(u, t; extrapolation = ExtrapolationType.extension) + A = QuadraticSpline(u, t; extrapolation = ExtrapolationType.Extension) @test A(-2.0) == P₁(-2.0) * ones(4, 3) @test A(-0.5) == P₁(-0.5) * ones(4, 3) @test A(0.7) == P₁(0.7) * ones(4, 3) @@ -545,7 +545,7 @@ end # Test extrapolation u = [0.0, 1.0, 3.0] t = [-1.0, 0.0, 1.0] - A = QuadraticSpline(u, t; extrapolation = ExtrapolationType.extension) + A = QuadraticSpline(u, t; extrapolation = ExtrapolationType.Extension) @test A(-2.0) == 0.0 @test A(2.0) == 6.0 A = QuadraticSpline(u, t) @@ -559,7 +559,7 @@ end u = [0.0, 1.0, 3.0] t = [-1.0, 0.0, 1.0] - A = CubicSpline(u, t; extrapolation = ExtrapolationType.extension) + A = CubicSpline(u, t; extrapolation = ExtrapolationType.Extension) test_cached_index(A) # Solution @@ -578,7 +578,7 @@ end u_ = [0.0, 1.0, 3.0]' .* ones(4) u = [u_[:, i] for i in 1:size(u_, 2)] - A = CubicSpline(u, t; extrapolation = ExtrapolationType.extension) + A = CubicSpline(u, t; extrapolation = ExtrapolationType.Extension) for x in (-1.5, -0.5, -0.7) @test A(x) ≈ P₁(x) * ones(4) end @@ -587,7 +587,7 @@ end end u = [repeat(u[i], 1, 3) for i in 1:3] - A = CubicSpline(u, t; extrapolation = ExtrapolationType.extension) + A = CubicSpline(u, t; extrapolation = ExtrapolationType.Extension) for x in (-1.5, -0.5, -0.7) @test A(x) ≈ P₁(x) * ones(4, 3) end @@ -598,7 +598,7 @@ end # Test extrapolation u = [0.0, 1.0, 3.0] t = [-1.0, 0.0, 1.0] - A = CubicSpline(u, t; extrapolation = ExtrapolationType.extension) + A = CubicSpline(u, t; extrapolation = ExtrapolationType.Extension) @test A(-2.0) ≈ -1.0 @test A(2.0) ≈ 5.0 A = CubicSpline(u, t) @@ -643,7 +643,7 @@ end # Test extrapolation A = BSplineInterpolation( - u, t, 2, :Uniform, :Uniform; extrapolation = ExtrapolationType.extension) + u, t, 2, :Uniform, :Uniform; extrapolation = ExtrapolationType.Extension) @test A(-1.0) == u[1] @test A(300.0) == u[end] A = BSplineInterpolation(u, t, 2, :Uniform, :Uniform) @@ -664,7 +664,7 @@ end # Test extrapolation A = BSplineInterpolation( - u, t, 2, :ArcLen, :Average; extrapolation = ExtrapolationType.extension) + u, t, 2, :ArcLen, :Average; extrapolation = ExtrapolationType.Extension) @test A(-1.0) == u[1] @test A(300.0) == u[end] A = BSplineInterpolation(u, t, 2, :ArcLen, :Average) @@ -722,7 +722,7 @@ end # Test extrapolation A = BSplineApprox( - u, t, 2, 4, :Uniform, :Uniform; extrapolation = ExtrapolationType.extension) + u, t, 2, 4, :Uniform, :Uniform; extrapolation = ExtrapolationType.Extension) @test A(-1.0) == u[1] @test A(300.0) == u[end] A = BSplineApprox(u, t, 2, 4, :Uniform, :Uniform) @@ -768,7 +768,7 @@ end du = [-0.047, -0.058, 0.054, 0.012, -0.068, 0.0] u = [14.7, 11.51, 10.41, 14.95, 12.24, 11.22] t = [0.0, 62.25, 109.66, 162.66, 205.8, 252.3] - A = CubicHermiteSpline(du, u, t; extrapolation = ExtrapolationType.extension) + A = CubicHermiteSpline(du, u, t; extrapolation = ExtrapolationType.Extension) @test A.(t) ≈ u @test A(100.0)≈10.106770 rtol=1e-5 @test A(300.0)≈9.901542 rtol=1e-5 @@ -796,7 +796,7 @@ end du = [-0.047, -0.058, 0.054, 0.012, -0.068, 0.0] u = [14.7, 11.51, 10.41, 14.95, 12.24, 11.22] t = [0.0, 62.25, 109.66, 162.66, 205.8, 252.3] - A = QuinticHermiteSpline(ddu, du, u, t; extrapolation = ExtrapolationType.extension) + A = QuinticHermiteSpline(ddu, du, u, t; extrapolation = ExtrapolationType.Extension) @test A.(t) ≈ u @test A(100.0)≈10.107996 rtol=1e-5 @test A(300.0)≈11.364162 rtol=1e-5 diff --git a/test/regularization.jl b/test/regularization.jl index a3f4ef1c..eb8abca0 100644 --- a/test/regularization.jl +++ b/test/regularization.jl @@ -181,7 +181,7 @@ end @testset "Extrapolation" begin A = RegularizationSmooth( - uₒ, tₒ; alg = :fixed, extrapolation_right = ExtrapolationType.extension) + uₒ, tₒ; alg = :fixed, extrapolation_right = ExtrapolationType.Extension) @test A(10.0) == A.Aitp(10.0) A = RegularizationSmooth(uₒ, tₒ; alg = :fixed) @test_throws DataInterpolations.RightExtrapolationError A(10.0) diff --git a/test/zygote_tests.jl b/test/zygote_tests.jl index d8d178df..da4bf381 100644 --- a/test/zygote_tests.jl +++ b/test/zygote_tests.jl @@ -4,7 +4,7 @@ using Zygote function test_zygote(method, u, t; args = [], args_after = [], kwargs = [], name::String) func = method(args..., u, t, args_after...; kwargs..., - extrapolation = ExtrapolationType.extension) + extrapolation = ExtrapolationType.Extension) trange = collect(range(minimum(t) - 5.0, maximum(t) + 5.0, step = 0.1)) trange_exclude = filter(x -> !in(x, t), trange) @testset "$name, derivatives w.r.t. input" begin @@ -21,7 +21,7 @@ function test_zygote(method, u, t; args = [], args_after = [], kwargs = [], name @testset "$name, derivatives w.r.t. u" begin function f(u) A = method(args..., u, t, args_after...; kwargs..., - extrapolation = ExtrapolationType.extension) + extrapolation = ExtrapolationType.Extension) out = if u isa AbstractVector{<:Real} zero(eltype(u)) elseif u isa AbstractMatrix