sggevx.c
Go to the documentation of this file.
00001 /* sggevx.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 static integer c__0 = 0;
00020 static real c_b57 = 0.f;
00021 static real c_b58 = 1.f;
00022 
00023 /* Subroutine */ int sggevx_(char *balanc, char *jobvl, char *jobvr, char *
00024         sense, integer *n, real *a, integer *lda, real *b, integer *ldb, real 
00025         *alphar, real *alphai, real *beta, real *vl, integer *ldvl, real *vr, 
00026         integer *ldvr, integer *ilo, integer *ihi, real *lscale, real *rscale, 
00027          real *abnrm, real *bbnrm, real *rconde, real *rcondv, real *work, 
00028         integer *lwork, integer *iwork, logical *bwork, integer *info)
00029 {
00030     /* System generated locals */
00031     integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1, 
00032             vr_offset, i__1, i__2;
00033     real r__1, r__2, r__3, r__4;
00034 
00035     /* Builtin functions */
00036     double sqrt(doublereal);
00037 
00038     /* Local variables */
00039     integer i__, j, m, jc, in, mm, jr;
00040     real eps;
00041     logical ilv, pair;
00042     real anrm, bnrm;
00043     integer ierr, itau;
00044     real temp;
00045     logical ilvl, ilvr;
00046     integer iwrk, iwrk1;
00047     extern logical lsame_(char *, char *);
00048     integer icols;
00049     logical noscl;
00050     integer irows;
00051     extern /* Subroutine */ int slabad_(real *, real *), sggbak_(char *, char 
00052             *, integer *, integer *, integer *, real *, real *, integer *, 
00053             real *, integer *, integer *), sggbal_(char *, 
00054             integer *, real *, integer *, real *, integer *, integer *, 
00055             integer *, real *, real *, real *, integer *);
00056     logical ilascl, ilbscl;
00057     extern doublereal slamch_(char *);
00058     extern /* Subroutine */ int xerbla_(char *, integer *), sgghrd_(
00059             char *, char *, integer *, integer *, integer *, real *, integer *
00060 , real *, integer *, real *, integer *, real *, integer *, 
00061             integer *);
00062     logical ldumma[1];
00063     char chtemp[1];
00064     real bignum;
00065     extern /* Subroutine */ int slascl_(char *, integer *, integer *, real *, 
00066             real *, integer *, integer *, real *, integer *, integer *);
00067     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00068             integer *, integer *);
00069     extern doublereal slange_(char *, integer *, integer *, real *, integer *, 
00070              real *);
00071     integer ijobvl;
00072     extern /* Subroutine */ int sgeqrf_(integer *, integer *, real *, integer 
00073             *, real *, real *, integer *, integer *);
00074     integer ijobvr;
00075     extern /* Subroutine */ int slacpy_(char *, integer *, integer *, real *, 
00076             integer *, real *, integer *);
00077     logical wantsb;
00078     extern /* Subroutine */ int slaset_(char *, integer *, integer *, real *, 
00079             real *, real *, integer *);
00080     real anrmto;
00081     logical wantse;
00082     real bnrmto;
00083     extern /* Subroutine */ int shgeqz_(char *, char *, char *, integer *, 
00084             integer *, integer *, real *, integer *, real *, integer *, real *
00085 , real *, real *, real *, integer *, real *, integer *, real *, 
00086             integer *, integer *), stgevc_(char *, 
00087             char *, logical *, integer *, real *, integer *, real *, integer *
00088 , real *, integer *, real *, integer *, integer *, integer *, 
00089             real *, integer *), stgsna_(char *, char *, 
00090             logical *, integer *, real *, integer *, real *, integer *, real *
00091 , integer *, real *, integer *, real *, real *, integer *, 
00092             integer *, real *, integer *, integer *, integer *);
00093     integer minwrk, maxwrk;
00094     logical wantsn;
00095     real smlnum;
00096     extern /* Subroutine */ int sorgqr_(integer *, integer *, integer *, real 
00097             *, integer *, real *, real *, integer *, integer *);
00098     logical lquery, wantsv;
00099     extern /* Subroutine */ int sormqr_(char *, char *, integer *, integer *, 
00100             integer *, real *, integer *, real *, real *, integer *, real *, 
00101             integer *, integer *);
00102 
00103 
00104 /*  -- LAPACK driver routine (version 3.2) -- */
00105 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00106 /*     November 2006 */
00107 
00108 /*     .. Scalar Arguments .. */
00109 /*     .. */
00110 /*     .. Array Arguments .. */
00111 /*     .. */
00112 
00113 /*  Purpose */
00114 /*  ======= */
00115 
00116 /*  SGGEVX computes for a pair of N-by-N real nonsymmetric matrices (A,B) */
00117 /*  the generalized eigenvalues, and optionally, the left and/or right */
00118 /*  generalized eigenvectors. */
00119 
00120 /*  Optionally also, it computes a balancing transformation to improve */
00121 /*  the conditioning of the eigenvalues and eigenvectors (ILO, IHI, */
00122 /*  LSCALE, RSCALE, ABNRM, and BBNRM), reciprocal condition numbers for */
00123 /*  the eigenvalues (RCONDE), and reciprocal condition numbers for the */
00124 /*  right eigenvectors (RCONDV). */
00125 
00126 /*  A generalized eigenvalue for a pair of matrices (A,B) is a scalar */
00127 /*  lambda or a ratio alpha/beta = lambda, such that A - lambda*B is */
00128 /*  singular. It is usually represented as the pair (alpha,beta), as */
00129 /*  there is a reasonable interpretation for beta=0, and even for both */
00130 /*  being zero. */
00131 
00132 /*  The right eigenvector v(j) corresponding to the eigenvalue lambda(j) */
00133 /*  of (A,B) satisfies */
00134 
00135 /*                   A * v(j) = lambda(j) * B * v(j) . */
00136 
00137 /*  The left eigenvector u(j) corresponding to the eigenvalue lambda(j) */
00138 /*  of (A,B) satisfies */
00139 
00140 /*                   u(j)**H * A  = lambda(j) * u(j)**H * B. */
00141 
00142 /*  where u(j)**H is the conjugate-transpose of u(j). */
00143 
00144 
00145 /*  Arguments */
00146 /*  ========= */
00147 
00148 /*  BALANC  (input) CHARACTER*1 */
00149 /*          Specifies the balance option to be performed. */
00150 /*          = 'N':  do not diagonally scale or permute; */
00151 /*          = 'P':  permute only; */
00152 /*          = 'S':  scale only; */
00153 /*          = 'B':  both permute and scale. */
00154 /*          Computed reciprocal condition numbers will be for the */
00155 /*          matrices after permuting and/or balancing. Permuting does */
00156 /*          not change condition numbers (in exact arithmetic), but */
00157 /*          balancing does. */
00158 
00159 /*  JOBVL   (input) CHARACTER*1 */
00160 /*          = 'N':  do not compute the left generalized eigenvectors; */
00161 /*          = 'V':  compute the left generalized eigenvectors. */
00162 
00163 /*  JOBVR   (input) CHARACTER*1 */
00164 /*          = 'N':  do not compute the right generalized eigenvectors; */
00165 /*          = 'V':  compute the right generalized eigenvectors. */
00166 
00167 /*  SENSE   (input) CHARACTER*1 */
00168 /*          Determines which reciprocal condition numbers are computed. */
00169 /*          = 'N': none are computed; */
00170 /*          = 'E': computed for eigenvalues only; */
00171 /*          = 'V': computed for eigenvectors only; */
00172 /*          = 'B': computed for eigenvalues and eigenvectors. */
00173 
00174 /*  N       (input) INTEGER */
00175 /*          The order of the matrices A, B, VL, and VR.  N >= 0. */
00176 
00177 /*  A       (input/output) REAL array, dimension (LDA, N) */
00178 /*          On entry, the matrix A in the pair (A,B). */
00179 /*          On exit, A has been overwritten. If JOBVL='V' or JOBVR='V' */
00180 /*          or both, then A contains the first part of the real Schur */
00181 /*          form of the "balanced" versions of the input A and B. */
00182 
00183 /*  LDA     (input) INTEGER */
00184 /*          The leading dimension of A.  LDA >= max(1,N). */
00185 
00186 /*  B       (input/output) REAL array, dimension (LDB, N) */
00187 /*          On entry, the matrix B in the pair (A,B). */
00188 /*          On exit, B has been overwritten. If JOBVL='V' or JOBVR='V' */
00189 /*          or both, then B contains the second part of the real Schur */
00190 /*          form of the "balanced" versions of the input A and B. */
00191 
00192 /*  LDB     (input) INTEGER */
00193 /*          The leading dimension of B.  LDB >= max(1,N). */
00194 
00195 /*  ALPHAR  (output) REAL array, dimension (N) */
00196 /*  ALPHAI  (output) REAL array, dimension (N) */
00197 /*  BETA    (output) REAL array, dimension (N) */
00198 /*          On exit, (ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N, will */
00199 /*          be the generalized eigenvalues.  If ALPHAI(j) is zero, then */
00200 /*          the j-th eigenvalue is real; if positive, then the j-th and */
00201 /*          (j+1)-st eigenvalues are a complex conjugate pair, with */
00202 /*          ALPHAI(j+1) negative. */
00203 
00204 /*          Note: the quotients ALPHAR(j)/BETA(j) and ALPHAI(j)/BETA(j) */
00205 /*          may easily over- or underflow, and BETA(j) may even be zero. */
00206 /*          Thus, the user should avoid naively computing the ratio */
00207 /*          ALPHA/BETA. However, ALPHAR and ALPHAI will be always less */
00208 /*          than and usually comparable with norm(A) in magnitude, and */
00209 /*          BETA always less than and usually comparable with norm(B). */
00210 
00211 /*  VL      (output) REAL array, dimension (LDVL,N) */
00212 /*          If JOBVL = 'V', the left eigenvectors u(j) are stored one */
00213 /*          after another in the columns of VL, in the same order as */
00214 /*          their eigenvalues. If the j-th eigenvalue is real, then */
00215 /*          u(j) = VL(:,j), the j-th column of VL. If the j-th and */
00216 /*          (j+1)-th eigenvalues form a complex conjugate pair, then */
00217 /*          u(j) = VL(:,j)+i*VL(:,j+1) and u(j+1) = VL(:,j)-i*VL(:,j+1). */
00218 /*          Each eigenvector will be scaled so the largest component have */
00219 /*          abs(real part) + abs(imag. part) = 1. */
00220 /*          Not referenced if JOBVL = 'N'. */
00221 
00222 /*  LDVL    (input) INTEGER */
00223 /*          The leading dimension of the matrix VL. LDVL >= 1, and */
00224 /*          if JOBVL = 'V', LDVL >= N. */
00225 
00226 /*  VR      (output) REAL array, dimension (LDVR,N) */
00227 /*          If JOBVR = 'V', the right eigenvectors v(j) are stored one */
00228 /*          after another in the columns of VR, in the same order as */
00229 /*          their eigenvalues. If the j-th eigenvalue is real, then */
00230 /*          v(j) = VR(:,j), the j-th column of VR. If the j-th and */
00231 /*          (j+1)-th eigenvalues form a complex conjugate pair, then */
00232 /*          v(j) = VR(:,j)+i*VR(:,j+1) and v(j+1) = VR(:,j)-i*VR(:,j+1). */
00233 /*          Each eigenvector will be scaled so the largest component have */
00234 /*          abs(real part) + abs(imag. part) = 1. */
00235 /*          Not referenced if JOBVR = 'N'. */
00236 
00237 /*  LDVR    (input) INTEGER */
00238 /*          The leading dimension of the matrix VR. LDVR >= 1, and */
00239 /*          if JOBVR = 'V', LDVR >= N. */
00240 
00241 /*  ILO     (output) INTEGER */
00242 /*  IHI     (output) INTEGER */
00243 /*          ILO and IHI are integer values such that on exit */
00244 /*          A(i,j) = 0 and B(i,j) = 0 if i > j and */
00245 /*          j = 1,...,ILO-1 or i = IHI+1,...,N. */
00246 /*          If BALANC = 'N' or 'S', ILO = 1 and IHI = N. */
00247 
00248 /*  LSCALE  (output) REAL array, dimension (N) */
00249 /*          Details of the permutations and scaling factors applied */
00250 /*          to the left side of A and B.  If PL(j) is the index of the */
00251 /*          row interchanged with row j, and DL(j) is the scaling */
00252 /*          factor applied to row j, then */
00253 /*            LSCALE(j) = PL(j)  for j = 1,...,ILO-1 */
00254 /*                      = DL(j)  for j = ILO,...,IHI */
00255 /*                      = PL(j)  for j = IHI+1,...,N. */
00256 /*          The order in which the interchanges are made is N to IHI+1, */
00257 /*          then 1 to ILO-1. */
00258 
00259 /*  RSCALE  (output) REAL array, dimension (N) */
00260 /*          Details of the permutations and scaling factors applied */
00261 /*          to the right side of A and B.  If PR(j) is the index of the */
00262 /*          column interchanged with column j, and DR(j) is the scaling */
00263 /*          factor applied to column j, then */
00264 /*            RSCALE(j) = PR(j)  for j = 1,...,ILO-1 */
00265 /*                      = DR(j)  for j = ILO,...,IHI */
00266 /*                      = PR(j)  for j = IHI+1,...,N */
00267 /*          The order in which the interchanges are made is N to IHI+1, */
00268 /*          then 1 to ILO-1. */
00269 
00270 /*  ABNRM   (output) REAL */
00271 /*          The one-norm of the balanced matrix A. */
00272 
00273 /*  BBNRM   (output) REAL */
00274 /*          The one-norm of the balanced matrix B. */
00275 
00276 /*  RCONDE  (output) REAL array, dimension (N) */
00277 /*          If SENSE = 'E' or 'B', the reciprocal condition numbers of */
00278 /*          the eigenvalues, stored in consecutive elements of the array. */
00279 /*          For a complex conjugate pair of eigenvalues two consecutive */
00280 /*          elements of RCONDE are set to the same value. Thus RCONDE(j), */
00281 /*          RCONDV(j), and the j-th columns of VL and VR all correspond */
00282 /*          to the j-th eigenpair. */
00283 /*          If SENSE = 'N' or 'V', RCONDE is not referenced. */
00284 
00285 /*  RCONDV  (output) REAL array, dimension (N) */
00286 /*          If SENSE = 'V' or 'B', the estimated reciprocal condition */
00287 /*          numbers of the eigenvectors, stored in consecutive elements */
00288 /*          of the array. For a complex eigenvector two consecutive */
00289 /*          elements of RCONDV are set to the same value. If the */
00290 /*          eigenvalues cannot be reordered to compute RCONDV(j), */
00291 /*          RCONDV(j) is set to 0; this can only occur when the true */
00292 /*          value would be very small anyway. */
00293 /*          If SENSE = 'N' or 'E', RCONDV is not referenced. */
00294 
00295 /*  WORK    (workspace/output) REAL array, dimension (MAX(1,LWORK)) */
00296 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00297 
00298 /*  LWORK   (input) INTEGER */
00299 /*          The dimension of the array WORK. LWORK >= max(1,2*N). */
00300 /*          If BALANC = 'S' or 'B', or JOBVL = 'V', or JOBVR = 'V', */
00301 /*          LWORK >= max(1,6*N). */
00302 /*          If SENSE = 'E', LWORK >= max(1,10*N). */
00303 /*          If SENSE = 'V' or 'B', LWORK >= 2*N*N+8*N+16. */
00304 
00305 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00306 /*          only calculates the optimal size of the WORK array, returns */
00307 /*          this value as the first entry of the WORK array, and no error */
00308 /*          message related to LWORK is issued by XERBLA. */
00309 
00310 /*  IWORK   (workspace) INTEGER array, dimension (N+6) */
00311 /*          If SENSE = 'E', IWORK is not referenced. */
00312 
00313 /*  BWORK   (workspace) LOGICAL array, dimension (N) */
00314 /*          If SENSE = 'N', BWORK is not referenced. */
00315 
00316 /*  INFO    (output) INTEGER */
00317 /*          = 0:  successful exit */
00318 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00319 /*          = 1,...,N: */
00320 /*                The QZ iteration failed.  No eigenvectors have been */
00321 /*                calculated, but ALPHAR(j), ALPHAI(j), and BETA(j) */
00322 /*                should be correct for j=INFO+1,...,N. */
00323 /*          > N:  =N+1: other than QZ iteration failed in SHGEQZ. */
00324 /*                =N+2: error return from STGEVC. */
00325 
00326 /*  Further Details */
00327 /*  =============== */
00328 
00329 /*  Balancing a matrix pair (A,B) includes, first, permuting rows and */
00330 /*  columns to isolate eigenvalues, second, applying diagonal similarity */
00331 /*  transformation to the rows and columns to make the rows and columns */
00332 /*  as close in norm as possible. The computed reciprocal condition */
00333 /*  numbers correspond to the balanced matrix. Permuting rows and columns */
00334 /*  will not change the condition numbers (in exact arithmetic) but */
00335 /*  diagonal scaling will.  For further explanation of balancing, see */
00336 /*  section 4.11.1.2 of LAPACK Users' Guide. */
00337 
00338 /*  An approximate error bound on the chordal distance between the i-th */
00339 /*  computed generalized eigenvalue w and the corresponding exact */
00340 /*  eigenvalue lambda is */
00341 
00342 /*       chord(w, lambda) <= EPS * norm(ABNRM, BBNRM) / RCONDE(I) */
00343 
00344 /*  An approximate error bound for the angle between the i-th computed */
00345 /*  eigenvector VL(i) or VR(i) is given by */
00346 
00347 /*       EPS * norm(ABNRM, BBNRM) / DIF(i). */
00348 
00349 /*  For further explanation of the reciprocal condition numbers RCONDE */
00350 /*  and RCONDV, see section 4.11 of LAPACK User's Guide. */
00351 
00352 /*  ===================================================================== */
00353 
00354 /*     .. Parameters .. */
00355 /*     .. */
00356 /*     .. Local Scalars .. */
00357 /*     .. */
00358 /*     .. Local Arrays .. */
00359 /*     .. */
00360 /*     .. External Subroutines .. */
00361 /*     .. */
00362 /*     .. External Functions .. */
00363 /*     .. */
00364 /*     .. Intrinsic Functions .. */
00365 /*     .. */
00366 /*     .. Executable Statements .. */
00367 
00368 /*     Decode the input arguments */
00369 
00370     /* Parameter adjustments */
00371     a_dim1 = *lda;
00372     a_offset = 1 + a_dim1;
00373     a -= a_offset;
00374     b_dim1 = *ldb;
00375     b_offset = 1 + b_dim1;
00376     b -= b_offset;
00377     --alphar;
00378     --alphai;
00379     --beta;
00380     vl_dim1 = *ldvl;
00381     vl_offset = 1 + vl_dim1;
00382     vl -= vl_offset;
00383     vr_dim1 = *ldvr;
00384     vr_offset = 1 + vr_dim1;
00385     vr -= vr_offset;
00386     --lscale;
00387     --rscale;
00388     --rconde;
00389     --rcondv;
00390     --work;
00391     --iwork;
00392     --bwork;
00393 
00394     /* Function Body */
00395     if (lsame_(jobvl, "N")) {
00396         ijobvl = 1;
00397         ilvl = FALSE_;
00398     } else if (lsame_(jobvl, "V")) {
00399         ijobvl = 2;
00400         ilvl = TRUE_;
00401     } else {
00402         ijobvl = -1;
00403         ilvl = FALSE_;
00404     }
00405 
00406     if (lsame_(jobvr, "N")) {
00407         ijobvr = 1;
00408         ilvr = FALSE_;
00409     } else if (lsame_(jobvr, "V")) {
00410         ijobvr = 2;
00411         ilvr = TRUE_;
00412     } else {
00413         ijobvr = -1;
00414         ilvr = FALSE_;
00415     }
00416     ilv = ilvl || ilvr;
00417 
00418     noscl = lsame_(balanc, "N") || lsame_(balanc, "P");
00419     wantsn = lsame_(sense, "N");
00420     wantse = lsame_(sense, "E");
00421     wantsv = lsame_(sense, "V");
00422     wantsb = lsame_(sense, "B");
00423 
00424 /*     Test the input arguments */
00425 
00426     *info = 0;
00427     lquery = *lwork == -1;
00428     if (! (noscl || lsame_(balanc, "S") || lsame_(
00429             balanc, "B"))) {
00430         *info = -1;
00431     } else if (ijobvl <= 0) {
00432         *info = -2;
00433     } else if (ijobvr <= 0) {
00434         *info = -3;
00435     } else if (! (wantsn || wantse || wantsb || wantsv)) {
00436         *info = -4;
00437     } else if (*n < 0) {
00438         *info = -5;
00439     } else if (*lda < max(1,*n)) {
00440         *info = -7;
00441     } else if (*ldb < max(1,*n)) {
00442         *info = -9;
00443     } else if (*ldvl < 1 || ilvl && *ldvl < *n) {
00444         *info = -14;
00445     } else if (*ldvr < 1 || ilvr && *ldvr < *n) {
00446         *info = -16;
00447     }
00448 
00449 /*     Compute workspace */
00450 /*      (Note: Comments in the code beginning "Workspace:" describe the */
00451 /*       minimal amount of workspace needed at that point in the code, */
00452 /*       as well as the preferred amount for good performance. */
00453 /*       NB refers to the optimal block size for the immediately */
00454 /*       following subroutine, as returned by ILAENV. The workspace is */
00455 /*       computed assuming ILO = 1 and IHI = N, the worst case.) */
00456 
00457     if (*info == 0) {
00458         if (*n == 0) {
00459             minwrk = 1;
00460             maxwrk = 1;
00461         } else {
00462             if (noscl && ! ilv) {
00463                 minwrk = *n << 1;
00464             } else {
00465                 minwrk = *n * 6;
00466             }
00467             if (wantse) {
00468                 minwrk = *n * 10;
00469             } else if (wantsv || wantsb) {
00470                 minwrk = (*n << 1) * (*n + 4) + 16;
00471             }
00472             maxwrk = minwrk;
00473 /* Computing MAX */
00474             i__1 = maxwrk, i__2 = *n + *n * ilaenv_(&c__1, "SGEQRF", " ", n, &
00475                     c__1, n, &c__0);
00476             maxwrk = max(i__1,i__2);
00477 /* Computing MAX */
00478             i__1 = maxwrk, i__2 = *n + *n * ilaenv_(&c__1, "SORMQR", " ", n, &
00479                     c__1, n, &c__0);
00480             maxwrk = max(i__1,i__2);
00481             if (ilvl) {
00482 /* Computing MAX */
00483                 i__1 = maxwrk, i__2 = *n + *n * ilaenv_(&c__1, "SORGQR", 
00484                         " ", n, &c__1, n, &c__0);
00485                 maxwrk = max(i__1,i__2);
00486             }
00487         }
00488         work[1] = (real) maxwrk;
00489 
00490         if (*lwork < minwrk && ! lquery) {
00491             *info = -26;
00492         }
00493     }
00494 
00495     if (*info != 0) {
00496         i__1 = -(*info);
00497         xerbla_("SGGEVX", &i__1);
00498         return 0;
00499     } else if (lquery) {
00500         return 0;
00501     }
00502 
00503 /*     Quick return if possible */
00504 
00505     if (*n == 0) {
00506         return 0;
00507     }
00508 
00509 
00510 /*     Get machine constants */
00511 
00512     eps = slamch_("P");
00513     smlnum = slamch_("S");
00514     bignum = 1.f / smlnum;
00515     slabad_(&smlnum, &bignum);
00516     smlnum = sqrt(smlnum) / eps;
00517     bignum = 1.f / smlnum;
00518 
00519 /*     Scale A if max element outside range [SMLNUM,BIGNUM] */
00520 
00521     anrm = slange_("M", n, n, &a[a_offset], lda, &work[1]);
00522     ilascl = FALSE_;
00523     if (anrm > 0.f && anrm < smlnum) {
00524         anrmto = smlnum;
00525         ilascl = TRUE_;
00526     } else if (anrm > bignum) {
00527         anrmto = bignum;
00528         ilascl = TRUE_;
00529     }
00530     if (ilascl) {
00531         slascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, &
00532                 ierr);
00533     }
00534 
00535 /*     Scale B if max element outside range [SMLNUM,BIGNUM] */
00536 
00537     bnrm = slange_("M", n, n, &b[b_offset], ldb, &work[1]);
00538     ilbscl = FALSE_;
00539     if (bnrm > 0.f && bnrm < smlnum) {
00540         bnrmto = smlnum;
00541         ilbscl = TRUE_;
00542     } else if (bnrm > bignum) {
00543         bnrmto = bignum;
00544         ilbscl = TRUE_;
00545     }
00546     if (ilbscl) {
00547         slascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
00548                 ierr);
00549     }
00550 
00551 /*     Permute and/or balance the matrix pair (A,B) */
00552 /*     (Workspace: need 6*N if BALANC = 'S' or 'B', 1 otherwise) */
00553 
00554     sggbal_(balanc, n, &a[a_offset], lda, &b[b_offset], ldb, ilo, ihi, &
00555             lscale[1], &rscale[1], &work[1], &ierr);
00556 
00557 /*     Compute ABNRM and BBNRM */
00558 
00559     *abnrm = slange_("1", n, n, &a[a_offset], lda, &work[1]);
00560     if (ilascl) {
00561         work[1] = *abnrm;
00562         slascl_("G", &c__0, &c__0, &anrmto, &anrm, &c__1, &c__1, &work[1], &
00563                 c__1, &ierr);
00564         *abnrm = work[1];
00565     }
00566 
00567     *bbnrm = slange_("1", n, n, &b[b_offset], ldb, &work[1]);
00568     if (ilbscl) {
00569         work[1] = *bbnrm;
00570         slascl_("G", &c__0, &c__0, &bnrmto, &bnrm, &c__1, &c__1, &work[1], &
00571                 c__1, &ierr);
00572         *bbnrm = work[1];
00573     }
00574 
00575 /*     Reduce B to triangular form (QR decomposition of B) */
00576 /*     (Workspace: need N, prefer N*NB ) */
00577 
00578     irows = *ihi + 1 - *ilo;
00579     if (ilv || ! wantsn) {
00580         icols = *n + 1 - *ilo;
00581     } else {
00582         icols = irows;
00583     }
00584     itau = 1;
00585     iwrk = itau + irows;
00586     i__1 = *lwork + 1 - iwrk;
00587     sgeqrf_(&irows, &icols, &b[*ilo + *ilo * b_dim1], ldb, &work[itau], &work[
00588             iwrk], &i__1, &ierr);
00589 
00590 /*     Apply the orthogonal transformation to A */
00591 /*     (Workspace: need N, prefer N*NB) */
00592 
00593     i__1 = *lwork + 1 - iwrk;
00594     sormqr_("L", "T", &irows, &icols, &irows, &b[*ilo + *ilo * b_dim1], ldb, &
00595             work[itau], &a[*ilo + *ilo * a_dim1], lda, &work[iwrk], &i__1, &
00596             ierr);
00597 
00598 /*     Initialize VL and/or VR */
00599 /*     (Workspace: need N, prefer N*NB) */
00600 
00601     if (ilvl) {
00602         slaset_("Full", n, n, &c_b57, &c_b58, &vl[vl_offset], ldvl)
00603                 ;
00604         if (irows > 1) {
00605             i__1 = irows - 1;
00606             i__2 = irows - 1;
00607             slacpy_("L", &i__1, &i__2, &b[*ilo + 1 + *ilo * b_dim1], ldb, &vl[
00608                     *ilo + 1 + *ilo * vl_dim1], ldvl);
00609         }
00610         i__1 = *lwork + 1 - iwrk;
00611         sorgqr_(&irows, &irows, &irows, &vl[*ilo + *ilo * vl_dim1], ldvl, &
00612                 work[itau], &work[iwrk], &i__1, &ierr);
00613     }
00614 
00615     if (ilvr) {
00616         slaset_("Full", n, n, &c_b57, &c_b58, &vr[vr_offset], ldvr)
00617                 ;
00618     }
00619 
00620 /*     Reduce to generalized Hessenberg form */
00621 /*     (Workspace: none needed) */
00622 
00623     if (ilv || ! wantsn) {
00624 
00625 /*        Eigenvectors requested -- work on whole matrix. */
00626 
00627         sgghrd_(jobvl, jobvr, n, ilo, ihi, &a[a_offset], lda, &b[b_offset], 
00628                 ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, &ierr);
00629     } else {
00630         sgghrd_("N", "N", &irows, &c__1, &irows, &a[*ilo + *ilo * a_dim1], 
00631                 lda, &b[*ilo + *ilo * b_dim1], ldb, &vl[vl_offset], ldvl, &vr[
00632                 vr_offset], ldvr, &ierr);
00633     }
00634 
00635 /*     Perform QZ algorithm (Compute eigenvalues, and optionally, the */
00636 /*     Schur forms and Schur vectors) */
00637 /*     (Workspace: need N) */
00638 
00639     if (ilv || ! wantsn) {
00640         *(unsigned char *)chtemp = 'S';
00641     } else {
00642         *(unsigned char *)chtemp = 'E';
00643     }
00644 
00645     shgeqz_(chtemp, jobvl, jobvr, n, ilo, ihi, &a[a_offset], lda, &b[b_offset]
00646 , ldb, &alphar[1], &alphai[1], &beta[1], &vl[vl_offset], ldvl, &
00647             vr[vr_offset], ldvr, &work[1], lwork, &ierr);
00648     if (ierr != 0) {
00649         if (ierr > 0 && ierr <= *n) {
00650             *info = ierr;
00651         } else if (ierr > *n && ierr <= *n << 1) {
00652             *info = ierr - *n;
00653         } else {
00654             *info = *n + 1;
00655         }
00656         goto L130;
00657     }
00658 
00659 /*     Compute Eigenvectors and estimate condition numbers if desired */
00660 /*     (Workspace: STGEVC: need 6*N */
00661 /*                 STGSNA: need 2*N*(N+2)+16 if SENSE = 'V' or 'B', */
00662 /*                         need N otherwise ) */
00663 
00664     if (ilv || ! wantsn) {
00665         if (ilv) {
00666             if (ilvl) {
00667                 if (ilvr) {
00668                     *(unsigned char *)chtemp = 'B';
00669                 } else {
00670                     *(unsigned char *)chtemp = 'L';
00671                 }
00672             } else {
00673                 *(unsigned char *)chtemp = 'R';
00674             }
00675 
00676             stgevc_(chtemp, "B", ldumma, n, &a[a_offset], lda, &b[b_offset], 
00677                     ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, n, &in, &
00678                     work[1], &ierr);
00679             if (ierr != 0) {
00680                 *info = *n + 2;
00681                 goto L130;
00682             }
00683         }
00684 
00685         if (! wantsn) {
00686 
00687 /*           compute eigenvectors (STGEVC) and estimate condition */
00688 /*           numbers (STGSNA). Note that the definition of the condition */
00689 /*           number is not invariant under transformation (u,v) to */
00690 /*           (Q*u, Z*v), where (u,v) are eigenvectors of the generalized */
00691 /*           Schur form (S,T), Q and Z are orthogonal matrices. In order */
00692 /*           to avoid using extra 2*N*N workspace, we have to recalculate */
00693 /*           eigenvectors and estimate one condition numbers at a time. */
00694 
00695             pair = FALSE_;
00696             i__1 = *n;
00697             for (i__ = 1; i__ <= i__1; ++i__) {
00698 
00699                 if (pair) {
00700                     pair = FALSE_;
00701                     goto L20;
00702                 }
00703                 mm = 1;
00704                 if (i__ < *n) {
00705                     if (a[i__ + 1 + i__ * a_dim1] != 0.f) {
00706                         pair = TRUE_;
00707                         mm = 2;
00708                     }
00709                 }
00710 
00711                 i__2 = *n;
00712                 for (j = 1; j <= i__2; ++j) {
00713                     bwork[j] = FALSE_;
00714 /* L10: */
00715                 }
00716                 if (mm == 1) {
00717                     bwork[i__] = TRUE_;
00718                 } else if (mm == 2) {
00719                     bwork[i__] = TRUE_;
00720                     bwork[i__ + 1] = TRUE_;
00721                 }
00722 
00723                 iwrk = mm * *n + 1;
00724                 iwrk1 = iwrk + mm * *n;
00725 
00726 /*              Compute a pair of left and right eigenvectors. */
00727 /*              (compute workspace: need up to 4*N + 6*N) */
00728 
00729                 if (wantse || wantsb) {
00730                     stgevc_("B", "S", &bwork[1], n, &a[a_offset], lda, &b[
00731                             b_offset], ldb, &work[1], n, &work[iwrk], n, &mm, 
00732                             &m, &work[iwrk1], &ierr);
00733                     if (ierr != 0) {
00734                         *info = *n + 2;
00735                         goto L130;
00736                     }
00737                 }
00738 
00739                 i__2 = *lwork - iwrk1 + 1;
00740                 stgsna_(sense, "S", &bwork[1], n, &a[a_offset], lda, &b[
00741                         b_offset], ldb, &work[1], n, &work[iwrk], n, &rconde[
00742                         i__], &rcondv[i__], &mm, &m, &work[iwrk1], &i__2, &
00743                         iwork[1], &ierr);
00744 
00745 L20:
00746                 ;
00747             }
00748         }
00749     }
00750 
00751 /*     Undo balancing on VL and VR and normalization */
00752 /*     (Workspace: none needed) */
00753 
00754     if (ilvl) {
00755         sggbak_(balanc, "L", n, ilo, ihi, &lscale[1], &rscale[1], n, &vl[
00756                 vl_offset], ldvl, &ierr);
00757 
00758         i__1 = *n;
00759         for (jc = 1; jc <= i__1; ++jc) {
00760             if (alphai[jc] < 0.f) {
00761                 goto L70;
00762             }
00763             temp = 0.f;
00764             if (alphai[jc] == 0.f) {
00765                 i__2 = *n;
00766                 for (jr = 1; jr <= i__2; ++jr) {
00767 /* Computing MAX */
00768                     r__2 = temp, r__3 = (r__1 = vl[jr + jc * vl_dim1], dabs(
00769                             r__1));
00770                     temp = dmax(r__2,r__3);
00771 /* L30: */
00772                 }
00773             } else {
00774                 i__2 = *n;
00775                 for (jr = 1; jr <= i__2; ++jr) {
00776 /* Computing MAX */
00777                     r__3 = temp, r__4 = (r__1 = vl[jr + jc * vl_dim1], dabs(
00778                             r__1)) + (r__2 = vl[jr + (jc + 1) * vl_dim1], 
00779                             dabs(r__2));
00780                     temp = dmax(r__3,r__4);
00781 /* L40: */
00782                 }
00783             }
00784             if (temp < smlnum) {
00785                 goto L70;
00786             }
00787             temp = 1.f / temp;
00788             if (alphai[jc] == 0.f) {
00789                 i__2 = *n;
00790                 for (jr = 1; jr <= i__2; ++jr) {
00791                     vl[jr + jc * vl_dim1] *= temp;
00792 /* L50: */
00793                 }
00794             } else {
00795                 i__2 = *n;
00796                 for (jr = 1; jr <= i__2; ++jr) {
00797                     vl[jr + jc * vl_dim1] *= temp;
00798                     vl[jr + (jc + 1) * vl_dim1] *= temp;
00799 /* L60: */
00800                 }
00801             }
00802 L70:
00803             ;
00804         }
00805     }
00806     if (ilvr) {
00807         sggbak_(balanc, "R", n, ilo, ihi, &lscale[1], &rscale[1], n, &vr[
00808                 vr_offset], ldvr, &ierr);
00809         i__1 = *n;
00810         for (jc = 1; jc <= i__1; ++jc) {
00811             if (alphai[jc] < 0.f) {
00812                 goto L120;
00813             }
00814             temp = 0.f;
00815             if (alphai[jc] == 0.f) {
00816                 i__2 = *n;
00817                 for (jr = 1; jr <= i__2; ++jr) {
00818 /* Computing MAX */
00819                     r__2 = temp, r__3 = (r__1 = vr[jr + jc * vr_dim1], dabs(
00820                             r__1));
00821                     temp = dmax(r__2,r__3);
00822 /* L80: */
00823                 }
00824             } else {
00825                 i__2 = *n;
00826                 for (jr = 1; jr <= i__2; ++jr) {
00827 /* Computing MAX */
00828                     r__3 = temp, r__4 = (r__1 = vr[jr + jc * vr_dim1], dabs(
00829                             r__1)) + (r__2 = vr[jr + (jc + 1) * vr_dim1], 
00830                             dabs(r__2));
00831                     temp = dmax(r__3,r__4);
00832 /* L90: */
00833                 }
00834             }
00835             if (temp < smlnum) {
00836                 goto L120;
00837             }
00838             temp = 1.f / temp;
00839             if (alphai[jc] == 0.f) {
00840                 i__2 = *n;
00841                 for (jr = 1; jr <= i__2; ++jr) {
00842                     vr[jr + jc * vr_dim1] *= temp;
00843 /* L100: */
00844                 }
00845             } else {
00846                 i__2 = *n;
00847                 for (jr = 1; jr <= i__2; ++jr) {
00848                     vr[jr + jc * vr_dim1] *= temp;
00849                     vr[jr + (jc + 1) * vr_dim1] *= temp;
00850 /* L110: */
00851                 }
00852             }
00853 L120:
00854             ;
00855         }
00856     }
00857 
00858 /*     Undo scaling if necessary */
00859 
00860     if (ilascl) {
00861         slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphar[1], n, &
00862                 ierr);
00863         slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphai[1], n, &
00864                 ierr);
00865     }
00866 
00867     if (ilbscl) {
00868         slascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
00869                 ierr);
00870     }
00871 
00872 L130:
00873     work[1] = (real) maxwrk;
00874 
00875     return 0;
00876 
00877 /*     End of SGGEVX */
00878 
00879 } /* sggevx_ */


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