Stream: helpdesk (published)

Topic: ✔ How to check if a index of a sparse array is 'stored'?


view this post on Zulip Mason Protter (Nov 02 2024 at 14:51):

Is there some simple way to check if there's a stored value at a specific index of a sparse array? I'm imagining some function like

julia> A = sprand(3, 3, 0.5)
3×3 SparseMatrixCSC{Float64, Int64} with 5 stored entries:
 0.593332   ⋅         ⋅
  ⋅        0.349431   ⋅
 0.860202  0.653576  0.819548

julia> isstored(A, 1, 1)
true

julia> isstored(A, 1, 2)
false

view this post on Zulip Mason Protter (Nov 02 2024 at 14:54):

oh, turns out there is in fact a function for this in Base that's just not exported with the name I made up:

julia> Base.isstored(A, 1, 1)
true

julia> Base.isstored(A, 1, 2)
false

Guess I should have checked that :sweat_smile:

view this post on Zulip Notification Bot (Nov 02 2024 at 14:54):

Mason Protter has marked this topic as resolved.

view this post on Zulip Mason Protter (Nov 02 2024 at 21:48):

opened a PR to make it public: https://github.com/JuliaLang/julia/pull/56421

view this post on Zulip John Lapeyre (Nov 02 2024 at 23:08):

It's a bit mysterious. The function isstored is defined and implemented for AbstractArray in abstractarray.jl . But it's not exported and it's not referred to anywhere in Base. It is tested in Base. And the SparseArrays methods extend it. It kind of looks like its current state is not intentional.

view this post on Zulip Mason Protter (Nov 02 2024 at 23:17):

It's for special matrix types with sparity like SparseMatrix, BandedMatrix, UpperTriangular, etc.

view this post on Zulip Mason Protter (Nov 02 2024 at 23:18):

(none of which are defined in Base so it's just a default implementation there in Base)


Last updated: Nov 06 2024 at 04:40 UTC