Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix -(::SparseMatrixCSC{Bool}) #36738

Merged
merged 1 commit into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix -(::SparseMatrixCSC{Bool})
  • Loading branch information
sostock committed Jul 20, 2020
commit 933ebd839a6ea8cf03b556334f2305c89f2a3cd5
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