sgqrts.c
Go to the documentation of this file.
00001 /* sgqrts.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_b9 = -1e10f;
00019 static real c_b19 = 0.f;
00020 static real c_b30 = -1.f;
00021 static real c_b31 = 1.f;
00022 
00023 /* Subroutine */ int sgqrts_(integer *n, integer *m, integer *p, real *a, 
00024         real *af, real *q, real *r__, integer *lda, real *taua, real *b, real 
00025         *bf, real *z__, real *t, real *bwk, integer *ldb, real *taub, real *
00026         work, integer *lwork, real *rwork, real *result)
00027 {
00028     /* System generated locals */
00029     integer a_dim1, a_offset, af_dim1, af_offset, r_dim1, r_offset, q_dim1, 
00030             q_offset, b_dim1, b_offset, bf_dim1, bf_offset, t_dim1, t_offset, 
00031             z_dim1, z_offset, bwk_dim1, bwk_offset, i__1, i__2;
00032     real r__1;
00033 
00034     /* Local variables */
00035     real ulp;
00036     integer info;
00037     real unfl, resid;
00038     extern /* Subroutine */ int sgemm_(char *, char *, integer *, integer *, 
00039             integer *, real *, real *, integer *, real *, integer *, real *, 
00040             real *, integer *);
00041     real anorm, bnorm;
00042     extern /* Subroutine */ int ssyrk_(char *, char *, integer *, integer *, 
00043             real *, real *, integer *, real *, real *, integer *);
00044     extern doublereal slamch_(char *), slange_(char *, integer *, 
00045             integer *, real *, integer *, real *);
00046     extern /* Subroutine */ int sggqrf_(integer *, integer *, integer *, real 
00047             *, integer *, real *, real *, integer *, real *, real *, integer *
00048 , integer *), slacpy_(char *, integer *, integer *, real *, 
00049             integer *, real *, integer *), slaset_(char *, integer *, 
00050             integer *, real *, real *, real *, integer *);
00051     extern doublereal slansy_(char *, char *, integer *, real *, integer *, 
00052             real *);
00053     extern /* Subroutine */ int sorgqr_(integer *, integer *, integer *, real 
00054             *, integer *, real *, real *, integer *, integer *), sorgrq_(
00055             integer *, integer *, integer *, real *, integer *, real *, real *
00056 , integer *, integer *);
00057 
00058 
00059 /*  -- LAPACK test routine (version 3.1) -- */
00060 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00061 /*     November 2006 */
00062 
00063 /*     .. Scalar Arguments .. */
00064 /*     .. */
00065 /*     .. Array Arguments .. */
00066 /*     .. */
00067 
00068 /*  Purpose */
00069 /*  ======= */
00070 
00071 /*  SGQRTS tests SGGQRF, which computes the GQR factorization of an */
00072 /*  N-by-M matrix A and a N-by-P matrix B: A = Q*R and B = Q*T*Z. */
00073 
00074 /*  Arguments */
00075 /*  ========= */
00076 
00077 /*  N       (input) INTEGER */
00078 /*          The number of rows of the matrices A and B.  N >= 0. */
00079 
00080 /*  M       (input) INTEGER */
00081 /*          The number of columns of the matrix A.  M >= 0. */
00082 
00083 /*  P       (input) INTEGER */
00084 /*          The number of columns of the matrix B.  P >= 0. */
00085 
00086 /*  A       (input) REAL array, dimension (LDA,M) */
00087 /*          The N-by-M matrix A. */
00088 
00089 /*  AF      (output) REAL array, dimension (LDA,N) */
00090 /*          Details of the GQR factorization of A and B, as returned */
00091 /*          by SGGQRF, see SGGQRF for further details. */
00092 
00093 /*  Q       (output) REAL array, dimension (LDA,N) */
00094 /*          The M-by-M orthogonal matrix Q. */
00095 
00096 /*  R       (workspace) REAL array, dimension (LDA,MAX(M,N)) */
00097 
00098 /*  LDA     (input) INTEGER */
00099 /*          The leading dimension of the arrays A, AF, R and Q. */
00100 /*          LDA >= max(M,N). */
00101 
00102 /*  TAUA    (output) REAL array, dimension (min(M,N)) */
00103 /*          The scalar factors of the elementary reflectors, as returned */
00104 /*          by SGGQRF. */
00105 
00106 /*  B       (input) REAL array, dimension (LDB,P) */
00107 /*          On entry, the N-by-P matrix A. */
00108 
00109 /*  BF      (output) REAL array, dimension (LDB,N) */
00110 /*          Details of the GQR factorization of A and B, as returned */
00111 /*          by SGGQRF, see SGGQRF for further details. */
00112 
00113 /*  Z       (output) REAL array, dimension (LDB,P) */
00114 /*          The P-by-P orthogonal matrix Z. */
00115 
00116 /*  T       (workspace) REAL array, dimension (LDB,max(P,N)) */
00117 
00118 /*  BWK     (workspace) REAL array, dimension (LDB,N) */
00119 
00120 /*  LDB     (input) INTEGER */
00121 /*          The leading dimension of the arrays B, BF, Z and T. */
00122 /*          LDB >= max(P,N). */
00123 
00124 /*  TAUB    (output) REAL array, dimension (min(P,N)) */
00125 /*          The scalar factors of the elementary reflectors, as returned */
00126 /*          by SGGRQF. */
00127 
00128 /*  WORK    (workspace) REAL array, dimension (LWORK) */
00129 
00130 /*  LWORK   (input) INTEGER */
00131 /*          The dimension of the array WORK, LWORK >= max(N,M,P)**2. */
00132 
00133 /*  RWORK   (workspace) REAL array, dimension (max(N,M,P)) */
00134 
00135 /*  RESULT  (output) REAL array, dimension (4) */
00136 /*          The test ratios: */
00137 /*            RESULT(1) = norm( R - Q'*A ) / ( MAX(M,N)*norm(A)*ULP) */
00138 /*            RESULT(2) = norm( T*Z - Q'*B ) / (MAX(P,N)*norm(B)*ULP) */
00139 /*            RESULT(3) = norm( I - Q'*Q ) / ( M*ULP ) */
00140 /*            RESULT(4) = norm( I - Z'*Z ) / ( P*ULP ) */
00141 
00142 /*  ===================================================================== */
00143 
00144 /*     .. Parameters .. */
00145 /*     .. */
00146 /*     .. Local Scalars .. */
00147 /*     .. */
00148 /*     .. External Functions .. */
00149 /*     .. */
00150 /*     .. External Subroutines .. */
00151 /*     .. */
00152 /*     .. Intrinsic Functions .. */
00153 /*     .. */
00154 /*     .. Executable Statements .. */
00155 
00156     /* Parameter adjustments */
00157     r_dim1 = *lda;
00158     r_offset = 1 + r_dim1;
00159     r__ -= r_offset;
00160     q_dim1 = *lda;
00161     q_offset = 1 + q_dim1;
00162     q -= q_offset;
00163     af_dim1 = *lda;
00164     af_offset = 1 + af_dim1;
00165     af -= af_offset;
00166     a_dim1 = *lda;
00167     a_offset = 1 + a_dim1;
00168     a -= a_offset;
00169     --taua;
00170     bwk_dim1 = *ldb;
00171     bwk_offset = 1 + bwk_dim1;
00172     bwk -= bwk_offset;
00173     t_dim1 = *ldb;
00174     t_offset = 1 + t_dim1;
00175     t -= t_offset;
00176     z_dim1 = *ldb;
00177     z_offset = 1 + z_dim1;
00178     z__ -= z_offset;
00179     bf_dim1 = *ldb;
00180     bf_offset = 1 + bf_dim1;
00181     bf -= bf_offset;
00182     b_dim1 = *ldb;
00183     b_offset = 1 + b_dim1;
00184     b -= b_offset;
00185     --taub;
00186     --work;
00187     --rwork;
00188     --result;
00189 
00190     /* Function Body */
00191     ulp = slamch_("Precision");
00192     unfl = slamch_("Safe minimum");
00193 
00194 /*     Copy the matrix A to the array AF. */
00195 
00196     slacpy_("Full", n, m, &a[a_offset], lda, &af[af_offset], lda);
00197     slacpy_("Full", n, p, &b[b_offset], ldb, &bf[bf_offset], ldb);
00198 
00199 /* Computing MAX */
00200     r__1 = slange_("1", n, m, &a[a_offset], lda, &rwork[1]);
00201     anorm = dmax(r__1,unfl);
00202 /* Computing MAX */
00203     r__1 = slange_("1", n, p, &b[b_offset], ldb, &rwork[1]);
00204     bnorm = dmax(r__1,unfl);
00205 
00206 /*     Factorize the matrices A and B in the arrays AF and BF. */
00207 
00208     sggqrf_(n, m, p, &af[af_offset], lda, &taua[1], &bf[bf_offset], ldb, &
00209             taub[1], &work[1], lwork, &info);
00210 
00211 /*     Generate the N-by-N matrix Q */
00212 
00213     slaset_("Full", n, n, &c_b9, &c_b9, &q[q_offset], lda);
00214     i__1 = *n - 1;
00215     slacpy_("Lower", &i__1, m, &af[af_dim1 + 2], lda, &q[q_dim1 + 2], lda);
00216     i__1 = min(*n,*m);
00217     sorgqr_(n, n, &i__1, &q[q_offset], lda, &taua[1], &work[1], lwork, &info);
00218 
00219 /*     Generate the P-by-P matrix Z */
00220 
00221     slaset_("Full", p, p, &c_b9, &c_b9, &z__[z_offset], ldb);
00222     if (*n <= *p) {
00223         if (*n > 0 && *n < *p) {
00224             i__1 = *p - *n;
00225             slacpy_("Full", n, &i__1, &bf[bf_offset], ldb, &z__[*p - *n + 1 + 
00226                     z_dim1], ldb);
00227         }
00228         if (*n > 1) {
00229             i__1 = *n - 1;
00230             i__2 = *n - 1;
00231             slacpy_("Lower", &i__1, &i__2, &bf[(*p - *n + 1) * bf_dim1 + 2], 
00232                     ldb, &z__[*p - *n + 2 + (*p - *n + 1) * z_dim1], ldb);
00233         }
00234     } else {
00235         if (*p > 1) {
00236             i__1 = *p - 1;
00237             i__2 = *p - 1;
00238             slacpy_("Lower", &i__1, &i__2, &bf[*n - *p + 2 + bf_dim1], ldb, &
00239                     z__[z_dim1 + 2], ldb);
00240         }
00241     }
00242     i__1 = min(*n,*p);
00243     sorgrq_(p, p, &i__1, &z__[z_offset], ldb, &taub[1], &work[1], lwork, &
00244             info);
00245 
00246 /*     Copy R */
00247 
00248     slaset_("Full", n, m, &c_b19, &c_b19, &r__[r_offset], lda);
00249     slacpy_("Upper", n, m, &af[af_offset], lda, &r__[r_offset], lda);
00250 
00251 /*     Copy T */
00252 
00253     slaset_("Full", n, p, &c_b19, &c_b19, &t[t_offset], ldb);
00254     if (*n <= *p) {
00255         slacpy_("Upper", n, n, &bf[(*p - *n + 1) * bf_dim1 + 1], ldb, &t[(*p 
00256                 - *n + 1) * t_dim1 + 1], ldb);
00257     } else {
00258         i__1 = *n - *p;
00259         slacpy_("Full", &i__1, p, &bf[bf_offset], ldb, &t[t_offset], ldb);
00260         slacpy_("Upper", p, p, &bf[*n - *p + 1 + bf_dim1], ldb, &t[*n - *p + 
00261                 1 + t_dim1], ldb);
00262     }
00263 
00264 /*     Compute R - Q'*A */
00265 
00266     sgemm_("Transpose", "No transpose", n, m, n, &c_b30, &q[q_offset], lda, &
00267             a[a_offset], lda, &c_b31, &r__[r_offset], lda);
00268 
00269 /*     Compute norm( R - Q'*A ) / ( MAX(M,N)*norm(A)*ULP ) . */
00270 
00271     resid = slange_("1", n, m, &r__[r_offset], lda, &rwork[1]);
00272     if (anorm > 0.f) {
00273 /* Computing MAX */
00274         i__1 = max(1,*m);
00275         result[1] = resid / (real) max(i__1,*n) / anorm / ulp;
00276     } else {
00277         result[1] = 0.f;
00278     }
00279 
00280 /*     Compute T*Z - Q'*B */
00281 
00282     sgemm_("No Transpose", "No transpose", n, p, p, &c_b31, &t[t_offset], ldb, 
00283              &z__[z_offset], ldb, &c_b19, &bwk[bwk_offset], ldb);
00284     sgemm_("Transpose", "No transpose", n, p, n, &c_b30, &q[q_offset], lda, &
00285             b[b_offset], ldb, &c_b31, &bwk[bwk_offset], ldb);
00286 
00287 /*     Compute norm( T*Z - Q'*B ) / ( MAX(P,N)*norm(A)*ULP ) . */
00288 
00289     resid = slange_("1", n, p, &bwk[bwk_offset], ldb, &rwork[1]);
00290     if (bnorm > 0.f) {
00291 /* Computing MAX */
00292         i__1 = max(1,*p);
00293         result[2] = resid / (real) max(i__1,*n) / bnorm / ulp;
00294     } else {
00295         result[2] = 0.f;
00296     }
00297 
00298 /*     Compute I - Q'*Q */
00299 
00300     slaset_("Full", n, n, &c_b19, &c_b31, &r__[r_offset], lda);
00301     ssyrk_("Upper", "Transpose", n, n, &c_b30, &q[q_offset], lda, &c_b31, &
00302             r__[r_offset], lda);
00303 
00304 /*     Compute norm( I - Q'*Q ) / ( N * ULP ) . */
00305 
00306     resid = slansy_("1", "Upper", n, &r__[r_offset], lda, &rwork[1]);
00307     result[3] = resid / (real) max(1,*n) / ulp;
00308 
00309 /*     Compute I - Z'*Z */
00310 
00311     slaset_("Full", p, p, &c_b19, &c_b31, &t[t_offset], ldb);
00312     ssyrk_("Upper", "Transpose", p, p, &c_b30, &z__[z_offset], ldb, &c_b31, &
00313             t[t_offset], ldb);
00314 
00315 /*     Compute norm( I - Z'*Z ) / ( P*ULP ) . */
00316 
00317     resid = slansy_("1", "Upper", p, &t[t_offset], ldb, &rwork[1]);
00318     result[4] = resid / (real) max(1,*p) / ulp;
00319 
00320     return 0;
00321 
00322 /*     End of SGQRTS */
00323 
00324 } /* sgqrts_ */


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