Skip to content

Commit

Permalink
Merge pull request #192 from DaniGlez/master
Browse files Browse the repository at this point in the history
Bypass bracketing for AbstractRanges
  • Loading branch information
ChrisRackauckas authored Oct 14, 2023
2 parents 8306a5d + 45438da commit 22b588d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
3 changes: 3 additions & 0 deletions src/interpolation_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
55 changes: 30 additions & 25 deletions test/interpolation_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 22b588d

Please sign in to comment.