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


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