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
zero(x::AbstractArray{T}) where {T} =fill!(similar(x), zero(T))
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.
The text was updated successfully, but these errors were encountered:
PS apologies for butchering terminology. I'm always confused about what counts as the "structural zeros" -- the ones that are explicitly stored or the ones that aren't.
An obvious implementation for
zero(a::AbstractSparseArray)
would beHowever, in reality there's no specialization, and (the abstract fallback uses
fill!
:julia/base/abstractarray.jl
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:What do you think? Can we make this change in a minor release? If so, I'll gladly send in a pull request.
The text was updated successfully, but these errors were encountered: