code: def _cg(fhess_p, fgrad, maxiter, tol):
      """
      Solve iteratively the linear system 'fhess_p . xsupi = fgrad'
      with a conjugate gradient descent.
  
      Parameters
      ----------
      fhess_p : callable
          Function that takes the gradient as a parameter and returns the
          matrix product of the Hessian and gradient
  
      fgrad : ndarray, shape (n_features,) or (n_features + 1,)
          Gradient vector
  
      maxiter : int
          Number of CG iterations.
  
      tol : float
          Stopping criterion.
  
      Returns
      -------
      xsupi : ndarray, shape (n_features,) or (n_features + 1,)
          Estimated solution
      """
      xsupi = np.zeros(len(fgrad), dtype=fgrad.dtype)
      ri = fgrad
      psupi = -ri
      i = 0
      dri0 = np.dot(ri, ri)
  
      while i <= maxiter:
          if np.sum(np.abs(ri)) <= tol:
              break
  
          Ap = fhess_p(psupi)
          # check curvature
          curv = np.dot(psupi, Ap)
          if 0 <= curv <= 3 * np.finfo(np.float64).eps:
              break
          elif curv < 0:
              if i > 0:
                  break
              else:
                  # fall back to steepest descent direction
                  xsupi += dri0 / curv * psupi
                  break
          alphai = dri0 / curv
          xsupi += alphai * psupi
          ri = ri + alphai * Ap
          dri1 = np.dot(ri, ri)
          betai = dri1 / dri0
          psupi = -ri + betai * psupi
          i = i + 1
          dri0 = dri1  # update np.dot(ri,ri) for next time.
  
      return xsupi
  
file_path: catboost/contrib/python/scikit-learn/py2/sklearn/utils/optimize.py
imports: import numpy
  import warnings
  from scipy.optimize.linesearch import line_search_wolfe2, line_search_wolfe1
  from ..exceptions import ConvergenceWarning
label_desc: Use image node_id 2 for calling a global function with example usage: _cg(fhess_p, fgrad, maxiter, tol) and returns: xsupi