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