Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 28f6a3f

Browse files
committedSep 21, 2016
workarounds for broadcast not preserving sparsity in general
1 parent f3dc58c commit 28f6a3f

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed
 

‎test/sparsedir/sparsevector.jl

+14-12
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,9 @@ let x = spv_x1, x2 = x2 = spv_x2
581581

582582
# multiplies
583583
xm = SparseVector(8, [2, 6], [5.0, -19.25])
584-
@test exact_equal(x .* x, abs2(x))
584+
let y=x # workaround for broadcast not preserving sparsity in general
585+
@test exact_equal(x .* y, abs2(x))
586+
end
585587
@test exact_equal(x .* x2, xm)
586588
@test exact_equal(x2 .* x, xm)
587589

@@ -724,19 +726,19 @@ let x = sprand(16, 0.5), x2 = sprand(16, 0.4)
724726
end
725727

726728
# scale
727-
let sx = SparseVector(x.n, x.nzind, x.nzval * 2.5)
728-
@test exact_equal(x * 2.5, sx)
729-
@test exact_equal(x * (2.5 + 0.0*im), complex(sx))
730-
@test exact_equal(2.5 * x, sx)
731-
@test exact_equal((2.5 + 0.0*im) * x, complex(sx))
732-
@test exact_equal(x * 2.5, sx)
733-
@test exact_equal(2.5 * x, sx)
734-
@test exact_equal(x .* 2.5, sx)
735-
@test exact_equal(2.5 .* x, sx)
736-
@test exact_equal(x / 2.5, SparseVector(x.n, x.nzind, x.nzval / 2.5))
729+
let α = 2.5, sx = SparseVector(x.n, x.nzind, x.nzval * α)
730+
@test exact_equal(x * α, sx)
731+
@test exact_equal(x * (α + 0.0*im), complex(sx))
732+
@test exact_equal(α * x, sx)
733+
@test exact_equal((α + 0.0*im) * x, complex(sx))
734+
@test exact_equal(x * α, sx)
735+
@test exact_equal(α * x, sx)
736+
@test exact_equal(x .* α, sx)
737+
@test exact_equal(α .* x, sx)
738+
@test exact_equal(x / α, SparseVector(x.n, x.nzind, x.nzval / α))
737739

738740
xc = copy(x)
739-
@test is(scale!(xc, 2.5), xc)
741+
@test is(scale!(xc, α), xc)
740742
@test exact_equal(xc, sx)
741743
end
742744

0 commit comments

Comments
 (0)
Please sign in to comment.