Skip to content

Commit

Permalink
Merge pull request #18637 from JuliaLang/ksh/smallsparse
Browse files Browse the repository at this point in the history
Bugfix and tests for sparse
  • Loading branch information
kshyatt authored Sep 23, 2016
2 parents 792ded8 + 3cbcef1 commit 1c514e7
Show file tree
Hide file tree
Showing 3 changed files with 7 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
2 changes: 2 additions & 0 deletions test/sparsedir/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ for i = 1:5
@test (maximum(abs.(a*b - full(a)*b)) < 100*eps())
@test (maximum(abs.(A_mul_B!(similar(b), a, b) - full(a)*b)) < 100*eps()) # for compatibility with present matmul API. Should go away eventually.
@test (maximum(abs.(A_mul_B!(similar(c), a, c) - full(a)*c)) < 100*eps()) # for compatibility with present matmul API. Should go away eventually.
@test (maximum(abs.(At_mul_B!(similar(b), a, b) - full(a).'*b)) < 100*eps()) # for compatibility with present matmul API. Should go away eventually.
@test (maximum(abs.(At_mul_B!(similar(c), a, c) - full(a).'*c)) < 100*eps()) # for compatibility with present matmul API. Should go away eventually.
@test (maximum(abs.(a'b - full(a)'b)) < 100*eps())
@test (maximum(abs.(a.'b - full(a).'b)) < 100*eps())
@test (maximum(abs.(a\b - full(a)\b)) < 1000*eps())
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 1c514e7

Please sign in to comment.