zlaqr4.c
Go to the documentation of this file.
00001 /* zlaqr4.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__13 = 13;
00019 static integer c__15 = 15;
00020 static integer c_n1 = -1;
00021 static integer c__12 = 12;
00022 static integer c__14 = 14;
00023 static integer c__16 = 16;
00024 static logical c_false = FALSE_;
00025 static integer c__1 = 1;
00026 static integer c__3 = 3;
00027 
00028 /* Subroutine */ int zlaqr4_(logical *wantt, logical *wantz, integer *n, 
00029         integer *ilo, integer *ihi, doublecomplex *h__, integer *ldh, 
00030         doublecomplex *w, integer *iloz, integer *ihiz, doublecomplex *z__, 
00031         integer *ldz, doublecomplex *work, integer *lwork, integer *info)
00032 {
00033     /* System generated locals */
00034     integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
00035     doublereal d__1, d__2, d__3, d__4, d__5, d__6, d__7, d__8;
00036     doublecomplex z__1, z__2, z__3, z__4, z__5;
00037 
00038     /* Builtin functions */
00039     double d_imag(doublecomplex *);
00040     void z_sqrt(doublecomplex *, doublecomplex *);
00041 
00042     /* Local variables */
00043     integer i__, k;
00044     doublereal s;
00045     doublecomplex aa, bb, cc, dd;
00046     integer ld, nh, it, ks, kt, ku, kv, ls, ns, nw;
00047     doublecomplex tr2, det;
00048     integer inf, kdu, nho, nve, kwh, nsr, nwr, kwv, ndec, ndfl, kbot, nmin;
00049     doublecomplex swap;
00050     integer ktop;
00051     doublecomplex zdum[1]       /* was [1][1] */;
00052     integer kacc22, itmax, nsmax, nwmax, kwtop;
00053     extern /* Subroutine */ int zlaqr2_(logical *, logical *, integer *, 
00054             integer *, integer *, integer *, doublecomplex *, integer *, 
00055             integer *, integer *, doublecomplex *, integer *, integer *, 
00056             integer *, doublecomplex *, doublecomplex *, integer *, integer *, 
00057              doublecomplex *, integer *, integer *, doublecomplex *, integer *
00058 , doublecomplex *, integer *), zlaqr5_(logical *, logical *, 
00059             integer *, integer *, integer *, integer *, integer *, 
00060             doublecomplex *, doublecomplex *, integer *, integer *, integer *, 
00061              doublecomplex *, integer *, doublecomplex *, integer *, 
00062             doublecomplex *, integer *, integer *, doublecomplex *, integer *, 
00063              integer *, doublecomplex *, integer *);
00064     integer nibble;
00065     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00066             integer *, integer *);
00067     char jbcmpz[2];
00068     doublecomplex rtdisc;
00069     integer nwupbd;
00070     logical sorted;
00071     extern /* Subroutine */ int zlahqr_(logical *, logical *, integer *, 
00072             integer *, integer *, doublecomplex *, integer *, doublecomplex *, 
00073              integer *, integer *, doublecomplex *, integer *, integer *), 
00074             zlacpy_(char *, integer *, integer *, doublecomplex *, integer *, 
00075             doublecomplex *, integer *);
00076     integer lwkopt;
00077 
00078 
00079 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00080 /*     Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd.. */
00081 /*     November 2006 */
00082 
00083 /*     .. Scalar Arguments .. */
00084 /*     .. */
00085 /*     .. Array Arguments .. */
00086 /*     .. */
00087 
00088 /*     This subroutine implements one level of recursion for ZLAQR0. */
00089 /*     It is a complete implementation of the small bulge multi-shift */
00090 /*     QR algorithm.  It may be called by ZLAQR0 and, for large enough */
00091 /*     deflation window size, it may be called by ZLAQR3.  This */
00092 /*     subroutine is identical to ZLAQR0 except that it calls ZLAQR2 */
00093 /*     instead of ZLAQR3. */
00094 
00095 /*     Purpose */
00096 /*     ======= */
00097 
00098 /*     ZLAQR4 computes the eigenvalues of a Hessenberg matrix H */
00099 /*     and, optionally, the matrices T and Z from the Schur decomposition */
00100 /*     H = Z T Z**H, where T is an upper triangular matrix (the */
00101 /*     Schur form), and Z is the unitary matrix of Schur vectors. */
00102 
00103 /*     Optionally Z may be postmultiplied into an input unitary */
00104 /*     matrix Q so that this routine can give the Schur factorization */
00105 /*     of a matrix A which has been reduced to the Hessenberg form H */
00106 /*     by the unitary matrix Q:  A = Q*H*Q**H = (QZ)*H*(QZ)**H. */
00107 
00108 /*     Arguments */
00109 /*     ========= */
00110 
00111 /*     WANTT   (input) LOGICAL */
00112 /*          = .TRUE. : the full Schur form T is required; */
00113 /*          = .FALSE.: only eigenvalues are required. */
00114 
00115 /*     WANTZ   (input) LOGICAL */
00116 /*          = .TRUE. : the matrix of Schur vectors Z is required; */
00117 /*          = .FALSE.: Schur vectors are not required. */
00118 
00119 /*     N     (input) INTEGER */
00120 /*           The order of the matrix H.  N .GE. 0. */
00121 
00122 /*     ILO   (input) INTEGER */
00123 /*     IHI   (input) INTEGER */
00124 /*           It is assumed that H is already upper triangular in rows */
00125 /*           and columns 1:ILO-1 and IHI+1:N and, if ILO.GT.1, */
00126 /*           H(ILO,ILO-1) is zero. ILO and IHI are normally set by a */
00127 /*           previous call to ZGEBAL, and then passed to ZGEHRD when the */
00128 /*           matrix output by ZGEBAL is reduced to Hessenberg form. */
00129 /*           Otherwise, ILO and IHI should be set to 1 and N, */
00130 /*           respectively.  If N.GT.0, then 1.LE.ILO.LE.IHI.LE.N. */
00131 /*           If N = 0, then ILO = 1 and IHI = 0. */
00132 
00133 /*     H     (input/output) COMPLEX*16 array, dimension (LDH,N) */
00134 /*           On entry, the upper Hessenberg matrix H. */
00135 /*           On exit, if INFO = 0 and WANTT is .TRUE., then H */
00136 /*           contains the upper triangular matrix T from the Schur */
00137 /*           decomposition (the Schur form). If INFO = 0 and WANT is */
00138 /*           .FALSE., then the contents of H are unspecified on exit. */
00139 /*           (The output value of H when INFO.GT.0 is given under the */
00140 /*           description of INFO below.) */
00141 
00142 /*           This subroutine may explicitly set H(i,j) = 0 for i.GT.j and */
00143 /*           j = 1, 2, ... ILO-1 or j = IHI+1, IHI+2, ... N. */
00144 
00145 /*     LDH   (input) INTEGER */
00146 /*           The leading dimension of the array H. LDH .GE. max(1,N). */
00147 
00148 /*     W        (output) COMPLEX*16 array, dimension (N) */
00149 /*           The computed eigenvalues of H(ILO:IHI,ILO:IHI) are stored */
00150 /*           in W(ILO:IHI). If WANTT is .TRUE., then the eigenvalues are */
00151 /*           stored in the same order as on the diagonal of the Schur */
00152 /*           form returned in H, with W(i) = H(i,i). */
00153 
00154 /*     Z     (input/output) COMPLEX*16 array, dimension (LDZ,IHI) */
00155 /*           If WANTZ is .FALSE., then Z is not referenced. */
00156 /*           If WANTZ is .TRUE., then Z(ILO:IHI,ILOZ:IHIZ) is */
00157 /*           replaced by Z(ILO:IHI,ILOZ:IHIZ)*U where U is the */
00158 /*           orthogonal Schur factor of H(ILO:IHI,ILO:IHI). */
00159 /*           (The output value of Z when INFO.GT.0 is given under */
00160 /*           the description of INFO below.) */
00161 
00162 /*     LDZ   (input) INTEGER */
00163 /*           The leading dimension of the array Z.  if WANTZ is .TRUE. */
00164 /*           then LDZ.GE.MAX(1,IHIZ).  Otherwize, LDZ.GE.1. */
00165 
00166 /*     WORK  (workspace/output) COMPLEX*16 array, dimension LWORK */
00167 /*           On exit, if LWORK = -1, WORK(1) returns an estimate of */
00168 /*           the optimal value for LWORK. */
00169 
00170 /*     LWORK (input) INTEGER */
00171 /*           The dimension of the array WORK.  LWORK .GE. max(1,N) */
00172 /*           is sufficient, but LWORK typically as large as 6*N may */
00173 /*           be required for optimal performance.  A workspace query */
00174 /*           to determine the optimal workspace size is recommended. */
00175 
00176 /*           If LWORK = -1, then ZLAQR4 does a workspace query. */
00177 /*           In this case, ZLAQR4 checks the input parameters and */
00178 /*           estimates the optimal workspace size for the given */
00179 /*           values of N, ILO and IHI.  The estimate is returned */
00180 /*           in WORK(1).  No error message related to LWORK is */
00181 /*           issued by XERBLA.  Neither H nor Z are accessed. */
00182 
00183 
00184 /*     INFO  (output) INTEGER */
00185 /*             =  0:  successful exit */
00186 /*           .GT. 0:  if INFO = i, ZLAQR4 failed to compute all of */
00187 /*                the eigenvalues.  Elements 1:ilo-1 and i+1:n of WR */
00188 /*                and WI contain those eigenvalues which have been */
00189 /*                successfully computed.  (Failures are rare.) */
00190 
00191 /*                If INFO .GT. 0 and WANT is .FALSE., then on exit, */
00192 /*                the remaining unconverged eigenvalues are the eigen- */
00193 /*                values of the upper Hessenberg matrix rows and */
00194 /*                columns ILO through INFO of the final, output */
00195 /*                value of H. */
00196 
00197 /*                If INFO .GT. 0 and WANTT is .TRUE., then on exit */
00198 
00199 /*           (*)  (initial value of H)*U  = U*(final value of H) */
00200 
00201 /*                where U is a unitary matrix.  The final */
00202 /*                value of  H is upper Hessenberg and triangular in */
00203 /*                rows and columns INFO+1 through IHI. */
00204 
00205 /*                If INFO .GT. 0 and WANTZ is .TRUE., then on exit */
00206 
00207 /*                  (final value of Z(ILO:IHI,ILOZ:IHIZ) */
00208 /*                   =  (initial value of Z(ILO:IHI,ILOZ:IHIZ)*U */
00209 
00210 /*                where U is the unitary matrix in (*) (regard- */
00211 /*                less of the value of WANTT.) */
00212 
00213 /*                If INFO .GT. 0 and WANTZ is .FALSE., then Z is not */
00214 /*                accessed. */
00215 
00216 /*     ================================================================ */
00217 /*     Based on contributions by */
00218 /*        Karen Braman and Ralph Byers, Department of Mathematics, */
00219 /*        University of Kansas, USA */
00220 
00221 /*     ================================================================ */
00222 /*     References: */
00223 /*       K. Braman, R. Byers and R. Mathias, The Multi-Shift QR */
00224 /*       Algorithm Part I: Maintaining Well Focused Shifts, and Level 3 */
00225 /*       Performance, SIAM Journal of Matrix Analysis, volume 23, pages */
00226 /*       929--947, 2002. */
00227 
00228 /*       K. Braman, R. Byers and R. Mathias, The Multi-Shift QR */
00229 /*       Algorithm Part II: Aggressive Early Deflation, SIAM Journal */
00230 /*       of Matrix Analysis, volume 23, pages 948--973, 2002. */
00231 
00232 /*     ================================================================ */
00233 /*     .. Parameters .. */
00234 
00235 /*     ==== Matrices of order NTINY or smaller must be processed by */
00236 /*     .    ZLAHQR because of insufficient subdiagonal scratch space. */
00237 /*     .    (This is a hard limit.) ==== */
00238 
00239 /*     ==== Exceptional deflation windows:  try to cure rare */
00240 /*     .    slow convergence by varying the size of the */
00241 /*     .    deflation window after KEXNW iterations. ==== */
00242 
00243 /*     ==== Exceptional shifts: try to cure rare slow convergence */
00244 /*     .    with ad-hoc exceptional shifts every KEXSH iterations. */
00245 /*     .    ==== */
00246 
00247 /*     ==== The constant WILK1 is used to form the exceptional */
00248 /*     .    shifts. ==== */
00249 /*     .. */
00250 /*     .. Local Scalars .. */
00251 /*     .. */
00252 /*     .. External Functions .. */
00253 /*     .. */
00254 /*     .. Local Arrays .. */
00255 /*     .. */
00256 /*     .. External Subroutines .. */
00257 /*     .. */
00258 /*     .. Intrinsic Functions .. */
00259 /*     .. */
00260 /*     .. Statement Functions .. */
00261 /*     .. */
00262 /*     .. Statement Function definitions .. */
00263 /*     .. */
00264 /*     .. Executable Statements .. */
00265     /* Parameter adjustments */
00266     h_dim1 = *ldh;
00267     h_offset = 1 + h_dim1;
00268     h__ -= h_offset;
00269     --w;
00270     z_dim1 = *ldz;
00271     z_offset = 1 + z_dim1;
00272     z__ -= z_offset;
00273     --work;
00274 
00275     /* Function Body */
00276     *info = 0;
00277 
00278 /*     ==== Quick return for N = 0: nothing to do. ==== */
00279 
00280     if (*n == 0) {
00281         work[1].r = 1., work[1].i = 0.;
00282         return 0;
00283     }
00284 
00285     if (*n <= 11) {
00286 
00287 /*        ==== Tiny matrices must use ZLAHQR. ==== */
00288 
00289         lwkopt = 1;
00290         if (*lwork != -1) {
00291             zlahqr_(wantt, wantz, n, ilo, ihi, &h__[h_offset], ldh, &w[1], 
00292                     iloz, ihiz, &z__[z_offset], ldz, info);
00293         }
00294     } else {
00295 
00296 /*        ==== Use small bulge multi-shift QR with aggressive early */
00297 /*        .    deflation on larger-than-tiny matrices. ==== */
00298 
00299 /*        ==== Hope for the best. ==== */
00300 
00301         *info = 0;
00302 
00303 /*        ==== Set up job flags for ILAENV. ==== */
00304 
00305         if (*wantt) {
00306             *(unsigned char *)jbcmpz = 'S';
00307         } else {
00308             *(unsigned char *)jbcmpz = 'E';
00309         }
00310         if (*wantz) {
00311             *(unsigned char *)&jbcmpz[1] = 'V';
00312         } else {
00313             *(unsigned char *)&jbcmpz[1] = 'N';
00314         }
00315 
00316 /*        ==== NWR = recommended deflation window size.  At this */
00317 /*        .    point,  N .GT. NTINY = 11, so there is enough */
00318 /*        .    subdiagonal workspace for NWR.GE.2 as required. */
00319 /*        .    (In fact, there is enough subdiagonal space for */
00320 /*        .    NWR.GE.3.) ==== */
00321 
00322         nwr = ilaenv_(&c__13, "ZLAQR4", jbcmpz, n, ilo, ihi, lwork);
00323         nwr = max(2,nwr);
00324 /* Computing MIN */
00325         i__1 = *ihi - *ilo + 1, i__2 = (*n - 1) / 3, i__1 = min(i__1,i__2);
00326         nwr = min(i__1,nwr);
00327 
00328 /*        ==== NSR = recommended number of simultaneous shifts. */
00329 /*        .    At this point N .GT. NTINY = 11, so there is at */
00330 /*        .    enough subdiagonal workspace for NSR to be even */
00331 /*        .    and greater than or equal to two as required. ==== */
00332 
00333         nsr = ilaenv_(&c__15, "ZLAQR4", jbcmpz, n, ilo, ihi, lwork);
00334 /* Computing MIN */
00335         i__1 = nsr, i__2 = (*n + 6) / 9, i__1 = min(i__1,i__2), i__2 = *ihi - 
00336                 *ilo;
00337         nsr = min(i__1,i__2);
00338 /* Computing MAX */
00339         i__1 = 2, i__2 = nsr - nsr % 2;
00340         nsr = max(i__1,i__2);
00341 
00342 /*        ==== Estimate optimal workspace ==== */
00343 
00344 /*        ==== Workspace query call to ZLAQR2 ==== */
00345 
00346         i__1 = nwr + 1;
00347         zlaqr2_(wantt, wantz, n, ilo, ihi, &i__1, &h__[h_offset], ldh, iloz, 
00348                 ihiz, &z__[z_offset], ldz, &ls, &ld, &w[1], &h__[h_offset], 
00349                 ldh, n, &h__[h_offset], ldh, n, &h__[h_offset], ldh, &work[1], 
00350                  &c_n1);
00351 
00352 /*        ==== Optimal workspace = MAX(ZLAQR5, ZLAQR2) ==== */
00353 
00354 /* Computing MAX */
00355         i__1 = nsr * 3 / 2, i__2 = (integer) work[1].r;
00356         lwkopt = max(i__1,i__2);
00357 
00358 /*        ==== Quick return in case of workspace query. ==== */
00359 
00360         if (*lwork == -1) {
00361             d__1 = (doublereal) lwkopt;
00362             z__1.r = d__1, z__1.i = 0.;
00363             work[1].r = z__1.r, work[1].i = z__1.i;
00364             return 0;
00365         }
00366 
00367 /*        ==== ZLAHQR/ZLAQR0 crossover point ==== */
00368 
00369         nmin = ilaenv_(&c__12, "ZLAQR4", jbcmpz, n, ilo, ihi, lwork);
00370         nmin = max(11,nmin);
00371 
00372 /*        ==== Nibble crossover point ==== */
00373 
00374         nibble = ilaenv_(&c__14, "ZLAQR4", jbcmpz, n, ilo, ihi, lwork);
00375         nibble = max(0,nibble);
00376 
00377 /*        ==== Accumulate reflections during ttswp?  Use block */
00378 /*        .    2-by-2 structure during matrix-matrix multiply? ==== */
00379 
00380         kacc22 = ilaenv_(&c__16, "ZLAQR4", jbcmpz, n, ilo, ihi, lwork);
00381         kacc22 = max(0,kacc22);
00382         kacc22 = min(2,kacc22);
00383 
00384 /*        ==== NWMAX = the largest possible deflation window for */
00385 /*        .    which there is sufficient workspace. ==== */
00386 
00387 /* Computing MIN */
00388         i__1 = (*n - 1) / 3, i__2 = *lwork / 2;
00389         nwmax = min(i__1,i__2);
00390         nw = nwmax;
00391 
00392 /*        ==== NSMAX = the Largest number of simultaneous shifts */
00393 /*        .    for which there is sufficient workspace. ==== */
00394 
00395 /* Computing MIN */
00396         i__1 = (*n + 6) / 9, i__2 = (*lwork << 1) / 3;
00397         nsmax = min(i__1,i__2);
00398         nsmax -= nsmax % 2;
00399 
00400 /*        ==== NDFL: an iteration count restarted at deflation. ==== */
00401 
00402         ndfl = 1;
00403 
00404 /*        ==== ITMAX = iteration limit ==== */
00405 
00406 /* Computing MAX */
00407         i__1 = 10, i__2 = *ihi - *ilo + 1;
00408         itmax = max(i__1,i__2) * 30;
00409 
00410 /*        ==== Last row and column in the active block ==== */
00411 
00412         kbot = *ihi;
00413 
00414 /*        ==== Main Loop ==== */
00415 
00416         i__1 = itmax;
00417         for (it = 1; it <= i__1; ++it) {
00418 
00419 /*           ==== Done when KBOT falls below ILO ==== */
00420 
00421             if (kbot < *ilo) {
00422                 goto L80;
00423             }
00424 
00425 /*           ==== Locate active block ==== */
00426 
00427             i__2 = *ilo + 1;
00428             for (k = kbot; k >= i__2; --k) {
00429                 i__3 = k + (k - 1) * h_dim1;
00430                 if (h__[i__3].r == 0. && h__[i__3].i == 0.) {
00431                     goto L20;
00432                 }
00433 /* L10: */
00434             }
00435             k = *ilo;
00436 L20:
00437             ktop = k;
00438 
00439 /*           ==== Select deflation window size: */
00440 /*           .    Typical Case: */
00441 /*           .      If possible and advisable, nibble the entire */
00442 /*           .      active block.  If not, use size MIN(NWR,NWMAX) */
00443 /*           .      or MIN(NWR+1,NWMAX) depending upon which has */
00444 /*           .      the smaller corresponding subdiagonal entry */
00445 /*           .      (a heuristic). */
00446 /*           . */
00447 /*           .    Exceptional Case: */
00448 /*           .      If there have been no deflations in KEXNW or */
00449 /*           .      more iterations, then vary the deflation window */
00450 /*           .      size.   At first, because, larger windows are, */
00451 /*           .      in general, more powerful than smaller ones, */
00452 /*           .      rapidly increase the window to the maximum possible. */
00453 /*           .      Then, gradually reduce the window size. ==== */
00454 
00455             nh = kbot - ktop + 1;
00456             nwupbd = min(nh,nwmax);
00457             if (ndfl < 5) {
00458                 nw = min(nwupbd,nwr);
00459             } else {
00460 /* Computing MIN */
00461                 i__2 = nwupbd, i__3 = nw << 1;
00462                 nw = min(i__2,i__3);
00463             }
00464             if (nw < nwmax) {
00465                 if (nw >= nh - 1) {
00466                     nw = nh;
00467                 } else {
00468                     kwtop = kbot - nw + 1;
00469                     i__2 = kwtop + (kwtop - 1) * h_dim1;
00470                     i__3 = kwtop - 1 + (kwtop - 2) * h_dim1;
00471                     if ((d__1 = h__[i__2].r, abs(d__1)) + (d__2 = d_imag(&h__[
00472                             kwtop + (kwtop - 1) * h_dim1]), abs(d__2)) > (
00473                             d__3 = h__[i__3].r, abs(d__3)) + (d__4 = d_imag(&
00474                             h__[kwtop - 1 + (kwtop - 2) * h_dim1]), abs(d__4))
00475                             ) {
00476                         ++nw;
00477                     }
00478                 }
00479             }
00480             if (ndfl < 5) {
00481                 ndec = -1;
00482             } else if (ndec >= 0 || nw >= nwupbd) {
00483                 ++ndec;
00484                 if (nw - ndec < 2) {
00485                     ndec = 0;
00486                 }
00487                 nw -= ndec;
00488             }
00489 
00490 /*           ==== Aggressive early deflation: */
00491 /*           .    split workspace under the subdiagonal into */
00492 /*           .      - an nw-by-nw work array V in the lower */
00493 /*           .        left-hand-corner, */
00494 /*           .      - an NW-by-at-least-NW-but-more-is-better */
00495 /*           .        (NW-by-NHO) horizontal work array along */
00496 /*           .        the bottom edge, */
00497 /*           .      - an at-least-NW-but-more-is-better (NHV-by-NW) */
00498 /*           .        vertical work array along the left-hand-edge. */
00499 /*           .        ==== */
00500 
00501             kv = *n - nw + 1;
00502             kt = nw + 1;
00503             nho = *n - nw - 1 - kt + 1;
00504             kwv = nw + 2;
00505             nve = *n - nw - kwv + 1;
00506 
00507 /*           ==== Aggressive early deflation ==== */
00508 
00509             zlaqr2_(wantt, wantz, n, &ktop, &kbot, &nw, &h__[h_offset], ldh, 
00510                     iloz, ihiz, &z__[z_offset], ldz, &ls, &ld, &w[1], &h__[kv 
00511                     + h_dim1], ldh, &nho, &h__[kv + kt * h_dim1], ldh, &nve, &
00512                     h__[kwv + h_dim1], ldh, &work[1], lwork);
00513 
00514 /*           ==== Adjust KBOT accounting for new deflations. ==== */
00515 
00516             kbot -= ld;
00517 
00518 /*           ==== KS points to the shifts. ==== */
00519 
00520             ks = kbot - ls + 1;
00521 
00522 /*           ==== Skip an expensive QR sweep if there is a (partly */
00523 /*           .    heuristic) reason to expect that many eigenvalues */
00524 /*           .    will deflate without it.  Here, the QR sweep is */
00525 /*           .    skipped if many eigenvalues have just been deflated */
00526 /*           .    or if the remaining active block is small. */
00527 
00528             if (ld == 0 || ld * 100 <= nw * nibble && kbot - ktop + 1 > min(
00529                     nmin,nwmax)) {
00530 
00531 /*              ==== NS = nominal number of simultaneous shifts. */
00532 /*              .    This may be lowered (slightly) if ZLAQR2 */
00533 /*              .    did not provide that many shifts. ==== */
00534 
00535 /* Computing MIN */
00536 /* Computing MAX */
00537                 i__4 = 2, i__5 = kbot - ktop;
00538                 i__2 = min(nsmax,nsr), i__3 = max(i__4,i__5);
00539                 ns = min(i__2,i__3);
00540                 ns -= ns % 2;
00541 
00542 /*              ==== If there have been no deflations */
00543 /*              .    in a multiple of KEXSH iterations, */
00544 /*              .    then try exceptional shifts. */
00545 /*              .    Otherwise use shifts provided by */
00546 /*              .    ZLAQR2 above or from the eigenvalues */
00547 /*              .    of a trailing principal submatrix. ==== */
00548 
00549                 if (ndfl % 6 == 0) {
00550                     ks = kbot - ns + 1;
00551                     i__2 = ks + 1;
00552                     for (i__ = kbot; i__ >= i__2; i__ += -2) {
00553                         i__3 = i__;
00554                         i__4 = i__ + i__ * h_dim1;
00555                         i__5 = i__ + (i__ - 1) * h_dim1;
00556                         d__3 = ((d__1 = h__[i__5].r, abs(d__1)) + (d__2 = 
00557                                 d_imag(&h__[i__ + (i__ - 1) * h_dim1]), abs(
00558                                 d__2))) * .75;
00559                         z__1.r = h__[i__4].r + d__3, z__1.i = h__[i__4].i;
00560                         w[i__3].r = z__1.r, w[i__3].i = z__1.i;
00561                         i__3 = i__ - 1;
00562                         i__4 = i__;
00563                         w[i__3].r = w[i__4].r, w[i__3].i = w[i__4].i;
00564 /* L30: */
00565                     }
00566                 } else {
00567 
00568 /*                 ==== Got NS/2 or fewer shifts? Use ZLAHQR */
00569 /*                 .    on a trailing principal submatrix to */
00570 /*                 .    get more. (Since NS.LE.NSMAX.LE.(N+6)/9, */
00571 /*                 .    there is enough space below the subdiagonal */
00572 /*                 .    to fit an NS-by-NS scratch array.) ==== */
00573 
00574                     if (kbot - ks + 1 <= ns / 2) {
00575                         ks = kbot - ns + 1;
00576                         kt = *n - ns + 1;
00577                         zlacpy_("A", &ns, &ns, &h__[ks + ks * h_dim1], ldh, &
00578                                 h__[kt + h_dim1], ldh);
00579                         zlahqr_(&c_false, &c_false, &ns, &c__1, &ns, &h__[kt 
00580                                 + h_dim1], ldh, &w[ks], &c__1, &c__1, zdum, &
00581                                 c__1, &inf);
00582                         ks += inf;
00583 
00584 /*                    ==== In case of a rare QR failure use */
00585 /*                    .    eigenvalues of the trailing 2-by-2 */
00586 /*                    .    principal submatrix.  Scale to avoid */
00587 /*                    .    overflows, underflows and subnormals. */
00588 /*                    .    (The scale factor S can not be zero, */
00589 /*                    .    because H(KBOT,KBOT-1) is nonzero.) ==== */
00590 
00591                         if (ks >= kbot) {
00592                             i__2 = kbot - 1 + (kbot - 1) * h_dim1;
00593                             i__3 = kbot + (kbot - 1) * h_dim1;
00594                             i__4 = kbot - 1 + kbot * h_dim1;
00595                             i__5 = kbot + kbot * h_dim1;
00596                             s = (d__1 = h__[i__2].r, abs(d__1)) + (d__2 = 
00597                                     d_imag(&h__[kbot - 1 + (kbot - 1) * 
00598                                     h_dim1]), abs(d__2)) + ((d__3 = h__[i__3]
00599                                     .r, abs(d__3)) + (d__4 = d_imag(&h__[kbot 
00600                                     + (kbot - 1) * h_dim1]), abs(d__4))) + ((
00601                                     d__5 = h__[i__4].r, abs(d__5)) + (d__6 = 
00602                                     d_imag(&h__[kbot - 1 + kbot * h_dim1]), 
00603                                     abs(d__6))) + ((d__7 = h__[i__5].r, abs(
00604                                     d__7)) + (d__8 = d_imag(&h__[kbot + kbot *
00605                                      h_dim1]), abs(d__8)));
00606                             i__2 = kbot - 1 + (kbot - 1) * h_dim1;
00607                             z__1.r = h__[i__2].r / s, z__1.i = h__[i__2].i / 
00608                                     s;
00609                             aa.r = z__1.r, aa.i = z__1.i;
00610                             i__2 = kbot + (kbot - 1) * h_dim1;
00611                             z__1.r = h__[i__2].r / s, z__1.i = h__[i__2].i / 
00612                                     s;
00613                             cc.r = z__1.r, cc.i = z__1.i;
00614                             i__2 = kbot - 1 + kbot * h_dim1;
00615                             z__1.r = h__[i__2].r / s, z__1.i = h__[i__2].i / 
00616                                     s;
00617                             bb.r = z__1.r, bb.i = z__1.i;
00618                             i__2 = kbot + kbot * h_dim1;
00619                             z__1.r = h__[i__2].r / s, z__1.i = h__[i__2].i / 
00620                                     s;
00621                             dd.r = z__1.r, dd.i = z__1.i;
00622                             z__2.r = aa.r + dd.r, z__2.i = aa.i + dd.i;
00623                             z__1.r = z__2.r / 2., z__1.i = z__2.i / 2.;
00624                             tr2.r = z__1.r, tr2.i = z__1.i;
00625                             z__3.r = aa.r - tr2.r, z__3.i = aa.i - tr2.i;
00626                             z__4.r = dd.r - tr2.r, z__4.i = dd.i - tr2.i;
00627                             z__2.r = z__3.r * z__4.r - z__3.i * z__4.i, 
00628                                     z__2.i = z__3.r * z__4.i + z__3.i * 
00629                                     z__4.r;
00630                             z__5.r = bb.r * cc.r - bb.i * cc.i, z__5.i = bb.r 
00631                                     * cc.i + bb.i * cc.r;
00632                             z__1.r = z__2.r - z__5.r, z__1.i = z__2.i - 
00633                                     z__5.i;
00634                             det.r = z__1.r, det.i = z__1.i;
00635                             z__2.r = -det.r, z__2.i = -det.i;
00636                             z_sqrt(&z__1, &z__2);
00637                             rtdisc.r = z__1.r, rtdisc.i = z__1.i;
00638                             i__2 = kbot - 1;
00639                             z__2.r = tr2.r + rtdisc.r, z__2.i = tr2.i + 
00640                                     rtdisc.i;
00641                             z__1.r = s * z__2.r, z__1.i = s * z__2.i;
00642                             w[i__2].r = z__1.r, w[i__2].i = z__1.i;
00643                             i__2 = kbot;
00644                             z__2.r = tr2.r - rtdisc.r, z__2.i = tr2.i - 
00645                                     rtdisc.i;
00646                             z__1.r = s * z__2.r, z__1.i = s * z__2.i;
00647                             w[i__2].r = z__1.r, w[i__2].i = z__1.i;
00648 
00649                             ks = kbot - 1;
00650                         }
00651                     }
00652 
00653                     if (kbot - ks + 1 > ns) {
00654 
00655 /*                    ==== Sort the shifts (Helps a little) ==== */
00656 
00657                         sorted = FALSE_;
00658                         i__2 = ks + 1;
00659                         for (k = kbot; k >= i__2; --k) {
00660                             if (sorted) {
00661                                 goto L60;
00662                             }
00663                             sorted = TRUE_;
00664                             i__3 = k - 1;
00665                             for (i__ = ks; i__ <= i__3; ++i__) {
00666                                 i__4 = i__;
00667                                 i__5 = i__ + 1;
00668                                 if ((d__1 = w[i__4].r, abs(d__1)) + (d__2 = 
00669                                         d_imag(&w[i__]), abs(d__2)) < (d__3 = 
00670                                         w[i__5].r, abs(d__3)) + (d__4 = 
00671                                         d_imag(&w[i__ + 1]), abs(d__4))) {
00672                                     sorted = FALSE_;
00673                                     i__4 = i__;
00674                                     swap.r = w[i__4].r, swap.i = w[i__4].i;
00675                                     i__4 = i__;
00676                                     i__5 = i__ + 1;
00677                                     w[i__4].r = w[i__5].r, w[i__4].i = w[i__5]
00678                                             .i;
00679                                     i__4 = i__ + 1;
00680                                     w[i__4].r = swap.r, w[i__4].i = swap.i;
00681                                 }
00682 /* L40: */
00683                             }
00684 /* L50: */
00685                         }
00686 L60:
00687                         ;
00688                     }
00689                 }
00690 
00691 /*              ==== If there are only two shifts, then use */
00692 /*              .    only one.  ==== */
00693 
00694                 if (kbot - ks + 1 == 2) {
00695                     i__2 = kbot;
00696                     i__3 = kbot + kbot * h_dim1;
00697                     z__2.r = w[i__2].r - h__[i__3].r, z__2.i = w[i__2].i - 
00698                             h__[i__3].i;
00699                     z__1.r = z__2.r, z__1.i = z__2.i;
00700                     i__4 = kbot - 1;
00701                     i__5 = kbot + kbot * h_dim1;
00702                     z__4.r = w[i__4].r - h__[i__5].r, z__4.i = w[i__4].i - 
00703                             h__[i__5].i;
00704                     z__3.r = z__4.r, z__3.i = z__4.i;
00705                     if ((d__1 = z__1.r, abs(d__1)) + (d__2 = d_imag(&z__1), 
00706                             abs(d__2)) < (d__3 = z__3.r, abs(d__3)) + (d__4 = 
00707                             d_imag(&z__3), abs(d__4))) {
00708                         i__2 = kbot - 1;
00709                         i__3 = kbot;
00710                         w[i__2].r = w[i__3].r, w[i__2].i = w[i__3].i;
00711                     } else {
00712                         i__2 = kbot;
00713                         i__3 = kbot - 1;
00714                         w[i__2].r = w[i__3].r, w[i__2].i = w[i__3].i;
00715                     }
00716                 }
00717 
00718 /*              ==== Use up to NS of the the smallest magnatiude */
00719 /*              .    shifts.  If there aren't NS shifts available, */
00720 /*              .    then use them all, possibly dropping one to */
00721 /*              .    make the number of shifts even. ==== */
00722 
00723 /* Computing MIN */
00724                 i__2 = ns, i__3 = kbot - ks + 1;
00725                 ns = min(i__2,i__3);
00726                 ns -= ns % 2;
00727                 ks = kbot - ns + 1;
00728 
00729 /*              ==== Small-bulge multi-shift QR sweep: */
00730 /*              .    split workspace under the subdiagonal into */
00731 /*              .    - a KDU-by-KDU work array U in the lower */
00732 /*              .      left-hand-corner, */
00733 /*              .    - a KDU-by-at-least-KDU-but-more-is-better */
00734 /*              .      (KDU-by-NHo) horizontal work array WH along */
00735 /*              .      the bottom edge, */
00736 /*              .    - and an at-least-KDU-but-more-is-better-by-KDU */
00737 /*              .      (NVE-by-KDU) vertical work WV arrow along */
00738 /*              .      the left-hand-edge. ==== */
00739 
00740                 kdu = ns * 3 - 3;
00741                 ku = *n - kdu + 1;
00742                 kwh = kdu + 1;
00743                 nho = *n - kdu - 3 - (kdu + 1) + 1;
00744                 kwv = kdu + 4;
00745                 nve = *n - kdu - kwv + 1;
00746 
00747 /*              ==== Small-bulge multi-shift QR sweep ==== */
00748 
00749                 zlaqr5_(wantt, wantz, &kacc22, n, &ktop, &kbot, &ns, &w[ks], &
00750                         h__[h_offset], ldh, iloz, ihiz, &z__[z_offset], ldz, &
00751                         work[1], &c__3, &h__[ku + h_dim1], ldh, &nve, &h__[
00752                         kwv + h_dim1], ldh, &nho, &h__[ku + kwh * h_dim1], 
00753                         ldh);
00754             }
00755 
00756 /*           ==== Note progress (or the lack of it). ==== */
00757 
00758             if (ld > 0) {
00759                 ndfl = 1;
00760             } else {
00761                 ++ndfl;
00762             }
00763 
00764 /*           ==== End of main loop ==== */
00765 /* L70: */
00766         }
00767 
00768 /*        ==== Iteration limit exceeded.  Set INFO to show where */
00769 /*        .    the problem occurred and exit. ==== */
00770 
00771         *info = kbot;
00772 L80:
00773         ;
00774     }
00775 
00776 /*     ==== Return the optimal value of LWORK. ==== */
00777 
00778     d__1 = (doublereal) lwkopt;
00779     z__1.r = d__1, z__1.i = 0.;
00780     work[1].r = z__1.r, work[1].i = z__1.i;
00781 
00782 /*     ==== End of ZLAQR4 ==== */
00783 
00784     return 0;
00785 } /* zlaqr4_ */


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