1 *> \brief \b DLASD7 merges the two sets of singular values together into a single sorted set. Then it tries to deflate the size of the problem. Used by sbdsdc.
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DLASD7 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlasd7.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlasd7.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlasd7.f">
21 * SUBROUTINE DLASD7( ICOMPQ, NL, NR, SQRE, K, D, Z, ZW, VF, VFW, VL,
22 * VLW, ALPHA, BETA, DSIGMA, IDX, IDXP, IDXQ,
23 * PERM, GIVPTR, GIVCOL, LDGCOL, GIVNUM, LDGNUM,
26 * .. Scalar Arguments ..
27 * INTEGER GIVPTR, ICOMPQ, INFO, K, LDGCOL, LDGNUM, NL,
29 * DOUBLE PRECISION ALPHA, BETA, C, S
31 * .. Array Arguments ..
32 * INTEGER GIVCOL( LDGCOL, * ), IDX( * ), IDXP( * ),
33 * $ IDXQ( * ), PERM( * )
34 * DOUBLE PRECISION D( * ), DSIGMA( * ), GIVNUM( LDGNUM, * ),
35 * $ VF( * ), VFW( * ), VL( * ), VLW( * ), Z( * ),
45 *> DLASD7 merges the two sets of singular values together into a single
46 *> sorted set. Then it tries to deflate the size of the problem. There
47 *> are two ways in which deflation can occur: when two or more singular
48 *> values are close together or if there is a tiny entry in the Z
49 *> vector. For each such occurrence the order of the related
50 *> secular equation problem is reduced by one.
52 *> DLASD7 is called from DLASD6.
61 *> Specifies whether singular vectors are to be computed
62 *> in compact form, as follows:
63 *> = 0: Compute singular values only.
64 *> = 1: Compute singular vectors of upper
65 *> bidiagonal matrix in compact form.
71 *> The row dimension of the upper block. NL >= 1.
77 *> The row dimension of the lower block. NR >= 1.
83 *> = 0: the lower block is an NR-by-NR square matrix.
84 *> = 1: the lower block is an NR-by-(NR+1) rectangular matrix.
86 *> The bidiagonal matrix has
87 *> N = NL + NR + 1 rows and
88 *> M = N + SQRE >= N columns.
94 *> Contains the dimension of the non-deflated matrix, this is
95 *> the order of the related secular equation. 1 <= K <=N.
100 *> D is DOUBLE PRECISION array, dimension ( N )
101 *> On entry D contains the singular values of the two submatrices
102 *> to be combined. On exit D contains the trailing (N-K) updated
103 *> singular values (those which were deflated) sorted into
109 *> Z is DOUBLE PRECISION array, dimension ( M )
110 *> On exit Z contains the updating row vector in the secular
116 *> ZW is DOUBLE PRECISION array, dimension ( M )
122 *> VF is DOUBLE PRECISION array, dimension ( M )
123 *> On entry, VF(1:NL+1) contains the first components of all
124 *> right singular vectors of the upper block; and VF(NL+2:M)
125 *> contains the first components of all right singular vectors
126 *> of the lower block. On exit, VF contains the first components
127 *> of all right singular vectors of the bidiagonal matrix.
132 *> VFW is DOUBLE PRECISION array, dimension ( M )
138 *> VL is DOUBLE PRECISION array, dimension ( M )
139 *> On entry, VL(1:NL+1) contains the last components of all
140 *> right singular vectors of the upper block; and VL(NL+2:M)
141 *> contains the last components of all right singular vectors
142 *> of the lower block. On exit, VL contains the last components
143 *> of all right singular vectors of the bidiagonal matrix.
148 *> VLW is DOUBLE PRECISION array, dimension ( M )
154 *> ALPHA is DOUBLE PRECISION
155 *> Contains the diagonal element associated with the added row.
160 *> BETA is DOUBLE PRECISION
161 *> Contains the off-diagonal element associated with the added
165 *> \param[out] DSIGMA
167 *> DSIGMA is DOUBLE PRECISION array, dimension ( N )
168 *> Contains a copy of the diagonal elements (K-1 singular values
169 *> and one zero) in the secular equation.
174 *> IDX is INTEGER array, dimension ( N )
175 *> This will contain the permutation used to sort the contents of
176 *> D into ascending order.
181 *> IDXP is INTEGER array, dimension ( N )
182 *> This will contain the permutation used to place deflated
183 *> values of D at the end of the array. On output IDXP(2:K)
184 *> points to the nondeflated D-values and IDXP(K+1:N)
185 *> points to the deflated singular values.
190 *> IDXQ is INTEGER array, dimension ( N )
191 *> This contains the permutation which separately sorts the two
192 *> sub-problems in D into ascending order. Note that entries in
193 *> the first half of this permutation must first be moved one
194 *> position backward; and entries in the second half
195 *> must first have NL+1 added to their values.
200 *> PERM is INTEGER array, dimension ( N )
201 *> The permutations (from deflation and sorting) to be applied
202 *> to each singular block. Not referenced if ICOMPQ = 0.
205 *> \param[out] GIVPTR
208 *> The number of Givens rotations which took place in this
209 *> subproblem. Not referenced if ICOMPQ = 0.
212 *> \param[out] GIVCOL
214 *> GIVCOL is INTEGER array, dimension ( LDGCOL, 2 )
215 *> Each pair of numbers indicates a pair of columns to take place
216 *> in a Givens rotation. Not referenced if ICOMPQ = 0.
222 *> The leading dimension of GIVCOL, must be at least N.
225 *> \param[out] GIVNUM
227 *> GIVNUM is DOUBLE PRECISION array, dimension ( LDGNUM, 2 )
228 *> Each number indicates the C or S value to be used in the
229 *> corresponding Givens rotation. Not referenced if ICOMPQ = 0.
235 *> The leading dimension of GIVNUM, must be at least N.
240 *> C is DOUBLE PRECISION
241 *> C contains garbage if SQRE =0 and the C-value of a Givens
242 *> rotation related to the right null space if SQRE = 1.
247 *> S is DOUBLE PRECISION
248 *> S contains garbage if SQRE =0 and the S-value of a Givens
249 *> rotation related to the right null space if SQRE = 1.
255 *> = 0: successful exit.
256 *> < 0: if INFO = -i, the i-th argument had an illegal value.
262 *> \author Univ. of Tennessee
263 *> \author Univ. of California Berkeley
264 *> \author Univ. of Colorado Denver
267 *> \date September 2012
269 *> \ingroup auxOTHERauxiliary
271 *> \par Contributors:
274 *> Ming Gu and Huan Ren, Computer Science Division, University of
275 *> California at Berkeley, USA
277 * =====================================================================
278 SUBROUTINE DLASD7( ICOMPQ, NL, NR, SQRE, K, D, Z, ZW, VF, VFW, VL,
279 $ VLW, ALPHA, BETA, DSIGMA, IDX, IDXP, IDXQ,
280 $ PERM, GIVPTR, GIVCOL, LDGCOL, GIVNUM, LDGNUM,
283 * -- LAPACK auxiliary routine (version 3.4.2) --
284 * -- LAPACK is a software package provided by Univ. of Tennessee, --
285 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
288 * .. Scalar Arguments ..
289 INTEGER GIVPTR, ICOMPQ, INFO, K, LDGCOL, LDGNUM, NL,
291 DOUBLE PRECISION ALPHA, BETA, C, S
293 * .. Array Arguments ..
294 INTEGER GIVCOL( LDGCOL, * ), IDX( * ), IDXP( * ),
295 $ IDXQ( * ), PERM( * )
296 DOUBLE PRECISION D( * ), DSIGMA( * ), GIVNUM( LDGNUM, * ),
297 $ VF( * ), VFW( * ), VL( * ), VLW( * ), Z( * ),
301 * =====================================================================
304 DOUBLE PRECISION ZERO, ONE, TWO, EIGHT
305 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0, TWO = 2.0D+0,
308 * .. Local Scalars ..
310 INTEGER I, IDXI, IDXJ, IDXJP, J, JP, JPREV, K2, M, N,
312 DOUBLE PRECISION EPS, HLFTOL, TAU, TOL, Z1
314 * .. External Subroutines ..
315 EXTERNAL DCOPY, DLAMRG, DROT, XERBLA
317 * .. External Functions ..
318 DOUBLE PRECISION DLAMCH, DLAPY2
319 EXTERNAL DLAMCH, DLAPY2
321 * .. Intrinsic Functions ..
324 * .. Executable Statements ..
326 * Test the input parameters.
332 IF( ( ICOMPQ.LT.0 ) .OR. ( ICOMPQ.GT.1 ) ) THEN
334 ELSE IF( NL.LT.1 ) THEN
336 ELSE IF( NR.LT.1 ) THEN
338 ELSE IF( ( SQRE.LT.0 ) .OR. ( SQRE.GT.1 ) ) THEN
340 ELSE IF( LDGCOL.LT.N ) THEN
342 ELSE IF( LDGNUM.LT.N ) THEN
346 CALL XERBLA( 'DLASD7', -INFO )
352 IF( ICOMPQ.EQ.1 ) THEN
356 * Generate the first part of the vector Z and move the singular
357 * values in the first part of D one position backward.
359 Z1 = ALPHA*VL( NLP1 )
363 Z( I+1 ) = ALPHA*VL( I )
367 IDXQ( I+1 ) = IDXQ( I ) + 1
371 * Generate the second part of the vector Z.
374 Z( I ) = BETA*VF( I )
378 * Sort the singular values into increasing order
381 IDXQ( I ) = IDXQ( I ) + NLP1
384 * DSIGMA, IDXC, IDXC, and ZW are used as storage space.
387 DSIGMA( I ) = D( IDXQ( I ) )
388 ZW( I ) = Z( IDXQ( I ) )
389 VFW( I ) = VF( IDXQ( I ) )
390 VLW( I ) = VL( IDXQ( I ) )
393 CALL DLAMRG( NL, NR, DSIGMA( 2 ), 1, 1, IDX( 2 ) )
397 D( I ) = DSIGMA( IDXI )
399 VF( I ) = VFW( IDXI )
400 VL( I ) = VLW( IDXI )
403 * Calculate the allowable deflation tolerence
405 EPS = DLAMCH( 'Epsilon' )
406 TOL = MAX( ABS( ALPHA ), ABS( BETA ) )
407 TOL = EIGHT*EIGHT*EPS*MAX( ABS( D( N ) ), TOL )
409 * There are 2 kinds of deflation -- first a value in the z-vector
410 * is small, second two (or more) singular values are very close
411 * together (their difference is small).
413 * If the value in the z-vector is small, we simply permute the
414 * array so that the corresponding singular value is moved to the
417 * If two values in the D-vector are close, we perform a two-sided
418 * rotation designed to make one of the corresponding z-vector
419 * entries zero, and then permute the array so that the deflated
420 * singular value is moved to the end.
422 * If there are multiple singular values then the problem deflates.
423 * Here the number of equal singular values are found. As each equal
424 * singular value is found, an elementary reflector is computed to
425 * rotate the corresponding singular subspace so that the
426 * corresponding components of Z are zero in this new basis.
431 IF( ABS( Z( J ) ).LE.TOL ) THEN
433 * Deflate due to small z component.
450 IF( ABS( Z( J ) ).LE.TOL ) THEN
452 * Deflate due to small z component.
458 * Check if singular values are close enough to allow deflation.
460 IF( ABS( D( J )-D( JPREV ) ).LE.TOL ) THEN
462 * Deflation is possible.
467 * Find sqrt(a**2+b**2) without overflow or
468 * destructive underflow.
476 * Record the appropriate Givens rotation
478 IF( ICOMPQ.EQ.1 ) THEN
480 IDXJP = IDXQ( IDX( JPREV )+1 )
481 IDXJ = IDXQ( IDX( J )+1 )
482 IF( IDXJP.LE.NLP1 ) THEN
485 IF( IDXJ.LE.NLP1 ) THEN
488 GIVCOL( GIVPTR, 2 ) = IDXJP
489 GIVCOL( GIVPTR, 1 ) = IDXJ
490 GIVNUM( GIVPTR, 2 ) = C
491 GIVNUM( GIVPTR, 1 ) = S
493 CALL DROT( 1, VF( JPREV ), 1, VF( J ), 1, C, S )
494 CALL DROT( 1, VL( JPREV ), 1, VL( J ), 1, C, S )
501 DSIGMA( K ) = D( JPREV )
509 * Record the last singular value.
513 DSIGMA( K ) = D( JPREV )
518 * Sort the singular values into DSIGMA. The singular values which
519 * were not deflated go into the first K slots of DSIGMA, except
520 * that DSIGMA(1) is treated separately.
524 DSIGMA( J ) = D( JP )
528 IF( ICOMPQ.EQ.1 ) THEN
531 PERM( J ) = IDXQ( IDX( JP )+1 )
532 IF( PERM( J ).LE.NLP1 ) THEN
533 PERM( J ) = PERM( J ) - 1
538 * The deflated singular values go back into the last N - K slots of
541 CALL DCOPY( N-K, DSIGMA( K+1 ), 1, D( K+1 ), 1 )
543 * Determine DSIGMA(1), DSIGMA(2), Z(1), VF(1), VL(1), VF(M), and
548 IF( ABS( DSIGMA( 2 ) ).LE.HLFTOL )
549 $ DSIGMA( 2 ) = HLFTOL
551 Z( 1 ) = DLAPY2( Z1, Z( M ) )
552 IF( Z( 1 ).LE.TOL ) THEN
560 CALL DROT( 1, VF( M ), 1, VF( 1 ), 1, C, S )
561 CALL DROT( 1, VL( M ), 1, VL( 1 ), 1, C, S )
563 IF( ABS( Z1 ).LE.TOL ) THEN
570 * Restore Z, VF, and VL.
572 CALL DCOPY( K-1, ZW( 2 ), 1, Z( 2 ), 1 )
573 CALL DCOPY( N-1, VFW( 2 ), 1, VF( 2 ), 1 )
574 CALL DCOPY( N-1, VLW( 2 ), 1, VL( 2 ), 1 )