Reputation: 699
I am looking for Cholesky/LDL-decomposition for semi-definite matrices in python.
Search-results:
numpy.linalg.cholesky
and sympy.Matrix.LDLdecomposition
only work for positive-definite.My instances are rather small, about $100\times100$, so a symbolic solution is fine (the bottleneck is in some other place).
Upvotes: 2
Views: 2765
Reputation: 3106
With SciPy v1.1.0
and later, you can use scipy.linalg.ldl
for the factorization of indefinite matrices.
example :
Creating a positive definite matrix arr
>>> import numpy as np
>>> import scipy.linalg as la
>>> arr = np.random.rand(100,97)
>>> M = arr @ arr.T
>>> l, d, p = la.ldl(M)
>>> np.allclose(l.dot(d).dot(l.T) - M, np.zeros([100, 100]))
True
Upvotes: 2
Reputation: 1999
You can just use an LU decomposition. For symmetric or hermitian matrices they are equivalent up to some sign ambiguities.
Upvotes: 2