1 *> \brief <b> DSYEVR computes the eigenvalues and, optionally, the left and/or right eigenvectors for SY matrices</b>
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DSYEVR + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsyevr.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsyevr.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsyevr.f">
21 * SUBROUTINE DSYEVR( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU,
22 * ABSTOL, M, W, Z, LDZ, ISUPPZ, WORK, LWORK,
23 * IWORK, LIWORK, INFO )
25 * .. Scalar Arguments ..
26 * CHARACTER JOBZ, RANGE, UPLO
27 * INTEGER IL, INFO, IU, LDA, LDZ, LIWORK, LWORK, M, N
28 * DOUBLE PRECISION ABSTOL, VL, VU
30 * .. Array Arguments ..
31 * INTEGER ISUPPZ( * ), IWORK( * )
32 * DOUBLE PRECISION A( LDA, * ), W( * ), WORK( * ), Z( LDZ, * )
41 *> DSYEVR computes selected eigenvalues and, optionally, eigenvectors
42 *> of a real symmetric matrix A. Eigenvalues and eigenvectors can be
43 *> selected by specifying either a range of values or a range of
44 *> indices for the desired eigenvalues.
46 *> DSYEVR first reduces the matrix A to tridiagonal form T with a call
47 *> to DSYTRD. Then, whenever possible, DSYEVR calls DSTEMR to compute
48 *> the eigenspectrum using Relatively Robust Representations. DSTEMR
49 *> computes eigenvalues by the dqds algorithm, while orthogonal
50 *> eigenvectors are computed from various "good" L D L^T representations
51 *> (also known as Relatively Robust Representations). Gram-Schmidt
52 *> orthogonalization is avoided as far as possible. More specifically,
53 *> the various steps of the algorithm are as follows.
55 *> For each unreduced block (submatrix) of T,
56 *> (a) Compute T - sigma I = L D L^T, so that L and D
57 *> define all the wanted eigenvalues to high relative accuracy.
58 *> This means that small relative changes in the entries of D and L
59 *> cause only small relative changes in the eigenvalues and
60 *> eigenvectors. The standard (unfactored) representation of the
61 *> tridiagonal matrix T does not have this property in general.
62 *> (b) Compute the eigenvalues to suitable accuracy.
63 *> If the eigenvectors are desired, the algorithm attains full
64 *> accuracy of the computed eigenvalues only right before
65 *> the corresponding vectors have to be computed, see steps c) and d).
66 *> (c) For each cluster of close eigenvalues, select a new
67 *> shift close to the cluster, find a new factorization, and refine
68 *> the shifted eigenvalues to suitable accuracy.
69 *> (d) For each eigenvalue with a large enough relative separation compute
70 *> the corresponding eigenvector by forming a rank revealing twisted
71 *> factorization. Go back to (c) for any clusters that remain.
73 *> The desired accuracy of the output can be specified by the input
76 *> For more details, see DSTEMR's documentation and:
77 *> - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations
78 *> to compute orthogonal eigenvectors of symmetric tridiagonal matrices,"
79 *> Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004.
80 *> - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and
81 *> Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25,
82 *> 2004. Also LAPACK Working Note 154.
83 *> - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric
84 *> tridiagonal eigenvalue/eigenvector problem",
85 *> Computer Science Division Technical Report No. UCB/CSD-97-971,
86 *> UC Berkeley, May 1997.
89 *> Note 1 : DSYEVR calls DSTEMR when the full spectrum is requested
90 *> on machines which conform to the ieee-754 floating point standard.
91 *> DSYEVR calls DSTEBZ and SSTEIN on non-ieee machines and
92 *> when partial spectrum requests are made.
94 *> Normal execution of DSTEMR may create NaNs and infinities and
95 *> hence may abort due to a floating point exception in environments
96 *> which do not handle NaNs and infinities in the ieee standard default
105 *> JOBZ is CHARACTER*1
106 *> = 'N': Compute eigenvalues only;
107 *> = 'V': Compute eigenvalues and eigenvectors.
112 *> RANGE is CHARACTER*1
113 *> = 'A': all eigenvalues will be found.
114 *> = 'V': all eigenvalues in the half-open interval (VL,VU]
116 *> = 'I': the IL-th through IU-th eigenvalues will be found.
117 *> For RANGE = 'V' or 'I' and IU - IL < N - 1, DSTEBZ and
123 *> UPLO is CHARACTER*1
124 *> = 'U': Upper triangle of A is stored;
125 *> = 'L': Lower triangle of A is stored.
131 *> The order of the matrix A. N >= 0.
136 *> A is DOUBLE PRECISION array, dimension (LDA, N)
137 *> On entry, the symmetric matrix A. If UPLO = 'U', the
138 *> leading N-by-N upper triangular part of A contains the
139 *> upper triangular part of the matrix A. If UPLO = 'L',
140 *> the leading N-by-N lower triangular part of A contains
141 *> the lower triangular part of the matrix A.
142 *> On exit, the lower triangle (if UPLO='L') or the upper
143 *> triangle (if UPLO='U') of A, including the diagonal, is
150 *> The leading dimension of the array A. LDA >= max(1,N).
155 *> VL is DOUBLE PRECISION
156 *> If RANGE='V', the lower bound of the interval to
157 *> be searched for eigenvalues. VL < VU.
158 *> Not referenced if RANGE = 'A' or 'I'.
163 *> VU is DOUBLE PRECISION
164 *> If RANGE='V', the upper bound of the interval to
165 *> be searched for eigenvalues. VL < VU.
166 *> Not referenced if RANGE = 'A' or 'I'.
172 *> If RANGE='I', the index of the
173 *> smallest eigenvalue to be returned.
174 *> 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.
175 *> Not referenced if RANGE = 'A' or 'V'.
181 *> If RANGE='I', the index of the
182 *> largest eigenvalue to be returned.
183 *> 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.
184 *> Not referenced if RANGE = 'A' or 'V'.
189 *> ABSTOL is DOUBLE PRECISION
190 *> The absolute error tolerance for the eigenvalues.
191 *> An approximate eigenvalue is accepted as converged
192 *> when it is determined to lie in an interval [a,b]
193 *> of width less than or equal to
195 *> ABSTOL + EPS * max( |a|,|b| ) ,
197 *> where EPS is the machine precision. If ABSTOL is less than
198 *> or equal to zero, then EPS*|T| will be used in its place,
199 *> where |T| is the 1-norm of the tridiagonal matrix obtained
200 *> by reducing A to tridiagonal form.
202 *> See "Computing Small Singular Values of Bidiagonal Matrices
203 *> with Guaranteed High Relative Accuracy," by Demmel and
204 *> Kahan, LAPACK Working Note #3.
206 *> If high relative accuracy is important, set ABSTOL to
207 *> DLAMCH( 'Safe minimum' ). Doing so will guarantee that
208 *> eigenvalues are computed to high relative accuracy when
209 *> possible in future releases. The current code does not
210 *> make any guarantees about high relative accuracy, but
211 *> future releases will. See J. Barlow and J. Demmel,
212 *> "Computing Accurate Eigensystems of Scaled Diagonally
213 *> Dominant Matrices", LAPACK Working Note #7, for a discussion
214 *> of which matrices define their eigenvalues to high relative
221 *> The total number of eigenvalues found. 0 <= M <= N.
222 *> If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1.
227 *> W is DOUBLE PRECISION array, dimension (N)
228 *> The first M elements contain the selected eigenvalues in
234 *> Z is DOUBLE PRECISION array, dimension (LDZ, max(1,M))
235 *> If JOBZ = 'V', then if INFO = 0, the first M columns of Z
236 *> contain the orthonormal eigenvectors of the matrix A
237 *> corresponding to the selected eigenvalues, with the i-th
238 *> column of Z holding the eigenvector associated with W(i).
239 *> If JOBZ = 'N', then Z is not referenced.
240 *> Note: the user must ensure that at least max(1,M) columns are
241 *> supplied in the array Z; if RANGE = 'V', the exact value of M
242 *> is not known in advance and an upper bound must be used.
243 *> Supplying N columns is always safe.
249 *> The leading dimension of the array Z. LDZ >= 1, and if
250 *> JOBZ = 'V', LDZ >= max(1,N).
253 *> \param[out] ISUPPZ
255 *> ISUPPZ is INTEGER array, dimension ( 2*max(1,M) )
256 *> The support of the eigenvectors in Z, i.e., the indices
257 *> indicating the nonzero elements in Z. The i-th eigenvector
258 *> is nonzero only in elements ISUPPZ( 2*i-1 ) through
260 *> Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1
265 *> WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK))
266 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
272 *> The dimension of the array WORK. LWORK >= max(1,26*N).
273 *> For optimal efficiency, LWORK >= (NB+6)*N,
274 *> where NB is the max of the blocksize for DSYTRD and DORMTR
275 *> returned by ILAENV.
277 *> If LWORK = -1, then a workspace query is assumed; the routine
278 *> only calculates the optimal size of the WORK array, returns
279 *> this value as the first entry of the WORK array, and no error
280 *> message related to LWORK is issued by XERBLA.
285 *> IWORK is INTEGER array, dimension (MAX(1,LIWORK))
286 *> On exit, if INFO = 0, IWORK(1) returns the optimal LWORK.
292 *> The dimension of the array IWORK. LIWORK >= max(1,10*N).
294 *> If LIWORK = -1, then a workspace query is assumed; the
295 *> routine only calculates the optimal size of the IWORK array,
296 *> returns this value as the first entry of the IWORK array, and
297 *> no error message related to LIWORK is issued by XERBLA.
303 *> = 0: successful exit
304 *> < 0: if INFO = -i, the i-th argument had an illegal value
305 *> > 0: Internal error
311 *> \author Univ. of Tennessee
312 *> \author Univ. of California Berkeley
313 *> \author Univ. of Colorado Denver
318 *> \ingroup doubleSYeigen
320 *> \par Contributors:
323 *> Inderjit Dhillon, IBM Almaden, USA \n
324 *> Osni Marques, LBNL/NERSC, USA \n
325 *> Ken Stanley, Computer Science Division, University of
326 *> California at Berkeley, USA \n
327 *> Jason Riedy, Computer Science Division, University of
328 *> California at Berkeley, USA \n
330 * =====================================================================
331 SUBROUTINE DSYEVR( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU,
332 $ ABSTOL, M, W, Z, LDZ, ISUPPZ, WORK, LWORK,
333 $ IWORK, LIWORK, INFO )
335 * -- LAPACK driver routine (version 3.6.1) --
336 * -- LAPACK is a software package provided by Univ. of Tennessee, --
337 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
340 * .. Scalar Arguments ..
341 CHARACTER JOBZ, RANGE, UPLO
342 INTEGER IL, INFO, IU, LDA, LDZ, LIWORK, LWORK, M, N
343 DOUBLE PRECISION ABSTOL, VL, VU
345 * .. Array Arguments ..
346 INTEGER ISUPPZ( * ), IWORK( * )
347 DOUBLE PRECISION A( LDA, * ), W( * ), WORK( * ), Z( LDZ, * )
350 * =====================================================================
353 DOUBLE PRECISION ZERO, ONE, TWO
354 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0, TWO = 2.0D+0 )
356 * .. Local Scalars ..
357 LOGICAL ALLEIG, INDEIG, LOWER, LQUERY, VALEIG, WANTZ,
360 INTEGER I, IEEEOK, IINFO, IMAX, INDD, INDDD, INDE,
361 $ INDEE, INDIBL, INDIFL, INDISP, INDIWO, INDTAU,
362 $ INDWK, INDWKN, ISCALE, J, JJ, LIWMIN,
363 $ LLWORK, LLWRKN, LWKOPT, LWMIN, NB, NSPLIT
364 DOUBLE PRECISION ABSTLL, ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN,
365 $ SIGMA, SMLNUM, TMP1, VLL, VUU
367 * .. External Functions ..
370 DOUBLE PRECISION DLAMCH, DLANSY
371 EXTERNAL LSAME, ILAENV, DLAMCH, DLANSY
373 * .. External Subroutines ..
374 EXTERNAL DCOPY, DORMTR, DSCAL, DSTEBZ, DSTEMR, DSTEIN,
375 $ DSTERF, DSWAP, DSYTRD, XERBLA
377 * .. Intrinsic Functions ..
378 INTRINSIC MAX, MIN, SQRT
380 * .. Executable Statements ..
382 * Test the input parameters.
384 IEEEOK = ILAENV( 10, 'DSYEVR', 'N', 1, 2, 3, 4 )
386 LOWER = LSAME( UPLO, 'L' )
387 WANTZ = LSAME( JOBZ, 'V' )
388 ALLEIG = LSAME( RANGE, 'A' )
389 VALEIG = LSAME( RANGE, 'V' )
390 INDEIG = LSAME( RANGE, 'I' )
392 LQUERY = ( ( LWORK.EQ.-1 ) .OR. ( LIWORK.EQ.-1 ) )
394 LWMIN = MAX( 1, 26*N )
395 LIWMIN = MAX( 1, 10*N )
398 IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
400 ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN
402 ELSE IF( .NOT.( LOWER .OR. LSAME( UPLO, 'U' ) ) ) THEN
404 ELSE IF( N.LT.0 ) THEN
406 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
410 IF( N.GT.0 .AND. VU.LE.VL )
412 ELSE IF( INDEIG ) THEN
413 IF( IL.LT.1 .OR. IL.GT.MAX( 1, N ) ) THEN
415 ELSE IF( IU.LT.MIN( N, IL ) .OR. IU.GT.N ) THEN
421 IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
423 ELSE IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
425 ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
431 NB = ILAENV( 1, 'DSYTRD', UPLO, N, -1, -1, -1 )
432 NB = MAX( NB, ILAENV( 1, 'DORMTR', UPLO, N, -1, -1, -1 ) )
433 LWKOPT = MAX( ( NB+1 )*N, LWMIN )
439 CALL XERBLA( 'DSYEVR', -INFO )
441 ELSE IF( LQUERY ) THEN
445 * Quick return if possible
455 IF( ALLEIG .OR. INDEIG ) THEN
459 IF( VL.LT.A( 1, 1 ) .AND. VU.GE.A( 1, 1 ) ) THEN
472 * Get machine constants.
474 SAFMIN = DLAMCH( 'Safe minimum' )
475 EPS = DLAMCH( 'Precision' )
476 SMLNUM = SAFMIN / EPS
477 BIGNUM = ONE / SMLNUM
478 RMIN = SQRT( SMLNUM )
479 RMAX = MIN( SQRT( BIGNUM ), ONE / SQRT( SQRT( SAFMIN ) ) )
481 * Scale matrix to allowable range, if necessary.
489 ANRM = DLANSY( 'M', UPLO, N, A, LDA, WORK )
490 IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN
493 ELSE IF( ANRM.GT.RMAX ) THEN
497 IF( ISCALE.EQ.1 ) THEN
500 CALL DSCAL( N-J+1, SIGMA, A( J, J ), 1 )
504 CALL DSCAL( J, SIGMA, A( 1, J ), 1 )
508 $ ABSTLL = ABSTOL*SIGMA
515 * Initialize indices into workspaces. Note: The IWORK indices are
516 * used only if DSTERF or DSTEMR fail.
518 * WORK(INDTAU:INDTAU+N-1) stores the scalar factors of the
519 * elementary reflectors used in DSYTRD.
521 * WORK(INDD:INDD+N-1) stores the tridiagonal's diagonal entries.
523 * WORK(INDE:INDE+N-1) stores the off-diagonal entries of the
524 * tridiagonal matrix from DSYTRD.
526 * WORK(INDDD:INDDD+N-1) is a copy of the diagonal entries over
527 * -written by DSTEMR (the DSTERF path copies the diagonal to W).
529 * WORK(INDEE:INDEE+N-1) is a copy of the off-diagonal entries over
530 * -written while computing the eigenvalues in DSTERF and DSTEMR.
532 * INDWK is the starting offset of the left-over workspace, and
533 * LLWORK is the remaining workspace size.
535 LLWORK = LWORK - INDWK + 1
537 * IWORK(INDIBL:INDIBL+M-1) corresponds to IBLOCK in DSTEBZ and
538 * stores the block indices of each of the M<=N eigenvalues.
540 * IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in DSTEBZ and
541 * stores the starting and finishing indices of each block.
543 * IWORK(INDIFL:INDIFL+N-1) stores the indices of eigenvectors
544 * that corresponding to eigenvectors that fail to converge in
545 * DSTEIN. This information is discarded; if any fail, the driver
548 * INDIWO is the offset of the remaining integer workspace.
552 * Call DSYTRD to reduce symmetric matrix to tridiagonal form.
554 CALL DSYTRD( UPLO, N, A, LDA, WORK( INDD ), WORK( INDE ),
555 $ WORK( INDTAU ), WORK( INDWK ), LLWORK, IINFO )
557 * If all eigenvalues are desired
558 * then call DSTERF or DSTEMR and DORMTR.
560 IF( ( ALLEIG .OR. ( INDEIG .AND. IL.EQ.1 .AND. IU.EQ.N ) ) .AND.
562 IF( .NOT.WANTZ ) THEN
563 CALL DCOPY( N, WORK( INDD ), 1, W, 1 )
564 CALL DCOPY( N-1, WORK( INDE ), 1, WORK( INDEE ), 1 )
565 CALL DSTERF( N, W, WORK( INDEE ), INFO )
567 CALL DCOPY( N-1, WORK( INDE ), 1, WORK( INDEE ), 1 )
568 CALL DCOPY( N, WORK( INDD ), 1, WORK( INDDD ), 1 )
570 IF (ABSTOL .LE. TWO*N*EPS) THEN
575 CALL DSTEMR( JOBZ, 'A', N, WORK( INDDD ), WORK( INDEE ),
576 $ VL, VU, IL, IU, M, W, Z, LDZ, N, ISUPPZ,
577 $ TRYRAC, WORK( INDWK ), LWORK, IWORK, LIWORK,
582 * Apply orthogonal matrix used in reduction to tridiagonal
583 * form to eigenvectors returned by DSTEIN.
585 IF( WANTZ .AND. INFO.EQ.0 ) THEN
587 LLWRKN = LWORK - INDWKN + 1
588 CALL DORMTR( 'L', UPLO, 'N', N, M, A, LDA,
589 $ WORK( INDTAU ), Z, LDZ, WORK( INDWKN ),
596 * Everything worked. Skip DSTEBZ/DSTEIN. IWORK(:) are
604 * Otherwise, call DSTEBZ and, if eigenvectors are desired, DSTEIN.
605 * Also call DSTEBZ and DSTEIN if DSTEMR fails.
613 CALL DSTEBZ( RANGE, ORDER, N, VLL, VUU, IL, IU, ABSTLL,
614 $ WORK( INDD ), WORK( INDE ), M, NSPLIT, W,
615 $ IWORK( INDIBL ), IWORK( INDISP ), WORK( INDWK ),
616 $ IWORK( INDIWO ), INFO )
619 CALL DSTEIN( N, WORK( INDD ), WORK( INDE ), M, W,
620 $ IWORK( INDIBL ), IWORK( INDISP ), Z, LDZ,
621 $ WORK( INDWK ), IWORK( INDIWO ), IWORK( INDIFL ),
624 * Apply orthogonal matrix used in reduction to tridiagonal
625 * form to eigenvectors returned by DSTEIN.
628 LLWRKN = LWORK - INDWKN + 1
629 CALL DORMTR( 'L', UPLO, 'N', N, M, A, LDA, WORK( INDTAU ), Z,
630 $ LDZ, WORK( INDWKN ), LLWRKN, IINFO )
633 * If matrix was scaled, then rescale eigenvalues appropriately.
635 * Jump here if DSTEMR/DSTEIN succeeded.
637 IF( ISCALE.EQ.1 ) THEN
643 CALL DSCAL( IMAX, ONE / SIGMA, W, 1 )
646 * If eigenvalues are not in order, then sort them, along with
647 * eigenvectors. Note: We do not sort the IFAIL portion of IWORK.
648 * It may not be initialized (if DSTEMR/DSTEIN succeeded), and we do
649 * not return this detailed information to the user.
656 IF( W( JJ ).LT.TMP1 ) THEN
665 CALL DSWAP( N, Z( 1, I ), 1, Z( 1, J ), 1 )
670 * Set WORK(1) to optimal workspace size.