Closed
Description
openedon Apr 25, 2019
An obvious implementation for zero(a::AbstractSparseArray)
would be
zero(a::AbstractSparseArray) = spzeros(eltype(a), size(a)...)
However, in reality there's no specialization, and (the abstract fallback uses fill!
:
Line 903 in 93c9ae4
In particular, that means that it will be filled with non-structural zeros.
The reason why I haven't sent the obvious pull request is that this change is backwards incompatible where it relates to object identity. Namely, a side-effect of using fill!
is that for mutable objects, every 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
What do you think? Can we make this change in a minor release? If so, I'll gladly send in a pull request.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment