92
92
# TODO : Move to `GradedUnitRanges` or `BlockArraysExtensions`.
93
93
to_block (I:: Block{1} ) = I
94
94
to_block (I:: BlockIndexRange{1} ) = Block (I)
95
+ to_block (I:: BlockIndexVector ) = Block (I)
95
96
to_block_indices (I:: Block{1} ) = Colon ()
96
97
to_block_indices (I:: BlockIndexRange{1} ) = only (I. indices)
98
+ to_block_indices (I:: BlockIndexVector ) = I. indices
97
99
98
100
function Base. view (
99
- a:: AbstractBlockSparseArray{<:Any,N} , I:: Vararg{Union{Block{1},BlockIndexRange{1}},N}
101
+ a:: AbstractBlockSparseArray{<:Any,N} ,
102
+ I:: Vararg{Union{Block{1},BlockIndexRange{1},BlockIndexVector},N} ,
100
103
) where {N}
101
104
return @views a[to_block .(I)... ][to_block_indices .(I)... ]
102
105
end
@@ -108,7 +111,7 @@ function Base.view(
108
111
end
109
112
function Base. view (
110
113
a:: SubArray{T,N,<:AbstractBlockSparseArray{T,N}} ,
111
- I:: Vararg{Union{Block{1},BlockIndexRange{1}},N} ,
114
+ I:: Vararg{Union{Block{1},BlockIndexRange{1},BlockIndexVector },N} ,
112
115
) where {T,N}
113
116
return @views a[to_block .(I)... ][to_block_indices .(I)... ]
114
117
end
@@ -205,8 +208,14 @@ function BlockArrays.viewblock(
205
208
end
206
209
207
210
function to_blockindexrange (
208
- a:: BlockIndices {<: BlockVector{<:BlockIndex{1},<:Vector{<:BlockIndexRange{1}}} },
209
- I:: Block{1} ,
211
+ a:: BlockSlice {<: BlockVector{<:BlockIndex{1},<:Vector{<:BlockIndexRange{1}}} }, I:: Block{1}
212
+ )
213
+ # TODO : Ideally we would just use `a.blocks[I]` but that doesn't
214
+ # work right now.
215
+ return blocks (a. block)[Int (I)]
216
+ end
217
+ function to_blockindexrange (
218
+ a:: BlockIndices{<:BlockVector{<:BlockIndex{1},<:Vector{<:BlockIndexVector}}} , I:: Block{1}
210
219
)
211
220
# TODO : Ideally we would just use `a.blocks[I]` but that doesn't
212
221
# work right now.
@@ -247,20 +256,29 @@ end
247
256
248
257
# Block slice of the result of slicing `@view a[2:5, 2:5]`.
249
258
# TODO : Move this to `BlockArraysExtensions`.
250
- const BlockedSlice = Union{
251
- BlockSlice{<: BlockVector{<:BlockIndex{1},<:Vector{<:BlockIndexRange{1}}} },
252
- BlockIndices{<: BlockVector{<:BlockIndex{1},<:Vector{<:BlockIndexVector}} },
259
+ const BlockIndexRangeSlice = BlockSlice{
260
+ <: BlockVector{<:BlockIndex{1},<:Vector{<:BlockIndexRange{1}}}
261
+ }
262
+ const BlockIndexVectorSlice = BlockSlice{
263
+ <: BlockVector{<:BlockIndex{1},<:Vector{<:BlockIndexVector}}
253
264
}
265
+ const BlockedSlice = Union{BlockIndexRangeSlice,BlockIndexVectorSlice}
254
266
255
267
function Base. view (
256
268
a:: SubArray{T,N,<:AbstractBlockSparseArray{T,N},<:Tuple{Vararg{BlockedSlice,N}}} ,
257
269
block:: Union{Block{N},BlockIndexRange{N}} ,
258
270
) where {T,N}
259
271
return viewblock (a, block)
260
272
end
273
+ function Base. view (
274
+ a:: SubArray{T,N,<:AbstractBlockSparseArray{T,N},<:Tuple{Vararg{BlockIndexRangeSlice,N}}} ,
275
+ block:: Union{Block{N},BlockIndexRange{N}} ,
276
+ ) where {T,N}
277
+ return viewblock (a, block)
278
+ end
261
279
function Base. view (
262
280
a:: SubArray{T,N,<:AbstractBlockSparseArray{T,N},<:Tuple{Vararg{BlockedSlice,N}}} ,
263
- block:: Vararg{Union{Block{1},BlockIndexRange{1}},N} ,
281
+ block:: Vararg{Union{Block{1},BlockIndexRange{1},BlockIndexVector },N} ,
264
282
) where {T,N}
265
283
return viewblock (a, block... )
266
284
end
0 commit comments