33def cholesky(a: np.ndarray):
35 Compute the Cholesky factorization of a symmetric/Hermitian
36 positive-definite matrix A using NULAPACK.
41 Coefficient matrix (n x n) stored as a full matrix. Real matrices
42 should be symmetric, complex matrices should be Hermitian and
48 Lower-triangular matrix from the factorization (A = L * L^T or
51 0 if success, >0 if the matrix is not positive-definite.
53 a = np.ascontiguousarray(a)
57 a_flat = a.ravel(order=
"C")
58 l_flat = np.zeros_like(a_flat)
59 info = np.zeros(1, dtype=np.int32)
61 if np.issubdtype(a.dtype, np.floating):
62 if a.dtype == np.float32:
63 _nulapack.spoctrf(n, a_flat, l_flat, lda, info)
65 _nulapack.dpoctrf(n, a_flat, l_flat, lda, info)
66 elif np.issubdtype(a.dtype, np.complexfloating):
67 if a.dtype == np.complex64:
68 _nulapack.cpoctrf(n, a_flat, l_flat, lda, info)
70 _nulapack.zpoctrf(n, a_flat, l_flat, lda, info)
72 raise TypeError(f
"Unsupported array dtype: {a.dtype}")
74 return np.tril(l_flat.reshape(n, n, order=
"C")), int(info[0])