3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download SSTEMR + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sstemr.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sstemr.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sstemr.f">
21 * SUBROUTINE SSTEMR( JOBZ, RANGE, N, D, E, VL, VU, IL, IU,
22 * M, W, Z, LDZ, NZC, ISUPPZ, TRYRAC, WORK, LWORK,
23 * IWORK, LIWORK, INFO )
25 * .. Scalar Arguments ..
26 * CHARACTER JOBZ, RANGE
28 * INTEGER IL, INFO, IU, LDZ, NZC, LIWORK, LWORK, M, N
31 * .. Array Arguments ..
32 * INTEGER ISUPPZ( * ), IWORK( * )
33 * REAL D( * ), E( * ), W( * ), WORK( * )
43 *> SSTEMR computes selected eigenvalues and, optionally, eigenvectors
44 *> of a real symmetric tridiagonal matrix T. Any such unreduced matrix has
45 *> a well defined set of pairwise different real eigenvalues, the corresponding
46 *> real eigenvectors are pairwise orthogonal.
48 *> The spectrum may be computed either completely or partially by specifying
49 *> either an interval (VL,VU] or a range of indices IL:IU for the desired
52 *> Depending on the number of desired eigenvalues, these are computed either
53 *> by bisection or the dqds algorithm. Numerically orthogonal eigenvectors are
54 *> computed by the use of various suitable L D L^T factorizations near clusters
55 *> of close eigenvalues (referred to as RRRs, Relatively Robust
56 *> Representations). An informal sketch of the algorithm follows.
58 *> For each unreduced block (submatrix) of T,
59 *> (a) Compute T - sigma I = L D L^T, so that L and D
60 *> define all the wanted eigenvalues to high relative accuracy.
61 *> This means that small relative changes in the entries of D and L
62 *> cause only small relative changes in the eigenvalues and
63 *> eigenvectors. The standard (unfactored) representation of the
64 *> tridiagonal matrix T does not have this property in general.
65 *> (b) Compute the eigenvalues to suitable accuracy.
66 *> If the eigenvectors are desired, the algorithm attains full
67 *> accuracy of the computed eigenvalues only right before
68 *> the corresponding vectors have to be computed, see steps c) and d).
69 *> (c) For each cluster of close eigenvalues, select a new
70 *> shift close to the cluster, find a new factorization, and refine
71 *> the shifted eigenvalues to suitable accuracy.
72 *> (d) For each eigenvalue with a large enough relative separation compute
73 *> the corresponding eigenvector by forming a rank revealing twisted
74 *> factorization. Go back to (c) for any clusters that remain.
76 *> For more details, see:
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 *> 1.SSTEMR works only on machines which follow IEEE-754
90 *> floating-point standard in their handling of infinities and NaNs.
91 *> This permits the use of efficient inner loops avoiding a check for
100 *> JOBZ is CHARACTER*1
101 *> = 'N': Compute eigenvalues only;
102 *> = 'V': Compute eigenvalues and eigenvectors.
107 *> RANGE is CHARACTER*1
108 *> = 'A': all eigenvalues will be found.
109 *> = 'V': all eigenvalues in the half-open interval (VL,VU]
111 *> = 'I': the IL-th through IU-th eigenvalues will be found.
117 *> The order of the matrix. N >= 0.
122 *> D is REAL array, dimension (N)
123 *> On entry, the N diagonal elements of the tridiagonal matrix
124 *> T. On exit, D is overwritten.
129 *> E is REAL array, dimension (N)
130 *> On entry, the (N-1) subdiagonal elements of the tridiagonal
131 *> matrix T in elements 1 to N-1 of E. E(N) need not be set on
132 *> input, but is used internally as workspace.
133 *> On exit, E is overwritten.
140 *> If RANGE='V', the lower bound of the interval to
141 *> be searched for eigenvalues. VL < VU.
142 *> Not referenced if RANGE = 'A' or 'I'.
149 *> If RANGE='V', the upper bound of the interval to
150 *> be searched for eigenvalues. VL < VU.
151 *> Not referenced if RANGE = 'A' or 'I'.
158 *> If RANGE='I', the index of the
159 *> smallest eigenvalue to be returned.
160 *> 1 <= IL <= IU <= N, if N > 0.
161 *> Not referenced if RANGE = 'A' or 'V'.
168 *> If RANGE='I', the index of the
169 *> largest eigenvalue to be returned.
170 *> 1 <= IL <= IU <= N, if N > 0.
171 *> Not referenced if RANGE = 'A' or 'V'.
177 *> The total number of eigenvalues found. 0 <= M <= N.
178 *> If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1.
183 *> W is REAL array, dimension (N)
184 *> The first M elements contain the selected eigenvalues in
190 *> Z is REAL array, dimension (LDZ, max(1,M) )
191 *> If JOBZ = 'V', and if INFO = 0, then the first M columns of Z
192 *> contain the orthonormal eigenvectors of the matrix T
193 *> corresponding to the selected eigenvalues, with the i-th
194 *> column of Z holding the eigenvector associated with W(i).
195 *> If JOBZ = 'N', then Z is not referenced.
196 *> Note: the user must ensure that at least max(1,M) columns are
197 *> supplied in the array Z; if RANGE = 'V', the exact value of M
198 *> is not known in advance and can be computed with a workspace
199 *> query by setting NZC = -1, see below.
205 *> The leading dimension of the array Z. LDZ >= 1, and if
206 *> JOBZ = 'V', then LDZ >= max(1,N).
212 *> The number of eigenvectors to be held in the array Z.
213 *> If RANGE = 'A', then NZC >= max(1,N).
214 *> If RANGE = 'V', then NZC >= the number of eigenvalues in (VL,VU].
215 *> If RANGE = 'I', then NZC >= IU-IL+1.
216 *> If NZC = -1, then a workspace query is assumed; the
217 *> routine calculates the number of columns of the array Z that
218 *> are needed to hold the eigenvectors.
219 *> This value is returned as the first entry of the Z array, and
220 *> no error message related to NZC is issued by XERBLA.
223 *> \param[out] ISUPPZ
225 *> ISUPPZ is INTEGER ARRAY, dimension ( 2*max(1,M) )
226 *> The support of the eigenvectors in Z, i.e., the indices
227 *> indicating the nonzero elements in Z. The i-th computed eigenvector
228 *> is nonzero only in elements ISUPPZ( 2*i-1 ) through
229 *> ISUPPZ( 2*i ). This is relevant in the case when the matrix
230 *> is split. ISUPPZ is only accessed when JOBZ is 'V' and N > 0.
233 *> \param[in,out] TRYRAC
236 *> If TRYRAC.EQ..TRUE., indicates that the code should check whether
237 *> the tridiagonal matrix defines its eigenvalues to high relative
238 *> accuracy. If so, the code uses relative-accuracy preserving
239 *> algorithms that might be (a bit) slower depending on the matrix.
240 *> If the matrix does not define its eigenvalues to high relative
241 *> accuracy, the code can uses possibly faster algorithms.
242 *> If TRYRAC.EQ..FALSE., the code is not required to guarantee
243 *> relatively accurate eigenvalues and can use the fastest possible
245 *> On exit, a .TRUE. TRYRAC will be set to .FALSE. if the matrix
246 *> does not define its eigenvalues to high relative accuracy.
251 *> WORK is REAL array, dimension (LWORK)
252 *> On exit, if INFO = 0, WORK(1) returns the optimal
253 *> (and minimal) LWORK.
259 *> The dimension of the array WORK. LWORK >= max(1,18*N)
260 *> if JOBZ = 'V', and LWORK >= max(1,12*N) if JOBZ = 'N'.
261 *> If LWORK = -1, then a workspace query is assumed; the routine
262 *> only calculates the optimal size of the WORK array, returns
263 *> this value as the first entry of the WORK array, and no error
264 *> message related to LWORK is issued by XERBLA.
269 *> IWORK is INTEGER array, dimension (LIWORK)
270 *> On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.
276 *> The dimension of the array IWORK. LIWORK >= max(1,10*N)
277 *> if the eigenvectors are desired, and LIWORK >= max(1,8*N)
278 *> if only the eigenvalues are to be computed.
279 *> If LIWORK = -1, then a workspace query is assumed; the
280 *> routine only calculates the optimal size of the IWORK array,
281 *> returns this value as the first entry of the IWORK array, and
282 *> no error message related to LIWORK is issued by XERBLA.
289 *> = 0: successful exit
290 *> < 0: if INFO = -i, the i-th argument had an illegal value
291 *> > 0: if INFO = 1X, internal error in SLARRE,
292 *> if INFO = 2X, internal error in SLARRV.
293 *> Here, the digit X = ABS( IINFO ) < 10, where IINFO is
294 *> the nonzero error code returned by SLARRE or
295 *> SLARRV, respectively.
301 *> \author Univ. of Tennessee
302 *> \author Univ. of California Berkeley
303 *> \author Univ. of Colorado Denver
308 *> \ingroup realOTHERcomputational
310 *> \par Contributors:
313 *> Beresford Parlett, University of California, Berkeley, USA \n
314 *> Jim Demmel, University of California, Berkeley, USA \n
315 *> Inderjit Dhillon, University of Texas, Austin, USA \n
316 *> Osni Marques, LBNL/NERSC, USA \n
317 *> Christof Voemel, University of California, Berkeley, USA
319 * =====================================================================
320 SUBROUTINE SSTEMR( JOBZ, RANGE, N, D, E, VL, VU, IL, IU,
321 $ M, W, Z, LDZ, NZC, ISUPPZ, TRYRAC, WORK, LWORK,
322 $ IWORK, LIWORK, INFO )
324 * -- LAPACK computational routine (version 3.6.1) --
325 * -- LAPACK is a software package provided by Univ. of Tennessee, --
326 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
329 * .. Scalar Arguments ..
330 CHARACTER JOBZ, RANGE
332 INTEGER IL, INFO, IU, LDZ, NZC, LIWORK, LWORK, M, N
335 * .. Array Arguments ..
336 INTEGER ISUPPZ( * ), IWORK( * )
337 REAL D( * ), E( * ), W( * ), WORK( * )
341 * =====================================================================
344 REAL ZERO, ONE, FOUR, MINRGP
345 PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0,
349 * .. Local Scalars ..
350 LOGICAL ALLEIG, INDEIG, LQUERY, VALEIG, WANTZ, ZQUERY
351 INTEGER I, IBEGIN, IEND, IFIRST, IIL, IINDBL, IINDW,
352 $ IINDWK, IINFO, IINSPL, IIU, ILAST, IN, INDD,
353 $ INDE2, INDERR, INDGP, INDGRS, INDWRK, ITMP,
354 $ ITMP2, J, JBLK, JJ, LIWMIN, LWMIN, NSPLIT,
355 $ NZCMIN, OFFSET, WBEGIN, WEND
356 REAL BIGNUM, CS, EPS, PIVMIN, R1, R2, RMAX, RMIN,
357 $ RTOL1, RTOL2, SAFMIN, SCALE, SMLNUM, SN,
358 $ THRESH, TMP, TNRM, WL, WU
361 * .. External Functions ..
364 EXTERNAL LSAME, SLAMCH, SLANST
366 * .. External Subroutines ..
367 EXTERNAL SCOPY, SLAE2, SLAEV2, SLARRC, SLARRE, SLARRJ,
368 $ SLARRR, SLARRV, SLASRT, SSCAL, SSWAP, XERBLA
370 * .. Intrinsic Functions ..
371 INTRINSIC MAX, MIN, SQRT
373 * .. Executable Statements ..
375 * Test the input parameters.
377 WANTZ = LSAME( JOBZ, 'V' )
378 ALLEIG = LSAME( RANGE, 'A' )
379 VALEIG = LSAME( RANGE, 'V' )
380 INDEIG = LSAME( RANGE, 'I' )
382 LQUERY = ( ( LWORK.EQ.-1 ).OR.( LIWORK.EQ.-1 ) )
383 ZQUERY = ( NZC.EQ.-1 )
385 * SSTEMR needs WORK of size 6*N, IWORK of size 3*N.
386 * In addition, SLARRE needs WORK of size 6*N, IWORK of size 5*N.
387 * Furthermore, SLARRV needs WORK of size 12*N, IWORK of size 7*N.
392 * need less workspace if only the eigenvalues are wanted
404 * We do not reference VL, VU in the cases RANGE = 'I','A'
405 * The interval (WL, WU] contains all the wanted eigenvalues.
406 * It is either given by the user or computed in SLARRE.
409 ELSEIF( INDEIG ) THEN
410 * We do not reference IL, IU in the cases RANGE = 'V','A'
416 IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
418 ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN
420 ELSE IF( N.LT.0 ) THEN
422 ELSE IF( VALEIG .AND. N.GT.0 .AND. WU.LE.WL ) THEN
424 ELSE IF( INDEIG .AND. ( IIL.LT.1 .OR. IIL.GT.N ) ) THEN
426 ELSE IF( INDEIG .AND. ( IIU.LT.IIL .OR. IIU.GT.N ) ) THEN
428 ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
430 ELSE IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
432 ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
436 * Get machine constants.
438 SAFMIN = SLAMCH( 'Safe minimum' )
439 EPS = SLAMCH( 'Precision' )
440 SMLNUM = SAFMIN / EPS
441 BIGNUM = ONE / SMLNUM
442 RMIN = SQRT( SMLNUM )
443 RMAX = MIN( SQRT( BIGNUM ), ONE / SQRT( SQRT( SAFMIN ) ) )
449 IF( WANTZ .AND. ALLEIG ) THEN
451 ELSE IF( WANTZ .AND. VALEIG ) THEN
452 CALL SLARRC( 'T', N, VL, VU, D, E, SAFMIN,
453 $ NZCMIN, ITMP, ITMP2, INFO )
454 ELSE IF( WANTZ .AND. INDEIG ) THEN
460 IF( ZQUERY .AND. INFO.EQ.0 ) THEN
462 ELSE IF( NZC.LT.NZCMIN .AND. .NOT.ZQUERY ) THEN
469 CALL XERBLA( 'SSTEMR', -INFO )
472 ELSE IF( LQUERY .OR. ZQUERY ) THEN
476 * Handle N = 0, 1, and 2 cases immediately
483 IF( ALLEIG .OR. INDEIG ) THEN
487 IF( WL.LT.D( 1 ) .AND. WU.GE.D( 1 ) ) THEN
492 IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
501 IF( .NOT.WANTZ ) THEN
502 CALL SLAE2( D(1), E(1), D(2), R1, R2 )
503 ELSE IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
504 CALL SLAEV2( D(1), E(1), D(2), R1, R2, CS, SN )
507 $ (VALEIG.AND.(R2.GT.WL).AND.
509 $ (INDEIG.AND.(IIL.EQ.1)) ) THEN
512 IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
515 * Note: At most one of SN and CS can be zero.
531 $ (VALEIG.AND.(R1.GT.WL).AND.
533 $ (INDEIG.AND.(IIU.EQ.2)) ) THEN
536 IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
539 * Note: At most one of SN and CS can be zero.
556 * Continue with general N
570 * Scale matrix to allowable range, if necessary.
571 * The allowable range is related to the PIVMIN parameter; see the
572 * comments in SLARRD. The preference for scaling small values
573 * up is heuristic; we expect users' matrices not to be close to the
577 TNRM = SLANST( 'M', N, D, E )
578 IF( TNRM.GT.ZERO .AND. TNRM.LT.RMIN ) THEN
580 ELSE IF( TNRM.GT.RMAX ) THEN
583 IF( SCALE.NE.ONE ) THEN
584 CALL SSCAL( N, SCALE, D, 1 )
585 CALL SSCAL( N-1, SCALE, E, 1 )
588 * If eigenvalues in interval have to be found,
589 * scale (WL, WU] accordingly
595 * Compute the desired eigenvalues of the tridiagonal after splitting
596 * into smaller subblocks if the corresponding off-diagonal elements
598 * THRESH is the splitting parameter for SLARRE
599 * A negative THRESH forces the old splitting criterion based on the
600 * size of the off-diagonal. A positive THRESH switches to splitting
601 * which preserves relative accuracy.
604 * Test whether the matrix warrants the more expensive relative approach.
605 CALL SLARRR( N, D, E, IINFO )
607 * The user does not care about relative accurately eigenvalues
610 * Set the splitting criterion
615 * relative accuracy is desired but T does not guarantee it
620 * Copy original diagonal, needed to guarantee relative accuracy
621 CALL SCOPY(N,D,1,WORK(INDD),1)
623 * Store the squares of the offdiagonal values of T
625 WORK( INDE2+J-1 ) = E(J)**2
628 * Set the tolerance parameters for bisection
629 IF( .NOT.WANTZ ) THEN
630 * SLARRE computes the eigenvalues to full precision.
634 * SLARRE computes the eigenvalues to less than full precision.
635 * SLARRV will refine the eigenvalue approximations, and we can
636 * need less accurate initial bisection in SLARRE.
637 * Note: these settings do only affect the subset case and SLARRE
638 RTOL1 = MAX( SQRT(EPS)*5.0E-2, FOUR * EPS )
639 RTOL2 = MAX( SQRT(EPS)*5.0E-3, FOUR * EPS )
641 CALL SLARRE( RANGE, N, WL, WU, IIL, IIU, D, E,
642 $ WORK(INDE2), RTOL1, RTOL2, THRESH, NSPLIT,
643 $ IWORK( IINSPL ), M, W, WORK( INDERR ),
644 $ WORK( INDGP ), IWORK( IINDBL ),
645 $ IWORK( IINDW ), WORK( INDGRS ), PIVMIN,
646 $ WORK( INDWRK ), IWORK( IINDWK ), IINFO )
647 IF( IINFO.NE.0 ) THEN
648 INFO = 10 + ABS( IINFO )
651 * Note that if RANGE .NE. 'V', SLARRE computes bounds on the desired
652 * part of the spectrum. All desired eigenvalues are contained in
658 * Compute the desired eigenvectors corresponding to the computed
661 CALL SLARRV( N, WL, WU, D, E,
662 $ PIVMIN, IWORK( IINSPL ), M,
663 $ 1, M, MINRGP, RTOL1, RTOL2,
664 $ W, WORK( INDERR ), WORK( INDGP ), IWORK( IINDBL ),
665 $ IWORK( IINDW ), WORK( INDGRS ), Z, LDZ,
666 $ ISUPPZ, WORK( INDWRK ), IWORK( IINDWK ), IINFO )
667 IF( IINFO.NE.0 ) THEN
668 INFO = 20 + ABS( IINFO )
672 * SLARRE computes eigenvalues of the (shifted) root representation
673 * SLARRV returns the eigenvalues of the unshifted matrix.
674 * However, if the eigenvectors are not desired by the user, we need
675 * to apply the corresponding shifts from SLARRE to obtain the
676 * eigenvalues of the original matrix.
678 ITMP = IWORK( IINDBL+J-1 )
679 W( J ) = W( J ) + E( IWORK( IINSPL+ITMP-1 ) )
685 * Refine computed eigenvalues so that they are relatively accurate
686 * with respect to the original matrix T.
689 DO 39 JBLK = 1, IWORK( IINDBL+M-1 )
690 IEND = IWORK( IINSPL+JBLK-1 )
691 IN = IEND - IBEGIN + 1
693 * check if any eigenvalues have to be refined in this block
696 IF( IWORK( IINDBL+WEND ).EQ.JBLK ) THEN
701 IF( WEND.LT.WBEGIN ) THEN
706 OFFSET = IWORK(IINDW+WBEGIN-1)-1
707 IFIRST = IWORK(IINDW+WBEGIN-1)
708 ILAST = IWORK(IINDW+WEND-1)
711 $ WORK(INDD+IBEGIN-1), WORK(INDE2+IBEGIN-1),
712 $ IFIRST, ILAST, RTOL2, OFFSET, W(WBEGIN),
713 $ WORK( INDERR+WBEGIN-1 ),
714 $ WORK( INDWRK ), IWORK( IINDWK ), PIVMIN,
721 * If matrix was scaled, then rescale eigenvalues appropriately.
723 IF( SCALE.NE.ONE ) THEN
724 CALL SSCAL( M, ONE / SCALE, W, 1 )
728 * If eigenvalues are not in increasing order, then sort them,
729 * possibly along with eigenvectors.
731 IF( NSPLIT.GT.1 .OR. N.EQ.2 ) THEN
732 IF( .NOT. WANTZ ) THEN
733 CALL SLASRT( 'I', M, W, IINFO )
734 IF( IINFO.NE.0 ) THEN
743 IF( W( JJ ).LT.TMP ) THEN
752 CALL SSWAP( N, Z( 1, I ), 1, Z( 1, J ), 1 )
753 ITMP = ISUPPZ( 2*I-1 )
754 ISUPPZ( 2*I-1 ) = ISUPPZ( 2*J-1 )
755 ISUPPZ( 2*J-1 ) = ITMP
757 ISUPPZ( 2*I ) = ISUPPZ( 2*J )