Skip to content

Commit ea34937

Browse files
committed
Fix more slicing
1 parent 71b386b commit ea34937

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/BlockArraysExtensions/BlockArraysExtensions.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,20 @@ function blockrange(axis::AbstractUnitRange, r::NonBlockedVector)
258258
return Block(1):Block(1)
259259
end
260260

261+
# Find the blocks associated with the block slice.
262+
# This results from slices like `[Block(1), Block(2)]`
263+
# or `[Block(1)[1:2], Block(2)[2:3]]`.
264+
# This would be easier once something like:
265+
# https://github.com/JuliaArrays/BlockArrays.jl/pull/459
266+
# is implemented.
261267
function blockrange(axis::AbstractUnitRange, r::AbstractBlockVector)
262-
# XXX: This may be the inverse permutation.
263-
return Block.(indexin(blocks(r), blocks(axis)))
268+
inds = map(blocks(r)) do b_r
269+
findfirst(blocks(axis)) do b_axis
270+
return b_r b_axis
271+
end
272+
end
273+
any(isnothing, inds) && error("Block not found.")
274+
return Block.(inds)
264275
end
265276

266277
function blockrange(axis::AbstractUnitRange, r)

src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,6 @@ function Base.to_indices(
5959
return @interface BlockSparseArrayInterface() to_indices(a, inds, I)
6060
end
6161

62-
# a[[Block(1)[1:2], Block(2)[1:2]], [Block(1)[1:2], Block(2)[1:2]]]
63-
function Base.to_indices(
64-
a::AnyAbstractBlockSparseArray, inds, I::Tuple{Vector{<:BlockIndexRange{1}},Vararg{Any}}
65-
)
66-
return to_indices(a, inds, (mortar(I[1]), Base.tail(I)...))
67-
end
68-
6962
# BlockArrays `AbstractBlockArray` interface
7063
function BlockArrays.blocks(a::AnyAbstractBlockSparseArray)
7164
@interface BlockSparseArrayInterface() blocks(a)

0 commit comments

Comments
 (0)