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 dsyevr_(char *jobz, char *range, char *uplo, integer *n,
13 doublereal *a, integer *lda, doublereal *vl, doublereal *vu, integer *
14 il, integer *iu, doublereal *abstol, integer *m, doublereal *w,
15 doublereal *z__, integer *ldz, integer *isuppz, doublereal *work,
16 integer *lwork, integer *iwork, integer *liwork, integer *info)
18 /* System generated locals */
19 integer a_dim1, a_offset, z_dim1, z_offset, i__1, i__2;
20 doublereal d__1, d__2;
22 /* Builtin functions */
23 double sqrt(doublereal);
26 integer i__, j, nb, jj;
27 doublereal eps, vll, vuu, tmp1;
31 doublereal rmin, rmax;
33 extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
36 extern logical lsame_(char *, char *);
40 extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
41 doublereal *, integer *), dswap_(integer *, doublereal *, integer
42 *, doublereal *, integer *);
45 extern doublereal dlamch_(char *);
46 logical alleig, indeig;
47 integer iscale, ieeeok, indibl, indifl;
50 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
51 integer *, integer *);
52 extern /* Subroutine */ int xerbla_(char *, integer *);
53 doublereal abstll, bignum;
54 integer indtau, indisp;
55 extern /* Subroutine */ int dstein_(integer *, doublereal *, doublereal *,
56 integer *, doublereal *, integer *, integer *, doublereal *,
57 integer *, doublereal *, integer *, integer *, integer *),
58 dsterf_(integer *, doublereal *, doublereal *, integer *);
59 integer indiwo, indwkn;
60 extern doublereal dlansy_(char *, char *, integer *, doublereal *,
61 integer *, doublereal *);
62 extern /* Subroutine */ int dstebz_(char *, char *, integer *, doublereal
63 *, doublereal *, integer *, integer *, doublereal *, doublereal *,
64 doublereal *, integer *, integer *, doublereal *, integer *,
65 integer *, doublereal *, integer *, integer *),
66 dstemr_(char *, char *, integer *, doublereal *, doublereal *,
67 doublereal *, doublereal *, integer *, integer *, integer *,
68 doublereal *, doublereal *, integer *, integer *, integer *,
69 logical *, doublereal *, integer *, integer *, integer *, integer
73 extern /* Subroutine */ int dormtr_(char *, char *, char *, integer *,
74 integer *, doublereal *, integer *, doublereal *, doublereal *,
75 integer *, doublereal *, integer *, integer *);
76 integer llwrkn, llwork, nsplit;
78 extern /* Subroutine */ int dsytrd_(char *, integer *, doublereal *,
79 integer *, doublereal *, doublereal *, doublereal *, doublereal *,
80 integer *, integer *);
85 /* -- LAPACK driver routine (version 3.1) -- */
86 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
89 /* .. Scalar Arguments .. */
91 /* .. Array Arguments .. */
97 /* DSYEVR computes selected eigenvalues and, optionally, eigenvectors */
98 /* of a real symmetric matrix A. Eigenvalues and eigenvectors can be */
99 /* selected by specifying either a range of values or a range of */
100 /* indices for the desired eigenvalues. */
102 /* DSYEVR first reduces the matrix A to tridiagonal form T with a call */
103 /* to DSYTRD. Then, whenever possible, DSYEVR calls DSTEMR to compute */
104 /* the eigenspectrum using Relatively Robust Representations. DSTEMR */
105 /* computes eigenvalues by the dqds algorithm, while orthogonal */
106 /* eigenvectors are computed from various "good" L D L^T representations */
107 /* (also known as Relatively Robust Representations). Gram-Schmidt */
108 /* orthogonalization is avoided as far as possible. More specifically, */
109 /* the various steps of the algorithm are as follows. */
111 /* For each unreduced block (submatrix) of T, */
112 /* (a) Compute T - sigma I = L D L^T, so that L and D */
113 /* define all the wanted eigenvalues to high relative accuracy. */
114 /* This means that small relative changes in the entries of D and L */
115 /* cause only small relative changes in the eigenvalues and */
116 /* eigenvectors. The standard (unfactored) representation of the */
117 /* tridiagonal matrix T does not have this property in general. */
118 /* (b) Compute the eigenvalues to suitable accuracy. */
119 /* If the eigenvectors are desired, the algorithm attains full */
120 /* accuracy of the computed eigenvalues only right before */
121 /* the corresponding vectors have to be computed, see steps c) and d). */
122 /* (c) For each cluster of close eigenvalues, select a new */
123 /* shift close to the cluster, find a new factorization, and refine */
124 /* the shifted eigenvalues to suitable accuracy. */
125 /* (d) For each eigenvalue with a large enough relative separation compute */
126 /* the corresponding eigenvector by forming a rank revealing twisted */
127 /* factorization. Go back to (c) for any clusters that remain. */
129 /* The desired accuracy of the output can be specified by the input */
130 /* parameter ABSTOL. */
132 /* For more details, see DSTEMR's documentation and: */
133 /* - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations */
134 /* to compute orthogonal eigenvectors of symmetric tridiagonal matrices," */
135 /* Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004. */
136 /* - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and */
137 /* Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25, */
138 /* 2004. Also LAPACK Working Note 154. */
139 /* - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric */
140 /* tridiagonal eigenvalue/eigenvector problem", */
141 /* Computer Science Division Technical Report No. UCB/CSD-97-971, */
142 /* UC Berkeley, May 1997. */
145 /* Note 1 : DSYEVR calls DSTEMR when the full spectrum is requested */
146 /* on machines which conform to the ieee-754 floating point standard. */
147 /* DSYEVR calls DSTEBZ and SSTEIN on non-ieee machines and */
148 /* when partial spectrum requests are made. */
150 /* Normal execution of DSTEMR may create NaNs and infinities and */
151 /* hence may abort due to a floating point exception in environments */
152 /* which do not handle NaNs and infinities in the ieee standard default */
158 /* JOBZ (input) CHARACTER*1 */
159 /* = 'N': Compute eigenvalues only; */
160 /* = 'V': Compute eigenvalues and eigenvectors. */
162 /* RANGE (input) CHARACTER*1 */
163 /* = 'A': all eigenvalues will be found. */
164 /* = 'V': all eigenvalues in the half-open interval (VL,VU] */
166 /* = 'I': the IL-th through IU-th eigenvalues will be found. */
167 /* ********* For RANGE = 'V' or 'I' and IU - IL < N - 1, DSTEBZ and */
168 /* ********* DSTEIN are called */
170 /* UPLO (input) CHARACTER*1 */
171 /* = 'U': Upper triangle of A is stored; */
172 /* = 'L': Lower triangle of A is stored. */
174 /* N (input) INTEGER */
175 /* The order of the matrix A. N >= 0. */
177 /* A (input/output) DOUBLE PRECISION array, dimension (LDA, N) */
178 /* On entry, the symmetric matrix A. If UPLO = 'U', the */
179 /* leading N-by-N upper triangular part of A contains the */
180 /* upper triangular part of the matrix A. If UPLO = 'L', */
181 /* the leading N-by-N lower triangular part of A contains */
182 /* the lower triangular part of the matrix A. */
183 /* On exit, the lower triangle (if UPLO='L') or the upper */
184 /* triangle (if UPLO='U') of A, including the diagonal, is */
187 /* LDA (input) INTEGER */
188 /* The leading dimension of the array A. LDA >= max(1,N). */
190 /* VL (input) DOUBLE PRECISION */
191 /* VU (input) DOUBLE PRECISION */
192 /* If RANGE='V', the lower and upper bounds of the interval to */
193 /* be searched for eigenvalues. VL < VU. */
194 /* Not referenced if RANGE = 'A' or 'I'. */
196 /* IL (input) INTEGER */
197 /* IU (input) INTEGER */
198 /* If RANGE='I', the indices (in ascending order) of the */
199 /* smallest and largest eigenvalues to be returned. */
200 /* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
201 /* Not referenced if RANGE = 'A' or 'V'. */
203 /* ABSTOL (input) DOUBLE PRECISION */
204 /* The absolute error tolerance for the eigenvalues. */
205 /* An approximate eigenvalue is accepted as converged */
206 /* when it is determined to lie in an interval [a,b] */
207 /* of width less than or equal to */
209 /* ABSTOL + EPS * max( |a|,|b| ) , */
211 /* where EPS is the machine precision. If ABSTOL is less than */
212 /* or equal to zero, then EPS*|T| will be used in its place, */
213 /* where |T| is the 1-norm of the tridiagonal matrix obtained */
214 /* by reducing A to tridiagonal form. */
216 /* See "Computing Small Singular Values of Bidiagonal Matrices */
217 /* with Guaranteed High Relative Accuracy," by Demmel and */
218 /* Kahan, LAPACK Working Note #3. */
220 /* If high relative accuracy is important, set ABSTOL to */
221 /* DLAMCH( 'Safe minimum' ). Doing so will guarantee that */
222 /* eigenvalues are computed to high relative accuracy when */
223 /* possible in future releases. The current code does not */
224 /* make any guarantees about high relative accuracy, but */
225 /* future releases will. See J. Barlow and J. Demmel, */
226 /* "Computing Accurate Eigensystems of Scaled Diagonally */
227 /* Dominant Matrices", LAPACK Working Note #7, for a discussion */
228 /* of which matrices define their eigenvalues to high relative */
231 /* M (output) INTEGER */
232 /* The total number of eigenvalues found. 0 <= M <= N. */
233 /* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
235 /* W (output) DOUBLE PRECISION array, dimension (N) */
236 /* The first M elements contain the selected eigenvalues in */
237 /* ascending order. */
239 /* Z (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M)) */
240 /* If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
241 /* contain the orthonormal eigenvectors of the matrix A */
242 /* corresponding to the selected eigenvalues, with the i-th */
243 /* column of Z holding the eigenvector associated with W(i). */
244 /* If JOBZ = 'N', then Z is not referenced. */
245 /* Note: the user must ensure that at least max(1,M) columns are */
246 /* supplied in the array Z; if RANGE = 'V', the exact value of M */
247 /* is not known in advance and an upper bound must be used. */
248 /* Supplying N columns is always safe. */
250 /* LDZ (input) INTEGER */
251 /* The leading dimension of the array Z. LDZ >= 1, and if */
252 /* JOBZ = 'V', LDZ >= max(1,N). */
254 /* ISUPPZ (output) INTEGER array, dimension ( 2*max(1,M) ) */
255 /* The support of the eigenvectors in Z, i.e., the indices */
256 /* indicating the nonzero elements in Z. The i-th eigenvector */
257 /* is nonzero only in elements ISUPPZ( 2*i-1 ) through */
259 /* ********* Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1 */
261 /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
262 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
264 /* LWORK (input) INTEGER */
265 /* The dimension of the array WORK. LWORK >= max(1,26*N). */
266 /* For optimal efficiency, LWORK >= (NB+6)*N, */
267 /* where NB is the max of the blocksize for DSYTRD and DORMTR */
268 /* returned by ILAENV. */
270 /* If LWORK = -1, then a workspace query is assumed; the routine */
271 /* only calculates the optimal size of the WORK array, returns */
272 /* this value as the first entry of the WORK array, and no error */
273 /* message related to LWORK is issued by XERBLA. */
275 /* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */
276 /* On exit, if INFO = 0, IWORK(1) returns the optimal LWORK. */
278 /* LIWORK (input) INTEGER */
279 /* The dimension of the array IWORK. LIWORK >= max(1,10*N). */
281 /* If LIWORK = -1, then a workspace query is assumed; the */
282 /* routine only calculates the optimal size of the IWORK array, */
283 /* returns this value as the first entry of the IWORK array, and */
284 /* no error message related to LIWORK is issued by XERBLA. */
286 /* INFO (output) INTEGER */
287 /* = 0: successful exit */
288 /* < 0: if INFO = -i, the i-th argument had an illegal value */
289 /* > 0: Internal error */
291 /* Further Details */
292 /* =============== */
294 /* Based on contributions by */
295 /* Inderjit Dhillon, IBM Almaden, USA */
296 /* Osni Marques, LBNL/NERSC, USA */
297 /* Ken Stanley, Computer Science Division, University of */
298 /* California at Berkeley, USA */
299 /* Jason Riedy, Computer Science Division, University of */
300 /* California at Berkeley, USA */
302 /* ===================================================================== */
304 /* .. Parameters .. */
306 /* .. Local Scalars .. */
308 /* .. External Functions .. */
310 /* .. External Subroutines .. */
312 /* .. Intrinsic Functions .. */
314 /* .. Executable Statements .. */
316 /* Test the input parameters. */
318 /* Parameter adjustments */
320 a_offset = 1 + a_dim1;
324 z_offset = 1 + z_dim1;
331 ieeeok = ilaenv_(&c__10, "DSYEVR", "N", &c__1, &c__2, &c__3, &c__4);
333 lower = lsame_(uplo, "L");
334 wantz = lsame_(jobz, "V");
335 alleig = lsame_(range, "A");
336 valeig = lsame_(range, "V");
337 indeig = lsame_(range, "I");
339 lquery = *lwork == -1 || *liwork == -1;
342 i__1 = 1, i__2 = *n * 26;
343 lwmin = max(i__1,i__2);
345 i__1 = 1, i__2 = *n * 10;
346 liwmin = max(i__1,i__2);
349 if (! (wantz || lsame_(jobz, "N"))) {
351 } else if (! (alleig || valeig || indeig)) {
353 } else if (! (lower || lsame_(uplo, "U"))) {
357 } else if (*lda < max(1,*n)) {
361 if (*n > 0 && *vu <= *vl) {
365 if (*il < 1 || *il > max(1,*n)) {
367 } else if (*iu < min(*n,*il) || *iu > *n) {
373 if (*ldz < 1 || wantz && *ldz < *n) {
375 } else if (*lwork < lwmin && ! lquery) {
377 } else if (*liwork < liwmin && ! lquery) {
383 nb = ilaenv_(&c__1, "DSYTRD", uplo, n, &c_n1, &c_n1, &c_n1);
385 i__1 = nb, i__2 = ilaenv_(&c__1, "DORMTR", uplo, n, &c_n1, &c_n1, &
389 i__1 = (nb + 1) * *n;
390 lwkopt = max(i__1,lwmin);
391 work[1] = (doublereal) lwkopt;
397 xerbla_("DSYEVR", &i__1);
403 /* Quick return if possible */
413 if (alleig || indeig) {
415 w[1] = a[a_dim1 + 1];
417 if (*vl < a[a_dim1 + 1] && *vu >= a[a_dim1 + 1]) {
419 w[1] = a[a_dim1 + 1];
423 z__[z_dim1 + 1] = 1.;
428 /* Get machine constants. */
430 safmin = dlamch_("Safe minimum");
431 eps = dlamch_("Precision");
432 smlnum = safmin / eps;
433 bignum = 1. / smlnum;
436 d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin));
437 rmax = min(d__1,d__2);
439 /* Scale matrix to allowable range, if necessary. */
445 anrm = dlansy_("M", uplo, n, &a[a_offset], lda, &work[1]);
446 if (anrm > 0. && anrm < rmin) {
449 } else if (anrm > rmax) {
456 for (j = 1; j <= i__1; ++j) {
458 dscal_(&i__2, &sigma, &a[j + j * a_dim1], &c__1);
463 for (j = 1; j <= i__1; ++j) {
464 dscal_(&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 DSTERF or DSTEMR fail. */
478 /* WORK(INDTAU:INDTAU+N-1) stores the scalar factors of the */
479 /* elementary reflectors used in DSYTRD. */
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 DSYTRD. */
486 /* WORK(INDDD:INDDD+N-1) is a copy of the diagonal entries over */
487 /* -written by DSTEMR (the DSTERF 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 DSTERF and DSTEMR. */
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 DSTEBZ and */
497 /* stores the block indices of each of the M<=N eigenvalues. */
499 /* IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in DSTEBZ 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 /* DSTEIN. 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 DSYTRD to reduce symmetric matrix to tridiagonal form. */
512 dsytrd_(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 DSTERF or DSTEMR and DORMTR. */
518 if ((alleig || indeig && *il == 1 && *iu == *n) && ieeeok == 1) {
520 dcopy_(n, &work[indd], &c__1, &w[1], &c__1);
522 dcopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1);
523 dsterf_(n, &w[1], &work[indee], info);
526 dcopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1);
527 dcopy_(n, &work[indd], &c__1, &work[inddd], &c__1);
529 if (*abstol <= *n * 0. * eps) {
534 dstemr_(jobz, "A", n, &work[inddd], &work[indee], vl, vu, il, iu,
535 m, &w[1], &z__[z_offset], ldz, n, &isuppz[1], &tryrac, &
536 work[indwk], lwork, &iwork[1], liwork, info);
540 /* Apply orthogonal matrix used in reduction to tridiagonal */
541 /* form to eigenvectors returned by DSTEIN. */
543 if (wantz && *info == 0) {
545 llwrkn = *lwork - indwkn + 1;
546 dormtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau]
547 , &z__[z_offset], ldz, &work[indwkn], &llwrkn, &iinfo);
553 /* Everything worked. Skip DSTEBZ/DSTEIN. IWORK(:) are */
561 /* Otherwise, call DSTEBZ and, if eigenvectors are desired, DSTEIN. */
562 /* Also call DSTEBZ and DSTEIN if DSTEMR fails. */
565 *(unsigned char *)order = 'B';
567 *(unsigned char *)order = 'E';
569 dstebz_(range, order, n, &vll, &vuu, il, iu, &abstll, &work[indd], &work[
570 inde], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &work[
571 indwk], &iwork[indiwo], info);
574 dstein_(n, &work[indd], &work[inde], m, &w[1], &iwork[indibl], &iwork[
575 indisp], &z__[z_offset], ldz, &work[indwk], &iwork[indiwo], &
576 iwork[indifl], info);
578 /* Apply orthogonal matrix used in reduction to tridiagonal */
579 /* form to eigenvectors returned by DSTEIN. */
582 llwrkn = *lwork - indwkn + 1;
583 dormtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau], &z__[
584 z_offset], ldz, &work[indwkn], &llwrkn, &iinfo);
587 /* If matrix was scaled, then rescale eigenvalues appropriately. */
589 /* Jump here if DSTEMR/DSTEIN succeeded. */
598 dscal_(&imax, &d__1, &w[1], &c__1);
601 /* If eigenvalues are not in order, then sort them, along with */
602 /* eigenvectors. Note: We do not sort the IFAIL portion of IWORK. */
603 /* It may not be initialized (if DSTEMR/DSTEIN succeeded), and we do */
604 /* not return this detailed information to the user. */
608 for (j = 1; j <= i__1; ++j) {
612 for (jj = j + 1; jj <= i__2; ++jj) {
623 dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1],
630 /* Set WORK(1) to optimal workspace size. */
632 work[1] = (doublereal) lwkopt;