Skip to content

Commit

Permalink
Merge pull request #294 from SouthEndMusic/throw_extrapolation_error
Browse files Browse the repository at this point in the history
Throw extrapolation error also when interpolation is called with an `AbstractVector`
  • Loading branch information
ChrisRackauckas authored Jul 15, 2024
2 parents 409493a + 77b78d2 commit f947b75
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
12 changes: 7 additions & 5 deletions src/DataInterpolations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ include("online.jl")
include("show.jl")

(interp::AbstractInterpolation)(t::Number) = _interpolate(interp, t)
(interp::AbstractInterpolation)(t::Number, i::Integer) = _interpolate(interp, t, i)
function (interp::AbstractInterpolation)(t::Number, i::Integer)
interp.idx_prev[] = i
_interpolate(interp, t)
end

function (interp::AbstractInterpolation)(t::AbstractVector)
u = get_u(interp.u, t)
interp(u, t)
Expand All @@ -44,16 +48,14 @@ function get_u(u::AbstractMatrix, t)
end

function (interp::AbstractInterpolation)(u::AbstractMatrix, t::AbstractVector)
iguess = firstindex(interp.t)
@inbounds for i in eachindex(t)
u[:, i], iguess = interp(t[i], iguess)
u[:, i] = interp(t[i])
end
u
end
function (interp::AbstractInterpolation)(u::AbstractVector, t::AbstractVector)
iguess = firstindex(interp.t)
@inbounds for i in eachindex(u, t)
u[i], iguess = interp(t[i], iguess)
u[i] = interp(t[i])
end
u
end
Expand Down
1 change: 1 addition & 0 deletions test/interpolation_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ end
A = LinearInterpolation(u, t)
@test_throws DataInterpolations.ExtrapolationError A(-1.0)
@test_throws DataInterpolations.ExtrapolationError A(11.0)
@test_throws DataInterpolations.ExtrapolationError A([-1.0, 11.0])
end

@testset "Quadratic Interpolation" begin
Expand Down
7 changes: 4 additions & 3 deletions test/online_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ u1 = [0.0, 1.0, 0.0]
t2 = [4.0, 5.0, 6.0]
u2 = [1.0, 2.0, 1.0]

ts = 1.0:0.5:6.0
ts_append = 1.0:0.5:6.0
ts_push = 1.0:0.5:4.0

for method in [LinearInterpolation, QuadraticInterpolation, ConstantInterpolation]
func1 = method(u1, t1)
Expand All @@ -17,7 +18,7 @@ for method in [LinearInterpolation, QuadraticInterpolation, ConstantInterpolatio
for name in propertynames(func1.p)
@test getfield(func1.p, name) == getfield(func2.p, name)
end
@test func1(ts) == func2(ts)
@test func1(ts_append) == func2(ts_append)
@test func1.I == func2.I

func1 = method(u1, t1)
Expand All @@ -28,6 +29,6 @@ for method in [LinearInterpolation, QuadraticInterpolation, ConstantInterpolatio
for name in propertynames(func1.p)
@test getfield(func1.p, name) == getfield(func2.p, name)
end
@test func1(ts) == func2(ts)
@test func1(ts_push) == func2(ts_push)
@test func1.I == func2.I
end

0 comments on commit f947b75

Please sign in to comment.