00001 /* cggsvd.f -- translated by f2c (version 20061008). 00002 You must link the resulting object file with libf2c: 00003 on Microsoft Windows system, link with libf2c.lib; 00004 on Linux or Unix systems, link with .../path/to/libf2c.a -lm 00005 or, if you install libf2c.a in a standard place, with -lf2c -lm 00006 -- in that order, at the end of the command line, as in 00007 cc *.o -lf2c -lm 00008 Source for libf2c is in /netlib/f2c/libf2c.zip, e.g., 00009 00010 http://www.netlib.org/f2c/libf2c.zip 00011 */ 00012 00013 #include "f2c.h" 00014 #include "blaswrap.h" 00015 00016 /* Table of constant values */ 00017 00018 static integer c__1 = 1; 00019 00020 /* Subroutine */ int cggsvd_(char *jobu, char *jobv, char *jobq, integer *m, 00021 integer *n, integer *p, integer *k, integer *l, complex *a, integer * 00022 lda, complex *b, integer *ldb, real *alpha, real *beta, complex *u, 00023 integer *ldu, complex *v, integer *ldv, complex *q, integer *ldq, 00024 complex *work, real *rwork, integer *iwork, integer *info) 00025 { 00026 /* System generated locals */ 00027 integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, u_dim1, 00028 u_offset, v_dim1, v_offset, i__1, i__2; 00029 00030 /* Local variables */ 00031 integer i__, j; 00032 real ulp; 00033 integer ibnd; 00034 real tola; 00035 integer isub; 00036 real tolb, unfl, temp, smax; 00037 extern logical lsame_(char *, char *); 00038 real anorm, bnorm; 00039 logical wantq; 00040 extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, 00041 integer *); 00042 logical wantu, wantv; 00043 extern doublereal clange_(char *, integer *, integer *, complex *, 00044 integer *, real *), slamch_(char *); 00045 extern /* Subroutine */ int ctgsja_(char *, char *, char *, integer *, 00046 integer *, integer *, integer *, integer *, complex *, integer *, 00047 complex *, integer *, real *, real *, real *, real *, complex *, 00048 integer *, complex *, integer *, complex *, integer *, complex *, 00049 integer *, integer *); 00050 integer ncycle; 00051 extern /* Subroutine */ int xerbla_(char *, integer *), cggsvp_( 00052 char *, char *, char *, integer *, integer *, integer *, complex * 00053 , integer *, complex *, integer *, real *, real *, integer *, 00054 integer *, complex *, integer *, complex *, integer *, complex *, 00055 integer *, integer *, real *, complex *, complex *, integer *); 00056 00057 00058 /* -- LAPACK driver routine (version 3.2) -- */ 00059 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ 00060 /* November 2006 */ 00061 00062 /* .. Scalar Arguments .. */ 00063 /* .. */ 00064 /* .. Array Arguments .. */ 00065 /* .. */ 00066 00067 /* Purpose */ 00068 /* ======= */ 00069 00070 /* CGGSVD computes the generalized singular value decomposition (GSVD) */ 00071 /* of an M-by-N complex matrix A and P-by-N complex matrix B: */ 00072 00073 /* U'*A*Q = D1*( 0 R ), V'*B*Q = D2*( 0 R ) */ 00074 00075 /* where U, V and Q are unitary matrices, and Z' means the conjugate */ 00076 /* transpose of Z. Let K+L = the effective numerical rank of the */ 00077 /* matrix (A',B')', then R is a (K+L)-by-(K+L) nonsingular upper */ 00078 /* triangular matrix, D1 and D2 are M-by-(K+L) and P-by-(K+L) "diagonal" */ 00079 /* matrices and of the following structures, respectively: */ 00080 00081 /* If M-K-L >= 0, */ 00082 00083 /* K L */ 00084 /* D1 = K ( I 0 ) */ 00085 /* L ( 0 C ) */ 00086 /* M-K-L ( 0 0 ) */ 00087 00088 /* K L */ 00089 /* D2 = L ( 0 S ) */ 00090 /* P-L ( 0 0 ) */ 00091 00092 /* N-K-L K L */ 00093 /* ( 0 R ) = K ( 0 R11 R12 ) */ 00094 /* L ( 0 0 R22 ) */ 00095 /* where */ 00096 00097 /* C = diag( ALPHA(K+1), ... , ALPHA(K+L) ), */ 00098 /* S = diag( BETA(K+1), ... , BETA(K+L) ), */ 00099 /* C**2 + S**2 = I. */ 00100 00101 /* R is stored in A(1:K+L,N-K-L+1:N) on exit. */ 00102 00103 /* If M-K-L < 0, */ 00104 00105 /* K M-K K+L-M */ 00106 /* D1 = K ( I 0 0 ) */ 00107 /* M-K ( 0 C 0 ) */ 00108 00109 /* K M-K K+L-M */ 00110 /* D2 = M-K ( 0 S 0 ) */ 00111 /* K+L-M ( 0 0 I ) */ 00112 /* P-L ( 0 0 0 ) */ 00113 00114 /* N-K-L K M-K K+L-M */ 00115 /* ( 0 R ) = K ( 0 R11 R12 R13 ) */ 00116 /* M-K ( 0 0 R22 R23 ) */ 00117 /* K+L-M ( 0 0 0 R33 ) */ 00118 00119 /* where */ 00120 00121 /* C = diag( ALPHA(K+1), ... , ALPHA(M) ), */ 00122 /* S = diag( BETA(K+1), ... , BETA(M) ), */ 00123 /* C**2 + S**2 = I. */ 00124 00125 /* (R11 R12 R13 ) is stored in A(1:M, N-K-L+1:N), and R33 is stored */ 00126 /* ( 0 R22 R23 ) */ 00127 /* in B(M-K+1:L,N+M-K-L+1:N) on exit. */ 00128 00129 /* The routine computes C, S, R, and optionally the unitary */ 00130 /* transformation matrices U, V and Q. */ 00131 00132 /* In particular, if B is an N-by-N nonsingular matrix, then the GSVD of */ 00133 /* A and B implicitly gives the SVD of A*inv(B): */ 00134 /* A*inv(B) = U*(D1*inv(D2))*V'. */ 00135 /* If ( A',B')' has orthnormal columns, then the GSVD of A and B is also */ 00136 /* equal to the CS decomposition of A and B. Furthermore, the GSVD can */ 00137 /* be used to derive the solution of the eigenvalue problem: */ 00138 /* A'*A x = lambda* B'*B x. */ 00139 /* In some literature, the GSVD of A and B is presented in the form */ 00140 /* U'*A*X = ( 0 D1 ), V'*B*X = ( 0 D2 ) */ 00141 /* where U and V are orthogonal and X is nonsingular, and D1 and D2 are */ 00142 /* ``diagonal''. The former GSVD form can be converted to the latter */ 00143 /* form by taking the nonsingular matrix X as */ 00144 00145 /* X = Q*( I 0 ) */ 00146 /* ( 0 inv(R) ) */ 00147 00148 /* Arguments */ 00149 /* ========= */ 00150 00151 /* JOBU (input) CHARACTER*1 */ 00152 /* = 'U': Unitary matrix U is computed; */ 00153 /* = 'N': U is not computed. */ 00154 00155 /* JOBV (input) CHARACTER*1 */ 00156 /* = 'V': Unitary matrix V is computed; */ 00157 /* = 'N': V is not computed. */ 00158 00159 /* JOBQ (input) CHARACTER*1 */ 00160 /* = 'Q': Unitary matrix Q is computed; */ 00161 /* = 'N': Q is not computed. */ 00162 00163 /* M (input) INTEGER */ 00164 /* The number of rows of the matrix A. M >= 0. */ 00165 00166 /* N (input) INTEGER */ 00167 /* The number of columns of the matrices A and B. N >= 0. */ 00168 00169 /* P (input) INTEGER */ 00170 /* The number of rows of the matrix B. P >= 0. */ 00171 00172 /* K (output) INTEGER */ 00173 /* L (output) INTEGER */ 00174 /* On exit, K and L specify the dimension of the subblocks */ 00175 /* described in Purpose. */ 00176 /* K + L = effective numerical rank of (A',B')'. */ 00177 00178 /* A (input/output) COMPLEX array, dimension (LDA,N) */ 00179 /* On entry, the M-by-N matrix A. */ 00180 /* On exit, A contains the triangular matrix R, or part of R. */ 00181 /* See Purpose for details. */ 00182 00183 /* LDA (input) INTEGER */ 00184 /* The leading dimension of the array A. LDA >= max(1,M). */ 00185 00186 /* B (input/output) COMPLEX array, dimension (LDB,N) */ 00187 /* On entry, the P-by-N matrix B. */ 00188 /* On exit, B contains part of the triangular matrix R if */ 00189 /* M-K-L < 0. See Purpose for details. */ 00190 00191 /* LDB (input) INTEGER */ 00192 /* The leading dimension of the array B. LDB >= max(1,P). */ 00193 00194 /* ALPHA (output) REAL array, dimension (N) */ 00195 /* BETA (output) REAL array, dimension (N) */ 00196 /* On exit, ALPHA and BETA contain the generalized singular */ 00197 /* value pairs of A and B; */ 00198 /* ALPHA(1:K) = 1, */ 00199 /* BETA(1:K) = 0, */ 00200 /* and if M-K-L >= 0, */ 00201 /* ALPHA(K+1:K+L) = C, */ 00202 /* BETA(K+1:K+L) = S, */ 00203 /* or if M-K-L < 0, */ 00204 /* ALPHA(K+1:M)= C, ALPHA(M+1:K+L)= 0 */ 00205 /* BETA(K+1:M) = S, BETA(M+1:K+L) = 1 */ 00206 /* and */ 00207 /* ALPHA(K+L+1:N) = 0 */ 00208 /* BETA(K+L+1:N) = 0 */ 00209 00210 /* U (output) COMPLEX array, dimension (LDU,M) */ 00211 /* If JOBU = 'U', U contains the M-by-M unitary matrix U. */ 00212 /* If JOBU = 'N', U is not referenced. */ 00213 00214 /* LDU (input) INTEGER */ 00215 /* The leading dimension of the array U. LDU >= max(1,M) if */ 00216 /* JOBU = 'U'; LDU >= 1 otherwise. */ 00217 00218 /* V (output) COMPLEX array, dimension (LDV,P) */ 00219 /* If JOBV = 'V', V contains the P-by-P unitary matrix V. */ 00220 /* If JOBV = 'N', V is not referenced. */ 00221 00222 /* LDV (input) INTEGER */ 00223 /* The leading dimension of the array V. LDV >= max(1,P) if */ 00224 /* JOBV = 'V'; LDV >= 1 otherwise. */ 00225 00226 /* Q (output) COMPLEX array, dimension (LDQ,N) */ 00227 /* If JOBQ = 'Q', Q contains the N-by-N unitary matrix Q. */ 00228 /* If JOBQ = 'N', Q is not referenced. */ 00229 00230 /* LDQ (input) INTEGER */ 00231 /* The leading dimension of the array Q. LDQ >= max(1,N) if */ 00232 /* JOBQ = 'Q'; LDQ >= 1 otherwise. */ 00233 00234 /* WORK (workspace) COMPLEX array, dimension (max(3*N,M,P)+N) */ 00235 00236 /* RWORK (workspace) REAL array, dimension (2*N) */ 00237 00238 /* IWORK (workspace/output) INTEGER array, dimension (N) */ 00239 /* On exit, IWORK stores the sorting information. More */ 00240 /* precisely, the following loop will sort ALPHA */ 00241 /* for I = K+1, min(M,K+L) */ 00242 /* swap ALPHA(I) and ALPHA(IWORK(I)) */ 00243 /* endfor */ 00244 /* such that ALPHA(1) >= ALPHA(2) >= ... >= ALPHA(N). */ 00245 00246 /* INFO (output) INTEGER */ 00247 /* = 0: successful exit. */ 00248 /* < 0: if INFO = -i, the i-th argument had an illegal value. */ 00249 /* > 0: if INFO = 1, the Jacobi-type procedure failed to */ 00250 /* converge. For further details, see subroutine CTGSJA. */ 00251 00252 /* Internal Parameters */ 00253 /* =================== */ 00254 00255 /* TOLA REAL */ 00256 /* TOLB REAL */ 00257 /* TOLA and TOLB are the thresholds to determine the effective */ 00258 /* rank of (A',B')'. Generally, they are set to */ 00259 /* TOLA = MAX(M,N)*norm(A)*MACHEPS, */ 00260 /* TOLB = MAX(P,N)*norm(B)*MACHEPS. */ 00261 /* The size of TOLA and TOLB may affect the size of backward */ 00262 /* errors of the decomposition. */ 00263 00264 /* Further Details */ 00265 /* =============== */ 00266 00267 /* 2-96 Based on modifications by */ 00268 /* Ming Gu and Huan Ren, Computer Science Division, University of */ 00269 /* California at Berkeley, USA */ 00270 00271 /* ===================================================================== */ 00272 00273 /* .. Local Scalars .. */ 00274 /* .. */ 00275 /* .. External Functions .. */ 00276 /* .. */ 00277 /* .. External Subroutines .. */ 00278 /* .. */ 00279 /* .. Intrinsic Functions .. */ 00280 /* .. */ 00281 /* .. Executable Statements .. */ 00282 00283 /* Decode and test the input parameters */ 00284 00285 /* Parameter adjustments */ 00286 a_dim1 = *lda; 00287 a_offset = 1 + a_dim1; 00288 a -= a_offset; 00289 b_dim1 = *ldb; 00290 b_offset = 1 + b_dim1; 00291 b -= b_offset; 00292 --alpha; 00293 --beta; 00294 u_dim1 = *ldu; 00295 u_offset = 1 + u_dim1; 00296 u -= u_offset; 00297 v_dim1 = *ldv; 00298 v_offset = 1 + v_dim1; 00299 v -= v_offset; 00300 q_dim1 = *ldq; 00301 q_offset = 1 + q_dim1; 00302 q -= q_offset; 00303 --work; 00304 --rwork; 00305 --iwork; 00306 00307 /* Function Body */ 00308 wantu = lsame_(jobu, "U"); 00309 wantv = lsame_(jobv, "V"); 00310 wantq = lsame_(jobq, "Q"); 00311 00312 *info = 0; 00313 if (! (wantu || lsame_(jobu, "N"))) { 00314 *info = -1; 00315 } else if (! (wantv || lsame_(jobv, "N"))) { 00316 *info = -2; 00317 } else if (! (wantq || lsame_(jobq, "N"))) { 00318 *info = -3; 00319 } else if (*m < 0) { 00320 *info = -4; 00321 } else if (*n < 0) { 00322 *info = -5; 00323 } else if (*p < 0) { 00324 *info = -6; 00325 } else if (*lda < max(1,*m)) { 00326 *info = -10; 00327 } else if (*ldb < max(1,*p)) { 00328 *info = -12; 00329 } else if (*ldu < 1 || wantu && *ldu < *m) { 00330 *info = -16; 00331 } else if (*ldv < 1 || wantv && *ldv < *p) { 00332 *info = -18; 00333 } else if (*ldq < 1 || wantq && *ldq < *n) { 00334 *info = -20; 00335 } 00336 if (*info != 0) { 00337 i__1 = -(*info); 00338 xerbla_("CGGSVD", &i__1); 00339 return 0; 00340 } 00341 00342 /* Compute the Frobenius norm of matrices A and B */ 00343 00344 anorm = clange_("1", m, n, &a[a_offset], lda, &rwork[1]); 00345 bnorm = clange_("1", p, n, &b[b_offset], ldb, &rwork[1]); 00346 00347 /* Get machine precision and set up threshold for determining */ 00348 /* the effective numerical rank of the matrices A and B. */ 00349 00350 ulp = slamch_("Precision"); 00351 unfl = slamch_("Safe Minimum"); 00352 tola = max(*m,*n) * dmax(anorm,unfl) * ulp; 00353 tolb = max(*p,*n) * dmax(bnorm,unfl) * ulp; 00354 00355 cggsvp_(jobu, jobv, jobq, m, p, n, &a[a_offset], lda, &b[b_offset], ldb, & 00356 tola, &tolb, k, l, &u[u_offset], ldu, &v[v_offset], ldv, &q[ 00357 q_offset], ldq, &iwork[1], &rwork[1], &work[1], &work[*n + 1], 00358 info); 00359 00360 /* Compute the GSVD of two upper "triangular" matrices */ 00361 00362 ctgsja_(jobu, jobv, jobq, m, p, n, k, l, &a[a_offset], lda, &b[b_offset], 00363 ldb, &tola, &tolb, &alpha[1], &beta[1], &u[u_offset], ldu, &v[ 00364 v_offset], ldv, &q[q_offset], ldq, &work[1], &ncycle, info); 00365 00366 /* Sort the singular values and store the pivot indices in IWORK */ 00367 /* Copy ALPHA to RWORK, then sort ALPHA in RWORK */ 00368 00369 scopy_(n, &alpha[1], &c__1, &rwork[1], &c__1); 00370 /* Computing MIN */ 00371 i__1 = *l, i__2 = *m - *k; 00372 ibnd = min(i__1,i__2); 00373 i__1 = ibnd; 00374 for (i__ = 1; i__ <= i__1; ++i__) { 00375 00376 /* Scan for largest ALPHA(K+I) */ 00377 00378 isub = i__; 00379 smax = rwork[*k + i__]; 00380 i__2 = ibnd; 00381 for (j = i__ + 1; j <= i__2; ++j) { 00382 temp = rwork[*k + j]; 00383 if (temp > smax) { 00384 isub = j; 00385 smax = temp; 00386 } 00387 /* L10: */ 00388 } 00389 if (isub != i__) { 00390 rwork[*k + isub] = rwork[*k + i__]; 00391 rwork[*k + i__] = smax; 00392 iwork[*k + i__] = *k + isub; 00393 } else { 00394 iwork[*k + i__] = *k + i__; 00395 } 00396 /* L20: */ 00397 } 00398 00399 return 0; 00400 00401 /* End of CGGSVD */ 00402 00403 } /* cggsvd_ */