ztgsen.c
Go to the documentation of this file.
00001 /* ztgsen.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Table of constant values */
00017 
00018 static integer c__1 = 1;
00019 
00020 /* Subroutine */ int ztgsen_(integer *ijob, logical *wantq, logical *wantz, 
00021         logical *select, integer *n, doublecomplex *a, integer *lda, 
00022         doublecomplex *b, integer *ldb, doublecomplex *alpha, doublecomplex *
00023         beta, doublecomplex *q, integer *ldq, doublecomplex *z__, integer *
00024         ldz, integer *m, doublereal *pl, doublereal *pr, doublereal *dif, 
00025         doublecomplex *work, integer *lwork, integer *iwork, integer *liwork, 
00026         integer *info)
00027 {
00028     /* System generated locals */
00029     integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, z_dim1, 
00030             z_offset, i__1, i__2, i__3;
00031     doublecomplex z__1, z__2;
00032 
00033     /* Builtin functions */
00034     double sqrt(doublereal), z_abs(doublecomplex *);
00035     void d_cnjg(doublecomplex *, doublecomplex *);
00036 
00037     /* Local variables */
00038     integer i__, k, n1, n2, ks, mn2, ijb, kase, ierr;
00039     doublereal dsum;
00040     logical swap;
00041     doublecomplex temp1, temp2;
00042     integer isave[3];
00043     extern /* Subroutine */ int zscal_(integer *, doublecomplex *, 
00044             doublecomplex *, integer *);
00045     logical wantd;
00046     integer lwmin;
00047     logical wantp;
00048     extern /* Subroutine */ int zlacn2_(integer *, doublecomplex *, 
00049             doublecomplex *, doublereal *, integer *, integer *);
00050     logical wantd1, wantd2;
00051     extern doublereal dlamch_(char *);
00052     doublereal dscale, rdscal, safmin;
00053     extern /* Subroutine */ int xerbla_(char *, integer *);
00054     integer liwmin;
00055     extern /* Subroutine */ int zlacpy_(char *, integer *, integer *, 
00056             doublecomplex *, integer *, doublecomplex *, integer *), 
00057             ztgexc_(logical *, logical *, integer *, doublecomplex *, integer 
00058             *, doublecomplex *, integer *, doublecomplex *, integer *, 
00059             doublecomplex *, integer *, integer *, integer *, integer *), 
00060             zlassq_(integer *, doublecomplex *, integer *, doublereal *, 
00061             doublereal *);
00062     logical lquery;
00063     extern /* Subroutine */ int ztgsyl_(char *, integer *, integer *, integer 
00064             *, doublecomplex *, integer *, doublecomplex *, integer *, 
00065             doublecomplex *, integer *, doublecomplex *, integer *, 
00066             doublecomplex *, integer *, doublecomplex *, integer *, 
00067             doublereal *, doublereal *, doublecomplex *, integer *, integer *, 
00068              integer *);
00069 
00070 
00071 /*  -- LAPACK routine (version 3.2) -- */
00072 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00073 /*     January 2007 */
00074 
00075 /*     Modified to call ZLACN2 in place of ZLACON, 10 Feb 03, SJH. */
00076 
00077 /*     .. Scalar Arguments .. */
00078 /*     .. */
00079 /*     .. Array Arguments .. */
00080 /*     .. */
00081 
00082 /*  Purpose */
00083 /*  ======= */
00084 
00085 /*  ZTGSEN reorders the generalized Schur decomposition of a complex */
00086 /*  matrix pair (A, B) (in terms of an unitary equivalence trans- */
00087 /*  formation Q' * (A, B) * Z), so that a selected cluster of eigenvalues */
00088 /*  appears in the leading diagonal blocks of the pair (A,B). The leading */
00089 /*  columns of Q and Z form unitary bases of the corresponding left and */
00090 /*  right eigenspaces (deflating subspaces). (A, B) must be in */
00091 /*  generalized Schur canonical form, that is, A and B are both upper */
00092 /*  triangular. */
00093 
00094 /*  ZTGSEN also computes the generalized eigenvalues */
00095 
00096 /*           w(j)= ALPHA(j) / BETA(j) */
00097 
00098 /*  of the reordered matrix pair (A, B). */
00099 
00100 /*  Optionally, the routine computes estimates of reciprocal condition */
00101 /*  numbers for eigenvalues and eigenspaces. These are Difu[(A11,B11), */
00102 /*  (A22,B22)] and Difl[(A11,B11), (A22,B22)], i.e. the separation(s) */
00103 /*  between the matrix pairs (A11, B11) and (A22,B22) that correspond to */
00104 /*  the selected cluster and the eigenvalues outside the cluster, resp., */
00105 /*  and norms of "projections" onto left and right eigenspaces w.r.t. */
00106 /*  the selected cluster in the (1,1)-block. */
00107 
00108 
00109 /*  Arguments */
00110 /*  ========= */
00111 
00112 /*  IJOB    (input) integer */
00113 /*          Specifies whether condition numbers are required for the */
00114 /*          cluster of eigenvalues (PL and PR) or the deflating subspaces */
00115 /*          (Difu and Difl): */
00116 /*           =0: Only reorder w.r.t. SELECT. No extras. */
00117 /*           =1: Reciprocal of norms of "projections" onto left and right */
00118 /*               eigenspaces w.r.t. the selected cluster (PL and PR). */
00119 /*           =2: Upper bounds on Difu and Difl. F-norm-based estimate */
00120 /*               (DIF(1:2)). */
00121 /*           =3: Estimate of Difu and Difl. 1-norm-based estimate */
00122 /*               (DIF(1:2)). */
00123 /*               About 5 times as expensive as IJOB = 2. */
00124 /*           =4: Compute PL, PR and DIF (i.e. 0, 1 and 2 above): Economic */
00125 /*               version to get it all. */
00126 /*           =5: Compute PL, PR and DIF (i.e. 0, 1 and 3 above) */
00127 
00128 /*  WANTQ   (input) LOGICAL */
00129 /*          .TRUE. : update the left transformation matrix Q; */
00130 /*          .FALSE.: do not update Q. */
00131 
00132 /*  WANTZ   (input) LOGICAL */
00133 /*          .TRUE. : update the right transformation matrix Z; */
00134 /*          .FALSE.: do not update Z. */
00135 
00136 /*  SELECT  (input) LOGICAL array, dimension (N) */
00137 /*          SELECT specifies the eigenvalues in the selected cluster. To */
00138 /*          select an eigenvalue w(j), SELECT(j) must be set to */
00139 /*          .TRUE.. */
00140 
00141 /*  N       (input) INTEGER */
00142 /*          The order of the matrices A and B. N >= 0. */
00143 
00144 /*  A       (input/output) COMPLEX*16 array, dimension(LDA,N) */
00145 /*          On entry, the upper triangular matrix A, in generalized */
00146 /*          Schur canonical form. */
00147 /*          On exit, A is overwritten by the reordered matrix A. */
00148 
00149 /*  LDA     (input) INTEGER */
00150 /*          The leading dimension of the array A. LDA >= max(1,N). */
00151 
00152 /*  B       (input/output) COMPLEX*16 array, dimension(LDB,N) */
00153 /*          On entry, the upper triangular matrix B, in generalized */
00154 /*          Schur canonical form. */
00155 /*          On exit, B is overwritten by the reordered matrix B. */
00156 
00157 /*  LDB     (input) INTEGER */
00158 /*          The leading dimension of the array B. LDB >= max(1,N). */
00159 
00160 /*  ALPHA   (output) COMPLEX*16 array, dimension (N) */
00161 /*  BETA    (output) COMPLEX*16 array, dimension (N) */
00162 /*          The diagonal elements of A and B, respectively, */
00163 /*          when the pair (A,B) has been reduced to generalized Schur */
00164 /*          form.  ALPHA(i)/BETA(i) i=1,...,N are the generalized */
00165 /*          eigenvalues. */
00166 
00167 /*  Q       (input/output) COMPLEX*16 array, dimension (LDQ,N) */
00168 /*          On entry, if WANTQ = .TRUE., Q is an N-by-N matrix. */
00169 /*          On exit, Q has been postmultiplied by the left unitary */
00170 /*          transformation matrix which reorder (A, B); The leading M */
00171 /*          columns of Q form orthonormal bases for the specified pair of */
00172 /*          left eigenspaces (deflating subspaces). */
00173 /*          If WANTQ = .FALSE., Q is not referenced. */
00174 
00175 /*  LDQ     (input) INTEGER */
00176 /*          The leading dimension of the array Q. LDQ >= 1. */
00177 /*          If WANTQ = .TRUE., LDQ >= N. */
00178 
00179 /*  Z       (input/output) COMPLEX*16 array, dimension (LDZ,N) */
00180 /*          On entry, if WANTZ = .TRUE., Z is an N-by-N matrix. */
00181 /*          On exit, Z has been postmultiplied by the left unitary */
00182 /*          transformation matrix which reorder (A, B); The leading M */
00183 /*          columns of Z form orthonormal bases for the specified pair of */
00184 /*          left eigenspaces (deflating subspaces). */
00185 /*          If WANTZ = .FALSE., Z is not referenced. */
00186 
00187 /*  LDZ     (input) INTEGER */
00188 /*          The leading dimension of the array Z. LDZ >= 1. */
00189 /*          If WANTZ = .TRUE., LDZ >= N. */
00190 
00191 /*  M       (output) INTEGER */
00192 /*          The dimension of the specified pair of left and right */
00193 /*          eigenspaces, (deflating subspaces) 0 <= M <= N. */
00194 
00195 /*  PL      (output) DOUBLE PRECISION */
00196 /*  PR      (output) DOUBLE PRECISION */
00197 /*          If IJOB = 1, 4 or 5, PL, PR are lower bounds on the */
00198 /*          reciprocal  of the norm of "projections" onto left and right */
00199 /*          eigenspace with respect to the selected cluster. */
00200 /*          0 < PL, PR <= 1. */
00201 /*          If M = 0 or M = N, PL = PR  = 1. */
00202 /*          If IJOB = 0, 2 or 3 PL, PR are not referenced. */
00203 
00204 /*  DIF     (output) DOUBLE PRECISION array, dimension (2). */
00205 /*          If IJOB >= 2, DIF(1:2) store the estimates of Difu and Difl. */
00206 /*          If IJOB = 2 or 4, DIF(1:2) are F-norm-based upper bounds on */
00207 /*          Difu and Difl. If IJOB = 3 or 5, DIF(1:2) are 1-norm-based */
00208 /*          estimates of Difu and Difl, computed using reversed */
00209 /*          communication with ZLACN2. */
00210 /*          If M = 0 or N, DIF(1:2) = F-norm([A, B]). */
00211 /*          If IJOB = 0 or 1, DIF is not referenced. */
00212 
00213 /*  WORK    (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) */
00214 /*          IF IJOB = 0, WORK is not referenced.  Otherwise, */
00215 /*          on exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00216 
00217 /*  LWORK   (input) INTEGER */
00218 /*          The dimension of the array WORK. LWORK >=  1 */
00219 /*          If IJOB = 1, 2 or 4, LWORK >=  2*M*(N-M) */
00220 /*          If IJOB = 3 or 5, LWORK >=  4*M*(N-M) */
00221 
00222 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00223 /*          only calculates the optimal size of the WORK array, returns */
00224 /*          this value as the first entry of the WORK array, and no error */
00225 /*          message related to LWORK is issued by XERBLA. */
00226 
00227 /*  IWORK   (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */
00228 /*          IF IJOB = 0, IWORK is not referenced.  Otherwise, */
00229 /*          on exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
00230 
00231 /*  LIWORK  (input) INTEGER */
00232 /*          The dimension of the array IWORK. LIWORK >= 1. */
00233 /*          If IJOB = 1, 2 or 4, LIWORK >=  N+2; */
00234 /*          If IJOB = 3 or 5, LIWORK >= MAX(N+2, 2*M*(N-M)); */
00235 
00236 /*          If LIWORK = -1, then a workspace query is assumed; the */
00237 /*          routine only calculates the optimal size of the IWORK array, */
00238 /*          returns this value as the first entry of the IWORK array, and */
00239 /*          no error message related to LIWORK is issued by XERBLA. */
00240 
00241 /*  INFO    (output) INTEGER */
00242 /*            =0: Successful exit. */
00243 /*            <0: If INFO = -i, the i-th argument had an illegal value. */
00244 /*            =1: Reordering of (A, B) failed because the transformed */
00245 /*                matrix pair (A, B) would be too far from generalized */
00246 /*                Schur form; the problem is very ill-conditioned. */
00247 /*                (A, B) may have been partially reordered. */
00248 /*                If requested, 0 is returned in DIF(*), PL and PR. */
00249 
00250 
00251 /*  Further Details */
00252 /*  =============== */
00253 
00254 /*  ZTGSEN first collects the selected eigenvalues by computing unitary */
00255 /*  U and W that move them to the top left corner of (A, B). In other */
00256 /*  words, the selected eigenvalues are the eigenvalues of (A11, B11) in */
00257 
00258 /*                U'*(A, B)*W = (A11 A12) (B11 B12) n1 */
00259 /*                              ( 0  A22),( 0  B22) n2 */
00260 /*                                n1  n2    n1  n2 */
00261 
00262 /*  where N = n1+n2 and U' means the conjugate transpose of U. The first */
00263 /*  n1 columns of U and W span the specified pair of left and right */
00264 /*  eigenspaces (deflating subspaces) of (A, B). */
00265 
00266 /*  If (A, B) has been obtained from the generalized real Schur */
00267 /*  decomposition of a matrix pair (C, D) = Q*(A, B)*Z', then the */
00268 /*  reordered generalized Schur form of (C, D) is given by */
00269 
00270 /*           (C, D) = (Q*U)*(U'*(A, B)*W)*(Z*W)', */
00271 
00272 /*  and the first n1 columns of Q*U and Z*W span the corresponding */
00273 /*  deflating subspaces of (C, D) (Q and Z store Q*U and Z*W, resp.). */
00274 
00275 /*  Note that if the selected eigenvalue is sufficiently ill-conditioned, */
00276 /*  then its value may differ significantly from its value before */
00277 /*  reordering. */
00278 
00279 /*  The reciprocal condition numbers of the left and right eigenspaces */
00280 /*  spanned by the first n1 columns of U and W (or Q*U and Z*W) may */
00281 /*  be returned in DIF(1:2), corresponding to Difu and Difl, resp. */
00282 
00283 /*  The Difu and Difl are defined as: */
00284 
00285 /*       Difu[(A11, B11), (A22, B22)] = sigma-min( Zu ) */
00286 /*  and */
00287 /*       Difl[(A11, B11), (A22, B22)] = Difu[(A22, B22), (A11, B11)], */
00288 
00289 /*  where sigma-min(Zu) is the smallest singular value of the */
00290 /*  (2*n1*n2)-by-(2*n1*n2) matrix */
00291 
00292 /*       Zu = [ kron(In2, A11)  -kron(A22', In1) ] */
00293 /*            [ kron(In2, B11)  -kron(B22', In1) ]. */
00294 
00295 /*  Here, Inx is the identity matrix of size nx and A22' is the */
00296 /*  transpose of A22. kron(X, Y) is the Kronecker product between */
00297 /*  the matrices X and Y. */
00298 
00299 /*  When DIF(2) is small, small changes in (A, B) can cause large changes */
00300 /*  in the deflating subspace. An approximate (asymptotic) bound on the */
00301 /*  maximum angular error in the computed deflating subspaces is */
00302 
00303 /*       EPS * norm((A, B)) / DIF(2), */
00304 
00305 /*  where EPS is the machine precision. */
00306 
00307 /*  The reciprocal norm of the projectors on the left and right */
00308 /*  eigenspaces associated with (A11, B11) may be returned in PL and PR. */
00309 /*  They are computed as follows. First we compute L and R so that */
00310 /*  P*(A, B)*Q is block diagonal, where */
00311 
00312 /*       P = ( I -L ) n1           Q = ( I R ) n1 */
00313 /*           ( 0  I ) n2    and        ( 0 I ) n2 */
00314 /*             n1 n2                    n1 n2 */
00315 
00316 /*  and (L, R) is the solution to the generalized Sylvester equation */
00317 
00318 /*       A11*R - L*A22 = -A12 */
00319 /*       B11*R - L*B22 = -B12 */
00320 
00321 /*  Then PL = (F-norm(L)**2+1)**(-1/2) and PR = (F-norm(R)**2+1)**(-1/2). */
00322 /*  An approximate (asymptotic) bound on the average absolute error of */
00323 /*  the selected eigenvalues is */
00324 
00325 /*       EPS * norm((A, B)) / PL. */
00326 
00327 /*  There are also global error bounds which valid for perturbations up */
00328 /*  to a certain restriction:  A lower bound (x) on the smallest */
00329 /*  F-norm(E,F) for which an eigenvalue of (A11, B11) may move and */
00330 /*  coalesce with an eigenvalue of (A22, B22) under perturbation (E,F), */
00331 /*  (i.e. (A + E, B + F), is */
00332 
00333 /*   x = min(Difu,Difl)/((1/(PL*PL)+1/(PR*PR))**(1/2)+2*max(1/PL,1/PR)). */
00334 
00335 /*  An approximate bound on x can be computed from DIF(1:2), PL and PR. */
00336 
00337 /*  If y = ( F-norm(E,F) / x) <= 1, the angles between the perturbed */
00338 /*  (L', R') and unperturbed (L, R) left and right deflating subspaces */
00339 /*  associated with the selected cluster in the (1,1)-blocks can be */
00340 /*  bounded as */
00341 
00342 /*   max-angle(L, L') <= arctan( y * PL / (1 - y * (1 - PL * PL)**(1/2)) */
00343 /*   max-angle(R, R') <= arctan( y * PR / (1 - y * (1 - PR * PR)**(1/2)) */
00344 
00345 /*  See LAPACK User's Guide section 4.11 or the following references */
00346 /*  for more information. */
00347 
00348 /*  Note that if the default method for computing the Frobenius-norm- */
00349 /*  based estimate DIF is not wanted (see ZLATDF), then the parameter */
00350 /*  IDIFJB (see below) should be changed from 3 to 4 (routine ZLATDF */
00351 /*  (IJOB = 2 will be used)). See ZTGSYL for more details. */
00352 
00353 /*  Based on contributions by */
00354 /*     Bo Kagstrom and Peter Poromaa, Department of Computing Science, */
00355 /*     Umea University, S-901 87 Umea, Sweden. */
00356 
00357 /*  References */
00358 /*  ========== */
00359 
00360 /*  [1] B. Kagstrom; A Direct Method for Reordering Eigenvalues in the */
00361 /*      Generalized Real Schur Form of a Regular Matrix Pair (A, B), in */
00362 /*      M.S. Moonen et al (eds), Linear Algebra for Large Scale and */
00363 /*      Real-Time Applications, Kluwer Academic Publ. 1993, pp 195-218. */
00364 
00365 /*  [2] B. Kagstrom and P. Poromaa; Computing Eigenspaces with Specified */
00366 /*      Eigenvalues of a Regular Matrix Pair (A, B) and Condition */
00367 /*      Estimation: Theory, Algorithms and Software, Report */
00368 /*      UMINF - 94.04, Department of Computing Science, Umea University, */
00369 /*      S-901 87 Umea, Sweden, 1994. Also as LAPACK Working Note 87. */
00370 /*      To appear in Numerical Algorithms, 1996. */
00371 
00372 /*  [3] B. Kagstrom and P. Poromaa, LAPACK-Style Algorithms and Software */
00373 /*      for Solving the Generalized Sylvester Equation and Estimating the */
00374 /*      Separation between Regular Matrix Pairs, Report UMINF - 93.23, */
00375 /*      Department of Computing Science, Umea University, S-901 87 Umea, */
00376 /*      Sweden, December 1993, Revised April 1994, Also as LAPACK working */
00377 /*      Note 75. To appear in ACM Trans. on Math. Software, Vol 22, No 1, */
00378 /*      1996. */
00379 
00380 /*  ===================================================================== */
00381 
00382 /*     .. Parameters .. */
00383 /*     .. */
00384 /*     .. Local Scalars .. */
00385 /*     .. */
00386 /*     .. Local Arrays .. */
00387 /*     .. */
00388 /*     .. External Subroutines .. */
00389 /*     .. */
00390 /*     .. Intrinsic Functions .. */
00391 /*     .. */
00392 /*     .. External Functions .. */
00393 /*     .. */
00394 /*     .. Executable Statements .. */
00395 
00396 /*     Decode and test the input parameters */
00397 
00398     /* Parameter adjustments */
00399     --select;
00400     a_dim1 = *lda;
00401     a_offset = 1 + a_dim1;
00402     a -= a_offset;
00403     b_dim1 = *ldb;
00404     b_offset = 1 + b_dim1;
00405     b -= b_offset;
00406     --alpha;
00407     --beta;
00408     q_dim1 = *ldq;
00409     q_offset = 1 + q_dim1;
00410     q -= q_offset;
00411     z_dim1 = *ldz;
00412     z_offset = 1 + z_dim1;
00413     z__ -= z_offset;
00414     --dif;
00415     --work;
00416     --iwork;
00417 
00418     /* Function Body */
00419     *info = 0;
00420     lquery = *lwork == -1 || *liwork == -1;
00421 
00422     if (*ijob < 0 || *ijob > 5) {
00423         *info = -1;
00424     } else if (*n < 0) {
00425         *info = -5;
00426     } else if (*lda < max(1,*n)) {
00427         *info = -7;
00428     } else if (*ldb < max(1,*n)) {
00429         *info = -9;
00430     } else if (*ldq < 1 || *wantq && *ldq < *n) {
00431         *info = -13;
00432     } else if (*ldz < 1 || *wantz && *ldz < *n) {
00433         *info = -15;
00434     }
00435 
00436     if (*info != 0) {
00437         i__1 = -(*info);
00438         xerbla_("ZTGSEN", &i__1);
00439         return 0;
00440     }
00441 
00442     ierr = 0;
00443 
00444     wantp = *ijob == 1 || *ijob >= 4;
00445     wantd1 = *ijob == 2 || *ijob == 4;
00446     wantd2 = *ijob == 3 || *ijob == 5;
00447     wantd = wantd1 || wantd2;
00448 
00449 /*     Set M to the dimension of the specified pair of deflating */
00450 /*     subspaces. */
00451 
00452     *m = 0;
00453     i__1 = *n;
00454     for (k = 1; k <= i__1; ++k) {
00455         i__2 = k;
00456         i__3 = k + k * a_dim1;
00457         alpha[i__2].r = a[i__3].r, alpha[i__2].i = a[i__3].i;
00458         i__2 = k;
00459         i__3 = k + k * b_dim1;
00460         beta[i__2].r = b[i__3].r, beta[i__2].i = b[i__3].i;
00461         if (k < *n) {
00462             if (select[k]) {
00463                 ++(*m);
00464             }
00465         } else {
00466             if (select[*n]) {
00467                 ++(*m);
00468             }
00469         }
00470 /* L10: */
00471     }
00472 
00473     if (*ijob == 1 || *ijob == 2 || *ijob == 4) {
00474 /* Computing MAX */
00475         i__1 = 1, i__2 = (*m << 1) * (*n - *m);
00476         lwmin = max(i__1,i__2);
00477 /* Computing MAX */
00478         i__1 = 1, i__2 = *n + 2;
00479         liwmin = max(i__1,i__2);
00480     } else if (*ijob == 3 || *ijob == 5) {
00481 /* Computing MAX */
00482         i__1 = 1, i__2 = (*m << 2) * (*n - *m);
00483         lwmin = max(i__1,i__2);
00484 /* Computing MAX */
00485         i__1 = 1, i__2 = (*m << 1) * (*n - *m), i__1 = max(i__1,i__2), i__2 = 
00486                 *n + 2;
00487         liwmin = max(i__1,i__2);
00488     } else {
00489         lwmin = 1;
00490         liwmin = 1;
00491     }
00492 
00493     work[1].r = (doublereal) lwmin, work[1].i = 0.;
00494     iwork[1] = liwmin;
00495 
00496     if (*lwork < lwmin && ! lquery) {
00497         *info = -21;
00498     } else if (*liwork < liwmin && ! lquery) {
00499         *info = -23;
00500     }
00501 
00502     if (*info != 0) {
00503         i__1 = -(*info);
00504         xerbla_("ZTGSEN", &i__1);
00505         return 0;
00506     } else if (lquery) {
00507         return 0;
00508     }
00509 
00510 /*     Quick return if possible. */
00511 
00512     if (*m == *n || *m == 0) {
00513         if (wantp) {
00514             *pl = 1.;
00515             *pr = 1.;
00516         }
00517         if (wantd) {
00518             dscale = 0.;
00519             dsum = 1.;
00520             i__1 = *n;
00521             for (i__ = 1; i__ <= i__1; ++i__) {
00522                 zlassq_(n, &a[i__ * a_dim1 + 1], &c__1, &dscale, &dsum);
00523                 zlassq_(n, &b[i__ * b_dim1 + 1], &c__1, &dscale, &dsum);
00524 /* L20: */
00525             }
00526             dif[1] = dscale * sqrt(dsum);
00527             dif[2] = dif[1];
00528         }
00529         goto L70;
00530     }
00531 
00532 /*     Get machine constant */
00533 
00534     safmin = dlamch_("S");
00535 
00536 /*     Collect the selected blocks at the top-left corner of (A, B). */
00537 
00538     ks = 0;
00539     i__1 = *n;
00540     for (k = 1; k <= i__1; ++k) {
00541         swap = select[k];
00542         if (swap) {
00543             ++ks;
00544 
00545 /*           Swap the K-th block to position KS. Compute unitary Q */
00546 /*           and Z that will swap adjacent diagonal blocks in (A, B). */
00547 
00548             if (k != ks) {
00549                 ztgexc_(wantq, wantz, n, &a[a_offset], lda, &b[b_offset], ldb, 
00550                          &q[q_offset], ldq, &z__[z_offset], ldz, &k, &ks, &
00551                         ierr);
00552             }
00553 
00554             if (ierr > 0) {
00555 
00556 /*              Swap is rejected: exit. */
00557 
00558                 *info = 1;
00559                 if (wantp) {
00560                     *pl = 0.;
00561                     *pr = 0.;
00562                 }
00563                 if (wantd) {
00564                     dif[1] = 0.;
00565                     dif[2] = 0.;
00566                 }
00567                 goto L70;
00568             }
00569         }
00570 /* L30: */
00571     }
00572     if (wantp) {
00573 
00574 /*        Solve generalized Sylvester equation for R and L: */
00575 /*                   A11 * R - L * A22 = A12 */
00576 /*                   B11 * R - L * B22 = B12 */
00577 
00578         n1 = *m;
00579         n2 = *n - *m;
00580         i__ = n1 + 1;
00581         zlacpy_("Full", &n1, &n2, &a[i__ * a_dim1 + 1], lda, &work[1], &n1);
00582         zlacpy_("Full", &n1, &n2, &b[i__ * b_dim1 + 1], ldb, &work[n1 * n2 + 
00583                 1], &n1);
00584         ijb = 0;
00585         i__1 = *lwork - (n1 << 1) * n2;
00586         ztgsyl_("N", &ijb, &n1, &n2, &a[a_offset], lda, &a[i__ + i__ * a_dim1]
00587 , lda, &work[1], &n1, &b[b_offset], ldb, &b[i__ + i__ * 
00588                 b_dim1], ldb, &work[n1 * n2 + 1], &n1, &dscale, &dif[1], &
00589                 work[(n1 * n2 << 1) + 1], &i__1, &iwork[1], &ierr);
00590 
00591 /*        Estimate the reciprocal of norms of "projections" onto */
00592 /*        left and right eigenspaces */
00593 
00594         rdscal = 0.;
00595         dsum = 1.;
00596         i__1 = n1 * n2;
00597         zlassq_(&i__1, &work[1], &c__1, &rdscal, &dsum);
00598         *pl = rdscal * sqrt(dsum);
00599         if (*pl == 0.) {
00600             *pl = 1.;
00601         } else {
00602             *pl = dscale / (sqrt(dscale * dscale / *pl + *pl) * sqrt(*pl));
00603         }
00604         rdscal = 0.;
00605         dsum = 1.;
00606         i__1 = n1 * n2;
00607         zlassq_(&i__1, &work[n1 * n2 + 1], &c__1, &rdscal, &dsum);
00608         *pr = rdscal * sqrt(dsum);
00609         if (*pr == 0.) {
00610             *pr = 1.;
00611         } else {
00612             *pr = dscale / (sqrt(dscale * dscale / *pr + *pr) * sqrt(*pr));
00613         }
00614     }
00615     if (wantd) {
00616 
00617 /*        Compute estimates Difu and Difl. */
00618 
00619         if (wantd1) {
00620             n1 = *m;
00621             n2 = *n - *m;
00622             i__ = n1 + 1;
00623             ijb = 3;
00624 
00625 /*           Frobenius norm-based Difu estimate. */
00626 
00627             i__1 = *lwork - (n1 << 1) * n2;
00628             ztgsyl_("N", &ijb, &n1, &n2, &a[a_offset], lda, &a[i__ + i__ * 
00629                     a_dim1], lda, &work[1], &n1, &b[b_offset], ldb, &b[i__ + 
00630                     i__ * b_dim1], ldb, &work[n1 * n2 + 1], &n1, &dscale, &
00631                     dif[1], &work[(n1 * n2 << 1) + 1], &i__1, &iwork[1], &
00632                     ierr);
00633 
00634 /*           Frobenius norm-based Difl estimate. */
00635 
00636             i__1 = *lwork - (n1 << 1) * n2;
00637             ztgsyl_("N", &ijb, &n2, &n1, &a[i__ + i__ * a_dim1], lda, &a[
00638                     a_offset], lda, &work[1], &n2, &b[i__ + i__ * b_dim1], 
00639                     ldb, &b[b_offset], ldb, &work[n1 * n2 + 1], &n2, &dscale, 
00640                     &dif[2], &work[(n1 * n2 << 1) + 1], &i__1, &iwork[1], &
00641                     ierr);
00642         } else {
00643 
00644 /*           Compute 1-norm-based estimates of Difu and Difl using */
00645 /*           reversed communication with ZLACN2. In each step a */
00646 /*           generalized Sylvester equation or a transposed variant */
00647 /*           is solved. */
00648 
00649             kase = 0;
00650             n1 = *m;
00651             n2 = *n - *m;
00652             i__ = n1 + 1;
00653             ijb = 0;
00654             mn2 = (n1 << 1) * n2;
00655 
00656 /*           1-norm-based estimate of Difu. */
00657 
00658 L40:
00659             zlacn2_(&mn2, &work[mn2 + 1], &work[1], &dif[1], &kase, isave);
00660             if (kase != 0) {
00661                 if (kase == 1) {
00662 
00663 /*                 Solve generalized Sylvester equation */
00664 
00665                     i__1 = *lwork - (n1 << 1) * n2;
00666                     ztgsyl_("N", &ijb, &n1, &n2, &a[a_offset], lda, &a[i__ + 
00667                             i__ * a_dim1], lda, &work[1], &n1, &b[b_offset], 
00668                             ldb, &b[i__ + i__ * b_dim1], ldb, &work[n1 * n2 + 
00669                             1], &n1, &dscale, &dif[1], &work[(n1 * n2 << 1) + 
00670                             1], &i__1, &iwork[1], &ierr);
00671                 } else {
00672 
00673 /*                 Solve the transposed variant. */
00674 
00675                     i__1 = *lwork - (n1 << 1) * n2;
00676                     ztgsyl_("C", &ijb, &n1, &n2, &a[a_offset], lda, &a[i__ + 
00677                             i__ * a_dim1], lda, &work[1], &n1, &b[b_offset], 
00678                             ldb, &b[i__ + i__ * b_dim1], ldb, &work[n1 * n2 + 
00679                             1], &n1, &dscale, &dif[1], &work[(n1 * n2 << 1) + 
00680                             1], &i__1, &iwork[1], &ierr);
00681                 }
00682                 goto L40;
00683             }
00684             dif[1] = dscale / dif[1];
00685 
00686 /*           1-norm-based estimate of Difl. */
00687 
00688 L50:
00689             zlacn2_(&mn2, &work[mn2 + 1], &work[1], &dif[2], &kase, isave);
00690             if (kase != 0) {
00691                 if (kase == 1) {
00692 
00693 /*                 Solve generalized Sylvester equation */
00694 
00695                     i__1 = *lwork - (n1 << 1) * n2;
00696                     ztgsyl_("N", &ijb, &n2, &n1, &a[i__ + i__ * a_dim1], lda, 
00697                             &a[a_offset], lda, &work[1], &n2, &b[i__ + i__ * 
00698                             b_dim1], ldb, &b[b_offset], ldb, &work[n1 * n2 + 
00699                             1], &n2, &dscale, &dif[2], &work[(n1 * n2 << 1) + 
00700                             1], &i__1, &iwork[1], &ierr);
00701                 } else {
00702 
00703 /*                 Solve the transposed variant. */
00704 
00705                     i__1 = *lwork - (n1 << 1) * n2;
00706                     ztgsyl_("C", &ijb, &n2, &n1, &a[i__ + i__ * a_dim1], lda, 
00707                             &a[a_offset], lda, &work[1], &n2, &b[b_offset], 
00708                             ldb, &b[i__ + i__ * b_dim1], ldb, &work[n1 * n2 + 
00709                             1], &n2, &dscale, &dif[2], &work[(n1 * n2 << 1) + 
00710                             1], &i__1, &iwork[1], &ierr);
00711                 }
00712                 goto L50;
00713             }
00714             dif[2] = dscale / dif[2];
00715         }
00716     }
00717 
00718 /*     If B(K,K) is complex, make it real and positive (normalization */
00719 /*     of the generalized Schur form) and Store the generalized */
00720 /*     eigenvalues of reordered pair (A, B) */
00721 
00722     i__1 = *n;
00723     for (k = 1; k <= i__1; ++k) {
00724         dscale = z_abs(&b[k + k * b_dim1]);
00725         if (dscale > safmin) {
00726             i__2 = k + k * b_dim1;
00727             z__2.r = b[i__2].r / dscale, z__2.i = b[i__2].i / dscale;
00728             d_cnjg(&z__1, &z__2);
00729             temp1.r = z__1.r, temp1.i = z__1.i;
00730             i__2 = k + k * b_dim1;
00731             z__1.r = b[i__2].r / dscale, z__1.i = b[i__2].i / dscale;
00732             temp2.r = z__1.r, temp2.i = z__1.i;
00733             i__2 = k + k * b_dim1;
00734             b[i__2].r = dscale, b[i__2].i = 0.;
00735             i__2 = *n - k;
00736             zscal_(&i__2, &temp1, &b[k + (k + 1) * b_dim1], ldb);
00737             i__2 = *n - k + 1;
00738             zscal_(&i__2, &temp1, &a[k + k * a_dim1], lda);
00739             if (*wantq) {
00740                 zscal_(n, &temp2, &q[k * q_dim1 + 1], &c__1);
00741             }
00742         } else {
00743             i__2 = k + k * b_dim1;
00744             b[i__2].r = 0., b[i__2].i = 0.;
00745         }
00746 
00747         i__2 = k;
00748         i__3 = k + k * a_dim1;
00749         alpha[i__2].r = a[i__3].r, alpha[i__2].i = a[i__3].i;
00750         i__2 = k;
00751         i__3 = k + k * b_dim1;
00752         beta[i__2].r = b[i__3].r, beta[i__2].i = b[i__3].i;
00753 
00754 /* L60: */
00755     }
00756 
00757 L70:
00758 
00759     work[1].r = (doublereal) lwmin, work[1].i = 0.;
00760     iwork[1] = liwmin;
00761 
00762     return 0;
00763 
00764 /*     End of ZTGSEN */
00765 
00766 } /* ztgsen_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:43