Skip to content
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
13 changes: 9 additions & 4 deletions src/interpolation_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ end
# helper function for data manipulation
function munge_data(u::AbstractVector, t::AbstractVector;
check_sorted = t, sorted_arg_name = ("second", "t"))
length(t) == length(u) ||
throw(ArgumentError("`u`, `t` length mismatch: length(t) ≠ length(u)"))

Tu = nonmissingtype(eltype(u))
Tt = nonmissingtype(eltype(t))

Expand All @@ -109,8 +112,6 @@ function munge_data(u::AbstractVector, t::AbstractVector;
return u, t
end

@assert length(t) == length(u)

non_missing_mask = map((ui, ti) -> !ismissing(ui) && !ismissing(ti), u, t)
u = convert(AbstractVector{Tu}, u[non_missing_mask])
t = convert(AbstractVector{Tt}, t[non_missing_mask])
Expand All @@ -119,13 +120,15 @@ function munge_data(u::AbstractVector, t::AbstractVector;
end

function munge_data(U::AbstractMatrix, t::AbstractVector)
length(t) == size(U, 2) ||
throw(ArgumentError("`u`, `t` length mismatch: length(t) ≠ size(U, 2)"))

TU = nonmissingtype(eltype(U))
Tt = nonmissingtype(eltype(t))
if TU === eltype(U) && Tt === eltype(t)
return U, t
end

@assert length(t) == size(U, 2)
non_missing_mask = map(
(uis, ti) -> !any(ismissing, uis) && !ismissing(ti), eachcol(U), t)
U = convert(AbstractMatrix{TU}, U[:, non_missing_mask])
Expand All @@ -135,13 +138,15 @@ function munge_data(U::AbstractMatrix, t::AbstractVector)
end

function munge_data(U::AbstractArray{T, N}, t) where {T, N}
length(t) == size(U, N) ||
throw(ArgumentError("`u`, `t` length mismatch: length(t) ≠ size(U, N)"))

TU = nonmissingtype(eltype(U))
Tt = nonmissingtype(eltype(t))
if TU === eltype(U) && Tt === eltype(t)
return U, t
end

@assert length(t) == size(U, N)
non_missing_mask = map(
(uis, ti) -> !any(ismissing, uis) && !ismissing(ti), eachslice(U; dims = N), t)
U = convert(AbstractArray{TU, N}, copy(selectdim(U, N, non_missing_mask)))
Expand Down
4 changes: 2 additions & 2 deletions test/derivative_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ end

@testset "Constant Interpolation" begin
u = [0.0, 2.0, 1.0, 3.0, 2.0, 6.0, 5.5, 5.5, 2.7, 5.1, 3.0]
t = collect(0.0:11.0)
t = collect(0.0:10.0)
A = ConstantInterpolation(u, t)
t2 = collect(0.0:10.0)
t2 = collect(0.0:9.0)
@test all(isnan, derivative.(Ref(A), t))
@test all(derivative.(Ref(A), t2 .+ 0.1) .== 0.0)
end
Expand Down
2 changes: 1 addition & 1 deletion test/integral_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ end
args = [u, t, :Backward],
name = "Quadratic Interpolation (Vector)")
u = round.(rand(100), digits = 5)
t = 1.0collect(1:10)
t = 1.0collect(1:100)
test_integral(QuadraticInterpolation; args = [u, t],
name = "Quadratic Interpolation (Vector) with random points")
end
Expand Down
3 changes: 2 additions & 1 deletion test/interpolation_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,8 @@ end

@testset "user error" begin
@test_throws ArgumentError LinearInterpolation(rand(10), rand(10))
@test_throws ArgumentError LinearInterpolation(0:10, rand(10))
@test_throws ArgumentError LinearInterpolation(1:10, rand(10))
@test_throws ArgumentError LinearInterpolation(1:3, 1:5)
end

@testset "Symbolic interpolation" begin
Expand Down
Loading