3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download ZSTEMR + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zstemr.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zstemr.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zstemr.f">
21 * SUBROUTINE ZSTEMR( 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
29 * DOUBLE PRECISION VL, VU
31 * .. Array Arguments ..
32 * INTEGER ISUPPZ( * ), IWORK( * )
33 * DOUBLE PRECISION D( * ), E( * ), W( * ), WORK( * )
34 * COMPLEX*16 Z( LDZ, * )
43 *> ZSTEMR 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.ZSTEMR 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
94 *> 2. LAPACK routines can be used to reduce a complex Hermitean matrix to
95 *> real symmetric tridiagonal form.
97 *> (Any complex Hermitean tridiagonal matrix has real values on its diagonal
98 *> and potentially complex numbers on its off-diagonals. By applying a
99 *> similarity transform with an appropriate diagonal matrix
100 *> diag(1,e^{i \phy_1}, ... , e^{i \phy_{n-1}}), the complex Hermitean
101 *> matrix can be transformed into a real symmetric matrix and complex
102 *> arithmetic can be entirely avoided.)
104 *> While the eigenvectors of the real symmetric tridiagonal matrix are real,
105 *> the eigenvectors of original complex Hermitean matrix have complex entries
107 *> Since LAPACK drivers overwrite the matrix data with the eigenvectors,
108 *> ZSTEMR accepts complex workspace to facilitate interoperability
109 *> with ZUNMTR or ZUPMTR.
117 *> JOBZ is CHARACTER*1
118 *> = 'N': Compute eigenvalues only;
119 *> = 'V': Compute eigenvalues and eigenvectors.
124 *> RANGE is CHARACTER*1
125 *> = 'A': all eigenvalues will be found.
126 *> = 'V': all eigenvalues in the half-open interval (VL,VU]
128 *> = 'I': the IL-th through IU-th eigenvalues will be found.
134 *> The order of the matrix. N >= 0.
139 *> D is DOUBLE PRECISION array, dimension (N)
140 *> On entry, the N diagonal elements of the tridiagonal matrix
141 *> T. On exit, D is overwritten.
146 *> E is DOUBLE PRECISION array, dimension (N)
147 *> On entry, the (N-1) subdiagonal elements of the tridiagonal
148 *> matrix T in elements 1 to N-1 of E. E(N) need not be set on
149 *> input, but is used internally as workspace.
150 *> On exit, E is overwritten.
155 *> VL is DOUBLE PRECISION
157 *> If RANGE='V', the lower bound of the interval to
158 *> be searched for eigenvalues. VL < VU.
159 *> Not referenced if RANGE = 'A' or 'I'.
164 *> VU is DOUBLE PRECISION
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'.
175 *> If RANGE='I', the index of the
176 *> smallest eigenvalue to be returned.
177 *> 1 <= IL <= IU <= N, if N > 0.
178 *> Not referenced if RANGE = 'A' or 'V'.
185 *> If RANGE='I', the index of the
186 *> largest eigenvalue to be returned.
187 *> 1 <= IL <= IU <= N, if N > 0.
188 *> Not referenced if RANGE = 'A' or 'V'.
194 *> The total number of eigenvalues found. 0 <= M <= N.
195 *> If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1.
200 *> W is DOUBLE PRECISION array, dimension (N)
201 *> The first M elements contain the selected eigenvalues in
207 *> Z is COMPLEX*16 array, dimension (LDZ, max(1,M) )
208 *> If JOBZ = 'V', and if INFO = 0, then the first M columns of Z
209 *> contain the orthonormal eigenvectors of the matrix T
210 *> corresponding to the selected eigenvalues, with the i-th
211 *> column of Z holding the eigenvector associated with W(i).
212 *> If JOBZ = 'N', then Z is not referenced.
213 *> Note: the user must ensure that at least max(1,M) columns are
214 *> supplied in the array Z; if RANGE = 'V', the exact value of M
215 *> is not known in advance and can be computed with a workspace
216 *> query by setting NZC = -1, see below.
222 *> The leading dimension of the array Z. LDZ >= 1, and if
223 *> JOBZ = 'V', then LDZ >= max(1,N).
229 *> The number of eigenvectors to be held in the array Z.
230 *> If RANGE = 'A', then NZC >= max(1,N).
231 *> If RANGE = 'V', then NZC >= the number of eigenvalues in (VL,VU].
232 *> If RANGE = 'I', then NZC >= IU-IL+1.
233 *> If NZC = -1, then a workspace query is assumed; the
234 *> routine calculates the number of columns of the array Z that
235 *> are needed to hold the eigenvectors.
236 *> This value is returned as the first entry of the Z array, and
237 *> no error message related to NZC is issued by XERBLA.
240 *> \param[out] ISUPPZ
242 *> ISUPPZ is INTEGER ARRAY, dimension ( 2*max(1,M) )
243 *> The support of the eigenvectors in Z, i.e., the indices
244 *> indicating the nonzero elements in Z. The i-th computed eigenvector
245 *> is nonzero only in elements ISUPPZ( 2*i-1 ) through
246 *> ISUPPZ( 2*i ). This is relevant in the case when the matrix
247 *> is split. ISUPPZ is only accessed when JOBZ is 'V' and N > 0.
250 *> \param[in,out] TRYRAC
253 *> If TRYRAC.EQ..TRUE., indicates that the code should check whether
254 *> the tridiagonal matrix defines its eigenvalues to high relative
255 *> accuracy. If so, the code uses relative-accuracy preserving
256 *> algorithms that might be (a bit) slower depending on the matrix.
257 *> If the matrix does not define its eigenvalues to high relative
258 *> accuracy, the code can uses possibly faster algorithms.
259 *> If TRYRAC.EQ..FALSE., the code is not required to guarantee
260 *> relatively accurate eigenvalues and can use the fastest possible
262 *> On exit, a .TRUE. TRYRAC will be set to .FALSE. if the matrix
263 *> does not define its eigenvalues to high relative accuracy.
268 *> WORK is DOUBLE PRECISION array, dimension (LWORK)
269 *> On exit, if INFO = 0, WORK(1) returns the optimal
270 *> (and minimal) LWORK.
276 *> The dimension of the array WORK. LWORK >= max(1,18*N)
277 *> if JOBZ = 'V', and LWORK >= max(1,12*N) if JOBZ = 'N'.
278 *> If LWORK = -1, then a workspace query is assumed; the routine
279 *> only calculates the optimal size of the WORK array, returns
280 *> this value as the first entry of the WORK array, and no error
281 *> message related to LWORK is issued by XERBLA.
286 *> IWORK is INTEGER array, dimension (LIWORK)
287 *> On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.
293 *> The dimension of the array IWORK. LIWORK >= max(1,10*N)
294 *> if the eigenvectors are desired, and LIWORK >= max(1,8*N)
295 *> if only the eigenvalues are to be computed.
296 *> If LIWORK = -1, then a workspace query is assumed; the
297 *> routine only calculates the optimal size of the IWORK array,
298 *> returns this value as the first entry of the IWORK array, and
299 *> no error message related to LIWORK is issued by XERBLA.
306 *> = 0: successful exit
307 *> < 0: if INFO = -i, the i-th argument had an illegal value
308 *> > 0: if INFO = 1X, internal error in DLARRE,
309 *> if INFO = 2X, internal error in ZLARRV.
310 *> Here, the digit X = ABS( IINFO ) < 10, where IINFO is
311 *> the nonzero error code returned by DLARRE or
312 *> ZLARRV, respectively.
318 *> \author Univ. of Tennessee
319 *> \author Univ. of California Berkeley
320 *> \author Univ. of Colorado Denver
325 *> \ingroup complex16OTHERcomputational
327 *> \par Contributors:
330 *> Beresford Parlett, University of California, Berkeley, USA \n
331 *> Jim Demmel, University of California, Berkeley, USA \n
332 *> Inderjit Dhillon, University of Texas, Austin, USA \n
333 *> Osni Marques, LBNL/NERSC, USA \n
334 *> Christof Voemel, University of California, Berkeley, USA \n
336 * =====================================================================
337 SUBROUTINE ZSTEMR( JOBZ, RANGE, N, D, E, VL, VU, IL, IU,
338 $ M, W, Z, LDZ, NZC, ISUPPZ, TRYRAC, WORK, LWORK,
339 $ IWORK, LIWORK, INFO )
341 * -- LAPACK computational routine (version 3.6.1) --
342 * -- LAPACK is a software package provided by Univ. of Tennessee, --
343 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
346 * .. Scalar Arguments ..
347 CHARACTER JOBZ, RANGE
349 INTEGER IL, INFO, IU, LDZ, NZC, LIWORK, LWORK, M, N
350 DOUBLE PRECISION VL, VU
352 * .. Array Arguments ..
353 INTEGER ISUPPZ( * ), IWORK( * )
354 DOUBLE PRECISION D( * ), E( * ), W( * ), WORK( * )
355 COMPLEX*16 Z( LDZ, * )
358 * =====================================================================
361 DOUBLE PRECISION ZERO, ONE, FOUR, MINRGP
362 PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0,
366 * .. Local Scalars ..
367 LOGICAL ALLEIG, INDEIG, LQUERY, VALEIG, WANTZ, ZQUERY
368 INTEGER I, IBEGIN, IEND, IFIRST, IIL, IINDBL, IINDW,
369 $ IINDWK, IINFO, IINSPL, IIU, ILAST, IN, INDD,
370 $ INDE2, INDERR, INDGP, INDGRS, INDWRK, ITMP,
371 $ ITMP2, J, JBLK, JJ, LIWMIN, LWMIN, NSPLIT,
372 $ NZCMIN, OFFSET, WBEGIN, WEND
373 DOUBLE PRECISION BIGNUM, CS, EPS, PIVMIN, R1, R2, RMAX, RMIN,
374 $ RTOL1, RTOL2, SAFMIN, SCALE, SMLNUM, SN,
375 $ THRESH, TMP, TNRM, WL, WU
378 * .. External Functions ..
380 DOUBLE PRECISION DLAMCH, DLANST
381 EXTERNAL LSAME, DLAMCH, DLANST
383 * .. External Subroutines ..
384 EXTERNAL DCOPY, DLAE2, DLAEV2, DLARRC, DLARRE, DLARRJ,
385 $ DLARRR, DLASRT, DSCAL, XERBLA, ZLARRV, ZSWAP
387 * .. Intrinsic Functions ..
388 INTRINSIC MAX, MIN, SQRT
392 * .. Executable Statements ..
394 * Test the input parameters.
396 WANTZ = LSAME( JOBZ, 'V' )
397 ALLEIG = LSAME( RANGE, 'A' )
398 VALEIG = LSAME( RANGE, 'V' )
399 INDEIG = LSAME( RANGE, 'I' )
401 LQUERY = ( ( LWORK.EQ.-1 ).OR.( LIWORK.EQ.-1 ) )
402 ZQUERY = ( NZC.EQ.-1 )
404 * DSTEMR needs WORK of size 6*N, IWORK of size 3*N.
405 * In addition, DLARRE needs WORK of size 6*N, IWORK of size 5*N.
406 * Furthermore, ZLARRV needs WORK of size 12*N, IWORK of size 7*N.
411 * need less workspace if only the eigenvalues are wanted
423 * We do not reference VL, VU in the cases RANGE = 'I','A'
424 * The interval (WL, WU] contains all the wanted eigenvalues.
425 * It is either given by the user or computed in DLARRE.
428 ELSEIF( INDEIG ) THEN
429 * We do not reference IL, IU in the cases RANGE = 'V','A'
435 IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
437 ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN
439 ELSE IF( N.LT.0 ) THEN
441 ELSE IF( VALEIG .AND. N.GT.0 .AND. WU.LE.WL ) THEN
443 ELSE IF( INDEIG .AND. ( IIL.LT.1 .OR. IIL.GT.N ) ) THEN
445 ELSE IF( INDEIG .AND. ( IIU.LT.IIL .OR. IIU.GT.N ) ) THEN
447 ELSE IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
449 ELSE IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
451 ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
455 * Get machine constants.
457 SAFMIN = DLAMCH( 'Safe minimum' )
458 EPS = DLAMCH( 'Precision' )
459 SMLNUM = SAFMIN / EPS
460 BIGNUM = ONE / SMLNUM
461 RMIN = SQRT( SMLNUM )
462 RMAX = MIN( SQRT( BIGNUM ), ONE / SQRT( SQRT( SAFMIN ) ) )
468 IF( WANTZ .AND. ALLEIG ) THEN
470 ELSE IF( WANTZ .AND. VALEIG ) THEN
471 CALL DLARRC( 'T', N, VL, VU, D, E, SAFMIN,
472 $ NZCMIN, ITMP, ITMP2, INFO )
473 ELSE IF( WANTZ .AND. INDEIG ) THEN
479 IF( ZQUERY .AND. INFO.EQ.0 ) THEN
481 ELSE IF( NZC.LT.NZCMIN .AND. .NOT.ZQUERY ) THEN
488 CALL XERBLA( 'ZSTEMR', -INFO )
491 ELSE IF( LQUERY .OR. ZQUERY ) THEN
495 * Handle N = 0, 1, and 2 cases immediately
502 IF( ALLEIG .OR. INDEIG ) THEN
506 IF( WL.LT.D( 1 ) .AND. WU.GE.D( 1 ) ) THEN
511 IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
520 IF( .NOT.WANTZ ) THEN
521 CALL DLAE2( D(1), E(1), D(2), R1, R2 )
522 ELSE IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
523 CALL DLAEV2( D(1), E(1), D(2), R1, R2, CS, SN )
526 $ (VALEIG.AND.(R2.GT.WL).AND.
528 $ (INDEIG.AND.(IIL.EQ.1)) ) THEN
531 IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
534 * Note: At most one of SN and CS can be zero.
550 $ (VALEIG.AND.(R1.GT.WL).AND.
552 $ (INDEIG.AND.(IIU.EQ.2)) ) THEN
555 IF( WANTZ.AND.(.NOT.ZQUERY) ) THEN
558 * Note: At most one of SN and CS can be zero.
575 * Continue with general N
589 * Scale matrix to allowable range, if necessary.
590 * The allowable range is related to the PIVMIN parameter; see the
591 * comments in DLARRD. The preference for scaling small values
592 * up is heuristic; we expect users' matrices not to be close to the
596 TNRM = DLANST( 'M', N, D, E )
597 IF( TNRM.GT.ZERO .AND. TNRM.LT.RMIN ) THEN
599 ELSE IF( TNRM.GT.RMAX ) THEN
602 IF( SCALE.NE.ONE ) THEN
603 CALL DSCAL( N, SCALE, D, 1 )
604 CALL DSCAL( N-1, SCALE, E, 1 )
607 * If eigenvalues in interval have to be found,
608 * scale (WL, WU] accordingly
614 * Compute the desired eigenvalues of the tridiagonal after splitting
615 * into smaller subblocks if the corresponding off-diagonal elements
617 * THRESH is the splitting parameter for DLARRE
618 * A negative THRESH forces the old splitting criterion based on the
619 * size of the off-diagonal. A positive THRESH switches to splitting
620 * which preserves relative accuracy.
623 * Test whether the matrix warrants the more expensive relative approach.
624 CALL DLARRR( N, D, E, IINFO )
626 * The user does not care about relative accurately eigenvalues
629 * Set the splitting criterion
634 * relative accuracy is desired but T does not guarantee it
639 * Copy original diagonal, needed to guarantee relative accuracy
640 CALL DCOPY(N,D,1,WORK(INDD),1)
642 * Store the squares of the offdiagonal values of T
644 WORK( INDE2+J-1 ) = E(J)**2
647 * Set the tolerance parameters for bisection
648 IF( .NOT.WANTZ ) THEN
649 * DLARRE computes the eigenvalues to full precision.
653 * DLARRE computes the eigenvalues to less than full precision.
654 * ZLARRV will refine the eigenvalue approximations, and we only
655 * need less accurate initial bisection in DLARRE.
656 * Note: these settings do only affect the subset case and DLARRE
658 RTOL2 = MAX( SQRT(EPS)*5.0D-3, FOUR * EPS )
660 CALL DLARRE( RANGE, N, WL, WU, IIL, IIU, D, E,
661 $ WORK(INDE2), RTOL1, RTOL2, THRESH, NSPLIT,
662 $ IWORK( IINSPL ), M, W, WORK( INDERR ),
663 $ WORK( INDGP ), IWORK( IINDBL ),
664 $ IWORK( IINDW ), WORK( INDGRS ), PIVMIN,
665 $ WORK( INDWRK ), IWORK( IINDWK ), IINFO )
666 IF( IINFO.NE.0 ) THEN
667 INFO = 10 + ABS( IINFO )
670 * Note that if RANGE .NE. 'V', DLARRE computes bounds on the desired
671 * part of the spectrum. All desired eigenvalues are contained in
677 * Compute the desired eigenvectors corresponding to the computed
680 CALL ZLARRV( N, WL, WU, D, E,
681 $ PIVMIN, IWORK( IINSPL ), M,
682 $ 1, M, MINRGP, RTOL1, RTOL2,
683 $ W, WORK( INDERR ), WORK( INDGP ), IWORK( IINDBL ),
684 $ IWORK( IINDW ), WORK( INDGRS ), Z, LDZ,
685 $ ISUPPZ, WORK( INDWRK ), IWORK( IINDWK ), IINFO )
686 IF( IINFO.NE.0 ) THEN
687 INFO = 20 + ABS( IINFO )
691 * DLARRE computes eigenvalues of the (shifted) root representation
692 * ZLARRV returns the eigenvalues of the unshifted matrix.
693 * However, if the eigenvectors are not desired by the user, we need
694 * to apply the corresponding shifts from DLARRE to obtain the
695 * eigenvalues of the original matrix.
697 ITMP = IWORK( IINDBL+J-1 )
698 W( J ) = W( J ) + E( IWORK( IINSPL+ITMP-1 ) )
704 * Refine computed eigenvalues so that they are relatively accurate
705 * with respect to the original matrix T.
708 DO 39 JBLK = 1, IWORK( IINDBL+M-1 )
709 IEND = IWORK( IINSPL+JBLK-1 )
710 IN = IEND - IBEGIN + 1
712 * check if any eigenvalues have to be refined in this block
715 IF( IWORK( IINDBL+WEND ).EQ.JBLK ) THEN
720 IF( WEND.LT.WBEGIN ) THEN
725 OFFSET = IWORK(IINDW+WBEGIN-1)-1
726 IFIRST = IWORK(IINDW+WBEGIN-1)
727 ILAST = IWORK(IINDW+WEND-1)
730 $ WORK(INDD+IBEGIN-1), WORK(INDE2+IBEGIN-1),
731 $ IFIRST, ILAST, RTOL2, OFFSET, W(WBEGIN),
732 $ WORK( INDERR+WBEGIN-1 ),
733 $ WORK( INDWRK ), IWORK( IINDWK ), PIVMIN,
740 * If matrix was scaled, then rescale eigenvalues appropriately.
742 IF( SCALE.NE.ONE ) THEN
743 CALL DSCAL( M, ONE / SCALE, W, 1 )
747 * If eigenvalues are not in increasing order, then sort them,
748 * possibly along with eigenvectors.
750 IF( NSPLIT.GT.1 .OR. N.EQ.2 ) THEN
751 IF( .NOT. WANTZ ) THEN
752 CALL DLASRT( 'I', M, W, IINFO )
753 IF( IINFO.NE.0 ) THEN
762 IF( W( JJ ).LT.TMP ) THEN
771 CALL ZSWAP( N, Z( 1, I ), 1, Z( 1, J ), 1 )
772 ITMP = ISUPPZ( 2*I-1 )
773 ISUPPZ( 2*I-1 ) = ISUPPZ( 2*J-1 )
774 ISUPPZ( 2*J-1 ) = ITMP
776 ISUPPZ( 2*I ) = ISUPPZ( 2*J )