Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Throw extrapolation error also when interpolation is called with an AbstractVector #294

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading