1 *> \brief <b> CGGSVD3 computes the singular value decomposition (SVD) for OTHER matrices</b>
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CGGSVD3 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cggsvd3.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cggsvd3.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cggsvd3.f">
21 * SUBROUTINE CGGSVD3( JOBU, JOBV, JOBQ, M, N, P, K, L, A, LDA, B,
22 * LDB, ALPHA, BETA, U, LDU, V, LDV, Q, LDQ, WORK,
23 * LWORK, RWORK, IWORK, INFO )
25 * .. Scalar Arguments ..
26 * CHARACTER JOBQ, JOBU, JOBV
27 * INTEGER INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N, P, LWORK
29 * .. Array Arguments ..
31 * REAL ALPHA( * ), BETA( * ), RWORK( * )
32 * COMPLEX A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
33 * $ U( LDU, * ), V( LDV, * ), WORK( * )
42 *> CGGSVD3 computes the generalized singular value decomposition (GSVD)
43 *> of an M-by-N complex matrix A and P-by-N complex matrix B:
45 *> U**H*A*Q = D1*( 0 R ), V**H*B*Q = D2*( 0 R )
47 *> where U, V and Q are unitary matrices.
48 *> Let K+L = the effective numerical rank of the
49 *> matrix (A**H,B**H)**H, then R is a (K+L)-by-(K+L) nonsingular upper
50 *> triangular matrix, D1 and D2 are M-by-(K+L) and P-by-(K+L) "diagonal"
51 *> matrices and of the following structures, respectively:
65 *> ( 0 R ) = K ( 0 R11 R12 )
70 *> C = diag( ALPHA(K+1), ... , ALPHA(K+L) ),
71 *> S = diag( BETA(K+1), ... , BETA(K+L) ),
74 *> R is stored in A(1:K+L,N-K-L+1:N) on exit.
88 *> ( 0 R ) = K ( 0 R11 R12 R13 )
89 *> M-K ( 0 0 R22 R23 )
90 *> K+L-M ( 0 0 0 R33 )
94 *> C = diag( ALPHA(K+1), ... , ALPHA(M) ),
95 *> S = diag( BETA(K+1), ... , BETA(M) ),
98 *> (R11 R12 R13 ) is stored in A(1:M, N-K-L+1:N), and R33 is stored
100 *> in B(M-K+1:L,N+M-K-L+1:N) on exit.
102 *> The routine computes C, S, R, and optionally the unitary
103 *> transformation matrices U, V and Q.
105 *> In particular, if B is an N-by-N nonsingular matrix, then the GSVD of
106 *> A and B implicitly gives the SVD of A*inv(B):
107 *> A*inv(B) = U*(D1*inv(D2))*V**H.
108 *> If ( A**H,B**H)**H has orthonormal columns, then the GSVD of A and B is also
109 *> equal to the CS decomposition of A and B. Furthermore, the GSVD can
110 *> be used to derive the solution of the eigenvalue problem:
111 *> A**H*A x = lambda* B**H*B x.
112 *> In some literature, the GSVD of A and B is presented in the form
113 *> U**H*A*X = ( 0 D1 ), V**H*B*X = ( 0 D2 )
114 *> where U and V are orthogonal and X is nonsingular, and D1 and D2 are
115 *> ``diagonal''. The former GSVD form can be converted to the latter
116 *> form by taking the nonsingular matrix X as
127 *> JOBU is CHARACTER*1
128 *> = 'U': Unitary matrix U is computed;
129 *> = 'N': U is not computed.
134 *> JOBV is CHARACTER*1
135 *> = 'V': Unitary matrix V is computed;
136 *> = 'N': V is not computed.
141 *> JOBQ is CHARACTER*1
142 *> = 'Q': Unitary matrix Q is computed;
143 *> = 'N': Q is not computed.
149 *> The number of rows of the matrix A. M >= 0.
155 *> The number of columns of the matrices A and B. N >= 0.
161 *> The number of rows of the matrix B. P >= 0.
173 *> On exit, K and L specify the dimension of the subblocks
174 *> described in Purpose.
175 *> K + L = effective numerical rank of (A**H,B**H)**H.
180 *> A is COMPLEX array, dimension (LDA,N)
181 *> On entry, the M-by-N matrix A.
182 *> On exit, A contains the triangular matrix R, or part of R.
183 *> See Purpose for details.
189 *> The leading dimension of the array A. LDA >= max(1,M).
194 *> B is COMPLEX array, dimension (LDB,N)
195 *> On entry, the P-by-N matrix B.
196 *> On exit, B contains part of the triangular matrix R if
197 *> M-K-L < 0. See Purpose for details.
203 *> The leading dimension of the array B. LDB >= max(1,P).
208 *> ALPHA is REAL array, dimension (N)
213 *> BETA is REAL array, dimension (N)
215 *> On exit, ALPHA and BETA contain the generalized singular
216 *> value pairs of A and B;
219 *> and if M-K-L >= 0,
220 *> ALPHA(K+1:K+L) = C,
221 *> BETA(K+1:K+L) = S,
223 *> ALPHA(K+1:M)=C, ALPHA(M+1:K+L)=0
224 *> BETA(K+1:M) =S, BETA(M+1:K+L) =1
226 *> ALPHA(K+L+1:N) = 0
232 *> U is COMPLEX array, dimension (LDU,M)
233 *> If JOBU = 'U', U contains the M-by-M unitary matrix U.
234 *> If JOBU = 'N', U is not referenced.
240 *> The leading dimension of the array U. LDU >= max(1,M) if
241 *> JOBU = 'U'; LDU >= 1 otherwise.
246 *> V is COMPLEX array, dimension (LDV,P)
247 *> If JOBV = 'V', V contains the P-by-P unitary matrix V.
248 *> If JOBV = 'N', V is not referenced.
254 *> The leading dimension of the array V. LDV >= max(1,P) if
255 *> JOBV = 'V'; LDV >= 1 otherwise.
260 *> Q is COMPLEX array, dimension (LDQ,N)
261 *> If JOBQ = 'Q', Q contains the N-by-N unitary matrix Q.
262 *> If JOBQ = 'N', Q is not referenced.
268 *> The leading dimension of the array Q. LDQ >= max(1,N) if
269 *> JOBQ = 'Q'; LDQ >= 1 otherwise.
274 *> WORK is COMPLEX array, dimension (MAX(1,LWORK))
275 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
281 *> The dimension of the array WORK.
283 *> If LWORK = -1, then a workspace query is assumed; the routine
284 *> only calculates the optimal size of the WORK array, returns
285 *> this value as the first entry of the WORK array, and no error
286 *> message related to LWORK is issued by XERBLA.
291 *> RWORK is REAL array, dimension (2*N)
296 *> IWORK is INTEGER array, dimension (N)
297 *> On exit, IWORK stores the sorting information. More
298 *> precisely, the following loop will sort ALPHA
299 *> for I = K+1, min(M,K+L)
300 *> swap ALPHA(I) and ALPHA(IWORK(I))
302 *> such that ALPHA(1) >= ALPHA(2) >= ... >= ALPHA(N).
308 *> = 0: successful exit.
309 *> < 0: if INFO = -i, the i-th argument had an illegal value.
310 *> > 0: if INFO = 1, the Jacobi-type procedure failed to
311 *> converge. For further details, see subroutine CTGSJA.
314 *> \par Internal Parameters:
315 * =========================
320 *> TOLA and TOLB are the thresholds to determine the effective
321 *> rank of (A**H,B**H)**H. Generally, they are set to
322 *> TOLA = MAX(M,N)*norm(A)*MACHEPS,
323 *> TOLB = MAX(P,N)*norm(B)*MACHEPS.
324 *> The size of TOLA and TOLB may affect the size of backward
325 *> errors of the decomposition.
331 *> \author Univ. of Tennessee
332 *> \author Univ. of California Berkeley
333 *> \author Univ. of Colorado Denver
338 *> \ingroup complexOTHERsing
340 *> \par Contributors:
343 *> Ming Gu and Huan Ren, Computer Science Division, University of
344 *> California at Berkeley, USA
347 *> \par Further Details:
348 * =====================
350 *> CGGSVD3 replaces the deprecated subroutine CGGSVD.
352 * =====================================================================
353 SUBROUTINE CGGSVD3( JOBU, JOBV, JOBQ, M, N, P, K, L, A, LDA, B,
354 $ LDB, ALPHA, BETA, U, LDU, V, LDV, Q, LDQ,
355 $ WORK, LWORK, RWORK, IWORK, INFO )
357 * -- LAPACK driver routine (version 3.6.0) --
358 * -- LAPACK is a software package provided by Univ. of Tennessee, --
359 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
362 * .. Scalar Arguments ..
363 CHARACTER JOBQ, JOBU, JOBV
364 INTEGER INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N, P,
367 * .. Array Arguments ..
369 REAL ALPHA( * ), BETA( * ), RWORK( * )
370 COMPLEX A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
371 $ U( LDU, * ), V( LDV, * ), WORK( * )
374 * =====================================================================
376 * .. Local Scalars ..
377 LOGICAL WANTQ, WANTU, WANTV, LQUERY
378 INTEGER I, IBND, ISUB, J, NCYCLE, LWKOPT
379 REAL ANORM, BNORM, SMAX, TEMP, TOLA, TOLB, ULP, UNFL
381 * .. External Functions ..
384 EXTERNAL LSAME, CLANGE, SLAMCH
386 * .. External Subroutines ..
387 EXTERNAL CGGSVP3, CTGSJA, SCOPY, XERBLA
389 * .. Intrinsic Functions ..
392 * .. Executable Statements ..
394 * Decode and test the input parameters
396 WANTU = LSAME( JOBU, 'U' )
397 WANTV = LSAME( JOBV, 'V' )
398 WANTQ = LSAME( JOBQ, 'Q' )
399 LQUERY = ( LWORK.EQ.-1 )
402 * Test the input arguments
405 IF( .NOT.( WANTU .OR. LSAME( JOBU, 'N' ) ) ) THEN
407 ELSE IF( .NOT.( WANTV .OR. LSAME( JOBV, 'N' ) ) ) THEN
409 ELSE IF( .NOT.( WANTQ .OR. LSAME( JOBQ, 'N' ) ) ) THEN
411 ELSE IF( M.LT.0 ) THEN
413 ELSE IF( N.LT.0 ) THEN
415 ELSE IF( P.LT.0 ) THEN
417 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
419 ELSE IF( LDB.LT.MAX( 1, P ) ) THEN
421 ELSE IF( LDU.LT.1 .OR. ( WANTU .AND. LDU.LT.M ) ) THEN
423 ELSE IF( LDV.LT.1 .OR. ( WANTV .AND. LDV.LT.P ) ) THEN
425 ELSE IF( LDQ.LT.1 .OR. ( WANTQ .AND. LDQ.LT.N ) ) THEN
427 ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN
434 CALL CGGSVP3( JOBU, JOBV, JOBQ, M, P, N, A, LDA, B, LDB, TOLA,
435 $ TOLB, K, L, U, LDU, V, LDV, Q, LDQ, IWORK, RWORK,
436 $ WORK, WORK, -1, INFO )
437 LWKOPT = N + INT( WORK( 1 ) )
438 LWKOPT = MAX( 2*N, LWKOPT )
439 LWKOPT = MAX( 1, LWKOPT )
440 WORK( 1 ) = CMPLX( LWKOPT )
444 CALL XERBLA( 'CGGSVD3', -INFO )
451 * Compute the Frobenius norm of matrices A and B
453 ANORM = CLANGE( '1', M, N, A, LDA, RWORK )
454 BNORM = CLANGE( '1', P, N, B, LDB, RWORK )
456 * Get machine precision and set up threshold for determining
457 * the effective numerical rank of the matrices A and B.
459 ULP = SLAMCH( 'Precision' )
460 UNFL = SLAMCH( 'Safe Minimum' )
461 TOLA = MAX( M, N )*MAX( ANORM, UNFL )*ULP
462 TOLB = MAX( P, N )*MAX( BNORM, UNFL )*ULP
464 CALL CGGSVP3( JOBU, JOBV, JOBQ, M, P, N, A, LDA, B, LDB, TOLA,
465 $ TOLB, K, L, U, LDU, V, LDV, Q, LDQ, IWORK, RWORK,
466 $ WORK, WORK( N+1 ), LWORK-N, INFO )
468 * Compute the GSVD of two upper "triangular" matrices
470 CALL CTGSJA( JOBU, JOBV, JOBQ, M, P, N, K, L, A, LDA, B, LDB,
471 $ TOLA, TOLB, ALPHA, BETA, U, LDU, V, LDV, Q, LDQ,
472 $ WORK, NCYCLE, INFO )
474 * Sort the singular values and store the pivot indices in IWORK
475 * Copy ALPHA to RWORK, then sort ALPHA in RWORK
477 CALL SCOPY( N, ALPHA, 1, RWORK, 1 )
481 * Scan for largest ALPHA(K+I)
485 DO 10 J = I + 1, IBND
487 IF( TEMP.GT.SMAX ) THEN
493 RWORK( K+ISUB ) = RWORK( K+I )
495 IWORK( K+I ) = K + ISUB
501 WORK( 1 ) = CMPLX( LWKOPT )