Skip to content

Commit b4991a9

Browse files
committed
Fix tests
1 parent f3ff0d7 commit b4991a9

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

src/BlockArraysExtensions/BlockArraysExtensions.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ function _blockslice(x, y::AbstractVector)
8888
return BlockIndices(x, y)
8989
end
9090

91+
# TODO: Constrain the type of `BlockIndices` more, this seems
92+
# to assume that `S.blocks` is a list of blocks as opposed to
93+
# a flat list of block indices like the definition below.
9194
function Base.getindex(S::BlockIndices, i::BlockSlice{<:Block{1}})
9295
# TODO: Check that `i.indices` is consistent with `S.indices`.
9396
# It seems like this isn't handling the case where `i` is a
@@ -96,6 +99,13 @@ function Base.getindex(S::BlockIndices, i::BlockSlice{<:Block{1}})
9699
return _blockslice(S.blocks[Int(Block(i))], S.indices[Block(i)])
97100
end
98101

102+
function Base.getindex(
103+
S::BlockIndices{<:AbstractBlockVector{<:BlockIndex{1}}}, i::BlockSlice{<:Block{1}}
104+
)
105+
@assert length(S.indices[Block(i)]) == length(i.indices)
106+
return _blockslice(S.blocks[Block(i)], S.indices[Block(i)])
107+
end
108+
99109
# This is used in slicing like:
100110
# a = BlockSparseArray{Float64}([2, 2, 2, 2], [2, 2, 2, 2])
101111
# I = BlockedVector([Block(4), Block(3), Block(2), Block(1)], [2, 2])

src/abstractblocksparsearray/views.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,15 @@ function Base.view(
316316
) where {T,N}
317317
return viewblock(a, block...)
318318
end
319+
# Fix ambiguity error.
320+
function Base.view(
321+
a::SubArray{
322+
T,N,<:AbstractBlockSparseArray{T,N},<:Tuple{Vararg{SubBlockSliceCollection,N}}
323+
},
324+
block::Vararg{Block{1},N},
325+
) where {T,N}
326+
return viewblock(a, block...)
327+
end
319328
function BlockArrays.viewblock(
320329
a::SubArray{
321330
T,N,<:AbstractBlockSparseArray{T,N},<:Tuple{Vararg{SubBlockSliceCollection,N}}

src/blocksparsearrayinterface/blocksparsearrayinterface.jl

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,19 +222,25 @@ end
222222

223223
# a[mortar([Block(1)[1:2], Block(2)[1:3]]), mortar([Block(1)[1:2], Block(2)[1:3]])]
224224
# a[[Block(1)[1:2], Block(2)[1:3]], [Block(1)[1:2], Block(2)[1:3]]]
225-
@interface ::AbstractBlockSparseArrayInterface function Base.to_indices(
226-
a, inds, I::Tuple{BlockVector{<:BlockIndex{1},<:Vector{<:BlockIndexRange{1}}},Vararg{Any}}
227-
)
228-
I1 = BlockIndices(I[1], blockedunitrange_getindices(inds[1], I[1]))
229-
return (I1, to_indices(a, Base.tail(inds), Base.tail(I))...)
230-
end
231-
232225
@interface ::AbstractBlockSparseArrayInterface function Base.to_indices(
233226
a,
234227
inds,
235-
I::Tuple{BlockVector{<:BlockIndex{1},<:Vector{<:BlockIndexVector{1}}},Vararg{Any}},
228+
I::Tuple{
229+
BlockVector{<:BlockIndex{1},<:Vector{<:Union{BlockIndexRange{1},BlockIndexVector{1}}}},
230+
Vararg{Any},
231+
},
236232
)
237-
I1 = BlockIndices(I[1], blockedunitrange_getindices(inds[1], I[1]))
233+
# Index the `inds` by the `BlockIndexRange`/`BlockIndexVector`s on each block
234+
# in order to canonicalize the indices and preserve metadata,
235+
# such as sector data for symmetric tensors.
236+
bs = mortar(
237+
map(blocks(I[1])) do bi
238+
b = Block(bi)
239+
binds = only(bi.indices)
240+
return BlockIndexVector(b, Base.axes1(inds[1][b])[binds])
241+
end,
242+
)
243+
I1 = BlockIndices(bs, blockedunitrange_getindices(inds[1], I[1]))
238244
return (I1, to_indices(a, Base.tail(inds), Base.tail(I))...)
239245
end
240246
@interface ::AbstractBlockSparseArrayInterface function Base.to_indices(

0 commit comments

Comments
 (0)