Skip to content

Commit

Permalink
Provide a unary minus method specialized for sparse matrices. (JuliaL…
Browse files Browse the repository at this point in the history
  • Loading branch information
Sacha0 authored and tkelman committed Dec 14, 2016
1 parent 3037157 commit bfc72b6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions base/sparse/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2267,13 +2267,15 @@ broadcast_zpreserving{Tv,Ti}(f::Function, A_1::Union{Array,BitArray,Number}, A_2

# TODO: More appropriate location?
conj!(A::SparseMatrixCSC) = (broadcast!(conj, A.nzval, A.nzval); A)
(-)(A::SparseMatrixCSC) = SparseMatrixCSC(A.m, A.n, copy(A.colptr), copy(A.rowval), map(-, A.nzval))

# TODO: The following definitions should be deprecated.
ceil{To}(::Type{To}, A::SparseMatrixCSC) = ceil.(To, A)
floor{To}(::Type{To}, A::SparseMatrixCSC) = floor.(To, A)
trunc{To}(::Type{To}, A::SparseMatrixCSC) = trunc.(To, A)
round{To}(::Type{To}, A::SparseMatrixCSC) = round.(To, A)


## Binary arithmetic and boolean operators

# TODO: These seven functions should probably be reimplemented in terms of sparse map
Expand Down
3 changes: 3 additions & 0 deletions test/sparse/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,9 @@ end
# `SparseMatrixCSC`s determine a reasonable return type. (Issue #18974.)
@test eltype(sin.(spdiagm(Int64(1):Int64(4)))) == Float64

# Check calling of unary minus method specialized for SparseMatrixCSCs. (Issue #19503.)
@test which(-, (SparseMatrixCSC,)).module == Base.SparseArrays

# Test map/map! over sparse matrices
let
N, M = 10, 12
Expand Down

0 comments on commit bfc72b6

Please sign in to comment.