ctrt05.c
Go to the documentation of this file.
00001 /* ctrt05.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 ctrt05_(char *uplo, char *trans, char *diag, integer *n, 
00021         integer *nrhs, complex *a, integer *lda, complex *b, integer *ldb, 
00022         complex *x, integer *ldx, complex *xact, integer *ldxact, real *ferr, 
00023         real *berr, real *reslts)
00024 {
00025     /* System generated locals */
00026     integer a_dim1, a_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, 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 /*  CTRT05 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 n by n 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 / ( (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 /*  A       (input) COMPLEX array, dimension (LDA,N) */
00102 /*          The triangular matrix A.  If UPLO = 'U', the leading n by n */
00103 /*          upper triangular part of the array A contains the upper */
00104 /*          triangular matrix, and the strictly lower triangular part of */
00105 /*          A is not referenced.  If UPLO = 'L', the leading n by n lower */
00106 /*          triangular part of the array A contains the lower triangular */
00107 /*          matrix, and the strictly upper triangular part of A is not */
00108 /*          referenced.  If DIAG = 'U', the diagonal elements of A are */
00109 /*          also not referenced and are assumed to be 1. */
00110 
00111 /*  LDA     (input) INTEGER */
00112 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00113 
00114 /*  B       (input) COMPLEX array, dimension (LDB,NRHS) */
00115 /*          The right hand side vectors for the system of linear */
00116 /*          equations. */
00117 
00118 /*  LDB     (input) INTEGER */
00119 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00120 
00121 /*  X       (input) COMPLEX array, dimension (LDX,NRHS) */
00122 /*          The computed solution vectors.  Each vector is stored as a */
00123 /*          column of the matrix X. */
00124 
00125 /*  LDX     (input) INTEGER */
00126 /*          The leading dimension of the array X.  LDX >= max(1,N). */
00127 
00128 /*  XACT    (input) COMPLEX array, dimension (LDX,NRHS) */
00129 /*          The exact solution vectors.  Each vector is stored as a */
00130 /*          column of the matrix XACT. */
00131 
00132 /*  LDXACT  (input) INTEGER */
00133 /*          The leading dimension of the array XACT.  LDXACT >= max(1,N). */
00134 
00135 /*  FERR    (input) REAL array, dimension (NRHS) */
00136 /*          The estimated forward error bounds for each solution vector */
00137 /*          X.  If XTRUE is the true solution, FERR bounds the magnitude */
00138 /*          of the largest entry in (X - XTRUE) divided by the magnitude */
00139 /*          of the largest entry in X. */
00140 
00141 /*  BERR    (input) REAL array, dimension (NRHS) */
00142 /*          The componentwise relative backward error of each solution */
00143 /*          vector (i.e., the smallest relative change in any entry of A */
00144 /*          or B that makes X an exact solution). */
00145 
00146 /*  RESLTS  (output) REAL array, dimension (2) */
00147 /*          The maximum over the NRHS solution vectors of the ratios: */
00148 /*          RESLTS(1) = norm(X - XACT) / ( norm(X) * FERR ) */
00149 /*          RESLTS(2) = BERR / ( (n+1)*EPS + (*) ) */
00150 
00151 /*  ===================================================================== */
00152 
00153 /*     .. Parameters .. */
00154 /*     .. */
00155 /*     .. Local Scalars .. */
00156 /*     .. */
00157 /*     .. External Functions .. */
00158 /*     .. */
00159 /*     .. Intrinsic Functions .. */
00160 /*     .. */
00161 /*     .. Statement Functions .. */
00162 /*     .. */
00163 /*     .. Statement Function definitions .. */
00164 /*     .. */
00165 /*     .. Executable Statements .. */
00166 
00167 /*     Quick exit if N = 0 or NRHS = 0. */
00168 
00169     /* Parameter adjustments */
00170     a_dim1 = *lda;
00171     a_offset = 1 + a_dim1;
00172     a -= a_offset;
00173     b_dim1 = *ldb;
00174     b_offset = 1 + b_dim1;
00175     b -= b_offset;
00176     x_dim1 = *ldx;
00177     x_offset = 1 + x_dim1;
00178     x -= x_offset;
00179     xact_dim1 = *ldxact;
00180     xact_offset = 1 + xact_dim1;
00181     xact -= xact_offset;
00182     --ferr;
00183     --berr;
00184     --reslts;
00185 
00186     /* Function Body */
00187     if (*n <= 0 || *nrhs <= 0) {
00188         reslts[1] = 0.f;
00189         reslts[2] = 0.f;
00190         return 0;
00191     }
00192 
00193     eps = slamch_("Epsilon");
00194     unfl = slamch_("Safe minimum");
00195     ovfl = 1.f / unfl;
00196     upper = lsame_(uplo, "U");
00197     notran = lsame_(trans, "N");
00198     unit = lsame_(diag, "U");
00199 
00200 /*     Test 1:  Compute the maximum of */
00201 /*        norm(X - XACT) / ( norm(X) * FERR ) */
00202 /*     over all the vectors X and XACT using the infinity-norm. */
00203 
00204     errbnd = 0.f;
00205     i__1 = *nrhs;
00206     for (j = 1; j <= i__1; ++j) {
00207         imax = icamax_(n, &x[j * x_dim1 + 1], &c__1);
00208 /* Computing MAX */
00209         i__2 = imax + j * x_dim1;
00210         r__3 = (r__1 = x[i__2].r, dabs(r__1)) + (r__2 = r_imag(&x[imax + j * 
00211                 x_dim1]), dabs(r__2));
00212         xnorm = dmax(r__3,unfl);
00213         diff = 0.f;
00214         i__2 = *n;
00215         for (i__ = 1; i__ <= i__2; ++i__) {
00216             i__3 = i__ + j * x_dim1;
00217             i__4 = i__ + j * xact_dim1;
00218             q__2.r = x[i__3].r - xact[i__4].r, q__2.i = x[i__3].i - xact[i__4]
00219                     .i;
00220             q__1.r = q__2.r, q__1.i = q__2.i;
00221 /* Computing MAX */
00222             r__3 = diff, r__4 = (r__1 = q__1.r, dabs(r__1)) + (r__2 = r_imag(&
00223                     q__1), dabs(r__2));
00224             diff = dmax(r__3,r__4);
00225 /* L10: */
00226         }
00227 
00228         if (xnorm > 1.f) {
00229             goto L20;
00230         } else if (diff <= ovfl * xnorm) {
00231             goto L20;
00232         } else {
00233             errbnd = 1.f / eps;
00234             goto L30;
00235         }
00236 
00237 L20:
00238         if (diff / xnorm <= ferr[j]) {
00239 /* Computing MAX */
00240             r__1 = errbnd, r__2 = diff / xnorm / ferr[j];
00241             errbnd = dmax(r__1,r__2);
00242         } else {
00243             errbnd = 1.f / eps;
00244         }
00245 L30:
00246         ;
00247     }
00248     reslts[1] = errbnd;
00249 
00250 /*     Test 2:  Compute the maximum of BERR / ( (n+1)*EPS + (*) ), where */
00251 /*     (*) = (n+1)*UNFL / (min_i (abs(A)*abs(X) +abs(b))_i ) */
00252 
00253     ifu = 0;
00254     if (unit) {
00255         ifu = 1;
00256     }
00257     i__1 = *nrhs;
00258     for (k = 1; k <= i__1; ++k) {
00259         i__2 = *n;
00260         for (i__ = 1; i__ <= i__2; ++i__) {
00261             i__3 = i__ + k * b_dim1;
00262             tmp = (r__1 = b[i__3].r, dabs(r__1)) + (r__2 = r_imag(&b[i__ + k *
00263                      b_dim1]), dabs(r__2));
00264             if (upper) {
00265                 if (! notran) {
00266                     i__3 = i__ - ifu;
00267                     for (j = 1; j <= i__3; ++j) {
00268                         i__4 = j + i__ * a_dim1;
00269                         i__5 = j + k * x_dim1;
00270                         tmp += ((r__1 = a[i__4].r, dabs(r__1)) + (r__2 = 
00271                                 r_imag(&a[j + i__ * a_dim1]), dabs(r__2))) * (
00272                                 (r__3 = x[i__5].r, dabs(r__3)) + (r__4 = 
00273                                 r_imag(&x[j + k * x_dim1]), dabs(r__4)));
00274 /* L40: */
00275                     }
00276                     if (unit) {
00277                         i__3 = i__ + k * x_dim1;
00278                         tmp += (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = 
00279                                 r_imag(&x[i__ + k * x_dim1]), dabs(r__2));
00280                     }
00281                 } else {
00282                     if (unit) {
00283                         i__3 = i__ + k * x_dim1;
00284                         tmp += (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = 
00285                                 r_imag(&x[i__ + k * x_dim1]), dabs(r__2));
00286                     }
00287                     i__3 = *n;
00288                     for (j = i__ + ifu; j <= i__3; ++j) {
00289                         i__4 = i__ + j * a_dim1;
00290                         i__5 = j + k * x_dim1;
00291                         tmp += ((r__1 = a[i__4].r, dabs(r__1)) + (r__2 = 
00292                                 r_imag(&a[i__ + j * a_dim1]), dabs(r__2))) * (
00293                                 (r__3 = x[i__5].r, dabs(r__3)) + (r__4 = 
00294                                 r_imag(&x[j + k * x_dim1]), dabs(r__4)));
00295 /* L50: */
00296                     }
00297                 }
00298             } else {
00299                 if (notran) {
00300                     i__3 = i__ - ifu;
00301                     for (j = 1; j <= i__3; ++j) {
00302                         i__4 = i__ + j * a_dim1;
00303                         i__5 = j + k * x_dim1;
00304                         tmp += ((r__1 = a[i__4].r, dabs(r__1)) + (r__2 = 
00305                                 r_imag(&a[i__ + j * a_dim1]), dabs(r__2))) * (
00306                                 (r__3 = x[i__5].r, dabs(r__3)) + (r__4 = 
00307                                 r_imag(&x[j + k * x_dim1]), dabs(r__4)));
00308 /* L60: */
00309                     }
00310                     if (unit) {
00311                         i__3 = i__ + k * x_dim1;
00312                         tmp += (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = 
00313                                 r_imag(&x[i__ + k * x_dim1]), dabs(r__2));
00314                     }
00315                 } else {
00316                     if (unit) {
00317                         i__3 = i__ + k * x_dim1;
00318                         tmp += (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = 
00319                                 r_imag(&x[i__ + k * x_dim1]), dabs(r__2));
00320                     }
00321                     i__3 = *n;
00322                     for (j = i__ + ifu; j <= i__3; ++j) {
00323                         i__4 = j + i__ * a_dim1;
00324                         i__5 = j + k * x_dim1;
00325                         tmp += ((r__1 = a[i__4].r, dabs(r__1)) + (r__2 = 
00326                                 r_imag(&a[j + i__ * a_dim1]), dabs(r__2))) * (
00327                                 (r__3 = x[i__5].r, dabs(r__3)) + (r__4 = 
00328                                 r_imag(&x[j + k * x_dim1]), dabs(r__4)));
00329 /* L70: */
00330                     }
00331                 }
00332             }
00333             if (i__ == 1) {
00334                 axbi = tmp;
00335             } else {
00336                 axbi = dmin(axbi,tmp);
00337             }
00338 /* L80: */
00339         }
00340 /* Computing MAX */
00341         r__1 = axbi, r__2 = (*n + 1) * unfl;
00342         tmp = berr[k] / ((*n + 1) * eps + (*n + 1) * unfl / dmax(r__1,r__2));
00343         if (k == 1) {
00344             reslts[2] = tmp;
00345         } else {
00346             reslts[2] = dmax(reslts[2],tmp);
00347         }
00348 /* L90: */
00349     }
00350 
00351     return 0;
00352 
00353 /*     End of CTRT05 */
00354 
00355 } /* ctrt05_ */


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