33def gauss_seidel(a, b, max_iter=1000, tol=1e-8, omega=1.0):
35 Solve the linear system ax = b using the Gauss-Seidel method.
40 Coefficient matrix (n x n)
42 Right-hand side vector (n,)
43 max_iter : int, optional
44 Maximum number of iterations
47 omega : float, optional
55 0 if converged, non-zero otherwise
57 a = np.ascontiguousarray(a)
58 b = np.asfortranarray(b)
65 if np.issubdtype(a.dtype, np.floating):
66 if a.dtype == np.float32:
67 status = _nulapack.sgegssv(a_flat, b, x, max_iter, tol, omega, 0, n)
69 status = _nulapack.dgegssv(a_flat, b, x, max_iter, tol, omega, 0, n)
70 elif np.issubdtype(a.dtype, np.complexfloating):
71 if a.dtype == np.complex64:
72 status = _nulapack.cgegssv(a_flat, b, x, max_iter, tol, omega, 0, n)
74 status = _nulapack.zgegssv(a_flat, b, x, max_iter, tol, omega, 0, n)
76 raise TypeError(f
"Unsupported array dtype: {a.dtype}")
78 return x, int(status)
if status
is not None else 0