|
364 | 364 | function Base.size(a::SparseSubArrayBlocks)
|
365 | 365 | return length.(axes(a))
|
366 | 366 | 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 | + |
368 | 380 | # TODO: Define `getstoredindex`, `getunstoredindex` instead.
|
369 | 381 | function Base.getindex(a::SparseSubArrayBlocks{<:Any,N}, I::Vararg{Int,N}) where {N}
|
370 | 382 | # 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
|
400 | 412 | # TODO: Implement this properly.
|
401 | 413 | return true
|
402 | 414 | end
|
| 415 | + |
403 | 416 | 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)...)) |
405 | 424 | end
|
| 425 | + |
406 | 426 | # TODO: Either make this the generic interface or define
|
407 | 427 | # `SparseArraysBase.sparse_storage`, which is used
|
408 | 428 | # to defined this.
|
|
0 commit comments