Skip to content

Commit afc3f87

Browse files
committed
Get logical indexing working
1 parent 37c843f commit afc3f87

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/BlockArraysExtensions/BlockArraysExtensions.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,11 @@ function blockrange(axis::AbstractUnitRange, r::BlockIndexVector)
376376
return Block(r):Block(r)
377377
end
378378

379-
function blockrange(axis::AbstractUnitRange, r::Vector{<:BlockIndexVector})
380-
return map(Block, r)
379+
function blockrange(
380+
axis::AbstractUnitRange,
381+
r::BlockVector{<:BlockIndex{1},<:AbstractVector{<:BlockIndexVector}},
382+
)
383+
return map(Block, blocks(r))
381384
end
382385

383386
function blockrange(axis::AbstractUnitRange, r)

src/abstractblocksparsearray/views.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,9 @@ end
247247

248248
# Block slice of the result of slicing `@view a[2:5, 2:5]`.
249249
# TODO: Move this to `BlockArraysExtensions`.
250-
const BlockedSlice = BlockSlice{
251-
<:BlockVector{<:BlockIndex{1},<:Vector{<:BlockIndexRange{1}}}
250+
const BlockedSlice = Union{
251+
BlockSlice{<:BlockVector{<:BlockIndex{1},<:Vector{<:BlockIndexRange{1}}}},
252+
BlockIndices{<:BlockVector{<:BlockIndex{1},<:Vector{<:BlockIndexVector}}},
252253
}
253254

254255
function Base.view(
@@ -269,6 +270,11 @@ function BlockArrays.viewblock(
269270
) where {T,N}
270271
return viewblock(a, to_tuple(block)...)
271272
end
273+
274+
_block(x) = error("Not implemented.")
275+
_block(x::BlockSlice) = x.block
276+
_block(x::BlockIndices) = x.blocks
277+
272278
# TODO: Define `@interface BlockSparseArrayInterface() viewblock`.
273279
function BlockArrays.viewblock(
274280
a::SubArray{T,N,<:AbstractBlockSparseArray{T,N},<:Tuple{Vararg{BlockedSlice,N}}},
@@ -279,7 +285,7 @@ function BlockArrays.viewblock(
279285
# TODO: Ideally we would use this but it outputs a Vector,
280286
# not a range:
281287
# return parentindices(a)[dim].block[I[dim]]
282-
return blocks(parentindices(a)[dim].block)[Int(I[dim])]
288+
return blocks(_block(parentindices(a)[dim]))[Int(I[dim])]
283289
end
284290
return @view parent(a)[brs...]
285291
end

0 commit comments

Comments
 (0)