Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SparseArrays: specialize zero(...) so result has nnz(...) = 0 #34209

Commits on Dec 28, 2019

  1. SparseArrays: specialize zero(...) so result has nnz(...) = 0

    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.
    tkluck committed Dec 28, 2019
    Configuration menu
    Copy the full SHA
    02e0254 View commit details
    Browse the repository at this point in the history