You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SparseArrays: specialize zero(...) so result has nnz(...) = 0 (#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.
0 commit comments