dpst01.c
Go to the documentation of this file.
00001 /* dpst01.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_b18 = 1.;
00020 
00021 /* Subroutine */ int dpst01_(char *uplo, integer *n, doublereal *a, integer *
00022         lda, doublereal *afac, integer *ldafac, doublereal *perm, integer *
00023         ldperm, integer *piv, doublereal *rwork, doublereal *resid, integer *
00024         rank)
00025 {
00026     /* System generated locals */
00027     integer a_dim1, a_offset, afac_dim1, afac_offset, perm_dim1, perm_offset, 
00028             i__1, i__2;
00029 
00030     /* Local variables */
00031     integer i__, j, k;
00032     doublereal t, eps;
00033     extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *, 
00034             integer *);
00035     extern /* Subroutine */ int dsyr_(char *, integer *, doublereal *, 
00036             doublereal *, integer *, doublereal *, integer *), dscal_(
00037             integer *, doublereal *, doublereal *, integer *);
00038     extern logical lsame_(char *, char *);
00039     doublereal anorm;
00040     extern /* Subroutine */ int dtrmv_(char *, char *, char *, integer *, 
00041             doublereal *, integer *, doublereal *, integer *);
00042     extern doublereal dlamch_(char *), dlansy_(char *, char *, 
00043             integer *, doublereal *, integer *, doublereal *);
00044 
00045 
00046 /*  -- LAPACK test routine (version 3.1) -- */
00047 /*     Craig Lucas, University of Manchester / NAG Ltd. */
00048 /*     October, 2008 */
00049 
00050 /*     .. Scalar Arguments .. */
00051 /*     .. */
00052 /*     .. Array Arguments .. */
00053 /*     .. */
00054 
00055 /*  Purpose */
00056 /*  ======= */
00057 
00058 /*  DPST01 reconstructs a symmetric positive semidefinite matrix A */
00059 /*  from its L or U factors and the permutation matrix P and computes */
00060 /*  the residual */
00061 /*     norm( P*L*L'*P' - A ) / ( N * norm(A) * EPS ) or */
00062 /*     norm( P*U'*U*P' - A ) / ( N * norm(A) * EPS ), */
00063 /*  where EPS is the machine epsilon. */
00064 
00065 /*  Arguments */
00066 /*  ========== */
00067 
00068 /*  UPLO    (input) CHARACTER*1 */
00069 /*          Specifies whether the upper or lower triangular part of the */
00070 /*          symmetric matrix A is stored: */
00071 /*          = 'U':  Upper triangular */
00072 /*          = 'L':  Lower triangular */
00073 
00074 /*  N       (input) INTEGER */
00075 /*          The number of rows and columns of the matrix A.  N >= 0. */
00076 
00077 /*  A       (input) DOUBLE PRECISION array, dimension (LDA,N) */
00078 /*          The original symmetric matrix A. */
00079 
00080 /*  LDA     (input) INTEGER */
00081 /*          The leading dimension of the array A.  LDA >= max(1,N) */
00082 
00083 /*  AFAC    (input) DOUBLE PRECISION array, dimension (LDAFAC,N) */
00084 /*          The factor L or U from the L*L' or U'*U */
00085 /*          factorization of A. */
00086 
00087 /*  LDAFAC  (input) INTEGER */
00088 /*          The leading dimension of the array AFAC.  LDAFAC >= max(1,N). */
00089 
00090 /*  PERM    (output) DOUBLE PRECISION array, dimension (LDPERM,N) */
00091 /*          Overwritten with the reconstructed matrix, and then with the */
00092 /*          difference P*L*L'*P' - A (or P*U'*U*P' - A) */
00093 
00094 /*  LDPERM  (input) INTEGER */
00095 /*          The leading dimension of the array PERM. */
00096 /*          LDAPERM >= max(1,N). */
00097 
00098 /*  PIV     (input) INTEGER array, dimension (N) */
00099 /*          PIV is such that the nonzero entries are */
00100 /*          P( PIV( K ), K ) = 1. */
00101 
00102 /*  RWORK   (workspace) DOUBLE PRECISION array, dimension (N) */
00103 
00104 /*  RESID   (output) DOUBLE PRECISION */
00105 /*          If UPLO = 'L', norm(L*L' - A) / ( N * norm(A) * EPS ) */
00106 /*          If UPLO = 'U', norm(U'*U - A) / ( N * norm(A) * EPS ) */
00107 
00108 /*  ===================================================================== */
00109 
00110 /*     .. Parameters .. */
00111 /*     .. */
00112 /*     .. Local Scalars .. */
00113 /*     .. */
00114 /*     .. External Functions .. */
00115 /*     .. */
00116 /*     .. External Subroutines .. */
00117 /*     .. */
00118 /*     .. Intrinsic Functions .. */
00119 /*     .. */
00120 /*     .. Executable Statements .. */
00121 
00122 /*     Quick exit if N = 0. */
00123 
00124     /* Parameter adjustments */
00125     a_dim1 = *lda;
00126     a_offset = 1 + a_dim1;
00127     a -= a_offset;
00128     afac_dim1 = *ldafac;
00129     afac_offset = 1 + afac_dim1;
00130     afac -= afac_offset;
00131     perm_dim1 = *ldperm;
00132     perm_offset = 1 + perm_dim1;
00133     perm -= perm_offset;
00134     --piv;
00135     --rwork;
00136 
00137     /* Function Body */
00138     if (*n <= 0) {
00139         *resid = 0.;
00140         return 0;
00141     }
00142 
00143 /*     Exit with RESID = 1/EPS if ANORM = 0. */
00144 
00145     eps = dlamch_("Epsilon");
00146     anorm = dlansy_("1", uplo, n, &a[a_offset], lda, &rwork[1]);
00147     if (anorm <= 0.) {
00148         *resid = 1. / eps;
00149         return 0;
00150     }
00151 
00152 /*     Compute the product U'*U, overwriting U. */
00153 
00154     if (lsame_(uplo, "U")) {
00155 
00156         if (*rank < *n) {
00157             i__1 = *n;
00158             for (j = *rank + 1; j <= i__1; ++j) {
00159                 i__2 = j;
00160                 for (i__ = *rank + 1; i__ <= i__2; ++i__) {
00161                     afac[i__ + j * afac_dim1] = 0.;
00162 /* L100: */
00163                 }
00164 /* L110: */
00165             }
00166         }
00167 
00168         for (k = *n; k >= 1; --k) {
00169 
00170 /*           Compute the (K,K) element of the result. */
00171 
00172             t = ddot_(&k, &afac[k * afac_dim1 + 1], &c__1, &afac[k * 
00173                     afac_dim1 + 1], &c__1);
00174             afac[k + k * afac_dim1] = t;
00175 
00176 /*           Compute the rest of column K. */
00177 
00178             i__1 = k - 1;
00179             dtrmv_("Upper", "Transpose", "Non-unit", &i__1, &afac[afac_offset]
00180 , ldafac, &afac[k * afac_dim1 + 1], &c__1);
00181 
00182 /* L120: */
00183         }
00184 
00185 /*     Compute the product L*L', overwriting L. */
00186 
00187     } else {
00188 
00189         if (*rank < *n) {
00190             i__1 = *n;
00191             for (j = *rank + 1; j <= i__1; ++j) {
00192                 i__2 = *n;
00193                 for (i__ = j; i__ <= i__2; ++i__) {
00194                     afac[i__ + j * afac_dim1] = 0.;
00195 /* L130: */
00196                 }
00197 /* L140: */
00198             }
00199         }
00200 
00201         for (k = *n; k >= 1; --k) {
00202 /*           Add a multiple of column K of the factor L to each of */
00203 /*           columns K+1 through N. */
00204 
00205             if (k + 1 <= *n) {
00206                 i__1 = *n - k;
00207                 dsyr_("Lower", &i__1, &c_b18, &afac[k + 1 + k * afac_dim1], &
00208                         c__1, &afac[k + 1 + (k + 1) * afac_dim1], ldafac);
00209             }
00210 
00211 /*           Scale column K by the diagonal element. */
00212 
00213             t = afac[k + k * afac_dim1];
00214             i__1 = *n - k + 1;
00215             dscal_(&i__1, &t, &afac[k + k * afac_dim1], &c__1);
00216 /* L150: */
00217         }
00218 
00219     }
00220 
00221 /*        Form P*L*L'*P' or P*U'*U*P' */
00222 
00223     if (lsame_(uplo, "U")) {
00224 
00225         i__1 = *n;
00226         for (j = 1; j <= i__1; ++j) {
00227             i__2 = *n;
00228             for (i__ = 1; i__ <= i__2; ++i__) {
00229                 if (piv[i__] <= piv[j]) {
00230                     if (i__ <= j) {
00231                         perm[piv[i__] + piv[j] * perm_dim1] = afac[i__ + j * 
00232                                 afac_dim1];
00233                     } else {
00234                         perm[piv[i__] + piv[j] * perm_dim1] = afac[j + i__ * 
00235                                 afac_dim1];
00236                     }
00237                 }
00238 /* L160: */
00239             }
00240 /* L170: */
00241         }
00242 
00243 
00244     } else {
00245 
00246         i__1 = *n;
00247         for (j = 1; j <= i__1; ++j) {
00248             i__2 = *n;
00249             for (i__ = 1; i__ <= i__2; ++i__) {
00250                 if (piv[i__] >= piv[j]) {
00251                     if (i__ >= j) {
00252                         perm[piv[i__] + piv[j] * perm_dim1] = afac[i__ + j * 
00253                                 afac_dim1];
00254                     } else {
00255                         perm[piv[i__] + piv[j] * perm_dim1] = afac[j + i__ * 
00256                                 afac_dim1];
00257                     }
00258                 }
00259 /* L180: */
00260             }
00261 /* L190: */
00262         }
00263 
00264     }
00265 
00266 /*     Compute the difference  P*L*L'*P' - A (or P*U'*U*P' - A). */
00267 
00268     if (lsame_(uplo, "U")) {
00269         i__1 = *n;
00270         for (j = 1; j <= i__1; ++j) {
00271             i__2 = j;
00272             for (i__ = 1; i__ <= i__2; ++i__) {
00273                 perm[i__ + j * perm_dim1] -= a[i__ + j * a_dim1];
00274 /* L200: */
00275             }
00276 /* L210: */
00277         }
00278     } else {
00279         i__1 = *n;
00280         for (j = 1; j <= i__1; ++j) {
00281             i__2 = *n;
00282             for (i__ = j; i__ <= i__2; ++i__) {
00283                 perm[i__ + j * perm_dim1] -= a[i__ + j * a_dim1];
00284 /* L220: */
00285             }
00286 /* L230: */
00287         }
00288     }
00289 
00290 /*     Compute norm( P*L*L'P - A ) / ( N * norm(A) * EPS ), or */
00291 /*     ( P*U'*U*P' - A )/ ( N * norm(A) * EPS ). */
00292 
00293     *resid = dlansy_("1", uplo, n, &perm[perm_offset], ldafac, &rwork[1]);
00294 
00295     *resid = *resid / (doublereal) (*n) / anorm / eps;
00296 
00297     return 0;
00298 
00299 /*     End of DPST01 */
00300 
00301 } /* dpst01_ */


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