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

Bug in map! for sparse matrices with aliasing #26

Open
pablosanjose opened this issue Sep 3, 2020 · 0 comments
Open

Bug in map! for sparse matrices with aliasing #26

pablosanjose opened this issue Sep 3, 2020 · 0 comments

Comments

@pablosanjose
Copy link
Member

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
@KristofferC KristofferC transferred this issue from JuliaLang/julia Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant