Skip to content

Commit bc30ccf

Browse files
authored
checkindex BlockedUnitRange with BlockIndex (#242)
* checkindex BlockedUnitRange with BlockIndex * version bump to v0.16.24
1 parent 1705da1 commit bc30ccf

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/blockaxis.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ Base.dataids(b::BlockedUnitRange) = Base.dataids(blocklasts(b))
253253
Base.checkindex(::Type{Bool}, b::BlockRange, K::Int) = checkindex(Bool, Int.(b), K)
254254
Base.checkindex(::Type{Bool}, b::AbstractUnitRange{Int}, K::Block{1}) = checkindex(Bool, blockaxes(b,1), Int(K))
255255

256+
function Base.checkindex(::Type{Bool}, axis::BlockedUnitRange, ind::BlockIndexRange{1})
257+
checkindex(Bool, axis, first(ind)) && checkindex(Bool, axis, last(ind))
258+
end
259+
function Base.checkindex(::Type{Bool}, axis::BlockedUnitRange, ind::BlockIndex{1})
260+
checkindex(Bool, axis, block(ind)) && checkbounds(Bool, axis[block(ind)], blockindex(ind))
261+
end
262+
256263
function getindex(b::AbstractUnitRange{Int}, K::Block{1})
257264
@boundscheck K == Block(1) || throw(BlockBoundsError(b, K))
258265
b

test/test_blockindices.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,32 @@ end
296296
@test checkindex(Bool, b, Block(1))
297297
@test checkindex(Bool, b, Block(3))
298298
@test !checkindex(Bool, b, Block(4))
299+
# treat b as the array, and check against the axis of b
299300
@test checkbounds(Bool, b, Block(1)[1])
301+
@test checkbounds(Bool, b, Block(1)[1:1])
300302
@test !checkbounds(Bool, b, Block(1)[2])
303+
@test checkbounds(Bool, b, Block(2)[1])
304+
@test checkbounds(Bool, b, Block(2)[1:2])
305+
@test !checkbounds(Bool, b, Block(2)[3])
306+
@test checkbounds(Bool, b, Block(3)[1])
307+
@test checkbounds(Bool, b, Block(3)[3])
308+
@test checkbounds(Bool, b, Block(3)[1:3])
309+
@test !checkbounds(Bool, b, Block(3)[4])
301310
@test !checkbounds(Bool, b, Block(0)[1])
302311
@test !checkbounds(Bool, b, Block(1)[0])
312+
# treat b as the axis
313+
@test checkindex(Bool, b, Block(1)[1])
314+
@test checkindex(Bool, b, Block(1)[1:1])
315+
@test !checkindex(Bool, b, Block(1)[2])
316+
@test checkindex(Bool, b, Block(2)[1])
317+
@test checkindex(Bool, b, Block(2)[1:2])
318+
@test !checkindex(Bool, b, Block(2)[3])
319+
@test checkindex(Bool, b, Block(3)[1])
320+
@test checkindex(Bool, b, Block(3)[3])
321+
@test checkindex(Bool, b, Block(3)[1:3])
322+
@test !checkindex(Bool, b, Block(3)[4])
323+
@test !checkindex(Bool, b, Block(0)[1])
324+
@test !checkindex(Bool, b, Block(1)[0])
303325
end
304326

305327
@testset "Slice" begin

0 commit comments

Comments
 (0)