1 *> \brief \b SLASQ2 computes all the eigenvalues of the symmetric positive definite tridiagonal matrix associated with the qd Array Z to high relative accuracy. Used by sbdsqr and sstegr.
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download SLASQ2 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slasq2.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slasq2.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slasq2.f">
21 * SUBROUTINE SLASQ2( N, Z, INFO )
23 * .. Scalar Arguments ..
26 * .. Array Arguments ..
36 *> SLASQ2 computes all the eigenvalues of the symmetric positive
37 *> definite tridiagonal matrix associated with the qd array Z to high
38 *> relative accuracy are computed to high relative accuracy, in the
39 *> absence of denormalization, underflow and overflow.
41 *> To see the relation of Z to the tridiagonal matrix, let L be a
42 *> unit lower bidiagonal matrix with subdiagonals Z(2,4,6,,..) and
43 *> let U be an upper bidiagonal matrix with 1's above and diagonal
44 *> Z(1,3,5,,..). The tridiagonal is L*U or, if you prefer, the
45 *> symmetric tridiagonal to which it is similar.
47 *> Note : SLASQ2 defines a logical variable, IEEE, which is true
48 *> on machines which follow ieee-754 floating-point standard in their
49 *> handling of infinities and NaNs, and false otherwise. This variable
50 *> is passed to SLASQ3.
59 *> The number of rows and columns in the matrix. N >= 0.
64 *> Z is REAL array, dimension ( 4*N )
65 *> On entry Z holds the qd array. On exit, entries 1 to N hold
66 *> the eigenvalues in decreasing order, Z( 2*N+1 ) holds the
67 *> trace, and Z( 2*N+2 ) holds the sum of the eigenvalues. If
68 *> N > 2, then Z( 2*N+3 ) holds the iteration count, Z( 2*N+4 )
69 *> holds NDIVS/NIN^2, and Z( 2*N+5 ) holds the percentage of
70 *> shifts that failed.
76 *> = 0: successful exit
77 *> < 0: if the i-th argument is a scalar and had an illegal
78 *> value, then INFO = -i, if the i-th argument is an
79 *> array and the j-entry had an illegal value, then
81 *> > 0: the algorithm failed
82 *> = 1, a split was marked by a positive value in E
83 *> = 2, current block of Z not diagonalized after 100*N
84 *> iterations (in inner while loop). On exit Z holds
85 *> a qd array with the same eigenvalues as the given Z.
86 *> = 3, termination criterion of outer while loop not met
87 *> (program created more than N unreduced blocks)
93 *> \author Univ. of Tennessee
94 *> \author Univ. of California Berkeley
95 *> \author Univ. of Colorado Denver
98 *> \date September 2012
100 *> \ingroup auxOTHERcomputational
102 *> \par Further Details:
103 * =====================
107 *> Local Variables: I0:N0 defines a current unreduced segment of Z.
108 *> The shifts are accumulated in SIGMA. Iteration count is in ITER.
109 *> Ping-pong is controlled by PP (alternates between 0 and 1).
112 * =====================================================================
113 SUBROUTINE SLASQ2( N, Z, INFO )
115 * -- LAPACK computational routine (version 3.4.2) --
116 * -- LAPACK is a software package provided by Univ. of Tennessee, --
117 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
120 * .. Scalar Arguments ..
123 * .. Array Arguments ..
127 * =====================================================================
131 PARAMETER ( CBIAS = 1.50E0 )
132 REAL ZERO, HALF, ONE, TWO, FOUR, HUNDRD
133 PARAMETER ( ZERO = 0.0E0, HALF = 0.5E0, ONE = 1.0E0,
134 $ TWO = 2.0E0, FOUR = 4.0E0, HUNDRD = 100.0E0 )
136 * .. Local Scalars ..
138 INTEGER I0, I4, IINFO, IPN4, ITER, IWHILA, IWHILB, K,
139 $ KMIN, N0, NBIG, NDIV, NFAIL, PP, SPLT, TTYPE,
141 REAL D, DEE, DEEMIN, DESIG, DMIN, DMIN1, DMIN2, DN,
142 $ DN1, DN2, E, EMAX, EMIN, EPS, G, OLDEMN, QMAX,
143 $ QMIN, S, SAFMIN, SIGMA, T, TAU, TEMP, TOL,
144 $ TOL2, TRACE, ZMAX, TEMPE, TEMPQ
146 * .. External Subroutines ..
147 EXTERNAL SLASQ3, SLASRT, XERBLA
149 * .. External Functions ..
153 * .. Intrinsic Functions ..
154 INTRINSIC ABS, MAX, MIN, REAL, SQRT
156 * .. Executable Statements ..
158 * Test the input arguments.
159 * (in case SLASQ2 is not called by SLASQ1)
162 EPS = SLAMCH( 'Precision' )
163 SAFMIN = SLAMCH( 'Safe minimum' )
169 CALL XERBLA( 'SLASQ2', 1 )
171 ELSE IF( N.EQ.0 ) THEN
173 ELSE IF( N.EQ.1 ) THEN
177 IF( Z( 1 ).LT.ZERO ) THEN
179 CALL XERBLA( 'SLASQ2', 2 )
182 ELSE IF( N.EQ.2 ) THEN
186 IF( Z( 2 ).LT.ZERO .OR. Z( 3 ).LT.ZERO ) THEN
188 CALL XERBLA( 'SLASQ2', 2 )
190 ELSE IF( Z( 3 ).GT.Z( 1 ) ) THEN
195 Z( 5 ) = Z( 1 ) + Z( 2 ) + Z( 3 )
196 IF( Z( 2 ).GT.Z( 3 )*TOL2 ) THEN
197 T = HALF*( ( Z( 1 )-Z( 3 ) )+Z( 2 ) )
198 S = Z( 3 )*( Z( 2 ) / T )
200 S = Z( 3 )*( Z( 2 ) / ( T*( ONE+SQRT( ONE+S / T ) ) ) )
202 S = Z( 3 )*( Z( 2 ) / ( T+SQRT( T )*SQRT( T+S ) ) )
204 T = Z( 1 ) + ( S+Z( 2 ) )
205 Z( 3 ) = Z( 3 )*( Z( 1 ) / T )
209 Z( 6 ) = Z( 2 ) + Z( 1 )
213 * Check for negative data and compute sums of q's and e's.
222 DO 10 K = 1, 2*( N-1 ), 2
223 IF( Z( K ).LT.ZERO ) THEN
225 CALL XERBLA( 'SLASQ2', 2 )
227 ELSE IF( Z( K+1 ).LT.ZERO ) THEN
229 CALL XERBLA( 'SLASQ2', 2 )
234 QMAX = MAX( QMAX, Z( K ) )
235 EMIN = MIN( EMIN, Z( K+1 ) )
236 ZMAX = MAX( QMAX, ZMAX, Z( K+1 ) )
238 IF( Z( 2*N-1 ).LT.ZERO ) THEN
239 INFO = -( 200+2*N-1 )
240 CALL XERBLA( 'SLASQ2', 2 )
244 QMAX = MAX( QMAX, Z( 2*N-1 ) )
245 ZMAX = MAX( QMAX, ZMAX )
247 * Check for diagonality.
253 CALL SLASRT( 'D', N, Z, IINFO )
260 * Check for zero data.
262 IF( TRACE.EQ.ZERO ) THEN
267 * Check whether the machine is IEEE conformable.
269 * IEEE = ILAENV( 10, 'SLASQ2', 'N', 1, 2, 3, 4 ).EQ.1 .AND.
270 * $ ILAENV( 11, 'SLASQ2', 'N', 1, 2, 3, 4 ).EQ.1
272 * [11/15/2008] The case IEEE=.TRUE. has a problem in single precision with
273 * some the test matrices of type 16. The double precision code is fine.
277 * Rearrange data for locality: Z=(q1,qq1,e1,ee1,q2,qq2,e2,ee2,...).
283 Z( 2*K-3 ) = Z( K-1 )
289 * Reverse the qd-array, if warranted.
291 IF( CBIAS*Z( 4*I0-3 ).LT.Z( 4*N0-3 ) ) THEN
293 DO 40 I4 = 4*I0, 2*( I0+N0-1 ), 4
295 Z( I4-3 ) = Z( IPN4-I4-3 )
296 Z( IPN4-I4-3 ) = TEMP
298 Z( I4-1 ) = Z( IPN4-I4-5 )
299 Z( IPN4-I4-5 ) = TEMP
303 * Initial split checking via dqd and Li's test.
310 DO 50 I4 = 4*( N0-1 ) + PP, 4*I0 + PP, -4
311 IF( Z( I4-1 ).LE.TOL2*D ) THEN
315 D = Z( I4-3 )*( D / ( D+Z( I4-1 ) ) )
319 * dqd maps Z to ZZ plus Li's test.
321 EMIN = Z( 4*I0+PP+1 )
323 DO 60 I4 = 4*I0 + PP, 4*( N0-1 ) + PP, 4
324 Z( I4-2*PP-2 ) = D + Z( I4-1 )
325 IF( Z( I4-1 ).LE.TOL2*D ) THEN
330 ELSE IF( SAFMIN*Z( I4+1 ).LT.Z( I4-2*PP-2 ) .AND.
331 $ SAFMIN*Z( I4-2*PP-2 ).LT.Z( I4+1 ) ) THEN
332 TEMP = Z( I4+1 ) / Z( I4-2*PP-2 )
333 Z( I4-2*PP ) = Z( I4-1 )*TEMP
336 Z( I4-2*PP ) = Z( I4+1 )*( Z( I4-1 ) / Z( I4-2*PP-2 ) )
337 D = Z( I4+1 )*( D / Z( I4-2*PP-2 ) )
339 EMIN = MIN( EMIN, Z( I4-2*PP ) )
345 QMAX = Z( 4*I0-PP-2 )
346 DO 70 I4 = 4*I0 - PP + 2, 4*N0 - PP - 2, 4
347 QMAX = MAX( QMAX, Z( I4 ) )
350 * Prepare for the next iteration on K.
355 * Initialise variables to pass to SLASQ3.
370 DO 160 IWHILA = 1, N + 1
374 * While array unfinished do
376 * E(N0) holds the value of SIGMA when submatrix in I0:N0
377 * splits from the rest of the array, but is negated.
385 IF( SIGMA.LT.ZERO ) THEN
390 * Find last unreduced submatrix's top index I0, find QMAX and
391 * EMIN. Find Gershgorin-type bound if Q's much greater than E's.
395 EMIN = ABS( Z( 4*N0-5 ) )
401 DO 90 I4 = 4*N0, 8, -4
402 IF( Z( I4-5 ).LE.ZERO )
404 IF( QMIN.GE.FOUR*EMAX ) THEN
405 QMIN = MIN( QMIN, Z( I4-3 ) )
406 EMAX = MAX( EMAX, Z( I4-5 ) )
408 QMAX = MAX( QMAX, Z( I4-7 )+Z( I4-5 ) )
409 EMIN = MIN( EMIN, Z( I4-5 ) )
417 IF( N0-I0.GT.1 ) THEN
421 DO 110 I4 = 4*I0+1, 4*N0-3, 4
422 DEE = Z( I4 )*( DEE /( DEE+Z( I4-2 ) ) )
423 IF( DEE.LE.DEEMIN ) THEN
428 IF( (KMIN-I0)*2.LT.N0-KMIN .AND.
429 $ DEEMIN.LE.HALF*Z(4*N0-3) ) THEN
432 DO 120 I4 = 4*I0, 2*( I0+N0-1 ), 4
434 Z( I4-3 ) = Z( IPN4-I4-3 )
435 Z( IPN4-I4-3 ) = TEMP
437 Z( I4-2 ) = Z( IPN4-I4-2 )
438 Z( IPN4-I4-2 ) = TEMP
440 Z( I4-1 ) = Z( IPN4-I4-5 )
441 Z( IPN4-I4-5 ) = TEMP
443 Z( I4 ) = Z( IPN4-I4-4 )
444 Z( IPN4-I4-4 ) = TEMP
449 * Put -(initial shift) into DMIN.
451 DMIN = -MAX( ZERO, QMIN-TWO*SQRT( QMIN )*SQRT( EMAX ) )
453 * Now I0:N0 is unreduced.
454 * PP = 0 for ping, PP = 1 for pong.
455 * PP = 2 indicates that flipping was applied to the Z array and
456 * and that the tests for deflation upon entry in SLASQ3
457 * should not be performed.
459 NBIG = 100*( N0-I0+1 )
460 DO 140 IWHILB = 1, NBIG
464 * While submatrix unfinished take a good dqds step.
466 CALL SLASQ3( I0, N0, Z, PP, DMIN, SIGMA, DESIG, QMAX, NFAIL,
467 $ ITER, NDIV, IEEE, TTYPE, DMIN1, DMIN2, DN, DN1,
472 * When EMIN is very small check for splits.
474 IF( PP.EQ.0 .AND. N0-I0.GE.3 ) THEN
475 IF( Z( 4*N0 ).LE.TOL2*QMAX .OR.
476 $ Z( 4*N0-1 ).LE.TOL2*SIGMA ) THEN
481 DO 130 I4 = 4*I0, 4*( N0-3 ), 4
482 IF( Z( I4 ).LE.TOL2*Z( I4-3 ) .OR.
483 $ Z( I4-1 ).LE.TOL2*SIGMA ) THEN
490 QMAX = MAX( QMAX, Z( I4+1 ) )
491 EMIN = MIN( EMIN, Z( I4-1 ) )
492 OLDEMN = MIN( OLDEMN, Z( I4 ) )
505 * Maximum number of iterations exceeded, restore the shift
506 * SIGMA and place the new d's and e's in a qd array.
507 * This might need to be done for several blocks
513 Z( 4*I0-3 ) = Z( 4*I0-3 ) + SIGMA
516 Z( 4*K-5 ) = Z( 4*K-5 ) * (TEMPQ / Z( 4*K-7 ))
518 Z( 4*K-3 ) = Z( 4*K-3 ) + SIGMA + TEMPE - Z( 4*K-5 )
521 * Prepare to do this on the previous block if there is one
525 DO WHILE( ( I1.GE.2 ) .AND. ( Z(4*I1-5).GE.ZERO ) )
535 Z( 2*K-1 ) = Z( 4*K-3 )
537 * Only the block 1..N0 is unfinished. The rest of the e's
538 * must be essentially zero, although sometimes other data
539 * has been stored in them.
542 Z( 2*K ) = Z( 4*K-1 )
562 * Move q's to the front.
568 * Sort and compute sum of eigenvalues.
570 CALL SLASRT( 'D', N, Z, IINFO )
577 * Store trace, sum(eigenvalues) and information on performance.
581 Z( 2*N+3 ) = REAL( ITER )
582 Z( 2*N+4 ) = REAL( NDIV ) / REAL( N**2 )
583 Z( 2*N+5 ) = HUNDRD*NFAIL / REAL( ITER )