Skip to content

Commit 485185d

Browse files
committed
More generalizations
1 parent 247cacc commit 485185d

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

src/BlockArraysExtensions/blockedunitrange.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,19 @@ function blockedunitrange_getindices(
176176
return mortar(map(b -> a[b], blocks(indices)))
177177
end
178178

179+
function blockedunitrange_getindices(
180+
a::AbstractBlockedUnitRange,
181+
indices::BlockVector{<:BlockIndex{1},<:Vector{<:BlockIndexVector{1}}},
182+
)
183+
return mortar(map(b -> a[b], blocks(indices)))
184+
end
185+
function blockedunitrange_getindices(
186+
a::AbstractBlockedUnitRange,
187+
indices::BlockVector{<:GenericBlockIndex{1},<:Vector{<:BlockIndexVector{1}}},
188+
)
189+
return mortar(map(b -> a[b], blocks(indices)))
190+
end
191+
179192
function blockedunitrange_getindices(
180193
a::AbstractBlockedUnitRange, indices::AbstractVector{Bool}
181194
)

src/abstractblocksparsearray/wrappedabstractblocksparsearray.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,36 @@ function Base.to_indices(
7878
return @interface interface(a) to_indices(a, inds, I)
7979
end
8080

81+
# a[mortar([Block(1)[[1, 2]], Block(2)[[1, 3]]])]
82+
function Base.to_indices(
83+
a::AnyAbstractBlockSparseArray,
84+
inds,
85+
I::Tuple{BlockVector{<:BlockIndex{1},<:Vector{<:BlockIndexVector{1}}},Vararg{Any}},
86+
)
87+
return @interface interface(a) to_indices(a, inds, I)
88+
end
89+
function Base.to_indices(
90+
a::AnyAbstractBlockSparseArray,
91+
inds,
92+
I::Tuple{BlockVector{<:GenericBlockIndex{1},<:Vector{<:BlockIndexVector{1}}},Vararg{Any}},
93+
)
94+
return @interface interface(a) to_indices(a, inds, I)
95+
end
96+
8197
# a[[Block(1)[1:2], Block(2)[1:2]], [Block(1)[1:2], Block(2)[1:2]]]
8298
function Base.to_indices(
8399
a::AnyAbstractBlockSparseArray, inds, I::Tuple{Vector{<:BlockIndexRange{1}},Vararg{Any}}
84100
)
85101
return to_indices(a, inds, (mortar(I[1]), Base.tail(I)...))
86102
end
87103

104+
# a[[Block(1)[[1, 2]], Block(2)[[1, 2]]], [Block(1)[[1, 2]], Block(2)[[1, 2]]]]
105+
function Base.to_indices(
106+
a::AnyAbstractBlockSparseArray, inds, I::Tuple{Vector{<:BlockIndexVector{1}},Vararg{Any}}
107+
)
108+
return to_indices(a, inds, (mortar(I[1]), Base.tail(I)...))
109+
end
110+
88111
# BlockArrays `AbstractBlockArray` interface
89112
function BlockArrays.blocks(a::AnyAbstractBlockSparseArray)
90113
@interface interface(a) blocks(a)

src/blocksparsearrayinterface/blocksparsearrayinterface.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,23 @@ end
229229
return (I1, to_indices(a, Base.tail(inds), Base.tail(I))...)
230230
end
231231

232+
@interface ::AbstractBlockSparseArrayInterface function Base.to_indices(
233+
a,
234+
inds,
235+
I::Tuple{BlockVector{<:BlockIndex{1},<:Vector{<:BlockIndexVector{1}}},Vararg{Any}},
236+
)
237+
I1 = BlockIndices(I[1], blockedunitrange_getindices(inds[1], I[1]))
238+
return (I1, to_indices(a, Base.tail(inds), Base.tail(I))...)
239+
end
240+
@interface ::AbstractBlockSparseArrayInterface function Base.to_indices(
241+
a,
242+
inds,
243+
I::Tuple{BlockVector{<:GenericBlockIndex{1},<:Vector{<:BlockIndexVector{1}}},Vararg{Any}},
244+
)
245+
I1 = BlockIndices(I[1], blockedunitrange_getindices(inds[1], I[1]))
246+
return (I1, to_indices(a, Base.tail(inds), Base.tail(I))...)
247+
end
248+
232249
# a[BlockVector([Block(2), Block(1)], [2]), BlockVector([Block(2), Block(1)], [2])]
233250
# Permute and merge blocks.
234251
# TODO: This isn't merging blocks yet, that needs to be implemented that.

0 commit comments

Comments
 (0)