Skip to content

Commit

Permalink
Make ldlt throw with zero pivot (#38051)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarrasch authored Oct 29, 2020
1 parent 72971c4 commit f613b55
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
10 changes: 4 additions & 6 deletions stdlib/LinearAlgebra/src/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1284,12 +1284,10 @@ function factorize(A::StridedMatrix{T}) where T
return Bidiagonal(diag(A), diag(A, 1), :U)
end
if utri1
if (herm & (T <: Complex)) | sym
try
return ldlt!(SymTridiagonal(diag(A), diag(A, -1)))
catch
end
end
# TODO: enable once a specialized, non-dense bunchkaufman method exists
# if (herm & (T <: Complex)) | sym
# return bunchkaufman(SymTridiagonal(diag(A), diag(A, -1)))
# end
return lu(Tridiagonal(diag(A, -1), diag(A), diag(A, 1)))
end
end
Expand Down
3 changes: 2 additions & 1 deletion stdlib/LinearAlgebra/src/ldlt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ function ldlt!(S::SymTridiagonal{T,V}) where {T,V}
n = size(S,1)
d = S.dv
e = S.ev
@inbounds @simd for i = 1:n-1
@inbounds for i in 1:n-1
iszero(d[i]) && throw(ZeroPivotException(i))
e[i] /= d[i]
d[i+1] -= e[i]^2*d[i]
end
Expand Down
9 changes: 9 additions & 0 deletions stdlib/LinearAlgebra/test/lu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ dimg = randn(n)/2
@test luhs.L*luhs.U luhs.P*Matrix(HS)
end
end

@testset "Factorization of symtridiagonal dense matrix with zero ldlt-pivot (#38026)" begin
A = [0.0 -1.0 0.0 0.0
-1.0 0.0 0.0 0.0
0.0 0.0 0.0 -1.0
0.0 0.0 -1.0 0.0]
F = factorize(A)
@test all((!isnan).(Matrix(F)))
end
end

@testset "Singular matrices" for T in (Float64, ComplexF64)
Expand Down

0 comments on commit f613b55

Please sign in to comment.