code: def ordqz(
      A,
      B,
      sort="lhp",
      output="real",
      overwrite_a=False,
      overwrite_b=False,
      check_finite=True,
  ):
      """QZ decomposition for a pair of matrices with reordering.
  
      Parameters
      ----------
      A : (N, N) array_like
          2-D array to decompose
      B : (N, N) array_like
          2-D array to decompose
      sort : {callable, 'lhp', 'rhp', 'iuc', 'ouc'}, optional
          Specifies whether the upper eigenvalues should be sorted. A
          callable may be passed that, given an ordered pair ``(alpha,
          beta)`` representing the eigenvalue ``x = (alpha/beta)``,
          returns a boolean denoting whether the eigenvalue should be
          sorted to the top-left (True). For the real matrix pairs
          ``beta`` is real while ``alpha`` can be complex, and for
          complex matrix pairs both ``alpha`` and ``beta`` can be
          complex. The callable must be able to accept a NumPy
          array. Alternatively, string parameters may be used:
  
              - 'lhp'   Left-hand plane (x.real < 0.0)
              - 'rhp'   Right-hand plane (x.real > 0.0)
              - 'iuc'   Inside the unit circle (x*x.conjugate() < 1.0)
              - 'ouc'   Outside the unit circle (x*x.conjugate() > 1.0)
  
          With the predefined sorting functions, an infinite eigenvalue
          (i.e., ``alpha != 0`` and ``beta = 0``) is considered to lie in
          neither the left-hand nor the right-hand plane, but it is
          considered to lie outside the unit circle. For the eigenvalue
          ``(alpha, beta) = (0, 0)``, the predefined sorting functions
          all return `False`.
      output : str {'real','complex'}, optional
          Construct the real or complex QZ decomposition for real matrices.
          Default is 'real'.
      overwrite_a : bool, optional
          If True, the contents of A are overwritten.
      overwrite_b : bool, optional
          If True, the contents of B are overwritten.
      check_finite : bool, optional
          If true checks the elements of `A` and `B` are finite numbers. If
          false does no checking and passes matrix through to
          underlying algorithm.
  
      Returns
      -------
      AA : (N, N) ndarray
          Generalized Schur form of A.
      BB : (N, N) ndarray
          Generalized Schur form of B.
      alpha : (N,) ndarray
          alpha = alphar + alphai * 1j. See notes.
      beta : (N,) ndarray
          See notes.
      Q : (N, N) ndarray
          The left Schur vectors.
      Z : (N, N) ndarray
          The right Schur vectors.
  
      Notes
      -----
      On exit, ``(ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N``, will be the
      generalized eigenvalues.  ``ALPHAR(j) + ALPHAI(j)*i`` and
      ``BETA(j),j=1,...,N`` are the diagonals of the complex Schur form (S,T)
      that would result if the 2-by-2 diagonal blocks of the real generalized
      Schur form of (A,B) were further reduced to triangular form using complex
      unitary transformations. If ALPHAI(j) is zero, then the jth eigenvalue is
      real; if positive, then the ``j``th and ``(j+1)``st eigenvalues are a
      complex conjugate pair, with ``ALPHAI(j+1)`` negative.
  
      .. versionadded:: 0.17.0
  
      See also
      --------
      qz
  
      Examples
      --------
      >>> from scipy.linalg import ordqz
      >>> A = np.array([[2, 5, 8, 7], [5, 2, 2, 8], [7, 5, 6, 6], [5, 4, 4, 8]])
      >>> B = np.array([[0, 6, 0, 0], [5, 0, 2, 1], [5, 2, 6, 6], [4, 7, 7, 7]])
      >>> AA, BB, alpha, beta, Q, Z = ordqz(A, B, sort='lhp')
  
      Since we have sorted for left half plane eigenvalues, negatives come first
  
      >>> (alpha/beta).real < 0
      array([ True,  True, False, False], dtype=bool)
  
      """
      (AA, BB, _, *ab, Q, Z, _, _), typ = _qz(
          A,
          B,
          output=output,
          sort=None,
          overwrite_a=overwrite_a,
          overwrite_b=overwrite_b,
          check_finite=check_finite,
      )
  
      if typ == "s":
          alpha, beta = ab[0] + ab[1] * np.complex64(1j), ab[2]
      elif typ == "d":
          alpha, beta = ab[0] + ab[1] * 1.0j, ab[2]
      else:
          alpha, beta = ab
  
      sfunction = _select_function(sort)
      select = sfunction(alpha, beta)
  
      tgsen = get_lapack_funcs("tgsen", (AA, BB))
      # the real case needs 4n + 16 lwork
      lwork = 4 * AA.shape[0] + 16 if typ in "sd" else 1
      AAA, BBB, *ab, QQ, ZZ, _, _, _, _, info = tgsen(
          select, AA, BB, Q, Z, ijob=0, lwork=lwork, liwork=1
      )
  
      # Once more for tgsen output
      if typ == "s":
          alpha, beta = ab[0] + ab[1] * np.complex64(1j), ab[2]
      elif typ == "d":
          alpha, beta = ab[0] + ab[1] * 1.0j, ab[2]
      else:
          alpha, beta = ab
  
      if info < 0:
          raise ValueError(
              f"Illegal value in argument {-info} of tgsen"
          )
      elif info == 1:
          raise ValueError(
              "Reordering of (A, B) failed because the transformed"
              " matrix pair (A, B) would be too far from "
              "generalized Schur form; the problem is very "
              "ill-conditioned. (A, B) may have been partially "
              "reordered."
          )
  
      return AAA, BBB, alpha, beta, QQ, ZZ
  
file_path: catboost/contrib/python/scipy/py3/scipy/linalg/_decomp_qz.py
imports: import warnings
  import numpy
  from numpy import asarray_chkfinite
  from .misc import LinAlgError, _datacopied, LinAlgWarning
  from .lapack import get_lapack_funcs
label_desc: Use image node_id 8 for calling a global function with example usage: ordqz(A, B, sort, output, overwrite_a, overwrite_b, check_finite) and returns: AAA,  BBB,  alpha,  beta,  QQ,  ZZ