diff --git a/docs/src/extrapolation_methods.md b/docs/src/extrapolation_methods.md index 5b6286ba..09f8f0ae 100644 --- a/docs/src/extrapolation_methods.md +++ b/docs/src/extrapolation_methods.md @@ -13,7 +13,7 @@ A = QuadraticSpline(u, t) 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 `extension_left` and `extension_right` keywords respectively. +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` @@ -51,3 +51,15 @@ plot(A) plot!(t_eval_down, A.(t_eval_down); label = "extrapolation down") plot!(t_eval_up, A.(t_eval_up); label = "extrapolation up") ``` + +## Mixed extrapolation + +You can also have different extrapolation types left and right of the data. + +```@example tutorial +A = QuadraticSpline(u, t; extrapolation_left = ExtrapolationType.constant, + extrapolation_right = ExtrapolationType.linear) +plot(A) +plot!(t_eval_down, A.(t_eval_down); label = "extrapolation down") +plot!(t_eval_up, A.(t_eval_up); label = "extrapolation up") +``` diff --git a/src/DataInterpolations.jl b/src/DataInterpolations.jl index ee15a452..962b21a9 100644 --- a/src/DataInterpolations.jl +++ b/src/DataInterpolations.jl @@ -64,16 +64,16 @@ function Base.showerror(io::IO, ::ExtrapolationError) print(io, EXTRAPOLATION_ERROR) end -const DOWN_EXTRAPOLATION_ERROR = "Cannot extrapolate down as `extrapolation_left` keyword passed was `none`" -struct DownExtrapolationError <: Exception end -function Base.showerror(io::IO, ::DownExtrapolationError) - print(io, DOWN_EXTRAPOLATION_ERROR) +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 UP_EXTRAPOLATION_ERROR = "Cannot extrapolate up as `extrapolation_right` keyword passed was `none`" -struct UpExtrapolationError <: Exception end -function Base.showerror(io::IO, ::UpExtrapolationError) - print(io, UP_EXTRAPOLATION_ERROR) +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) end const INTEGRAL_NOT_FOUND_ERROR = "Cannot integrate it analytically. Please use Numerical Integration methods." diff --git a/src/derivatives.jl b/src/derivatives.jl index 6b1f02e6..da007025 100644 --- a/src/derivatives.jl +++ b/src/derivatives.jl @@ -17,7 +17,7 @@ function _extrapolate_derivative_down(A, t, order) (; extrapolation_left) = A typed_zero = zero(first(A.u) / one(A.t[1])) if extrapolation_left == ExtrapolationType.none - throw(DownExtrapolationError()) + throw(LeftExtrapolationError()) elseif extrapolation_left == ExtrapolationType.constant typed_zero elseif extrapolation_left == ExtrapolationType.linear @@ -36,7 +36,7 @@ function _extrapolate_derivative_up(A, t, order) (; extrapolation_right) = A typed_zero = zero(first(A.u) / one(A.t[1])) if extrapolation_right == ExtrapolationType.none - throw(UpExtrapolationError()) + throw(RightExtrapolationError()) elseif extrapolation_right == ExtrapolationType.constant typed_zero elseif extrapolation_right == ExtrapolationType.linear diff --git a/src/integrals.jl b/src/integrals.jl index d24a79a8..af2eb3bd 100644 --- a/src/integrals.jl +++ b/src/integrals.jl @@ -65,7 +65,7 @@ end function _extrapolate_integral_down(A, t) (; extrapolation_left) = A if extrapolation_left == ExtrapolationType.none - throw(DownExtrapolationError()) + throw(LeftExtrapolationError()) elseif extrapolation_left == ExtrapolationType.constant first(A.u) * (first(A.t) - t) elseif extrapolation_left == ExtrapolationType.linear @@ -80,7 +80,7 @@ end function _extrapolate_integral_up(A, t) (; extrapolation_right) = A if extrapolation_right == ExtrapolationType.none - throw(UpExtrapolationError()) + throw(RightExtrapolationError()) elseif extrapolation_right == ExtrapolationType.constant last(A.u) * (t - last(A.t)) elseif extrapolation_right == ExtrapolationType.linear diff --git a/src/interpolation_caches.jl b/src/interpolation_caches.jl index 4cc2670b..faeec06a 100644 --- a/src/interpolation_caches.jl +++ b/src/interpolation_caches.jl @@ -1,6 +1,7 @@ """ - LinearInterpolation(u, t; extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, cache_parameters = false) + 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. Extrapolation extends the last linear polynomial on each side. @@ -16,9 +17,9 @@ Extrapolation extends the last linear polynomial on each side. are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, `ExtrapolationType.linear` and `ExtrapolationType.extension`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `cache_parameters`: precompute parameters at initialization for faster interpolation computations. Note: if activated, `u` and `t` should not be modified. Defaults to `false`. - `assume_linear_t`: boolean value to specify a faster index lookup behavior for @@ -65,7 +66,8 @@ end """ QuadraticInterpolation(u, t, mode = :Forward; extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, cache_parameters = false) + 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. Extrapolation extends the last quadratic polynomial on each side. @@ -82,9 +84,9 @@ Extrapolation extends the last quadratic polynomial on each side. are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, `ExtrapolationType.linear` and `ExtrapolationType.extension`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `cache_parameters`: precompute parameters at initialization for faster interpolation computations. Note: if activated, `u` and `t` should not be modified. Defaults to `false`. - `assume_linear_t`: boolean value to specify a faster index lookup behaviour for evenly-distributed abscissae. Alternatively, a numerical threshold may be specified @@ -138,8 +140,8 @@ function QuadraticInterpolation(u, t; kwargs...) end """ - LagrangeInterpolation(u, t, n = length(t) - 1; extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, safetycopy = true) + 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. @@ -155,9 +157,9 @@ It is the method of interpolation using Lagrange polynomials of (k-1)th order pa are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, `ExtrapolationType.linear` and `ExtrapolationType.extension`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. """ struct LagrangeInterpolation{uType, tType, T, bcacheType, N} <: AbstractInterpolation{T, N} @@ -201,7 +203,7 @@ function LagrangeInterpolation( end """ - AkimaInterpolation(u, t; extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, + 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). @@ -218,9 +220,9 @@ Extrapolation extends the last cubic polynomial on each side. are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, `ExtrapolationType.linear` and `ExtrapolationType.extension`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `cache_parameters`: precompute parameters at initialization for faster interpolation computations. Note: if activated, `u` and `t` should not be modified. Defaults to `false`. - `assume_linear_t`: boolean value to specify a faster index lookup behaviour for evenly-distributed abscissae. Alternatively, a numerical threshold may be specified @@ -298,7 +300,7 @@ function AkimaInterpolation( end """ - ConstantInterpolation(u, t; dir = :left, extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, + 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`. @@ -317,9 +319,9 @@ Extrapolation extends the last constant polynomial at the end points on each sid are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, `ExtrapolationType.linear` and `ExtrapolationType.extension`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `cache_parameters`: precompute parameters at initialization for faster interpolation computations. Note: if activated, `u` and `t` should not be modified. Defaults to `false`. - `assume_linear_t`: boolean value to specify a faster index lookup behaviour for evenly-distributed abscissae. Alternatively, a numerical threshold may be specified @@ -365,7 +367,7 @@ function ConstantInterpolation( end """ - QuadraticSpline(u, t; extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, + 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. @@ -382,9 +384,9 @@ Extrapolation extends the last quadratic polynomial on each side. are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, `ExtrapolationType.linear` and `ExtrapolationType.extension`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `cache_parameters`: precompute parameters at initialization for faster interpolation computations. Note: if activated, `u` and `t` should not be modified. Defaults to `false`. - `assume_linear_t`: boolean value to specify a faster index lookup behaviour for evenly-distributed abscissae. Alternatively, a numerical threshold may be specified @@ -488,7 +490,7 @@ function QuadraticSpline( end """ - CubicSpline(u, t; extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, + 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. @@ -505,9 +507,9 @@ Second derivative on both ends are zero, which are also called "natural" boundar are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, `ExtrapolationType.linear` and `ExtrapolationType.extension`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `cache_parameters`: precompute parameters at initialization for faster interpolation computations. Note: if activated, `u` and `t` should not be modified. Defaults to `false`. - `assume_linear_t`: boolean value to specify a faster index lookup behaviour for evenly-distributed abscissae. Alternatively, a numerical threshold may be specified @@ -655,8 +657,8 @@ function CubicSpline( end """ - BSplineInterpolation(u, t, d, pVecType, knotVecType; extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, safetycopy = true) + 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. @@ -675,10 +677,10 @@ Extrapolation is a constant polynomial of the end points on each side. are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, `ExtrapolationType.linear` and `ExtrapolationType.extension`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for - the possible options. - - `assume_linear_t`: boolean value to specify a faster index lookup behaviour for + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. + - `assume_linear_t`: boolean value to specify a faster index lookup behavior for evenly-distributed abscissae. Alternatively, a numerical threshold may be specified for a test based on the normalized standard deviation of the difference with respect to the straight line (see [`looks_linear`](@ref)). Defaults to 1e-2. @@ -885,7 +887,7 @@ function BSplineInterpolation( end """ - BSplineApprox(u, t, d, h, pVecType, knotVecType; extrapolation_left::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. @@ -907,9 +909,9 @@ Extrapolation is a constant polynomial of the end points on each side. are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, `ExtrapolationType.linear` and `ExtrapolationType.extension`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `assume_linear_t`: boolean value to specify a faster index lookup behaviour for evenly-distributed abscissae. Alternatively, a numerical threshold may be specified for a test based on the normalized standard deviation of the difference with respect @@ -1164,7 +1166,7 @@ function BSplineApprox( extrapolation_left, extrapolation_right, assume_linear_t) end """ - CubicHermiteSpline(du, u, t; extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, + 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. @@ -1181,9 +1183,9 @@ It is a Cubic Hermite interpolation, which is a piece-wise third degree polynomi are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, `ExtrapolationType.linear` and `ExtrapolationType.extension`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `cache_parameters`: precompute parameters at initialization for faster interpolation computations. Note: if activated, `u` and `t` should not be modified. Defaults to `false`. - `assume_linear_t`: boolean value to specify a faster index lookup behaviour for evenly-distributed abscissae. Alternatively, a numerical threshold may be specified @@ -1232,8 +1234,8 @@ function CubicHermiteSpline( end """ - PCHIPInterpolation(u, t; extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, safetycopy = true) + 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), @@ -1250,9 +1252,9 @@ section 3.4 for more details. are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, `ExtrapolationType.linear` and `ExtrapolationType.extension`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `cache_parameters`: precompute parameters at initialization for faster interpolation computations. Note: if activated, `u` and `t` should not be modified. Defaults to `false`. - `assume_linear_t`: boolean value to specify a faster index lookup behaviour for evenly-distributed abscissae. Alternatively, a numerical threshold may be specified @@ -1267,7 +1269,7 @@ end """ QuinticHermiteSpline(ddu, du, u, t; extrapolation_left::ExtrapolationType.T = ExtrapolationType.none, - extrapolation_right::ExtrapolationType.T = ExtrapolationType.none, safetycopy = true) + 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. @@ -1284,9 +1286,9 @@ It is a Quintic Hermite interpolation, which is a piece-wise fifth degree polyno are `ExtrapolationType.none` (default), `ExtrapolationType.constant`, `ExtrapolationType.linear` and `ExtrapolationType.extension`. - `extrapolation_left`: The extrapolation type applied left of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `extrapolation_right`: The extrapolation type applied right of the data. See `extrapolation` for - the possible options. + the possible options. This keyword is ignored if `extrapolation != Extrapolation.none`. - `cache_parameters`: precompute parameters at initialization for faster interpolation computations. Note: if activated, `u` and `t` should not be modified. Defaults to `false`. - `assume_linear_t`: boolean value to specify a faster index lookup behaviour for evenly-distributed abscissae. Alternatively, a numerical threshold may be specified diff --git a/src/interpolation_methods.jl b/src/interpolation_methods.jl index a691fbb2..a781acf3 100644 --- a/src/interpolation_methods.jl +++ b/src/interpolation_methods.jl @@ -11,7 +11,7 @@ end function _extrapolate_down(A, t) (; extrapolation_left) = A if extrapolation_left == ExtrapolationType.none - throw(DownExtrapolationError()) + throw(LeftExtrapolationError()) elseif extrapolation_left == ExtrapolationType.constant slope = derivative(A, first(A.t)) first(A.u) + slope * zero(t) @@ -27,7 +27,7 @@ end function _extrapolate_up(A, t) (; extrapolation_right) = A if extrapolation_right == ExtrapolationType.none - throw(UpExtrapolationError()) + throw(RightExtrapolationError()) elseif extrapolation_right == ExtrapolationType.constant slope = derivative(A, last(A.t)) last(A.u) + slope * zero(t) diff --git a/test/derivative_tests.jl b/test/derivative_tests.jl index df96b0fb..e9e33328 100644 --- a/test/derivative_tests.jl +++ b/test/derivative_tests.jl @@ -76,8 +76,9 @@ function test_derivatives(method; args = [], kwargs = [], name::String) @test_throws DataInterpolations.ExtrapolationError derivative(func, t[1] - 1.0) @test_throws DataInterpolations.ExtrapolationError derivative(func, t[end] + 1.0) else - @test_throws DataInterpolations.DownExtrapolationError derivative(func, t[1] - 1.0) - @test_throws DataInterpolations.UpExtrapolationError derivative(func, t[end] + 1.0) + @test_throws DataInterpolations.LeftExtrapolationError derivative(func, t[1] - 1.0) + @test_throws DataInterpolations.RightExtrapolationError derivative( + func, t[end] + 1.0) end @test_throws DataInterpolations.DerivativeNotFoundError derivative( func, t[1], 3) diff --git a/test/extrapolation_tests.jl b/test/extrapolation_tests.jl index 9ba616f4..7fa75f06 100644 --- a/test/extrapolation_tests.jl +++ b/test/extrapolation_tests.jl @@ -5,8 +5,8 @@ function test_extrapolation_errors(method, u, t) @test A.extrapolation_right == ExtrapolationType.none @test A.extrapolation_left == ExtrapolationType.none for (error_type, t_eval) in zip( - (DataInterpolations.DownExtrapolationError, - DataInterpolations.UpExtrapolationError), + (DataInterpolations.LeftExtrapolationError, + DataInterpolations.RightExtrapolationError), (first(t) - 1, last(t) + 1)) @test_throws error_type A(t_eval) @test_throws error_type DataInterpolations.derivative( diff --git a/test/integral_tests.jl b/test/integral_tests.jl index c37d9d8d..09ba655b 100644 --- a/test/integral_tests.jl +++ b/test/integral_tests.jl @@ -49,10 +49,11 @@ function test_integral(method; args = [], kwargs = [], name::String) @test isapprox(qint, aint, atol = 1e-6, rtol = 1e-8) end func = method(args...; kwargs...) - @test_throws DataInterpolations.DownExtrapolationError integral(func, t[1] - 1.0) - @test_throws DataInterpolations.UpExtrapolationError integral(func, t[end] + 1.0) - @test_throws DataInterpolations.DownExtrapolationError integral(func, t[1] - 1.0, t[2]) - @test_throws DataInterpolations.UpExtrapolationError integral(func, t[1], t[end] + 1.0) + @test_throws DataInterpolations.LeftExtrapolationError integral(func, t[1] - 1.0) + @test_throws DataInterpolations.RightExtrapolationError integral(func, t[end] + 1.0) + @test_throws DataInterpolations.LeftExtrapolationError integral(func, t[1] - 1.0, t[2]) + @test_throws DataInterpolations.RightExtrapolationError integral( + func, t[1], t[end] + 1.0) end @testset "LinearInterpolation" begin diff --git a/test/interpolation_tests.jl b/test/interpolation_tests.jl index 3b374c00..83a0bef1 100644 --- a/test/interpolation_tests.jl +++ b/test/interpolation_tests.jl @@ -176,9 +176,9 @@ end @test A(-1.0) == -2.0 @test A(11.0) == 22.0 A = LinearInterpolation(u, t) - @test_throws DataInterpolations.DownExtrapolationError A(-1.0) - @test_throws DataInterpolations.UpExtrapolationError A(11.0) - @test_throws DataInterpolations.DownExtrapolationError A([-1.0, 11.0]) + @test_throws DataInterpolations.LeftExtrapolationError A(-1.0) + @test_throws DataInterpolations.RightExtrapolationError A(11.0) + @test_throws DataInterpolations.LeftExtrapolationError A([-1.0, 11.0]) end @testset "Quadratic Interpolation" begin @@ -275,8 +275,8 @@ end @test A(0.0) == -4.5 @test A(5.0) == -7.5 A = QuadraticInterpolation(u, t) - @test_throws DataInterpolations.DownExtrapolationError A(0.0) - @test_throws DataInterpolations.UpExtrapolationError A(5.0) + @test_throws DataInterpolations.LeftExtrapolationError A(0.0) + @test_throws DataInterpolations.RightExtrapolationError A(5.0) end @testset "Lagrange Interpolation" begin @@ -335,8 +335,8 @@ end @test A(0.0) == 0.0 @test A(4.0) == 16.0 A = LagrangeInterpolation(u, t) - @test_throws DataInterpolations.DownExtrapolationError A(-1.0) - @test_throws DataInterpolations.UpExtrapolationError A(4.0) + @test_throws DataInterpolations.LeftExtrapolationError A(-1.0) + @test_throws DataInterpolations.RightExtrapolationError A(4.0) end @testset "Akima Interpolation" begin @@ -366,8 +366,8 @@ end @test A(-1.0) ≈ -5.0 @test A(11.0) ≈ -3.924742268041234 A = AkimaInterpolation(u, t) - @test_throws DataInterpolations.DownExtrapolationError A(-1.0) - @test_throws DataInterpolations.UpExtrapolationError A(11.0) + @test_throws DataInterpolations.LeftExtrapolationError A(-1.0) + @test_throws DataInterpolations.RightExtrapolationError A(11.0) end @testset "ConstantInterpolation" begin @@ -496,8 +496,8 @@ end @test A(-1.0) == 1.0 @test A(11.0) == 1.0 A = ConstantInterpolation(u, t) - @test_throws DataInterpolations.DownExtrapolationError A(-1.0) - @test_throws DataInterpolations.UpExtrapolationError A(11.0) + @test_throws DataInterpolations.LeftExtrapolationError A(-1.0) + @test_throws DataInterpolations.RightExtrapolationError A(11.0) # Test extrapolation with infs with regularly spaced t u = [1.67e7, 1.6867e7, 1.7034e7, 1.7201e7, 1.7368e7] @@ -549,8 +549,8 @@ end @test A(-2.0) == 0.0 @test A(2.0) == 6.0 A = QuadraticSpline(u, t) - @test_throws DataInterpolations.DownExtrapolationError A(-2.0) - @test_throws DataInterpolations.UpExtrapolationError A(2.0) + @test_throws DataInterpolations.LeftExtrapolationError A(-2.0) + @test_throws DataInterpolations.RightExtrapolationError A(2.0) end @testset "CubicSpline Interpolation" begin @@ -602,8 +602,8 @@ end @test A(-2.0) ≈ -1.0 @test A(2.0) ≈ 5.0 A = CubicSpline(u, t) - @test_throws DataInterpolations.DownExtrapolationError A(-2.0) - @test_throws DataInterpolations.UpExtrapolationError A(2.0) + @test_throws DataInterpolations.LeftExtrapolationError A(-2.0) + @test_throws DataInterpolations.RightExtrapolationError A(2.0) @testset "AbstractMatrix" begin t = 0.1:0.1:1.0 @@ -647,8 +647,8 @@ end @test A(-1.0) == u[1] @test A(300.0) == u[end] A = BSplineInterpolation(u, t, 2, :Uniform, :Uniform) - @test_throws DataInterpolations.DownExtrapolationError A(-1.0) - @test_throws DataInterpolations.UpExtrapolationError A(300.0) + @test_throws DataInterpolations.LeftExtrapolationError A(-1.0) + @test_throws DataInterpolations.RightExtrapolationError A(300.0) A = BSplineInterpolation(u, t, 2, :ArcLen, :Average) @@ -668,8 +668,8 @@ end @test A(-1.0) == u[1] @test A(300.0) == u[end] A = BSplineInterpolation(u, t, 2, :ArcLen, :Average) - @test_throws DataInterpolations.DownExtrapolationError A(-1.0) - @test_throws DataInterpolations.UpExtrapolationError A(300.0) + @test_throws DataInterpolations.LeftExtrapolationError A(-1.0) + @test_throws DataInterpolations.RightExtrapolationError A(300.0) @testset "AbstractMatrix" begin t = 0.1:0.1:1.0 @@ -726,8 +726,8 @@ end @test A(-1.0) == u[1] @test A(300.0) == u[end] A = BSplineApprox(u, t, 2, 4, :Uniform, :Uniform) - @test_throws DataInterpolations.DownExtrapolationError A(-1.0) - @test_throws DataInterpolations.UpExtrapolationError A(300.0) + @test_throws DataInterpolations.LeftExtrapolationError A(-1.0) + @test_throws DataInterpolations.RightExtrapolationError A(300.0) @testset "AbstractMatrix" begin t = 0.1:0.1:1.0 diff --git a/test/regularization.jl b/test/regularization.jl index 6d850475..a3f4ef1c 100644 --- a/test/regularization.jl +++ b/test/regularization.jl @@ -184,7 +184,7 @@ end 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.UpExtrapolationError A(10.0) + @test_throws DataInterpolations.RightExtrapolationError A(10.0) end @testset "Type inference" begin