1 *> \brief \b DLAED8 used by sstedc. Merges eigenvalues and deflates secular equation. Used when the original matrix is dense.
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DLAED8 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlaed8.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlaed8.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlaed8.f">
21 * SUBROUTINE DLAED8( ICOMPQ, K, N, QSIZ, D, Q, LDQ, INDXQ, RHO,
22 * CUTPNT, Z, DLAMDA, Q2, LDQ2, W, PERM, GIVPTR,
23 * GIVCOL, GIVNUM, INDXP, INDX, INFO )
25 * .. Scalar Arguments ..
26 * INTEGER CUTPNT, GIVPTR, ICOMPQ, INFO, K, LDQ, LDQ2, N,
28 * DOUBLE PRECISION RHO
30 * .. Array Arguments ..
31 * INTEGER GIVCOL( 2, * ), INDX( * ), INDXP( * ),
32 * $ INDXQ( * ), PERM( * )
33 * DOUBLE PRECISION D( * ), DLAMDA( * ), GIVNUM( 2, * ),
34 * $ Q( LDQ, * ), Q2( LDQ2, * ), W( * ), Z( * )
43 *> DLAED8 merges the two sets of eigenvalues together into a single
44 *> sorted set. Then it tries to deflate the size of the problem.
45 *> There are two ways in which deflation can occur: when two or more
46 *> eigenvalues are close together or if there is a tiny element in the
47 *> Z vector. For each such occurrence the order of the related secular
48 *> equation problem is reduced by one.
57 *> = 0: Compute eigenvalues only.
58 *> = 1: Compute eigenvectors of original dense symmetric matrix
59 *> also. On entry, Q contains the orthogonal matrix used
60 *> to reduce the original matrix to tridiagonal form.
66 *> The number of non-deflated eigenvalues, and the order of the
67 *> related secular equation.
73 *> The dimension of the symmetric tridiagonal matrix. N >= 0.
79 *> The dimension of the orthogonal matrix used to reduce
80 *> the full matrix to tridiagonal form. QSIZ >= N if ICOMPQ = 1.
85 *> D is DOUBLE PRECISION array, dimension (N)
86 *> On entry, the eigenvalues of the two submatrices to be
87 *> combined. On exit, the trailing (N-K) updated eigenvalues
88 *> (those which were deflated) sorted into increasing order.
93 *> Q is DOUBLE PRECISION array, dimension (LDQ,N)
94 *> If ICOMPQ = 0, Q is not referenced. Otherwise,
95 *> on entry, Q contains the eigenvectors of the partially solved
96 *> system which has been previously updated in matrix
97 *> multiplies with other partially solved eigensystems.
98 *> On exit, Q contains the trailing (N-K) updated eigenvectors
99 *> (those which were deflated) in its last N-K columns.
105 *> The leading dimension of the array Q. LDQ >= max(1,N).
110 *> INDXQ is INTEGER array, dimension (N)
111 *> The permutation which separately sorts the two sub-problems
112 *> in D into ascending order. Note that elements in the second
113 *> half of this permutation must first have CUTPNT added to
114 *> their values in order to be accurate.
117 *> \param[in,out] RHO
119 *> RHO is DOUBLE PRECISION
120 *> On entry, the off-diagonal element associated with the rank-1
121 *> cut which originally split the two submatrices which are now
123 *> On exit, RHO has been modified to the value required by
130 *> The location of the last eigenvalue in the leading
131 *> sub-matrix. min(1,N) <= CUTPNT <= N.
136 *> Z is DOUBLE PRECISION array, dimension (N)
137 *> On entry, Z contains the updating vector (the last row of
138 *> the first sub-eigenvector matrix and the first row of the
139 *> second sub-eigenvector matrix).
140 *> On exit, the contents of Z are destroyed by the updating
144 *> \param[out] DLAMDA
146 *> DLAMDA is DOUBLE PRECISION array, dimension (N)
147 *> A copy of the first K eigenvalues which will be used by
148 *> DLAED3 to form the secular equation.
153 *> Q2 is DOUBLE PRECISION array, dimension (LDQ2,N)
154 *> If ICOMPQ = 0, Q2 is not referenced. Otherwise,
155 *> a copy of the first K eigenvectors which will be used by
156 *> DLAED7 in a matrix multiply (DGEMM) to update the new
163 *> The leading dimension of the array Q2. LDQ2 >= max(1,N).
168 *> W is DOUBLE PRECISION array, dimension (N)
169 *> The first k values of the final deflation-altered z-vector and
170 *> will be passed to DLAED3.
175 *> PERM is INTEGER array, dimension (N)
176 *> The permutations (from deflation and sorting) to be applied
177 *> to each eigenblock.
180 *> \param[out] GIVPTR
183 *> The number of Givens rotations which took place in this
187 *> \param[out] GIVCOL
189 *> GIVCOL is INTEGER array, dimension (2, N)
190 *> Each pair of numbers indicates a pair of columns to take place
191 *> in a Givens rotation.
194 *> \param[out] GIVNUM
196 *> GIVNUM is DOUBLE PRECISION array, dimension (2, N)
197 *> Each number indicates the S value to be used in the
198 *> corresponding Givens rotation.
203 *> INDXP is INTEGER array, dimension (N)
204 *> The permutation used to place deflated values of D at the end
205 *> of the array. INDXP(1:K) points to the nondeflated D-values
206 *> and INDXP(K+1:N) points to the deflated eigenvalues.
211 *> INDX is INTEGER array, dimension (N)
212 *> The permutation used to sort the contents of D into ascending
219 *> = 0: successful exit.
220 *> < 0: if INFO = -i, the i-th argument had an illegal value.
226 *> \author Univ. of Tennessee
227 *> \author Univ. of California Berkeley
228 *> \author Univ. of Colorado Denver
231 *> \date September 2012
233 *> \ingroup auxOTHERcomputational
235 *> \par Contributors:
238 *> Jeff Rutter, Computer Science Division, University of California
241 * =====================================================================
242 SUBROUTINE DLAED8( ICOMPQ, K, N, QSIZ, D, Q, LDQ, INDXQ, RHO,
243 $ CUTPNT, Z, DLAMDA, Q2, LDQ2, W, PERM, GIVPTR,
244 $ GIVCOL, GIVNUM, INDXP, INDX, INFO )
246 * -- LAPACK computational routine (version 3.4.2) --
247 * -- LAPACK is a software package provided by Univ. of Tennessee, --
248 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
251 * .. Scalar Arguments ..
252 INTEGER CUTPNT, GIVPTR, ICOMPQ, INFO, K, LDQ, LDQ2, N,
256 * .. Array Arguments ..
257 INTEGER GIVCOL( 2, * ), INDX( * ), INDXP( * ),
258 $ INDXQ( * ), PERM( * )
259 DOUBLE PRECISION D( * ), DLAMDA( * ), GIVNUM( 2, * ),
260 $ Q( LDQ, * ), Q2( LDQ2, * ), W( * ), Z( * )
263 * =====================================================================
266 DOUBLE PRECISION MONE, ZERO, ONE, TWO, EIGHT
267 PARAMETER ( MONE = -1.0D0, ZERO = 0.0D0, ONE = 1.0D0,
268 $ TWO = 2.0D0, EIGHT = 8.0D0 )
270 * .. Local Scalars ..
272 INTEGER I, IMAX, J, JLAM, JMAX, JP, K2, N1, N1P1, N2
273 DOUBLE PRECISION C, EPS, S, T, TAU, TOL
275 * .. External Functions ..
277 DOUBLE PRECISION DLAMCH, DLAPY2
278 EXTERNAL IDAMAX, DLAMCH, DLAPY2
280 * .. External Subroutines ..
281 EXTERNAL DCOPY, DLACPY, DLAMRG, DROT, DSCAL, XERBLA
283 * .. Intrinsic Functions ..
284 INTRINSIC ABS, MAX, MIN, SQRT
286 * .. Executable Statements ..
288 * Test the input parameters.
292 IF( ICOMPQ.LT.0 .OR. ICOMPQ.GT.1 ) THEN
294 ELSE IF( N.LT.0 ) THEN
296 ELSE IF( ICOMPQ.EQ.1 .AND. QSIZ.LT.N ) THEN
298 ELSE IF( LDQ.LT.MAX( 1, N ) ) THEN
300 ELSE IF( CUTPNT.LT.MIN( 1, N ) .OR. CUTPNT.GT.N ) THEN
302 ELSE IF( LDQ2.LT.MAX( 1, N ) ) THEN
306 CALL XERBLA( 'DLAED8', -INFO )
310 * Need to initialize GIVPTR to O here in case of quick exit
311 * to prevent an unspecified code behavior (usually sigfault)
312 * when IWORK array on entry to *stedc is not zeroed
313 * (or at least some IWORK entries which used in *laed7 for GIVPTR).
317 * Quick return if possible
326 IF( RHO.LT.ZERO ) THEN
327 CALL DSCAL( N2, MONE, Z( N1P1 ), 1 )
330 * Normalize z so that norm(z) = 1
332 T = ONE / SQRT( TWO )
336 CALL DSCAL( N, T, Z, 1 )
339 * Sort the eigenvalues into increasing order
341 DO 20 I = CUTPNT + 1, N
342 INDXQ( I ) = INDXQ( I ) + CUTPNT
345 DLAMDA( I ) = D( INDXQ( I ) )
346 W( I ) = Z( INDXQ( I ) )
350 CALL DLAMRG( N1, N2, DLAMDA, 1, 1, INDX )
352 D( I ) = DLAMDA( INDX( I ) )
353 Z( I ) = W( INDX( I ) )
356 * Calculate the allowable deflation tolerence
358 IMAX = IDAMAX( N, Z, 1 )
359 JMAX = IDAMAX( N, D, 1 )
360 EPS = DLAMCH( 'Epsilon' )
361 TOL = EIGHT*EPS*ABS( D( JMAX ) )
363 * If the rank-1 modifier is small enough, no more needs to be done
364 * except to reorganize Q so that its columns correspond with the
367 IF( RHO*ABS( Z( IMAX ) ).LE.TOL ) THEN
369 IF( ICOMPQ.EQ.0 ) THEN
371 PERM( J ) = INDXQ( INDX( J ) )
375 PERM( J ) = INDXQ( INDX( J ) )
376 CALL DCOPY( QSIZ, Q( 1, PERM( J ) ), 1, Q2( 1, J ), 1 )
378 CALL DLACPY( 'A', QSIZ, N, Q2( 1, 1 ), LDQ2, Q( 1, 1 ),
384 * If there are multiple eigenvalues then the problem deflates. Here
385 * the number of equal eigenvalues are found. As each equal
386 * eigenvalue is found, an elementary reflector is computed to rotate
387 * the corresponding eigensubspace so that the corresponding
388 * components of Z are zero in this new basis.
393 IF( RHO*ABS( Z( J ) ).LE.TOL ) THEN
395 * Deflate due to small z component.
410 IF( RHO*ABS( Z( J ) ).LE.TOL ) THEN
412 * Deflate due to small z component.
418 * Check if eigenvalues are close enough to allow deflation.
423 * Find sqrt(a**2+b**2) without overflow or
424 * destructive underflow.
427 T = D( J ) - D( JLAM )
430 IF( ABS( T*C*S ).LE.TOL ) THEN
432 * Deflation is possible.
437 * Record the appropriate Givens rotation
440 GIVCOL( 1, GIVPTR ) = INDXQ( INDX( JLAM ) )
441 GIVCOL( 2, GIVPTR ) = INDXQ( INDX( J ) )
442 GIVNUM( 1, GIVPTR ) = C
443 GIVNUM( 2, GIVPTR ) = S
444 IF( ICOMPQ.EQ.1 ) THEN
445 CALL DROT( QSIZ, Q( 1, INDXQ( INDX( JLAM ) ) ), 1,
446 $ Q( 1, INDXQ( INDX( J ) ) ), 1, C, S )
448 T = D( JLAM )*C*C + D( J )*S*S
449 D( J ) = D( JLAM )*S*S + D( J )*C*C
455 IF( D( JLAM ).LT.D( INDXP( K2+I ) ) ) THEN
456 INDXP( K2+I-1 ) = INDXP( K2+I )
461 INDXP( K2+I-1 ) = JLAM
464 INDXP( K2+I-1 ) = JLAM
470 DLAMDA( K ) = D( JLAM )
478 * Record the last eigenvalue.
482 DLAMDA( K ) = D( JLAM )
487 * Sort the eigenvalues and corresponding eigenvectors into DLAMDA
488 * and Q2 respectively. The eigenvalues/vectors which were not
489 * deflated go into the first K slots of DLAMDA and Q2 respectively,
490 * while those which were deflated go into the last N - K slots.
492 IF( ICOMPQ.EQ.0 ) THEN
495 DLAMDA( J ) = D( JP )
496 PERM( J ) = INDXQ( INDX( JP ) )
501 DLAMDA( J ) = D( JP )
502 PERM( J ) = INDXQ( INDX( JP ) )
503 CALL DCOPY( QSIZ, Q( 1, PERM( J ) ), 1, Q2( 1, J ), 1 )
507 * The deflated eigenvalues and their corresponding vectors go back
508 * into the last N - K slots of D and Q respectively.
511 IF( ICOMPQ.EQ.0 ) THEN
512 CALL DCOPY( N-K, DLAMDA( K+1 ), 1, D( K+1 ), 1 )
514 CALL DCOPY( N-K, DLAMDA( K+1 ), 1, D( K+1 ), 1 )
515 CALL DLACPY( 'A', QSIZ, N-K, Q2( 1, K+1 ), LDQ2,