Skip to content

Make isstored public #56421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

MasonProtter
Copy link
Contributor

This is a useful function when working with sparse arrays, I think we should make it public but give a weak guarantee, letting people know that a result of true could be wrong (though a value of false should be trustworthy).

@jishnub jishnub added the docs This change adds or pertains to documentation label Nov 2, 2024
@nsajko nsajko added the sparse Sparse arrays label Nov 3, 2024
MasonProtter and others added 2 commits November 3, 2024 19:17
Co-authored-by: Lars Göttgens <lars.goettgens@gmail.com>
@MasonProtter MasonProtter added the arrays [a, r, r, a, y, s] label Nov 19, 2024
@MasonProtter
Copy link
Contributor Author

@LilithHafner could this get an assigned reviewer? I'm not sure how the bot system for it works or if it can be done retroactively.

@LilithHafner LilithHafner added the triage This should be discussed on a triage call label Jul 13, 2025
@LilithHafner LilithHafner self-assigned this Jul 13, 2025
@LilithHafner
Copy link
Member

This PR proposes expanding the public API of Julia so it should get discussed at Triage before merging. It seems reasonable to me, but I don't have the expertise to know for sure. @stevengj, are you willing to weigh in here?

@LilithHafner LilithHafner removed their assignment Jul 13, 2025
@halleysfifthinc
Copy link
Contributor

What about using a default of missing? That would allow a strong interpretation of the true cases, and would match the standard definition/use-case for missingness.

@stevengj
Copy link
Member

@MasonProtter, do you know of anyone that is using this function? I can't find anything on JuliaHub.

As far as I can tell, it is used only in stdlib/SparseArrays, and even there only in a single place: in the printing code in order to decide when to print a dot instead of a zero.

Without a better sense of its practical utility, I'm a little cautious about exporting it.

@MasonProtter
Copy link
Contributor Author

I'd like to use it in GraphDynamics.jl and Neuroblox.jl . We have sparse connection matrix structures that describe the interaction between subsystems, and there are somecases where I care if something is "stored" vs just a zero connection.

Maybe this is a sign I need to stop using SparseArrays though and go build a new type that better exposes this difference. It'd be too bad though if I had to do that though because there's a lot of features of SparseArrays I really like for what I'm doing here.

@stevengj
Copy link
Member

Using it for graphs is a good example. In that case, I'm in favor of just making this public.

@LilithHafner
Copy link
Member

From triage, why can't this live in LinearAlgebra (or possibly even SparseArrays with a weak dependency on LinearAlgebra)? isstored is a fairly SparseArrays-specific concept. For example a rank-1 matrix which stores two vectors and computes their product on demand... what is stored?

@MasonProtter
Copy link
Contributor Author

MasonProtter commented Jul 17, 2025

I don't see why it should be moved to another package. Base is the owner of AbstractArray, and isstored is basically a utility for AbstractArray subtypes to opt into. Base seems like the right place to me. I guess if Base really doesn't want to own it we could move it to LinearAlgebra, but I would say absolutely not SparseArrays, because SparseArrays depends on LinearAlgebra and not vice versa. LinearAlgebra has a lot of isstored overloads:

julia> methods(Base.isstored)
# 6 methods for generic function "isstored" from Base:
 [1] isstored(A::Bidiagonal, i::Int64, j::Int64)
     @ ~/.julia/juliaup/julia-1.12.0-rc1+0.x64.linux.gnu/share/julia/stdlib/v1.12/LinearAlgebra/src/bidiag.jl:131
 [2] isstored(D::Diagonal, i::Int64, j::Int64)
     @ ~/.julia/juliaup/julia-1.12.0-rc1+0.x64.linux.gnu/share/julia/stdlib/v1.12/LinearAlgebra/src/diagonal.jl:157
 [3] isstored(A::Union{LowerTriangular{T, S}, UnitLowerTriangular{T, S}, UnitUpperTriangular{T, S}, UpperTriangular{T, S}} where {T, S}, i::Int64, j::Int64)
     @ ~/.julia/juliaup/julia-1.12.0-rc1+0.x64.linux.gnu/share/julia/stdlib/v1.12/LinearAlgebra/src/triangular.jl:230
 [4] isstored(A::Tridiagonal, i::Int64, j::Int64)
     @ ~/.julia/juliaup/julia-1.12.0-rc1+0.x64.linux.gnu/share/julia/stdlib/v1.12/LinearAlgebra/src/tridiag.jl:693
 [5] isstored(A::SymTridiagonal, i::Int64, j::Int64)
     @ ~/.julia/juliaup/julia-1.12.0-rc1+0.x64.linux.gnu/share/julia/stdlib/v1.12/LinearAlgebra/src/tridiag.jl:450
 [6] isstored(A::AbstractArray{<:Any, N}, I::Vararg{Integer, N}) where N
     @ abstractarray.jl:610
``

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] docs This change adds or pertains to documentation sparse Sparse arrays triage This should be discussed on a triage call
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants