1 *> \brief \b CLAED8 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 CLAED8 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/claed8.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/claed8.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/claed8.f">
21 * SUBROUTINE CLAED8( K, N, QSIZ, Q, LDQ, D, RHO, CUTPNT, Z, DLAMDA,
22 * Q2, LDQ2, W, INDXP, INDX, INDXQ, PERM, GIVPTR,
23 * GIVCOL, GIVNUM, INFO )
25 * .. Scalar Arguments ..
26 * INTEGER CUTPNT, GIVPTR, INFO, K, LDQ, LDQ2, N, QSIZ
29 * .. Array Arguments ..
30 * INTEGER GIVCOL( 2, * ), INDX( * ), INDXP( * ),
31 * $ INDXQ( * ), PERM( * )
32 * REAL D( * ), DLAMDA( * ), GIVNUM( 2, * ), W( * ),
34 * COMPLEX Q( LDQ, * ), Q2( LDQ2, * )
43 *> CLAED8 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 *> Contains the number of non-deflated eigenvalues.
58 *> This is the order of the related secular equation.
64 *> The dimension of the symmetric tridiagonal matrix. N >= 0.
70 *> The dimension of the unitary matrix used to reduce
71 *> the dense or band matrix to tridiagonal form.
72 *> QSIZ >= N if ICOMPQ = 1.
77 *> Q is COMPLEX array, dimension (LDQ,N)
78 *> On entry, Q contains the eigenvectors of the partially solved
79 *> system which has been previously updated in matrix
80 *> multiplies with other partially solved eigensystems.
81 *> On exit, Q contains the trailing (N-K) updated eigenvectors
82 *> (those which were deflated) in its last N-K columns.
88 *> The leading dimension of the array Q. LDQ >= max( 1, N ).
93 *> D is REAL array, dimension (N)
94 *> On entry, D contains the eigenvalues of the two submatrices to
95 *> be combined. On exit, D contains the trailing (N-K) updated
96 *> eigenvalues (those which were deflated) sorted into increasing
100 *> \param[in,out] RHO
103 *> Contains the off diagonal element associated with the rank-1
104 *> cut which originally split the two submatrices which are now
105 *> being recombined. RHO is modified during the computation to
106 *> the value required by SLAED3.
112 *> Contains the location of the last eigenvalue in the leading
113 *> sub-matrix. MIN(1,N) <= CUTPNT <= N.
118 *> Z is REAL array, dimension (N)
119 *> On input this vector contains the updating vector (the last
120 *> row of the first sub-eigenvector matrix and the first row of
121 *> the second sub-eigenvector matrix). The contents of Z are
122 *> destroyed during the updating process.
125 *> \param[out] DLAMDA
127 *> DLAMDA is REAL array, dimension (N)
128 *> Contains a copy of the first K eigenvalues which will be used
129 *> by SLAED3 to form the secular equation.
134 *> Q2 is COMPLEX array, dimension (LDQ2,N)
135 *> If ICOMPQ = 0, Q2 is not referenced. Otherwise,
136 *> Contains a copy of the first K eigenvectors which will be used
137 *> by SLAED7 in a matrix multiply (SGEMM) to update the new
144 *> The leading dimension of the array Q2. LDQ2 >= max( 1, N ).
149 *> W is REAL array, dimension (N)
150 *> This will hold the first k values of the final
151 *> deflation-altered z-vector and will be passed to SLAED3.
156 *> INDXP is INTEGER array, dimension (N)
157 *> This will contain the permutation used to place deflated
158 *> values of D at the end of the array. On output INDXP(1:K)
159 *> points to the nondeflated D-values and INDXP(K+1:N)
160 *> points to the deflated eigenvalues.
165 *> INDX is INTEGER array, dimension (N)
166 *> This will contain the permutation used to sort the contents of
167 *> D into ascending order.
172 *> INDXQ is INTEGER array, dimension (N)
173 *> This contains the permutation which separately sorts the two
174 *> sub-problems in D into ascending order. Note that elements in
175 *> the second half of this permutation must first have CUTPNT
176 *> added to their values in order to be accurate.
181 *> PERM is INTEGER array, dimension (N)
182 *> Contains the permutations (from deflation and sorting) to be
183 *> applied to each eigenblock.
186 *> \param[out] GIVPTR
189 *> Contains the number of Givens rotations which took place in
193 *> \param[out] GIVCOL
195 *> GIVCOL is INTEGER array, dimension (2, N)
196 *> Each pair of numbers indicates a pair of columns to take place
197 *> in a Givens rotation.
200 *> \param[out] GIVNUM
202 *> GIVNUM is REAL array, dimension (2, N)
203 *> Each number indicates the S value to be used in the
204 *> corresponding Givens rotation.
210 *> = 0: successful exit.
211 *> < 0: if INFO = -i, the i-th argument had an illegal value.
217 *> \author Univ. of Tennessee
218 *> \author Univ. of California Berkeley
219 *> \author Univ. of Colorado Denver
222 *> \date September 2012
224 *> \ingroup complexOTHERcomputational
226 * =====================================================================
227 SUBROUTINE CLAED8( K, N, QSIZ, Q, LDQ, D, RHO, CUTPNT, Z, DLAMDA,
228 $ Q2, LDQ2, W, INDXP, INDX, INDXQ, PERM, GIVPTR,
229 $ GIVCOL, GIVNUM, INFO )
231 * -- LAPACK computational routine (version 3.4.2) --
232 * -- LAPACK is a software package provided by Univ. of Tennessee, --
233 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
236 * .. Scalar Arguments ..
237 INTEGER CUTPNT, GIVPTR, INFO, K, LDQ, LDQ2, N, QSIZ
240 * .. Array Arguments ..
241 INTEGER GIVCOL( 2, * ), INDX( * ), INDXP( * ),
242 $ INDXQ( * ), PERM( * )
243 REAL D( * ), DLAMDA( * ), GIVNUM( 2, * ), W( * ),
245 COMPLEX Q( LDQ, * ), Q2( LDQ2, * )
248 * =====================================================================
251 REAL MONE, ZERO, ONE, TWO, EIGHT
252 PARAMETER ( MONE = -1.0E0, ZERO = 0.0E0, ONE = 1.0E0,
253 $ TWO = 2.0E0, EIGHT = 8.0E0 )
255 * .. Local Scalars ..
256 INTEGER I, IMAX, J, JLAM, JMAX, JP, K2, N1, N1P1, N2
257 REAL C, EPS, S, T, TAU, TOL
259 * .. External Functions ..
262 EXTERNAL ISAMAX, SLAMCH, SLAPY2
264 * .. External Subroutines ..
265 EXTERNAL CCOPY, CLACPY, CSROT, SCOPY, SLAMRG, SSCAL,
268 * .. Intrinsic Functions ..
269 INTRINSIC ABS, MAX, MIN, SQRT
271 * .. Executable Statements ..
273 * Test the input parameters.
279 ELSE IF( QSIZ.LT.N ) THEN
281 ELSE IF( LDQ.LT.MAX( 1, N ) ) THEN
283 ELSE IF( CUTPNT.LT.MIN( 1, N ) .OR. CUTPNT.GT.N ) THEN
285 ELSE IF( LDQ2.LT.MAX( 1, N ) ) THEN
289 CALL XERBLA( 'CLAED8', -INFO )
293 * Need to initialize GIVPTR to O here in case of quick exit
294 * to prevent an unspecified code behavior (usually sigfault)
295 * when IWORK array on entry to *stedc is not zeroed
296 * (or at least some IWORK entries which used in *laed7 for GIVPTR).
300 * Quick return if possible
309 IF( RHO.LT.ZERO ) THEN
310 CALL SSCAL( N2, MONE, Z( N1P1 ), 1 )
313 * Normalize z so that norm(z) = 1
315 T = ONE / SQRT( TWO )
319 CALL SSCAL( N, T, Z, 1 )
322 * Sort the eigenvalues into increasing order
324 DO 20 I = CUTPNT + 1, N
325 INDXQ( I ) = INDXQ( I ) + CUTPNT
328 DLAMDA( I ) = D( INDXQ( I ) )
329 W( I ) = Z( INDXQ( I ) )
333 CALL SLAMRG( N1, N2, DLAMDA, 1, 1, INDX )
335 D( I ) = DLAMDA( INDX( I ) )
336 Z( I ) = W( INDX( I ) )
339 * Calculate the allowable deflation tolerance
341 IMAX = ISAMAX( N, Z, 1 )
342 JMAX = ISAMAX( N, D, 1 )
343 EPS = SLAMCH( 'Epsilon' )
344 TOL = EIGHT*EPS*ABS( D( JMAX ) )
346 * If the rank-1 modifier is small enough, no more needs to be done
347 * -- except to reorganize Q so that its columns correspond with the
350 IF( RHO*ABS( Z( IMAX ) ).LE.TOL ) THEN
353 PERM( J ) = INDXQ( INDX( J ) )
354 CALL CCOPY( QSIZ, Q( 1, PERM( J ) ), 1, Q2( 1, J ), 1 )
356 CALL CLACPY( 'A', QSIZ, N, Q2( 1, 1 ), LDQ2, Q( 1, 1 ), LDQ )
360 * If there are multiple eigenvalues then the problem deflates. Here
361 * the number of equal eigenvalues are found. As each equal
362 * eigenvalue is found, an elementary reflector is computed to rotate
363 * the corresponding eigensubspace so that the corresponding
364 * components of Z are zero in this new basis.
369 IF( RHO*ABS( Z( J ) ).LE.TOL ) THEN
371 * Deflate due to small z component.
386 IF( RHO*ABS( Z( J ) ).LE.TOL ) THEN
388 * Deflate due to small z component.
394 * Check if eigenvalues are close enough to allow deflation.
399 * Find sqrt(a**2+b**2) without overflow or
400 * destructive underflow.
403 T = D( J ) - D( JLAM )
406 IF( ABS( T*C*S ).LE.TOL ) THEN
408 * Deflation is possible.
413 * Record the appropriate Givens rotation
416 GIVCOL( 1, GIVPTR ) = INDXQ( INDX( JLAM ) )
417 GIVCOL( 2, GIVPTR ) = INDXQ( INDX( J ) )
418 GIVNUM( 1, GIVPTR ) = C
419 GIVNUM( 2, GIVPTR ) = S
420 CALL CSROT( QSIZ, Q( 1, INDXQ( INDX( JLAM ) ) ), 1,
421 $ Q( 1, INDXQ( INDX( J ) ) ), 1, C, S )
422 T = D( JLAM )*C*C + D( J )*S*S
423 D( J ) = D( JLAM )*S*S + D( J )*C*C
429 IF( D( JLAM ).LT.D( INDXP( K2+I ) ) ) THEN
430 INDXP( K2+I-1 ) = INDXP( K2+I )
435 INDXP( K2+I-1 ) = JLAM
438 INDXP( K2+I-1 ) = JLAM
444 DLAMDA( K ) = D( JLAM )
452 * Record the last eigenvalue.
456 DLAMDA( K ) = D( JLAM )
461 * Sort the eigenvalues and corresponding eigenvectors into DLAMDA
462 * and Q2 respectively. The eigenvalues/vectors which were not
463 * deflated go into the first K slots of DLAMDA and Q2 respectively,
464 * while those which were deflated go into the last N - K slots.
468 DLAMDA( J ) = D( JP )
469 PERM( J ) = INDXQ( INDX( JP ) )
470 CALL CCOPY( QSIZ, Q( 1, PERM( J ) ), 1, Q2( 1, J ), 1 )
473 * The deflated eigenvalues and their corresponding vectors go back
474 * into the last N - K slots of D and Q respectively.
477 CALL SCOPY( N-K, DLAMDA( K+1 ), 1, D( K+1 ), 1 )
478 CALL CLACPY( 'A', QSIZ, N-K, Q2( 1, K+1 ), LDQ2, Q( 1, K+1 ),