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


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