Skip to content

Commit 754280c

Browse files
authored
fix cholesky linear solve with sparse rhs (#709)
Closes #630
1 parent 361d557 commit 754280c

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/solvers/cholmod.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ function Sparse(A::SparseMatrixCSC{<:Union{ComplexF16, ComplexF32}}, stype::Inte
990990
end
991991

992992
# convert SparseVectors into CHOLMOD Sparse types through a mx1 CSC matrix
993-
Sparse(A::SparseVector) = Sparse(SparseMatrixCSC(A))
993+
Sparse(A::SparseVector) = Sparse(SparseMatrixCSC(A), 0)
994994
function Sparse{Tv, Ti}(A::SparseMatrixCSC) where {Tv<:VTypes, Ti<:ITypes}
995995
o = Sparse{Tv, Ti}(A, 0)
996996
# check if array is symmetric and change stype if it is
@@ -1135,6 +1135,7 @@ function SparseVector{Tv, Ti}(A::Sparse{Tv, Ti}) where {Tv, Ti<:ITypes}
11351135
end
11361136
args = _extract_args(s, Tv)
11371137
s.sorted == 0 && _sort_buffers!(args...);
1138+
_trim_nz_builder!(args...)
11381139
return SparseVector(args[1], args[4], args[5])
11391140
end
11401141

test/cholmod.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,14 @@ end
807807
@test chI \ sparseI sparseI
808808
end
809809

810+
@testset "Issue 630" begin
811+
sparseI = sparse(1.0I, 1, 1)
812+
@test cholesky(sparseI) \ sparse([1.0]) == [1]
813+
sparseI = sparse(1.0I, 2, 2)
814+
res = cholesky(sparseI) \ spzeros(2)
815+
@test isempty(nonzeros(res))
816+
end
817+
810818
@testset "Real factorization and complex rhs" begin
811819
A = sprandn(5, 5, 0.4) |> t -> t't + I
812820
B = complex.(randn(5, 5), randn(5, 5))

0 commit comments

Comments
 (0)