Skip to content

Commit

Permalink
Fix -(::SparseMatrixCSC{Bool}) (JuliaLang#36738)
Browse files Browse the repository at this point in the history
  • Loading branch information
sostock authored Jul 20, 2020
1 parent d806fb9 commit bd318e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stdlib/SparseArrays/src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,7 @@ function conj!(A::AbstractSparseMatrixCSC)
return A
end
function (-)(A::AbstractSparseMatrixCSC)
nzval = similar(nonzeros(A))
nzval = similar(nonzeros(A), typeof(-zero(eltype(A))))
map!(-, view(nzval, 1:nnz(A)), nzvalview(A))
return SparseMatrixCSC(size(A, 1), size(A, 2), copy(getcolptr(A)), copy(rowvals(A)), nzval)
end
Expand Down
6 changes: 6 additions & 0 deletions stdlib/SparseArrays/test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,12 @@ end
@test typeof(min.(A12118, B12118)) == SparseMatrixCSC{Int,Int}
end

@testset "unary minus for SparseMatrixCSC{Bool}" begin
A = sparse([1,3], [1,3], [true, true])
B = sparse([1,3], [1,3], [-1, -1])
@test -A == B
end

@testset "sparse matrix norms" begin
Ac = sprandn(10,10,.1) + im* sprandn(10,10,.1)
Ar = sprandn(10,10,.1)
Expand Down

0 comments on commit bd318e6

Please sign in to comment.