1 *> \brief \b SLASD3 finds all square roots of the roots of the secular equation, as defined by the values in D and Z, and then updates the singular vectors by matrix multiplication. Used by sbdsdc.
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download SLASD3 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slasd3.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slasd3.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slasd3.f">
21 * SUBROUTINE SLASD3( NL, NR, SQRE, K, D, Q, LDQ, DSIGMA, U, LDU, U2,
22 * LDU2, VT, LDVT, VT2, LDVT2, IDXC, CTOT, Z,
25 * .. Scalar Arguments ..
26 * INTEGER INFO, K, LDQ, LDU, LDU2, LDVT, LDVT2, NL, NR,
29 * .. Array Arguments ..
30 * INTEGER CTOT( * ), IDXC( * )
31 * REAL D( * ), DSIGMA( * ), Q( LDQ, * ), U( LDU, * ),
32 * $ U2( LDU2, * ), VT( LDVT, * ), VT2( LDVT2, * ),
42 *> SLASD3 finds all the square roots of the roots of the secular
43 *> equation, as defined by the values in D and Z. It makes the
44 *> appropriate calls to SLASD4 and then updates the singular
45 *> vectors by matrix multiplication.
47 *> This code makes very mild assumptions about floating point
48 *> arithmetic. It will work on machines with a guard digit in
49 *> add/subtract, or on those binary machines without guard digits
50 *> which subtract like the Cray XMP, Cray YMP, Cray C 90, or Cray 2.
51 *> It could conceivably fail on hexadecimal or decimal machines
52 *> without guard digits, but we know of none.
54 *> SLASD3 is called from SLASD1.
63 *> The row dimension of the upper block. NL >= 1.
69 *> The row dimension of the lower block. NR >= 1.
75 *> = 0: the lower block is an NR-by-NR square matrix.
76 *> = 1: the lower block is an NR-by-(NR+1) rectangular matrix.
78 *> The bidiagonal matrix has N = NL + NR + 1 rows and
79 *> M = N + SQRE >= N columns.
85 *> The size of the secular equation, 1 =< K = < N.
90 *> D is REAL array, dimension(K)
91 *> On exit the square roots of the roots of the secular equation,
92 *> in ascending order.
98 *> dimension at least (LDQ,K).
104 *> The leading dimension of the array Q. LDQ >= K.
107 *> \param[in,out] DSIGMA
109 *> DSIGMA is REAL array, dimension(K)
110 *> The first K elements of this array contain the old roots
111 *> of the deflated updating problem. These are the poles
112 *> of the secular equation.
117 *> U is REAL array, dimension (LDU, N)
118 *> The last N - K columns of this matrix contain the deflated
119 *> left singular vectors.
125 *> The leading dimension of the array U. LDU >= N.
130 *> U2 is REAL array, dimension (LDU2, N)
131 *> The first K columns of this matrix contain the non-deflated
132 *> left singular vectors for the split problem.
138 *> The leading dimension of the array U2. LDU2 >= N.
143 *> VT is REAL array, dimension (LDVT, M)
144 *> The last M - K columns of VT**T contain the deflated
145 *> right singular vectors.
151 *> The leading dimension of the array VT. LDVT >= N.
154 *> \param[in,out] VT2
156 *> VT2 is REAL array, dimension (LDVT2, N)
157 *> The first K columns of VT2**T contain the non-deflated
158 *> right singular vectors for the split problem.
164 *> The leading dimension of the array VT2. LDVT2 >= N.
169 *> IDXC is INTEGER array, dimension (N)
170 *> The permutation used to arrange the columns of U (and rows of
171 *> VT) into three groups: the first group contains non-zero
172 *> entries only at and above (or before) NL +1; the second
173 *> contains non-zero entries only at and below (or after) NL+2;
174 *> and the third is dense. The first column of U and the row of
175 *> VT are treated separately, however.
177 *> The rows of the singular vectors found by SLASD4
178 *> must be likewise permuted before the matrix multiplies can
184 *> CTOT is INTEGER array, dimension (4)
185 *> A count of the total number of the various types of columns
186 *> in U (or rows in VT), as described in IDXC. The fourth column
187 *> type is any column which has been deflated.
192 *> Z is REAL array, dimension (K)
193 *> The first K elements of this array contain the components
194 *> of the deflation-adjusted updating row vector.
200 *> = 0: successful exit.
201 *> < 0: if INFO = -i, the i-th argument had an illegal value.
202 *> > 0: if INFO = 1, a singular value did not converge
208 *> \author Univ. of Tennessee
209 *> \author Univ. of California Berkeley
210 *> \author Univ. of Colorado Denver
213 *> \date November 2015
215 *> \ingroup OTHERauxiliary
217 *> \par Contributors:
220 *> Ming Gu and Huan Ren, Computer Science Division, University of
221 *> California at Berkeley, USA
223 * =====================================================================
224 SUBROUTINE SLASD3( NL, NR, SQRE, K, D, Q, LDQ, DSIGMA, U, LDU, U2,
225 $ LDU2, VT, LDVT, VT2, LDVT2, IDXC, CTOT, Z,
228 * -- LAPACK auxiliary routine (version 3.6.0) --
229 * -- LAPACK is a software package provided by Univ. of Tennessee, --
230 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
233 * .. Scalar Arguments ..
234 INTEGER INFO, K, LDQ, LDU, LDU2, LDVT, LDVT2, NL, NR,
237 * .. Array Arguments ..
238 INTEGER CTOT( * ), IDXC( * )
239 REAL D( * ), DSIGMA( * ), Q( LDQ, * ), U( LDU, * ),
240 $ U2( LDU2, * ), VT( LDVT, * ), VT2( LDVT2, * ),
244 * =====================================================================
247 REAL ONE, ZERO, NEGONE
248 PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0,
251 * .. Local Scalars ..
252 INTEGER CTEMP, I, J, JC, KTEMP, M, N, NLP1, NLP2, NRP1
255 * .. External Functions ..
257 EXTERNAL SLAMC3, SNRM2
259 * .. External Subroutines ..
260 EXTERNAL SCOPY, SGEMM, SLACPY, SLASCL, SLASD4, XERBLA
262 * .. Intrinsic Functions ..
263 INTRINSIC ABS, SIGN, SQRT
265 * .. Executable Statements ..
267 * Test the input parameters.
273 ELSE IF( NR.LT.1 ) THEN
275 ELSE IF( ( SQRE.NE.1 ) .AND. ( SQRE.NE.0 ) ) THEN
284 IF( ( K.LT.1 ) .OR. ( K.GT.N ) ) THEN
286 ELSE IF( LDQ.LT.K ) THEN
288 ELSE IF( LDU.LT.N ) THEN
290 ELSE IF( LDU2.LT.N ) THEN
292 ELSE IF( LDVT.LT.M ) THEN
294 ELSE IF( LDVT2.LT.M ) THEN
298 CALL XERBLA( 'SLASD3', -INFO )
302 * Quick return if possible
305 D( 1 ) = ABS( Z( 1 ) )
306 CALL SCOPY( M, VT2( 1, 1 ), LDVT2, VT( 1, 1 ), LDVT )
307 IF( Z( 1 ).GT.ZERO ) THEN
308 CALL SCOPY( N, U2( 1, 1 ), 1, U( 1, 1 ), 1 )
311 U( I, 1 ) = -U2( I, 1 )
317 * Modify values DSIGMA(i) to make sure all DSIGMA(i)-DSIGMA(j) can
318 * be computed with high relative accuracy (barring over/underflow).
319 * This is a problem on machines without a guard digit in
320 * add/subtract (Cray XMP, Cray YMP, Cray C 90 and Cray 2).
321 * The following code replaces DSIGMA(I) by 2*DSIGMA(I)-DSIGMA(I),
322 * which on any of these machines zeros out the bottommost
323 * bit of DSIGMA(I) if it is 1; this makes the subsequent
324 * subtractions DSIGMA(I)-DSIGMA(J) unproblematic when cancellation
325 * occurs. On binary machines with a guard digit (almost all
326 * machines) it does not change DSIGMA(I) at all. On hexadecimal
327 * and decimal machines with a guard digit, it slightly
328 * changes the bottommost bits of DSIGMA(I). It does not account
329 * for hexadecimal or decimal machines without guard digits
330 * (we know of none). We use a subroutine call to compute
331 * 2*DSIGMA(I) to prevent optimizing compilers from eliminating
335 DSIGMA( I ) = SLAMC3( DSIGMA( I ), DSIGMA( I ) ) - DSIGMA( I )
340 CALL SCOPY( K, Z, 1, Q, 1 )
344 RHO = SNRM2( K, Z, 1 )
345 CALL SLASCL( 'G', 0, 0, RHO, ONE, K, 1, Z, K, INFO )
348 * Find the new singular values.
351 CALL SLASD4( K, J, DSIGMA, Z, U( 1, J ), RHO, D( J ),
354 * If the zero finder fails, report the convergence failure.
364 Z( I ) = U( I, K )*VT( I, K )
366 Z( I ) = Z( I )*( U( I, J )*VT( I, J ) /
367 $ ( DSIGMA( I )-DSIGMA( J ) ) /
368 $ ( DSIGMA( I )+DSIGMA( J ) ) )
371 Z( I ) = Z( I )*( U( I, J )*VT( I, J ) /
372 $ ( DSIGMA( I )-DSIGMA( J+1 ) ) /
373 $ ( DSIGMA( I )+DSIGMA( J+1 ) ) )
375 Z( I ) = SIGN( SQRT( ABS( Z( I ) ) ), Q( I, 1 ) )
378 * Compute left singular vectors of the modified diagonal matrix,
379 * and store related information for the right singular vectors.
382 VT( 1, I ) = Z( 1 ) / U( 1, I ) / VT( 1, I )
385 VT( J, I ) = Z( J ) / U( J, I ) / VT( J, I )
386 U( J, I ) = DSIGMA( J )*VT( J, I )
388 TEMP = SNRM2( K, U( 1, I ), 1 )
389 Q( 1, I ) = U( 1, I ) / TEMP
392 Q( J, I ) = U( JC, I ) / TEMP
396 * Update the left singular vector matrix.
399 CALL SGEMM( 'N', 'N', N, K, K, ONE, U2, LDU2, Q, LDQ, ZERO, U,
403 IF( CTOT( 1 ).GT.0 ) THEN
404 CALL SGEMM( 'N', 'N', NL, K, CTOT( 1 ), ONE, U2( 1, 2 ), LDU2,
405 $ Q( 2, 1 ), LDQ, ZERO, U( 1, 1 ), LDU )
406 IF( CTOT( 3 ).GT.0 ) THEN
407 KTEMP = 2 + CTOT( 1 ) + CTOT( 2 )
408 CALL SGEMM( 'N', 'N', NL, K, CTOT( 3 ), ONE, U2( 1, KTEMP ),
409 $ LDU2, Q( KTEMP, 1 ), LDQ, ONE, U( 1, 1 ), LDU )
411 ELSE IF( CTOT( 3 ).GT.0 ) THEN
412 KTEMP = 2 + CTOT( 1 ) + CTOT( 2 )
413 CALL SGEMM( 'N', 'N', NL, K, CTOT( 3 ), ONE, U2( 1, KTEMP ),
414 $ LDU2, Q( KTEMP, 1 ), LDQ, ZERO, U( 1, 1 ), LDU )
416 CALL SLACPY( 'F', NL, K, U2, LDU2, U, LDU )
418 CALL SCOPY( K, Q( 1, 1 ), LDQ, U( NLP1, 1 ), LDU )
419 KTEMP = 2 + CTOT( 1 )
420 CTEMP = CTOT( 2 ) + CTOT( 3 )
421 CALL SGEMM( 'N', 'N', NR, K, CTEMP, ONE, U2( NLP2, KTEMP ), LDU2,
422 $ Q( KTEMP, 1 ), LDQ, ZERO, U( NLP2, 1 ), LDU )
424 * Generate the right singular vectors.
428 TEMP = SNRM2( K, VT( 1, I ), 1 )
429 Q( I, 1 ) = VT( 1, I ) / TEMP
432 Q( I, J ) = VT( JC, I ) / TEMP
436 * Update the right singular vector matrix.
439 CALL SGEMM( 'N', 'N', K, M, K, ONE, Q, LDQ, VT2, LDVT2, ZERO,
443 KTEMP = 1 + CTOT( 1 )
444 CALL SGEMM( 'N', 'N', K, NLP1, KTEMP, ONE, Q( 1, 1 ), LDQ,
445 $ VT2( 1, 1 ), LDVT2, ZERO, VT( 1, 1 ), LDVT )
446 KTEMP = 2 + CTOT( 1 ) + CTOT( 2 )
448 $ CALL SGEMM( 'N', 'N', K, NLP1, CTOT( 3 ), ONE, Q( 1, KTEMP ),
449 $ LDQ, VT2( KTEMP, 1 ), LDVT2, ONE, VT( 1, 1 ),
452 KTEMP = CTOT( 1 ) + 1
454 IF( KTEMP.GT.1 ) THEN
456 Q( I, KTEMP ) = Q( I, 1 )
459 VT2( KTEMP, I ) = VT2( 1, I )
462 CTEMP = 1 + CTOT( 2 ) + CTOT( 3 )
463 CALL SGEMM( 'N', 'N', K, NRP1, CTEMP, ONE, Q( 1, KTEMP ), LDQ,
464 $ VT2( KTEMP, NLP2 ), LDVT2, ZERO, VT( 1, NLP2 ), LDVT )