class_docstr: Preconditioned conjugate gradient method.
  
  To solve Ax = b:
      M = A.diagonal() # or some other preconditioner
      solver = _PCGSolver(lambda x: A * x, lambda x: M * x)
      x = solver.solve(b)
  
  The inputs A and M are functions which compute
  matrix multiplication on the argument.
  A - multiply by the matrix A in Ax=b
  M - multiply by M, the preconditioner surrogate for A
  
  Warning: There is no limit on number of iterations.
class_docstr_tok: ["Preconditioned","conjugate","gradient","method",".","To","solve","Ax","=","b",":","M","=","A.diagonal","(",")","#","or","some","other","preconditioner","solver","=","_PCGSolver","(","lambda","x",":","A","*","x",",","lambda","x",":","M","*","x",")","x","=","solver.solve","(","b",")","The","inputs","A","and","M","are","functions","which","compute","matrix","multiplication","on","the","argument",".","A","-","multiply","by","the","matrix","A","in","Ax=b","M","-","multiply","by","M",",","the","preconditioner","surrogate","for","A","Warning",":","There","is","no","limit","on","number","of","iterations","."]
code: def _solve(self, b, tol):
      import numpy as np
      import scipy as sp
  
      A = self._A
      M = self._M
      tol *= sp.linalg.blas.dasum(b)
      # Initialize.
      x = np.zeros(b.shape)
      r = b.copy()
      z = M(r)
      rz = sp.linalg.blas.ddot(r, z)
      p = z.copy()
      # Iterate.
      while True:
          Ap = A(p)
          alpha = rz / sp.linalg.blas.ddot(p, Ap)
          x = sp.linalg.blas.daxpy(p, x, a=alpha)
          r = sp.linalg.blas.daxpy(Ap, r, a=-alpha)
          if sp.linalg.blas.dasum(r) < tol:
              return x
          z = M(r)
          beta = sp.linalg.blas.ddot(r, z)
          beta, rz = beta / rz, beta
          p = sp.linalg.blas.daxpy(p, z, a=beta)
  
file_path: networkx/networkx/linalg/algebraicconnectivity.py
imports: from functools import partial
  import networkx
  from networkx.utils import not_implemented_for, np_random_state, reverse_cuthill_mckee_ordering
label_desc: Use image node_id 3 for calling the _PCGSolver obj's underlying member method code with example usage: obj._solve(b, tol) and returns: x