1 *> \brief <b> SSTEVR computes the eigenvalues and, optionally, the left and/or right eigenvectors for OTHER matrices</b>
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download SSTEVR + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sstevr.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sstevr.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sstevr.f">
21 * SUBROUTINE SSTEVR( JOBZ, RANGE, N, D, E, VL, VU, IL, IU, ABSTOL,
22 * M, W, Z, LDZ, ISUPPZ, WORK, LWORK, IWORK,
25 * .. Scalar Arguments ..
26 * CHARACTER JOBZ, RANGE
27 * INTEGER IL, INFO, IU, LDZ, LIWORK, LWORK, M, N
30 * .. Array Arguments ..
31 * INTEGER ISUPPZ( * ), IWORK( * )
32 * REAL D( * ), E( * ), W( * ), WORK( * ), Z( LDZ, * )
41 *> SSTEVR computes selected eigenvalues and, optionally, eigenvectors
42 *> of a real symmetric tridiagonal matrix T. Eigenvalues and
43 *> eigenvectors can be selected by specifying either a range of values
44 *> or a range of indices for the desired eigenvalues.
46 *> Whenever possible, SSTEVR calls SSTEMR to compute the
47 *> eigenspectrum using Relatively Robust Representations. SSTEMR
48 *> computes eigenvalues by the dqds algorithm, while orthogonal
49 *> eigenvectors are computed from various "good" L D L^T representations
50 *> (also known as Relatively Robust Representations). Gram-Schmidt
51 *> orthogonalization is avoided as far as possible. More specifically,
52 *> the various steps of the algorithm are as follows. For the i-th
53 *> unreduced block of T,
54 *> (a) Compute T - sigma_i = L_i D_i L_i^T, such that L_i D_i L_i^T
55 *> is a relatively robust representation,
56 *> (b) Compute the eigenvalues, lambda_j, of L_i D_i L_i^T to high
57 *> relative accuracy by the dqds algorithm,
58 *> (c) If there is a cluster of close eigenvalues, "choose" sigma_i
59 *> close to the cluster, and go to step (a),
60 *> (d) Given the approximate eigenvalue lambda_j of L_i D_i L_i^T,
61 *> compute the corresponding eigenvector by forming a
62 *> rank-revealing twisted factorization.
63 *> The desired accuracy of the output can be specified by the input
66 *> For more details, see "A new O(n^2) algorithm for the symmetric
67 *> tridiagonal eigenvalue/eigenvector problem", by Inderjit Dhillon,
68 *> Computer Science Division Technical Report No. UCB//CSD-97-971,
69 *> UC Berkeley, May 1997.
72 *> Note 1 : SSTEVR calls SSTEMR when the full spectrum is requested
73 *> on machines which conform to the ieee-754 floating point standard.
74 *> SSTEVR calls SSTEBZ and SSTEIN on non-ieee machines and
75 *> when partial spectrum requests are made.
77 *> Normal execution of SSTEMR may create NaNs and infinities and
78 *> hence may abort due to a floating point exception in environments
79 *> which do not handle NaNs and infinities in the ieee standard default
88 *> JOBZ is CHARACTER*1
89 *> = 'N': Compute eigenvalues only;
90 *> = 'V': Compute eigenvalues and eigenvectors.
95 *> RANGE is CHARACTER*1
96 *> = 'A': all eigenvalues will be found.
97 *> = 'V': all eigenvalues in the half-open interval (VL,VU]
99 *> = 'I': the IL-th through IU-th eigenvalues will be found.
100 *> For RANGE = 'V' or 'I' and IU - IL < N - 1, SSTEBZ and
107 *> The order of the matrix. N >= 0.
112 *> D is REAL array, dimension (N)
113 *> On entry, the n diagonal elements of the tridiagonal matrix
115 *> On exit, D may be multiplied by a constant factor chosen
116 *> to avoid over/underflow in computing the eigenvalues.
121 *> E is REAL array, dimension (max(1,N-1))
122 *> On entry, the (n-1) subdiagonal elements of the tridiagonal
123 *> matrix A in elements 1 to N-1 of E.
124 *> On exit, E may be multiplied by a constant factor chosen
125 *> to avoid over/underflow in computing the eigenvalues.
131 *> If RANGE='V', the lower bound of the interval to
132 *> be searched for eigenvalues. VL < VU.
133 *> Not referenced if RANGE = 'A' or 'I'.
139 *> If RANGE='V', the upper bound of the interval to
140 *> be searched for eigenvalues. VL < VU.
141 *> Not referenced if RANGE = 'A' or 'I'.
147 *> If RANGE='I', the index of the
148 *> smallest eigenvalue to be returned.
149 *> 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.
150 *> Not referenced if RANGE = 'A' or 'V'.
156 *> If RANGE='I', the index of the
157 *> largest eigenvalue to be returned.
158 *> 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.
159 *> Not referenced if RANGE = 'A' or 'V'.
165 *> The absolute error tolerance for the eigenvalues.
166 *> An approximate eigenvalue is accepted as converged
167 *> when it is determined to lie in an interval [a,b]
168 *> of width less than or equal to
170 *> ABSTOL + EPS * max( |a|,|b| ) ,
172 *> where EPS is the machine precision. If ABSTOL is less than
173 *> or equal to zero, then EPS*|T| will be used in its place,
174 *> where |T| is the 1-norm of the tridiagonal matrix obtained
175 *> by reducing A to tridiagonal form.
177 *> See "Computing Small Singular Values of Bidiagonal Matrices
178 *> with Guaranteed High Relative Accuracy," by Demmel and
179 *> Kahan, LAPACK Working Note #3.
181 *> If high relative accuracy is important, set ABSTOL to
182 *> SLAMCH( 'Safe minimum' ). Doing so will guarantee that
183 *> eigenvalues are computed to high relative accuracy when
184 *> possible in future releases. The current code does not
185 *> make any guarantees about high relative accuracy, but
186 *> future releases will. See J. Barlow and J. Demmel,
187 *> "Computing Accurate Eigensystems of Scaled Diagonally
188 *> Dominant Matrices", LAPACK Working Note #7, for a discussion
189 *> of which matrices define their eigenvalues to high relative
196 *> The total number of eigenvalues found. 0 <= M <= N.
197 *> If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1.
202 *> W is REAL array, dimension (N)
203 *> The first M elements contain the selected eigenvalues in
209 *> Z is REAL array, dimension (LDZ, max(1,M) )
210 *> If JOBZ = 'V', then if INFO = 0, the first M columns of Z
211 *> contain the orthonormal eigenvectors of the matrix A
212 *> corresponding to the selected eigenvalues, with the i-th
213 *> column of Z holding the eigenvector associated with W(i).
214 *> Note: the user must ensure that at least max(1,M) columns are
215 *> supplied in the array Z; if RANGE = 'V', the exact value of M
216 *> is not known in advance and an upper bound must be used.
222 *> The leading dimension of the array Z. LDZ >= 1, and if
223 *> JOBZ = 'V', LDZ >= max(1,N).
226 *> \param[out] ISUPPZ
228 *> ISUPPZ is INTEGER array, dimension ( 2*max(1,M) )
229 *> The support of the eigenvectors in Z, i.e., the indices
230 *> indicating the nonzero elements in Z. The i-th eigenvector
231 *> is nonzero only in elements ISUPPZ( 2*i-1 ) through
233 *> Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1
238 *> WORK is REAL array, dimension (MAX(1,LWORK))
239 *> On exit, if INFO = 0, WORK(1) returns the optimal (and
246 *> The dimension of the array WORK. LWORK >= 20*N.
248 *> If LWORK = -1, then a workspace query is assumed; the routine
249 *> only calculates the optimal sizes of the WORK and IWORK
250 *> arrays, returns these values as the first entries of the WORK
251 *> and IWORK arrays, and no error message related to LWORK or
252 *> LIWORK is issued by XERBLA.
257 *> IWORK is INTEGER array, dimension (MAX(1,LIWORK))
258 *> On exit, if INFO = 0, IWORK(1) returns the optimal (and
265 *> The dimension of the array IWORK. LIWORK >= 10*N.
267 *> If LIWORK = -1, then a workspace query is assumed; the
268 *> routine only calculates the optimal sizes of the WORK and
269 *> IWORK arrays, returns these values as the first entries of
270 *> the WORK and IWORK arrays, and no error message related to
271 *> LWORK or LIWORK is issued by XERBLA.
277 *> = 0: successful exit
278 *> < 0: if INFO = -i, the i-th argument had an illegal value
279 *> > 0: Internal error
285 *> \author Univ. of Tennessee
286 *> \author Univ. of California Berkeley
287 *> \author Univ. of Colorado Denver
292 *> \ingroup realOTHEReigen
294 *> \par Contributors:
297 *> Inderjit Dhillon, IBM Almaden, USA \n
298 *> Osni Marques, LBNL/NERSC, USA \n
299 *> Ken Stanley, Computer Science Division, University of
300 *> California at Berkeley, USA \n
301 *> Jason Riedy, Computer Science Division, University of
302 *> California at Berkeley, USA \n
304 * =====================================================================
305 SUBROUTINE SSTEVR( JOBZ, RANGE, N, D, E, VL, VU, IL, IU, ABSTOL,
306 $ M, W, Z, LDZ, ISUPPZ, WORK, LWORK, IWORK,
309 * -- LAPACK driver routine (version 3.6.1) --
310 * -- LAPACK is a software package provided by Univ. of Tennessee, --
311 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
314 * .. Scalar Arguments ..
315 CHARACTER JOBZ, RANGE
316 INTEGER IL, INFO, IU, LDZ, LIWORK, LWORK, M, N
319 * .. Array Arguments ..
320 INTEGER ISUPPZ( * ), IWORK( * )
321 REAL D( * ), E( * ), W( * ), WORK( * ), Z( LDZ, * )
324 * =====================================================================
328 PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0, TWO = 2.0E+0 )
330 * .. Local Scalars ..
331 LOGICAL ALLEIG, INDEIG, TEST, LQUERY, VALEIG, WANTZ,
334 INTEGER I, IEEEOK, IMAX, INDIBL, INDIFL, INDISP,
335 $ INDIWO, ISCALE, J, JJ, LIWMIN, LWMIN, NSPLIT
336 REAL BIGNUM, EPS, RMAX, RMIN, SAFMIN, SIGMA, SMLNUM,
337 $ TMP1, TNRM, VLL, VUU
339 * .. External Functions ..
343 EXTERNAL LSAME, ILAENV, SLAMCH, SLANST
345 * .. External Subroutines ..
346 EXTERNAL SCOPY, SSCAL, SSTEBZ, SSTEMR, SSTEIN, SSTERF,
349 * .. Intrinsic Functions ..
350 INTRINSIC MAX, MIN, SQRT
352 * .. Executable Statements ..
355 * Test the input parameters.
357 IEEEOK = ILAENV( 10, 'SSTEVR', 'N', 1, 2, 3, 4 )
359 WANTZ = LSAME( JOBZ, 'V' )
360 ALLEIG = LSAME( RANGE, 'A' )
361 VALEIG = LSAME( RANGE, 'V' )
362 INDEIG = LSAME( RANGE, 'I' )
364 LQUERY = ( ( LWORK.EQ.-1 ) .OR. ( LIWORK.EQ.-1 ) )
365 LWMIN = MAX( 1, 20*N )
366 LIWMIN = MAX(1, 10*N )
370 IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
372 ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN
374 ELSE IF( N.LT.0 ) THEN
378 IF( N.GT.0 .AND. VU.LE.VL )
380 ELSE IF( INDEIG ) THEN
381 IF( IL.LT.1 .OR. IL.GT.MAX( 1, N ) ) THEN
383 ELSE IF( IU.LT.MIN( N, IL ) .OR. IU.GT.N ) THEN
389 IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
398 IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
400 ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
406 CALL XERBLA( 'SSTEVR', -INFO )
408 ELSE IF( LQUERY ) THEN
412 * Quick return if possible
419 IF( ALLEIG .OR. INDEIG ) THEN
423 IF( VL.LT.D( 1 ) .AND. VU.GE.D( 1 ) ) THEN
433 * Get machine constants.
435 SAFMIN = SLAMCH( 'Safe minimum' )
436 EPS = SLAMCH( 'Precision' )
437 SMLNUM = SAFMIN / EPS
438 BIGNUM = ONE / SMLNUM
439 RMIN = SQRT( SMLNUM )
440 RMAX = MIN( SQRT( BIGNUM ), ONE / SQRT( SQRT( SAFMIN ) ) )
443 * Scale matrix to allowable range, if necessary.
451 TNRM = SLANST( 'M', N, D, E )
452 IF( TNRM.GT.ZERO .AND. TNRM.LT.RMIN ) THEN
455 ELSE IF( TNRM.GT.RMAX ) THEN
459 IF( ISCALE.EQ.1 ) THEN
460 CALL SSCAL( N, SIGMA, D, 1 )
461 CALL SSCAL( N-1, SIGMA, E( 1 ), 1 )
468 * Initialize indices into workspaces. Note: These indices are used only
469 * if SSTERF or SSTEMR fail.
471 * IWORK(INDIBL:INDIBL+M-1) corresponds to IBLOCK in SSTEBZ and
472 * stores the block indices of each of the M<=N eigenvalues.
474 * IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in SSTEBZ and
475 * stores the starting and finishing indices of each block.
477 * IWORK(INDIFL:INDIFL+N-1) stores the indices of eigenvectors
478 * that corresponding to eigenvectors that fail to converge in
479 * SSTEIN. This information is discarded; if any fail, the driver
482 * INDIWO is the offset of the remaining integer workspace.
485 * If all eigenvalues are desired, then
486 * call SSTERF or SSTEMR. If this fails for some eigenvalue, then
492 IF( IL.EQ.1 .AND. IU.EQ.N ) THEN
496 IF( ( ALLEIG .OR. TEST ) .AND. IEEEOK.EQ.1 ) THEN
497 CALL SCOPY( N-1, E( 1 ), 1, WORK( 1 ), 1 )
498 IF( .NOT.WANTZ ) THEN
499 CALL SCOPY( N, D, 1, W, 1 )
500 CALL SSTERF( N, W, WORK, INFO )
502 CALL SCOPY( N, D, 1, WORK( N+1 ), 1 )
503 IF (ABSTOL .LE. TWO*N*EPS) THEN
508 CALL SSTEMR( JOBZ, 'A', N, WORK( N+1 ), WORK, VL, VU, IL,
509 $ IU, M, W, Z, LDZ, N, ISUPPZ, TRYRAC,
510 $ WORK( 2*N+1 ), LWORK-2*N, IWORK, LIWORK, INFO )
520 * Otherwise, call SSTEBZ and, if eigenvectors are desired, SSTEIN.
528 CALL SSTEBZ( RANGE, ORDER, N, VLL, VUU, IL, IU, ABSTOL, D, E, M,
529 $ NSPLIT, W, IWORK( INDIBL ), IWORK( INDISP ), WORK,
530 $ IWORK( INDIWO ), INFO )
533 CALL SSTEIN( N, D, E, M, W, IWORK( INDIBL ), IWORK( INDISP ),
534 $ Z, LDZ, WORK, IWORK( INDIWO ), IWORK( INDIFL ),
538 * If matrix was scaled, then rescale eigenvalues appropriately.
541 IF( ISCALE.EQ.1 ) THEN
547 CALL SSCAL( IMAX, ONE / SIGMA, W, 1 )
550 * If eigenvalues are not in order, then sort them, along with
558 IF( W( JJ ).LT.TMP1 ) THEN
567 CALL SSWAP( N, Z( 1, I ), 1, Z( 1, J ), 1 )
572 * Causes problems with tests 19 & 20:
573 * IF (wantz .and. INDEIG ) Z( 1,1) = Z(1,1) / 1.002 + .002