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


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