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


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