spot01.c
Go to the documentation of this file.
00001 /* spot01.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_b14 = 1.f;
00020 
00021 /* Subroutine */ int spot01_(char *uplo, integer *n, real *a, integer *lda, 
00022         real *afac, integer *ldafac, real *rwork, real *resid)
00023 {
00024     /* System generated locals */
00025     integer a_dim1, a_offset, afac_dim1, afac_offset, i__1, i__2;
00026 
00027     /* Local variables */
00028     integer i__, j, k;
00029     real t, eps;
00030     extern doublereal sdot_(integer *, real *, integer *, real *, integer *);
00031     extern /* Subroutine */ int ssyr_(char *, integer *, real *, real *, 
00032             integer *, real *, integer *);
00033     extern logical lsame_(char *, char *);
00034     extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
00035     real anorm;
00036     extern /* Subroutine */ int strmv_(char *, char *, char *, integer *, 
00037             real *, integer *, real *, integer *);
00038     extern doublereal slamch_(char *), slansy_(char *, char *, 
00039             integer *, real *, integer *, real *);
00040 
00041 
00042 /*  -- LAPACK test routine (version 3.1) -- */
00043 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00044 /*     November 2006 */
00045 
00046 /*     .. Scalar Arguments .. */
00047 /*     .. */
00048 /*     .. Array Arguments .. */
00049 /*     .. */
00050 
00051 /*  Purpose */
00052 /*  ======= */
00053 
00054 /*  SPOT01 reconstructs a symmetric positive definite matrix  A  from */
00055 /*  its L*L' or U'*U factorization and computes the residual */
00056 /*     norm( L*L' - A ) / ( N * norm(A) * EPS ) or */
00057 /*     norm( U'*U - A ) / ( N * norm(A) * EPS ), */
00058 /*  where EPS is the machine epsilon. */
00059 
00060 /*  Arguments */
00061 /*  ========== */
00062 
00063 /*  UPLO    (input) CHARACTER*1 */
00064 /*          Specifies whether the upper or lower triangular part of the */
00065 /*          symmetric matrix A is stored: */
00066 /*          = 'U':  Upper triangular */
00067 /*          = 'L':  Lower triangular */
00068 
00069 /*  N       (input) INTEGER */
00070 /*          The number of rows and columns of the matrix A.  N >= 0. */
00071 
00072 /*  A       (input) REAL array, dimension (LDA,N) */
00073 /*          The original symmetric matrix A. */
00074 
00075 /*  LDA     (input) INTEGER */
00076 /*          The leading dimension of the array A.  LDA >= max(1,N) */
00077 
00078 /*  AFAC    (input/output) REAL array, dimension (LDAFAC,N) */
00079 /*          On entry, the factor L or U from the L*L' or U'*U */
00080 /*          factorization of A. */
00081 /*          Overwritten with the reconstructed matrix, and then with the */
00082 /*          difference L*L' - A (or U'*U - A). */
00083 
00084 /*  LDAFAC  (input) INTEGER */
00085 /*          The leading dimension of the array AFAC.  LDAFAC >= max(1,N). */
00086 
00087 /*  RWORK   (workspace) REAL array, dimension (N) */
00088 
00089 /*  RESID   (output) REAL */
00090 /*          If UPLO = 'L', norm(L*L' - A) / ( N * norm(A) * EPS ) */
00091 /*          If UPLO = 'U', norm(U'*U - A) / ( N * norm(A) * EPS ) */
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 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     --rwork;
00117 
00118     /* Function Body */
00119     if (*n <= 0) {
00120         *resid = 0.f;
00121         return 0;
00122     }
00123 
00124 /*     Exit with RESID = 1/EPS if ANORM = 0. */
00125 
00126     eps = slamch_("Epsilon");
00127     anorm = slansy_("1", uplo, n, &a[a_offset], lda, &rwork[1]);
00128     if (anorm <= 0.f) {
00129         *resid = 1.f / eps;
00130         return 0;
00131     }
00132 
00133 /*     Compute the product U'*U, overwriting U. */
00134 
00135     if (lsame_(uplo, "U")) {
00136         for (k = *n; k >= 1; --k) {
00137 
00138 /*           Compute the (K,K) element of the result. */
00139 
00140             t = sdot_(&k, &afac[k * afac_dim1 + 1], &c__1, &afac[k * 
00141                     afac_dim1 + 1], &c__1);
00142             afac[k + k * afac_dim1] = t;
00143 
00144 /*           Compute the rest of column K. */
00145 
00146             i__1 = k - 1;
00147             strmv_("Upper", "Transpose", "Non-unit", &i__1, &afac[afac_offset]
00148 , ldafac, &afac[k * afac_dim1 + 1], &c__1);
00149 
00150 /* L10: */
00151         }
00152 
00153 /*     Compute the product L*L', overwriting L. */
00154 
00155     } else {
00156         for (k = *n; k >= 1; --k) {
00157 
00158 /*           Add a multiple of column K of the factor L to each of */
00159 /*           columns K+1 through N. */
00160 
00161             if (k + 1 <= *n) {
00162                 i__1 = *n - k;
00163                 ssyr_("Lower", &i__1, &c_b14, &afac[k + 1 + k * afac_dim1], &
00164                         c__1, &afac[k + 1 + (k + 1) * afac_dim1], ldafac);
00165             }
00166 
00167 /*           Scale column K by the diagonal element. */
00168 
00169             t = afac[k + k * afac_dim1];
00170             i__1 = *n - k + 1;
00171             sscal_(&i__1, &t, &afac[k + k * afac_dim1], &c__1);
00172 
00173 /* L20: */
00174         }
00175     }
00176 
00177 /*     Compute the difference  L*L' - A (or U'*U - A). */
00178 
00179     if (lsame_(uplo, "U")) {
00180         i__1 = *n;
00181         for (j = 1; j <= i__1; ++j) {
00182             i__2 = j;
00183             for (i__ = 1; i__ <= i__2; ++i__) {
00184                 afac[i__ + j * afac_dim1] -= a[i__ + j * a_dim1];
00185 /* L30: */
00186             }
00187 /* L40: */
00188         }
00189     } else {
00190         i__1 = *n;
00191         for (j = 1; j <= i__1; ++j) {
00192             i__2 = *n;
00193             for (i__ = j; i__ <= i__2; ++i__) {
00194                 afac[i__ + j * afac_dim1] -= a[i__ + j * a_dim1];
00195 /* L50: */
00196             }
00197 /* L60: */
00198         }
00199     }
00200 
00201 /*     Compute norm( L*U - A ) / ( N * norm(A) * EPS ) */
00202 
00203     *resid = slansy_("1", uplo, n, &afac[afac_offset], ldafac, &rwork[1]);
00204 
00205     *resid = *resid / (real) (*n) / anorm / eps;
00206 
00207     return 0;
00208 
00209 /*     End of SPOT01 */
00210 
00211 } /* spot01_ */


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