code: def scalar_search_wolfe1(
      phi,
      derphi,
      phi0=None,
      old_phi0=None,
      derphi0=None,
      c1=1e-4,
      c2=0.9,
      amax=50,
      amin=1e-8,
      xtol=1e-14,
  ):
      """
      Scalar function search for alpha that satisfies strong Wolfe conditions
  
      alpha > 0 is assumed to be a descent direction.
  
      Parameters
      ----------
      phi : callable phi(alpha)
          Function at point `alpha`
      derphi : callable phi'(alpha)
          Objective function derivative. Returns a scalar.
      phi0 : float, optional
          Value of phi at 0
      old_phi0 : float, optional
          Value of phi at previous point
      derphi0 : float, optional
          Value derphi at 0
      c1 : float, optional
          Parameter for Armijo condition rule.
      c2 : float, optional
          Parameter for curvature condition rule.
      amax, amin : float, optional
          Maximum and minimum step size
      xtol : float, optional
          Relative tolerance for an acceptable step.
  
      Returns
      -------
      alpha : float
          Step size, or None if no suitable step was found
      phi : float
          Value of `phi` at the new point `alpha`
      phi0 : float
          Value of `phi` at `alpha=0`
  
      Notes
      -----
      Uses routine DCSRCH from MINPACK.
  
      """
  
      if phi0 is None:
          phi0 = phi(0.0)
      if derphi0 is None:
          derphi0 = derphi(0.0)
  
      if old_phi0 is not None and derphi0 != 0:
          alpha1 = min(1.0, 1.01 * 2 * (phi0 - old_phi0) / derphi0)
          if alpha1 < 0:
              alpha1 = 1.0
      else:
          alpha1 = 1.0
  
      phi1 = phi0
      derphi1 = derphi0
      isave = np.zeros((2,), np.intc)
      dsave = np.zeros((13,), float)
      task = b"START"
  
      maxiter = 100
      for i in range(maxiter):
          stp, phi1, derphi1, task = minpack2.dcsrch(
              alpha1,
              phi1,
              derphi1,
              c1,
              c2,
              xtol,
              task,
              amin,
              amax,
              isave,
              dsave,
          )
          if task[:2] == b"FG":
              alpha1 = stp
              phi1 = phi(stp)
              derphi1 = derphi(stp)
          else:
              break
      else:
          # maxiter reached, the line search did not converge
          stp = None
  
      if task[:5] == b"ERROR" or task[:4] == b"WARN":
          stp = None  # failed
  
      return stp, phi1, phi0
  
file_path: catboost/contrib/python/scipy/py3/scipy/optimize/linesearch.py
imports: from warnings import warn
  from scipy.optimize import minpack2
  import numpy
label_desc: Use image node_id 2 for calling a global function with example usage: scalar_search_wolfe1(phi, derphi, phi0, old_phi0, derphi0, c1, c2, amax, amin, xtol) and returns: stp,  phi1,  phi0