Skip to content

Commit 43fe00f

Browse files
authored
Merge pull request #566 from N5N3/cbfix
Fix `checkbounds` for trailing/missing dimensions.
2 parents 4b617f6 + 4113d66 commit 43fe00f

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

.github/workflows/CI.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
version:
16-
- '1.3'
1716
- '1.6'
1817
- '1'
1918
- 'nightly'

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Requires = "1.1"
3232
StaticArrays = "0.12, 1"
3333
Unitful = "1"
3434
WoodburyMatrices = "0.4, 0.5"
35-
julia = "1.3"
35+
julia = "1.6"
3636

3737
[extras]
3838
ColorVectorSpace = "c3611d14-8923-5661-9e6a-0046d554d3a4"

src/Interpolations.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,12 @@ _checkbounds(::CheckWillPass, itp, x) = true
418418
_checkbounds(::NeedsCheck, itp, x) = checklubounds(lbounds(itp), ubounds(itp), x)
419419

420420
checklubounds(ls, us, xs) = _checklubounds(true, ls, us, xs)
421-
_checklubounds(tf::Bool, ls, us, xs::Tuple{Number, Vararg{Any}}) =
422-
_checklubounds(tf & (ls[1] <= xs[1] <= us[1]), Base.tail(ls), Base.tail(us), Base.tail(xs))
423-
_checklubounds(tf::Bool, ls, us, xs::Tuple{AbstractVector, Vararg{Any}}) =
421+
_checklubounds(tf::Bool, ls::Tuple, us::Tuple, xs::Tuple) =
424422
_checklubounds(tf & allbetween(ls[1], xs[1], us[1]), Base.tail(ls), Base.tail(us), Base.tail(xs))
423+
_checklubounds(tf::Bool, ::Tuple{}, ::Tuple{}, xs::Tuple) =
424+
_checklubounds(tf & all(isone, xs[1]), (), (), Base.tail(xs))
425+
_checklubounds(tf::Bool, ls::Tuple, us::Tuple, ::Tuple{}) =
426+
_checklubounds(tf & (ls[1] == us[1]), Base.tail(ls), Base.tail(us), ())
425427
_checklubounds(tf::Bool, ::Tuple{}, ::Tuple{}, ::Tuple{}) = tf
426428

427429
maybe_clamp(itp, xs) = maybe_clamp(BoundsCheckStyle(itp), itp, xs)

src/utils.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,15 @@ function getindex!(dest, itp, xs::Vararg{AbstractArray,N}) where N
9898
return dest
9999
end
100100

101-
function allbetween(l::Real, xs, u::Real)
101+
allbetween(l, x::Number, u) = (l <= x) & (x <= u)
102+
function allbetween(l, xs::AbstractVector, u)
102103
ret = true
103104
@inbounds for x in xs
104-
ret = ret & (l <= x) & (x <= u)
105+
ret = ret & allbetween(l, x, u)
105106
end
106107
return ret
107108
end
108-
allbetween(l::Real, xs::AbstractRange, u::Real) = (l <= minimum(xs)) & (maximum(xs) <= u)
109+
allbetween(l::Real, xs::AbstractRange{<:Real}, u::Real) = (l <= minimum(xs)) & (maximum(xs) <= u)
109110

110111
allisreal(x) = _allisreal(true, x...)
111112
@inline _allisreal(ret, x1::Real, xs...) = _allisreal(ret, xs...)

test/core.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,12 @@ end
7979
@test (@inferred eltype(itp)) == Float64
8080
@test (@inferred ndims(itp)) == 1
8181
end
82+
83+
@testset "checkbounds" begin
84+
itp = interpolate(randn(2,2,1), (BSpline(Linear()), BSpline(Linear()), NoInterp()))
85+
@test !Base.checkbounds(Bool, itp, 1)
86+
@test Base.checkbounds(Bool, itp, 1, 1)
87+
@test Base.checkbounds(Bool, itp, 1, 1, 1)
88+
@test Base.checkbounds(Bool, itp, 1, 1, 1, 1)
89+
@test !Base.checkbounds(Bool, itp, 1, 1, 1, 1, 2)
90+
end

0 commit comments

Comments
 (0)