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
6 changes: 3 additions & 3 deletions ext/DataInterpolationsRegularizationToolsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function RegularizationSmooth(u::AbstractVector, t::AbstractVector, t̂::Abstrac
cache_parameters::Bool = false)
extrapolation_left, extrapolation_right = munge_extrapolation(
extrapolation, extrapolation_left, extrapolation_right)
u, t = munge_data(u, t)
u, t = munge_data(u, t; check_sorted = t̂, sorted_arg_name = ("third", "t̂"))
M = _mapping_matrix(t̂, t)
Wls½ = LA.diagm(sqrt.(wls))
Wr½ = LA.diagm(sqrt.(wr))
Expand Down Expand Up @@ -139,7 +139,7 @@ function RegularizationSmooth(u::AbstractVector, t::AbstractVector, t̂::Abstrac
cache_parameters::Bool = false)
extrapolation_left, extrapolation_right = munge_extrapolation(
extrapolation, extrapolation_left, extrapolation_right)
u, t = munge_data(u, t)
u, t = munge_data(u, t; check_sorted = t̂, sorted_arg_name = ("third", "t̂"))
N, N̂ = length(t), length(t̂)
M = _mapping_matrix(t̂, t)
Wls½ = Array{Float64}(LA.I, N, N)
Expand Down Expand Up @@ -176,7 +176,7 @@ function RegularizationSmooth(u::AbstractVector, t::AbstractVector, t̂::Abstrac
cache_parameters::Bool = false)
extrapolation_left, extrapolation_right = munge_extrapolation(
extrapolation, extrapolation_left, extrapolation_right)
u, t = munge_data(u, t)
u, t = munge_data(u, t; check_sorted = t̂, sorted_arg_name = ("third", "t̂"))
N, N̂ = length(t), length(t̂)
M = _mapping_matrix(t̂, t)
Wls½ = LA.diagm(sqrt.(wls))
Expand Down
14 changes: 13 additions & 1 deletion src/interpolation_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,26 @@ function quadratic_spline_params(t::AbstractVector, sc::AbstractVector)
end

# helper function for data manipulation
function munge_data(u::AbstractVector, t::AbstractVector)
function munge_data(u::AbstractVector, t::AbstractVector;
check_sorted = t, sorted_arg_name = ("second", "t"))
Tu = nonmissingtype(eltype(u))
Tt = nonmissingtype(eltype(t))

if Tu === eltype(u) && Tt === eltype(t)
if !issorted(check_sorted)
# there is likely an user error
msg = "The $(sorted_arg_name[1]) argument (`$(sorted_arg_name[2])`), which is used for the interpolation domain, is not sorted."
if issorted(u)
msg *= "\nIt looks like the arguments `u` and `$(sorted_arg_name[2])` were inversed, make sure you used the arguments in the correct order."
end
throw(ArgumentError(msg))
end

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 Down
5 changes: 5 additions & 0 deletions test/interpolation_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1105,3 +1105,8 @@ f_cubic_spline = c -> square(CubicSpline, c)
end
end
end

@testset "user error" begin
@test_throws ArgumentError LinearInterpolation(rand(10), rand(10))
@test_throws ArgumentError LinearInterpolation(0:10, rand(10))
end
7 changes: 7 additions & 0 deletions test/regularization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,10 @@ end
A = RegularizationSmooth(uₒ, tₒ; alg = :fixed)
@test @inferred(A(1.0)) == A(1.0)
end

@testset "User error" begin
@test_throws ArgumentError RegularizationSmooth(tₒ, uₒ; alg = :fixed)
N̂ = 20
t̂ = collect(range(xmin, xmin + xspan, length = N̂))
@test_throws ArgumentError RegularizationSmooth(u, t̂, t)
end
Loading