Skip to content
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
7 changes: 7 additions & 0 deletions src/solvers/cholmod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,11 @@ function check_hermitian_stype(A::Sparse)
throw(ArgumentError("sparse matrix is not symmetric/Hermitian"))
return nothing
end
function check_refactor_size(F::Factor, A::Sparse)
size(A) == size(F) || throw(DimensionMismatch(
"matrix has size $(size(A)), but the factorization has size $(size(F))"))
return nothing
end

## Compute that symbolic factorization only
function symbolic(A::Sparse{<:VTypes, Ti};
Expand Down Expand Up @@ -1710,6 +1715,7 @@ function cholesky!(F::Factor{Tv}, A::Sparse{Tv};
shift::Real=0.0, check::Bool = true) where Tv
check_hermitian_stype(A)
@lock F.lock begin
check_refactor_size(F, A)
@cholmod_param final_ll = true begin
factorize_p!(A, shift, F)
end
Expand Down Expand Up @@ -1901,6 +1907,7 @@ function ldlt!(F::Factor{Tv}, A::Sparse{Tv};
shift::Real=0.0, check::Bool = true) where Tv
check_hermitian_stype(A)
@lock F.lock begin
check_refactor_size(F, A)
change_factor!(F, false, false, true, false)
factorize_p!(A, shift, F)
check && (issuccess(F) || throw(factorization_exception(F)))
Expand Down
8 changes: 8 additions & 0 deletions test/solvers/issues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ end
@test cholesky!(F, SparseMatrixCSC{Float64,Int16}(2A)) \ [1.0, 2.0, 3.0] ≈ (2A) \ [1.0, 2.0, 3.0]
end

@testset "ldlt! with a matrix of another size leaves an LLt factor unchanged" begin
A = sparse([4.0 1 0; 1 4 1; 0 1 4])
F = cholesky(A)
@test_throws DimensionMismatch ldlt!(F, sparse(1.0I, 4, 4))
@test :D ∉ propertynames(F)
@test F \ ones(3) ≈ A \ ones(3)
end

@testset "Issues #26367 and #26368" begin
A = sparse([0.0 1 0 0; 0 0 0 0])
F = qr(A)
Expand Down
Loading