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


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