sqrt01.c
Go to the documentation of this file.
00001 /* sqrt01.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 /* Common Block Declarations */
00017 
00018 struct {
00019     char srnamt[32];
00020 } srnamc_;
00021 
00022 #define srnamc_1 srnamc_
00023 
00024 /* Table of constant values */
00025 
00026 static real c_b6 = -1e10f;
00027 static real c_b11 = 0.f;
00028 static real c_b16 = -1.f;
00029 static real c_b17 = 1.f;
00030 
00031 /* Subroutine */ int sqrt01_(integer *m, integer *n, real *a, real *af, real *
00032         q, real *r__, integer *lda, real *tau, real *work, integer *lwork, 
00033         real *rwork, real *result)
00034 {
00035     /* System generated locals */
00036     integer a_dim1, a_offset, af_dim1, af_offset, q_dim1, q_offset, r_dim1, 
00037             r_offset, i__1;
00038 
00039     /* Builtin functions */
00040     /* Subroutine */ int s_copy(char *, char *, ftnlen, ftnlen);
00041 
00042     /* Local variables */
00043     real eps;
00044     integer info;
00045     real resid;
00046     extern /* Subroutine */ int sgemm_(char *, char *, integer *, integer *, 
00047             integer *, real *, real *, integer *, real *, integer *, real *, 
00048             real *, integer *);
00049     real anorm;
00050     integer minmn;
00051     extern /* Subroutine */ int ssyrk_(char *, char *, integer *, integer *, 
00052             real *, real *, integer *, real *, real *, integer *);
00053     extern doublereal slamch_(char *), slange_(char *, integer *, 
00054             integer *, real *, integer *, real *);
00055     extern /* Subroutine */ int sgeqrf_(integer *, integer *, real *, integer 
00056             *, real *, real *, integer *, integer *), slacpy_(char *, integer 
00057             *, integer *, real *, integer *, real *, integer *), 
00058             slaset_(char *, integer *, integer *, real *, real *, real *, 
00059             integer *);
00060     extern doublereal slansy_(char *, char *, integer *, real *, integer *, 
00061             real *);
00062     extern /* Subroutine */ int sorgqr_(integer *, integer *, integer *, real 
00063             *, integer *, real *, real *, integer *, integer *);
00064 
00065 
00066 /*  -- LAPACK test routine (version 3.1) -- */
00067 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00068 /*     November 2006 */
00069 
00070 /*     .. Scalar Arguments .. */
00071 /*     .. */
00072 /*     .. Array Arguments .. */
00073 /*     .. */
00074 
00075 /*  Purpose */
00076 /*  ======= */
00077 
00078 /*  SQRT01 tests SGEQRF, which computes the QR factorization of an m-by-n */
00079 /*  matrix A, and partially tests SORGQR which forms the m-by-m */
00080 /*  orthogonal matrix Q. */
00081 
00082 /*  SQRT01 compares R with Q'*A, and checks that Q is orthogonal. */
00083 
00084 /*  Arguments */
00085 /*  ========= */
00086 
00087 /*  M       (input) INTEGER */
00088 /*          The number of rows of the matrix A.  M >= 0. */
00089 
00090 /*  N       (input) INTEGER */
00091 /*          The number of columns of the matrix A.  N >= 0. */
00092 
00093 /*  A       (input) REAL array, dimension (LDA,N) */
00094 /*          The m-by-n matrix A. */
00095 
00096 /*  AF      (output) REAL array, dimension (LDA,N) */
00097 /*          Details of the QR factorization of A, as returned by SGEQRF. */
00098 /*          See SGEQRF for further details. */
00099 
00100 /*  Q       (output) REAL array, dimension (LDA,M) */
00101 /*          The m-by-m orthogonal matrix Q. */
00102 
00103 /*  R       (workspace) REAL array, dimension (LDA,max(M,N)) */
00104 
00105 /*  LDA     (input) INTEGER */
00106 /*          The leading dimension of the arrays A, AF, Q and R. */
00107 /*          LDA >= max(M,N). */
00108 
00109 /*  TAU     (output) REAL array, dimension (min(M,N)) */
00110 /*          The scalar factors of the elementary reflectors, as returned */
00111 /*          by SGEQRF. */
00112 
00113 /*  WORK    (workspace) REAL array, dimension (LWORK) */
00114 
00115 /*  LWORK   (input) INTEGER */
00116 /*          The dimension of the array WORK. */
00117 
00118 /*  RWORK   (workspace) REAL array, dimension (M) */
00119 
00120 /*  RESULT  (output) REAL array, dimension (2) */
00121 /*          The test ratios: */
00122 /*          RESULT(1) = norm( R - Q'*A ) / ( M * norm(A) * EPS ) */
00123 /*          RESULT(2) = norm( I - Q'*Q ) / ( M * EPS ) */
00124 
00125 /*  ===================================================================== */
00126 
00127 /*     .. Parameters .. */
00128 /*     .. */
00129 /*     .. Local Scalars .. */
00130 /*     .. */
00131 /*     .. External Functions .. */
00132 /*     .. */
00133 /*     .. External Subroutines .. */
00134 /*     .. */
00135 /*     .. Intrinsic Functions .. */
00136 /*     .. */
00137 /*     .. Scalars in Common .. */
00138 /*     .. */
00139 /*     .. Common blocks .. */
00140 /*     .. */
00141 /*     .. Executable Statements .. */
00142 
00143     /* Parameter adjustments */
00144     r_dim1 = *lda;
00145     r_offset = 1 + r_dim1;
00146     r__ -= r_offset;
00147     q_dim1 = *lda;
00148     q_offset = 1 + q_dim1;
00149     q -= q_offset;
00150     af_dim1 = *lda;
00151     af_offset = 1 + af_dim1;
00152     af -= af_offset;
00153     a_dim1 = *lda;
00154     a_offset = 1 + a_dim1;
00155     a -= a_offset;
00156     --tau;
00157     --work;
00158     --rwork;
00159     --result;
00160 
00161     /* Function Body */
00162     minmn = min(*m,*n);
00163     eps = slamch_("Epsilon");
00164 
00165 /*     Copy the matrix A to the array AF. */
00166 
00167     slacpy_("Full", m, n, &a[a_offset], lda, &af[af_offset], lda);
00168 
00169 /*     Factorize the matrix A in the array AF. */
00170 
00171     s_copy(srnamc_1.srnamt, "SGEQRF", (ftnlen)32, (ftnlen)6);
00172     sgeqrf_(m, n, &af[af_offset], lda, &tau[1], &work[1], lwork, &info);
00173 
00174 /*     Copy details of Q */
00175 
00176     slaset_("Full", m, m, &c_b6, &c_b6, &q[q_offset], lda);
00177     i__1 = *m - 1;
00178     slacpy_("Lower", &i__1, n, &af[af_dim1 + 2], lda, &q[q_dim1 + 2], lda);
00179 
00180 /*     Generate the m-by-m matrix Q */
00181 
00182     s_copy(srnamc_1.srnamt, "SORGQR", (ftnlen)32, (ftnlen)6);
00183     sorgqr_(m, m, &minmn, &q[q_offset], lda, &tau[1], &work[1], lwork, &info);
00184 
00185 /*     Copy R */
00186 
00187     slaset_("Full", m, n, &c_b11, &c_b11, &r__[r_offset], lda);
00188     slacpy_("Upper", m, n, &af[af_offset], lda, &r__[r_offset], lda);
00189 
00190 /*     Compute R - Q'*A */
00191 
00192     sgemm_("Transpose", "No transpose", m, n, m, &c_b16, &q[q_offset], lda, &
00193             a[a_offset], lda, &c_b17, &r__[r_offset], lda);
00194 
00195 /*     Compute norm( R - Q'*A ) / ( M * norm(A) * EPS ) . */
00196 
00197     anorm = slange_("1", m, n, &a[a_offset], lda, &rwork[1]);
00198     resid = slange_("1", m, n, &r__[r_offset], lda, &rwork[1]);
00199     if (anorm > 0.f) {
00200         result[1] = resid / (real) max(1,*m) / anorm / eps;
00201     } else {
00202         result[1] = 0.f;
00203     }
00204 
00205 /*     Compute I - Q'*Q */
00206 
00207     slaset_("Full", m, m, &c_b11, &c_b17, &r__[r_offset], lda);
00208     ssyrk_("Upper", "Transpose", m, m, &c_b16, &q[q_offset], lda, &c_b17, &
00209             r__[r_offset], lda);
00210 
00211 /*     Compute norm( I - Q'*Q ) / ( M * EPS ) . */
00212 
00213     resid = slansy_("1", "Upper", m, &r__[r_offset], lda, &rwork[1]);
00214 
00215     result[2] = resid / (real) max(1,*m) / eps;
00216 
00217     return 0;
00218 
00219 /*     End of SQRT01 */
00220 
00221 } /* sqrt01_ */


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