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


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