Julia: sparse binary broadcast incorrect for non-(zero-preserving) functions

Created on 26 Oct 2016  路  5Comments  路  Source: JuliaLang/julia

The definitions here and here cause

julia> VERSION
v"0.6.0-dev.1092"

julia> broadcast((x,y) -> sin(x) + cos(y), speye(5), speye(5))
5脳5 sparse matrix with 5 Float64 nonzero entries:
    [1, 1]  =  1.38177
    [2, 2]  =  1.38177
    [3, 3]  =  1.38177
    [4, 4]  =  1.38177
    [5, 5]  =  1.38177

julia> broadcast((x,y) -> sin(x) + cos(y), Array(speye(5)), Array(speye(5)))
5脳5 Array{Float64,2}:
 1.38177  1.0      1.0      1.0      1.0
 1.0      1.38177  1.0      1.0      1.0
 1.0      1.0      1.38177  1.0      1.0
 1.0      1.0      1.0      1.38177  1.0
 1.0      1.0      1.0      1.0      1.38177

Best!

sparse

Most helpful comment

Ouch. Yet another reason that all the sparse broadcast methods should be replaced with a unified approach that (a) assumes purity, (b) checks f(0...), and (c) always returns a SparseMatrixCSC even if the output is dense, as we've discussed in #18590.

Agreed. Discovered this bug while experimenting with an implementation; look for more from me shortly :). Best!

All 5 comments

Ouch. Yet another reason that all the sparse broadcast methods should be replaced with a unified approach that (a) assumes purity, (b) checks f(0...), and (c) always returns a SparseMatrixCSC even if the output is dense, as we've discussed in #18590.

Ouch. Yet another reason that all the sparse broadcast methods should be replaced with a unified approach that (a) assumes purity, (b) checks f(0...), and (c) always returns a SparseMatrixCSC even if the output is dense, as we've discussed in #18590.

Agreed. Discovered this bug while experimenting with an implementation; look for more from me shortly :). Best!

19371 provided a partial fix. #19518 should close this altogether. Best!

I believe this one is already fixed. Right?

I believe this one is already fixed. Right?

Yes, happily fixed :).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wilburtownsend picture wilburtownsend  路  3Comments

yurivish picture yurivish  路  3Comments

tkoolen picture tkoolen  路  3Comments

Keno picture Keno  路  3Comments

sbromberger picture sbromberger  路  3Comments