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


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