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


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