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


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