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


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