dggsvp.c
Go to the documentation of this file.
00001 /* dggsvp.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 doublereal c_b12 = 0.;
00019 static doublereal c_b22 = 1.;
00020 
00021 /* Subroutine */ int dggsvp_(char *jobu, char *jobv, char *jobq, integer *m, 
00022         integer *p, integer *n, doublereal *a, integer *lda, doublereal *b, 
00023         integer *ldb, doublereal *tola, doublereal *tolb, integer *k, integer 
00024         *l, doublereal *u, integer *ldu, doublereal *v, integer *ldv, 
00025         doublereal *q, integer *ldq, integer *iwork, doublereal *tau, 
00026         doublereal *work, integer *info)
00027 {
00028     /* System generated locals */
00029     integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, u_dim1, 
00030             u_offset, v_dim1, v_offset, i__1, i__2, i__3;
00031     doublereal d__1;
00032 
00033     /* Local variables */
00034     integer i__, j;
00035     extern logical lsame_(char *, char *);
00036     logical wantq, wantu, wantv;
00037     extern /* Subroutine */ int dgeqr2_(integer *, integer *, doublereal *, 
00038             integer *, doublereal *, doublereal *, integer *), dgerq2_(
00039             integer *, integer *, doublereal *, integer *, doublereal *, 
00040             doublereal *, integer *), dorg2r_(integer *, integer *, integer *, 
00041              doublereal *, integer *, doublereal *, doublereal *, integer *), 
00042             dorm2r_(char *, char *, integer *, integer *, integer *, 
00043             doublereal *, integer *, doublereal *, doublereal *, integer *, 
00044             doublereal *, integer *), dormr2_(char *, char *, 
00045             integer *, integer *, integer *, doublereal *, integer *, 
00046             doublereal *, doublereal *, integer *, doublereal *, integer *), dgeqpf_(integer *, integer *, doublereal *, 
00047             integer *, integer *, doublereal *, doublereal *, integer *), 
00048             dlacpy_(char *, integer *, integer *, doublereal *, integer *, 
00049             doublereal *, integer *), dlaset_(char *, integer *, 
00050             integer *, doublereal *, doublereal *, doublereal *, integer *), xerbla_(char *, integer *), dlapmt_(logical *, 
00051             integer *, integer *, doublereal *, integer *, integer *);
00052     logical forwrd;
00053 
00054 
00055 /*  -- LAPACK routine (version 3.2) -- */
00056 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00057 /*     November 2006 */
00058 
00059 /*     .. Scalar Arguments .. */
00060 /*     .. */
00061 /*     .. Array Arguments .. */
00062 /*     .. */
00063 
00064 /*  Purpose */
00065 /*  ======= */
00066 
00067 /*  DGGSVP computes orthogonal matrices U, V and Q such that */
00068 
00069 /*                   N-K-L  K    L */
00070 /*   U'*A*Q =     K ( 0    A12  A13 )  if M-K-L >= 0; */
00071 /*                L ( 0     0   A23 ) */
00072 /*            M-K-L ( 0     0    0  ) */
00073 
00074 /*                   N-K-L  K    L */
00075 /*          =     K ( 0    A12  A13 )  if M-K-L < 0; */
00076 /*              M-K ( 0     0   A23 ) */
00077 
00078 /*                 N-K-L  K    L */
00079 /*   V'*B*Q =   L ( 0     0   B13 ) */
00080 /*            P-L ( 0     0    0  ) */
00081 
00082 /*  where the K-by-K matrix A12 and L-by-L matrix B13 are nonsingular */
00083 /*  upper triangular; A23 is L-by-L upper triangular if M-K-L >= 0, */
00084 /*  otherwise A23 is (M-K)-by-L upper trapezoidal.  K+L = the effective */
00085 /*  numerical rank of the (M+P)-by-N matrix (A',B')'.  Z' denotes the */
00086 /*  transpose of Z. */
00087 
00088 /*  This decomposition is the preprocessing step for computing the */
00089 /*  Generalized Singular Value Decomposition (GSVD), see subroutine */
00090 /*  DGGSVD. */
00091 
00092 /*  Arguments */
00093 /*  ========= */
00094 
00095 /*  JOBU    (input) CHARACTER*1 */
00096 /*          = 'U':  Orthogonal matrix U is computed; */
00097 /*          = 'N':  U is not computed. */
00098 
00099 /*  JOBV    (input) CHARACTER*1 */
00100 /*          = 'V':  Orthogonal matrix V is computed; */
00101 /*          = 'N':  V is not computed. */
00102 
00103 /*  JOBQ    (input) CHARACTER*1 */
00104 /*          = 'Q':  Orthogonal matrix Q is computed; */
00105 /*          = 'N':  Q is not computed. */
00106 
00107 /*  M       (input) INTEGER */
00108 /*          The number of rows of the matrix A.  M >= 0. */
00109 
00110 /*  P       (input) INTEGER */
00111 /*          The number of rows of the matrix B.  P >= 0. */
00112 
00113 /*  N       (input) INTEGER */
00114 /*          The number of columns of the matrices A and B.  N >= 0. */
00115 
00116 /*  A       (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
00117 /*          On entry, the M-by-N matrix A. */
00118 /*          On exit, A contains the triangular (or trapezoidal) matrix */
00119 /*          described in the Purpose section. */
00120 
00121 /*  LDA     (input) INTEGER */
00122 /*          The leading dimension of the array A. LDA >= max(1,M). */
00123 
00124 /*  B       (input/output) DOUBLE PRECISION array, dimension (LDB,N) */
00125 /*          On entry, the P-by-N matrix B. */
00126 /*          On exit, B contains the triangular matrix described in */
00127 /*          the Purpose section. */
00128 
00129 /*  LDB     (input) INTEGER */
00130 /*          The leading dimension of the array B. LDB >= max(1,P). */
00131 
00132 /*  TOLA    (input) DOUBLE PRECISION */
00133 /*  TOLB    (input) DOUBLE PRECISION */
00134 /*          TOLA and TOLB are the thresholds to determine the effective */
00135 /*          numerical rank of matrix B and a subblock of A. Generally, */
00136 /*          they are set to */
00137 /*             TOLA = MAX(M,N)*norm(A)*MAZHEPS, */
00138 /*             TOLB = MAX(P,N)*norm(B)*MAZHEPS. */
00139 /*          The size of TOLA and TOLB may affect the size of backward */
00140 /*          errors of the decomposition. */
00141 
00142 /*  K       (output) INTEGER */
00143 /*  L       (output) INTEGER */
00144 /*          On exit, K and L specify the dimension of the subblocks */
00145 /*          described in Purpose. */
00146 /*          K + L = effective numerical rank of (A',B')'. */
00147 
00148 /*  U       (output) DOUBLE PRECISION array, dimension (LDU,M) */
00149 /*          If JOBU = 'U', U contains the orthogonal matrix U. */
00150 /*          If JOBU = 'N', U is not referenced. */
00151 
00152 /*  LDU     (input) INTEGER */
00153 /*          The leading dimension of the array U. LDU >= max(1,M) if */
00154 /*          JOBU = 'U'; LDU >= 1 otherwise. */
00155 
00156 /*  V       (output) DOUBLE PRECISION array, dimension (LDV,P) */
00157 /*          If JOBV = 'V', V contains the orthogonal matrix V. */
00158 /*          If JOBV = 'N', V is not referenced. */
00159 
00160 /*  LDV     (input) INTEGER */
00161 /*          The leading dimension of the array V. LDV >= max(1,P) if */
00162 /*          JOBV = 'V'; LDV >= 1 otherwise. */
00163 
00164 /*  Q       (output) DOUBLE PRECISION array, dimension (LDQ,N) */
00165 /*          If JOBQ = 'Q', Q contains the orthogonal matrix Q. */
00166 /*          If JOBQ = 'N', Q is not referenced. */
00167 
00168 /*  LDQ     (input) INTEGER */
00169 /*          The leading dimension of the array Q. LDQ >= max(1,N) if */
00170 /*          JOBQ = 'Q'; LDQ >= 1 otherwise. */
00171 
00172 /*  IWORK   (workspace) INTEGER array, dimension (N) */
00173 
00174 /*  TAU     (workspace) DOUBLE PRECISION array, dimension (N) */
00175 
00176 /*  WORK    (workspace) DOUBLE PRECISION array, dimension (max(3*N,M,P)) */
00177 
00178 /*  INFO    (output) INTEGER */
00179 /*          = 0:  successful exit */
00180 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00181 
00182 
00183 /*  Further Details */
00184 /*  =============== */
00185 
00186 /*  The subroutine uses LAPACK subroutine DGEQPF for the QR factorization */
00187 /*  with column pivoting to detect the effective numerical rank of the */
00188 /*  a matrix. It may be replaced by a better rank determination strategy. */
00189 
00190 /*  ===================================================================== */
00191 
00192 /*     .. Parameters .. */
00193 /*     .. */
00194 /*     .. Local Scalars .. */
00195 /*     .. */
00196 /*     .. External Functions .. */
00197 /*     .. */
00198 /*     .. External Subroutines .. */
00199 /*     .. */
00200 /*     .. Intrinsic Functions .. */
00201 /*     .. */
00202 /*     .. Executable Statements .. */
00203 
00204 /*     Test the input parameters */
00205 
00206     /* Parameter adjustments */
00207     a_dim1 = *lda;
00208     a_offset = 1 + a_dim1;
00209     a -= a_offset;
00210     b_dim1 = *ldb;
00211     b_offset = 1 + b_dim1;
00212     b -= b_offset;
00213     u_dim1 = *ldu;
00214     u_offset = 1 + u_dim1;
00215     u -= u_offset;
00216     v_dim1 = *ldv;
00217     v_offset = 1 + v_dim1;
00218     v -= v_offset;
00219     q_dim1 = *ldq;
00220     q_offset = 1 + q_dim1;
00221     q -= q_offset;
00222     --iwork;
00223     --tau;
00224     --work;
00225 
00226     /* Function Body */
00227     wantu = lsame_(jobu, "U");
00228     wantv = lsame_(jobv, "V");
00229     wantq = lsame_(jobq, "Q");
00230     forwrd = TRUE_;
00231 
00232     *info = 0;
00233     if (! (wantu || lsame_(jobu, "N"))) {
00234         *info = -1;
00235     } else if (! (wantv || lsame_(jobv, "N"))) {
00236         *info = -2;
00237     } else if (! (wantq || lsame_(jobq, "N"))) {
00238         *info = -3;
00239     } else if (*m < 0) {
00240         *info = -4;
00241     } else if (*p < 0) {
00242         *info = -5;
00243     } else if (*n < 0) {
00244         *info = -6;
00245     } else if (*lda < max(1,*m)) {
00246         *info = -8;
00247     } else if (*ldb < max(1,*p)) {
00248         *info = -10;
00249     } else if (*ldu < 1 || wantu && *ldu < *m) {
00250         *info = -16;
00251     } else if (*ldv < 1 || wantv && *ldv < *p) {
00252         *info = -18;
00253     } else if (*ldq < 1 || wantq && *ldq < *n) {
00254         *info = -20;
00255     }
00256     if (*info != 0) {
00257         i__1 = -(*info);
00258         xerbla_("DGGSVP", &i__1);
00259         return 0;
00260     }
00261 
00262 /*     QR with column pivoting of B: B*P = V*( S11 S12 ) */
00263 /*                                           (  0   0  ) */
00264 
00265     i__1 = *n;
00266     for (i__ = 1; i__ <= i__1; ++i__) {
00267         iwork[i__] = 0;
00268 /* L10: */
00269     }
00270     dgeqpf_(p, n, &b[b_offset], ldb, &iwork[1], &tau[1], &work[1], info);
00271 
00272 /*     Update A := A*P */
00273 
00274     dlapmt_(&forwrd, m, n, &a[a_offset], lda, &iwork[1]);
00275 
00276 /*     Determine the effective rank of matrix B. */
00277 
00278     *l = 0;
00279     i__1 = min(*p,*n);
00280     for (i__ = 1; i__ <= i__1; ++i__) {
00281         if ((d__1 = b[i__ + i__ * b_dim1], abs(d__1)) > *tolb) {
00282             ++(*l);
00283         }
00284 /* L20: */
00285     }
00286 
00287     if (wantv) {
00288 
00289 /*        Copy the details of V, and form V. */
00290 
00291         dlaset_("Full", p, p, &c_b12, &c_b12, &v[v_offset], ldv);
00292         if (*p > 1) {
00293             i__1 = *p - 1;
00294             dlacpy_("Lower", &i__1, n, &b[b_dim1 + 2], ldb, &v[v_dim1 + 2], 
00295                     ldv);
00296         }
00297         i__1 = min(*p,*n);
00298         dorg2r_(p, p, &i__1, &v[v_offset], ldv, &tau[1], &work[1], info);
00299     }
00300 
00301 /*     Clean up B */
00302 
00303     i__1 = *l - 1;
00304     for (j = 1; j <= i__1; ++j) {
00305         i__2 = *l;
00306         for (i__ = j + 1; i__ <= i__2; ++i__) {
00307             b[i__ + j * b_dim1] = 0.;
00308 /* L30: */
00309         }
00310 /* L40: */
00311     }
00312     if (*p > *l) {
00313         i__1 = *p - *l;
00314         dlaset_("Full", &i__1, n, &c_b12, &c_b12, &b[*l + 1 + b_dim1], ldb);
00315     }
00316 
00317     if (wantq) {
00318 
00319 /*        Set Q = I and Update Q := Q*P */
00320 
00321         dlaset_("Full", n, n, &c_b12, &c_b22, &q[q_offset], ldq);
00322         dlapmt_(&forwrd, n, n, &q[q_offset], ldq, &iwork[1]);
00323     }
00324 
00325     if (*p >= *l && *n != *l) {
00326 
00327 /*        RQ factorization of (S11 S12): ( S11 S12 ) = ( 0 S12 )*Z */
00328 
00329         dgerq2_(l, n, &b[b_offset], ldb, &tau[1], &work[1], info);
00330 
00331 /*        Update A := A*Z' */
00332 
00333         dormr2_("Right", "Transpose", m, n, l, &b[b_offset], ldb, &tau[1], &a[
00334                 a_offset], lda, &work[1], info);
00335 
00336         if (wantq) {
00337 
00338 /*           Update Q := Q*Z' */
00339 
00340             dormr2_("Right", "Transpose", n, n, l, &b[b_offset], ldb, &tau[1], 
00341                      &q[q_offset], ldq, &work[1], info);
00342         }
00343 
00344 /*        Clean up B */
00345 
00346         i__1 = *n - *l;
00347         dlaset_("Full", l, &i__1, &c_b12, &c_b12, &b[b_offset], ldb);
00348         i__1 = *n;
00349         for (j = *n - *l + 1; j <= i__1; ++j) {
00350             i__2 = *l;
00351             for (i__ = j - *n + *l + 1; i__ <= i__2; ++i__) {
00352                 b[i__ + j * b_dim1] = 0.;
00353 /* L50: */
00354             }
00355 /* L60: */
00356         }
00357 
00358     }
00359 
00360 /*     Let              N-L     L */
00361 /*                A = ( A11    A12 ) M, */
00362 
00363 /*     then the following does the complete QR decomposition of A11: */
00364 
00365 /*              A11 = U*(  0  T12 )*P1' */
00366 /*                      (  0   0  ) */
00367 
00368     i__1 = *n - *l;
00369     for (i__ = 1; i__ <= i__1; ++i__) {
00370         iwork[i__] = 0;
00371 /* L70: */
00372     }
00373     i__1 = *n - *l;
00374     dgeqpf_(m, &i__1, &a[a_offset], lda, &iwork[1], &tau[1], &work[1], info);
00375 
00376 /*     Determine the effective rank of A11 */
00377 
00378     *k = 0;
00379 /* Computing MIN */
00380     i__2 = *m, i__3 = *n - *l;
00381     i__1 = min(i__2,i__3);
00382     for (i__ = 1; i__ <= i__1; ++i__) {
00383         if ((d__1 = a[i__ + i__ * a_dim1], abs(d__1)) > *tola) {
00384             ++(*k);
00385         }
00386 /* L80: */
00387     }
00388 
00389 /*     Update A12 := U'*A12, where A12 = A( 1:M, N-L+1:N ) */
00390 
00391 /* Computing MIN */
00392     i__2 = *m, i__3 = *n - *l;
00393     i__1 = min(i__2,i__3);
00394     dorm2r_("Left", "Transpose", m, l, &i__1, &a[a_offset], lda, &tau[1], &a[(
00395             *n - *l + 1) * a_dim1 + 1], lda, &work[1], info);
00396 
00397     if (wantu) {
00398 
00399 /*        Copy the details of U, and form U */
00400 
00401         dlaset_("Full", m, m, &c_b12, &c_b12, &u[u_offset], ldu);
00402         if (*m > 1) {
00403             i__1 = *m - 1;
00404             i__2 = *n - *l;
00405             dlacpy_("Lower", &i__1, &i__2, &a[a_dim1 + 2], lda, &u[u_dim1 + 2]
00406 , ldu);
00407         }
00408 /* Computing MIN */
00409         i__2 = *m, i__3 = *n - *l;
00410         i__1 = min(i__2,i__3);
00411         dorg2r_(m, m, &i__1, &u[u_offset], ldu, &tau[1], &work[1], info);
00412     }
00413 
00414     if (wantq) {
00415 
00416 /*        Update Q( 1:N, 1:N-L )  = Q( 1:N, 1:N-L )*P1 */
00417 
00418         i__1 = *n - *l;
00419         dlapmt_(&forwrd, n, &i__1, &q[q_offset], ldq, &iwork[1]);
00420     }
00421 
00422 /*     Clean up A: set the strictly lower triangular part of */
00423 /*     A(1:K, 1:K) = 0, and A( K+1:M, 1:N-L ) = 0. */
00424 
00425     i__1 = *k - 1;
00426     for (j = 1; j <= i__1; ++j) {
00427         i__2 = *k;
00428         for (i__ = j + 1; i__ <= i__2; ++i__) {
00429             a[i__ + j * a_dim1] = 0.;
00430 /* L90: */
00431         }
00432 /* L100: */
00433     }
00434     if (*m > *k) {
00435         i__1 = *m - *k;
00436         i__2 = *n - *l;
00437         dlaset_("Full", &i__1, &i__2, &c_b12, &c_b12, &a[*k + 1 + a_dim1], 
00438                 lda);
00439     }
00440 
00441     if (*n - *l > *k) {
00442 
00443 /*        RQ factorization of ( T11 T12 ) = ( 0 T12 )*Z1 */
00444 
00445         i__1 = *n - *l;
00446         dgerq2_(k, &i__1, &a[a_offset], lda, &tau[1], &work[1], info);
00447 
00448         if (wantq) {
00449 
00450 /*           Update Q( 1:N,1:N-L ) = Q( 1:N,1:N-L )*Z1' */
00451 
00452             i__1 = *n - *l;
00453             dormr2_("Right", "Transpose", n, &i__1, k, &a[a_offset], lda, &
00454                     tau[1], &q[q_offset], ldq, &work[1], info);
00455         }
00456 
00457 /*        Clean up A */
00458 
00459         i__1 = *n - *l - *k;
00460         dlaset_("Full", k, &i__1, &c_b12, &c_b12, &a[a_offset], lda);
00461         i__1 = *n - *l;
00462         for (j = *n - *l - *k + 1; j <= i__1; ++j) {
00463             i__2 = *k;
00464             for (i__ = j - *n + *l + *k + 1; i__ <= i__2; ++i__) {
00465                 a[i__ + j * a_dim1] = 0.;
00466 /* L110: */
00467             }
00468 /* L120: */
00469         }
00470 
00471     }
00472 
00473     if (*m > *k) {
00474 
00475 /*        QR factorization of A( K+1:M,N-L+1:N ) */
00476 
00477         i__1 = *m - *k;
00478         dgeqr2_(&i__1, l, &a[*k + 1 + (*n - *l + 1) * a_dim1], lda, &tau[1], &
00479                 work[1], info);
00480 
00481         if (wantu) {
00482 
00483 /*           Update U(:,K+1:M) := U(:,K+1:M)*U1 */
00484 
00485             i__1 = *m - *k;
00486 /* Computing MIN */
00487             i__3 = *m - *k;
00488             i__2 = min(i__3,*l);
00489             dorm2r_("Right", "No transpose", m, &i__1, &i__2, &a[*k + 1 + (*n 
00490                     - *l + 1) * a_dim1], lda, &tau[1], &u[(*k + 1) * u_dim1 + 
00491                     1], ldu, &work[1], info);
00492         }
00493 
00494 /*        Clean up */
00495 
00496         i__1 = *n;
00497         for (j = *n - *l + 1; j <= i__1; ++j) {
00498             i__2 = *m;
00499             for (i__ = j - *n + *k + *l + 1; i__ <= i__2; ++i__) {
00500                 a[i__ + j * a_dim1] = 0.;
00501 /* L130: */
00502             }
00503 /* L140: */
00504         }
00505 
00506     }
00507 
00508     return 0;
00509 
00510 /*     End of DGGSVP */
00511 
00512 } /* dggsvp_ */


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