1 *> \brief \b DLAED2 used by sstedc. Merges eigenvalues and deflates secular equation. Used when the original matrix is tridiagonal.
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DLAED2 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlaed2.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlaed2.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlaed2.f">
21 * SUBROUTINE DLAED2( K, N, N1, D, Q, LDQ, INDXQ, RHO, Z, DLAMDA, W,
22 * Q2, INDX, INDXC, INDXP, COLTYP, INFO )
24 * .. Scalar Arguments ..
25 * INTEGER INFO, K, LDQ, N, N1
26 * DOUBLE PRECISION RHO
28 * .. Array Arguments ..
29 * INTEGER COLTYP( * ), INDX( * ), INDXC( * ), INDXP( * ),
31 * DOUBLE PRECISION D( * ), DLAMDA( * ), Q( LDQ, * ), Q2( * ),
41 *> DLAED2 merges the two sets of eigenvalues together into a single
42 *> sorted set. Then it tries to deflate the size of the problem.
43 *> There are two ways in which deflation can occur: when two or more
44 *> eigenvalues are close together or if there is a tiny entry in the
45 *> Z vector. For each such occurrence the order of the related secular
46 *> equation problem is reduced by one.
55 *> The number of non-deflated eigenvalues, and the order of the
56 *> related secular equation. 0 <= K <=N.
62 *> The dimension of the symmetric tridiagonal matrix. N >= 0.
68 *> The location of the last eigenvalue in the leading sub-matrix.
69 *> min(1,N) <= N1 <= N/2.
74 *> D is DOUBLE PRECISION array, dimension (N)
75 *> On entry, D contains the eigenvalues of the two submatrices to
77 *> On exit, D contains the trailing (N-K) updated eigenvalues
78 *> (those which were deflated) sorted into increasing order.
83 *> Q is DOUBLE PRECISION array, dimension (LDQ, N)
84 *> On entry, Q contains the eigenvectors of two submatrices in
85 *> the two square blocks with corners at (1,1), (N1,N1)
86 *> and (N1+1, N1+1), (N,N).
87 *> On exit, Q contains the trailing (N-K) updated eigenvectors
88 *> (those which were deflated) in its last N-K columns.
94 *> The leading dimension of the array Q. LDQ >= max(1,N).
97 *> \param[in,out] INDXQ
99 *> INDXQ is INTEGER array, dimension (N)
100 *> The permutation which separately sorts the two sub-problems
101 *> in D into ascending order. Note that elements in the second
102 *> half of this permutation must first have N1 added to their
103 *> values. Destroyed on exit.
106 *> \param[in,out] RHO
108 *> RHO is DOUBLE PRECISION
109 *> On entry, the off-diagonal element associated with the rank-1
110 *> cut which originally split the two submatrices which are now
112 *> On exit, RHO has been modified to the value required by
118 *> Z is DOUBLE PRECISION array, dimension (N)
119 *> On entry, Z 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).
122 *> On exit, the contents of Z have been destroyed by the updating
126 *> \param[out] DLAMDA
128 *> DLAMDA is DOUBLE PRECISION array, dimension (N)
129 *> A copy of the first K eigenvalues which will be used by
130 *> DLAED3 to form the secular equation.
135 *> W is DOUBLE PRECISION array, dimension (N)
136 *> The first k values of the final deflation-altered z-vector
137 *> which will be passed to DLAED3.
142 *> Q2 is DOUBLE PRECISION array, dimension (N1**2+(N-N1)**2)
143 *> A copy of the first K eigenvectors which will be used by
144 *> DLAED3 in a matrix multiply (DGEMM) to solve for the new
150 *> INDX is INTEGER array, dimension (N)
151 *> The permutation used to sort the contents of DLAMDA into
157 *> INDXC is INTEGER array, dimension (N)
158 *> The permutation used to arrange the columns of the deflated
159 *> Q matrix into three groups: the first group contains non-zero
160 *> elements only at and above N1, the second contains
161 *> non-zero elements only below N1, and the third is dense.
166 *> INDXP is INTEGER array, dimension (N)
167 *> The permutation used to place deflated values of D at the end
168 *> of the array. INDXP(1:K) points to the nondeflated D-values
169 *> and INDXP(K+1:N) points to the deflated eigenvalues.
172 *> \param[out] COLTYP
174 *> COLTYP is INTEGER array, dimension (N)
175 *> During execution, a label which will indicate which of the
176 *> following types a column in the Q2 matrix is:
177 *> 1 : non-zero in the upper half only;
179 *> 3 : non-zero in the lower half only;
181 *> On exit, COLTYP(i) is the number of columns of type i,
182 *> for i=1 to 4 only.
188 *> = 0: successful exit.
189 *> < 0: if INFO = -i, the i-th argument had an illegal value.
195 *> \author Univ. of Tennessee
196 *> \author Univ. of California Berkeley
197 *> \author Univ. of Colorado Denver
200 *> \date September 2012
202 *> \ingroup auxOTHERcomputational
204 *> \par Contributors:
207 *> Jeff Rutter, Computer Science Division, University of California
208 *> at Berkeley, USA \n
209 *> Modified by Francoise Tisseur, University of Tennessee
211 * =====================================================================
212 SUBROUTINE DLAED2( K, N, N1, D, Q, LDQ, INDXQ, RHO, Z, DLAMDA, W,
213 $ Q2, INDX, INDXC, INDXP, COLTYP, INFO )
215 * -- LAPACK computational routine (version 3.4.2) --
216 * -- LAPACK is a software package provided by Univ. of Tennessee, --
217 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
220 * .. Scalar Arguments ..
221 INTEGER INFO, K, LDQ, N, N1
224 * .. Array Arguments ..
225 INTEGER COLTYP( * ), INDX( * ), INDXC( * ), INDXP( * ),
227 DOUBLE PRECISION D( * ), DLAMDA( * ), Q( LDQ, * ), Q2( * ),
231 * =====================================================================
234 DOUBLE PRECISION MONE, ZERO, ONE, TWO, EIGHT
235 PARAMETER ( MONE = -1.0D0, ZERO = 0.0D0, ONE = 1.0D0,
236 $ TWO = 2.0D0, EIGHT = 8.0D0 )
239 INTEGER CTOT( 4 ), PSM( 4 )
241 * .. Local Scalars ..
242 INTEGER CT, I, IMAX, IQ1, IQ2, J, JMAX, JS, K2, N1P1,
244 DOUBLE PRECISION C, EPS, S, T, TAU, TOL
246 * .. External Functions ..
248 DOUBLE PRECISION DLAMCH, DLAPY2
249 EXTERNAL IDAMAX, DLAMCH, DLAPY2
251 * .. External Subroutines ..
252 EXTERNAL DCOPY, DLACPY, DLAMRG, DROT, DSCAL, XERBLA
254 * .. Intrinsic Functions ..
255 INTRINSIC ABS, MAX, MIN, SQRT
257 * .. Executable Statements ..
259 * Test the input parameters.
265 ELSE IF( LDQ.LT.MAX( 1, N ) ) THEN
267 ELSE IF( MIN( 1, ( N / 2 ) ).GT.N1 .OR. ( N / 2 ).LT.N1 ) THEN
271 CALL XERBLA( 'DLAED2', -INFO )
275 * Quick return if possible
283 IF( RHO.LT.ZERO ) THEN
284 CALL DSCAL( N2, MONE, Z( N1P1 ), 1 )
287 * Normalize z so that norm(z) = 1. Since z is the concatenation of
288 * two normalized vectors, norm2(z) = sqrt(2).
290 T = ONE / SQRT( TWO )
291 CALL DSCAL( N, T, Z, 1 )
293 * RHO = ABS( norm(z)**2 * RHO )
297 * Sort the eigenvalues into increasing order
300 INDXQ( I ) = INDXQ( I ) + N1
303 * re-integrate the deflated parts from the last pass
306 DLAMDA( I ) = D( INDXQ( I ) )
308 CALL DLAMRG( N1, N2, DLAMDA, 1, 1, INDXC )
310 INDX( I ) = INDXQ( INDXC( I ) )
313 * Calculate the allowable deflation tolerance
315 IMAX = IDAMAX( N, Z, 1 )
316 JMAX = IDAMAX( N, D, 1 )
317 EPS = DLAMCH( 'Epsilon' )
318 TOL = EIGHT*EPS*MAX( ABS( D( JMAX ) ), ABS( Z( IMAX ) ) )
320 * If the rank-1 modifier is small enough, no more needs to be done
321 * except to reorganize Q so that its columns correspond with the
324 IF( RHO*ABS( Z( IMAX ) ).LE.TOL ) THEN
329 CALL DCOPY( N, Q( 1, I ), 1, Q2( IQ2 ), 1 )
333 CALL DLACPY( 'A', N, N, Q2, N, Q, LDQ )
334 CALL DCOPY( N, DLAMDA, 1, D, 1 )
338 * If there are multiple eigenvalues then the problem deflates. Here
339 * the number of equal eigenvalues are found. As each equal
340 * eigenvalue is found, an elementary reflector is computed to rotate
341 * the corresponding eigensubspace so that the corresponding
342 * components of Z are zero in this new basis.
356 IF( RHO*ABS( Z( NJ ) ).LE.TOL ) THEN
358 * Deflate due to small z component.
375 IF( RHO*ABS( Z( NJ ) ).LE.TOL ) THEN
377 * Deflate due to small z component.
384 * Check if eigenvalues are close enough to allow deflation.
389 * Find sqrt(a**2+b**2) without overflow or
390 * destructive underflow.
393 T = D( NJ ) - D( PJ )
396 IF( ABS( T*C*S ).LE.TOL ) THEN
398 * Deflation is possible.
402 IF( COLTYP( NJ ).NE.COLTYP( PJ ) )
405 CALL DROT( N, Q( 1, PJ ), 1, Q( 1, NJ ), 1, C, S )
406 T = D( PJ )*C**2 + D( NJ )*S**2
407 D( NJ ) = D( PJ )*S**2 + D( NJ )*C**2
413 IF( D( PJ ).LT.D( INDXP( K2+I ) ) ) THEN
414 INDXP( K2+I-1 ) = INDXP( K2+I )
427 DLAMDA( K ) = D( PJ )
436 * Record the last eigenvalue.
439 DLAMDA( K ) = D( PJ )
443 * Count up the total number of the various types of columns, then
444 * form a permutation which positions the four column types into
445 * four uniform groups (although one or more of these groups may be
453 CTOT( CT ) = CTOT( CT ) + 1
456 * PSM(*) = Position in SubMatrix (of types 1 through 4)
459 PSM( 2 ) = 1 + CTOT( 1 )
460 PSM( 3 ) = PSM( 2 ) + CTOT( 2 )
461 PSM( 4 ) = PSM( 3 ) + CTOT( 3 )
464 * Fill out the INDXC array so that the permutation which it induces
465 * will place all type-1 columns first, all type-2 columns next,
466 * then all type-3's, and finally all type-4's.
471 INDX( PSM( CT ) ) = JS
472 INDXC( PSM( CT ) ) = J
473 PSM( CT ) = PSM( CT ) + 1
476 * Sort the eigenvalues and corresponding eigenvectors into DLAMDA
477 * and Q2 respectively. The eigenvalues/vectors which were not
478 * deflated go into the first K slots of DLAMDA and Q2 respectively,
479 * while those which were deflated go into the last N - K slots.
483 IQ2 = 1 + ( CTOT( 1 )+CTOT( 2 ) )*N1
484 DO 140 J = 1, CTOT( 1 )
486 CALL DCOPY( N1, Q( 1, JS ), 1, Q2( IQ1 ), 1 )
492 DO 150 J = 1, CTOT( 2 )
494 CALL DCOPY( N1, Q( 1, JS ), 1, Q2( IQ1 ), 1 )
495 CALL DCOPY( N2, Q( N1+1, JS ), 1, Q2( IQ2 ), 1 )
502 DO 160 J = 1, CTOT( 3 )
504 CALL DCOPY( N2, Q( N1+1, JS ), 1, Q2( IQ2 ), 1 )
511 DO 170 J = 1, CTOT( 4 )
513 CALL DCOPY( N, Q( 1, JS ), 1, Q2( IQ2 ), 1 )
519 * The deflated eigenvalues and their corresponding vectors go back
520 * into the last N - K slots of D and Q respectively.
523 CALL DLACPY( 'A', N, CTOT( 4 ), Q2( IQ1 ), N,
525 CALL DCOPY( N-K, Z( K+1 ), 1, D( K+1 ), 1 )
528 * Copy CTOT into COLTYP for referencing in DLAED3.
531 COLTYP( J ) = CTOT( J )