dpnp.scipy.sparse.linalg.cg¶
- dpnp.scipy.sparse.linalg.cg(A, b, x0: dpnp_array | None = None, *, rtol: float = 1e-05, tol: float | None = None, maxiter: int | None = None, M=None, callback: Callable | None = None, atol=None) tuple[dpnp_array, int][source]¶
Use Conjugate Gradient iteration to solve
Ax = bfor a Hermitian positive-definiteA.For full documentation refer to
scipy.sparse.linalg.cg.- Parameters:
- A{dpnp.ndarray, usm_ndarray, LinearOperator, csr_matrix}
The Hermitian positive-definite operator of shape
(N, N).- b{dpnp.ndarray, usm_ndarray}
Right-hand side of the linear system, shape
(N,)or(N, 1).- x0{None, dpnp.ndarray, usm_ndarray}, optional
Initial guess for the solution. Default:
None(zeros).- rtolfloat, optional
Relative convergence tolerance. Default:
1e-5.- tol{None, float}, optional
Deprecated alias for rtol. Default:
None.- maxiter{None, int}, optional
Maximum number of iterations. Default:
10 * N.- M{None, dpnp.ndarray, usm_ndarray, LinearOperator}, optional
Symmetric positive-definite preconditioner. Default:
None.- callback{None, callable}, optional
Called as
callback(xk)after each iteration. Default:None.- atol{None, float}, optional
Absolute convergence tolerance. Default:
None.
- Returns:
- xdpnp.ndarray
The converged solution.
- infoint
infofollows the SciPy / CuPy contract:info == 0: converged successfullyinfo > 0: did not converge; value is the iteration count at which the solver stopped (equalsmaxiterwhen the iteration budget was exhausted, or the iteration index when a numerical breakdown short-circuited the loop).info < 0: reserved for illegal-input errors; not produced by this implementation (illegal inputs raiseValueErrorinstead).
Previous versions of this routine returned
-1for anrz/pApbreakdown, which violated the SciPy contract and broke user code that branched oninfo > 0.