code: def _line_search_wolfe12(
      f, fprime, xk, pk, gfk, old_fval, old_old_fval, **kwargs
  ):
      """
      Same as line_search_wolfe1, but fall back to line_search_wolfe2 if
      suitable step length is not found, and raise an exception if a
      suitable step length is not found.
  
      Raises
      ------
      _LineSearchError
          If no suitable step size is found
  
      """
  
      extra_condition = kwargs.pop("extra_condition", None)
  
      ret = line_search_wolfe1(
          f, fprime, xk, pk, gfk, old_fval, old_old_fval, **kwargs
      )
  
      if ret[0] is not None and extra_condition is not None:
          xp1 = xk + ret[0] * pk
          if not extra_condition(ret[0], xp1, ret[3], ret[5]):
              # Reject step if extra_condition fails
              ret = (None,)
  
      if ret[0] is None:
          # line search failed: try different one.
          with warnings.catch_warnings():
              warnings.simplefilter("ignore", LineSearchWarning)
              kwargs2 = {}
              for key in ("c1", "c2", "amax"):
                  if key in kwargs:
                      kwargs2[key] = kwargs[key]
              ret = line_search_wolfe2(
                  f,
                  fprime,
                  xk,
                  pk,
                  gfk,
                  old_fval,
                  old_old_fval,
                  extra_condition=extra_condition,
                  **kwargs2,
              )
  
      if ret[0] is None:
          raise _LineSearchError()
  
      return ret
  
imports: import warnings
  import sys
  from numpy import atleast_1d, eye, argmin, zeros, shape, squeeze, asarray, sqrt, Inf, asfarray, isinf
  import numpy
  from .linesearch import line_search_wolfe1, line_search_wolfe2, line_search_wolfe2, LineSearchWarning
  from ._numdiff import approx_derivative
  from scipy._lib._util import getfullargspec_no_self
  from scipy._lib._util import MapWrapper
  from scipy.optimize._differentiable_functions import ScalarFunction, FD_METHODS
label_desc: Use image node_id 17 for calling a global function with example usage: _line_search_wolfe12(f, fprime, xk, pk, gfk, old_fval, old_old_fval) and returns: ret