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


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