00001 /* zhseqr.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 doublecomplex c_b1 = {0.,0.}; 00019 static doublecomplex c_b2 = {1.,0.}; 00020 static integer c__1 = 1; 00021 static integer c__12 = 12; 00022 static integer c__2 = 2; 00023 static integer c__49 = 49; 00024 00025 /* Subroutine */ int zhseqr_(char *job, char *compz, integer *n, integer *ilo, 00026 integer *ihi, doublecomplex *h__, integer *ldh, doublecomplex *w, 00027 doublecomplex *z__, integer *ldz, doublecomplex *work, integer *lwork, 00028 integer *info) 00029 { 00030 /* System generated locals */ 00031 address a__1[2]; 00032 integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2, i__3[2]; 00033 doublereal d__1, d__2, d__3; 00034 doublecomplex z__1; 00035 char ch__1[2]; 00036 00037 /* Builtin functions */ 00038 /* Subroutine */ int s_cat(char *, char **, integer *, integer *, ftnlen); 00039 00040 /* Local variables */ 00041 doublecomplex hl[2401] /* was [49][49] */; 00042 integer kbot, nmin; 00043 extern logical lsame_(char *, char *); 00044 logical initz; 00045 doublecomplex workl[49]; 00046 logical wantt, wantz; 00047 extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *, 00048 doublecomplex *, integer *), zlaqr0_(logical *, logical *, 00049 integer *, integer *, integer *, doublecomplex *, integer *, 00050 doublecomplex *, integer *, integer *, doublecomplex *, integer *, 00051 doublecomplex *, integer *, integer *), xerbla_(char *, integer * 00052 ); 00053 extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 00054 integer *, integer *); 00055 extern /* Subroutine */ int zlahqr_(logical *, logical *, integer *, 00056 integer *, integer *, doublecomplex *, integer *, doublecomplex *, 00057 integer *, integer *, doublecomplex *, integer *, integer *), 00058 zlacpy_(char *, integer *, integer *, doublecomplex *, integer *, 00059 doublecomplex *, integer *), zlaset_(char *, integer *, 00060 integer *, doublecomplex *, doublecomplex *, doublecomplex *, 00061 integer *); 00062 logical lquery; 00063 00064 00065 /* -- LAPACK driver routine (version 3.2) -- */ 00066 /* Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd.. */ 00067 /* November 2006 */ 00068 00069 /* .. Scalar Arguments .. */ 00070 /* .. */ 00071 /* .. Array Arguments .. */ 00072 /* .. */ 00073 /* Purpose */ 00074 /* ======= */ 00075 00076 /* ZHSEQR computes the eigenvalues of a Hessenberg matrix H */ 00077 /* and, optionally, the matrices T and Z from the Schur decomposition */ 00078 /* H = Z T Z**H, where T is an upper triangular matrix (the */ 00079 /* Schur form), and Z is the unitary matrix of Schur vectors. */ 00080 00081 /* Optionally Z may be postmultiplied into an input unitary */ 00082 /* matrix Q so that this routine can give the Schur factorization */ 00083 /* of a matrix A which has been reduced to the Hessenberg form H */ 00084 /* by the unitary matrix Q: A = Q*H*Q**H = (QZ)*H*(QZ)**H. */ 00085 00086 /* Arguments */ 00087 /* ========= */ 00088 00089 /* JOB (input) CHARACTER*1 */ 00090 /* = 'E': compute eigenvalues only; */ 00091 /* = 'S': compute eigenvalues and the Schur form T. */ 00092 00093 /* COMPZ (input) CHARACTER*1 */ 00094 /* = 'N': no Schur vectors are computed; */ 00095 /* = 'I': Z is initialized to the unit matrix and the matrix Z */ 00096 /* of Schur vectors of H is returned; */ 00097 /* = 'V': Z must contain an unitary matrix Q on entry, and */ 00098 /* the product Q*Z is returned. */ 00099 00100 /* N (input) INTEGER */ 00101 /* The order of the matrix H. N .GE. 0. */ 00102 00103 /* ILO (input) INTEGER */ 00104 /* IHI (input) INTEGER */ 00105 /* It is assumed that H is already upper triangular in rows */ 00106 /* and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally */ 00107 /* set by a previous call to ZGEBAL, and then passed to ZGEHRD */ 00108 /* when the matrix output by ZGEBAL is reduced to Hessenberg */ 00109 /* form. Otherwise ILO and IHI should be set to 1 and N */ 00110 /* respectively. If N.GT.0, then 1.LE.ILO.LE.IHI.LE.N. */ 00111 /* If N = 0, then ILO = 1 and IHI = 0. */ 00112 00113 /* H (input/output) COMPLEX*16 array, dimension (LDH,N) */ 00114 /* On entry, the upper Hessenberg matrix H. */ 00115 /* On exit, if INFO = 0 and JOB = 'S', H contains the upper */ 00116 /* triangular matrix T from the Schur decomposition (the */ 00117 /* Schur form). If INFO = 0 and JOB = 'E', the contents of */ 00118 /* H are unspecified on exit. (The output value of H when */ 00119 /* INFO.GT.0 is given under the description of INFO below.) */ 00120 00121 /* Unlike earlier versions of ZHSEQR, this subroutine may */ 00122 /* explicitly H(i,j) = 0 for i.GT.j and j = 1, 2, ... ILO-1 */ 00123 /* or j = IHI+1, IHI+2, ... N. */ 00124 00125 /* LDH (input) INTEGER */ 00126 /* The leading dimension of the array H. LDH .GE. max(1,N). */ 00127 00128 /* W (output) COMPLEX*16 array, dimension (N) */ 00129 /* The computed eigenvalues. If JOB = 'S', the eigenvalues are */ 00130 /* stored in the same order as on the diagonal of the Schur */ 00131 /* form returned in H, with W(i) = H(i,i). */ 00132 00133 /* Z (input/output) COMPLEX*16 array, dimension (LDZ,N) */ 00134 /* If COMPZ = 'N', Z is not referenced. */ 00135 /* If COMPZ = 'I', on entry Z need not be set and on exit, */ 00136 /* if INFO = 0, Z contains the unitary matrix Z of the Schur */ 00137 /* vectors of H. If COMPZ = 'V', on entry Z must contain an */ 00138 /* N-by-N matrix Q, which is assumed to be equal to the unit */ 00139 /* matrix except for the submatrix Z(ILO:IHI,ILO:IHI). On exit, */ 00140 /* if INFO = 0, Z contains Q*Z. */ 00141 /* Normally Q is the unitary matrix generated by ZUNGHR */ 00142 /* after the call to ZGEHRD which formed the Hessenberg matrix */ 00143 /* H. (The output value of Z when INFO.GT.0 is given under */ 00144 /* the description of INFO below.) */ 00145 00146 /* LDZ (input) INTEGER */ 00147 /* The leading dimension of the array Z. if COMPZ = 'I' or */ 00148 /* COMPZ = 'V', then LDZ.GE.MAX(1,N). Otherwize, LDZ.GE.1. */ 00149 00150 /* WORK (workspace/output) COMPLEX*16 array, dimension (LWORK) */ 00151 /* On exit, if INFO = 0, WORK(1) returns an estimate of */ 00152 /* the optimal value for LWORK. */ 00153 00154 /* LWORK (input) INTEGER */ 00155 /* The dimension of the array WORK. LWORK .GE. max(1,N) */ 00156 /* is sufficient and delivers very good and sometimes */ 00157 /* optimal performance. However, LWORK as large as 11*N */ 00158 /* may be required for optimal performance. A workspace */ 00159 /* query is recommended to determine the optimal workspace */ 00160 /* size. */ 00161 00162 /* If LWORK = -1, then ZHSEQR does a workspace query. */ 00163 /* In this case, ZHSEQR checks the input parameters and */ 00164 /* estimates the optimal workspace size for the given */ 00165 /* values of N, ILO and IHI. The estimate is returned */ 00166 /* in WORK(1). No error message related to LWORK is */ 00167 /* issued by XERBLA. Neither H nor Z are accessed. */ 00168 00169 00170 /* INFO (output) INTEGER */ 00171 /* = 0: successful exit */ 00172 /* .LT. 0: if INFO = -i, the i-th argument had an illegal */ 00173 /* value */ 00174 /* .GT. 0: if INFO = i, ZHSEQR failed to compute all of */ 00175 /* the eigenvalues. Elements 1:ilo-1 and i+1:n of WR */ 00176 /* and WI contain those eigenvalues which have been */ 00177 /* successfully computed. (Failures are rare.) */ 00178 00179 /* If INFO .GT. 0 and JOB = 'E', then on exit, the */ 00180 /* remaining unconverged eigenvalues are the eigen- */ 00181 /* values of the upper Hessenberg matrix rows and */ 00182 /* columns ILO through INFO of the final, output */ 00183 /* value of H. */ 00184 00185 /* If INFO .GT. 0 and JOB = 'S', then on exit */ 00186 00187 /* (*) (initial value of H)*U = U*(final value of H) */ 00188 00189 /* where U is a unitary matrix. The final */ 00190 /* value of H is upper Hessenberg and triangular in */ 00191 /* rows and columns INFO+1 through IHI. */ 00192 00193 /* If INFO .GT. 0 and COMPZ = 'V', then on exit */ 00194 00195 /* (final value of Z) = (initial value of Z)*U */ 00196 00197 /* where U is the unitary matrix in (*) (regard- */ 00198 /* less of the value of JOB.) */ 00199 00200 /* If INFO .GT. 0 and COMPZ = 'I', then on exit */ 00201 /* (final value of Z) = U */ 00202 /* where U is the unitary matrix in (*) (regard- */ 00203 /* less of the value of JOB.) */ 00204 00205 /* If INFO .GT. 0 and COMPZ = 'N', then Z is not */ 00206 /* accessed. */ 00207 00208 /* ================================================================ */ 00209 /* Default values supplied by */ 00210 /* ILAENV(ISPEC,'ZHSEQR',JOB(:1)//COMPZ(:1),N,ILO,IHI,LWORK). */ 00211 /* It is suggested that these defaults be adjusted in order */ 00212 /* to attain best performance in each particular */ 00213 /* computational environment. */ 00214 00215 /* ISPEC=12: The ZLAHQR vs ZLAQR0 crossover point. */ 00216 /* Default: 75. (Must be at least 11.) */ 00217 00218 /* ISPEC=13: Recommended deflation window size. */ 00219 /* This depends on ILO, IHI and NS. NS is the */ 00220 /* number of simultaneous shifts returned */ 00221 /* by ILAENV(ISPEC=15). (See ISPEC=15 below.) */ 00222 /* The default for (IHI-ILO+1).LE.500 is NS. */ 00223 /* The default for (IHI-ILO+1).GT.500 is 3*NS/2. */ 00224 00225 /* ISPEC=14: Nibble crossover point. (See IPARMQ for */ 00226 /* details.) Default: 14% of deflation window */ 00227 /* size. */ 00228 00229 /* ISPEC=15: Number of simultaneous shifts in a multishift */ 00230 /* QR iteration. */ 00231 00232 /* If IHI-ILO+1 is ... */ 00233 00234 /* greater than ...but less ... the */ 00235 /* or equal to ... than default is */ 00236 00237 /* 1 30 NS = 2(+) */ 00238 /* 30 60 NS = 4(+) */ 00239 /* 60 150 NS = 10(+) */ 00240 /* 150 590 NS = ** */ 00241 /* 590 3000 NS = 64 */ 00242 /* 3000 6000 NS = 128 */ 00243 /* 6000 infinity NS = 256 */ 00244 00245 /* (+) By default some or all matrices of this order */ 00246 /* are passed to the implicit double shift routine */ 00247 /* ZLAHQR and this parameter is ignored. See */ 00248 /* ISPEC=12 above and comments in IPARMQ for */ 00249 /* details. */ 00250 00251 /* (**) The asterisks (**) indicate an ad-hoc */ 00252 /* function of N increasing from 10 to 64. */ 00253 00254 /* ISPEC=16: Select structured matrix multiply. */ 00255 /* If the number of simultaneous shifts (specified */ 00256 /* by ISPEC=15) is less than 14, then the default */ 00257 /* for ISPEC=16 is 0. Otherwise the default for */ 00258 /* ISPEC=16 is 2. */ 00259 00260 /* ================================================================ */ 00261 /* Based on contributions by */ 00262 /* Karen Braman and Ralph Byers, Department of Mathematics, */ 00263 /* University of Kansas, USA */ 00264 00265 /* ================================================================ */ 00266 /* References: */ 00267 /* K. Braman, R. Byers and R. Mathias, The Multi-Shift QR */ 00268 /* Algorithm Part I: Maintaining Well Focused Shifts, and Level 3 */ 00269 /* Performance, SIAM Journal of Matrix Analysis, volume 23, pages */ 00270 /* 929--947, 2002. */ 00271 00272 /* K. Braman, R. Byers and R. Mathias, The Multi-Shift QR */ 00273 /* Algorithm Part II: Aggressive Early Deflation, SIAM Journal */ 00274 /* of Matrix Analysis, volume 23, pages 948--973, 2002. */ 00275 00276 /* ================================================================ */ 00277 /* .. Parameters .. */ 00278 00279 /* ==== Matrices of order NTINY or smaller must be processed by */ 00280 /* . ZLAHQR because of insufficient subdiagonal scratch space. */ 00281 /* . (This is a hard limit.) ==== */ 00282 00283 /* ==== NL allocates some local workspace to help small matrices */ 00284 /* . through a rare ZLAHQR failure. NL .GT. NTINY = 11 is */ 00285 /* . required and NL .LE. NMIN = ILAENV(ISPEC=12,...) is recom- */ 00286 /* . mended. (The default value of NMIN is 75.) Using NL = 49 */ 00287 /* . allows up to six simultaneous shifts and a 16-by-16 */ 00288 /* . deflation window. ==== */ 00289 /* .. */ 00290 /* .. Local Arrays .. */ 00291 /* .. */ 00292 /* .. Local Scalars .. */ 00293 /* .. */ 00294 /* .. External Functions .. */ 00295 /* .. */ 00296 /* .. External Subroutines .. */ 00297 /* .. */ 00298 /* .. Intrinsic Functions .. */ 00299 /* .. */ 00300 /* .. Executable Statements .. */ 00301 00302 /* ==== Decode and check the input parameters. ==== */ 00303 00304 /* Parameter adjustments */ 00305 h_dim1 = *ldh; 00306 h_offset = 1 + h_dim1; 00307 h__ -= h_offset; 00308 --w; 00309 z_dim1 = *ldz; 00310 z_offset = 1 + z_dim1; 00311 z__ -= z_offset; 00312 --work; 00313 00314 /* Function Body */ 00315 wantt = lsame_(job, "S"); 00316 initz = lsame_(compz, "I"); 00317 wantz = initz || lsame_(compz, "V"); 00318 d__1 = (doublereal) max(1,*n); 00319 z__1.r = d__1, z__1.i = 0.; 00320 work[1].r = z__1.r, work[1].i = z__1.i; 00321 lquery = *lwork == -1; 00322 00323 *info = 0; 00324 if (! lsame_(job, "E") && ! wantt) { 00325 *info = -1; 00326 } else if (! lsame_(compz, "N") && ! wantz) { 00327 *info = -2; 00328 } else if (*n < 0) { 00329 *info = -3; 00330 } else if (*ilo < 1 || *ilo > max(1,*n)) { 00331 *info = -4; 00332 } else if (*ihi < min(*ilo,*n) || *ihi > *n) { 00333 *info = -5; 00334 } else if (*ldh < max(1,*n)) { 00335 *info = -7; 00336 } else if (*ldz < 1 || wantz && *ldz < max(1,*n)) { 00337 *info = -10; 00338 } else if (*lwork < max(1,*n) && ! lquery) { 00339 *info = -12; 00340 } 00341 00342 if (*info != 0) { 00343 00344 /* ==== Quick return in case of invalid argument. ==== */ 00345 00346 i__1 = -(*info); 00347 xerbla_("ZHSEQR", &i__1); 00348 return 0; 00349 00350 } else if (*n == 0) { 00351 00352 /* ==== Quick return in case N = 0; nothing to do. ==== */ 00353 00354 return 0; 00355 00356 } else if (lquery) { 00357 00358 /* ==== Quick return in case of a workspace query ==== */ 00359 00360 zlaqr0_(&wantt, &wantz, n, ilo, ihi, &h__[h_offset], ldh, &w[1], ilo, 00361 ihi, &z__[z_offset], ldz, &work[1], lwork, info); 00362 /* ==== Ensure reported workspace size is backward-compatible with */ 00363 /* . previous LAPACK versions. ==== */ 00364 /* Computing MAX */ 00365 d__2 = work[1].r, d__3 = (doublereal) max(1,*n); 00366 d__1 = max(d__2,d__3); 00367 z__1.r = d__1, z__1.i = 0.; 00368 work[1].r = z__1.r, work[1].i = z__1.i; 00369 return 0; 00370 00371 } else { 00372 00373 /* ==== copy eigenvalues isolated by ZGEBAL ==== */ 00374 00375 if (*ilo > 1) { 00376 i__1 = *ilo - 1; 00377 i__2 = *ldh + 1; 00378 zcopy_(&i__1, &h__[h_offset], &i__2, &w[1], &c__1); 00379 } 00380 if (*ihi < *n) { 00381 i__1 = *n - *ihi; 00382 i__2 = *ldh + 1; 00383 zcopy_(&i__1, &h__[*ihi + 1 + (*ihi + 1) * h_dim1], &i__2, &w[* 00384 ihi + 1], &c__1); 00385 } 00386 00387 /* ==== Initialize Z, if requested ==== */ 00388 00389 if (initz) { 00390 zlaset_("A", n, n, &c_b1, &c_b2, &z__[z_offset], ldz); 00391 } 00392 00393 /* ==== Quick return if possible ==== */ 00394 00395 if (*ilo == *ihi) { 00396 i__1 = *ilo; 00397 i__2 = *ilo + *ilo * h_dim1; 00398 w[i__1].r = h__[i__2].r, w[i__1].i = h__[i__2].i; 00399 return 0; 00400 } 00401 00402 /* ==== ZLAHQR/ZLAQR0 crossover point ==== */ 00403 00404 /* Writing concatenation */ 00405 i__3[0] = 1, a__1[0] = job; 00406 i__3[1] = 1, a__1[1] = compz; 00407 s_cat(ch__1, a__1, i__3, &c__2, (ftnlen)2); 00408 nmin = ilaenv_(&c__12, "ZHSEQR", ch__1, n, ilo, ihi, lwork); 00409 nmin = max(11,nmin); 00410 00411 /* ==== ZLAQR0 for big matrices; ZLAHQR for small ones ==== */ 00412 00413 if (*n > nmin) { 00414 zlaqr0_(&wantt, &wantz, n, ilo, ihi, &h__[h_offset], ldh, &w[1], 00415 ilo, ihi, &z__[z_offset], ldz, &work[1], lwork, info); 00416 } else { 00417 00418 /* ==== Small matrix ==== */ 00419 00420 zlahqr_(&wantt, &wantz, n, ilo, ihi, &h__[h_offset], ldh, &w[1], 00421 ilo, ihi, &z__[z_offset], ldz, info); 00422 00423 if (*info > 0) { 00424 00425 /* ==== A rare ZLAHQR failure! ZLAQR0 sometimes succeeds */ 00426 /* . when ZLAHQR fails. ==== */ 00427 00428 kbot = *info; 00429 00430 if (*n >= 49) { 00431 00432 /* ==== Larger matrices have enough subdiagonal scratch */ 00433 /* . space to call ZLAQR0 directly. ==== */ 00434 00435 zlaqr0_(&wantt, &wantz, n, ilo, &kbot, &h__[h_offset], 00436 ldh, &w[1], ilo, ihi, &z__[z_offset], ldz, &work[ 00437 1], lwork, info); 00438 00439 } else { 00440 00441 /* ==== Tiny matrices don't have enough subdiagonal */ 00442 /* . scratch space to benefit from ZLAQR0. Hence, */ 00443 /* . tiny matrices must be copied into a larger */ 00444 /* . array before calling ZLAQR0. ==== */ 00445 00446 zlacpy_("A", n, n, &h__[h_offset], ldh, hl, &c__49); 00447 i__1 = *n + 1 + *n * 49 - 50; 00448 hl[i__1].r = 0., hl[i__1].i = 0.; 00449 i__1 = 49 - *n; 00450 zlaset_("A", &c__49, &i__1, &c_b1, &c_b1, &hl[(*n + 1) * 00451 49 - 49], &c__49); 00452 zlaqr0_(&wantt, &wantz, &c__49, ilo, &kbot, hl, &c__49, & 00453 w[1], ilo, ihi, &z__[z_offset], ldz, workl, & 00454 c__49, info); 00455 if (wantt || *info != 0) { 00456 zlacpy_("A", n, n, hl, &c__49, &h__[h_offset], ldh); 00457 } 00458 } 00459 } 00460 } 00461 00462 /* ==== Clear out the trash, if necessary. ==== */ 00463 00464 if ((wantt || *info != 0) && *n > 2) { 00465 i__1 = *n - 2; 00466 i__2 = *n - 2; 00467 zlaset_("L", &i__1, &i__2, &c_b1, &c_b1, &h__[h_dim1 + 3], ldh); 00468 } 00469 00470 /* ==== Ensure reported workspace size is backward-compatible with */ 00471 /* . previous LAPACK versions. ==== */ 00472 00473 /* Computing MAX */ 00474 d__2 = (doublereal) max(1,*n), d__3 = work[1].r; 00475 d__1 = max(d__2,d__3); 00476 z__1.r = d__1, z__1.i = 0.; 00477 work[1].r = z__1.r, work[1].i = z__1.i; 00478 } 00479 00480 /* ==== End of ZHSEQR ==== */ 00481 00482 return 0; 00483 } /* zhseqr_ */