Skip to content

Commit

Permalink
Fixed scale! bugs for SparseVector; added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kshyatt committed Sep 22, 2016
1 parent a06314b commit 1530ef4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1358,8 +1358,8 @@ end

scale!(x::AbstractSparseVector, a::Real) = (scale!(nonzeros(x), a); x)
scale!(x::AbstractSparseVector, a::Complex) = (scale!(nonzeros(x), a); x)
scale!(a::Real, x::AbstractSparseVector) = scale!(nonzeros(x), a)
scale!(a::Complex, x::AbstractSparseVector) = scale!(nonzeros(x), a)
scale!(a::Real, x::AbstractSparseVector) = (scale!(nonzeros(x), a); x)
scale!(a::Complex, x::AbstractSparseVector) = (scale!(nonzeros(x), a); x)


.*(x::AbstractSparseVector, a::Number) = SparseVector(length(x), copy(nonzeroinds(x)), nonzeros(x) * a)
Expand Down
3 changes: 3 additions & 0 deletions test/sparsedir/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,9 @@ let x = sprand(16, 0.5), x2 = sprand(16, 0.4)
xc = copy(x)
@test is(scale!(xc, 2.5), xc)
@test exact_equal(xc, sx)
xc = copy(x)
@test is(scale!(2.5, xc), xc)
@test exact_equal(xc, sx)
end

# dot
Expand Down

0 comments on commit 1530ef4

Please sign in to comment.