-
-
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
fix dropstored for sparse matrices #20516
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.
who's counting anyway
I did not understand your comment. |
Would it make sense for |
Probably no. I would argue they have different semantics. |
Don't they both delete the value associated with keys, if there is one, reverting back to a default value, and returning the collection? |
@@ -2745,7 +2745,7 @@ function dropstored!(A::SparseMatrixCSC, i::Integer, j::Integer) | |||
# Entry A[i,j] is stored. Drop and return. | |||
deleteat!(A.rowval, searchk) | |||
deleteat!(A.nzval, searchk) | |||
@simd for m in j:(A.n + 1) | |||
@simd for m in (j+1):(A.n + 1) |
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!
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.
Thanks for fixing this! :)
@StefanKarpinski for example: julia> d = Dict(1 => 1.0);
julia> delete!(d, 1);
julia> d[1]
ERROR: KeyError: key 1 not found
Stacktrace:
[1] getindex(::Dict{Int64,Float64}, ::Int64) at ./dict.jl:474
julia> x = sparse([1]);
julia> Base.SparseArrays.dropstored!(x, 1);
julia> x[1]
0 |
julia> using DataStructures
julia> d = DefaultDict(0.0, 1 => 1.0)
DataStructures.DefaultDict{Int64,Float64,Float64} with 1 entry:
1 => 1.0
julia> delete!(d, 1)
DataStructures.DefaultDict{Int64,Float64,Float64} with 0 entries
julia> d[1]
0.0 |
I.e. the difference is only because the standard |
+1 for this suggestion. @KristofferC, have you other semantic differences in mind? Best! |
Nah, I was wrong :) |
#20531 would make it not such a good idea though, as deleteat! resizes but dropstored! does not. |
That seems like a gotcha distinction that should be eliminated. |
they serve different purposes, and resizing deleteat! doesn't work for anything other than 1D |
Then it seems mostly like |
Depends whether people expect delete! to resize or not. Is that only defined for Associatives right now? In that case resizing isn't all that meaningful. I could see these 3 functions being consolidated into 2 in a few combinations, but not into 1. |
The thinking behind |
(cherry picked from commit e24faa5) testset replaced by let block for release-0.5
Should fix #20513