dgsvts.c
Go to the documentation of this file.
00001 /* dgsvts.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_b17 = 1.;
00019 static doublereal c_b18 = 0.;
00020 static doublereal c_b44 = -1.;
00021 static integer c__1 = 1;
00022 
00023 /* Subroutine */ int dgsvts_(integer *m, integer *p, integer *n, doublereal *
00024         a, doublereal *af, integer *lda, doublereal *b, doublereal *bf, 
00025         integer *ldb, doublereal *u, integer *ldu, doublereal *v, integer *
00026         ldv, doublereal *q, integer *ldq, doublereal *alpha, doublereal *beta, 
00027          doublereal *r__, integer *ldr, integer *iwork, doublereal *work, 
00028         integer *lwork, doublereal *rwork, doublereal *result)
00029 {
00030     /* System generated locals */
00031     integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, bf_dim1, 
00032             bf_offset, q_dim1, q_offset, r_dim1, r_offset, u_dim1, u_offset, 
00033             v_dim1, v_offset, i__1, i__2;
00034     doublereal d__1;
00035 
00036     /* Local variables */
00037     integer i__, j, k, l;
00038     doublereal ulp;
00039     integer info;
00040     doublereal unfl, temp;
00041     extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *, 
00042             integer *, doublereal *, doublereal *, integer *, doublereal *, 
00043             integer *, doublereal *, doublereal *, integer *);
00044     doublereal resid, anorm, bnorm;
00045     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, 
00046             doublereal *, integer *), dsyrk_(char *, char *, integer *, 
00047             integer *, doublereal *, doublereal *, integer *, doublereal *, 
00048             doublereal *, integer *);
00049     extern doublereal dlamch_(char *), dlange_(char *, integer *, 
00050             integer *, doublereal *, integer *, doublereal *);
00051     extern /* Subroutine */ int dlacpy_(char *, integer *, integer *, 
00052             doublereal *, integer *, doublereal *, integer *), 
00053             dlaset_(char *, integer *, integer *, doublereal *, doublereal *, 
00054             doublereal *, integer *), dggsvd_(char *, char *, char *, 
00055             integer *, integer *, integer *, integer *, integer *, doublereal 
00056             *, integer *, doublereal *, integer *, doublereal *, doublereal *, 
00057              doublereal *, integer *, doublereal *, integer *, doublereal *, 
00058             integer *, doublereal *, integer *, integer *);
00059     extern doublereal dlansy_(char *, char *, integer *, doublereal *, 
00060             integer *, doublereal *);
00061     doublereal ulpinv;
00062 
00063 
00064 /*  -- LAPACK test routine (version 3.1) -- */
00065 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00066 /*     November 2006 */
00067 
00068 /*     .. Scalar Arguments .. */
00069 /*     .. */
00070 /*     .. Array Arguments .. */
00071 /*     .. */
00072 
00073 /*  Purpose */
00074 /*  ======= */
00075 
00076 /*  DGSVTS tests DGGSVD, which computes the GSVD of an M-by-N matrix A */
00077 /*  and a P-by-N matrix B: */
00078 /*               U'*A*Q = D1*R and V'*B*Q = D2*R. */
00079 
00080 /*  Arguments */
00081 /*  ========= */
00082 
00083 /*  M       (input) INTEGER */
00084 /*          The number of rows of the matrix A.  M >= 0. */
00085 
00086 /*  P       (input) INTEGER */
00087 /*          The number of rows of the matrix B.  P >= 0. */
00088 
00089 /*  N       (input) INTEGER */
00090 /*          The number of columns of the matrices A and B.  N >= 0. */
00091 
00092 /*  A       (input) DOUBLE PRECISION array, dimension (LDA,M) */
00093 /*          The M-by-N matrix A. */
00094 
00095 /*  AF      (output) DOUBLE PRECISION array, dimension (LDA,N) */
00096 /*          Details of the GSVD of A and B, as returned by DGGSVD, */
00097 /*          see DGGSVD for further details. */
00098 
00099 /*  LDA     (input) INTEGER */
00100 /*          The leading dimension of the arrays A and AF. */
00101 /*          LDA >= max( 1,M ). */
00102 
00103 /*  B       (input) DOUBLE PRECISION array, dimension (LDB,P) */
00104 /*          On entry, the P-by-N matrix B. */
00105 
00106 /*  BF      (output) DOUBLE PRECISION array, dimension (LDB,N) */
00107 /*          Details of the GSVD of A and B, as returned by DGGSVD, */
00108 /*          see DGGSVD for further details. */
00109 
00110 /*  LDB     (input) INTEGER */
00111 /*          The leading dimension of the arrays B and BF. */
00112 /*          LDB >= max(1,P). */
00113 
00114 /*  U       (output) DOUBLE PRECISION array, dimension(LDU,M) */
00115 /*          The M by M orthogonal matrix U. */
00116 
00117 /*  LDU     (input) INTEGER */
00118 /*          The leading dimension of the array U. LDU >= max(1,M). */
00119 
00120 /*  V       (output) DOUBLE PRECISION array, dimension(LDV,M) */
00121 /*          The P by P orthogonal matrix V. */
00122 
00123 /*  LDV     (input) INTEGER */
00124 /*          The leading dimension of the array V. LDV >= max(1,P). */
00125 
00126 /*  Q       (output) DOUBLE PRECISION array, dimension(LDQ,N) */
00127 /*          The N by N orthogonal matrix Q. */
00128 
00129 /*  LDQ     (input) INTEGER */
00130 /*          The leading dimension of the array Q. LDQ >= max(1,N). */
00131 
00132 /*  ALPHA   (output) DOUBLE PRECISION array, dimension (N) */
00133 /*  BETA    (output) DOUBLE PRECISION array, dimension (N) */
00134 /*          The generalized singular value pairs of A and B, the */
00135 /*          ``diagonal'' matrices D1 and D2 are constructed from */
00136 /*          ALPHA and BETA, see subroutine DGGSVD for details. */
00137 
00138 /*  R       (output) DOUBLE PRECISION array, dimension(LDQ,N) */
00139 /*          The upper triangular matrix R. */
00140 
00141 /*  LDR     (input) INTEGER */
00142 /*          The leading dimension of the array R. LDR >= max(1,N). */
00143 
00144 /*  IWORK   (workspace) INTEGER array, dimension (N) */
00145 
00146 /*  WORK    (workspace) DOUBLE PRECISION array, dimension (LWORK) */
00147 
00148 /*  LWORK   (input) INTEGER */
00149 /*          The dimension of the array WORK, */
00150 /*          LWORK >= max(M,P,N)*max(M,P,N). */
00151 
00152 /*  RWORK   (workspace) DOUBLE PRECISION array, dimension (max(M,P,N)) */
00153 
00154 /*  RESULT  (output) DOUBLE PRECISION array, dimension (6) */
00155 /*          The test ratios: */
00156 /*          RESULT(1) = norm( U'*A*Q - D1*R ) / ( MAX(M,N)*norm(A)*ULP) */
00157 /*          RESULT(2) = norm( V'*B*Q - D2*R ) / ( MAX(P,N)*norm(B)*ULP) */
00158 /*          RESULT(3) = norm( I - U'*U ) / ( M*ULP ) */
00159 /*          RESULT(4) = norm( I - V'*V ) / ( P*ULP ) */
00160 /*          RESULT(5) = norm( I - Q'*Q ) / ( N*ULP ) */
00161 /*          RESULT(6) = 0        if ALPHA is in decreasing order; */
00162 /*                    = ULPINV   otherwise. */
00163 
00164 /*  ===================================================================== */
00165 
00166 /*     .. Parameters .. */
00167 /*     .. */
00168 /*     .. Local Scalars .. */
00169 /*     .. */
00170 /*     .. External Functions .. */
00171 /*     .. */
00172 /*     .. External Subroutines .. */
00173 /*     .. */
00174 /*     .. Intrinsic Functions .. */
00175 /*     .. */
00176 /*     .. Executable Statements .. */
00177 
00178     /* Parameter adjustments */
00179     af_dim1 = *lda;
00180     af_offset = 1 + af_dim1;
00181     af -= af_offset;
00182     a_dim1 = *lda;
00183     a_offset = 1 + a_dim1;
00184     a -= a_offset;
00185     bf_dim1 = *ldb;
00186     bf_offset = 1 + bf_dim1;
00187     bf -= bf_offset;
00188     b_dim1 = *ldb;
00189     b_offset = 1 + b_dim1;
00190     b -= b_offset;
00191     u_dim1 = *ldu;
00192     u_offset = 1 + u_dim1;
00193     u -= u_offset;
00194     v_dim1 = *ldv;
00195     v_offset = 1 + v_dim1;
00196     v -= v_offset;
00197     q_dim1 = *ldq;
00198     q_offset = 1 + q_dim1;
00199     q -= q_offset;
00200     --alpha;
00201     --beta;
00202     r_dim1 = *ldr;
00203     r_offset = 1 + r_dim1;
00204     r__ -= r_offset;
00205     --iwork;
00206     --work;
00207     --rwork;
00208     --result;
00209 
00210     /* Function Body */
00211     ulp = dlamch_("Precision");
00212     ulpinv = 1. / ulp;
00213     unfl = dlamch_("Safe minimum");
00214 
00215 /*     Copy the matrix A to the array AF. */
00216 
00217     dlacpy_("Full", m, n, &a[a_offset], lda, &af[af_offset], lda);
00218     dlacpy_("Full", p, n, &b[b_offset], ldb, &bf[bf_offset], ldb);
00219 
00220 /* Computing MAX */
00221     d__1 = dlange_("1", m, n, &a[a_offset], lda, &rwork[1]);
00222     anorm = max(d__1,unfl);
00223 /* Computing MAX */
00224     d__1 = dlange_("1", p, n, &b[b_offset], ldb, &rwork[1]);
00225     bnorm = max(d__1,unfl);
00226 
00227 /*     Factorize the matrices A and B in the arrays AF and BF. */
00228 
00229     dggsvd_("U", "V", "Q", m, n, p, &k, &l, &af[af_offset], lda, &bf[
00230             bf_offset], ldb, &alpha[1], &beta[1], &u[u_offset], ldu, &v[
00231             v_offset], ldv, &q[q_offset], ldq, &work[1], &iwork[1], &info);
00232 
00233 /*     Copy R */
00234 
00235 /* Computing MIN */
00236     i__2 = k + l;
00237     i__1 = min(i__2,*m);
00238     for (i__ = 1; i__ <= i__1; ++i__) {
00239         i__2 = k + l;
00240         for (j = i__; j <= i__2; ++j) {
00241             r__[i__ + j * r_dim1] = af[i__ + (*n - k - l + j) * af_dim1];
00242 /* L10: */
00243         }
00244 /* L20: */
00245     }
00246 
00247     if (*m - k - l < 0) {
00248         i__1 = k + l;
00249         for (i__ = *m + 1; i__ <= i__1; ++i__) {
00250             i__2 = k + l;
00251             for (j = i__; j <= i__2; ++j) {
00252                 r__[i__ + j * r_dim1] = bf[i__ - k + (*n - k - l + j) * 
00253                         bf_dim1];
00254 /* L30: */
00255             }
00256 /* L40: */
00257         }
00258     }
00259 
00260 /*     Compute A:= U'*A*Q - D1*R */
00261 
00262     dgemm_("No transpose", "No transpose", m, n, n, &c_b17, &a[a_offset], lda, 
00263              &q[q_offset], ldq, &c_b18, &work[1], lda)
00264             ;
00265 
00266     dgemm_("Transpose", "No transpose", m, n, m, &c_b17, &u[u_offset], ldu, &
00267             work[1], lda, &c_b18, &a[a_offset], lda);
00268 
00269     i__1 = k;
00270     for (i__ = 1; i__ <= i__1; ++i__) {
00271         i__2 = k + l;
00272         for (j = i__; j <= i__2; ++j) {
00273             a[i__ + (*n - k - l + j) * a_dim1] -= r__[i__ + j * r_dim1];
00274 /* L50: */
00275         }
00276 /* L60: */
00277     }
00278 
00279 /* Computing MIN */
00280     i__2 = k + l;
00281     i__1 = min(i__2,*m);
00282     for (i__ = k + 1; i__ <= i__1; ++i__) {
00283         i__2 = k + l;
00284         for (j = i__; j <= i__2; ++j) {
00285             a[i__ + (*n - k - l + j) * a_dim1] -= alpha[i__] * r__[i__ + j * 
00286                     r_dim1];
00287 /* L70: */
00288         }
00289 /* L80: */
00290     }
00291 
00292 /*     Compute norm( U'*A*Q - D1*R ) / ( MAX(1,M,N)*norm(A)*ULP ) . */
00293 
00294     resid = dlange_("1", m, n, &a[a_offset], lda, &rwork[1]);
00295 
00296     if (anorm > 0.) {
00297 /* Computing MAX */
00298         i__1 = max(1,*m);
00299         result[1] = resid / (doublereal) max(i__1,*n) / anorm / ulp;
00300     } else {
00301         result[1] = 0.;
00302     }
00303 
00304 /*     Compute B := V'*B*Q - D2*R */
00305 
00306     dgemm_("No transpose", "No transpose", p, n, n, &c_b17, &b[b_offset], ldb, 
00307              &q[q_offset], ldq, &c_b18, &work[1], ldb)
00308             ;
00309 
00310     dgemm_("Transpose", "No transpose", p, n, p, &c_b17, &v[v_offset], ldv, &
00311             work[1], ldb, &c_b18, &b[b_offset], ldb);
00312 
00313     i__1 = l;
00314     for (i__ = 1; i__ <= i__1; ++i__) {
00315         i__2 = l;
00316         for (j = i__; j <= i__2; ++j) {
00317             b[i__ + (*n - l + j) * b_dim1] -= beta[k + i__] * r__[k + i__ + (
00318                     k + j) * r_dim1];
00319 /* L90: */
00320         }
00321 /* L100: */
00322     }
00323 
00324 /*     Compute norm( V'*B*Q - D2*R ) / ( MAX(P,N)*norm(B)*ULP ) . */
00325 
00326     resid = dlange_("1", p, n, &b[b_offset], ldb, &rwork[1]);
00327     if (bnorm > 0.) {
00328 /* Computing MAX */
00329         i__1 = max(1,*p);
00330         result[2] = resid / (doublereal) max(i__1,*n) / bnorm / ulp;
00331     } else {
00332         result[2] = 0.;
00333     }
00334 
00335 /*     Compute I - U'*U */
00336 
00337     dlaset_("Full", m, m, &c_b18, &c_b17, &work[1], ldq);
00338     dsyrk_("Upper", "Transpose", m, m, &c_b44, &u[u_offset], ldu, &c_b17, &
00339             work[1], ldu);
00340 
00341 /*     Compute norm( I - U'*U ) / ( M * ULP ) . */
00342 
00343     resid = dlansy_("1", "Upper", m, &work[1], ldu, &rwork[1]);
00344     result[3] = resid / (doublereal) max(1,*m) / ulp;
00345 
00346 /*     Compute I - V'*V */
00347 
00348     dlaset_("Full", p, p, &c_b18, &c_b17, &work[1], ldv);
00349     dsyrk_("Upper", "Transpose", p, p, &c_b44, &v[v_offset], ldv, &c_b17, &
00350             work[1], ldv);
00351 
00352 /*     Compute norm( I - V'*V ) / ( P * ULP ) . */
00353 
00354     resid = dlansy_("1", "Upper", p, &work[1], ldv, &rwork[1]);
00355     result[4] = resid / (doublereal) max(1,*p) / ulp;
00356 
00357 /*     Compute I - Q'*Q */
00358 
00359     dlaset_("Full", n, n, &c_b18, &c_b17, &work[1], ldq);
00360     dsyrk_("Upper", "Transpose", n, n, &c_b44, &q[q_offset], ldq, &c_b17, &
00361             work[1], ldq);
00362 
00363 /*     Compute norm( I - Q'*Q ) / ( N * ULP ) . */
00364 
00365     resid = dlansy_("1", "Upper", n, &work[1], ldq, &rwork[1]);
00366     result[5] = resid / (doublereal) max(1,*n) / ulp;
00367 
00368 /*     Check sorting */
00369 
00370     dcopy_(n, &alpha[1], &c__1, &work[1], &c__1);
00371 /* Computing MIN */
00372     i__2 = k + l;
00373     i__1 = min(i__2,*m);
00374     for (i__ = k + 1; i__ <= i__1; ++i__) {
00375         j = iwork[i__];
00376         if (i__ != j) {
00377             temp = work[i__];
00378             work[i__] = work[j];
00379             work[j] = temp;
00380         }
00381 /* L110: */
00382     }
00383 
00384     result[6] = 0.;
00385 /* Computing MIN */
00386     i__2 = k + l;
00387     i__1 = min(i__2,*m) - 1;
00388     for (i__ = k + 1; i__ <= i__1; ++i__) {
00389         if (work[i__] < work[i__ + 1]) {
00390             result[6] = ulpinv;
00391         }
00392 /* L120: */
00393     }
00394 
00395     return 0;
00396 
00397 /*     End of DGSVTS */
00398 
00399 } /* dgsvts_ */


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