-
-
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
Make setindex! for sparse matrices and vectors not purge stored entries on zero assignment #17404
Conversation
e4169e0
to
e22fe8f
Compare
… expunges stored entries on zero assignment, throws a more explicit BoundsError when needed, and also for simplicity and clarity. Also add tests.
Please see the test failures, can you reproduce them locally? This is a bit of a behavior change but IMO could be okay for before feature freeze if you hurry. |
The |
@nanosoldier |
AppVeyor i686 string test failure seems unrelated? |
I would assume so, but I've never seen that before
|
Your benchmark job has completed - no performance regressions were detected. A full report can be found here. cc @jrevels |
Am I misreading BaseBenchmarks/SparseBenchmarks.jl, or does Nanosoldier not cover sparse |
It might not. |
lenI = length(I) | ||
|
||
if (!isempty(I) && (I[1] < 1 || I[end] > m)) || (!isempty(J) && (J[1] < 1 || J[end] > n)) | ||
function setindex!{TvA,Tx<:Number,TiI<:Integer,TiJ<:Integer}(A::SparseMatrixCSC{TvA}, x::Tx, |
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.
Tx
doesn't need to be a type parameter
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 catch! Related question: To fix the show
test failure I reverted comparisons of the form x == zero(Tx)
to the former implementation's x == 0
, the test failure being due to lack of a zero
method for some <:Number
. Is zero
part of the implicit Number
interface? That is, in the long run would keeping x == zero(Tx)
and requiring all <:Number
s to implement zero
be better than using x == 0
, or is x == 0
the preferred expression? Thanks!
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'd rather continue allowing sparse matrices with value types that don't implement zero
if at all possible
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.
Cheers, the most recent version should make that so. Thanks!
Is there an API (unexported?) for deleting a specific value from the nonzero structure? |
…expunges stored entries on zero assignment. Also add tests.
…hat, when an assigning zero to entry A[i,j], if A[i,j] is not presently stored, the method does not introduce storage for A[i,j]. Also add tests.
… that it no longer expunges stored entries on zero assignment. Also add tests.
…it no longer expunges stored entries on zero assignment. Also add tests.
Not at the moment, but we could introduce one now if you would like that facility to appear in the same PR. If so, name? |
|
… from SparseMatrixCSCs.
Prototype implementation of |
… stored entries on zero assignment. Modify tests accordingly.
The most recent commits should make |
…arseVectors. Also introduce associated tests.
…ger purges allocated entries on zero assignment and that dropstored! now exists to drop stored entries.
this may not be all that useful given the likely lack of sparse setindex tests, but it's otherwise probably idle right now so |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels |
|
||
if ndel > 0 | ||
A.colptr[n+1] = rowidx | ||
deleteat!(rowvalA, rowidx:nnzA) |
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.
This could use resize!
instead?
Apologies for the slow response (travel Saturday through Monday). Re. |
I think we'd be fine to merge this now and do cleanup later. Couldn't tell from the diffs that this was reused code. |
Sorry about that. Reshuffling the contents of the commits such that |
No, I don't think that's worth the hassle right now. There are other more pressing issues that could use your input. |
+1 for merge as is |
Thanks for the reviews and merge! |
return A | ||
end | ||
""" | ||
dropstored!(A::SparseMatrix, I::AbstractVector{<:Integer}, J::AbstractVector{<:Integer}) |
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.
should this say SparseMatrixCSC ?
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.
#20664. Thanks!
This pull request makes
setindex!
forSparseMatrixCSC
s: (1) not purge allocated entries on zero assignment; and (2) not introduce new allocated entries on zero assignment. See the proposal in #15568 (comment) / extensive discussion in #15568, #9928, #9906, #6769, #5538, #5454, and probably others. Thanks to @KristofferC for getting the ball rolling with #15568!TODO: Expand tests for new behavior.Now with expanded tests!