ztgsja.c
Go to the documentation of this file.
00001 /* ztgsja.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 doublecomplex c_b1 = {0.,0.};
00019 static doublecomplex c_b2 = {1.,0.};
00020 static integer c__1 = 1;
00021 static doublereal c_b39 = -1.;
00022 static doublereal c_b42 = 1.;
00023 
00024 /* Subroutine */ int ztgsja_(char *jobu, char *jobv, char *jobq, integer *m, 
00025         integer *p, integer *n, integer *k, integer *l, doublecomplex *a, 
00026         integer *lda, doublecomplex *b, integer *ldb, doublereal *tola, 
00027         doublereal *tolb, doublereal *alpha, doublereal *beta, doublecomplex *
00028         u, integer *ldu, doublecomplex *v, integer *ldv, doublecomplex *q, 
00029         integer *ldq, doublecomplex *work, integer *ncycle, integer *info)
00030 {
00031     /* System generated locals */
00032     integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, u_dim1, 
00033             u_offset, v_dim1, v_offset, i__1, i__2, i__3, i__4;
00034     doublereal d__1;
00035     doublecomplex z__1;
00036 
00037     /* Builtin functions */
00038     void d_cnjg(doublecomplex *, doublecomplex *);
00039 
00040     /* Local variables */
00041     integer i__, j;
00042     doublereal a1, b1, a3, b3;
00043     doublecomplex a2, b2;
00044     doublereal csq, csu, csv;
00045     doublecomplex snq;
00046     doublereal rwk;
00047     doublecomplex snu, snv;
00048     extern /* Subroutine */ int zrot_(integer *, doublecomplex *, integer *, 
00049             doublecomplex *, integer *, doublereal *, doublecomplex *);
00050     doublereal gamma;
00051     extern logical lsame_(char *, char *);
00052     logical initq, initu, initv, wantq, upper;
00053     doublereal error, ssmin;
00054     logical wantu, wantv;
00055     extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *, 
00056             doublecomplex *, integer *), zlags2_(logical *, doublereal *, 
00057             doublecomplex *, doublereal *, doublereal *, doublecomplex *, 
00058             doublereal *, doublereal *, doublecomplex *, doublereal *, 
00059             doublecomplex *, doublereal *, doublecomplex *);
00060     integer kcycle;
00061     extern /* Subroutine */ int dlartg_(doublereal *, doublereal *, 
00062             doublereal *, doublereal *, doublereal *), xerbla_(char *, 
00063             integer *), zdscal_(integer *, doublereal *, 
00064             doublecomplex *, integer *), zlapll_(integer *, doublecomplex *, 
00065             integer *, doublecomplex *, integer *, doublereal *), zlaset_(
00066             char *, integer *, integer *, doublecomplex *, doublecomplex *, 
00067             doublecomplex *, integer *);
00068 
00069 
00070 /*  -- LAPACK routine (version 3.2) -- */
00071 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00072 /*     November 2006 */
00073 
00074 /*     .. Scalar Arguments .. */
00075 /*     .. */
00076 /*     .. Array Arguments .. */
00077 /*     .. */
00078 
00079 /*  Purpose */
00080 /*  ======= */
00081 
00082 /*  ZTGSJA computes the generalized singular value decomposition (GSVD) */
00083 /*  of two complex upper triangular (or trapezoidal) matrices A and B. */
00084 
00085 /*  On entry, it is assumed that matrices A and B have the following */
00086 /*  forms, which may be obtained by the preprocessing subroutine ZGGSVP */
00087 /*  from a general M-by-N matrix A and P-by-N matrix B: */
00088 
00089 /*               N-K-L  K    L */
00090 /*     A =    K ( 0    A12  A13 ) if M-K-L >= 0; */
00091 /*            L ( 0     0   A23 ) */
00092 /*        M-K-L ( 0     0    0  ) */
00093 
00094 /*             N-K-L  K    L */
00095 /*     A =  K ( 0    A12  A13 ) if M-K-L < 0; */
00096 /*        M-K ( 0     0   A23 ) */
00097 
00098 /*             N-K-L  K    L */
00099 /*     B =  L ( 0     0   B13 ) */
00100 /*        P-L ( 0     0    0  ) */
00101 
00102 /*  where the K-by-K matrix A12 and L-by-L matrix B13 are nonsingular */
00103 /*  upper triangular; A23 is L-by-L upper triangular if M-K-L >= 0, */
00104 /*  otherwise A23 is (M-K)-by-L upper trapezoidal. */
00105 
00106 /*  On exit, */
00107 
00108 /*         U'*A*Q = D1*( 0 R ),    V'*B*Q = D2*( 0 R ), */
00109 
00110 /*  where U, V and Q are unitary matrices, Z' denotes the conjugate */
00111 /*  transpose of Z, R is a nonsingular upper triangular matrix, and D1 */
00112 /*  and D2 are ``diagonal'' matrices, which are of the following */
00113 /*  structures: */
00114 
00115 /*  If M-K-L >= 0, */
00116 
00117 /*                      K  L */
00118 /*         D1 =     K ( I  0 ) */
00119 /*                  L ( 0  C ) */
00120 /*              M-K-L ( 0  0 ) */
00121 
00122 /*                     K  L */
00123 /*         D2 = L   ( 0  S ) */
00124 /*              P-L ( 0  0 ) */
00125 
00126 /*                 N-K-L  K    L */
00127 /*    ( 0 R ) = K (  0   R11  R12 ) K */
00128 /*              L (  0    0   R22 ) L */
00129 
00130 /*  where */
00131 
00132 /*    C = diag( ALPHA(K+1), ... , ALPHA(K+L) ), */
00133 /*    S = diag( BETA(K+1),  ... , BETA(K+L) ), */
00134 /*    C**2 + S**2 = I. */
00135 
00136 /*    R is stored in A(1:K+L,N-K-L+1:N) on exit. */
00137 
00138 /*  If M-K-L < 0, */
00139 
00140 /*                 K M-K K+L-M */
00141 /*      D1 =   K ( I  0    0   ) */
00142 /*           M-K ( 0  C    0   ) */
00143 
00144 /*                   K M-K K+L-M */
00145 /*      D2 =   M-K ( 0  S    0   ) */
00146 /*           K+L-M ( 0  0    I   ) */
00147 /*             P-L ( 0  0    0   ) */
00148 
00149 /*                 N-K-L  K   M-K  K+L-M */
00150 /* ( 0 R ) =    K ( 0    R11  R12  R13  ) */
00151 /*            M-K ( 0     0   R22  R23  ) */
00152 /*          K+L-M ( 0     0    0   R33  ) */
00153 
00154 /*  where */
00155 /*  C = diag( ALPHA(K+1), ... , ALPHA(M) ), */
00156 /*  S = diag( BETA(K+1),  ... , BETA(M) ), */
00157 /*  C**2 + S**2 = I. */
00158 
00159 /*  R = ( R11 R12 R13 ) is stored in A(1:M, N-K-L+1:N) and R33 is stored */
00160 /*      (  0  R22 R23 ) */
00161 /*  in B(M-K+1:L,N+M-K-L+1:N) on exit. */
00162 
00163 /*  The computation of the unitary transformation matrices U, V or Q */
00164 /*  is optional.  These matrices may either be formed explicitly, or they */
00165 /*  may be postmultiplied into input matrices U1, V1, or Q1. */
00166 
00167 /*  Arguments */
00168 /*  ========= */
00169 
00170 /*  JOBU    (input) CHARACTER*1 */
00171 /*          = 'U':  U must contain a unitary matrix U1 on entry, and */
00172 /*                  the product U1*U is returned; */
00173 /*          = 'I':  U is initialized to the unit matrix, and the */
00174 /*                  unitary matrix U is returned; */
00175 /*          = 'N':  U is not computed. */
00176 
00177 /*  JOBV    (input) CHARACTER*1 */
00178 /*          = 'V':  V must contain a unitary matrix V1 on entry, and */
00179 /*                  the product V1*V is returned; */
00180 /*          = 'I':  V is initialized to the unit matrix, and the */
00181 /*                  unitary matrix V is returned; */
00182 /*          = 'N':  V is not computed. */
00183 
00184 /*  JOBQ    (input) CHARACTER*1 */
00185 /*          = 'Q':  Q must contain a unitary matrix Q1 on entry, and */
00186 /*                  the product Q1*Q is returned; */
00187 /*          = 'I':  Q is initialized to the unit matrix, and the */
00188 /*                  unitary matrix Q is returned; */
00189 /*          = 'N':  Q is not computed. */
00190 
00191 /*  M       (input) INTEGER */
00192 /*          The number of rows of the matrix A.  M >= 0. */
00193 
00194 /*  P       (input) INTEGER */
00195 /*          The number of rows of the matrix B.  P >= 0. */
00196 
00197 /*  N       (input) INTEGER */
00198 /*          The number of columns of the matrices A and B.  N >= 0. */
00199 
00200 /*  K       (input) INTEGER */
00201 /*  L       (input) INTEGER */
00202 /*          K and L specify the subblocks in the input matrices A and B: */
00203 /*          A23 = A(K+1:MIN(K+L,M),N-L+1:N) and B13 = B(1:L,,N-L+1:N) */
00204 /*          of A and B, whose GSVD is going to be computed by ZTGSJA. */
00205 /*          See Further details. */
00206 
00207 /*  A       (input/output) COMPLEX*16 array, dimension (LDA,N) */
00208 /*          On entry, the M-by-N matrix A. */
00209 /*          On exit, A(N-K+1:N,1:MIN(K+L,M) ) contains the triangular */
00210 /*          matrix R or part of R.  See Purpose for details. */
00211 
00212 /*  LDA     (input) INTEGER */
00213 /*          The leading dimension of the array A. LDA >= max(1,M). */
00214 
00215 /*  B       (input/output) COMPLEX*16 array, dimension (LDB,N) */
00216 /*          On entry, the P-by-N matrix B. */
00217 /*          On exit, if necessary, B(M-K+1:L,N+M-K-L+1:N) contains */
00218 /*          a part of R.  See Purpose for details. */
00219 
00220 /*  LDB     (input) INTEGER */
00221 /*          The leading dimension of the array B. LDB >= max(1,P). */
00222 
00223 /*  TOLA    (input) DOUBLE PRECISION */
00224 /*  TOLB    (input) DOUBLE PRECISION */
00225 /*          TOLA and TOLB are the convergence criteria for the Jacobi- */
00226 /*          Kogbetliantz iteration procedure. Generally, they are the */
00227 /*          same as used in the preprocessing step, say */
00228 /*              TOLA = MAX(M,N)*norm(A)*MAZHEPS, */
00229 /*              TOLB = MAX(P,N)*norm(B)*MAZHEPS. */
00230 
00231 /*  ALPHA   (output) DOUBLE PRECISION array, dimension (N) */
00232 /*  BETA    (output) DOUBLE PRECISION array, dimension (N) */
00233 /*          On exit, ALPHA and BETA contain the generalized singular */
00234 /*          value pairs of A and B; */
00235 /*            ALPHA(1:K) = 1, */
00236 /*            BETA(1:K)  = 0, */
00237 /*          and if M-K-L >= 0, */
00238 /*            ALPHA(K+1:K+L) = diag(C), */
00239 /*            BETA(K+1:K+L)  = diag(S), */
00240 /*          or if M-K-L < 0, */
00241 /*            ALPHA(K+1:M)= C, ALPHA(M+1:K+L)= 0 */
00242 /*            BETA(K+1:M) = S, BETA(M+1:K+L) = 1. */
00243 /*          Furthermore, if K+L < N, */
00244 /*            ALPHA(K+L+1:N) = 0 */
00245 /*            BETA(K+L+1:N)  = 0. */
00246 
00247 /*  U       (input/output) COMPLEX*16 array, dimension (LDU,M) */
00248 /*          On entry, if JOBU = 'U', U must contain a matrix U1 (usually */
00249 /*          the unitary matrix returned by ZGGSVP). */
00250 /*          On exit, */
00251 /*          if JOBU = 'I', U contains the unitary matrix U; */
00252 /*          if JOBU = 'U', U contains the product U1*U. */
00253 /*          If JOBU = 'N', U is not referenced. */
00254 
00255 /*  LDU     (input) INTEGER */
00256 /*          The leading dimension of the array U. LDU >= max(1,M) if */
00257 /*          JOBU = 'U'; LDU >= 1 otherwise. */
00258 
00259 /*  V       (input/output) COMPLEX*16 array, dimension (LDV,P) */
00260 /*          On entry, if JOBV = 'V', V must contain a matrix V1 (usually */
00261 /*          the unitary matrix returned by ZGGSVP). */
00262 /*          On exit, */
00263 /*          if JOBV = 'I', V contains the unitary matrix V; */
00264 /*          if JOBV = 'V', V contains the product V1*V. */
00265 /*          If JOBV = 'N', V is not referenced. */
00266 
00267 /*  LDV     (input) INTEGER */
00268 /*          The leading dimension of the array V. LDV >= max(1,P) if */
00269 /*          JOBV = 'V'; LDV >= 1 otherwise. */
00270 
00271 /*  Q       (input/output) COMPLEX*16 array, dimension (LDQ,N) */
00272 /*          On entry, if JOBQ = 'Q', Q must contain a matrix Q1 (usually */
00273 /*          the unitary matrix returned by ZGGSVP). */
00274 /*          On exit, */
00275 /*          if JOBQ = 'I', Q contains the unitary matrix Q; */
00276 /*          if JOBQ = 'Q', Q contains the product Q1*Q. */
00277 /*          If JOBQ = 'N', Q is not referenced. */
00278 
00279 /*  LDQ     (input) INTEGER */
00280 /*          The leading dimension of the array Q. LDQ >= max(1,N) if */
00281 /*          JOBQ = 'Q'; LDQ >= 1 otherwise. */
00282 
00283 /*  WORK    (workspace) COMPLEX*16 array, dimension (2*N) */
00284 
00285 /*  NCYCLE  (output) INTEGER */
00286 /*          The number of cycles required for convergence. */
00287 
00288 /*  INFO    (output) INTEGER */
00289 /*          = 0:  successful exit */
00290 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00291 /*          = 1:  the procedure does not converge after MAXIT cycles. */
00292 
00293 /*  Internal Parameters */
00294 /*  =================== */
00295 
00296 /*  MAXIT   INTEGER */
00297 /*          MAXIT specifies the total loops that the iterative procedure */
00298 /*          may take. If after MAXIT cycles, the routine fails to */
00299 /*          converge, we return INFO = 1. */
00300 
00301 /*  Further Details */
00302 /*  =============== */
00303 
00304 /*  ZTGSJA essentially uses a variant of Kogbetliantz algorithm to reduce */
00305 /*  min(L,M-K)-by-L triangular (or trapezoidal) matrix A23 and L-by-L */
00306 /*  matrix B13 to the form: */
00307 
00308 /*           U1'*A13*Q1 = C1*R1; V1'*B13*Q1 = S1*R1, */
00309 
00310 /*  where U1, V1 and Q1 are unitary matrix, and Z' is the conjugate */
00311 /*  transpose of Z.  C1 and S1 are diagonal matrices satisfying */
00312 
00313 /*                C1**2 + S1**2 = I, */
00314 
00315 /*  and R1 is an L-by-L nonsingular upper triangular matrix. */
00316 
00317 /*  ===================================================================== */
00318 
00319 /*     .. Parameters .. */
00320 /*     .. */
00321 /*     .. Local Scalars .. */
00322 
00323 /*     .. */
00324 /*     .. External Functions .. */
00325 /*     .. */
00326 /*     .. External Subroutines .. */
00327 /*     .. */
00328 /*     .. Intrinsic Functions .. */
00329 /*     .. */
00330 /*     .. Executable Statements .. */
00331 
00332 /*     Decode and test the input parameters */
00333 
00334     /* Parameter adjustments */
00335     a_dim1 = *lda;
00336     a_offset = 1 + a_dim1;
00337     a -= a_offset;
00338     b_dim1 = *ldb;
00339     b_offset = 1 + b_dim1;
00340     b -= b_offset;
00341     --alpha;
00342     --beta;
00343     u_dim1 = *ldu;
00344     u_offset = 1 + u_dim1;
00345     u -= u_offset;
00346     v_dim1 = *ldv;
00347     v_offset = 1 + v_dim1;
00348     v -= v_offset;
00349     q_dim1 = *ldq;
00350     q_offset = 1 + q_dim1;
00351     q -= q_offset;
00352     --work;
00353 
00354     /* Function Body */
00355     initu = lsame_(jobu, "I");
00356     wantu = initu || lsame_(jobu, "U");
00357 
00358     initv = lsame_(jobv, "I");
00359     wantv = initv || lsame_(jobv, "V");
00360 
00361     initq = lsame_(jobq, "I");
00362     wantq = initq || lsame_(jobq, "Q");
00363 
00364     *info = 0;
00365     if (! (initu || wantu || lsame_(jobu, "N"))) {
00366         *info = -1;
00367     } else if (! (initv || wantv || lsame_(jobv, "N"))) 
00368             {
00369         *info = -2;
00370     } else if (! (initq || wantq || lsame_(jobq, "N"))) 
00371             {
00372         *info = -3;
00373     } else if (*m < 0) {
00374         *info = -4;
00375     } else if (*p < 0) {
00376         *info = -5;
00377     } else if (*n < 0) {
00378         *info = -6;
00379     } else if (*lda < max(1,*m)) {
00380         *info = -10;
00381     } else if (*ldb < max(1,*p)) {
00382         *info = -12;
00383     } else if (*ldu < 1 || wantu && *ldu < *m) {
00384         *info = -18;
00385     } else if (*ldv < 1 || wantv && *ldv < *p) {
00386         *info = -20;
00387     } else if (*ldq < 1 || wantq && *ldq < *n) {
00388         *info = -22;
00389     }
00390     if (*info != 0) {
00391         i__1 = -(*info);
00392         xerbla_("ZTGSJA", &i__1);
00393         return 0;
00394     }
00395 
00396 /*     Initialize U, V and Q, if necessary */
00397 
00398     if (initu) {
00399         zlaset_("Full", m, m, &c_b1, &c_b2, &u[u_offset], ldu);
00400     }
00401     if (initv) {
00402         zlaset_("Full", p, p, &c_b1, &c_b2, &v[v_offset], ldv);
00403     }
00404     if (initq) {
00405         zlaset_("Full", n, n, &c_b1, &c_b2, &q[q_offset], ldq);
00406     }
00407 
00408 /*     Loop until convergence */
00409 
00410     upper = FALSE_;
00411     for (kcycle = 1; kcycle <= 40; ++kcycle) {
00412 
00413         upper = ! upper;
00414 
00415         i__1 = *l - 1;
00416         for (i__ = 1; i__ <= i__1; ++i__) {
00417             i__2 = *l;
00418             for (j = i__ + 1; j <= i__2; ++j) {
00419 
00420                 a1 = 0.;
00421                 a2.r = 0., a2.i = 0.;
00422                 a3 = 0.;
00423                 if (*k + i__ <= *m) {
00424                     i__3 = *k + i__ + (*n - *l + i__) * a_dim1;
00425                     a1 = a[i__3].r;
00426                 }
00427                 if (*k + j <= *m) {
00428                     i__3 = *k + j + (*n - *l + j) * a_dim1;
00429                     a3 = a[i__3].r;
00430                 }
00431 
00432                 i__3 = i__ + (*n - *l + i__) * b_dim1;
00433                 b1 = b[i__3].r;
00434                 i__3 = j + (*n - *l + j) * b_dim1;
00435                 b3 = b[i__3].r;
00436 
00437                 if (upper) {
00438                     if (*k + i__ <= *m) {
00439                         i__3 = *k + i__ + (*n - *l + j) * a_dim1;
00440                         a2.r = a[i__3].r, a2.i = a[i__3].i;
00441                     }
00442                     i__3 = i__ + (*n - *l + j) * b_dim1;
00443                     b2.r = b[i__3].r, b2.i = b[i__3].i;
00444                 } else {
00445                     if (*k + j <= *m) {
00446                         i__3 = *k + j + (*n - *l + i__) * a_dim1;
00447                         a2.r = a[i__3].r, a2.i = a[i__3].i;
00448                     }
00449                     i__3 = j + (*n - *l + i__) * b_dim1;
00450                     b2.r = b[i__3].r, b2.i = b[i__3].i;
00451                 }
00452 
00453                 zlags2_(&upper, &a1, &a2, &a3, &b1, &b2, &b3, &csu, &snu, &
00454                         csv, &snv, &csq, &snq);
00455 
00456 /*              Update (K+I)-th and (K+J)-th rows of matrix A: U'*A */
00457 
00458                 if (*k + j <= *m) {
00459                     d_cnjg(&z__1, &snu);
00460                     zrot_(l, &a[*k + j + (*n - *l + 1) * a_dim1], lda, &a[*k 
00461                             + i__ + (*n - *l + 1) * a_dim1], lda, &csu, &z__1)
00462                             ;
00463                 }
00464 
00465 /*              Update I-th and J-th rows of matrix B: V'*B */
00466 
00467                 d_cnjg(&z__1, &snv);
00468                 zrot_(l, &b[j + (*n - *l + 1) * b_dim1], ldb, &b[i__ + (*n - *
00469                         l + 1) * b_dim1], ldb, &csv, &z__1);
00470 
00471 /*              Update (N-L+I)-th and (N-L+J)-th columns of matrices */
00472 /*              A and B: A*Q and B*Q */
00473 
00474 /* Computing MIN */
00475                 i__4 = *k + *l;
00476                 i__3 = min(i__4,*m);
00477                 zrot_(&i__3, &a[(*n - *l + j) * a_dim1 + 1], &c__1, &a[(*n - *
00478                         l + i__) * a_dim1 + 1], &c__1, &csq, &snq);
00479 
00480                 zrot_(l, &b[(*n - *l + j) * b_dim1 + 1], &c__1, &b[(*n - *l + 
00481                         i__) * b_dim1 + 1], &c__1, &csq, &snq);
00482 
00483                 if (upper) {
00484                     if (*k + i__ <= *m) {
00485                         i__3 = *k + i__ + (*n - *l + j) * a_dim1;
00486                         a[i__3].r = 0., a[i__3].i = 0.;
00487                     }
00488                     i__3 = i__ + (*n - *l + j) * b_dim1;
00489                     b[i__3].r = 0., b[i__3].i = 0.;
00490                 } else {
00491                     if (*k + j <= *m) {
00492                         i__3 = *k + j + (*n - *l + i__) * a_dim1;
00493                         a[i__3].r = 0., a[i__3].i = 0.;
00494                     }
00495                     i__3 = j + (*n - *l + i__) * b_dim1;
00496                     b[i__3].r = 0., b[i__3].i = 0.;
00497                 }
00498 
00499 /*              Ensure that the diagonal elements of A and B are real. */
00500 
00501                 if (*k + i__ <= *m) {
00502                     i__3 = *k + i__ + (*n - *l + i__) * a_dim1;
00503                     i__4 = *k + i__ + (*n - *l + i__) * a_dim1;
00504                     d__1 = a[i__4].r;
00505                     a[i__3].r = d__1, a[i__3].i = 0.;
00506                 }
00507                 if (*k + j <= *m) {
00508                     i__3 = *k + j + (*n - *l + j) * a_dim1;
00509                     i__4 = *k + j + (*n - *l + j) * a_dim1;
00510                     d__1 = a[i__4].r;
00511                     a[i__3].r = d__1, a[i__3].i = 0.;
00512                 }
00513                 i__3 = i__ + (*n - *l + i__) * b_dim1;
00514                 i__4 = i__ + (*n - *l + i__) * b_dim1;
00515                 d__1 = b[i__4].r;
00516                 b[i__3].r = d__1, b[i__3].i = 0.;
00517                 i__3 = j + (*n - *l + j) * b_dim1;
00518                 i__4 = j + (*n - *l + j) * b_dim1;
00519                 d__1 = b[i__4].r;
00520                 b[i__3].r = d__1, b[i__3].i = 0.;
00521 
00522 /*              Update unitary matrices U, V, Q, if desired. */
00523 
00524                 if (wantu && *k + j <= *m) {
00525                     zrot_(m, &u[(*k + j) * u_dim1 + 1], &c__1, &u[(*k + i__) *
00526                              u_dim1 + 1], &c__1, &csu, &snu);
00527                 }
00528 
00529                 if (wantv) {
00530                     zrot_(p, &v[j * v_dim1 + 1], &c__1, &v[i__ * v_dim1 + 1], 
00531                             &c__1, &csv, &snv);
00532                 }
00533 
00534                 if (wantq) {
00535                     zrot_(n, &q[(*n - *l + j) * q_dim1 + 1], &c__1, &q[(*n - *
00536                             l + i__) * q_dim1 + 1], &c__1, &csq, &snq);
00537                 }
00538 
00539 /* L10: */
00540             }
00541 /* L20: */
00542         }
00543 
00544         if (! upper) {
00545 
00546 /*           The matrices A13 and B13 were lower triangular at the start */
00547 /*           of the cycle, and are now upper triangular. */
00548 
00549 /*           Convergence test: test the parallelism of the corresponding */
00550 /*           rows of A and B. */
00551 
00552             error = 0.;
00553 /* Computing MIN */
00554             i__2 = *l, i__3 = *m - *k;
00555             i__1 = min(i__2,i__3);
00556             for (i__ = 1; i__ <= i__1; ++i__) {
00557                 i__2 = *l - i__ + 1;
00558                 zcopy_(&i__2, &a[*k + i__ + (*n - *l + i__) * a_dim1], lda, &
00559                         work[1], &c__1);
00560                 i__2 = *l - i__ + 1;
00561                 zcopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &work[*
00562                         l + 1], &c__1);
00563                 i__2 = *l - i__ + 1;
00564                 zlapll_(&i__2, &work[1], &c__1, &work[*l + 1], &c__1, &ssmin);
00565                 error = max(error,ssmin);
00566 /* L30: */
00567             }
00568 
00569             if (abs(error) <= min(*tola,*tolb)) {
00570                 goto L50;
00571             }
00572         }
00573 
00574 /*        End of cycle loop */
00575 
00576 /* L40: */
00577     }
00578 
00579 /*     The algorithm has not converged after MAXIT cycles. */
00580 
00581     *info = 1;
00582     goto L100;
00583 
00584 L50:
00585 
00586 /*     If ERROR <= MIN(TOLA,TOLB), then the algorithm has converged. */
00587 /*     Compute the generalized singular value pairs (ALPHA, BETA), and */
00588 /*     set the triangular matrix R to array A. */
00589 
00590     i__1 = *k;
00591     for (i__ = 1; i__ <= i__1; ++i__) {
00592         alpha[i__] = 1.;
00593         beta[i__] = 0.;
00594 /* L60: */
00595     }
00596 
00597 /* Computing MIN */
00598     i__2 = *l, i__3 = *m - *k;
00599     i__1 = min(i__2,i__3);
00600     for (i__ = 1; i__ <= i__1; ++i__) {
00601 
00602         i__2 = *k + i__ + (*n - *l + i__) * a_dim1;
00603         a1 = a[i__2].r;
00604         i__2 = i__ + (*n - *l + i__) * b_dim1;
00605         b1 = b[i__2].r;
00606 
00607         if (a1 != 0.) {
00608             gamma = b1 / a1;
00609 
00610             if (gamma < 0.) {
00611                 i__2 = *l - i__ + 1;
00612                 zdscal_(&i__2, &c_b39, &b[i__ + (*n - *l + i__) * b_dim1], 
00613                         ldb);
00614                 if (wantv) {
00615                     zdscal_(p, &c_b39, &v[i__ * v_dim1 + 1], &c__1);
00616                 }
00617             }
00618 
00619             d__1 = abs(gamma);
00620             dlartg_(&d__1, &c_b42, &beta[*k + i__], &alpha[*k + i__], &rwk);
00621 
00622             if (alpha[*k + i__] >= beta[*k + i__]) {
00623                 i__2 = *l - i__ + 1;
00624                 d__1 = 1. / alpha[*k + i__];
00625                 zdscal_(&i__2, &d__1, &a[*k + i__ + (*n - *l + i__) * a_dim1], 
00626                          lda);
00627             } else {
00628                 i__2 = *l - i__ + 1;
00629                 d__1 = 1. / beta[*k + i__];
00630                 zdscal_(&i__2, &d__1, &b[i__ + (*n - *l + i__) * b_dim1], ldb)
00631                         ;
00632                 i__2 = *l - i__ + 1;
00633                 zcopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &a[*k 
00634                         + i__ + (*n - *l + i__) * a_dim1], lda);
00635             }
00636 
00637         } else {
00638             alpha[*k + i__] = 0.;
00639             beta[*k + i__] = 1.;
00640             i__2 = *l - i__ + 1;
00641             zcopy_(&i__2, &b[i__ + (*n - *l + i__) * b_dim1], ldb, &a[*k + 
00642                     i__ + (*n - *l + i__) * a_dim1], lda);
00643         }
00644 /* L70: */
00645     }
00646 
00647 /*     Post-assignment */
00648 
00649     i__1 = *k + *l;
00650     for (i__ = *m + 1; i__ <= i__1; ++i__) {
00651         alpha[i__] = 0.;
00652         beta[i__] = 1.;
00653 /* L80: */
00654     }
00655 
00656     if (*k + *l < *n) {
00657         i__1 = *n;
00658         for (i__ = *k + *l + 1; i__ <= i__1; ++i__) {
00659             alpha[i__] = 0.;
00660             beta[i__] = 0.;
00661 /* L90: */
00662         }
00663     }
00664 
00665 L100:
00666     *ncycle = kcycle;
00667 
00668     return 0;
00669 
00670 /*     End of ZTGSJA */
00671 
00672 } /* ztgsja_ */


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