diff --git a/src/interpolation_utils.jl b/src/interpolation_utils.jl index acdccb24..83b70269 100644 --- a/src/interpolation_utils.jl +++ b/src/interpolation_utils.jl @@ -123,3 +123,6 @@ function searchsortedlastcorrelated(v::AbstractVector, x, guess) lo, hi = bracketstrictlymontonic(v, x, guess, Base.Order.Forward) searchsortedlast(v, x, lo, hi, Base.Order.Forward) end + +searchsortedfirstcorrelated(r::AbstractRange, x, _) = searchsortedfirst(r, x) +searchsortedlastcorrelated(r::AbstractRange, x, _) = searchsortedlast(r, x) \ No newline at end of file diff --git a/test/interpolation_tests.jl b/test/interpolation_tests.jl index 9062d7f8..e89ca45f 100644 --- a/test/interpolation_tests.jl +++ b/test/interpolation_tests.jl @@ -4,36 +4,41 @@ using Optim import ForwardDiff @testset "Linear Interpolation" begin - u = 2.0collect(1:10) - t = 1.0collect(1:10) - A = LinearInterpolation(u, t) - - for (_t, _u) in zip(t, u) - @test A(_t) == _u - end - @test A(0) == 0.0 - @test A(5.5) == 11.0 - @test A(11) == 22 - - u = vcat(2.0collect(1:10)', 3.0collect(1:10)') - A = LinearInterpolation(u, t) - - for (_t, _u) in zip(t, eachcol(u)) - @test A(_t) == _u + for t in (1.0:10.0, 1.0collect(1:10)) + u = 2.0collect(1:10) + #t = 1.0collect(1:10) + A = LinearInterpolation(u, t) + + for (_t, _u) in zip(t, u) + @test A(_t) == _u + end + @test A(0) == 0.0 + @test A(5.5) == 11.0 + @test A(11) == 22 + + u = vcat(2.0collect(1:10)', 3.0collect(1:10)') + A = LinearInterpolation(u, t) + + for (_t, _u) in zip(t, eachcol(u)) + @test A(_t) == _u + end + @test A(0) == [0.0, 0.0] + @test A(5.5) == [11.0, 16.5] + @test A(11) == [22, 33] + + x = 1:10 + y = 2:4 + u_ = x' .* y + u = [u_[:, i] for i in 1:size(u_, 2)] + A = LinearInterpolation(u, t) + @test A(0) == [0.0, 0.0, 0.0] + @test A(5.5) == [11.0, 16.5, 22.0] + @test A(11) == [22.0, 33.0, 44.0] end - @test A(0) == [0.0, 0.0] - @test A(5.5) == [11.0, 16.5] - @test A(11) == [22, 33] x = 1:10 y = 2:4 u_ = x' .* y - u = [u_[:, i] for i in 1:size(u_, 2)] - A = LinearInterpolation(u, t) - @test A(0) == [0.0, 0.0, 0.0] - @test A(5.5) == [11.0, 16.5, 22.0] - @test A(11) == [22.0, 33.0, 44.0] - u = [u_[:, i:(i + 1)] for i in 1:2:10] t = 1.0collect(2:2:10) A = LinearInterpolation(u, t)