sqpt01.c
Go to the documentation of this file.
00001 /* sqpt01.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 integer c__10 = 10;
00019 static integer c__1 = 1;
00020 static real c_b14 = -1.f;
00021 
00022 doublereal sqpt01_(integer *m, integer *n, integer *k, real *a, real *af, 
00023         integer *lda, real *tau, integer *jpvt, real *work, integer *lwork)
00024 {
00025     /* System generated locals */
00026     integer a_dim1, a_offset, af_dim1, af_offset, i__1, i__2;
00027     real ret_val;
00028 
00029     /* Local variables */
00030     integer i__, j, info;
00031     real norma;
00032     extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, 
00033             integer *);
00034     real rwork[1];
00035     extern /* Subroutine */ int saxpy_(integer *, real *, real *, integer *, 
00036             real *, integer *);
00037     extern doublereal slamch_(char *), slange_(char *, integer *, 
00038             integer *, real *, integer *, real *);
00039     extern /* Subroutine */ int xerbla_(char *, integer *), sormqr_(
00040             char *, char *, integer *, integer *, integer *, real *, integer *
00041 , real *, real *, integer *, real *, integer *, integer *);
00042 
00043 
00044 /*  -- LAPACK test routine (version 3.1) -- */
00045 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00046 /*     November 2006 */
00047 
00048 /*     .. Scalar Arguments .. */
00049 /*     .. */
00050 /*     .. Array Arguments .. */
00051 /*     .. */
00052 
00053 /*  Purpose */
00054 /*  ======= */
00055 
00056 /*  SQPT01 tests the QR-factorization with pivoting of a matrix A.  The */
00057 /*  array AF contains the (possibly partial) QR-factorization of A, where */
00058 /*  the upper triangle of AF(1:k,1:k) is a partial triangular factor, */
00059 /*  the entries below the diagonal in the first k columns are the */
00060 /*  Householder vectors, and the rest of AF contains a partially updated */
00061 /*  matrix. */
00062 
00063 /*  This function returns ||A*P - Q*R||/(||norm(A)||*eps*M) */
00064 
00065 /*  Arguments */
00066 /*  ========= */
00067 
00068 /*  M       (input) INTEGER */
00069 /*          The number of rows of the matrices A and AF. */
00070 
00071 /*  N       (input) INTEGER */
00072 /*          The number of columns of the matrices A and AF. */
00073 
00074 /*  K       (input) INTEGER */
00075 /*          The number of columns of AF that have been reduced */
00076 /*          to upper triangular form. */
00077 
00078 /*  A       (input) REAL array, dimension (LDA, N) */
00079 /*          The original matrix A. */
00080 
00081 /*  AF      (input) REAL array, dimension (LDA,N) */
00082 /*          The (possibly partial) output of SGEQPF.  The upper triangle */
00083 /*          of AF(1:k,1:k) is a partial triangular factor, the entries */
00084 /*          below the diagonal in the first k columns are the Householder */
00085 /*          vectors, and the rest of AF contains a partially updated */
00086 /*          matrix. */
00087 
00088 /*  LDA     (input) INTEGER */
00089 /*          The leading dimension of the arrays A and AF. */
00090 
00091 /*  TAU     (input) REAL array, dimension (K) */
00092 /*          Details of the Householder transformations as returned by */
00093 /*          SGEQPF. */
00094 
00095 /*  JPVT    (input) INTEGER array, dimension (N) */
00096 /*          Pivot information as returned by SGEQPF. */
00097 
00098 /*  WORK    (workspace) REAL array, dimension (LWORK) */
00099 
00100 /*  LWORK   (input) INTEGER */
00101 /*          The length of the array WORK.  LWORK >= M*N+N. */
00102 
00103 /*  ===================================================================== */
00104 
00105 /*     .. Parameters .. */
00106 /*     .. */
00107 /*     .. Local Scalars .. */
00108 /*     .. */
00109 /*     .. Local Arrays .. */
00110 /*     .. */
00111 /*     .. External Functions .. */
00112 /*     .. */
00113 /*     .. External Subroutines .. */
00114 /*     .. */
00115 /*     .. Intrinsic Functions .. */
00116 /*     .. */
00117 /*     .. Executable Statements .. */
00118 
00119     /* Parameter adjustments */
00120     af_dim1 = *lda;
00121     af_offset = 1 + af_dim1;
00122     af -= af_offset;
00123     a_dim1 = *lda;
00124     a_offset = 1 + a_dim1;
00125     a -= a_offset;
00126     --tau;
00127     --jpvt;
00128     --work;
00129 
00130     /* Function Body */
00131     ret_val = 0.f;
00132 
00133 /*     Test if there is enough workspace */
00134 
00135     if (*lwork < *m * *n + *n) {
00136         xerbla_("SQPT01", &c__10);
00137         return ret_val;
00138     }
00139 
00140 /*     Quick return if possible */
00141 
00142     if (*m <= 0 || *n <= 0) {
00143         return ret_val;
00144     }
00145 
00146     norma = slange_("One-norm", m, n, &a[a_offset], lda, rwork);
00147 
00148     i__1 = *k;
00149     for (j = 1; j <= i__1; ++j) {
00150         i__2 = min(j,*m);
00151         for (i__ = 1; i__ <= i__2; ++i__) {
00152             work[(j - 1) * *m + i__] = af[i__ + j * af_dim1];
00153 /* L10: */
00154         }
00155         i__2 = *m;
00156         for (i__ = j + 1; i__ <= i__2; ++i__) {
00157             work[(j - 1) * *m + i__] = 0.f;
00158 /* L20: */
00159         }
00160 /* L30: */
00161     }
00162     i__1 = *n;
00163     for (j = *k + 1; j <= i__1; ++j) {
00164         scopy_(m, &af[j * af_dim1 + 1], &c__1, &work[(j - 1) * *m + 1], &c__1)
00165                 ;
00166 /* L40: */
00167     }
00168 
00169     i__1 = *lwork - *m * *n;
00170     sormqr_("Left", "No transpose", m, n, k, &af[af_offset], lda, &tau[1], &
00171             work[1], m, &work[*m * *n + 1], &i__1, &info);
00172 
00173     i__1 = *n;
00174     for (j = 1; j <= i__1; ++j) {
00175 
00176 /*        Compare i-th column of QR and jpvt(i)-th column of A */
00177 
00178         saxpy_(m, &c_b14, &a[jpvt[j] * a_dim1 + 1], &c__1, &work[(j - 1) * *m 
00179                 + 1], &c__1);
00180 /* L50: */
00181     }
00182 
00183     ret_val = slange_("One-norm", m, n, &work[1], m, rwork) / ((
00184             real) max(*m,*n) * slamch_("Epsilon"));
00185     if (norma != 0.f) {
00186         ret_val /= norma;
00187     }
00188 
00189     return ret_val;
00190 
00191 /*     End of SQPT01 */
00192 
00193 } /* sqpt01_ */


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