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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:36