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


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