33def thomas(a: np.ndarray, b: np.ndarray):
35 Solve a tridiagonal linear system A * X = B using the Thomas algorithm.
40 Coefficient matrix (n x n) stored as a full matrix.
42 Right-hand side vector (n,)
49 0 if success, <0 if zero diagonal detected
51 a = np.ascontiguousarray(a)
52 b = np.asfortranarray(b)
59 if np.issubdtype(a.dtype, np.floating):
60 if a.dtype == np.float32:
61 status = _nulapack.sgttsv(a_flat, b, x, 0, n)
63 status = _nulapack.dgttsv(a_flat, b, x, 0, n)
64 elif np.issubdtype(a.dtype, np.complexfloating):
65 if a.dtype == np.complex64:
66 status = _nulapack.cgttsv(a_flat, b, x, 0, n)
68 status = _nulapack.zgttsv(a_flat, b, x, 0, n)
70 raise TypeError(f
"Unsupported array dtype: {a.dtype}")
72 return x, int(status)
if status
is not None else 0