1 *> \brief \b DLASDQ computes the SVD of a real bidiagonal matrix with diagonal d and off-diagonal e. Used by sbdsdc.
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DLASDQ + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlasdq.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlasdq.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlasdq.f">
21 * SUBROUTINE DLASDQ( UPLO, SQRE, N, NCVT, NRU, NCC, D, E, VT, LDVT,
22 * U, LDU, C, LDC, WORK, INFO )
24 * .. Scalar Arguments ..
26 * INTEGER INFO, LDC, LDU, LDVT, N, NCC, NCVT, NRU, SQRE
28 * .. Array Arguments ..
29 * DOUBLE PRECISION C( LDC, * ), D( * ), E( * ), U( LDU, * ),
30 * $ VT( LDVT, * ), WORK( * )
39 *> DLASDQ computes the singular value decomposition (SVD) of a real
40 *> (upper or lower) bidiagonal matrix with diagonal D and offdiagonal
41 *> E, accumulating the transformations if desired. Letting B denote
42 *> the input bidiagonal matrix, the algorithm computes orthogonal
43 *> matrices Q and P such that B = Q * S * P**T (P**T denotes the transpose
44 *> of P). The singular values S are overwritten on D.
46 *> The input matrix U is changed to U * Q if desired.
47 *> The input matrix VT is changed to P**T * VT if desired.
48 *> The input matrix C is changed to Q**T * C if desired.
50 *> See "Computing Small Singular Values of Bidiagonal Matrices With
51 *> Guaranteed High Relative Accuracy," by J. Demmel and W. Kahan,
52 *> LAPACK Working Note #3, for a detailed description of the algorithm.
60 *> UPLO is CHARACTER*1
61 *> On entry, UPLO specifies whether the input bidiagonal matrix
62 *> is upper or lower bidiagonal, and whether it is square are
64 *> UPLO = 'U' or 'u' B is upper bidiagonal.
65 *> UPLO = 'L' or 'l' B is lower bidiagonal.
71 *> = 0: then the input matrix is N-by-N.
72 *> = 1: then the input matrix is N-by-(N+1) if UPLU = 'U' and
73 *> (N+1)-by-N if UPLU = 'L'.
75 *> The bidiagonal matrix has
76 *> N = NL + NR + 1 rows and
77 *> M = N + SQRE >= N columns.
83 *> On entry, N specifies the number of rows and columns
84 *> in the matrix. N must be at least 0.
90 *> On entry, NCVT specifies the number of columns of
91 *> the matrix VT. NCVT must be at least 0.
97 *> On entry, NRU specifies the number of rows of
98 *> the matrix U. NRU must be at least 0.
104 *> On entry, NCC specifies the number of columns of
105 *> the matrix C. NCC must be at least 0.
110 *> D is DOUBLE PRECISION array, dimension (N)
111 *> On entry, D contains the diagonal entries of the
112 *> bidiagonal matrix whose SVD is desired. On normal exit,
113 *> D contains the singular values in ascending order.
118 *> E is DOUBLE PRECISION array.
119 *> dimension is (N-1) if SQRE = 0 and N if SQRE = 1.
120 *> On entry, the entries of E contain the offdiagonal entries
121 *> of the bidiagonal matrix whose SVD is desired. On normal
122 *> exit, E will contain 0. If the algorithm does not converge,
123 *> D and E will contain the diagonal and superdiagonal entries
124 *> of a bidiagonal matrix orthogonally equivalent to the one
130 *> VT is DOUBLE PRECISION array, dimension (LDVT, NCVT)
131 *> On entry, contains a matrix which on exit has been
132 *> premultiplied by P**T, dimension N-by-NCVT if SQRE = 0
133 *> and (N+1)-by-NCVT if SQRE = 1 (not referenced if NCVT=0).
139 *> On entry, LDVT specifies the leading dimension of VT as
140 *> declared in the calling (sub) program. LDVT must be at
141 *> least 1. If NCVT is nonzero LDVT must also be at least N.
146 *> U is DOUBLE PRECISION array, dimension (LDU, N)
147 *> On entry, contains a matrix which on exit has been
148 *> postmultiplied by Q, dimension NRU-by-N if SQRE = 0
149 *> and NRU-by-(N+1) if SQRE = 1 (not referenced if NRU=0).
155 *> On entry, LDU specifies the leading dimension of U as
156 *> declared in the calling (sub) program. LDU must be at
157 *> least max( 1, NRU ) .
162 *> C is DOUBLE PRECISION array, dimension (LDC, NCC)
163 *> On entry, contains an N-by-NCC matrix which on exit
164 *> has been premultiplied by Q**T dimension N-by-NCC if SQRE = 0
165 *> and (N+1)-by-NCC if SQRE = 1 (not referenced if NCC=0).
171 *> On entry, LDC specifies the leading dimension of C as
172 *> declared in the calling (sub) program. LDC must be at
173 *> least 1. If NCC is nonzero, LDC must also be at least N.
178 *> WORK is DOUBLE PRECISION array, dimension (4*N)
179 *> Workspace. Only referenced if one of NCVT, NRU, or NCC is
180 *> nonzero, and if N is at least 2.
186 *> On exit, a value of 0 indicates a successful exit.
187 *> If INFO < 0, argument number -INFO is illegal.
188 *> If INFO > 0, the algorithm did not converge, and INFO
189 *> specifies how many superdiagonals did not converge.
195 *> \author Univ. of Tennessee
196 *> \author Univ. of California Berkeley
197 *> \author Univ. of Colorado Denver
202 *> \ingroup auxOTHERauxiliary
204 *> \par Contributors:
207 *> Ming Gu and Huan Ren, Computer Science Division, University of
208 *> California at Berkeley, USA
210 * =====================================================================
211 SUBROUTINE DLASDQ( UPLO, SQRE, N, NCVT, NRU, NCC, D, E, VT, LDVT,
212 $ U, LDU, C, LDC, WORK, INFO )
214 * -- LAPACK auxiliary routine (version 3.6.1) --
215 * -- LAPACK is a software package provided by Univ. of Tennessee, --
216 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
219 * .. Scalar Arguments ..
221 INTEGER INFO, LDC, LDU, LDVT, N, NCC, NCVT, NRU, SQRE
223 * .. Array Arguments ..
224 DOUBLE PRECISION C( LDC, * ), D( * ), E( * ), U( LDU, * ),
225 $ VT( LDVT, * ), WORK( * )
228 * =====================================================================
231 DOUBLE PRECISION ZERO
232 PARAMETER ( ZERO = 0.0D+0 )
234 * .. Local Scalars ..
236 INTEGER I, ISUB, IUPLO, J, NP1, SQRE1
237 DOUBLE PRECISION CS, R, SMIN, SN
239 * .. External Subroutines ..
240 EXTERNAL DBDSQR, DLARTG, DLASR, DSWAP, XERBLA
242 * .. External Functions ..
246 * .. Intrinsic Functions ..
249 * .. Executable Statements ..
251 * Test the input parameters.
255 IF( LSAME( UPLO, 'U' ) )
257 IF( LSAME( UPLO, 'L' ) )
259 IF( IUPLO.EQ.0 ) THEN
261 ELSE IF( ( SQRE.LT.0 ) .OR. ( SQRE.GT.1 ) ) THEN
263 ELSE IF( N.LT.0 ) THEN
265 ELSE IF( NCVT.LT.0 ) THEN
267 ELSE IF( NRU.LT.0 ) THEN
269 ELSE IF( NCC.LT.0 ) THEN
271 ELSE IF( ( NCVT.EQ.0 .AND. LDVT.LT.1 ) .OR.
272 $ ( NCVT.GT.0 .AND. LDVT.LT.MAX( 1, N ) ) ) THEN
274 ELSE IF( LDU.LT.MAX( 1, NRU ) ) THEN
276 ELSE IF( ( NCC.EQ.0 .AND. LDC.LT.1 ) .OR.
277 $ ( NCC.GT.0 .AND. LDC.LT.MAX( 1, N ) ) ) THEN
281 CALL XERBLA( 'DLASDQ', -INFO )
287 * ROTATE is true if any singular vectors desired, false otherwise
289 ROTATE = ( NCVT.GT.0 ) .OR. ( NRU.GT.0 ) .OR. ( NCC.GT.0 )
293 * If matrix non-square upper bidiagonal, rotate to be lower
294 * bidiagonal. The rotations are on the right.
296 IF( ( IUPLO.EQ.1 ) .AND. ( SQRE1.EQ.1 ) ) THEN
298 CALL DLARTG( D( I ), E( I ), CS, SN, R )
301 D( I+1 ) = CS*D( I+1 )
307 CALL DLARTG( D( N ), E( N ), CS, SN, R )
317 * Update singular vectors if desired.
320 $ CALL DLASR( 'L', 'V', 'F', NP1, NCVT, WORK( 1 ),
321 $ WORK( NP1 ), VT, LDVT )
324 * If matrix lower bidiagonal, rotate to be upper bidiagonal
325 * by applying Givens rotations on the left.
327 IF( IUPLO.EQ.2 ) THEN
329 CALL DLARTG( D( I ), E( I ), CS, SN, R )
332 D( I+1 ) = CS*D( I+1 )
339 * If matrix (N+1)-by-N lower bidiagonal, one additional
340 * rotation is needed.
342 IF( SQRE1.EQ.1 ) THEN
343 CALL DLARTG( D( N ), E( N ), CS, SN, R )
351 * Update singular vectors if desired.
354 IF( SQRE1.EQ.0 ) THEN
355 CALL DLASR( 'R', 'V', 'F', NRU, N, WORK( 1 ),
356 $ WORK( NP1 ), U, LDU )
358 CALL DLASR( 'R', 'V', 'F', NRU, NP1, WORK( 1 ),
359 $ WORK( NP1 ), U, LDU )
363 IF( SQRE1.EQ.0 ) THEN
364 CALL DLASR( 'L', 'V', 'F', N, NCC, WORK( 1 ),
365 $ WORK( NP1 ), C, LDC )
367 CALL DLASR( 'L', 'V', 'F', NP1, NCC, WORK( 1 ),
368 $ WORK( NP1 ), C, LDC )
373 * Call DBDSQR to compute the SVD of the reduced real
374 * N-by-N upper bidiagonal matrix.
376 CALL DBDSQR( 'U', N, NCVT, NRU, NCC, D, E, VT, LDVT, U, LDU, C,
379 * Sort the singular values into ascending order (insertion sort on
380 * singular values, but only one transposition per singular vector)
384 * Scan for smallest D(I).
389 IF( D( J ).LT.SMIN ) THEN
396 * Swap singular values and vectors.
401 $ CALL DSWAP( NCVT, VT( ISUB, 1 ), LDVT, VT( I, 1 ), LDVT )
403 $ CALL DSWAP( NRU, U( 1, ISUB ), 1, U( 1, I ), 1 )
405 $ CALL DSWAP( NCC, C( ISUB, 1 ), LDC, C( I, 1 ), LDC )