Skip to content
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

Merged
merged 1 commit into from
Feb 8, 2017
Merged

fix dropstored for sparse matrices #20516

merged 1 commit into from
Feb 8, 2017

Conversation

KristofferC
Copy link
Member

@KristofferC KristofferC commented Feb 8, 2017

Should fix #20513

@KristofferC KristofferC added the sparse Sparse arrays label Feb 8, 2017
@KristofferC KristofferC requested review from Sacha0 and tkelman February 8, 2017 08:12
@tkelman tkelman added backport pending 0.5 bugfix This change fixes an existing bug labels Feb 8, 2017
Copy link
Contributor

@tkelman tkelman left a 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

@KristofferC
Copy link
Member Author

I did not understand your comment.

@StefanKarpinski
Copy link
Member

Would it make sense for dropstored! to be a method of delete!?

@KristofferC
Copy link
Member Author

Probably no. I would argue they have different semantics.

@StefanKarpinski
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Copy link
Member

@Sacha0 Sacha0 left a 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! :)

@KristofferC
Copy link
Member Author

@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

@KristofferC KristofferC merged commit e24faa5 into master Feb 8, 2017
@KristofferC KristofferC deleted the kc/sparse_drop branch February 8, 2017 21:01
@StefanKarpinski
Copy link
Member

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

@StefanKarpinski
Copy link
Member

I.e. the difference is only because the standard Dict has no default value while sparse matrices and vectors do. The generic delete! operation covers both of these behaviors.

@Sacha0
Copy link
Member

Sacha0 commented Feb 8, 2017

Would it make sense for dropstored! to be a method of delete!?

+1 for this suggestion. @KristofferC, have you other semantic differences in mind? Best!

@KristofferC
Copy link
Member Author

Nah, I was wrong :)

@tkelman
Copy link
Contributor

tkelman commented Feb 9, 2017

#20531 would make it not such a good idea though, as deleteat! resizes but dropstored! does not.

@StefanKarpinski
Copy link
Member

StefanKarpinski commented Feb 9, 2017

That seems like a gotcha distinction that should be eliminated.

@tkelman
Copy link
Contributor

tkelman commented Feb 9, 2017

they serve different purposes, and resizing deleteat! doesn't work for anything other than 1D

@StefanKarpinski
Copy link
Member

Then it seems mostly like delete! and deleteat! should not be merged after all.

@tkelman
Copy link
Contributor

tkelman commented Feb 9, 2017

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.

@StefanKarpinski
Copy link
Member

The thinking behind deleteat! being separate from delete! is coming back to me and IIRC, it was precisely that delete! didn't make sense in an indexed collection because it has the effect of change all subsequent "keys" – i.e. indices. The delete! function, on the other hand only affects the key you ask to delete, which applies to sparse matrices/vectors and dicts, but not arrays.

tkelman pushed a commit that referenced this pull request Mar 1, 2017
(cherry picked from commit e24faa5)

testset replaced by let block for release-0.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug sparse Sparse arrays
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dropstored! had one job
4 participants