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


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