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


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