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


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