cpot01.c
Go to the documentation of this file.
00001 /* cpot01.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_b15 = 1.f;
00020 
00021 /* Subroutine */ int cpot01_(char *uplo, integer *n, complex *a, integer *lda, 
00022          complex *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, i__3, i__4, 
00026             i__5;
00027     real r__1;
00028     complex q__1;
00029 
00030     /* Builtin functions */
00031     double r_imag(complex *);
00032 
00033     /* Local variables */
00034     integer i__, j, k;
00035     complex tc;
00036     real tr, eps;
00037     extern /* Subroutine */ int cher_(char *, integer *, real *, complex *, 
00038             integer *, complex *, integer *), cscal_(integer *, 
00039             complex *, complex *, integer *);
00040     extern /* Complex */ VOID cdotc_(complex *, integer *, complex *, integer 
00041             *, complex *, integer *);
00042     extern logical lsame_(char *, char *);
00043     real anorm;
00044     extern /* Subroutine */ int ctrmv_(char *, char *, char *, integer *, 
00045             complex *, integer *, complex *, integer *);
00046     extern doublereal clanhe_(char *, char *, integer *, complex *, integer *, 
00047              real *), slamch_(char *);
00048 
00049 
00050 /*  -- LAPACK test routine (version 3.1) -- */
00051 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00052 /*     November 2006 */
00053 
00054 /*     .. Scalar Arguments .. */
00055 /*     .. */
00056 /*     .. Array Arguments .. */
00057 /*     .. */
00058 
00059 /*  Purpose */
00060 /*  ======= */
00061 
00062 /*  CPOT01 reconstructs a Hermitian positive definite matrix  A  from */
00063 /*  its L*L' or U'*U factorization and computes the residual */
00064 /*     norm( L*L' - A ) / ( N * norm(A) * EPS ) or */
00065 /*     norm( U'*U - A ) / ( N * norm(A) * EPS ), */
00066 /*  where EPS is the machine epsilon, L' is the conjugate transpose of L, */
00067 /*  and U' is the conjugate transpose of U. */
00068 
00069 /*  Arguments */
00070 /*  ========== */
00071 
00072 /*  UPLO    (input) CHARACTER*1 */
00073 /*          Specifies whether the upper or lower triangular part of the */
00074 /*          Hermitian matrix A is stored: */
00075 /*          = 'U':  Upper triangular */
00076 /*          = 'L':  Lower triangular */
00077 
00078 /*  N       (input) INTEGER */
00079 /*          The number of rows and columns of the matrix A.  N >= 0. */
00080 
00081 /*  A       (input) COMPLEX array, dimension (LDA,N) */
00082 /*          The original Hermitian matrix A. */
00083 
00084 /*  LDA     (input) INTEGER */
00085 /*          The leading dimension of the array A.  LDA >= max(1,N) */
00086 
00087 /*  AFAC    (input/output) COMPLEX array, dimension (LDAFAC,N) */
00088 /*          On entry, the factor L or U from the L*L' or U'*U */
00089 /*          factorization of A. */
00090 /*          Overwritten with the reconstructed matrix, and then with the */
00091 /*          difference L*L' - A (or U'*U - A). */
00092 
00093 /*  LDAFAC  (input) INTEGER */
00094 /*          The leading dimension of the array AFAC.  LDAFAC >= max(1,N). */
00095 
00096 /*  RWORK   (workspace) REAL array, dimension (N) */
00097 
00098 /*  RESID   (output) REAL */
00099 /*          If UPLO = 'L', norm(L*L' - A) / ( N * norm(A) * EPS ) */
00100 /*          If UPLO = 'U', norm(U'*U - A) / ( N * norm(A) * EPS ) */
00101 
00102 /*  ===================================================================== */
00103 
00104 /*     .. Parameters .. */
00105 /*     .. */
00106 /*     .. Local Scalars .. */
00107 /*     .. */
00108 /*     .. External Functions .. */
00109 /*     .. */
00110 /*     .. External Subroutines .. */
00111 /*     .. */
00112 /*     .. Intrinsic Functions .. */
00113 /*     .. */
00114 /*     .. Executable Statements .. */
00115 
00116 /*     Quick exit if N = 0. */
00117 
00118     /* Parameter adjustments */
00119     a_dim1 = *lda;
00120     a_offset = 1 + a_dim1;
00121     a -= a_offset;
00122     afac_dim1 = *ldafac;
00123     afac_offset = 1 + afac_dim1;
00124     afac -= afac_offset;
00125     --rwork;
00126 
00127     /* Function Body */
00128     if (*n <= 0) {
00129         *resid = 0.f;
00130         return 0;
00131     }
00132 
00133 /*     Exit with RESID = 1/EPS if ANORM = 0. */
00134 
00135     eps = slamch_("Epsilon");
00136     anorm = clanhe_("1", uplo, n, &a[a_offset], lda, &rwork[1]);
00137     if (anorm <= 0.f) {
00138         *resid = 1.f / eps;
00139         return 0;
00140     }
00141 
00142 /*     Check the imaginary parts of the diagonal elements and return with */
00143 /*     an error code if any are nonzero. */
00144 
00145     i__1 = *n;
00146     for (j = 1; j <= i__1; ++j) {
00147         if (r_imag(&afac[j + j * afac_dim1]) != 0.f) {
00148             *resid = 1.f / eps;
00149             return 0;
00150         }
00151 /* L10: */
00152     }
00153 
00154 /*     Compute the product U'*U, overwriting U. */
00155 
00156     if (lsame_(uplo, "U")) {
00157         for (k = *n; k >= 1; --k) {
00158 
00159 /*           Compute the (K,K) element of the result. */
00160 
00161             cdotc_(&q__1, &k, &afac[k * afac_dim1 + 1], &c__1, &afac[k * 
00162                     afac_dim1 + 1], &c__1);
00163             tr = q__1.r;
00164             i__1 = k + k * afac_dim1;
00165             afac[i__1].r = tr, afac[i__1].i = 0.f;
00166 
00167 /*           Compute the rest of column K. */
00168 
00169             i__1 = k - 1;
00170             ctrmv_("Upper", "Conjugate", "Non-unit", &i__1, &afac[afac_offset]
00171 , ldafac, &afac[k * afac_dim1 + 1], &c__1);
00172 
00173 /* L20: */
00174         }
00175 
00176 /*     Compute the product L*L', overwriting L. */
00177 
00178     } else {
00179         for (k = *n; k >= 1; --k) {
00180 
00181 /*           Add a multiple of column K of the factor L to each of */
00182 /*           columns K+1 through N. */
00183 
00184             if (k + 1 <= *n) {
00185                 i__1 = *n - k;
00186                 cher_("Lower", &i__1, &c_b15, &afac[k + 1 + k * afac_dim1], &
00187                         c__1, &afac[k + 1 + (k + 1) * afac_dim1], ldafac);
00188             }
00189 
00190 /*           Scale column K by the diagonal element. */
00191 
00192             i__1 = k + k * afac_dim1;
00193             tc.r = afac[i__1].r, tc.i = afac[i__1].i;
00194             i__1 = *n - k + 1;
00195             cscal_(&i__1, &tc, &afac[k + k * afac_dim1], &c__1);
00196 
00197 /* L30: */
00198         }
00199     }
00200 
00201 /*     Compute the difference  L*L' - A (or U'*U - A). */
00202 
00203     if (lsame_(uplo, "U")) {
00204         i__1 = *n;
00205         for (j = 1; j <= i__1; ++j) {
00206             i__2 = j - 1;
00207             for (i__ = 1; i__ <= i__2; ++i__) {
00208                 i__3 = i__ + j * afac_dim1;
00209                 i__4 = i__ + j * afac_dim1;
00210                 i__5 = i__ + j * a_dim1;
00211                 q__1.r = afac[i__4].r - a[i__5].r, q__1.i = afac[i__4].i - a[
00212                         i__5].i;
00213                 afac[i__3].r = q__1.r, afac[i__3].i = q__1.i;
00214 /* L40: */
00215             }
00216             i__2 = j + j * afac_dim1;
00217             i__3 = j + j * afac_dim1;
00218             i__4 = j + j * a_dim1;
00219             r__1 = a[i__4].r;
00220             q__1.r = afac[i__3].r - r__1, q__1.i = afac[i__3].i;
00221             afac[i__2].r = q__1.r, afac[i__2].i = q__1.i;
00222 /* L50: */
00223         }
00224     } else {
00225         i__1 = *n;
00226         for (j = 1; j <= i__1; ++j) {
00227             i__2 = j + j * afac_dim1;
00228             i__3 = j + j * afac_dim1;
00229             i__4 = j + j * a_dim1;
00230             r__1 = a[i__4].r;
00231             q__1.r = afac[i__3].r - r__1, q__1.i = afac[i__3].i;
00232             afac[i__2].r = q__1.r, afac[i__2].i = q__1.i;
00233             i__2 = *n;
00234             for (i__ = j + 1; i__ <= i__2; ++i__) {
00235                 i__3 = i__ + j * afac_dim1;
00236                 i__4 = i__ + j * afac_dim1;
00237                 i__5 = i__ + j * a_dim1;
00238                 q__1.r = afac[i__4].r - a[i__5].r, q__1.i = afac[i__4].i - a[
00239                         i__5].i;
00240                 afac[i__3].r = q__1.r, afac[i__3].i = q__1.i;
00241 /* L60: */
00242             }
00243 /* L70: */
00244         }
00245     }
00246 
00247 /*     Compute norm( L*U - A ) / ( N * norm(A) * EPS ) */
00248 
00249     *resid = clanhe_("1", uplo, n, &afac[afac_offset], ldafac, &rwork[1]);
00250 
00251     *resid = *resid / (real) (*n) / anorm / eps;
00252 
00253     return 0;
00254 
00255 /*     End of CPOT01 */
00256 
00257 } /* cpot01_ */


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