3 /* Table of constant values */
5 static integer c__10 = 10;
6 static integer c__1 = 1;
7 static integer c__2 = 2;
8 static integer c__3 = 3;
9 static integer c__4 = 4;
10 static integer c_n1 = -1;
12 /* Subroutine */ int ssyevr_(char *jobz, char *range, char *uplo, integer *n,
13 real *a, integer *lda, real *vl, real *vu, integer *il, integer *iu,
14 real *abstol, integer *m, real *w, real *z__, integer *ldz, integer *
15 isuppz, real *work, integer *lwork, integer *iwork, integer *liwork,
18 /* System generated locals */
19 integer a_dim1, a_offset, z_dim1, z_offset, i__1, i__2;
22 /* Builtin functions */
23 double sqrt(doublereal);
26 integer i__, j, nb, jj;
27 real eps, vll, vuu, tmp1;
35 extern logical lsame_(char *, char *);
37 extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
41 extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *,
42 integer *), sswap_(integer *, real *, integer *, real *, integer *
44 logical wantz, alleig, indeig;
45 integer iscale, ieeeok, indibl, indifl;
47 extern doublereal slamch_(char *);
49 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
50 integer *, integer *);
51 extern /* Subroutine */ int xerbla_(char *, integer *);
53 integer indtau, indisp, indiwo, indwkn, liwmin;
55 extern /* Subroutine */ int sstein_(integer *, real *, real *, integer *,
56 real *, integer *, integer *, real *, integer *, real *, integer *
57 , integer *, integer *), ssterf_(integer *, real *, real *,
59 integer llwrkn, llwork, nsplit;
61 extern doublereal slansy_(char *, char *, integer *, real *, integer *,
63 extern /* Subroutine */ int sstebz_(char *, char *, integer *, real *,
64 real *, integer *, integer *, real *, real *, real *, integer *,
65 integer *, real *, integer *, integer *, real *, integer *,
66 integer *), sstemr_(char *, char *, integer *,
67 real *, real *, real *, real *, integer *, integer *, integer *,
68 real *, real *, integer *, integer *, integer *, logical *, real *
69 , integer *, integer *, integer *, integer *);
72 extern /* Subroutine */ int sormtr_(char *, char *, char *, integer *,
73 integer *, real *, integer *, real *, real *, integer *, real *,
74 integer *, integer *), ssytrd_(char *,
75 integer *, real *, integer *, real *, real *, real *, real *,
76 integer *, integer *);
79 /* -- LAPACK driver routine (version 3.1) -- */
80 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
83 /* .. Scalar Arguments .. */
85 /* .. Array Arguments .. */
91 /* SSYEVR computes selected eigenvalues and, optionally, eigenvectors */
92 /* of a real symmetric matrix A. Eigenvalues and eigenvectors can be */
93 /* selected by specifying either a range of values or a range of */
94 /* indices for the desired eigenvalues. */
96 /* SSYEVR first reduces the matrix A to tridiagonal form T with a call */
97 /* to SSYTRD. Then, whenever possible, SSYEVR calls SSTEMR to compute */
98 /* the eigenspectrum using Relatively Robust Representations. SSTEMR */
99 /* computes eigenvalues by the dqds algorithm, while orthogonal */
100 /* eigenvectors are computed from various "good" L D L^T representations */
101 /* (also known as Relatively Robust Representations). Gram-Schmidt */
102 /* orthogonalization is avoided as far as possible. More specifically, */
103 /* the various steps of the algorithm are as follows. */
105 /* For each unreduced block (submatrix) of T, */
106 /* (a) Compute T - sigma I = L D L^T, so that L and D */
107 /* define all the wanted eigenvalues to high relative accuracy. */
108 /* This means that small relative changes in the entries of D and L */
109 /* cause only small relative changes in the eigenvalues and */
110 /* eigenvectors. The standard (unfactored) representation of the */
111 /* tridiagonal matrix T does not have this property in general. */
112 /* (b) Compute the eigenvalues to suitable accuracy. */
113 /* If the eigenvectors are desired, the algorithm attains full */
114 /* accuracy of the computed eigenvalues only right before */
115 /* the corresponding vectors have to be computed, see steps c) and d). */
116 /* (c) For each cluster of close eigenvalues, select a new */
117 /* shift close to the cluster, find a new factorization, and refine */
118 /* the shifted eigenvalues to suitable accuracy. */
119 /* (d) For each eigenvalue with a large enough relative separation compute */
120 /* the corresponding eigenvector by forming a rank revealing twisted */
121 /* factorization. Go back to (c) for any clusters that remain. */
123 /* The desired accuracy of the output can be specified by the input */
124 /* parameter ABSTOL. */
126 /* For more details, see SSTEMR's documentation and: */
127 /* - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations */
128 /* to compute orthogonal eigenvectors of symmetric tridiagonal matrices," */
129 /* Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004. */
130 /* - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and */
131 /* Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25, */
132 /* 2004. Also LAPACK Working Note 154. */
133 /* - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric */
134 /* tridiagonal eigenvalue/eigenvector problem", */
135 /* Computer Science Division Technical Report No. UCB/CSD-97-971, */
136 /* UC Berkeley, May 1997. */
139 /* Note 1 : SSYEVR calls SSTEMR when the full spectrum is requested */
140 /* on machines which conform to the ieee-754 floating point standard. */
141 /* SSYEVR calls SSTEBZ and SSTEIN on non-ieee machines and */
142 /* when partial spectrum requests are made. */
144 /* Normal execution of SSTEMR may create NaNs and infinities and */
145 /* hence may abort due to a floating point exception in environments */
146 /* which do not handle NaNs and infinities in the ieee standard default */
152 /* JOBZ (input) CHARACTER*1 */
153 /* = 'N': Compute eigenvalues only; */
154 /* = 'V': Compute eigenvalues and eigenvectors. */
156 /* RANGE (input) CHARACTER*1 */
157 /* = 'A': all eigenvalues will be found. */
158 /* = 'V': all eigenvalues in the half-open interval (VL,VU] */
160 /* = 'I': the IL-th through IU-th eigenvalues will be found. */
161 /* ********* For RANGE = 'V' or 'I' and IU - IL < N - 1, SSTEBZ and */
162 /* ********* SSTEIN are called */
164 /* UPLO (input) CHARACTER*1 */
165 /* = 'U': Upper triangle of A is stored; */
166 /* = 'L': Lower triangle of A is stored. */
168 /* N (input) INTEGER */
169 /* The order of the matrix A. N >= 0. */
171 /* A (input/output) REAL array, dimension (LDA, N) */
172 /* On entry, the symmetric matrix A. If UPLO = 'U', the */
173 /* leading N-by-N upper triangular part of A contains the */
174 /* upper triangular part of the matrix A. If UPLO = 'L', */
175 /* the leading N-by-N lower triangular part of A contains */
176 /* the lower triangular part of the matrix A. */
177 /* On exit, the lower triangle (if UPLO='L') or the upper */
178 /* triangle (if UPLO='U') of A, including the diagonal, is */
181 /* LDA (input) INTEGER */
182 /* The leading dimension of the array A. LDA >= max(1,N). */
184 /* VL (input) REAL */
185 /* VU (input) REAL */
186 /* If RANGE='V', the lower and upper bounds of the interval to */
187 /* be searched for eigenvalues. VL < VU. */
188 /* Not referenced if RANGE = 'A' or 'I'. */
190 /* IL (input) INTEGER */
191 /* IU (input) INTEGER */
192 /* If RANGE='I', the indices (in ascending order) of the */
193 /* smallest and largest eigenvalues to be returned. */
194 /* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
195 /* Not referenced if RANGE = 'A' or 'V'. */
197 /* ABSTOL (input) REAL */
198 /* The absolute error tolerance for the eigenvalues. */
199 /* An approximate eigenvalue is accepted as converged */
200 /* when it is determined to lie in an interval [a,b] */
201 /* of width less than or equal to */
203 /* ABSTOL + EPS * max( |a|,|b| ) , */
205 /* where EPS is the machine precision. If ABSTOL is less than */
206 /* or equal to zero, then EPS*|T| will be used in its place, */
207 /* where |T| is the 1-norm of the tridiagonal matrix obtained */
208 /* by reducing A to tridiagonal form. */
210 /* See "Computing Small Singular Values of Bidiagonal Matrices */
211 /* with Guaranteed High Relative Accuracy," by Demmel and */
212 /* Kahan, LAPACK Working Note #3. */
214 /* If high relative accuracy is important, set ABSTOL to */
215 /* SLAMCH( 'Safe minimum' ). Doing so will guarantee that */
216 /* eigenvalues are computed to high relative accuracy when */
217 /* possible in future releases. The current code does not */
218 /* make any guarantees about high relative accuracy, but */
219 /* future releases will. See J. Barlow and J. Demmel, */
220 /* "Computing Accurate Eigensystems of Scaled Diagonally */
221 /* Dominant Matrices", LAPACK Working Note #7, for a discussion */
222 /* of which matrices define their eigenvalues to high relative */
225 /* M (output) INTEGER */
226 /* The total number of eigenvalues found. 0 <= M <= N. */
227 /* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
229 /* W (output) REAL array, dimension (N) */
230 /* The first M elements contain the selected eigenvalues in */
231 /* ascending order. */
233 /* Z (output) REAL array, dimension (LDZ, max(1,M)) */
234 /* If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
235 /* contain the orthonormal eigenvectors of the matrix A */
236 /* corresponding to the selected eigenvalues, with the i-th */
237 /* column of Z holding the eigenvector associated with W(i). */
238 /* If JOBZ = 'N', then Z is not referenced. */
239 /* Note: the user must ensure that at least max(1,M) columns are */
240 /* supplied in the array Z; if RANGE = 'V', the exact value of M */
241 /* is not known in advance and an upper bound must be used. */
242 /* Supplying N columns is always safe. */
244 /* LDZ (input) INTEGER */
245 /* The leading dimension of the array Z. LDZ >= 1, and if */
246 /* JOBZ = 'V', LDZ >= max(1,N). */
248 /* ISUPPZ (output) INTEGER array, dimension ( 2*max(1,M) ) */
249 /* The support of the eigenvectors in Z, i.e., the indices */
250 /* indicating the nonzero elements in Z. The i-th eigenvector */
251 /* is nonzero only in elements ISUPPZ( 2*i-1 ) through */
253 /* ********* Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1 */
255 /* WORK (workspace/output) REAL array, dimension (MAX(1,LWORK)) */
256 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
258 /* LWORK (input) INTEGER */
259 /* The dimension of the array WORK. LWORK >= max(1,26*N). */
260 /* For optimal efficiency, LWORK >= (NB+6)*N, */
261 /* where NB is the max of the blocksize for SSYTRD and SORMTR */
262 /* returned by ILAENV. */
264 /* If LWORK = -1, then a workspace query is assumed; the routine */
265 /* only calculates the optimal sizes of the WORK and IWORK */
266 /* arrays, returns these values as the first entries of the WORK */
267 /* and IWORK arrays, and no error message related to LWORK or */
268 /* LIWORK is issued by XERBLA. */
270 /* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */
271 /* On exit, if INFO = 0, IWORK(1) returns the optimal LWORK. */
273 /* LIWORK (input) INTEGER */
274 /* The dimension of the array IWORK. LIWORK >= max(1,10*N). */
276 /* If LIWORK = -1, then a workspace query is assumed; the */
277 /* routine only calculates the optimal sizes of the WORK and */
278 /* IWORK arrays, returns these values as the first entries of */
279 /* the WORK and IWORK arrays, and no error message related to */
280 /* LWORK or LIWORK is issued by XERBLA. */
282 /* INFO (output) INTEGER */
283 /* = 0: successful exit */
284 /* < 0: if INFO = -i, the i-th argument had an illegal value */
285 /* > 0: Internal error */
287 /* Further Details */
288 /* =============== */
290 /* Based on contributions by */
291 /* Inderjit Dhillon, IBM Almaden, USA */
292 /* Osni Marques, LBNL/NERSC, USA */
293 /* Ken Stanley, Computer Science Division, University of */
294 /* California at Berkeley, USA */
295 /* Jason Riedy, Computer Science Division, University of */
296 /* California at Berkeley, USA */
298 /* ===================================================================== */
300 /* .. Parameters .. */
302 /* .. Local Scalars .. */
304 /* .. External Functions .. */
306 /* .. External Subroutines .. */
308 /* .. Intrinsic Functions .. */
310 /* .. Executable Statements .. */
312 /* Test the input parameters. */
314 /* Parameter adjustments */
316 a_offset = 1 + a_dim1;
320 z_offset = 1 + z_dim1;
327 ieeeok = ilaenv_(&c__10, "SSYEVR", "N", &c__1, &c__2, &c__3, &c__4);
329 lower = lsame_(uplo, "L");
330 wantz = lsame_(jobz, "V");
331 alleig = lsame_(range, "A");
332 valeig = lsame_(range, "V");
333 indeig = lsame_(range, "I");
335 lquery = *lwork == -1 || *liwork == -1;
338 i__1 = 1, i__2 = *n * 26;
339 lwmin = max(i__1,i__2);
341 i__1 = 1, i__2 = *n * 10;
342 liwmin = max(i__1,i__2);
345 if (! (wantz || lsame_(jobz, "N"))) {
347 } else if (! (alleig || valeig || indeig)) {
349 } else if (! (lower || lsame_(uplo, "U"))) {
353 } else if (*lda < max(1,*n)) {
357 if (*n > 0 && *vu <= *vl) {
361 if (*il < 1 || *il > max(1,*n)) {
363 } else if (*iu < min(*n,*il) || *iu > *n) {
369 if (*ldz < 1 || wantz && *ldz < *n) {
375 nb = ilaenv_(&c__1, "SSYTRD", uplo, n, &c_n1, &c_n1, &c_n1);
377 i__1 = nb, i__2 = ilaenv_(&c__1, "SORMTR", uplo, n, &c_n1, &c_n1, &
381 i__1 = (nb + 1) * *n;
382 lwkopt = max(i__1,lwmin);
383 work[1] = (real) lwkopt;
386 if (*lwork < lwmin && ! lquery) {
388 } else if (*liwork < liwmin && ! lquery) {
395 xerbla_("SSYEVR", &i__1);
401 /* Quick return if possible */
411 if (alleig || indeig) {
413 w[1] = a[a_dim1 + 1];
415 if (*vl < a[a_dim1 + 1] && *vu >= a[a_dim1 + 1]) {
417 w[1] = a[a_dim1 + 1];
421 z__[z_dim1 + 1] = 1.f;
426 /* Get machine constants. */
428 safmin = slamch_("Safe minimum");
429 eps = slamch_("Precision");
430 smlnum = safmin / eps;
431 bignum = 1.f / smlnum;
434 r__1 = sqrt(bignum), r__2 = 1.f / sqrt(sqrt(safmin));
435 rmax = dmin(r__1,r__2);
437 /* Scale matrix to allowable range, if necessary. */
445 anrm = slansy_("M", uplo, n, &a[a_offset], lda, &work[1]);
446 if (anrm > 0.f && anrm < rmin) {
449 } else if (anrm > rmax) {
456 for (j = 1; j <= i__1; ++j) {
458 sscal_(&i__2, &sigma, &a[j + j * a_dim1], &c__1);
463 for (j = 1; j <= i__1; ++j) {
464 sscal_(&j, &sigma, &a[j * a_dim1 + 1], &c__1);
469 abstll = *abstol * sigma;
476 /* Initialize indices into workspaces. Note: The IWORK indices are */
477 /* used only if SSTERF or SSTEMR fail. */
478 /* WORK(INDTAU:INDTAU+N-1) stores the scalar factors of the */
479 /* elementary reflectors used in SSYTRD. */
481 /* WORK(INDD:INDD+N-1) stores the tridiagonal's diagonal entries. */
483 /* WORK(INDE:INDE+N-1) stores the off-diagonal entries of the */
484 /* tridiagonal matrix from SSYTRD. */
486 /* WORK(INDDD:INDDD+N-1) is a copy of the diagonal entries over */
487 /* -written by SSTEMR (the SSTERF path copies the diagonal to W). */
489 /* WORK(INDEE:INDEE+N-1) is a copy of the off-diagonal entries over */
490 /* -written while computing the eigenvalues in SSTERF and SSTEMR. */
492 /* INDWK is the starting offset of the left-over workspace, and */
493 /* LLWORK is the remaining workspace size. */
495 llwork = *lwork - indwk + 1;
496 /* IWORK(INDIBL:INDIBL+M-1) corresponds to IBLOCK in SSTEBZ and */
497 /* stores the block indices of each of the M<=N eigenvalues. */
499 /* IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in SSTEBZ and */
500 /* stores the starting and finishing indices of each block. */
501 indisp = indibl + *n;
502 /* IWORK(INDIFL:INDIFL+N-1) stores the indices of eigenvectors */
503 /* that corresponding to eigenvectors that fail to converge in */
504 /* SSTEIN. This information is discarded; if any fail, the driver */
505 /* returns INFO > 0. */
506 indifl = indisp + *n;
507 /* INDIWO is the offset of the remaining integer workspace. */
508 indiwo = indisp + *n;
510 /* Call SSYTRD to reduce symmetric matrix to tridiagonal form. */
512 ssytrd_(uplo, n, &a[a_offset], lda, &work[indd], &work[inde], &work[
513 indtau], &work[indwk], &llwork, &iinfo);
515 /* If all eigenvalues are desired */
516 /* then call SSTERF or SSTEMR and SORMTR. */
520 if (*il == 1 && *iu == *n) {
524 if ((alleig || test) && ieeeok == 1) {
526 scopy_(n, &work[indd], &c__1, &w[1], &c__1);
528 scopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1);
529 ssterf_(n, &w[1], &work[indee], info);
532 scopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1);
533 scopy_(n, &work[indd], &c__1, &work[inddd], &c__1);
535 if (*abstol <= *n * 2.f * eps) {
540 sstemr_(jobz, "A", n, &work[inddd], &work[indee], vl, vu, il, iu,
541 m, &w[1], &z__[z_offset], ldz, n, &isuppz[1], &tryrac, &
542 work[indwk], lwork, &iwork[1], liwork, info);
546 /* Apply orthogonal matrix used in reduction to tridiagonal */
547 /* form to eigenvectors returned by SSTEIN. */
549 if (wantz && *info == 0) {
551 llwrkn = *lwork - indwkn + 1;
552 sormtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau]
553 , &z__[z_offset], ldz, &work[indwkn], &llwrkn, &iinfo);
559 /* Everything worked. Skip SSTEBZ/SSTEIN. IWORK(:) are */
567 /* Otherwise, call SSTEBZ and, if eigenvectors are desired, SSTEIN. */
568 /* Also call SSTEBZ and SSTEIN if SSTEMR fails. */
571 *(unsigned char *)order = 'B';
573 *(unsigned char *)order = 'E';
575 sstebz_(range, order, n, &vll, &vuu, il, iu, &abstll, &work[indd], &work[
576 inde], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &work[
577 indwk], &iwork[indiwo], info);
580 sstein_(n, &work[indd], &work[inde], m, &w[1], &iwork[indibl], &iwork[
581 indisp], &z__[z_offset], ldz, &work[indwk], &iwork[indiwo], &
582 iwork[indifl], info);
584 /* Apply orthogonal matrix used in reduction to tridiagonal */
585 /* form to eigenvectors returned by SSTEIN. */
588 llwrkn = *lwork - indwkn + 1;
589 sormtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau], &z__[
590 z_offset], ldz, &work[indwkn], &llwrkn, &iinfo);
593 /* If matrix was scaled, then rescale eigenvalues appropriately. */
595 /* Jump here if SSTEMR/SSTEIN succeeded. */
604 sscal_(&imax, &r__1, &w[1], &c__1);
607 /* If eigenvalues are not in order, then sort them, along with */
608 /* eigenvectors. Note: We do not sort the IFAIL portion of IWORK. */
609 /* It may not be initialized (if SSTEMR/SSTEIN succeeded), and we do */
610 /* not return this detailed information to the user. */
614 for (j = 1; j <= i__1; ++j) {
618 for (jj = j + 1; jj <= i__2; ++jj) {
629 sswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1],
636 /* Set WORK(1) to optimal workspace size. */
638 work[1] = (real) lwkopt;