1 *> \brief <b> CHEEVR computes the eigenvalues and, optionally, the left and/or right eigenvectors for HE matrices</b>
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CHEEVR + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cheevr.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cheevr.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cheevr.f">
21 * SUBROUTINE CHEEVR( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU,
22 * ABSTOL, M, W, Z, LDZ, ISUPPZ, WORK, LWORK,
23 * RWORK, LRWORK, IWORK, LIWORK, INFO )
25 * .. Scalar Arguments ..
26 * CHARACTER JOBZ, RANGE, UPLO
27 * INTEGER IL, INFO, IU, LDA, LDZ, LIWORK, LRWORK, LWORK,
31 * .. Array Arguments ..
32 * INTEGER ISUPPZ( * ), IWORK( * )
33 * REAL RWORK( * ), W( * )
34 * COMPLEX A( LDA, * ), WORK( * ), Z( LDZ, * )
43 *> CHEEVR computes selected eigenvalues and, optionally, eigenvectors
44 *> of a complex Hermitian matrix A. Eigenvalues and eigenvectors can
45 *> be selected by specifying either a range of values or a range of
46 *> indices for the desired eigenvalues.
48 *> CHEEVR first reduces the matrix A to tridiagonal form T with a call
49 *> to CHETRD. Then, whenever possible, CHEEVR calls CSTEMR to compute
50 *> the eigenspectrum using Relatively Robust Representations. CSTEMR
51 *> computes eigenvalues by the dqds algorithm, while orthogonal
52 *> eigenvectors are computed from various "good" L D L^T representations
53 *> (also known as Relatively Robust Representations). Gram-Schmidt
54 *> orthogonalization is avoided as far as possible. More specifically,
55 *> the various steps of the algorithm are as follows.
57 *> For each unreduced block (submatrix) of T,
58 *> (a) Compute T - sigma I = L D L^T, so that L and D
59 *> define all the wanted eigenvalues to high relative accuracy.
60 *> This means that small relative changes in the entries of D and L
61 *> cause only small relative changes in the eigenvalues and
62 *> eigenvectors. The standard (unfactored) representation of the
63 *> tridiagonal matrix T does not have this property in general.
64 *> (b) Compute the eigenvalues to suitable accuracy.
65 *> If the eigenvectors are desired, the algorithm attains full
66 *> accuracy of the computed eigenvalues only right before
67 *> the corresponding vectors have to be computed, see steps c) and d).
68 *> (c) For each cluster of close eigenvalues, select a new
69 *> shift close to the cluster, find a new factorization, and refine
70 *> the shifted eigenvalues to suitable accuracy.
71 *> (d) For each eigenvalue with a large enough relative separation compute
72 *> the corresponding eigenvector by forming a rank revealing twisted
73 *> factorization. Go back to (c) for any clusters that remain.
75 *> The desired accuracy of the output can be specified by the input
78 *> For more details, see DSTEMR's documentation and:
79 *> - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations
80 *> to compute orthogonal eigenvectors of symmetric tridiagonal matrices,"
81 *> Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004.
82 *> - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and
83 *> Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25,
84 *> 2004. Also LAPACK Working Note 154.
85 *> - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric
86 *> tridiagonal eigenvalue/eigenvector problem",
87 *> Computer Science Division Technical Report No. UCB/CSD-97-971,
88 *> UC Berkeley, May 1997.
91 *> Note 1 : CHEEVR calls CSTEMR when the full spectrum is requested
92 *> on machines which conform to the ieee-754 floating point standard.
93 *> CHEEVR calls SSTEBZ and CSTEIN on non-ieee machines and
94 *> when partial spectrum requests are made.
96 *> Normal execution of CSTEMR may create NaNs and infinities and
97 *> hence may abort due to a floating point exception in environments
98 *> which do not handle NaNs and infinities in the ieee standard default
107 *> JOBZ is CHARACTER*1
108 *> = 'N': Compute eigenvalues only;
109 *> = 'V': Compute eigenvalues and eigenvectors.
114 *> RANGE is CHARACTER*1
115 *> = 'A': all eigenvalues will be found.
116 *> = 'V': all eigenvalues in the half-open interval (VL,VU]
118 *> = 'I': the IL-th through IU-th eigenvalues will be found.
119 *> For RANGE = 'V' or 'I' and IU - IL < N - 1, SSTEBZ and
125 *> UPLO is CHARACTER*1
126 *> = 'U': Upper triangle of A is stored;
127 *> = 'L': Lower triangle of A is stored.
133 *> The order of the matrix A. N >= 0.
138 *> A is COMPLEX array, dimension (LDA, N)
139 *> On entry, the Hermitian matrix A. If UPLO = 'U', the
140 *> leading N-by-N upper triangular part of A contains the
141 *> upper triangular part of the matrix A. If UPLO = 'L',
142 *> the leading N-by-N lower triangular part of A contains
143 *> the lower triangular part of the matrix A.
144 *> On exit, the lower triangle (if UPLO='L') or the upper
145 *> triangle (if UPLO='U') of A, including the diagonal, is
152 *> The leading dimension of the array A. LDA >= max(1,N).
158 *> If RANGE='V', the lower bound of the interval to
159 *> be searched for eigenvalues. VL < VU.
160 *> Not referenced if RANGE = 'A' or 'I'.
166 *> If RANGE='V', the upper bound of the interval to
167 *> be searched for eigenvalues. VL < VU.
168 *> Not referenced if RANGE = 'A' or 'I'.
174 *> If RANGE='I', the index of the
175 *> smallest eigenvalue to be returned.
176 *> 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.
177 *> Not referenced if RANGE = 'A' or 'V'.
183 *> If RANGE='I', the index of the
184 *> largest eigenvalue to be returned.
185 *> 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.
186 *> Not referenced if RANGE = 'A' or 'V'.
192 *> The absolute error tolerance for the eigenvalues.
193 *> An approximate eigenvalue is accepted as converged
194 *> when it is determined to lie in an interval [a,b]
195 *> of width less than or equal to
197 *> ABSTOL + EPS * max( |a|,|b| ) ,
199 *> where EPS is the machine precision. If ABSTOL is less than
200 *> or equal to zero, then EPS*|T| will be used in its place,
201 *> where |T| is the 1-norm of the tridiagonal matrix obtained
202 *> by reducing A to tridiagonal form.
204 *> See "Computing Small Singular Values of Bidiagonal Matrices
205 *> with Guaranteed High Relative Accuracy," by Demmel and
206 *> Kahan, LAPACK Working Note #3.
208 *> If high relative accuracy is important, set ABSTOL to
209 *> SLAMCH( 'Safe minimum' ). Doing so will guarantee that
210 *> eigenvalues are computed to high relative accuracy when
211 *> possible in future releases. The current code does not
212 *> make any guarantees about high relative accuracy, but
213 *> furutre releases will. See J. Barlow and J. Demmel,
214 *> "Computing Accurate Eigensystems of Scaled Diagonally
215 *> Dominant Matrices", LAPACK Working Note #7, for a discussion
216 *> of which matrices define their eigenvalues to high relative
223 *> The total number of eigenvalues found. 0 <= M <= N.
224 *> If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1.
229 *> W is REAL array, dimension (N)
230 *> The first M elements contain the selected eigenvalues in
236 *> Z is COMPLEX array, dimension (LDZ, max(1,M))
237 *> If JOBZ = 'V', then if INFO = 0, the first M columns of Z
238 *> contain the orthonormal eigenvectors of the matrix A
239 *> corresponding to the selected eigenvalues, with the i-th
240 *> column of Z holding the eigenvector associated with W(i).
241 *> If JOBZ = 'N', then Z is not referenced.
242 *> Note: the user must ensure that at least max(1,M) columns are
243 *> supplied in the array Z; if RANGE = 'V', the exact value of M
244 *> is not known in advance and an upper bound must be used.
250 *> The leading dimension of the array Z. LDZ >= 1, and if
251 *> JOBZ = 'V', LDZ >= max(1,N).
254 *> \param[out] ISUPPZ
256 *> ISUPPZ is INTEGER array, dimension ( 2*max(1,M) )
257 *> The support of the eigenvectors in Z, i.e., the indices
258 *> indicating the nonzero elements in Z. The i-th eigenvector
259 *> is nonzero only in elements ISUPPZ( 2*i-1 ) through
261 *> Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1
266 *> WORK is COMPLEX array, dimension (MAX(1,LWORK))
267 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
273 *> The length of the array WORK. LWORK >= max(1,2*N).
274 *> For optimal efficiency, LWORK >= (NB+1)*N,
275 *> where NB is the max of the blocksize for CHETRD and for
276 *> CUNMTR as returned by ILAENV.
278 *> If LWORK = -1, then a workspace query is assumed; the routine
279 *> only calculates the optimal sizes of the WORK, RWORK and
280 *> IWORK arrays, returns these values as the first entries of
281 *> the WORK, RWORK and IWORK arrays, and no error message
282 *> related to LWORK or LRWORK or LIWORK is issued by XERBLA.
287 *> RWORK is REAL array, dimension (MAX(1,LRWORK))
288 *> On exit, if INFO = 0, RWORK(1) returns the optimal
289 *> (and minimal) LRWORK.
295 *> The length of the array RWORK. LRWORK >= max(1,24*N).
297 *> If LRWORK = -1, then a workspace query is assumed; the
298 *> routine only calculates the optimal sizes of the WORK, RWORK
299 *> and IWORK arrays, returns these values as the first entries
300 *> of the WORK, RWORK and IWORK arrays, and no error message
301 *> related to LWORK or LRWORK or LIWORK is issued by XERBLA.
306 *> IWORK is INTEGER array, dimension (MAX(1,LIWORK))
307 *> On exit, if INFO = 0, IWORK(1) returns the optimal
308 *> (and minimal) LIWORK.
314 *> The dimension of the array IWORK. LIWORK >= max(1,10*N).
316 *> If LIWORK = -1, then a workspace query is assumed; the
317 *> routine only calculates the optimal sizes of the WORK, RWORK
318 *> and IWORK arrays, returns these values as the first entries
319 *> of the WORK, RWORK and IWORK arrays, and no error message
320 *> related to LWORK or LRWORK or LIWORK is issued by XERBLA.
326 *> = 0: successful exit
327 *> < 0: if INFO = -i, the i-th argument had an illegal value
328 *> > 0: Internal error
334 *> \author Univ. of Tennessee
335 *> \author Univ. of California Berkeley
336 *> \author Univ. of Colorado Denver
341 *> \ingroup complexHEeigen
343 *> \par Contributors:
346 *> Inderjit Dhillon, IBM Almaden, USA \n
347 *> Osni Marques, LBNL/NERSC, USA \n
348 *> Ken Stanley, Computer Science Division, University of
349 *> California at Berkeley, USA \n
350 *> Jason Riedy, Computer Science Division, University of
351 *> California at Berkeley, USA \n
353 * =====================================================================
354 SUBROUTINE CHEEVR( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU,
355 $ ABSTOL, M, W, Z, LDZ, ISUPPZ, WORK, LWORK,
356 $ RWORK, LRWORK, IWORK, LIWORK, INFO )
358 * -- LAPACK driver routine (version 3.6.1) --
359 * -- LAPACK is a software package provided by Univ. of Tennessee, --
360 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
363 * .. Scalar Arguments ..
364 CHARACTER JOBZ, RANGE, UPLO
365 INTEGER IL, INFO, IU, LDA, LDZ, LIWORK, LRWORK, LWORK,
369 * .. Array Arguments ..
370 INTEGER ISUPPZ( * ), IWORK( * )
371 REAL RWORK( * ), W( * )
372 COMPLEX A( LDA, * ), WORK( * ), Z( LDZ, * )
375 * =====================================================================
379 PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0, TWO = 2.0E+0 )
381 * .. Local Scalars ..
382 LOGICAL ALLEIG, INDEIG, LOWER, LQUERY, TEST, VALEIG,
385 INTEGER I, IEEEOK, IINFO, IMAX, INDIBL, INDIFL, INDISP,
386 $ INDIWO, INDRD, INDRDD, INDRE, INDREE, INDRWK,
387 $ INDTAU, INDWK, INDWKN, ISCALE, ITMP1, J, JJ,
388 $ LIWMIN, LLWORK, LLRWORK, LLWRKN, LRWMIN,
389 $ LWKOPT, LWMIN, NB, NSPLIT
390 REAL ABSTLL, ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN,
391 $ SIGMA, SMLNUM, TMP1, VLL, VUU
393 * .. External Functions ..
397 EXTERNAL LSAME, ILAENV, CLANSY, SLAMCH
399 * .. External Subroutines ..
400 EXTERNAL CHETRD, CSSCAL, CSTEMR, CSTEIN, CSWAP, CUNMTR,
401 $ SCOPY, SSCAL, SSTEBZ, SSTERF, XERBLA
403 * .. Intrinsic Functions ..
404 INTRINSIC MAX, MIN, REAL, SQRT
406 * .. Executable Statements ..
408 * Test the input parameters.
410 IEEEOK = ILAENV( 10, 'CHEEVR', 'N', 1, 2, 3, 4 )
412 LOWER = LSAME( UPLO, 'L' )
413 WANTZ = LSAME( JOBZ, 'V' )
414 ALLEIG = LSAME( RANGE, 'A' )
415 VALEIG = LSAME( RANGE, 'V' )
416 INDEIG = LSAME( RANGE, 'I' )
418 LQUERY = ( ( LWORK.EQ.-1 ) .OR. ( LRWORK.EQ.-1 ) .OR.
421 LRWMIN = MAX( 1, 24*N )
422 LIWMIN = MAX( 1, 10*N )
423 LWMIN = MAX( 1, 2*N )
426 IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
428 ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN
430 ELSE IF( .NOT.( LOWER .OR. LSAME( UPLO, 'U' ) ) ) THEN
432 ELSE IF( N.LT.0 ) THEN
434 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
438 IF( N.GT.0 .AND. VU.LE.VL )
440 ELSE IF( INDEIG ) THEN
441 IF( IL.LT.1 .OR. IL.GT.MAX( 1, N ) ) THEN
443 ELSE IF( IU.LT.MIN( N, IL ) .OR. IU.GT.N ) THEN
449 IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
455 NB = ILAENV( 1, 'CHETRD', UPLO, N, -1, -1, -1 )
456 NB = MAX( NB, ILAENV( 1, 'CUNMTR', UPLO, N, -1, -1, -1 ) )
457 LWKOPT = MAX( ( NB+1 )*N, LWMIN )
462 IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
464 ELSE IF( LRWORK.LT.LRWMIN .AND. .NOT.LQUERY ) THEN
466 ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
472 CALL XERBLA( 'CHEEVR', -INFO )
474 ELSE IF( LQUERY ) THEN
478 * Quick return if possible
488 IF( ALLEIG .OR. INDEIG ) THEN
490 W( 1 ) = REAL( A( 1, 1 ) )
492 IF( VL.LT.REAL( A( 1, 1 ) ) .AND. VU.GE.REAL( A( 1, 1 ) ) )
495 W( 1 ) = REAL( A( 1, 1 ) )
506 * Get machine constants.
508 SAFMIN = SLAMCH( 'Safe minimum' )
509 EPS = SLAMCH( 'Precision' )
510 SMLNUM = SAFMIN / EPS
511 BIGNUM = ONE / SMLNUM
512 RMIN = SQRT( SMLNUM )
513 RMAX = MIN( SQRT( BIGNUM ), ONE / SQRT( SQRT( SAFMIN ) ) )
515 * Scale matrix to allowable range, if necessary.
523 ANRM = CLANSY( 'M', UPLO, N, A, LDA, RWORK )
524 IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN
527 ELSE IF( ANRM.GT.RMAX ) THEN
531 IF( ISCALE.EQ.1 ) THEN
534 CALL CSSCAL( N-J+1, SIGMA, A( J, J ), 1 )
538 CALL CSSCAL( J, SIGMA, A( 1, J ), 1 )
542 $ ABSTLL = ABSTOL*SIGMA
549 * Initialize indices into workspaces. Note: The IWORK indices are
550 * used only if SSTERF or CSTEMR fail.
552 * WORK(INDTAU:INDTAU+N-1) stores the complex scalar factors of the
553 * elementary reflectors used in CHETRD.
555 * INDWK is the starting offset of the remaining complex workspace,
556 * and LLWORK is the remaining complex workspace size.
558 LLWORK = LWORK - INDWK + 1
560 * RWORK(INDRD:INDRD+N-1) stores the real tridiagonal's diagonal
563 * RWORK(INDRE:INDRE+N-1) stores the off-diagonal entries of the
564 * tridiagonal matrix from CHETRD.
566 * RWORK(INDRDD:INDRDD+N-1) is a copy of the diagonal entries over
567 * -written by CSTEMR (the SSTERF path copies the diagonal to W).
569 * RWORK(INDREE:INDREE+N-1) is a copy of the off-diagonal entries over
570 * -written while computing the eigenvalues in SSTERF and CSTEMR.
572 * INDRWK is the starting offset of the left-over real workspace, and
573 * LLRWORK is the remaining workspace size.
575 LLRWORK = LRWORK - INDRWK + 1
577 * IWORK(INDIBL:INDIBL+M-1) corresponds to IBLOCK in SSTEBZ and
578 * stores the block indices of each of the M<=N eigenvalues.
580 * IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in SSTEBZ and
581 * stores the starting and finishing indices of each block.
583 * IWORK(INDIFL:INDIFL+N-1) stores the indices of eigenvectors
584 * that corresponding to eigenvectors that fail to converge in
585 * SSTEIN. This information is discarded; if any fail, the driver
588 * INDIWO is the offset of the remaining integer workspace.
592 * Call CHETRD to reduce Hermitian matrix to tridiagonal form.
594 CALL CHETRD( UPLO, N, A, LDA, RWORK( INDRD ), RWORK( INDRE ),
595 $ WORK( INDTAU ), WORK( INDWK ), LLWORK, IINFO )
597 * If all eigenvalues are desired
598 * then call SSTERF or CSTEMR and CUNMTR.
602 IF( IL.EQ.1 .AND. IU.EQ.N ) THEN
606 IF( ( ALLEIG.OR.TEST ) .AND. ( IEEEOK.EQ.1 ) ) THEN
607 IF( .NOT.WANTZ ) THEN
608 CALL SCOPY( N, RWORK( INDRD ), 1, W, 1 )
609 CALL SCOPY( N-1, RWORK( INDRE ), 1, RWORK( INDREE ), 1 )
610 CALL SSTERF( N, W, RWORK( INDREE ), INFO )
612 CALL SCOPY( N-1, RWORK( INDRE ), 1, RWORK( INDREE ), 1 )
613 CALL SCOPY( N, RWORK( INDRD ), 1, RWORK( INDRDD ), 1 )
615 IF (ABSTOL .LE. TWO*N*EPS) THEN
620 CALL CSTEMR( JOBZ, 'A', N, RWORK( INDRDD ),
621 $ RWORK( INDREE ), VL, VU, IL, IU, M, W,
622 $ Z, LDZ, N, ISUPPZ, TRYRAC,
623 $ RWORK( INDRWK ), LLRWORK,
624 $ IWORK, LIWORK, INFO )
626 * Apply unitary matrix used in reduction to tridiagonal
627 * form to eigenvectors returned by CSTEIN.
629 IF( WANTZ .AND. INFO.EQ.0 ) THEN
631 LLWRKN = LWORK - INDWKN + 1
632 CALL CUNMTR( 'L', UPLO, 'N', N, M, A, LDA,
633 $ WORK( INDTAU ), Z, LDZ, WORK( INDWKN ),
646 * Otherwise, call SSTEBZ and, if eigenvectors are desired, CSTEIN.
647 * Also call SSTEBZ and CSTEIN if CSTEMR fails.
655 CALL SSTEBZ( RANGE, ORDER, N, VLL, VUU, IL, IU, ABSTLL,
656 $ RWORK( INDRD ), RWORK( INDRE ), M, NSPLIT, W,
657 $ IWORK( INDIBL ), IWORK( INDISP ), RWORK( INDRWK ),
658 $ IWORK( INDIWO ), INFO )
661 CALL CSTEIN( N, RWORK( INDRD ), RWORK( INDRE ), M, W,
662 $ IWORK( INDIBL ), IWORK( INDISP ), Z, LDZ,
663 $ RWORK( INDRWK ), IWORK( INDIWO ), IWORK( INDIFL ),
666 * Apply unitary matrix used in reduction to tridiagonal
667 * form to eigenvectors returned by CSTEIN.
670 LLWRKN = LWORK - INDWKN + 1
671 CALL CUNMTR( 'L', UPLO, 'N', N, M, A, LDA, WORK( INDTAU ), Z,
672 $ LDZ, WORK( INDWKN ), LLWRKN, IINFO )
675 * If matrix was scaled, then rescale eigenvalues appropriately.
678 IF( ISCALE.EQ.1 ) THEN
684 CALL SSCAL( IMAX, ONE / SIGMA, W, 1 )
687 * If eigenvalues are not in order, then sort them, along with
695 IF( W( JJ ).LT.TMP1 ) THEN
702 ITMP1 = IWORK( INDIBL+I-1 )
704 IWORK( INDIBL+I-1 ) = IWORK( INDIBL+J-1 )
706 IWORK( INDIBL+J-1 ) = ITMP1
707 CALL CSWAP( N, Z( 1, I ), 1, Z( 1, J ), 1 )
712 * Set WORK(1) to optimal workspace size.