sget01.c
Go to the documentation of this file.
00001 /* sget01.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__1 = 1;
00019 static real c_b11 = 1.f;
00020 static integer c_n1 = -1;
00021 
00022 /* Subroutine */ int sget01_(integer *m, integer *n, real *a, integer *lda, 
00023         real *afac, integer *ldafac, integer *ipiv, real *rwork, real *resid)
00024 {
00025     /* System generated locals */
00026     integer a_dim1, a_offset, afac_dim1, afac_offset, i__1, i__2;
00027 
00028     /* Local variables */
00029     integer i__, j, k;
00030     real t, eps;
00031     extern doublereal sdot_(integer *, real *, integer *, real *, integer *);
00032     extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
00033     real anorm;
00034     extern /* Subroutine */ int sgemv_(char *, integer *, integer *, real *, 
00035             real *, integer *, real *, integer *, real *, real *, integer *), strmv_(char *, char *, char *, integer *, real *, 
00036             integer *, real *, integer *);
00037     extern doublereal slamch_(char *), slange_(char *, integer *, 
00038             integer *, real *, integer *, real *);
00039     extern /* Subroutine */ int slaswp_(integer *, real *, integer *, integer 
00040             *, integer *, integer *, integer *);
00041 
00042 
00043 /*  -- LAPACK test routine (version 3.1) -- */
00044 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00045 /*     November 2006 */
00046 
00047 /*     .. Scalar Arguments .. */
00048 /*     .. */
00049 /*     .. Array Arguments .. */
00050 /*     .. */
00051 
00052 /*  Purpose */
00053 /*  ======= */
00054 
00055 /*  SGET01 reconstructs a matrix A from its L*U factorization and */
00056 /*  computes the residual */
00057 /*     norm(L*U - A) / ( N * norm(A) * EPS ), */
00058 /*  where EPS is the machine epsilon. */
00059 
00060 /*  Arguments */
00061 /*  ========== */
00062 
00063 /*  M       (input) INTEGER */
00064 /*          The number of rows of the matrix A.  M >= 0. */
00065 
00066 /*  N       (input) INTEGER */
00067 /*          The number of columns of the matrix A.  N >= 0. */
00068 
00069 /*  A       (input) REAL array, dimension (LDA,N) */
00070 /*          The original M x N matrix A. */
00071 
00072 /*  LDA     (input) INTEGER */
00073 /*          The leading dimension of the array A.  LDA >= max(1,M). */
00074 
00075 /*  AFAC    (input/output) REAL array, dimension (LDAFAC,N) */
00076 /*          The factored form of the matrix A.  AFAC contains the factors */
00077 /*          L and U from the L*U factorization as computed by SGETRF. */
00078 /*          Overwritten with the reconstructed matrix, and then with the */
00079 /*          difference L*U - A. */
00080 
00081 /*  LDAFAC  (input) INTEGER */
00082 /*          The leading dimension of the array AFAC.  LDAFAC >= max(1,M). */
00083 
00084 /*  IPIV    (input) INTEGER array, dimension (N) */
00085 /*          The pivot indices from SGETRF. */
00086 
00087 /*  RWORK   (workspace) REAL array, dimension (M) */
00088 
00089 /*  RESID   (output) REAL */
00090 /*          norm(L*U - A) / ( N * norm(A) * EPS ) */
00091 
00092 /*  ===================================================================== */
00093 
00094 
00095 /*     .. Parameters .. */
00096 /*     .. */
00097 /*     .. Local Scalars .. */
00098 /*     .. */
00099 /*     .. External Functions .. */
00100 /*     .. */
00101 /*     .. External Subroutines .. */
00102 /*     .. */
00103 /*     .. Intrinsic Functions .. */
00104 /*     .. */
00105 /*     .. Executable Statements .. */
00106 
00107 /*     Quick exit if M = 0 or N = 0. */
00108 
00109     /* Parameter adjustments */
00110     a_dim1 = *lda;
00111     a_offset = 1 + a_dim1;
00112     a -= a_offset;
00113     afac_dim1 = *ldafac;
00114     afac_offset = 1 + afac_dim1;
00115     afac -= afac_offset;
00116     --ipiv;
00117     --rwork;
00118 
00119     /* Function Body */
00120     if (*m <= 0 || *n <= 0) {
00121         *resid = 0.f;
00122         return 0;
00123     }
00124 
00125 /*     Determine EPS and the norm of A. */
00126 
00127     eps = slamch_("Epsilon");
00128     anorm = slange_("1", m, n, &a[a_offset], lda, &rwork[1]);
00129 
00130 /*     Compute the product L*U and overwrite AFAC with the result. */
00131 /*     A column at a time of the product is obtained, starting with */
00132 /*     column N. */
00133 
00134     for (k = *n; k >= 1; --k) {
00135         if (k > *m) {
00136             strmv_("Lower", "No transpose", "Unit", m, &afac[afac_offset], 
00137                     ldafac, &afac[k * afac_dim1 + 1], &c__1);
00138         } else {
00139 
00140 /*           Compute elements (K+1:M,K) */
00141 
00142             t = afac[k + k * afac_dim1];
00143             if (k + 1 <= *m) {
00144                 i__1 = *m - k;
00145                 sscal_(&i__1, &t, &afac[k + 1 + k * afac_dim1], &c__1);
00146                 i__1 = *m - k;
00147                 i__2 = k - 1;
00148                 sgemv_("No transpose", &i__1, &i__2, &c_b11, &afac[k + 1 + 
00149                         afac_dim1], ldafac, &afac[k * afac_dim1 + 1], &c__1, &
00150                         c_b11, &afac[k + 1 + k * afac_dim1], &c__1);
00151             }
00152 
00153 /*           Compute the (K,K) element */
00154 
00155             i__1 = k - 1;
00156             afac[k + k * afac_dim1] = t + sdot_(&i__1, &afac[k + afac_dim1], 
00157                     ldafac, &afac[k * afac_dim1 + 1], &c__1);
00158 
00159 /*           Compute elements (1:K-1,K) */
00160 
00161             i__1 = k - 1;
00162             strmv_("Lower", "No transpose", "Unit", &i__1, &afac[afac_offset], 
00163                      ldafac, &afac[k * afac_dim1 + 1], &c__1);
00164         }
00165 /* L10: */
00166     }
00167     i__1 = min(*m,*n);
00168     slaswp_(n, &afac[afac_offset], ldafac, &c__1, &i__1, &ipiv[1], &c_n1);
00169 
00170 /*     Compute the difference  L*U - A  and store in AFAC. */
00171 
00172     i__1 = *n;
00173     for (j = 1; j <= i__1; ++j) {
00174         i__2 = *m;
00175         for (i__ = 1; i__ <= i__2; ++i__) {
00176             afac[i__ + j * afac_dim1] -= a[i__ + j * a_dim1];
00177 /* L20: */
00178         }
00179 /* L30: */
00180     }
00181 
00182 /*     Compute norm( L*U - A ) / ( N * norm(A) * EPS ) */
00183 
00184     *resid = slange_("1", m, n, &afac[afac_offset], ldafac, &rwork[1]);
00185 
00186     if (anorm <= 0.f) {
00187         if (*resid != 0.f) {
00188             *resid = 1.f / eps;
00189         }
00190     } else {
00191         *resid = *resid / (real) (*n) / anorm / eps;
00192     }
00193 
00194     return 0;
00195 
00196 /*     End of SGET01 */
00197 
00198 } /* sget01_ */


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