@@ -26,7 +26,13 @@ to_index(::BlockRange) = throw(ArgumentError("BlockRange must be converted by to
2626
2727@inline  to_indices (A, inds, I:: Tuple{Block{1}, Vararg{Any}} ) = 
2828    (unblock (A, inds, I), to_indices (A, _maybetail (inds), tail (I))... )
29- @inline  to_indices (A, inds, I:: Tuple{BlockRange{1,R}, Vararg{Any}} ) where  R = 
29+ @inline  to_indices (A, inds, I:: Tuple{BlockRange{1}, Vararg{Any}} ) = 
30+     (unblock (A, inds, I), to_indices (A, _maybetail (inds), tail (I))... )
31+ @inline  to_indices (A, inds, I:: Tuple{AbstractVector{<:Block{1}}, Vararg{Any}} ) = 
32+     (unblock (A, inds, I), to_indices (A, _maybetail (inds), tail (I))... )
33+ @inline  to_indices (A, inds, I:: Tuple{AbstractVector{<:BlockRange{1}}, Vararg{Any}} ) = 
34+     (unblock (A, inds, I), to_indices (A, _maybetail (inds), tail (I))... )
35+ @inline  to_indices (A, inds, I:: Tuple {AbstractVector{<: AbstractVector{<:Block{1}} }, Vararg{Any}}) = 
3036    (unblock (A, inds, I), to_indices (A, _maybetail (inds), tail (I))... )
3137@inline  to_indices (A, inds, I:: Tuple{BlockIndex{1}, Vararg{Any}} ) = 
3238    (inds[1 ][I[1 ]], to_indices (A, _maybetail (inds), tail (I))... )
@@ -38,12 +44,20 @@ to_index(::BlockRange) = throw(ArgumentError("BlockRange must be converted by to
3844    (unblock (A, inds, I), to_indices (A, _maybetail (inds), tail (I))... )
3945@inline  to_indices (A, inds, I:: Tuple{AbstractVector{<:BlockIndices{1}}, Vararg{Any}} ) = 
4046    (unblock (A, inds, I), to_indices (A, _maybetail (inds), tail (I))... )
47+ @inline  to_indices (A, inds, I:: Tuple {AbstractVector{<: AbstractVector{<:BlockIndex{1}} }, Vararg{Any}}) = 
48+     (unblock (A, inds, I), to_indices (A, _maybetail (inds), tail (I))... )
49+ @inline  to_indices (A, inds, I:: Tuple {AbstractVector{<: AbstractVector{<:BlockIndices{1}} }, Vararg{Any}}) = 
50+     (unblock (A, inds, I), to_indices (A, _maybetail (inds), tail (I))... )
51+ @inline  to_indices (A, inds, I:: Tuple {AbstractVector{<: AbstractVector{<:AbstractVector{<:BlockIndex{1}}} }, Vararg{Any}}) = 
52+     (unblock (A, inds, I), to_indices (A, _maybetail (inds), tail (I))... )
4153
4254
4355#  splat out higher dimensional blocks
4456#  this mimics view of a CartesianIndex
4557@inline  to_indices (A, inds, I:: Tuple{Block, Vararg{Any}} ) = 
4658    to_indices (A, inds, (Block .(I[1 ]. n)... , tail (I)... ))
59+ @inline  to_indices (A, inds, I:: Tuple{BlockRange, Vararg{Any}} ) = 
60+     to_indices (A, inds, (BlockRange .(tuple .(I[1 ]. indices))... , tail (I)... ))
4761@inline  to_indices (A, inds, I:: Tuple{BlockIndex, Vararg{Any}} ) = 
4862    to_indices (A, inds, (BlockIndex .(I[1 ]. I, I[1 ]. α)... , tail (I)... ))
4963@inline  to_indices (A, inds, I:: Tuple{BlockIndices, Vararg{Any}} ) = 
@@ -57,8 +71,57 @@ to_index(::BlockRange) = throw(ArgumentError("BlockRange must be converted by to
5771@inline  to_indices (A, I:: Tuple{Block, Vararg{Any}} ) =  to_indices (A, axes (A), I)
5872@inline  to_indices (A, I:: Tuple{BlockRange, Vararg{Any}} ) =  to_indices (A, axes (A), I)
5973@inline  to_indices (A, I:: Tuple{AbstractVector{<:Block{1}}, Vararg{Any}} ) =  to_indices (A, axes (A), I)
74+ @inline  to_indices (A, I:: Tuple{AbstractVector{<:BlockRange{1}}, Vararg{Any}} ) =  to_indices (A, axes (A), I)
75+ @inline  to_indices (A, I:: Tuple {AbstractVector{<: AbstractVector{<:Block{1}} }, Vararg{Any}}) =  to_indices (A, axes (A), I)
6076@inline  to_indices (A, I:: Tuple{AbstractVector{<:BlockIndex{1}}, Vararg{Any}} ) =  to_indices (A, axes (A), I)
6177@inline  to_indices (A, I:: Tuple{AbstractVector{<:BlockIndices{1}}, Vararg{Any}} ) =  to_indices (A, axes (A), I)
78+ @inline  to_indices (A, I:: Tuple {AbstractVector{<: AbstractVector{<:BlockIndex{1}} }, Vararg{Any}}) =  to_indices (A, axes (A), I)
79+ @inline  to_indices (A, I:: Tuple {AbstractVector{<: AbstractVector{<:BlockIndices{1}} }, Vararg{Any}}) =  to_indices (A, axes (A), I)
80+ @inline  to_indices (A, I:: Tuple {AbstractVector{<: AbstractVector{<:AbstractVector{<:BlockIndex{1}}} }, Vararg{Any}}) =  to_indices (A, axes (A), I)
81+ 
82+ # # BlockedLogicalIndex
83+ #  Blocked version of `LogicalIndex`:
84+ #  https://github.com/JuliaLang/julia/blob/3e2f90fbb8f6b0651f2601d7599c55d4e3efd496/base/multidimensional.jl#L819-L831
85+ const  BlockedLogicalIndex{T,R<: LogicalIndex{T} ,BS<: Tuple{AbstractUnitRange{<:Integer}} } =  BlockedVector{T,R,BS}
86+ function  BlockedLogicalIndex (I:: AbstractVector{Bool} )
87+     blocklengths =  map (b ->  count (view (I, b)), BlockRange (I))
88+     return  BlockedVector (LogicalIndex (I), blocklengths)
89+ end 
90+ #  https://github.com/JuliaLang/julia/blob/3e2f90fbb8f6b0651f2601d7599c55d4e3efd496/base/multidimensional.jl#L838-L839
91+ show (io:: IO , r:: BlockedLogicalIndex ) =  print (io, blockcollect (r))
92+ print_array (io:: IO , X:: BlockedLogicalIndex ) =  print_array (io, blockcollect (X))
93+ 
94+ #  Blocked version of `to_index(::AbstractArray{Bool})`:
95+ #  https://github.com/JuliaLang/julia/blob/3e2f90fbb8f6b0651f2601d7599c55d4e3efd496/base/indices.jl#L309
96+ function  to_index (I:: AbstractBlockVector{Bool} )
97+     return  BlockedLogicalIndex (I)
98+ end 
99+ 
100+ #  Blocked version of `collect(::LogicalIndex)`:
101+ #  https://github.com/JuliaLang/julia/blob/3e2f90fbb8f6b0651f2601d7599c55d4e3efd496/base/multidimensional.jl#L837
102+ #  Without this definition, `collect` will try to call `getindex` on the `LogicalIndex`
103+ #  which isn't defined.
104+ collect (I:: BlockedLogicalIndex ) =  collect (I. blocks)
105+ 
106+ #  Iteration of BlockedLogicalIndex is just iteration over the underlying
107+ #  LogicalIndex, which is implemented here:
108+ #  https://github.com/JuliaLang/julia/blob/3e2f90fbb8f6b0651f2601d7599c55d4e3efd496/base/multidimensional.jl#L840-L890
109+ @inline  iterate (I:: BlockedLogicalIndex ) =  iterate (I. blocks)
110+ @inline  iterate (I:: BlockedLogicalIndex , s) =  iterate (I. blocks, s)
111+ 
112+ # # Boundscheck for BlockLogicalindex
113+ #  Like for LogicalIndex, map all calls to mask:
114+ #  https://github.com/JuliaLang/julia/blob/3e2f90fbb8f6b0651f2601d7599c55d4e3efd496/base/multidimensional.jl#L892-L897
115+ checkbounds (:: Type{Bool} , A:: AbstractArray , i:: BlockedLogicalIndex ) =  checkbounds (Bool, A, i. blocks. mask)
116+ #  `checkbounds_indices` has been handled via `I::AbstractArray` fallback
117+ checkindex (:: Type{Bool} , inds:: AbstractUnitRange , i:: BlockedLogicalIndex ) =  checkindex (Bool, inds, i. blocks. mask)
118+ checkindex (:: Type{Bool} , inds:: Tuple , i:: BlockedLogicalIndex ) =  checkindex (Bool, inds, i. blocks. mask)
119+ 
120+ #  Instantiate the BlockedLogicalIndex when constructing a SubArray, similar to
121+ #  `ensure_indexable(I::Tuple{LogicalIndex,Vararg{Any}})`:
122+ #  https://github.com/JuliaLang/julia/blob/3e2f90fbb8f6b0651f2601d7599c55d4e3efd496/base/multidimensional.jl#L918
123+ @inline  ensure_indexable (I:: Tuple{BlockedLogicalIndex,Vararg{Any}} ) = 
124+     (blockcollect (I[1 ]), ensure_indexable (tail (I))... )
62125
63126@propagate_inbounds  reindex (idxs:: Tuple{BlockSlice{<:BlockRange}, Vararg{Any}} ,
64127        subidxs:: Tuple{BlockSlice{<:BlockIndices}, Vararg{Any}} ) = 
0 commit comments