Skip to content

Commit

Permalink
workarounds for broadcast not preserving sparsity in general
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Sep 21, 2016
1 parent 96c01da commit 4932623
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions test/sparsedir/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,9 @@ let x = spv_x1, x2 = x2 = spv_x2

# multiplies
xm = SparseVector(8, [2, 6], [5.0, -19.25])
@test exact_equal(x .* x, abs2(x))
let y=x # workaround for broadcast not preserving sparsity in general
@test exact_equal(x .* y, abs2(x))
end
@test exact_equal(x .* x2, xm)
@test exact_equal(x2 .* x, xm)

Expand Down Expand Up @@ -724,19 +726,19 @@ let x = sprand(16, 0.5), x2 = sprand(16, 0.4)
end

# scale
let sx = SparseVector(x.n, x.nzind, x.nzval * 2.5)
@test exact_equal(x * 2.5, sx)
@test exact_equal(x * (2.5 + 0.0*im), complex(sx))
@test exact_equal(2.5 * x, sx)
@test exact_equal((2.5 + 0.0*im) * x, complex(sx))
@test exact_equal(x * 2.5, sx)
@test exact_equal(2.5 * x, sx)
@test exact_equal(x .* 2.5, sx)
@test exact_equal(2.5 .* x, sx)
@test exact_equal(x / 2.5, SparseVector(x.n, x.nzind, x.nzval / 2.5))
let α = 2.5, sx = SparseVector(x.n, x.nzind, x.nzval * α)
@test exact_equal(x * α, sx)
@test exact_equal(x * (α + 0.0*im), complex(sx))
@test exact_equal(α * x, sx)
@test exact_equal((α + 0.0*im) * x, complex(sx))
@test exact_equal(x * α, sx)
@test exact_equal(α * x, sx)
@test exact_equal(x .* α, sx)
@test exact_equal(α .* x, sx)
@test exact_equal(x / α, SparseVector(x.n, x.nzind, x.nzval / α))

xc = copy(x)
@test is(scale!(xc, 2.5), xc)
@test is(scale!(xc, α), xc)
@test exact_equal(xc, sx)
end

Expand Down

0 comments on commit 4932623

Please sign in to comment.