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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:45