shseqr.c
Go to the documentation of this file.
00001 /* shseqr.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 real c_b11 = 0.f;
00019 static real c_b12 = 1.f;
00020 static integer c__12 = 12;
00021 static integer c__2 = 2;
00022 static integer c__49 = 49;
00023 
00024 /* Subroutine */ int shseqr_(char *job, char *compz, integer *n, integer *ilo, 
00025          integer *ihi, real *h__, integer *ldh, real *wr, real *wi, real *z__, 
00026          integer *ldz, real *work, integer *lwork, integer *info)
00027 {
00028     /* System generated locals */
00029     address a__1[2];
00030     integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2[2], i__3;
00031     real r__1;
00032     char ch__1[2];
00033 
00034     /* Builtin functions */
00035     /* Subroutine */ int s_cat(char *, char **, integer *, integer *, ftnlen);
00036 
00037     /* Local variables */
00038     integer i__;
00039     real hl[2401]       /* was [49][49] */;
00040     integer kbot, nmin;
00041     extern logical lsame_(char *, char *);
00042     logical initz;
00043     real workl[49];
00044     logical wantt, wantz;
00045     extern /* Subroutine */ int slaqr0_(logical *, logical *, integer *, 
00046             integer *, integer *, real *, integer *, real *, real *, integer *
00047 , integer *, real *, integer *, real *, integer *, integer *), 
00048             xerbla_(char *, integer *);
00049     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00050             integer *, integer *);
00051     extern /* Subroutine */ int slahqr_(logical *, logical *, integer *, 
00052             integer *, integer *, real *, integer *, real *, real *, integer *
00053 , integer *, real *, integer *, integer *), slacpy_(char *, 
00054             integer *, integer *, real *, integer *, real *, integer *), slaset_(char *, integer *, integer *, real *, real *, 
00055             real *, integer *);
00056     logical lquery;
00057 
00058 
00059 /*  -- LAPACK driver routine (version 3.2) -- */
00060 /*     Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd.. */
00061 /*     November 2006 */
00062 
00063 /*     .. Scalar Arguments .. */
00064 /*     .. */
00065 /*     .. Array Arguments .. */
00066 /*     .. */
00067 /*     Purpose */
00068 /*     ======= */
00069 
00070 /*     SHSEQR computes the eigenvalues of a Hessenberg matrix H */
00071 /*     and, optionally, the matrices T and Z from the Schur decomposition */
00072 /*     H = Z T Z**T, where T is an upper quasi-triangular matrix (the */
00073 /*     Schur form), and Z is the orthogonal matrix of Schur vectors. */
00074 
00075 /*     Optionally Z may be postmultiplied into an input orthogonal */
00076 /*     matrix Q so that this routine can give the Schur factorization */
00077 /*     of a matrix A which has been reduced to the Hessenberg form H */
00078 /*     by the orthogonal matrix Q:  A = Q*H*Q**T = (QZ)*T*(QZ)**T. */
00079 
00080 /*     Arguments */
00081 /*     ========= */
00082 
00083 /*     JOB   (input) CHARACTER*1 */
00084 /*           = 'E':  compute eigenvalues only; */
00085 /*           = 'S':  compute eigenvalues and the Schur form T. */
00086 
00087 /*     COMPZ (input) CHARACTER*1 */
00088 /*           = 'N':  no Schur vectors are computed; */
00089 /*           = 'I':  Z is initialized to the unit matrix and the matrix Z */
00090 /*                   of Schur vectors of H is returned; */
00091 /*           = 'V':  Z must contain an orthogonal matrix Q on entry, and */
00092 /*                   the product Q*Z is returned. */
00093 
00094 /*     N     (input) INTEGER */
00095 /*           The order of the matrix H.  N .GE. 0. */
00096 
00097 /*     ILO   (input) INTEGER */
00098 /*     IHI   (input) INTEGER */
00099 /*           It is assumed that H is already upper triangular in rows */
00100 /*           and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally */
00101 /*           set by a previous call to SGEBAL, and then passed to SGEHRD */
00102 /*           when the matrix output by SGEBAL is reduced to Hessenberg */
00103 /*           form. Otherwise ILO and IHI should be set to 1 and N */
00104 /*           respectively.  If N.GT.0, then 1.LE.ILO.LE.IHI.LE.N. */
00105 /*           If N = 0, then ILO = 1 and IHI = 0. */
00106 
00107 /*     H     (input/output) REAL array, dimension (LDH,N) */
00108 /*           On entry, the upper Hessenberg matrix H. */
00109 /*           On exit, if INFO = 0 and JOB = 'S', then H contains the */
00110 /*           upper quasi-triangular matrix T from the Schur decomposition */
00111 /*           (the Schur form); 2-by-2 diagonal blocks (corresponding to */
00112 /*           complex conjugate pairs of eigenvalues) are returned in */
00113 /*           standard form, with H(i,i) = H(i+1,i+1) and */
00114 /*           H(i+1,i)*H(i,i+1).LT.0. If INFO = 0 and JOB = 'E', the */
00115 /*           contents of H are unspecified on exit.  (The output value of */
00116 /*           H when INFO.GT.0 is given under the description of INFO */
00117 /*           below.) */
00118 
00119 /*           Unlike earlier versions of SHSEQR, this subroutine may */
00120 /*           explicitly H(i,j) = 0 for i.GT.j and j = 1, 2, ... ILO-1 */
00121 /*           or j = IHI+1, IHI+2, ... N. */
00122 
00123 /*     LDH   (input) INTEGER */
00124 /*           The leading dimension of the array H. LDH .GE. max(1,N). */
00125 
00126 /*     WR    (output) REAL array, dimension (N) */
00127 /*     WI    (output) REAL array, dimension (N) */
00128 /*           The real and imaginary parts, respectively, of the computed */
00129 /*           eigenvalues. If two eigenvalues are computed as a complex */
00130 /*           conjugate pair, they are stored in consecutive elements of */
00131 /*           WR and WI, say the i-th and (i+1)th, with WI(i) .GT. 0 and */
00132 /*           WI(i+1) .LT. 0. If JOB = 'S', the eigenvalues are stored in */
00133 /*           the same order as on the diagonal of the Schur form returned */
00134 /*           in H, with WR(i) = H(i,i) and, if H(i:i+1,i:i+1) is a 2-by-2 */
00135 /*           diagonal block, WI(i) = sqrt(-H(i+1,i)*H(i,i+1)) and */
00136 /*           WI(i+1) = -WI(i). */
00137 
00138 /*     Z     (input/output) REAL array, dimension (LDZ,N) */
00139 /*           If COMPZ = 'N', Z is not referenced. */
00140 /*           If COMPZ = 'I', on entry Z need not be set and on exit, */
00141 /*           if INFO = 0, Z contains the orthogonal matrix Z of the Schur */
00142 /*           vectors of H.  If COMPZ = 'V', on entry Z must contain an */
00143 /*           N-by-N matrix Q, which is assumed to be equal to the unit */
00144 /*           matrix except for the submatrix Z(ILO:IHI,ILO:IHI). On exit, */
00145 /*           if INFO = 0, Z contains Q*Z. */
00146 /*           Normally Q is the orthogonal matrix generated by SORGHR */
00147 /*           after the call to SGEHRD which formed the Hessenberg matrix */
00148 /*           H. (The output value of Z when INFO.GT.0 is given under */
00149 /*           the description of INFO below.) */
00150 
00151 /*     LDZ   (input) INTEGER */
00152 /*           The leading dimension of the array Z.  if COMPZ = 'I' or */
00153 /*           COMPZ = 'V', then LDZ.GE.MAX(1,N).  Otherwize, LDZ.GE.1. */
00154 
00155 /*     WORK  (workspace/output) REAL array, dimension (LWORK) */
00156 /*           On exit, if INFO = 0, WORK(1) returns an estimate of */
00157 /*           the optimal value for LWORK. */
00158 
00159 /*     LWORK (input) INTEGER */
00160 /*           The dimension of the array WORK.  LWORK .GE. max(1,N) */
00161 /*           is sufficient and delivers very good and sometimes */
00162 /*           optimal performance.  However, LWORK as large as 11*N */
00163 /*           may be required for optimal performance.  A workspace */
00164 /*           query is recommended to determine the optimal workspace */
00165 /*           size. */
00166 
00167 /*           If LWORK = -1, then SHSEQR does a workspace query. */
00168 /*           In this case, SHSEQR checks the input parameters and */
00169 /*           estimates the optimal workspace size for the given */
00170 /*           values of N, ILO and IHI.  The estimate is returned */
00171 /*           in WORK(1).  No error message related to LWORK is */
00172 /*           issued by XERBLA.  Neither H nor Z are accessed. */
00173 
00174 
00175 /*     INFO  (output) INTEGER */
00176 /*             =  0:  successful exit */
00177 /*           .LT. 0:  if INFO = -i, the i-th argument had an illegal */
00178 /*                    value */
00179 /*           .GT. 0:  if INFO = i, SHSEQR failed to compute all of */
00180 /*                the eigenvalues.  Elements 1:ilo-1 and i+1:n of WR */
00181 /*                and WI contain those eigenvalues which have been */
00182 /*                successfully computed.  (Failures are rare.) */
00183 
00184 /*                If INFO .GT. 0 and JOB = 'E', then on exit, the */
00185 /*                remaining unconverged eigenvalues are the eigen- */
00186 /*                values of the upper Hessenberg matrix rows and */
00187 /*                columns ILO through INFO of the final, output */
00188 /*                value of H. */
00189 
00190 /*                If INFO .GT. 0 and JOB   = 'S', then on exit */
00191 
00192 /*           (*)  (initial value of H)*U  = U*(final value of H) */
00193 
00194 /*                where U is an orthogonal matrix.  The final */
00195 /*                value of H is upper Hessenberg and quasi-triangular */
00196 /*                in rows and columns INFO+1 through IHI. */
00197 
00198 /*                If INFO .GT. 0 and COMPZ = 'V', then on exit */
00199 
00200 /*                  (final value of Z)  =  (initial value of Z)*U */
00201 
00202 /*                where U is the orthogonal matrix in (*) (regard- */
00203 /*                less of the value of JOB.) */
00204 
00205 /*                If INFO .GT. 0 and COMPZ = 'I', then on exit */
00206 /*                      (final value of Z)  = U */
00207 /*                where U is the orthogonal matrix in (*) (regard- */
00208 /*                less of the value of JOB.) */
00209 
00210 /*                If INFO .GT. 0 and COMPZ = 'N', then Z is not */
00211 /*                accessed. */
00212 
00213 /*     ================================================================ */
00214 /*             Default values supplied by */
00215 /*             ILAENV(ISPEC,'SHSEQR',JOB(:1)//COMPZ(:1),N,ILO,IHI,LWORK). */
00216 /*             It is suggested that these defaults be adjusted in order */
00217 /*             to attain best performance in each particular */
00218 /*             computational environment. */
00219 
00220 /*            ISPEC=12: The SLAHQR vs SLAQR0 crossover point. */
00221 /*                      Default: 75. (Must be at least 11.) */
00222 
00223 /*            ISPEC=13: Recommended deflation window size. */
00224 /*                      This depends on ILO, IHI and NS.  NS is the */
00225 /*                      number of simultaneous shifts returned */
00226 /*                      by ILAENV(ISPEC=15).  (See ISPEC=15 below.) */
00227 /*                      The default for (IHI-ILO+1).LE.500 is NS. */
00228 /*                      The default for (IHI-ILO+1).GT.500 is 3*NS/2. */
00229 
00230 /*            ISPEC=14: Nibble crossover point. (See IPARMQ for */
00231 /*                      details.)  Default: 14% of deflation window */
00232 /*                      size. */
00233 
00234 /*            ISPEC=15: Number of simultaneous shifts in a multishift */
00235 /*                      QR iteration. */
00236 
00237 /*                      If IHI-ILO+1 is ... */
00238 
00239 /*                      greater than      ...but less    ... the */
00240 /*                      or equal to ...      than        default is */
00241 
00242 /*                           1               30          NS =   2(+) */
00243 /*                          30               60          NS =   4(+) */
00244 /*                          60              150          NS =  10(+) */
00245 /*                         150              590          NS =  ** */
00246 /*                         590             3000          NS =  64 */
00247 /*                        3000             6000          NS = 128 */
00248 /*                        6000             infinity      NS = 256 */
00249 
00250 /*                  (+)  By default some or all matrices of this order */
00251 /*                       are passed to the implicit double shift routine */
00252 /*                       SLAHQR and this parameter is ignored.  See */
00253 /*                       ISPEC=12 above and comments in IPARMQ for */
00254 /*                       details. */
00255 
00256 /*                 (**)  The asterisks (**) indicate an ad-hoc */
00257 /*                       function of N increasing from 10 to 64. */
00258 
00259 /*            ISPEC=16: Select structured matrix multiply. */
00260 /*                      If the number of simultaneous shifts (specified */
00261 /*                      by ISPEC=15) is less than 14, then the default */
00262 /*                      for ISPEC=16 is 0.  Otherwise the default for */
00263 /*                      ISPEC=16 is 2. */
00264 
00265 /*     ================================================================ */
00266 /*     Based on contributions by */
00267 /*        Karen Braman and Ralph Byers, Department of Mathematics, */
00268 /*        University of Kansas, USA */
00269 
00270 /*     ================================================================ */
00271 /*     References: */
00272 /*       K. Braman, R. Byers and R. Mathias, The Multi-Shift QR */
00273 /*       Algorithm Part I: Maintaining Well Focused Shifts, and Level 3 */
00274 /*       Performance, SIAM Journal of Matrix Analysis, volume 23, pages */
00275 /*       929--947, 2002. */
00276 
00277 /*       K. Braman, R. Byers and R. Mathias, The Multi-Shift QR */
00278 /*       Algorithm Part II: Aggressive Early Deflation, SIAM Journal */
00279 /*       of Matrix Analysis, volume 23, pages 948--973, 2002. */
00280 
00281 /*     ================================================================ */
00282 /*     .. Parameters .. */
00283 
00284 /*     ==== Matrices of order NTINY or smaller must be processed by */
00285 /*     .    SLAHQR because of insufficient subdiagonal scratch space. */
00286 /*     .    (This is a hard limit.) ==== */
00287 
00288 /*     ==== NL allocates some local workspace to help small matrices */
00289 /*     .    through a rare SLAHQR failure.  NL .GT. NTINY = 11 is */
00290 /*     .    required and NL .LE. NMIN = ILAENV(ISPEC=12,...) is recom- */
00291 /*     .    mended.  (The default value of NMIN is 75.)  Using NL = 49 */
00292 /*     .    allows up to six simultaneous shifts and a 16-by-16 */
00293 /*     .    deflation window.  ==== */
00294 /*     .. */
00295 /*     .. Local Arrays .. */
00296 /*     .. */
00297 /*     .. Local Scalars .. */
00298 /*     .. */
00299 /*     .. External Functions .. */
00300 /*     .. */
00301 /*     .. External Subroutines .. */
00302 /*     .. */
00303 /*     .. Intrinsic Functions .. */
00304 /*     .. */
00305 /*     .. Executable Statements .. */
00306 
00307 /*     ==== Decode and check the input parameters. ==== */
00308 
00309     /* Parameter adjustments */
00310     h_dim1 = *ldh;
00311     h_offset = 1 + h_dim1;
00312     h__ -= h_offset;
00313     --wr;
00314     --wi;
00315     z_dim1 = *ldz;
00316     z_offset = 1 + z_dim1;
00317     z__ -= z_offset;
00318     --work;
00319 
00320     /* Function Body */
00321     wantt = lsame_(job, "S");
00322     initz = lsame_(compz, "I");
00323     wantz = initz || lsame_(compz, "V");
00324     work[1] = (real) max(1,*n);
00325     lquery = *lwork == -1;
00326 
00327     *info = 0;
00328     if (! lsame_(job, "E") && ! wantt) {
00329         *info = -1;
00330     } else if (! lsame_(compz, "N") && ! wantz) {
00331         *info = -2;
00332     } else if (*n < 0) {
00333         *info = -3;
00334     } else if (*ilo < 1 || *ilo > max(1,*n)) {
00335         *info = -4;
00336     } else if (*ihi < min(*ilo,*n) || *ihi > *n) {
00337         *info = -5;
00338     } else if (*ldh < max(1,*n)) {
00339         *info = -7;
00340     } else if (*ldz < 1 || wantz && *ldz < max(1,*n)) {
00341         *info = -11;
00342     } else if (*lwork < max(1,*n) && ! lquery) {
00343         *info = -13;
00344     }
00345 
00346     if (*info != 0) {
00347 
00348 /*        ==== Quick return in case of invalid argument. ==== */
00349 
00350         i__1 = -(*info);
00351         xerbla_("SHSEQR", &i__1);
00352         return 0;
00353 
00354     } else if (*n == 0) {
00355 
00356 /*        ==== Quick return in case N = 0; nothing to do. ==== */
00357 
00358         return 0;
00359 
00360     } else if (lquery) {
00361 
00362 /*        ==== Quick return in case of a workspace query ==== */
00363 
00364         slaqr0_(&wantt, &wantz, n, ilo, ihi, &h__[h_offset], ldh, &wr[1], &wi[
00365                 1], ilo, ihi, &z__[z_offset], ldz, &work[1], lwork, info);
00366 /*        ==== Ensure reported workspace size is backward-compatible with */
00367 /*        .    previous LAPACK versions. ==== */
00368 /* Computing MAX */
00369         r__1 = (real) max(1,*n);
00370         work[1] = dmax(r__1,work[1]);
00371         return 0;
00372 
00373     } else {
00374 
00375 /*        ==== copy eigenvalues isolated by SGEBAL ==== */
00376 
00377         i__1 = *ilo - 1;
00378         for (i__ = 1; i__ <= i__1; ++i__) {
00379             wr[i__] = h__[i__ + i__ * h_dim1];
00380             wi[i__] = 0.f;
00381 /* L10: */
00382         }
00383         i__1 = *n;
00384         for (i__ = *ihi + 1; i__ <= i__1; ++i__) {
00385             wr[i__] = h__[i__ + i__ * h_dim1];
00386             wi[i__] = 0.f;
00387 /* L20: */
00388         }
00389 
00390 /*        ==== Initialize Z, if requested ==== */
00391 
00392         if (initz) {
00393             slaset_("A", n, n, &c_b11, &c_b12, &z__[z_offset], ldz)
00394                     ;
00395         }
00396 
00397 /*        ==== Quick return if possible ==== */
00398 
00399         if (*ilo == *ihi) {
00400             wr[*ilo] = h__[*ilo + *ilo * h_dim1];
00401             wi[*ilo] = 0.f;
00402             return 0;
00403         }
00404 
00405 /*        ==== SLAHQR/SLAQR0 crossover point ==== */
00406 
00407 /* Writing concatenation */
00408         i__2[0] = 1, a__1[0] = job;
00409         i__2[1] = 1, a__1[1] = compz;
00410         s_cat(ch__1, a__1, i__2, &c__2, (ftnlen)2);
00411         nmin = ilaenv_(&c__12, "SHSEQR", ch__1, n, ilo, ihi, lwork);
00412         nmin = max(11,nmin);
00413 
00414 /*        ==== SLAQR0 for big matrices; SLAHQR for small ones ==== */
00415 
00416         if (*n > nmin) {
00417             slaqr0_(&wantt, &wantz, n, ilo, ihi, &h__[h_offset], ldh, &wr[1], 
00418                     &wi[1], ilo, ihi, &z__[z_offset], ldz, &work[1], lwork, 
00419                     info);
00420         } else {
00421 
00422 /*           ==== Small matrix ==== */
00423 
00424             slahqr_(&wantt, &wantz, n, ilo, ihi, &h__[h_offset], ldh, &wr[1], 
00425                     &wi[1], ilo, ihi, &z__[z_offset], ldz, info);
00426 
00427             if (*info > 0) {
00428 
00429 /*              ==== A rare SLAHQR failure!  SLAQR0 sometimes succeeds */
00430 /*              .    when SLAHQR fails. ==== */
00431 
00432                 kbot = *info;
00433 
00434                 if (*n >= 49) {
00435 
00436 /*                 ==== Larger matrices have enough subdiagonal scratch */
00437 /*                 .    space to call SLAQR0 directly. ==== */
00438 
00439                     slaqr0_(&wantt, &wantz, n, ilo, &kbot, &h__[h_offset], 
00440                             ldh, &wr[1], &wi[1], ilo, ihi, &z__[z_offset], 
00441                             ldz, &work[1], lwork, info);
00442 
00443                 } else {
00444 
00445 /*                 ==== Tiny matrices don't have enough subdiagonal */
00446 /*                 .    scratch space to benefit from SLAQR0.  Hence, */
00447 /*                 .    tiny matrices must be copied into a larger */
00448 /*                 .    array before calling SLAQR0. ==== */
00449 
00450                     slacpy_("A", n, n, &h__[h_offset], ldh, hl, &c__49);
00451                     hl[*n + 1 + *n * 49 - 50] = 0.f;
00452                     i__1 = 49 - *n;
00453                     slaset_("A", &c__49, &i__1, &c_b11, &c_b11, &hl[(*n + 1) *
00454                              49 - 49], &c__49);
00455                     slaqr0_(&wantt, &wantz, &c__49, ilo, &kbot, hl, &c__49, &
00456                             wr[1], &wi[1], ilo, ihi, &z__[z_offset], ldz, 
00457                             workl, &c__49, info);
00458                     if (wantt || *info != 0) {
00459                         slacpy_("A", n, n, hl, &c__49, &h__[h_offset], ldh);
00460                     }
00461                 }
00462             }
00463         }
00464 
00465 /*        ==== Clear out the trash, if necessary. ==== */
00466 
00467         if ((wantt || *info != 0) && *n > 2) {
00468             i__1 = *n - 2;
00469             i__3 = *n - 2;
00470             slaset_("L", &i__1, &i__3, &c_b11, &c_b11, &h__[h_dim1 + 3], ldh);
00471         }
00472 
00473 /*        ==== Ensure reported workspace size is backward-compatible with */
00474 /*        .    previous LAPACK versions. ==== */
00475 
00476 /* Computing MAX */
00477         r__1 = (real) max(1,*n);
00478         work[1] = dmax(r__1,work[1]);
00479     }
00480 
00481 /*     ==== End of SHSEQR ==== */
00482 
00483     return 0;
00484 } /* shseqr_ */


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