Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SparseArrays: specialize zero(...) so result has nnz(...) = 0 (JuliaL…
…ang#34209) Before this commit, the result of zero(x::AbstractSparseArray) is filled with stored zeros exactly where `x` has a stored value. That is a wasteful artifact of the default fallback implementation for `AbstractArray`. After this commit, we return a sparse array of the same dimensions as `x` without any stored values. This change is backwards incompatible where it relates to object identity. Before this commit, for mutable objects, every stored zero has the same identity. Example: julia> using SparseArrays julia> y = zero(BigInt[1,2,3]); y[1] === y[2] true julia> y = zero(sparse(BigInt[1,2,3])); y[1] === y[2] true julia> Base.zero(a::AbstractSparseArray) = spzeros(eltype(a), size(a)...) julia> y = zero(sparse(BigInt[1,2,3])); y[1] === y[2] false But this behaviour should be classified as a performance bug and can therefore be fixed in a minor (but not a patch) release.
- Loading branch information