Skip to content

Bug in map! for sparse matrices with aliasing #26

Open
@pablosanjose

Description

@pablosanjose

We've had aliasing safeguards for broadcast and generic map! for a while (see JuliaLang/julia#21693, JuliaLang/julia#25890 in particular). However, I believe this machinery was never ported to SparseArrays's map!:

julia> using SparseArrays

julia> s0 = sprand(10, 10, 0.1); s1 = sprand(10, 10, 0.1); sc = copy(s0);

julia> map!(+, s0, s0, s1);

julia> s0 == sc + s1
false

The last should be true, as in the dense case:

julia> s0 = Matrix(sprand(10, 10, 0.1)); s1 = Matrix(sprand(10, 10, 0.1)); sc = copy(s0);

julia> map!(+, s0, s0, s1);

julia> s0 == sc + s1
true

This behaviour is in 1.5.1 and master

Broadcast seems to work ok, although I think it doesn't use sparse-specific codepaths, so it is much slower than map!

julia> s0 = sprand(10,10,0.1); s1 = sprand(10,10,0.1); sc = copy(s0);

julia> s0 .= s0 .+ s1;

julia> s0 == sc + s1
true

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions