00001 /* sstevr.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__10 = 10; 00019 static integer c__1 = 1; 00020 static integer c__2 = 2; 00021 static integer c__3 = 3; 00022 static integer c__4 = 4; 00023 00024 /* Subroutine */ int sstevr_(char *jobz, char *range, integer *n, real *d__, 00025 real *e, real *vl, real *vu, integer *il, integer *iu, real *abstol, 00026 integer *m, real *w, real *z__, integer *ldz, integer *isuppz, real * 00027 work, integer *lwork, integer *iwork, integer *liwork, integer *info) 00028 { 00029 /* System generated locals */ 00030 integer z_dim1, z_offset, i__1, i__2; 00031 real r__1, r__2; 00032 00033 /* Builtin functions */ 00034 double sqrt(doublereal); 00035 00036 /* Local variables */ 00037 integer i__, j, jj; 00038 real eps, vll, vuu, tmp1; 00039 integer imax; 00040 real rmin, rmax; 00041 logical test; 00042 real tnrm, sigma; 00043 extern logical lsame_(char *, char *); 00044 extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *); 00045 char order[1]; 00046 integer lwmin; 00047 extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, 00048 integer *), sswap_(integer *, real *, integer *, real *, integer * 00049 ); 00050 logical wantz, alleig, indeig; 00051 integer iscale, ieeeok, indibl, indifl; 00052 logical valeig; 00053 extern doublereal slamch_(char *); 00054 real safmin; 00055 extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 00056 integer *, integer *); 00057 extern /* Subroutine */ int xerbla_(char *, integer *); 00058 real bignum; 00059 integer indisp, indiwo, liwmin; 00060 logical tryrac; 00061 extern doublereal slanst_(char *, integer *, real *, real *); 00062 extern /* Subroutine */ int sstein_(integer *, real *, real *, integer *, 00063 real *, integer *, integer *, real *, integer *, real *, integer * 00064 , integer *, integer *), ssterf_(integer *, real *, real *, 00065 integer *); 00066 integer nsplit; 00067 extern /* Subroutine */ int sstebz_(char *, char *, integer *, real *, 00068 real *, integer *, integer *, real *, real *, real *, integer *, 00069 integer *, real *, integer *, integer *, real *, integer *, 00070 integer *); 00071 real smlnum; 00072 extern /* Subroutine */ int sstemr_(char *, char *, integer *, real *, 00073 real *, real *, real *, integer *, integer *, integer *, real *, 00074 real *, integer *, integer *, integer *, logical *, real *, 00075 integer *, integer *, integer *, integer *); 00076 logical lquery; 00077 00078 00079 /* -- LAPACK driver routine (version 3.2) -- */ 00080 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ 00081 /* November 2006 */ 00082 00083 /* .. Scalar Arguments .. */ 00084 /* .. */ 00085 /* .. Array Arguments .. */ 00086 /* .. */ 00087 00088 /* Purpose */ 00089 /* ======= */ 00090 00091 /* SSTEVR computes selected eigenvalues and, optionally, eigenvectors */ 00092 /* of a real symmetric tridiagonal matrix T. Eigenvalues and */ 00093 /* eigenvectors can be selected by specifying either a range of values */ 00094 /* or a range of indices for the desired eigenvalues. */ 00095 00096 /* Whenever possible, SSTEVR calls SSTEMR to compute the */ 00097 /* eigenspectrum using Relatively Robust Representations. SSTEMR */ 00098 /* computes eigenvalues by the dqds algorithm, while orthogonal */ 00099 /* eigenvectors are computed from various "good" L D L^T representations */ 00100 /* (also known as Relatively Robust Representations). Gram-Schmidt */ 00101 /* orthogonalization is avoided as far as possible. More specifically, */ 00102 /* the various steps of the algorithm are as follows. For the i-th */ 00103 /* unreduced block of T, */ 00104 /* (a) Compute T - sigma_i = L_i D_i L_i^T, such that L_i D_i L_i^T */ 00105 /* is a relatively robust representation, */ 00106 /* (b) Compute the eigenvalues, lambda_j, of L_i D_i L_i^T to high */ 00107 /* relative accuracy by the dqds algorithm, */ 00108 /* (c) If there is a cluster of close eigenvalues, "choose" sigma_i */ 00109 /* close to the cluster, and go to step (a), */ 00110 /* (d) Given the approximate eigenvalue lambda_j of L_i D_i L_i^T, */ 00111 /* compute the corresponding eigenvector by forming a */ 00112 /* rank-revealing twisted factorization. */ 00113 /* The desired accuracy of the output can be specified by the input */ 00114 /* parameter ABSTOL. */ 00115 00116 /* For more details, see "A new O(n^2) algorithm for the symmetric */ 00117 /* tridiagonal eigenvalue/eigenvector problem", by Inderjit Dhillon, */ 00118 /* Computer Science Division Technical Report No. UCB//CSD-97-971, */ 00119 /* UC Berkeley, May 1997. */ 00120 00121 00122 /* Note 1 : SSTEVR calls SSTEMR when the full spectrum is requested */ 00123 /* on machines which conform to the ieee-754 floating point standard. */ 00124 /* SSTEVR calls SSTEBZ and SSTEIN on non-ieee machines and */ 00125 /* when partial spectrum requests are made. */ 00126 00127 /* Normal execution of SSTEMR may create NaNs and infinities and */ 00128 /* hence may abort due to a floating point exception in environments */ 00129 /* which do not handle NaNs and infinities in the ieee standard default */ 00130 /* manner. */ 00131 00132 /* Arguments */ 00133 /* ========= */ 00134 00135 /* JOBZ (input) CHARACTER*1 */ 00136 /* = 'N': Compute eigenvalues only; */ 00137 /* = 'V': Compute eigenvalues and eigenvectors. */ 00138 00139 /* RANGE (input) CHARACTER*1 */ 00140 /* = 'A': all eigenvalues will be found. */ 00141 /* = 'V': all eigenvalues in the half-open interval (VL,VU] */ 00142 /* will be found. */ 00143 /* = 'I': the IL-th through IU-th eigenvalues will be found. */ 00144 /* ********* For RANGE = 'V' or 'I' and IU - IL < N - 1, SSTEBZ and */ 00145 /* ********* SSTEIN are called */ 00146 00147 /* N (input) INTEGER */ 00148 /* The order of the matrix. N >= 0. */ 00149 00150 /* D (input/output) REAL array, dimension (N) */ 00151 /* On entry, the n diagonal elements of the tridiagonal matrix */ 00152 /* A. */ 00153 /* On exit, D may be multiplied by a constant factor chosen */ 00154 /* to avoid over/underflow in computing the eigenvalues. */ 00155 00156 /* E (input/output) REAL array, dimension (max(1,N-1)) */ 00157 /* On entry, the (n-1) subdiagonal elements of the tridiagonal */ 00158 /* matrix A in elements 1 to N-1 of E. */ 00159 /* On exit, E may be multiplied by a constant factor chosen */ 00160 /* to avoid over/underflow in computing the eigenvalues. */ 00161 00162 /* VL (input) REAL */ 00163 /* VU (input) REAL */ 00164 /* If RANGE='V', the lower and upper bounds of the interval to */ 00165 /* be searched for eigenvalues. VL < VU. */ 00166 /* Not referenced if RANGE = 'A' or 'I'. */ 00167 00168 /* IL (input) INTEGER */ 00169 /* IU (input) INTEGER */ 00170 /* If RANGE='I', the indices (in ascending order) of the */ 00171 /* smallest and largest eigenvalues to be returned. */ 00172 /* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */ 00173 /* Not referenced if RANGE = 'A' or 'V'. */ 00174 00175 /* ABSTOL (input) REAL */ 00176 /* The absolute error tolerance for the eigenvalues. */ 00177 /* An approximate eigenvalue is accepted as converged */ 00178 /* when it is determined to lie in an interval [a,b] */ 00179 /* of width less than or equal to */ 00180 00181 /* ABSTOL + EPS * max( |a|,|b| ) , */ 00182 00183 /* where EPS is the machine precision. If ABSTOL is less than */ 00184 /* or equal to zero, then EPS*|T| will be used in its place, */ 00185 /* where |T| is the 1-norm of the tridiagonal matrix obtained */ 00186 /* by reducing A to tridiagonal form. */ 00187 00188 /* See "Computing Small Singular Values of Bidiagonal Matrices */ 00189 /* with Guaranteed High Relative Accuracy," by Demmel and */ 00190 /* Kahan, LAPACK Working Note #3. */ 00191 00192 /* If high relative accuracy is important, set ABSTOL to */ 00193 /* SLAMCH( 'Safe minimum' ). Doing so will guarantee that */ 00194 /* eigenvalues are computed to high relative accuracy when */ 00195 /* possible in future releases. The current code does not */ 00196 /* make any guarantees about high relative accuracy, but */ 00197 /* future releases will. See J. Barlow and J. Demmel, */ 00198 /* "Computing Accurate Eigensystems of Scaled Diagonally */ 00199 /* Dominant Matrices", LAPACK Working Note #7, for a discussion */ 00200 /* of which matrices define their eigenvalues to high relative */ 00201 /* accuracy. */ 00202 00203 /* M (output) INTEGER */ 00204 /* The total number of eigenvalues found. 0 <= M <= N. */ 00205 /* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */ 00206 00207 /* W (output) REAL array, dimension (N) */ 00208 /* The first M elements contain the selected eigenvalues in */ 00209 /* ascending order. */ 00210 00211 /* Z (output) REAL array, dimension (LDZ, max(1,M) ) */ 00212 /* If JOBZ = 'V', then if INFO = 0, the first M columns of Z */ 00213 /* contain the orthonormal eigenvectors of the matrix A */ 00214 /* corresponding to the selected eigenvalues, with the i-th */ 00215 /* column of Z holding the eigenvector associated with W(i). */ 00216 /* Note: the user must ensure that at least max(1,M) columns are */ 00217 /* supplied in the array Z; if RANGE = 'V', the exact value of M */ 00218 /* is not known in advance and an upper bound must be used. */ 00219 00220 /* LDZ (input) INTEGER */ 00221 /* The leading dimension of the array Z. LDZ >= 1, and if */ 00222 /* JOBZ = 'V', LDZ >= max(1,N). */ 00223 00224 /* ISUPPZ (output) INTEGER array, dimension ( 2*max(1,M) ) */ 00225 /* The support of the eigenvectors in Z, i.e., the indices */ 00226 /* indicating the nonzero elements in Z. The i-th eigenvector */ 00227 /* is nonzero only in elements ISUPPZ( 2*i-1 ) through */ 00228 /* ISUPPZ( 2*i ). */ 00229 /* ********* Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1 */ 00230 00231 /* WORK (workspace/output) REAL array, dimension (MAX(1,LWORK)) */ 00232 /* On exit, if INFO = 0, WORK(1) returns the optimal (and */ 00233 /* minimal) LWORK. */ 00234 00235 /* LWORK (input) INTEGER */ 00236 /* The dimension of the array WORK. LWORK >= 20*N. */ 00237 00238 /* If LWORK = -1, then a workspace query is assumed; the routine */ 00239 /* only calculates the optimal sizes of the WORK and IWORK */ 00240 /* arrays, returns these values as the first entries of the WORK */ 00241 /* and IWORK arrays, and no error message related to LWORK or */ 00242 /* LIWORK is issued by XERBLA. */ 00243 00244 /* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */ 00245 /* On exit, if INFO = 0, IWORK(1) returns the optimal (and */ 00246 /* minimal) LIWORK. */ 00247 00248 /* LIWORK (input) INTEGER */ 00249 /* The dimension of the array IWORK. LIWORK >= 10*N. */ 00250 00251 /* If LIWORK = -1, then a workspace query is assumed; the */ 00252 /* routine only calculates the optimal sizes of the WORK and */ 00253 /* IWORK arrays, returns these values as the first entries of */ 00254 /* the WORK and IWORK arrays, and no error message related to */ 00255 /* LWORK or LIWORK is issued by XERBLA. */ 00256 00257 /* INFO (output) INTEGER */ 00258 /* = 0: successful exit */ 00259 /* < 0: if INFO = -i, the i-th argument had an illegal value */ 00260 /* > 0: Internal error */ 00261 00262 /* Further Details */ 00263 /* =============== */ 00264 00265 /* Based on contributions by */ 00266 /* Inderjit Dhillon, IBM Almaden, USA */ 00267 /* Osni Marques, LBNL/NERSC, USA */ 00268 /* Ken Stanley, Computer Science Division, University of */ 00269 /* California at Berkeley, USA */ 00270 /* Jason Riedy, Computer Science Division, University of */ 00271 /* California at Berkeley, USA */ 00272 00273 /* ===================================================================== */ 00274 00275 /* .. Parameters .. */ 00276 /* .. */ 00277 /* .. Local Scalars .. */ 00278 /* .. */ 00279 /* .. External Functions .. */ 00280 /* .. */ 00281 /* .. External Subroutines .. */ 00282 /* .. */ 00283 /* .. Intrinsic Functions .. */ 00284 /* .. */ 00285 /* .. Executable Statements .. */ 00286 00287 00288 /* Test the input parameters. */ 00289 00290 /* Parameter adjustments */ 00291 --d__; 00292 --e; 00293 --w; 00294 z_dim1 = *ldz; 00295 z_offset = 1 + z_dim1; 00296 z__ -= z_offset; 00297 --isuppz; 00298 --work; 00299 --iwork; 00300 00301 /* Function Body */ 00302 ieeeok = ilaenv_(&c__10, "SSTEVR", "N", &c__1, &c__2, &c__3, &c__4); 00303 00304 wantz = lsame_(jobz, "V"); 00305 alleig = lsame_(range, "A"); 00306 valeig = lsame_(range, "V"); 00307 indeig = lsame_(range, "I"); 00308 00309 lquery = *lwork == -1 || *liwork == -1; 00310 /* Computing MAX */ 00311 i__1 = 1, i__2 = *n * 20; 00312 lwmin = max(i__1,i__2); 00313 /* Computing MAX */ 00314 i__1 = 1, i__2 = *n * 10; 00315 liwmin = max(i__1,i__2); 00316 00317 00318 *info = 0; 00319 if (! (wantz || lsame_(jobz, "N"))) { 00320 *info = -1; 00321 } else if (! (alleig || valeig || indeig)) { 00322 *info = -2; 00323 } else if (*n < 0) { 00324 *info = -3; 00325 } else { 00326 if (valeig) { 00327 if (*n > 0 && *vu <= *vl) { 00328 *info = -7; 00329 } 00330 } else if (indeig) { 00331 if (*il < 1 || *il > max(1,*n)) { 00332 *info = -8; 00333 } else if (*iu < min(*n,*il) || *iu > *n) { 00334 *info = -9; 00335 } 00336 } 00337 } 00338 if (*info == 0) { 00339 if (*ldz < 1 || wantz && *ldz < *n) { 00340 *info = -14; 00341 } 00342 } 00343 00344 if (*info == 0) { 00345 work[1] = (real) lwmin; 00346 iwork[1] = liwmin; 00347 00348 if (*lwork < lwmin && ! lquery) { 00349 *info = -17; 00350 } else if (*liwork < liwmin && ! lquery) { 00351 *info = -19; 00352 } 00353 } 00354 00355 if (*info != 0) { 00356 i__1 = -(*info); 00357 xerbla_("SSTEVR", &i__1); 00358 return 0; 00359 } else if (lquery) { 00360 return 0; 00361 } 00362 00363 /* Quick return if possible */ 00364 00365 *m = 0; 00366 if (*n == 0) { 00367 return 0; 00368 } 00369 00370 if (*n == 1) { 00371 if (alleig || indeig) { 00372 *m = 1; 00373 w[1] = d__[1]; 00374 } else { 00375 if (*vl < d__[1] && *vu >= d__[1]) { 00376 *m = 1; 00377 w[1] = d__[1]; 00378 } 00379 } 00380 if (wantz) { 00381 z__[z_dim1 + 1] = 1.f; 00382 } 00383 return 0; 00384 } 00385 00386 /* Get machine constants. */ 00387 00388 safmin = slamch_("Safe minimum"); 00389 eps = slamch_("Precision"); 00390 smlnum = safmin / eps; 00391 bignum = 1.f / smlnum; 00392 rmin = sqrt(smlnum); 00393 /* Computing MIN */ 00394 r__1 = sqrt(bignum), r__2 = 1.f / sqrt(sqrt(safmin)); 00395 rmax = dmin(r__1,r__2); 00396 00397 00398 /* Scale matrix to allowable range, if necessary. */ 00399 00400 iscale = 0; 00401 vll = *vl; 00402 vuu = *vu; 00403 00404 tnrm = slanst_("M", n, &d__[1], &e[1]); 00405 if (tnrm > 0.f && tnrm < rmin) { 00406 iscale = 1; 00407 sigma = rmin / tnrm; 00408 } else if (tnrm > rmax) { 00409 iscale = 1; 00410 sigma = rmax / tnrm; 00411 } 00412 if (iscale == 1) { 00413 sscal_(n, &sigma, &d__[1], &c__1); 00414 i__1 = *n - 1; 00415 sscal_(&i__1, &sigma, &e[1], &c__1); 00416 if (valeig) { 00417 vll = *vl * sigma; 00418 vuu = *vu * sigma; 00419 } 00420 } 00421 /* Initialize indices into workspaces. Note: These indices are used only */ 00422 /* if SSTERF or SSTEMR fail. */ 00423 /* IWORK(INDIBL:INDIBL+M-1) corresponds to IBLOCK in SSTEBZ and */ 00424 /* stores the block indices of each of the M<=N eigenvalues. */ 00425 indibl = 1; 00426 /* IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in SSTEBZ and */ 00427 /* stores the starting and finishing indices of each block. */ 00428 indisp = indibl + *n; 00429 /* IWORK(INDIFL:INDIFL+N-1) stores the indices of eigenvectors */ 00430 /* that corresponding to eigenvectors that fail to converge in */ 00431 /* SSTEIN. This information is discarded; if any fail, the driver */ 00432 /* returns INFO > 0. */ 00433 indifl = indisp + *n; 00434 /* INDIWO is the offset of the remaining integer workspace. */ 00435 indiwo = indisp + *n; 00436 00437 /* If all eigenvalues are desired, then */ 00438 /* call SSTERF or SSTEMR. If this fails for some eigenvalue, then */ 00439 /* try SSTEBZ. */ 00440 00441 00442 test = FALSE_; 00443 if (indeig) { 00444 if (*il == 1 && *iu == *n) { 00445 test = TRUE_; 00446 } 00447 } 00448 if ((alleig || test) && ieeeok == 1) { 00449 i__1 = *n - 1; 00450 scopy_(&i__1, &e[1], &c__1, &work[1], &c__1); 00451 if (! wantz) { 00452 scopy_(n, &d__[1], &c__1, &w[1], &c__1); 00453 ssterf_(n, &w[1], &work[1], info); 00454 } else { 00455 scopy_(n, &d__[1], &c__1, &work[*n + 1], &c__1); 00456 if (*abstol <= *n * 2.f * eps) { 00457 tryrac = TRUE_; 00458 } else { 00459 tryrac = FALSE_; 00460 } 00461 i__1 = *lwork - (*n << 1); 00462 sstemr_(jobz, "A", n, &work[*n + 1], &work[1], vl, vu, il, iu, m, 00463 &w[1], &z__[z_offset], ldz, n, &isuppz[1], &tryrac, &work[ 00464 (*n << 1) + 1], &i__1, &iwork[1], liwork, info); 00465 00466 } 00467 if (*info == 0) { 00468 *m = *n; 00469 goto L10; 00470 } 00471 *info = 0; 00472 } 00473 00474 /* Otherwise, call SSTEBZ and, if eigenvectors are desired, SSTEIN. */ 00475 00476 if (wantz) { 00477 *(unsigned char *)order = 'B'; 00478 } else { 00479 *(unsigned char *)order = 'E'; 00480 } 00481 sstebz_(range, order, n, &vll, &vuu, il, iu, abstol, &d__[1], &e[1], m, & 00482 nsplit, &w[1], &iwork[indibl], &iwork[indisp], &work[1], &iwork[ 00483 indiwo], info); 00484 00485 if (wantz) { 00486 sstein_(n, &d__[1], &e[1], m, &w[1], &iwork[indibl], &iwork[indisp], & 00487 z__[z_offset], ldz, &work[1], &iwork[indiwo], &iwork[indifl], 00488 info); 00489 } 00490 00491 /* If matrix was scaled, then rescale eigenvalues appropriately. */ 00492 00493 L10: 00494 if (iscale == 1) { 00495 if (*info == 0) { 00496 imax = *m; 00497 } else { 00498 imax = *info - 1; 00499 } 00500 r__1 = 1.f / sigma; 00501 sscal_(&imax, &r__1, &w[1], &c__1); 00502 } 00503 00504 /* If eigenvalues are not in order, then sort them, along with */ 00505 /* eigenvectors. */ 00506 00507 if (wantz) { 00508 i__1 = *m - 1; 00509 for (j = 1; j <= i__1; ++j) { 00510 i__ = 0; 00511 tmp1 = w[j]; 00512 i__2 = *m; 00513 for (jj = j + 1; jj <= i__2; ++jj) { 00514 if (w[jj] < tmp1) { 00515 i__ = jj; 00516 tmp1 = w[jj]; 00517 } 00518 /* L20: */ 00519 } 00520 00521 if (i__ != 0) { 00522 w[i__] = w[j]; 00523 w[j] = tmp1; 00524 sswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1], 00525 &c__1); 00526 } 00527 /* L30: */ 00528 } 00529 } 00530 00531 /* Causes problems with tests 19 & 20: */ 00532 /* IF (wantz .and. INDEIG ) Z( 1,1) = Z(1,1) / 1.002 + .002 */ 00533 00534 00535 work[1] = (real) lwmin; 00536 iwork[1] = liwmin; 00537 return 0; 00538 00539 /* End of SSTEVR */ 00540 00541 } /* sstevr_ */