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


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