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: from __future__ import division, print_function, absolute_import
  import warnings
  import sys
  import numpy
  from scipy._lib.six import callable, xrange
  from numpy import atleast_1d, eye, mgrid, argmin, zeros, shape, squeeze, vectorize, asarray, sqrt, Inf, asfarray, isinf
  import numpy
  from .linesearch import line_search_wolfe1, line_search_wolfe2, line_search_wolfe2, LineSearchWarning
  from scipy._lib._util import getargspec_no_self
label_desc: Use image node_id 15 for calling a global function with example usage: _line_search_wolfe12(f, fprime, xk, pk, gfk, old_fval, old_old_fval) and returns: ret