nodes: 0, module; 1, function_definition; 2, function_name:ordqz; 3, parameters; 4, block; 5, identifier:A; 6, identifier:B; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, expression_statement; 13, import_statement; 14, import_statement; 15, import_from_statement; 16, import_from_statement; 17, import_from_statement; 18, import_from_statement; 19, import_from_statement; 20, comment:#NOTE: should users be able to set these?; 21, expression_statement; 22, expression_statement; 23, expression_statement; 24, if_statement; 25, expression_statement; 26, expression_statement; 27, expression_statement; 28, if_statement; 29, expression_statement; 30, if_statement; 31, expression_statement; 32, expression_statement; 33, if_statement; 34, comment:# for real results has a, b, alphar, alphai, beta, q, z, m, pl, pr, dif,; 35, comment:# work, iwork, info; 36, if_statement; 37, identifier:sort; 38, string; 39, identifier:output; 40, string; 41, identifier:overwrite_a; 42, False; 43, identifier:overwrite_b; 44, False; 45, identifier:check_finite; 46, True; 47, comment:"""
      QZ decomposition for a pair of matrices with reordering.
  
      .. versionadded:: 0.17.0
  
      Parameters
      ----------
      A : (N, N) array_like
          2d array to decompose
      B : (N, N) array_like
          2d 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 a eigenvalue, returns a boolean denoting
          whether the eigenvalue should be sorted to the top-left (True). For
          real matrix pairs, the sort function takes three real arguments
          (alphar, alphai, beta). The eigenvalue
          ``x = (alphar + alphai*1j)/beta``.  For complex matrix pairs or
          output='complex', the sort function takes two complex arguments
          (alpha, beta). The eigenvalue ``x = (alpha/beta)``.
          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)
  
      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 j-th eigenvalue is
      real; if positive, then the ``j``-th and ``(j+1)``-st eigenvalues are a complex
      conjugate pair, with ``ALPHAI(j+1)`` negative.
  
      See also
      --------
      qz
      """; 48, dotted_name; 49, aliased_import; 50, dotted_name; 51, dotted_name; 52, dotted_name; 53, dotted_name; 54, dotted_name; 55, dotted_name; 56, dotted_name; 57, dotted_name; 58, dotted_name; 59, dotted_name; 60, dotted_name; 61, dotted_name; 62, assignment; 63, assignment; 64, assignment; 65, comparison_operator:typ not in 'cz'; 66, block; 67, else_clause; 68, assignment; 69, assignment; 70, assignment; 71, boolean_operator; 72, block; 73, assignment; 74, boolean_operator; 75, block; 76, assignment; 77, assignment; 78, comparison_operator:info < 0; 79, block; 80, elif_clause; 81, comparison_operator:typ in ['f', 'd']; 82, block; 83, comment:# for complex results has a, b, alpha, beta, q, z, m, pl, pr, dif, work,; 84, comment:# iwork, info; 85, else_clause; 86, string_content:lhp; 87, string_content:real; 88, identifier:warnings; 89, dotted_name; 90, identifier:np; 91, identifier:numpy; 92, identifier:asarray_chkfinite; 93, identifier:scipy; 94, identifier:linalg; 95, identifier:misc; 96, identifier:LinAlgError; 97, identifier:_datacopied; 98, identifier:scipy; 99, identifier:linalg; 100, identifier:lapack; 101, identifier:get_lapack_funcs; 102, identifier:scipy; 103, identifier:_lib; 104, identifier:six; 105, identifier:callable; 106, identifier:scipy; 107, identifier:linalg; 108, identifier:_decomp_qz; 109, identifier:_qz; 110, identifier:_select_function; 111, identifier:lwork; 112, None; 113, pattern_list; 114, call; 115, pattern_list; 116, expression_list; 117, identifier:typ; 118, string; 119, expression_statement; 120, block; 121, identifier:sfunction; 122, call; 123, identifier:select; 124, call; 125, pattern_list; 126, call; 127, comparison_operator:lwork is None; 128, comparison_operator:lwork == -1; 129, expression_statement; 130, expression_statement; 131, comment:# looks like wrong value passed to ZTGSYL if not; 132, expression_statement; 133, identifier:liwork; 134, None; 135, comparison_operator:liwork is None; 136, comparison_operator:liwork == -1; 137, expression_statement; 138, expression_statement; 139, identifier:result; 140, call; 141, identifier:info; 142, subscript; 143, identifier:info; 144, integer:0; 145, raise_statement; 146, comparison_operator:info == 1; 147, block; 148, identifier:typ; 149, list; 150, expression_statement; 151, return_statement; 152, block; 153, identifier:numpy; 154, identifier:result; 155, identifier:typ; 156, identifier:_qz; 157, argument_list; 158, identifier:AA; 159, identifier:BB; 160, identifier:Q; 161, identifier:Z; 162, subscript; 163, subscript; 164, subscript; 165, subscript; 166, string_content:cz; 167, assignment; 168, expression_statement; 169, identifier:_select_function; 170, argument_list; 171, identifier:sfunction; 172, argument_list; 173, identifier:tgsen; 174, identifier:get_lapack_funcs; 175, argument_list; 176, identifier:lwork; 177, None; 178, identifier:lwork; 179, unary_operator; 180, assignment; 181, assignment; 182, augmented_assignment; 183, identifier:liwork; 184, None; 185, identifier:liwork; 186, unary_operator; 187, assignment; 188, assignment; 189, identifier:tgsen; 190, argument_list; 191, identifier:result; 192, unary_operator; 193, call; 194, identifier:info; 195, integer:1; 196, raise_statement; 197, string; 198, string; 199, assignment; 200, tuple; 201, return_statement; 202, identifier:A; 203, identifier:B; 204, keyword_argument; 205, keyword_argument; 206, keyword_argument; 207, keyword_argument; 208, keyword_argument; 209, keyword_argument; 210, identifier:result; 211, integer:0; 212, identifier:result; 213, integer:1; 214, identifier:result; 215, unary_operator; 216, identifier:result; 217, unary_operator; 218, pattern_list; 219, expression_list; 220, assignment; 221, identifier:sort; 222, identifier:alpha; 223, identifier:beta; 224, tuple; 225, tuple; 226, integer:1; 227, identifier:result; 228, call; 229, identifier:lwork; 230, call; 231, identifier:lwork; 232, integer:1; 233, integer:1; 234, identifier:result; 235, call; 236, identifier:liwork; 237, subscript; 238, identifier:select; 239, identifier:AA; 240, identifier:BB; 241, identifier:Q; 242, identifier:Z; 243, keyword_argument; 244, keyword_argument; 245, integer:1; 246, identifier:ValueError; 247, argument_list; 248, call; 249, string_content:f; 250, string_content:d; 251, identifier:alpha; 252, binary_operator:result[2] + result[3] * 1.j; 253, subscript; 254, subscript; 255, identifier:alpha; 256, subscript; 257, subscript; 258, subscript; 259, expression_list; 260, identifier:output; 261, identifier:output; 262, identifier:lwork; 263, identifier:lwork; 264, identifier:sort; 265, None; 266, identifier:overwrite_a; 267, identifier:overwrite_a; 268, identifier:overwrite_b; 269, identifier:overwrite_b; 270, identifier:check_finite; 271, identifier:check_finite; 272, integer:4; 273, integer:3; 274, identifier:alpha; 275, identifier:beta; 276, binary_operator:result[3] + result[4]*1.j; 277, subscript; 278, pattern_list; 279, expression_list; 280, string; 281, identifier:AA; 282, identifier:BB; 283, identifier:tgsen; 284, argument_list; 285, attribute; 286, argument_list; 287, identifier:tgsen; 288, argument_list; 289, subscript; 290, integer:0; 291, identifier:lwork; 292, identifier:lwork; 293, identifier:liwork; 294, identifier:liwork; 295, binary_operator:"Illegal value in argument %d of tgsen" % -info; 296, identifier:ValueError; 297, argument_list; 298, subscript; 299, binary_operator:result[3] * 1.j; 300, identifier:result; 301, integer:0; 302, identifier:result; 303, integer:1; 304, identifier:result; 305, integer:4; 306, identifier:result; 307, integer:5; 308, identifier:result; 309, integer:6; 310, subscript; 311, subscript; 312, subscript; 313, subscript; 314, subscript; 315, subscript; 316, subscript; 317, binary_operator:result[4]*1.j; 318, identifier:result; 319, integer:5; 320, identifier:alpha; 321, identifier:beta; 322, subscript; 323, subscript; 324, string_content:tgsen; 325, identifier:select; 326, identifier:AA; 327, identifier:BB; 328, identifier:Q; 329, identifier:Z; 330, keyword_argument; 331, attribute; 332, identifier:astype; 333, attribute; 334, identifier:select; 335, identifier:AA; 336, identifier:BB; 337, identifier:Q; 338, identifier:Z; 339, keyword_argument; 340, identifier:result; 341, unary_operator; 342, string:"Illegal value in argument %d of tgsen"; 343, unary_operator; 344, concatenated_string; 345, identifier:result; 346, integer:2; 347, subscript; 348, float:1.j; 349, identifier:result; 350, integer:0; 351, identifier:result; 352, integer:1; 353, identifier:result; 354, integer:2; 355, identifier:result; 356, integer:3; 357, identifier:result; 358, integer:4; 359, identifier:result; 360, integer:5; 361, identifier:result; 362, integer:3; 363, subscript; 364, float:1.j; 365, identifier:result; 366, integer:3; 367, identifier:result; 368, integer:4; 369, identifier:lwork; 370, unary_operator; 371, subscript; 372, identifier:real; 373, identifier:np; 374, identifier:int; 375, identifier:liwork; 376, unary_operator; 377, integer:2; 378, identifier:info; 379, string:"Reordering of (A, B) failed because the transformed"; 380, string:" matrix pair (A, B) would be too far from "; 381, string:"generalized Schur form; the problem is very "; 382, string:"ill-conditioned. (A, B) may have been partially "; 383, string:"reorded. If requested, 0 is returned in DIF(*), "; 384, string:"PL, and PR."; 385, identifier:result; 386, integer:3; 387, identifier:result; 388, integer:4; 389, integer:1; 390, subscript; 391, integer:0; 392, integer:1; 393, identifier:result; 394, unary_operator; 395, integer:3
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.
  
      .. versionadded:: 0.17.0
  
      Parameters
      ----------
      A : (N, N) array_like
          2d array to decompose
      B : (N, N) array_like
          2d 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 a eigenvalue, returns a boolean denoting
          whether the eigenvalue should be sorted to the top-left (True). For
          real matrix pairs, the sort function takes three real arguments
          (alphar, alphai, beta). The eigenvalue
          ``x = (alphar + alphai*1j)/beta``.  For complex matrix pairs or
          output='complex', the sort function takes two complex arguments
          (alpha, beta). The eigenvalue ``x = (alpha/beta)``.
          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)
  
      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 j-th eigenvalue is
      real; if positive, then the ``j``-th and ``(j+1)``-st eigenvalues are a complex
      conjugate pair, with ``ALPHAI(j+1)`` negative.
  
      See also
      --------
      qz
      """
  
  
      import warnings
  
      import numpy as np
      from numpy import asarray_chkfinite
  
      from scipy.linalg.misc import LinAlgError, _datacopied
      from scipy.linalg.lapack import get_lapack_funcs
  
      from scipy._lib.six import callable
  
      from scipy.linalg._decomp_qz import _qz, _select_function
  
      #NOTE: should users be able to set these?
      lwork = None
      result, typ = _qz(A, B, output=output, lwork=lwork, sort=None,
                        overwrite_a=overwrite_a, overwrite_b=overwrite_b,
                        check_finite=check_finite)
      AA, BB, Q, Z = result[0], result[1], result[-4], result[-3]
      if typ not in 'cz':
          alpha, beta = result[3] + result[4]*1.j, result[5]
      else:
          alpha, beta = result[3], result[4]
  
      sfunction = _select_function(sort)
      select = sfunction(alpha, beta)
  
      tgsen, = get_lapack_funcs(('tgsen',), (AA, BB))
  
      if lwork is None or lwork == -1:
          result = tgsen(select, AA, BB, Q, Z, lwork=-1)
          lwork = result[-3][0].real.astype(np.int)
          # looks like wrong value passed to ZTGSYL if not
          lwork += 1
  
      liwork = None
      if liwork is None or liwork == -1:
          result = tgsen(select, AA, BB, Q, Z, liwork=-1)
          liwork = result[-2][0]
  
      result = tgsen(select, AA, BB, Q, Z, lwork=lwork, liwork=liwork)
  
      info = result[-1]
      if info < 0:
          raise ValueError("Illegal value in argument %d of tgsen" % -info)
      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 "
                           "reorded. If requested, 0 is returned in DIF(*), "
                           "PL, and PR.")
  
      # for real results has a, b, alphar, alphai, beta, q, z, m, pl, pr, dif,
      # work, iwork, info
      if typ in ['f', 'd']:
          alpha = result[2] + result[3] * 1.j
          return (result[0], result[1], alpha, result[4], result[5], result[6])
      # for complex results has a, b, alpha, beta, q, z, m, pl, pr, dif, work,
      # iwork, info
      else:
          return result[0], result[1], result[2], result[3], result[4], result[5]