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


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