Skip to content

Commit f3ff0d7

Browse files
committed
Fix ambiguities
1 parent 33b8200 commit f3ff0d7

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

src/abstractblocksparsearray/views.jl

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,27 @@ function Base.view(
189189
) where {T,N}
190190
return viewblock(a, block...)
191191
end
192-
# Fix ambiguity error with BlockArrays.jl.
192+
193+
# Disambiguate between block reindexing of blockwise views
194+
# (`BlockSliceCollection`) and subblockwise views (`SubBlockSliceCollection`),
195+
# which both include `Base.Slice`.
193196
function Base.view(
194-
a::SubArray{
195-
T,
196-
N,
197-
<:AbstractBlockSparseArray{T,N},
198-
<:Tuple{Vararg{Union{Base.Slice,BlockSlice{Union{},<:Integer}},N}},
199-
},
197+
a::SubArray{T,N,<:AbstractBlockSparseArray{T,N},<:Tuple{Vararg{Base.Slice,N}}},
200198
block::Block{N},
201199
) where {T,N}
202200
return viewblock(a, block)
203201
end
204202

203+
# Block reindexing of blockwise views (`BlockSliceCollection`).
204+
function viewblock_blockslice(a::SubArray{<:Any,N}, block::Vararg{Block{1},N}) where {N}
205+
I = CartesianIndex(Int.(block))
206+
# TODO: Use `eachblockstoredindex`.
207+
if I eachstoredindex(blocks(a))
208+
return blocks(a)[I]
209+
end
210+
return BlockView(parent(a), Block.(Base.reindex(parentindices(blocks(a)), Tuple(I))))
211+
end
212+
205213
# XXX: TODO: Distinguish if a sub-view of the block needs to be taken!
206214
# Define a new `SubBlockSlice` which is used in:
207215
# `@interface interface(a) to_indices(a, inds, I::Tuple{UnitRange{<:Integer},Vararg{Any}})`
@@ -211,12 +219,17 @@ function BlockArrays.viewblock(
211219
a::SubArray{T,N,<:AbstractBlockSparseArray{T,N},<:Tuple{Vararg{BlockSliceCollection,N}}},
212220
block::Vararg{Block{1},N},
213221
) where {T,N}
214-
I = CartesianIndex(Int.(block))
215-
# TODO: Use `eachblockstoredindex`.
216-
if I eachstoredindex(blocks(a))
217-
return blocks(a)[I]
218-
end
219-
return BlockView(parent(a), Block.(Base.reindex(parentindices(blocks(a)), Tuple(I))))
222+
return viewblock_blockslice(a, block...)
223+
end
224+
225+
# Disambiguate between block reindexing of blockwise views
226+
# (`BlockSliceCollection`) and subblockwise views (`SubBlockSliceCollection`),
227+
# which both include `Base.Slice`.
228+
function BlockArrays.viewblock(
229+
a::SubArray{T,N,<:AbstractBlockSparseArray{T,N},<:Tuple{Vararg{Base.Slice,N}}},
230+
block::Vararg{Block{1},N},
231+
) where {T,N}
232+
return viewblock_blockslice(a, block...)
220233
end
221234

222235
function to_blockindexrange(

0 commit comments

Comments
 (0)