-
Notifications
You must be signed in to change notification settings - Fork 54
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
Sparse matrix/vectors with fixed sparsity pattern. #201
Conversation
after some hacking, i've come with some cases that needs discussing. |
X .+ Y should be a union of the patterns I believe. X .+ 1 is tricky, and I'll defer to @ChrisRackauckas here since he asked for this initially. |
Yes.
That's just dense: there's no other representation. So make it a dense sparse matrix, but of course, almost certainly the user would never do that. |
fa199bb
to
1e1220e
Compare
for reasons i don't fully understand this seems to work. I propose adding
as furthermore, i think it would be nice to have a shortcut for
i.e. add 1 to all non structural zeros. Since
can't be that (as it would not work with the array api), maybe there could be another operator? maybe a macro could do the job? |
Codecov Report
@@ Coverage Diff @@
## main #201 +/- ##
==========================================
- Coverage 92.13% 91.68% -0.45%
==========================================
Files 11 12 +1
Lines 7210 7302 +92
==========================================
+ Hits 6643 6695 +52
- Misses 567 607 +40
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@ChrisRackauckas could you test it a bit? the instruction to use a dev version of this package is in the README, and you can use |
There's a lot going on in this PR - I'll need time to understand. |
Is AbstractSparseVectorC any different from AbstractSparseVector? I'm not sure it makes sense to differentiate between storage orders for a 1-d array. I think storage order should be a trait anyway but that's a bigger issue. |
i assumed one can implement a AbstractSparseVector with a dictionary or start from 0 instead of 1. Hence AbstractSparseVectorC is the subset that work like SparseVector, with one indexed nonzeros/nonzeroinds. The point is that AbstractSparseArray{Tv, Ti, 1} does not say anything about the structure of the array. |
case in point, look at #219 |
I am wondering if this code can live in a separate package? Or rather what do we need to do in SparseArrays.jl so that it can be a separate package? |
i don't think it can be a separate package w/o much redundancy (and piracy) in higherorderfns. having fixed arrays changes the meaning of broadcast/map/map!. also it should be much easier to check for breakage if they are part of this package. |
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.
A few comments on the actual code inline.
You mentioned that this can't be split out because that would be piracy. I don't think there would be any need for piracy (these changes involve a new type anyway).
I would argue this should look like:
- Make
higherorderfns
useAbstractSparseMatrixCSC
rather thanSparseMatrixCSC
in theSparseOrStructuredMatrix
union. Most other instances ofSparseMatrixCSC
in signatures can be turned intoAbstractSparseMatrixCSC
. - Add trait to determine whether new indices can be inserted.
_is_fixed
is fine as is,_can_insert
might be more clear. _noshapecheck_map
can be overloaded in a new package forAbstractFixed...
, perhaps as simply as_noshapecheck_map(f, A::AbstractFixed, Bs...) = fixed(invoke(_noshapecheck_map, AbstractSparseMatrixCSC, ..., A, Bs...)
.
That avoids any piracy (as far as I can tell), and lets us avoid significant additions to the SparseArrays API before Julia 1.10 when we can really look at major changes (SparseArrays will still be an stdlib for 1.9 unfortunately).
Is this ready @SobhanMP ? Everything including concrete types can be merged once green. Please be sure to document that this is not public right now. |
i'd like to have a bit more time to check stuff, will merge by monday. |
This patch updates SparseArrays. In particular it contains JuliaSparse/SparseArrays.jl#260 which is necessary to make progress in #46759. All changes: - Fix direction of circshift (JuliaSparse/SparseArrays.jl#260) - Fix `vcat` of sparse vectors with numbers (JuliaSparse/SparseArrays.jl#253) - decrement should always return a vector (JuliaSparse/SparseArrays.jl#241) - change order of arguments in fkeep, fix bug with fixed elements (JuliaSparse/SparseArrays.jl#240) - Sparse matrix/vectors with fixed sparsity pattern. (JuliaSparse/SparseArrays.jl#201)
This patch updates SparseArrays. In particular it contains JuliaSparse/SparseArrays.jl#260 which is necessary to make progress in #46759. All changes: - Remove fkeep! from the documentation (JuliaSparse/SparseArrays.jl#261) - Fix direction of circshift (JuliaSparse/SparseArrays.jl#260) - Fix `vcat` of sparse vectors with numbers (JuliaSparse/SparseArrays.jl#253) - decrement should always return a vector (JuliaSparse/SparseArrays.jl#241) - change order of arguments in fkeep, fix bug with fixed elements (JuliaSparse/SparseArrays.jl#240) - Sparse matrix/vectors with fixed sparsity pattern. (JuliaSparse/SparseArrays.jl#201)
This patch updates SparseArrays. In particular it contains JuliaSparse/SparseArrays.jl#260 which is necessary to make progress in #46759. All changes: - Fix ambiguities with Base. (JuliaSparse/SparseArrays.jl#268) - add == for vectors (JuliaSparse/SparseArrays.jl#248) - add undef initializers (JuliaSparse/SparseArrays.jl#263) - Make sure reductions benefit from sparsity (JuliaSparse/SparseArrays.jl#244) - Remove fkeep! from the documentation (JuliaSparse/SparseArrays.jl#261) - Fix direction of circshift (JuliaSparse/SparseArrays.jl#260) - Fix `vcat` of sparse vectors with numbers (JuliaSparse/SparseArrays.jl#253) - decrement should always return a vector (JuliaSparse/SparseArrays.jl#241) - change order of arguments in fkeep, fix bug with fixed elements (JuliaSparse/SparseArrays.jl#240) - Sparse matrix/vectors with fixed sparsity pattern. (JuliaSparse/SparseArrays.jl#201)
This patch updates SparseArrays. In particular it contains JuliaSparse/SparseArrays.jl#260 which is necessary to make progress in #46759. All changes: - Fix ambiguities with Base. (JuliaSparse/SparseArrays.jl#268) - add == for vectors (JuliaSparse/SparseArrays.jl#248) - add undef initializers (JuliaSparse/SparseArrays.jl#263) - Make sure reductions benefit from sparsity (JuliaSparse/SparseArrays.jl#244) - Remove fkeep! from the documentation (JuliaSparse/SparseArrays.jl#261) - Fix direction of circshift (JuliaSparse/SparseArrays.jl#260) - Fix `vcat` of sparse vectors with numbers (JuliaSparse/SparseArrays.jl#253) - decrement should always return a vector (JuliaSparse/SparseArrays.jl#241) - change order of arguments in fkeep, fix bug with fixed elements (JuliaSparse/SparseArrays.jl#240) - Sparse matrix/vectors with fixed sparsity pattern. (JuliaSparse/SparseArrays.jl#201)
This pull request adds
return _is_fixed(A, Bs...) ? fixed(r) : r
is typesafe.fixed
function can be used as a shortcut for creating sparse things with fixed sparsity.once all green this should be ready to merge. this commit is NOT breaking.
apart from the bike-shed possible, i have a few concerns
SparseMatrixCSC
toAbstractSparseMatrixCSC
. is this correct?i too feel that it's unfortunately long, 🙃. i thought it would be easier than this.
Ref: #190