Skip to content

Commit e80370e

Browse files
committed
More general eachstoredindex/isstored for SubArray blocks
1 parent 5e53555 commit e80370e

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/blocksparsearrayinterface/blocksparsearrayinterface.jl

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,19 @@ end
364364
function Base.size(a::SparseSubArrayBlocks)
365365
return length.(axes(a))
366366
end
367-
# TODO: Define `isstored`.
367+
368+
# TODO: Make a faster version for when the slice is blockwise.
369+
function SparseArraysBase.isstored(
370+
a::SparseSubArrayBlocks{<:Any,N}, I::Vararg{Int,N}
371+
) where {N}
372+
J = Base.reindex(parentindices(a.array), to_indices(a.array, Block.(I)))
373+
# TODO: Try doing this blockwise when possible rather
374+
# than elementwise.
375+
return any(Iterators.product(J...)) do K
376+
return isstored(parent(a.array), K...)
377+
end
378+
end
379+
368380
# TODO: Define `getstoredindex`, `getunstoredindex` instead.
369381
function Base.getindex(a::SparseSubArrayBlocks{<:Any,N}, I::Vararg{Int,N}) where {N}
370382
# TODO: Should this be defined as `@view a.array[Block(I)]` instead?
@@ -400,9 +412,17 @@ function Base.isassigned(a::SparseSubArrayBlocks{<:Any,N}, I::Vararg{Int,N}) whe
400412
# TODO: Implement this properly.
401413
return true
402414
end
415+
403416
function SparseArraysBase.eachstoredindex(::IndexCartesian, a::SparseSubArrayBlocks)
404-
return eachstoredindex(view(blocks(parent(a.array)), blockrange(a)...))
417+
return filter(eachindex(a)) do I
418+
return isstored(a, I)
419+
end
420+
421+
## # TODO: This only works for blockwise slices, i.e. slices using
422+
## # `BlockSliceCollection`.
423+
## return eachstoredindex(view(blocks(parent(a.array)), blockrange(a)...))
405424
end
425+
406426
# TODO: Either make this the generic interface or define
407427
# `SparseArraysBase.sparse_storage`, which is used
408428
# to defined this.

0 commit comments

Comments
 (0)