33def doolittle(a: np.ndarray):
35 Compute the LU Doolittle decomposition of a general matrix A.
40 Coefficient matrix (n x n) stored as a full matrix.
45 Lower triangular matrix from the factorization.
47 Upper triangular matrix from the factorization.
49 0 if success, <0 if a zero diagonal in U was detected.
51 a = np.ascontiguousarray(a)
54 a_flat = a.ravel(order=
"C")
55 l_flat = np.zeros_like(a_flat)
56 u_flat = np.zeros_like(a_flat)
57 info = np.zeros(1, dtype=np.int32)
59 if np.issubdtype(a.dtype, np.floating):
60 if a.dtype == np.float32:
61 _nulapack.sgedtrf(n, a_flat, l_flat, u_flat, info)
63 _nulapack.dgedtrf(n, a_flat, l_flat, u_flat, info)
64 elif np.issubdtype(a.dtype, np.complexfloating):
65 if a.dtype == np.complex64:
66 _nulapack.cgedtrf(n, a_flat, l_flat, u_flat, info)
68 _nulapack.zgedtrf(n, a_flat, l_flat, u_flat, info)
70 raise TypeError(f
"Unsupported array dtype: {a.dtype}")
72 return l_flat.reshape(n, n, order=
"C"), u_flat.reshape(n, n, order=
"C"), int(info[0])