Skip to content
Draft
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
14 changes: 14 additions & 0 deletions src/interpolation_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ function munge_data(U::AbstractMatrix, t::AbstractVector)
TU = nonmissingtype(eltype(U))
Tt = nonmissingtype(eltype(t))
if TU === eltype(U) && Tt === eltype(t)
if !issorted(t; by = ForwardDiff.value)
throw(
ArgumentError(
"The second argument (`t`), which is used for the interpolation domain, is not sorted."
)
)
end
return U, t
end

Expand All @@ -347,6 +354,13 @@ function munge_data(U::AbstractArray{T, N}, t) where {T, N}
TU = nonmissingtype(eltype(U))
Tt = nonmissingtype(eltype(t))
if TU === eltype(U) && Tt === eltype(t)
if !issorted(t; by = ForwardDiff.value)
throw(
ArgumentError(
"The second argument (`t`), which is used for the interpolation domain, is not sorted."
)
)
end
return U, t
end

Expand Down
10 changes: 10 additions & 0 deletions test/interpolation_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2214,6 +2214,16 @@ f_cubic_spline = c -> square(CubicSpline, c)
end
end

@testset "munge_data rejects unsorted t for matrix/N-d u" begin
# The vector `munge_data` method already rejects unsorted `t`; the matrix and
# N-d methods silently accepted it and returned wrong values
# (https://github.com/SciML/DataInterpolations.jl, candidate 5).
us = [1.0, 2.0, 3.0, 4.0]
ts = [1.0, 3.0, 2.0, 4.0]
@test_throws ArgumentError LinearInterpolation([us'; us'], ts)
@test_throws ArgumentError LinearInterpolation(reshape(vcat(us, us), 2, 1, 4), ts)
end

@testset "user error" begin
@test_throws ArgumentError LinearInterpolation(rand(10), rand(10))
@test_throws ArgumentError LinearInterpolation(1:10, rand(10))
Expand Down
Loading