Skip to content

Commit 442a1c2

Browse files
martinholtersKristofferC
authored andcommitted
Fix -, conj, and conj! for sparse matrices with invalid entries in nzval (#31187)
(cherry picked from commit ca92c7b)
1 parent 8a84ba5 commit 442a1c2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

stdlib/SparseArrays/test/sparse.jl

+12
Original file line numberDiff line numberDiff line change
@@ -2586,4 +2586,16 @@ end
25862586
@test sum(x1, dims=2) == sum(x2, dims=2)
25872587
end
25882588

2589+
@testset "unary operations on matrices where length(nzval)>nnz" begin
2590+
# this should create a sparse matrix with length(nzval)>nnz
2591+
A = SparseMatrixCSC(Complex{BigInt}[1+im 2+2im]')'[1:1, 2:2]
2592+
# ...ensure it does! If necessary, the test needs to be updated to use
2593+
# another mechanism to create a suitable A.
2594+
@assert length(A.nzval) > nnz(A)
2595+
@test -A == fill(-2-2im, 1, 1)
2596+
@test conj(A) == fill(2-2im, 1, 1)
2597+
conj!(A)
2598+
@test A == fill(2-2im, 1, 1)
2599+
end
2600+
25892601
end # module

0 commit comments

Comments
 (0)