Skip to content

Commit e2c16ac

Browse files
committed
prevent slow fallback for sparsevector */ scalar
1 parent fdbcdf7 commit e2c16ac

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

base/sparse/sparsevector.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,11 +1245,10 @@ scale!(x::AbstractSparseVector, a::Complex) = (scale!(nonzeros(x), a); x)
12451245
scale!(a::Real, x::AbstractSparseVector) = scale!(nonzeros(x), a)
12461246
scale!(a::Complex, x::AbstractSparseVector) = scale!(nonzeros(x), a)
12471247

1248-
# *(x::AbstractSparseVector, a::Real) = SparseVector(length(x), copy(nonzeroinds(x)), scale(nonzeros(x), a))
1249-
# *(x::AbstractSparseVector, a::Complex) = SparseVector(length(x), copy(nonzeroinds(x)), scale(nonzeros(x), a))
1250-
# *(a::Number, x::AbstractSparseVector) = xa)
1251-
# .*(x::AbstractSparseVector, a::Number) = scale(x, a)
1252-
# .*(a::Number, x::AbstractSparseVector) = scale(x, a)
1248+
1249+
.*(x::AbstractSparseVector, a::Number) = SparseVector(length(x), copy(nonzeroinds(x)), nonzeros(x) * a)
1250+
.*(a::Number, x::AbstractSparseVector) = SparseVector(length(x), copy(nonzeroinds(x)), a * nonzeros(x))
1251+
./(x::AbstractSparseVector, a::Number) = SparseVector(length(x), copy(nonzeroinds(x)), nonzeros(x) / a)
12531252

12541253

12551254
# dot

test/sparsedir/sparsevector.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ let x = sprand(16, 0.5), x2 = sprand(16, 0.4)
672672
@test exact_equal(2.5 * x, sx)
673673
@test exact_equal(x .* 2.5, sx)
674674
@test exact_equal(2.5 .* x, sx)
675+
@test exact_equal(x / 2.5, SparseVector(x.n, x.nzind, x.nzval / 2.5))
675676

676677
xc = copy(x)
677678
@test is(scale!(xc, 2.5), xc)

0 commit comments

Comments
 (0)