Skip to content

Commit 8785f64

Browse files
authored
Add checkindex for Blocks (#111)
1 parent b095f3f commit 8785f64

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BlockArrays"
22
uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
3-
version = "0.12.4"
3+
version = "0.12.5"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/blockaxis.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ Base.dataids(b::BlockedUnitRange) = Base.dataids(blocklasts(b))
187187
###
188188
# BlockedUnitRange interface
189189
###
190+
Base.checkindex(::Type{Bool}, b::BlockRange, K::Int) = checkindex(Bool, Int.(b), K)
191+
Base.checkindex(::Type{Bool}, b::AbstractUnitRange{Int}, K::Block{1}) = checkindex(Bool, blockaxes(b,1), Int(K))
192+
190193
function getindex(b::AbstractUnitRange{Int}, K::Block{1})
191194
@boundscheck K == Block(1) || throw(BlockBoundsError(b, K))
192195
b

test/test_blockindices.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,14 @@ end
239239
@testset "BlockIndex type piracy (#108)" begin
240240
@test zeros()[] == 0.0
241241
end
242+
243+
@testset "checkindex" begin
244+
b = blockedrange([1,2,3])
245+
@test !checkindex(Bool, b, Block(0))
246+
@test checkindex(Bool, b, Block(1))
247+
@test checkindex(Bool, b, Block(3))
248+
@test !checkindex(Bool, b, Block(4))
249+
end
242250
end
243251

244252
@testset "BlockSlice" begin

0 commit comments

Comments
 (0)