stbrfs.c
Go to the documentation of this file.
00001 /* stbrfs.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 static real c_b19 = -1.f;
00020 
00021 /* Subroutine */ int stbrfs_(char *uplo, char *trans, char *diag, integer *n, 
00022         integer *kd, integer *nrhs, real *ab, integer *ldab, real *b, integer 
00023         *ldb, real *x, integer *ldx, real *ferr, real *berr, real *work, 
00024         integer *iwork, integer *info)
00025 {
00026     /* System generated locals */
00027     integer ab_dim1, ab_offset, b_dim1, b_offset, x_dim1, x_offset, i__1, 
00028             i__2, i__3, i__4, i__5;
00029     real r__1, r__2, r__3;
00030 
00031     /* Local variables */
00032     integer i__, j, k;
00033     real s, xk;
00034     integer nz;
00035     real eps;
00036     integer kase;
00037     real safe1, safe2;
00038     extern logical lsame_(char *, char *);
00039     integer isave[3];
00040     logical upper;
00041     extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, 
00042             integer *), stbmv_(char *, char *, char *, integer *, integer *, 
00043             real *, integer *, real *, integer *), 
00044             stbsv_(char *, char *, char *, integer *, integer *, real *, 
00045             integer *, real *, integer *), saxpy_(
00046             integer *, real *, real *, integer *, real *, integer *), slacn2_(
00047             integer *, real *, real *, integer *, real *, integer *, integer *
00048 );
00049     extern doublereal slamch_(char *);
00050     real safmin;
00051     extern /* Subroutine */ int xerbla_(char *, integer *);
00052     logical notran;
00053     char transt[1];
00054     logical nounit;
00055     real lstres;
00056 
00057 
00058 /*  -- LAPACK routine (version 3.2) -- */
00059 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00060 /*     November 2006 */
00061 
00062 /*     Modified to call SLACN2 in place of SLACON, 7 Feb 03, SJH. */
00063 
00064 /*     .. Scalar Arguments .. */
00065 /*     .. */
00066 /*     .. Array Arguments .. */
00067 /*     .. */
00068 
00069 /*  Purpose */
00070 /*  ======= */
00071 
00072 /*  STBRFS provides error bounds and backward error estimates for the */
00073 /*  solution to a system of linear equations with a triangular band */
00074 /*  coefficient matrix. */
00075 
00076 /*  The solution matrix X must be computed by STBTRS or some other */
00077 /*  means before entering this routine.  STBRFS does not do iterative */
00078 /*  refinement because doing so cannot improve the backward error. */
00079 
00080 /*  Arguments */
00081 /*  ========= */
00082 
00083 /*  UPLO    (input) CHARACTER*1 */
00084 /*          = 'U':  A is upper triangular; */
00085 /*          = 'L':  A is lower triangular. */
00086 
00087 /*  TRANS   (input) CHARACTER*1 */
00088 /*          Specifies the form of the system of equations: */
00089 /*          = 'N':  A * X = B  (No transpose) */
00090 /*          = 'T':  A**T * X = B  (Transpose) */
00091 /*          = 'C':  A**H * X = B  (Conjugate transpose = Transpose) */
00092 
00093 /*  DIAG    (input) CHARACTER*1 */
00094 /*          = 'N':  A is non-unit triangular; */
00095 /*          = 'U':  A is unit triangular. */
00096 
00097 /*  N       (input) INTEGER */
00098 /*          The order of the matrix A.  N >= 0. */
00099 
00100 /*  KD      (input) INTEGER */
00101 /*          The number of superdiagonals or subdiagonals of the */
00102 /*          triangular band matrix A.  KD >= 0. */
00103 
00104 /*  NRHS    (input) INTEGER */
00105 /*          The number of right hand sides, i.e., the number of columns */
00106 /*          of the matrices B and X.  NRHS >= 0. */
00107 
00108 /*  AB      (input) REAL array, dimension (LDAB,N) */
00109 /*          The upper or lower triangular band matrix A, stored in the */
00110 /*          first kd+1 rows of the array. The j-th column of A is stored */
00111 /*          in the j-th column of the array AB as follows: */
00112 /*          if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; */
00113 /*          if UPLO = 'L', AB(1+i-j,j)    = A(i,j) for j<=i<=min(n,j+kd). */
00114 /*          If DIAG = 'U', the diagonal elements of A are not referenced */
00115 /*          and are assumed to be 1. */
00116 
00117 /*  LDAB    (input) INTEGER */
00118 /*          The leading dimension of the array AB.  LDAB >= KD+1. */
00119 
00120 /*  B       (input) REAL array, dimension (LDB,NRHS) */
00121 /*          The right hand side matrix B. */
00122 
00123 /*  LDB     (input) INTEGER */
00124 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00125 
00126 /*  X       (input) REAL array, dimension (LDX,NRHS) */
00127 /*          The solution matrix X. */
00128 
00129 /*  LDX     (input) INTEGER */
00130 /*          The leading dimension of the array X.  LDX >= max(1,N). */
00131 
00132 /*  FERR    (output) REAL array, dimension (NRHS) */
00133 /*          The estimated forward error bound for each solution vector */
00134 /*          X(j) (the j-th column of the solution matrix X). */
00135 /*          If XTRUE is the true solution corresponding to X(j), FERR(j) */
00136 /*          is an estimated upper bound for the magnitude of the largest */
00137 /*          element in (X(j) - XTRUE) divided by the magnitude of the */
00138 /*          largest element in X(j).  The estimate is as reliable as */
00139 /*          the estimate for RCOND, and is almost always a slight */
00140 /*          overestimate of the true error. */
00141 
00142 /*  BERR    (output) REAL array, dimension (NRHS) */
00143 /*          The componentwise relative backward error of each solution */
00144 /*          vector X(j) (i.e., the smallest relative change in */
00145 /*          any element of A or B that makes X(j) an exact solution). */
00146 
00147 /*  WORK    (workspace) REAL array, dimension (3*N) */
00148 
00149 /*  IWORK   (workspace) INTEGER array, dimension (N) */
00150 
00151 /*  INFO    (output) INTEGER */
00152 /*          = 0:  successful exit */
00153 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00154 
00155 /*  ===================================================================== */
00156 
00157 /*     .. Parameters .. */
00158 /*     .. */
00159 /*     .. Local Scalars .. */
00160 /*     .. */
00161 /*     .. Local Arrays .. */
00162 /*     .. */
00163 /*     .. External Subroutines .. */
00164 /*     .. */
00165 /*     .. Intrinsic Functions .. */
00166 /*     .. */
00167 /*     .. External Functions .. */
00168 /*     .. */
00169 /*     .. Executable Statements .. */
00170 
00171 /*     Test the input parameters. */
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     --ferr;
00184     --berr;
00185     --work;
00186     --iwork;
00187 
00188     /* Function Body */
00189     *info = 0;
00190     upper = lsame_(uplo, "U");
00191     notran = lsame_(trans, "N");
00192     nounit = lsame_(diag, "N");
00193 
00194     if (! upper && ! lsame_(uplo, "L")) {
00195         *info = -1;
00196     } else if (! notran && ! lsame_(trans, "T") && ! 
00197             lsame_(trans, "C")) {
00198         *info = -2;
00199     } else if (! nounit && ! lsame_(diag, "U")) {
00200         *info = -3;
00201     } else if (*n < 0) {
00202         *info = -4;
00203     } else if (*kd < 0) {
00204         *info = -5;
00205     } else if (*nrhs < 0) {
00206         *info = -6;
00207     } else if (*ldab < *kd + 1) {
00208         *info = -8;
00209     } else if (*ldb < max(1,*n)) {
00210         *info = -10;
00211     } else if (*ldx < max(1,*n)) {
00212         *info = -12;
00213     }
00214     if (*info != 0) {
00215         i__1 = -(*info);
00216         xerbla_("STBRFS", &i__1);
00217         return 0;
00218     }
00219 
00220 /*     Quick return if possible */
00221 
00222     if (*n == 0 || *nrhs == 0) {
00223         i__1 = *nrhs;
00224         for (j = 1; j <= i__1; ++j) {
00225             ferr[j] = 0.f;
00226             berr[j] = 0.f;
00227 /* L10: */
00228         }
00229         return 0;
00230     }
00231 
00232     if (notran) {
00233         *(unsigned char *)transt = 'T';
00234     } else {
00235         *(unsigned char *)transt = 'N';
00236     }
00237 
00238 /*     NZ = maximum number of nonzero elements in each row of A, plus 1 */
00239 
00240     nz = *kd + 2;
00241     eps = slamch_("Epsilon");
00242     safmin = slamch_("Safe minimum");
00243     safe1 = nz * safmin;
00244     safe2 = safe1 / eps;
00245 
00246 /*     Do for each right hand side */
00247 
00248     i__1 = *nrhs;
00249     for (j = 1; j <= i__1; ++j) {
00250 
00251 /*        Compute residual R = B - op(A) * X, */
00252 /*        where op(A) = A or A', depending on TRANS. */
00253 
00254         scopy_(n, &x[j * x_dim1 + 1], &c__1, &work[*n + 1], &c__1);
00255         stbmv_(uplo, trans, diag, n, kd, &ab[ab_offset], ldab, &work[*n + 1], 
00256                 &c__1);
00257         saxpy_(n, &c_b19, &b[j * b_dim1 + 1], &c__1, &work[*n + 1], &c__1);
00258 
00259 /*        Compute componentwise relative backward error from formula */
00260 
00261 /*        max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) ) */
00262 
00263 /*        where abs(Z) is the componentwise absolute value of the matrix */
00264 /*        or vector Z.  If the i-th component of the denominator is less */
00265 /*        than SAFE2, then SAFE1 is added to the i-th components of the */
00266 /*        numerator and denominator before dividing. */
00267 
00268         i__2 = *n;
00269         for (i__ = 1; i__ <= i__2; ++i__) {
00270             work[i__] = (r__1 = b[i__ + j * b_dim1], dabs(r__1));
00271 /* L20: */
00272         }
00273 
00274         if (notran) {
00275 
00276 /*           Compute abs(A)*abs(X) + abs(B). */
00277 
00278             if (upper) {
00279                 if (nounit) {
00280                     i__2 = *n;
00281                     for (k = 1; k <= i__2; ++k) {
00282                         xk = (r__1 = x[k + j * x_dim1], dabs(r__1));
00283 /* Computing MAX */
00284                         i__3 = 1, i__4 = k - *kd;
00285                         i__5 = k;
00286                         for (i__ = max(i__3,i__4); i__ <= i__5; ++i__) {
00287                             work[i__] += (r__1 = ab[*kd + 1 + i__ - k + k * 
00288                                     ab_dim1], dabs(r__1)) * xk;
00289 /* L30: */
00290                         }
00291 /* L40: */
00292                     }
00293                 } else {
00294                     i__2 = *n;
00295                     for (k = 1; k <= i__2; ++k) {
00296                         xk = (r__1 = x[k + j * x_dim1], dabs(r__1));
00297 /* Computing MAX */
00298                         i__5 = 1, i__3 = k - *kd;
00299                         i__4 = k - 1;
00300                         for (i__ = max(i__5,i__3); i__ <= i__4; ++i__) {
00301                             work[i__] += (r__1 = ab[*kd + 1 + i__ - k + k * 
00302                                     ab_dim1], dabs(r__1)) * xk;
00303 /* L50: */
00304                         }
00305                         work[k] += xk;
00306 /* L60: */
00307                     }
00308                 }
00309             } else {
00310                 if (nounit) {
00311                     i__2 = *n;
00312                     for (k = 1; k <= i__2; ++k) {
00313                         xk = (r__1 = x[k + j * x_dim1], dabs(r__1));
00314 /* Computing MIN */
00315                         i__5 = *n, i__3 = k + *kd;
00316                         i__4 = min(i__5,i__3);
00317                         for (i__ = k; i__ <= i__4; ++i__) {
00318                             work[i__] += (r__1 = ab[i__ + 1 - k + k * ab_dim1]
00319                                     , dabs(r__1)) * xk;
00320 /* L70: */
00321                         }
00322 /* L80: */
00323                     }
00324                 } else {
00325                     i__2 = *n;
00326                     for (k = 1; k <= i__2; ++k) {
00327                         xk = (r__1 = x[k + j * x_dim1], dabs(r__1));
00328 /* Computing MIN */
00329                         i__5 = *n, i__3 = k + *kd;
00330                         i__4 = min(i__5,i__3);
00331                         for (i__ = k + 1; i__ <= i__4; ++i__) {
00332                             work[i__] += (r__1 = ab[i__ + 1 - k + k * ab_dim1]
00333                                     , dabs(r__1)) * xk;
00334 /* L90: */
00335                         }
00336                         work[k] += xk;
00337 /* L100: */
00338                     }
00339                 }
00340             }
00341         } else {
00342 
00343 /*           Compute abs(A')*abs(X) + abs(B). */
00344 
00345             if (upper) {
00346                 if (nounit) {
00347                     i__2 = *n;
00348                     for (k = 1; k <= i__2; ++k) {
00349                         s = 0.f;
00350 /* Computing MAX */
00351                         i__4 = 1, i__5 = k - *kd;
00352                         i__3 = k;
00353                         for (i__ = max(i__4,i__5); i__ <= i__3; ++i__) {
00354                             s += (r__1 = ab[*kd + 1 + i__ - k + k * ab_dim1], 
00355                                     dabs(r__1)) * (r__2 = x[i__ + j * x_dim1],
00356                                      dabs(r__2));
00357 /* L110: */
00358                         }
00359                         work[k] += s;
00360 /* L120: */
00361                     }
00362                 } else {
00363                     i__2 = *n;
00364                     for (k = 1; k <= i__2; ++k) {
00365                         s = (r__1 = x[k + j * x_dim1], dabs(r__1));
00366 /* Computing MAX */
00367                         i__3 = 1, i__4 = k - *kd;
00368                         i__5 = k - 1;
00369                         for (i__ = max(i__3,i__4); i__ <= i__5; ++i__) {
00370                             s += (r__1 = ab[*kd + 1 + i__ - k + k * ab_dim1], 
00371                                     dabs(r__1)) * (r__2 = x[i__ + j * x_dim1],
00372                                      dabs(r__2));
00373 /* L130: */
00374                         }
00375                         work[k] += s;
00376 /* L140: */
00377                     }
00378                 }
00379             } else {
00380                 if (nounit) {
00381                     i__2 = *n;
00382                     for (k = 1; k <= i__2; ++k) {
00383                         s = 0.f;
00384 /* Computing MIN */
00385                         i__3 = *n, i__4 = k + *kd;
00386                         i__5 = min(i__3,i__4);
00387                         for (i__ = k; i__ <= i__5; ++i__) {
00388                             s += (r__1 = ab[i__ + 1 - k + k * ab_dim1], dabs(
00389                                     r__1)) * (r__2 = x[i__ + j * x_dim1], 
00390                                     dabs(r__2));
00391 /* L150: */
00392                         }
00393                         work[k] += s;
00394 /* L160: */
00395                     }
00396                 } else {
00397                     i__2 = *n;
00398                     for (k = 1; k <= i__2; ++k) {
00399                         s = (r__1 = x[k + j * x_dim1], dabs(r__1));
00400 /* Computing MIN */
00401                         i__3 = *n, i__4 = k + *kd;
00402                         i__5 = min(i__3,i__4);
00403                         for (i__ = k + 1; i__ <= i__5; ++i__) {
00404                             s += (r__1 = ab[i__ + 1 - k + k * ab_dim1], dabs(
00405                                     r__1)) * (r__2 = x[i__ + j * x_dim1], 
00406                                     dabs(r__2));
00407 /* L170: */
00408                         }
00409                         work[k] += s;
00410 /* L180: */
00411                     }
00412                 }
00413             }
00414         }
00415         s = 0.f;
00416         i__2 = *n;
00417         for (i__ = 1; i__ <= i__2; ++i__) {
00418             if (work[i__] > safe2) {
00419 /* Computing MAX */
00420                 r__2 = s, r__3 = (r__1 = work[*n + i__], dabs(r__1)) / work[
00421                         i__];
00422                 s = dmax(r__2,r__3);
00423             } else {
00424 /* Computing MAX */
00425                 r__2 = s, r__3 = ((r__1 = work[*n + i__], dabs(r__1)) + safe1)
00426                          / (work[i__] + safe1);
00427                 s = dmax(r__2,r__3);
00428             }
00429 /* L190: */
00430         }
00431         berr[j] = s;
00432 
00433 /*        Bound error from formula */
00434 
00435 /*        norm(X - XTRUE) / norm(X) .le. FERR = */
00436 /*        norm( abs(inv(op(A)))* */
00437 /*           ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X) */
00438 
00439 /*        where */
00440 /*          norm(Z) is the magnitude of the largest component of Z */
00441 /*          inv(op(A)) is the inverse of op(A) */
00442 /*          abs(Z) is the componentwise absolute value of the matrix or */
00443 /*             vector Z */
00444 /*          NZ is the maximum number of nonzeros in any row of A, plus 1 */
00445 /*          EPS is machine epsilon */
00446 
00447 /*        The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B)) */
00448 /*        is incremented by SAFE1 if the i-th component of */
00449 /*        abs(op(A))*abs(X) + abs(B) is less than SAFE2. */
00450 
00451 /*        Use SLACN2 to estimate the infinity-norm of the matrix */
00452 /*           inv(op(A)) * diag(W), */
00453 /*        where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) */
00454 
00455         i__2 = *n;
00456         for (i__ = 1; i__ <= i__2; ++i__) {
00457             if (work[i__] > safe2) {
00458                 work[i__] = (r__1 = work[*n + i__], dabs(r__1)) + nz * eps * 
00459                         work[i__];
00460             } else {
00461                 work[i__] = (r__1 = work[*n + i__], dabs(r__1)) + nz * eps * 
00462                         work[i__] + safe1;
00463             }
00464 /* L200: */
00465         }
00466 
00467         kase = 0;
00468 L210:
00469         slacn2_(n, &work[(*n << 1) + 1], &work[*n + 1], &iwork[1], &ferr[j], &
00470                 kase, isave);
00471         if (kase != 0) {
00472             if (kase == 1) {
00473 
00474 /*              Multiply by diag(W)*inv(op(A)'). */
00475 
00476                 stbsv_(uplo, transt, diag, n, kd, &ab[ab_offset], ldab, &work[
00477                         *n + 1], &c__1);
00478                 i__2 = *n;
00479                 for (i__ = 1; i__ <= i__2; ++i__) {
00480                     work[*n + i__] = work[i__] * work[*n + i__];
00481 /* L220: */
00482                 }
00483             } else {
00484 
00485 /*              Multiply by inv(op(A))*diag(W). */
00486 
00487                 i__2 = *n;
00488                 for (i__ = 1; i__ <= i__2; ++i__) {
00489                     work[*n + i__] = work[i__] * work[*n + i__];
00490 /* L230: */
00491                 }
00492                 stbsv_(uplo, trans, diag, n, kd, &ab[ab_offset], ldab, &work[*
00493                         n + 1], &c__1);
00494             }
00495             goto L210;
00496         }
00497 
00498 /*        Normalize error. */
00499 
00500         lstres = 0.f;
00501         i__2 = *n;
00502         for (i__ = 1; i__ <= i__2; ++i__) {
00503 /* Computing MAX */
00504             r__2 = lstres, r__3 = (r__1 = x[i__ + j * x_dim1], dabs(r__1));
00505             lstres = dmax(r__2,r__3);
00506 /* L240: */
00507         }
00508         if (lstres != 0.f) {
00509             ferr[j] /= lstres;
00510         }
00511 
00512 /* L250: */
00513     }
00514 
00515     return 0;
00516 
00517 /*     End of STBRFS */
00518 
00519 } /* stbrfs_ */


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