dpot01.c
Go to the documentation of this file.
00001 /* dpot01.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 doublereal c_b14 = 1.;
00020 
00021 /* Subroutine */ int dpot01_(char *uplo, integer *n, doublereal *a, integer *
00022         lda, doublereal *afac, integer *ldafac, doublereal *rwork, doublereal 
00023         *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     doublereal t, eps;
00031     extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *, 
00032             integer *);
00033     extern /* Subroutine */ int dsyr_(char *, integer *, doublereal *, 
00034             doublereal *, integer *, doublereal *, integer *), dscal_(
00035             integer *, doublereal *, doublereal *, integer *);
00036     extern logical lsame_(char *, char *);
00037     doublereal anorm;
00038     extern /* Subroutine */ int dtrmv_(char *, char *, char *, integer *, 
00039             doublereal *, integer *, doublereal *, integer *);
00040     extern doublereal dlamch_(char *), dlansy_(char *, char *, 
00041             integer *, doublereal *, integer *, doublereal *);
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 /*  DPOT01 reconstructs a symmetric positive definite matrix  A  from */
00057 /*  its L*L' or U'*U factorization and computes the residual */
00058 /*     norm( L*L' - A ) / ( N * norm(A) * EPS ) or */
00059 /*     norm( U'*U - A ) / ( N * norm(A) * EPS ), */
00060 /*  where EPS is the machine epsilon. */
00061 
00062 /*  Arguments */
00063 /*  ========== */
00064 
00065 /*  UPLO    (input) CHARACTER*1 */
00066 /*          Specifies whether the upper or lower triangular part of the */
00067 /*          symmetric matrix A is stored: */
00068 /*          = 'U':  Upper triangular */
00069 /*          = 'L':  Lower triangular */
00070 
00071 /*  N       (input) INTEGER */
00072 /*          The number of rows and columns of the matrix A.  N >= 0. */
00073 
00074 /*  A       (input) DOUBLE PRECISION array, dimension (LDA,N) */
00075 /*          The original symmetric matrix A. */
00076 
00077 /*  LDA     (input) INTEGER */
00078 /*          The leading dimension of the array A.  LDA >= max(1,N) */
00079 
00080 /*  AFAC    (input/output) DOUBLE PRECISION array, dimension (LDAFAC,N) */
00081 /*          On entry, the factor L or U from the L*L' or U'*U */
00082 /*          factorization of A. */
00083 /*          Overwritten with the reconstructed matrix, and then with the */
00084 /*          difference L*L' - A (or U'*U - A). */
00085 
00086 /*  LDAFAC  (input) INTEGER */
00087 /*          The leading dimension of the array AFAC.  LDAFAC >= max(1,N). */
00088 
00089 /*  RWORK   (workspace) DOUBLE PRECISION array, dimension (N) */
00090 
00091 /*  RESID   (output) DOUBLE PRECISION */
00092 /*          If UPLO = 'L', norm(L*L' - A) / ( N * norm(A) * EPS ) */
00093 /*          If UPLO = 'U', norm(U'*U - A) / ( N * norm(A) * EPS ) */
00094 
00095 /*  ===================================================================== */
00096 
00097 /*     .. Parameters .. */
00098 /*     .. */
00099 /*     .. Local Scalars .. */
00100 /*     .. */
00101 /*     .. External Functions .. */
00102 /*     .. */
00103 /*     .. External Subroutines .. */
00104 /*     .. */
00105 /*     .. Intrinsic Functions .. */
00106 /*     .. */
00107 /*     .. Executable Statements .. */
00108 
00109 /*     Quick exit if N = 0. */
00110 
00111     /* Parameter adjustments */
00112     a_dim1 = *lda;
00113     a_offset = 1 + a_dim1;
00114     a -= a_offset;
00115     afac_dim1 = *ldafac;
00116     afac_offset = 1 + afac_dim1;
00117     afac -= afac_offset;
00118     --rwork;
00119 
00120     /* Function Body */
00121     if (*n <= 0) {
00122         *resid = 0.;
00123         return 0;
00124     }
00125 
00126 /*     Exit with RESID = 1/EPS if ANORM = 0. */
00127 
00128     eps = dlamch_("Epsilon");
00129     anorm = dlansy_("1", uplo, n, &a[a_offset], lda, &rwork[1]);
00130     if (anorm <= 0.) {
00131         *resid = 1. / eps;
00132         return 0;
00133     }
00134 
00135 /*     Compute the product U'*U, overwriting U. */
00136 
00137     if (lsame_(uplo, "U")) {
00138         for (k = *n; k >= 1; --k) {
00139 
00140 /*           Compute the (K,K) element of the result. */
00141 
00142             t = ddot_(&k, &afac[k * afac_dim1 + 1], &c__1, &afac[k * 
00143                     afac_dim1 + 1], &c__1);
00144             afac[k + k * afac_dim1] = t;
00145 
00146 /*           Compute the rest of column K. */
00147 
00148             i__1 = k - 1;
00149             dtrmv_("Upper", "Transpose", "Non-unit", &i__1, &afac[afac_offset]
00150 , ldafac, &afac[k * afac_dim1 + 1], &c__1);
00151 
00152 /* L10: */
00153         }
00154 
00155 /*     Compute the product L*L', overwriting L. */
00156 
00157     } else {
00158         for (k = *n; k >= 1; --k) {
00159 
00160 /*           Add a multiple of column K of the factor L to each of */
00161 /*           columns K+1 through N. */
00162 
00163             if (k + 1 <= *n) {
00164                 i__1 = *n - k;
00165                 dsyr_("Lower", &i__1, &c_b14, &afac[k + 1 + k * afac_dim1], &
00166                         c__1, &afac[k + 1 + (k + 1) * afac_dim1], ldafac);
00167             }
00168 
00169 /*           Scale column K by the diagonal element. */
00170 
00171             t = afac[k + k * afac_dim1];
00172             i__1 = *n - k + 1;
00173             dscal_(&i__1, &t, &afac[k + k * afac_dim1], &c__1);
00174 
00175 /* L20: */
00176         }
00177     }
00178 
00179 /*     Compute the difference  L*L' - A (or U'*U - A). */
00180 
00181     if (lsame_(uplo, "U")) {
00182         i__1 = *n;
00183         for (j = 1; j <= i__1; ++j) {
00184             i__2 = j;
00185             for (i__ = 1; i__ <= i__2; ++i__) {
00186                 afac[i__ + j * afac_dim1] -= a[i__ + j * a_dim1];
00187 /* L30: */
00188             }
00189 /* L40: */
00190         }
00191     } else {
00192         i__1 = *n;
00193         for (j = 1; j <= i__1; ++j) {
00194             i__2 = *n;
00195             for (i__ = j; i__ <= i__2; ++i__) {
00196                 afac[i__ + j * afac_dim1] -= a[i__ + j * a_dim1];
00197 /* L50: */
00198             }
00199 /* L60: */
00200         }
00201     }
00202 
00203 /*     Compute norm( L*U - A ) / ( N * norm(A) * EPS ) */
00204 
00205     *resid = dlansy_("1", uplo, n, &afac[afac_offset], ldafac, &rwork[1]);
00206 
00207     *resid = *resid / (doublereal) (*n) / anorm / eps;
00208 
00209     return 0;
00210 
00211 /*     End of DPOT01 */
00212 
00213 } /* dpot01_ */


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