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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:34