Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/views.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ collect(I::BlockedLogicalIndex) = collect(I.blocks)
checkbounds(::Type{Bool}, A::AbstractArray, i::BlockedLogicalIndex) = checkbounds(Bool, A, i.blocks.mask)
# `checkbounds_indices` has been handled via `I::AbstractArray` fallback
checkindex(::Type{Bool}, inds::AbstractUnitRange, i::BlockedLogicalIndex) = checkindex(Bool, inds, i.blocks.mask)
checkindex(::Type{Bool}, inds::Tuple, i::BlockedLogicalIndex) = checkindex(Bool, inds, i.blocks.mask)

# Instantiate the BlockedLogicalIndex when constructing a SubArray, similar to
# `ensure_indexable(I::Tuple{LogicalIndex,Vararg{Any}})`:
Expand Down
11 changes: 11 additions & 0 deletions test/test_blockviews.jl
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ bview(a, b) = Base.invoke(view, Tuple{AbstractArray,Any}, a, b)
a = randn(6, 6)
for mask in ([true, true, false, false, true, false], BitVector([true, true, false, false, true, false]))
I = BlockedVector(mask, [3, 3])
@test Base.to_index(I) == BlockedLogicalIndex(I)
@test Base.to_index(I) == [1, 2, 5]
@test Base.to_index(I) isa BlockedLogicalIndex
@test to_indices(a, (I, I)) == to_indices(a, (mask, mask))
@test to_indices(a, (I, I)) == (BlockedVector(LogicalIndex(mask), [2, 1]), BlockedVector(LogicalIndex(mask), [2, 1]))
@test to_indices(a, (I, I)) isa Tuple{BlockedLogicalIndex{Int},BlockedLogicalIndex{Int}}
Expand All @@ -372,7 +375,15 @@ bview(a, b) = Base.invoke(view, Tuple{AbstractArray,Any}, a, b)
@test parentindices(view(a, I, I)) == (BlockedVector([1, 2, 5], [2, 1]), BlockedVector([1, 2, 5], [2, 1]))
@test parentindices(view(a, I, I)) isa Tuple{BlockedVector{Int,Vector{Int}},BlockedVector{Int,Vector{Int}}}
@test blocklengths.(Base.axes1.(parentindices(view(a, I, I)))) == ([2, 1], [2, 1])
@test sprint(show, BlockedLogicalIndex(I)) == "[1, 2, 5]"
end
bl = BlockedLogicalIndex(BlockedVector([true, true, false, false, true, false], [3, 3]))
@test sprint(show, "text/plain", bl) ==
"2-blocked 3-element BlockedVector{Int64, Base.LogicalIndex{Int64, BlockedVector{Bool, Vector{Bool}, Tuple{BlockedOneTo{Int64, Vector{Int64}}}}}, Tuple{BlockedOneTo{Int64, Vector{Int64}}}}:\n 1\n 2\n ─\n 5"
@test checkbounds(Bool, randn(6), bl)
@test !checkbounds(Bool, randn(5), bl)
@test checkindex(Bool, 1:6, bl)
@test !checkindex(Bool, 1:5, bl)
end
end

Expand Down
Loading