Skip to content

Fix error message for LDL factorization failures - #2956

Merged
odow merged 2 commits into
masterfrom
od/fix-ldl
Mar 1, 2026
Merged

Fix error message for LDL factorization failures#2956
odow merged 2 commits into
masterfrom
od/fix-ldl

Conversation

@odow

@odow odow commented Feb 27, 2026

Copy link
Copy Markdown
Member

@odow

odow commented Mar 1, 2026

Copy link
Copy Markdown
Member Author

I'm not sure what's going on here. LDLFactorizations.factorized returns false, but there is a valid factorisation:

julia> import LDLFactorizations

julia> import LinearAlgebra

julia> Q = [1.0 1.0; 1.0 1.0]
2×2 Matrix{Float64}:
 1.0  1.0
 1.0  1.0

julia> f = LDLFactorizations.ldl(Q)
LDLFactorizations.LDLFactorization{Float64, Int64, Int64, Int64}(true, false, false, 2, [2, -1], [1, 0], [2, 2], [1, 2], [1, 2], [1, 2, 2], Int64[], Int64[], [2], [1.0], [1.0, 0.0], [0.0, 0.0], [1, 1], 0.0, 0.0, 0.0, 2)

julia> @assert f.P == [1, 2]

julia> L = Matrix(f.L) .+ LinearAlgebra.I(2)
2×2 Matrix{Float64}:
 1.0  0.0
 1.0  1.0

julia> D = Matrix(f.D)
2×2 Matrix{Float64}:
 1.0  0.0
 0.0  0.0

julia> LDLFactorizations.factorized(f)
false

julia> L * D * L'
2×2 Matrix{Float64}:
 1.0  1.0
 1.0  1.0

cc @amontoison any ideas?

@amontoison

Copy link
Copy Markdown
Contributor

@odow I checked the code and we stop the factorization when we encounter D[k] == 0 and we return false for "factorized".

But if k == n, we reached the end of the factorization and we can return true.

@odow

odow commented Mar 1, 2026

Copy link
Copy Markdown
Member Author

Is that intentional or a bug?

@amontoison

Copy link
Copy Markdown
Contributor

It was intentional because we can't do ldiv! or \ if we have D[k] == 0.
But we can still do mul!.
I added another attribute to specify if we have a singularity of not.

@odow

odow commented Mar 1, 2026

Copy link
Copy Markdown
Member Author

Merging because this is an improvement for now. We can update when a new version of LDLFactorizations is released

@odow
odow merged commit 6dec535 into master Mar 1, 2026
34 checks passed
@odow
odow deleted the od/fix-ldl branch March 1, 2026 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants