ztpt05.c
Go to the documentation of this file.
00001 /* ztpt05.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 
00020 /* Subroutine */ int ztpt05_(char *uplo, char *trans, char *diag, integer *n, 
00021         integer *nrhs, doublecomplex *ap, doublecomplex *b, integer *ldb, 
00022         doublecomplex *x, integer *ldx, doublecomplex *xact, integer *ldxact, 
00023         doublereal *ferr, doublereal *berr, doublereal *reslts)
00024 {
00025     /* System generated locals */
00026     integer b_dim1, b_offset, x_dim1, x_offset, xact_dim1, xact_offset, i__1, 
00027             i__2, i__3, i__4, i__5;
00028     doublereal d__1, d__2, d__3, d__4;
00029     doublecomplex z__1, z__2;
00030 
00031     /* Builtin functions */
00032     double d_imag(doublecomplex *);
00033 
00034     /* Local variables */
00035     integer i__, j, k, jc, ifu;
00036     doublereal eps, tmp, diff, axbi;
00037     integer imax;
00038     doublereal unfl, ovfl;
00039     logical unit;
00040     extern logical lsame_(char *, char *);
00041     logical upper;
00042     doublereal xnorm;
00043     extern doublereal dlamch_(char *);
00044     doublereal errbnd;
00045     extern integer izamax_(integer *, doublecomplex *, integer *);
00046     logical notran;
00047 
00048 
00049 /*  -- LAPACK test routine (version 3.1) -- */
00050 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00051 /*     November 2006 */
00052 
00053 /*     .. Scalar Arguments .. */
00054 /*     .. */
00055 /*     .. Array Arguments .. */
00056 /*     .. */
00057 
00058 /*  Purpose */
00059 /*  ======= */
00060 
00061 /*  ZTPT05 tests the error bounds from iterative refinement for the */
00062 /*  computed solution to a system of equations A*X = B, where A is a */
00063 /*  triangular matrix in packed storage format. */
00064 
00065 /*  RESLTS(1) = test of the error bound */
00066 /*            = norm(X - XACT) / ( norm(X) * FERR ) */
00067 
00068 /*  A large value is returned if this ratio is not less than one. */
00069 
00070 /*  RESLTS(2) = residual from the iterative refinement routine */
00071 /*            = the maximum of BERR / ( (n+1)*EPS + (*) ), where */
00072 /*              (*) = (n+1)*UNFL / (min_i (abs(A)*abs(X) +abs(b))_i ) */
00073 
00074 /*  Arguments */
00075 /*  ========= */
00076 
00077 /*  UPLO    (input) CHARACTER*1 */
00078 /*          Specifies whether the matrix A is upper or lower triangular. */
00079 /*          = 'U':  Upper triangular */
00080 /*          = 'L':  Lower triangular */
00081 
00082 /*  TRANS   (input) CHARACTER*1 */
00083 /*          Specifies the form of the system of equations. */
00084 /*          = 'N':  A * X = B  (No transpose) */
00085 /*          = 'T':  A'* X = B  (Transpose) */
00086 /*          = 'C':  A'* X = B  (Conjugate transpose = Transpose) */
00087 
00088 /*  DIAG    (input) CHARACTER*1 */
00089 /*          Specifies whether or not the matrix A is unit triangular. */
00090 /*          = 'N':  Non-unit triangular */
00091 /*          = 'U':  Unit triangular */
00092 
00093 /*  N       (input) INTEGER */
00094 /*          The number of rows of the matrices X, B, and XACT, and the */
00095 /*          order of the matrix A.  N >= 0. */
00096 
00097 /*  NRHS    (input) INTEGER */
00098 /*          The number of columns of the matrices X, B, and XACT. */
00099 /*          NRHS >= 0. */
00100 
00101 /*  AP      (input) COMPLEX*16 array, dimension (N*(N+1)/2) */
00102 /*          The upper or lower triangular matrix A, packed columnwise in */
00103 /*          a linear array.  The j-th column of A is stored in the array */
00104 /*          AP as follows: */
00105 /*          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
00106 /*          if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */
00107 /*          If DIAG = 'U', the diagonal elements of A are not referenced */
00108 /*          and are assumed to be 1. */
00109 
00110 /*  B       (input) COMPLEX*16 array, dimension (LDB,NRHS) */
00111 /*          The right hand side vectors for the system of linear */
00112 /*          equations. */
00113 
00114 /*  LDB     (input) INTEGER */
00115 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00116 
00117 /*  X       (input) COMPLEX*16 array, dimension (LDX,NRHS) */
00118 /*          The computed solution vectors.  Each vector is stored as a */
00119 /*          column of the matrix X. */
00120 
00121 /*  LDX     (input) INTEGER */
00122 /*          The leading dimension of the array X.  LDX >= max(1,N). */
00123 
00124 /*  XACT    (input) COMPLEX*16 array, dimension (LDX,NRHS) */
00125 /*          The exact solution vectors.  Each vector is stored as a */
00126 /*          column of the matrix XACT. */
00127 
00128 /*  LDXACT  (input) INTEGER */
00129 /*          The leading dimension of the array XACT.  LDXACT >= max(1,N). */
00130 
00131 /*  FERR    (input) DOUBLE PRECISION array, dimension (NRHS) */
00132 /*          The estimated forward error bounds for each solution vector */
00133 /*          X.  If XTRUE is the true solution, FERR bounds the magnitude */
00134 /*          of the largest entry in (X - XTRUE) divided by the magnitude */
00135 /*          of the largest entry in X. */
00136 
00137 /*  BERR    (input) DOUBLE PRECISION array, dimension (NRHS) */
00138 /*          The componentwise relative backward error of each solution */
00139 /*          vector (i.e., the smallest relative change in any entry of A */
00140 /*          or B that makes X an exact solution). */
00141 
00142 /*  RESLTS  (output) DOUBLE PRECISION array, dimension (2) */
00143 /*          The maximum over the NRHS solution vectors of the ratios: */
00144 /*          RESLTS(1) = norm(X - XACT) / ( norm(X) * FERR ) */
00145 /*          RESLTS(2) = BERR / ( (n+1)*EPS + (*) ) */
00146 
00147 /*  ===================================================================== */
00148 
00149 /*     .. Parameters .. */
00150 /*     .. */
00151 /*     .. Local Scalars .. */
00152 /*     .. */
00153 /*     .. External Functions .. */
00154 /*     .. */
00155 /*     .. Intrinsic Functions .. */
00156 /*     .. */
00157 /*     .. Statement Functions .. */
00158 /*     .. */
00159 /*     .. Statement Function definitions .. */
00160 /*     .. */
00161 /*     .. Executable Statements .. */
00162 
00163 /*     Quick exit if N = 0 or NRHS = 0. */
00164 
00165     /* Parameter adjustments */
00166     --ap;
00167     b_dim1 = *ldb;
00168     b_offset = 1 + b_dim1;
00169     b -= b_offset;
00170     x_dim1 = *ldx;
00171     x_offset = 1 + x_dim1;
00172     x -= x_offset;
00173     xact_dim1 = *ldxact;
00174     xact_offset = 1 + xact_dim1;
00175     xact -= xact_offset;
00176     --ferr;
00177     --berr;
00178     --reslts;
00179 
00180     /* Function Body */
00181     if (*n <= 0 || *nrhs <= 0) {
00182         reslts[1] = 0.;
00183         reslts[2] = 0.;
00184         return 0;
00185     }
00186 
00187     eps = dlamch_("Epsilon");
00188     unfl = dlamch_("Safe minimum");
00189     ovfl = 1. / unfl;
00190     upper = lsame_(uplo, "U");
00191     notran = lsame_(trans, "N");
00192     unit = lsame_(diag, "U");
00193 
00194 /*     Test 1:  Compute the maximum of */
00195 /*        norm(X - XACT) / ( norm(X) * FERR ) */
00196 /*     over all the vectors X and XACT using the infinity-norm. */
00197 
00198     errbnd = 0.;
00199     i__1 = *nrhs;
00200     for (j = 1; j <= i__1; ++j) {
00201         imax = izamax_(n, &x[j * x_dim1 + 1], &c__1);
00202 /* Computing MAX */
00203         i__2 = imax + j * x_dim1;
00204         d__3 = (d__1 = x[i__2].r, abs(d__1)) + (d__2 = d_imag(&x[imax + j * 
00205                 x_dim1]), abs(d__2));
00206         xnorm = max(d__3,unfl);
00207         diff = 0.;
00208         i__2 = *n;
00209         for (i__ = 1; i__ <= i__2; ++i__) {
00210             i__3 = i__ + j * x_dim1;
00211             i__4 = i__ + j * xact_dim1;
00212             z__2.r = x[i__3].r - xact[i__4].r, z__2.i = x[i__3].i - xact[i__4]
00213                     .i;
00214             z__1.r = z__2.r, z__1.i = z__2.i;
00215 /* Computing MAX */
00216             d__3 = diff, d__4 = (d__1 = z__1.r, abs(d__1)) + (d__2 = d_imag(&
00217                     z__1), abs(d__2));
00218             diff = max(d__3,d__4);
00219 /* L10: */
00220         }
00221 
00222         if (xnorm > 1.) {
00223             goto L20;
00224         } else if (diff <= ovfl * xnorm) {
00225             goto L20;
00226         } else {
00227             errbnd = 1. / eps;
00228             goto L30;
00229         }
00230 
00231 L20:
00232         if (diff / xnorm <= ferr[j]) {
00233 /* Computing MAX */
00234             d__1 = errbnd, d__2 = diff / xnorm / ferr[j];
00235             errbnd = max(d__1,d__2);
00236         } else {
00237             errbnd = 1. / eps;
00238         }
00239 L30:
00240         ;
00241     }
00242     reslts[1] = errbnd;
00243 
00244 /*     Test 2:  Compute the maximum of BERR / ( (n+1)*EPS + (*) ), where */
00245 /*     (*) = (n+1)*UNFL / (min_i (abs(A)*abs(X) +abs(b))_i ) */
00246 
00247     ifu = 0;
00248     if (unit) {
00249         ifu = 1;
00250     }
00251     i__1 = *nrhs;
00252     for (k = 1; k <= i__1; ++k) {
00253         i__2 = *n;
00254         for (i__ = 1; i__ <= i__2; ++i__) {
00255             i__3 = i__ + k * b_dim1;
00256             tmp = (d__1 = b[i__3].r, abs(d__1)) + (d__2 = d_imag(&b[i__ + k * 
00257                     b_dim1]), abs(d__2));
00258             if (upper) {
00259                 jc = (i__ - 1) * i__ / 2;
00260                 if (! notran) {
00261                     i__3 = i__ - ifu;
00262                     for (j = 1; j <= i__3; ++j) {
00263                         i__4 = jc + j;
00264                         i__5 = j + k * x_dim1;
00265                         tmp += ((d__1 = ap[i__4].r, abs(d__1)) + (d__2 = 
00266                                 d_imag(&ap[jc + j]), abs(d__2))) * ((d__3 = x[
00267                                 i__5].r, abs(d__3)) + (d__4 = d_imag(&x[j + k 
00268                                 * x_dim1]), abs(d__4)));
00269 /* L40: */
00270                     }
00271                     if (unit) {
00272                         i__3 = i__ + k * x_dim1;
00273                         tmp += (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(
00274                                 &x[i__ + k * x_dim1]), abs(d__2));
00275                     }
00276                 } else {
00277                     jc += i__;
00278                     if (unit) {
00279                         i__3 = i__ + k * x_dim1;
00280                         tmp += (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(
00281                                 &x[i__ + k * x_dim1]), abs(d__2));
00282                         jc += i__;
00283                     }
00284                     i__3 = *n;
00285                     for (j = i__ + ifu; j <= i__3; ++j) {
00286                         i__4 = jc;
00287                         i__5 = j + k * x_dim1;
00288                         tmp += ((d__1 = ap[i__4].r, abs(d__1)) + (d__2 = 
00289                                 d_imag(&ap[jc]), abs(d__2))) * ((d__3 = x[
00290                                 i__5].r, abs(d__3)) + (d__4 = d_imag(&x[j + k 
00291                                 * x_dim1]), abs(d__4)));
00292                         jc += j;
00293 /* L50: */
00294                     }
00295                 }
00296             } else {
00297                 if (notran) {
00298                     jc = i__;
00299                     i__3 = i__ - ifu;
00300                     for (j = 1; j <= i__3; ++j) {
00301                         i__4 = jc;
00302                         i__5 = j + k * x_dim1;
00303                         tmp += ((d__1 = ap[i__4].r, abs(d__1)) + (d__2 = 
00304                                 d_imag(&ap[jc]), abs(d__2))) * ((d__3 = x[
00305                                 i__5].r, abs(d__3)) + (d__4 = d_imag(&x[j + k 
00306                                 * x_dim1]), abs(d__4)));
00307                         jc = jc + *n - j;
00308 /* L60: */
00309                     }
00310                     if (unit) {
00311                         i__3 = i__ + k * x_dim1;
00312                         tmp += (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(
00313                                 &x[i__ + k * x_dim1]), abs(d__2));
00314                     }
00315                 } else {
00316                     jc = (i__ - 1) * (*n - i__) + i__ * (i__ + 1) / 2;
00317                     if (unit) {
00318                         i__3 = i__ + k * x_dim1;
00319                         tmp += (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(
00320                                 &x[i__ + k * x_dim1]), abs(d__2));
00321                     }
00322                     i__3 = *n;
00323                     for (j = i__ + ifu; j <= i__3; ++j) {
00324                         i__4 = jc + j - i__;
00325                         i__5 = j + k * x_dim1;
00326                         tmp += ((d__1 = ap[i__4].r, abs(d__1)) + (d__2 = 
00327                                 d_imag(&ap[jc + j - i__]), abs(d__2))) * ((
00328                                 d__3 = x[i__5].r, abs(d__3)) + (d__4 = d_imag(
00329                                 &x[j + k * x_dim1]), abs(d__4)));
00330 /* L70: */
00331                     }
00332                 }
00333             }
00334             if (i__ == 1) {
00335                 axbi = tmp;
00336             } else {
00337                 axbi = min(axbi,tmp);
00338             }
00339 /* L80: */
00340         }
00341 /* Computing MAX */
00342         d__1 = axbi, d__2 = (*n + 1) * unfl;
00343         tmp = berr[k] / ((*n + 1) * eps + (*n + 1) * unfl / max(d__1,d__2));
00344         if (k == 1) {
00345             reslts[2] = tmp;
00346         } else {
00347             reslts[2] = max(reslts[2],tmp);
00348         }
00349 /* L90: */
00350     }
00351 
00352     return 0;
00353 
00354 /*     End of ZTPT05 */
00355 
00356 } /* ztpt05_ */


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