-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[WIP] generic sparse indices #40103
[WIP] generic sparse indices #40103
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious how you're going to implement the iterator for *Triangular
s and *Diagonal
s. I was playing around with a little predicate-based draft. It turned out to improve on the current state, but wasn't nearly as fast as your latest Diagonal
contribution.
I think some indices might require allocating? If you have some funky array where there non-zero pattern is well-defined but not trivially implementable with ranges or CartesianIndices. The compromise would be:
I don't think we will do as fast as specialized methods for end-functions with specific types (like dot on Diagonal). However, this can still be a better base than having to rely on |
Co-authored-by: Daniel Karrasch <daniel.karrasch@posteo.de>
@dkarrasch looking at |
Not sure why SparseArrays does not depend on Printf, it seems like it should? |
I guess it depends on where you want to use it. I think we rarely, if ever, call getindex(A::AbstractSparseMatrixCSC, I::CartesianIndex{2}) = getindex(A, I[1], I[2]) method. |
I would be ok with adding the method, but it already has the corresponding behaviour implemented with the current fallback: julia> using SparseArrays
julia> m = spzeros(200,100);
julia> m[CartesianIndex(1,1)]
0.0 why do you have it in mind? |
Because I saw that we have such a method specifically for tuples of integers, so it seemed we don't rely on fallbacks there either. But otherwise no other reason. |
Co-authored-by: Daniel Karrasch <daniel.karrasch@posteo.de>
""" | ||
eachstoredindex(A) | ||
|
||
Returns an iterable over the indices of `A` where the values are structurally non-zero. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to define this as being tied to structural nonzeros? Or simply stored values? We could simultaneously introduce a unstoredvalue
to give room for other sorts of structures.
In any case, I like this and think it's very needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. What would be expected for a FillArrays.Ones
? In the case of stored values, it would return an empty iterator? I am not sure we can make this useful in general, except for constructors?
@matbesancon It looks like this PR touches seven files. Two of those files ( We have moved the SparseArrays stdlib to an external repository. Therefore, for the portion of this PR that modifies the SparseArrays stdlib, can you please:
Thank you! |
This tackles https://github.com/JuliaLang/julia/issues/31330
Linked issue: https://github.com/JuliaLang/julia/issues/25118
Will solve in a cleaner way: https://github.com/JuliaLang/julia/issues/39887
Design goal:
a generic index iterator for structural non-zeros of abstract arrays. This will allow efficient generic algorithms exploiting sparsity.
The function is defined in Base, so it can be implemented by the types in both LinearAlgebra and SparseArrays, I found it awkward to have it defined in LinearAlgebra itself
ping @dkarrasch