SparseArrays.jl icon indicating copy to clipboard operation
SparseArrays.jl copied to clipboard

hash(SparseVector) very slow

Open dpinol opened this issue 1 year ago • 1 comments

const sp=spzeros(Int,1_000_000_000)
1000000000-element SparseVector{Int64, Int64} with 0 stored entries

@btime hash(sp)
  182.608 ms (0 allocations: 0 bytes)

I can create a PR with the alternative implementation if you agree with it

@btime hash((sp.nzind, sp.nzval, sp.n))
  4.208 ns (0 allocations: 0 bytes)

dpinol avatar Oct 18 '24 11:10 dpinol

Needs to satisfy these properties I think:

julia> using SparseArrays

julia> x = zeros(5); xs = spzeros(5);

julia> isequal(x, xs)
true

julia> hash(x) == hash(xs)
true

fredrikekre avatar Oct 18 '24 11:10 fredrikekre