Skip to content

Commit

Permalink
prevent slow fallback for sparsevector */ scalar
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Mar 21, 2016
1 parent fdbcdf7 commit e2c16ac
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
9 changes: 4 additions & 5 deletions base/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1245,11 +1245,10 @@ 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)

# *(x::AbstractSparseVector, a::Real) = SparseVector(length(x), copy(nonzeroinds(x)), scale(nonzeros(x), a))
# *(x::AbstractSparseVector, a::Complex) = SparseVector(length(x), copy(nonzeroinds(x)), scale(nonzeros(x), a))
# *(a::Number, x::AbstractSparseVector) = xa)
# .*(x::AbstractSparseVector, a::Number) = scale(x, a)
# .*(a::Number, x::AbstractSparseVector) = scale(x, a)

.*(x::AbstractSparseVector, a::Number) = SparseVector(length(x), copy(nonzeroinds(x)), nonzeros(x) * a)
.*(a::Number, x::AbstractSparseVector) = SparseVector(length(x), copy(nonzeroinds(x)), a * nonzeros(x))
./(x::AbstractSparseVector, a::Number) = SparseVector(length(x), copy(nonzeroinds(x)), nonzeros(x) / a)


# dot
Expand Down
1 change: 1 addition & 0 deletions test/sparsedir/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ let x = sprand(16, 0.5), x2 = sprand(16, 0.4)
@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))

xc = copy(x)
@test is(scale!(xc, 2.5), xc)
Expand Down

0 comments on commit e2c16ac

Please sign in to comment.