JuliaSparse / SparseArrays.jl

SparseArrays.jl is a Julia stdlib
https://sparsearrays.juliasparse.org/
Other
92 stars 53 forks source link

hash(SparseVector) very slow #570

Open dpinol opened 1 month ago

dpinol commented 1 month ago
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)
fredrikekre commented 1 month ago

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