Skip to content

fix: Cholesky::new returns None non-positive-definite complex matrices#1592

Open
DiogoRibeiro7 wants to merge 5 commits intodimforge:mainfrom
DiogoRibeiro7:fix/cholesky-complex-non-pd
Open

fix: Cholesky::new returns None non-positive-definite complex matrices#1592
DiogoRibeiro7 wants to merge 5 commits intodimforge:mainfrom
DiogoRibeiro7:fix/cholesky-complex-non-pd

Conversation

@DiogoRibeiro7
Copy link
Copy Markdown

For complex types, always succeeds (every complex number has a square root), so non-PD matrices were silently producing garbage results. Fix by calling on the real part of each diagonal pivot instead — matching the behaviour already correct for .

Fixes #1536

197g and others added 3 commits January 4, 2026 21:33
* Add known-failing unit test case for SymmetricEigen

* Fix eigenvector calculation for subdim=2 case in SymmetricEigen
…rices

For complex types,  always succeeds (every complex number has
a square root), so non-PD matrices were silently producing garbage
results. Fix by calling  on the real part of each diagonal
pivot instead — matching the behaviour already correct for .

Fixes dimforge#1536
@alexhroom
Copy link
Copy Markdown
Collaborator

first just to note this has already been fixed in #1574 - but if you're able to answer review comments faster than that I'll probably merge this instead.

Secondly before I review, there seems to be some commits that aren't relevant to your PR here - do you mind tidying them up?

@DiogoRibeiro7 DiogoRibeiro7 force-pushed the fix/cholesky-complex-non-pd branch from 7aed676 to f2bc954 Compare April 10, 2026 11:35
@DiogoRibeiro7
Copy link
Copy Markdown
Author

first just to note this has already been fixed in #1574 - but if you're able to answer review comments faster than that I'll probably merge this instead.

Secondly before I review, there seems to be some commits that aren't relevant to your PR here - do you mind tidying them up?

Thanks for the suggestion! I went a slightly different route — instead of explicit checks, the closure now just does v.real().try_sqrt().map(T::from_real). This way try_sqrt() on the real part naturally returns None for negative/zero values, and the imaginary part is intentionally ignored to tolerate small floating-point residuals (for Hermitian matrices the diagonal stays real throughout the algorithm). I also cleaned up the unrelated commits.

…rices

For complex types,  always succeeds (every complex number has
a square root), so non-PD matrices were silently producing garbage
results. Fix by calling  on the real part of each diagonal
pivot instead — matching the behaviour already correct for .

Fixes dimforge#1536
@DiogoRibeiro7 DiogoRibeiro7 force-pushed the fix/cholesky-complex-non-pd branch from f2bc954 to d136b91 Compare April 10, 2026 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cholesky erroneously produces (wrong) results for non-positive-definite complex matrices

4 participants