dsprfs.c
Go to the documentation of this file.
00001 /* dsprfs.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_b12 = -1.;
00020 static doublereal c_b14 = 1.;
00021 
00022 /* Subroutine */ int dsprfs_(char *uplo, integer *n, integer *nrhs, 
00023         doublereal *ap, doublereal *afp, integer *ipiv, doublereal *b, 
00024         integer *ldb, doublereal *x, integer *ldx, doublereal *ferr, 
00025         doublereal *berr, doublereal *work, integer *iwork, integer *info)
00026 {
00027     /* System generated locals */
00028     integer b_dim1, b_offset, x_dim1, x_offset, i__1, i__2, i__3;
00029     doublereal d__1, d__2, d__3;
00030 
00031     /* Local variables */
00032     integer i__, j, k;
00033     doublereal s;
00034     integer ik, kk;
00035     doublereal xk;
00036     integer nz;
00037     doublereal eps;
00038     integer kase;
00039     doublereal safe1, safe2;
00040     extern logical lsame_(char *, char *);
00041     integer isave[3];
00042     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, 
00043             doublereal *, integer *), daxpy_(integer *, doublereal *, 
00044             doublereal *, integer *, doublereal *, integer *);
00045     integer count;
00046     extern /* Subroutine */ int dspmv_(char *, integer *, doublereal *, 
00047             doublereal *, doublereal *, integer *, doublereal *, doublereal *, 
00048              integer *);
00049     logical upper;
00050     extern /* Subroutine */ int dlacn2_(integer *, doublereal *, doublereal *, 
00051              integer *, doublereal *, integer *, integer *);
00052     extern doublereal dlamch_(char *);
00053     doublereal safmin;
00054     extern /* Subroutine */ int xerbla_(char *, integer *);
00055     doublereal lstres;
00056     extern /* Subroutine */ int dsptrs_(char *, integer *, integer *, 
00057             doublereal *, integer *, doublereal *, integer *, integer *);
00058 
00059 
00060 /*  -- LAPACK routine (version 3.2) -- */
00061 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00062 /*     November 2006 */
00063 
00064 /*     Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH. */
00065 
00066 /*     .. Scalar Arguments .. */
00067 /*     .. */
00068 /*     .. Array Arguments .. */
00069 /*     .. */
00070 
00071 /*  Purpose */
00072 /*  ======= */
00073 
00074 /*  DSPRFS improves the computed solution to a system of linear */
00075 /*  equations when the coefficient matrix is symmetric indefinite */
00076 /*  and packed, and provides error bounds and backward error estimates */
00077 /*  for the solution. */
00078 
00079 /*  Arguments */
00080 /*  ========= */
00081 
00082 /*  UPLO    (input) CHARACTER*1 */
00083 /*          = 'U':  Upper triangle of A is stored; */
00084 /*          = 'L':  Lower triangle of A is stored. */
00085 
00086 /*  N       (input) INTEGER */
00087 /*          The order of the matrix A.  N >= 0. */
00088 
00089 /*  NRHS    (input) INTEGER */
00090 /*          The number of right hand sides, i.e., the number of columns */
00091 /*          of the matrices B and X.  NRHS >= 0. */
00092 
00093 /*  AP      (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
00094 /*          The upper or lower triangle of the symmetric matrix A, packed */
00095 /*          columnwise in a linear array.  The j-th column of A is stored */
00096 /*          in the array AP as follows: */
00097 /*          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
00098 /*          if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */
00099 
00100 /*  AFP     (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
00101 /*          The factored form of the matrix A.  AFP contains the block */
00102 /*          diagonal matrix D and the multipliers used to obtain the */
00103 /*          factor U or L from the factorization A = U*D*U**T or */
00104 /*          A = L*D*L**T as computed by DSPTRF, stored as a packed */
00105 /*          triangular matrix. */
00106 
00107 /*  IPIV    (input) INTEGER array, dimension (N) */
00108 /*          Details of the interchanges and the block structure of D */
00109 /*          as determined by DSPTRF. */
00110 
00111 /*  B       (input) DOUBLE PRECISION 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/output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
00118 /*          On entry, the solution matrix X, as computed by DSPTRS. */
00119 /*          On exit, the improved solution matrix X. */
00120 
00121 /*  LDX     (input) INTEGER */
00122 /*          The leading dimension of the array X.  LDX >= max(1,N). */
00123 
00124 /*  FERR    (output) DOUBLE PRECISION array, dimension (NRHS) */
00125 /*          The estimated forward error bound for each solution vector */
00126 /*          X(j) (the j-th column of the solution matrix X). */
00127 /*          If XTRUE is the true solution corresponding to X(j), FERR(j) */
00128 /*          is an estimated upper bound for the magnitude of the largest */
00129 /*          element in (X(j) - XTRUE) divided by the magnitude of the */
00130 /*          largest element in X(j).  The estimate is as reliable as */
00131 /*          the estimate for RCOND, and is almost always a slight */
00132 /*          overestimate of the true error. */
00133 
00134 /*  BERR    (output) DOUBLE PRECISION array, dimension (NRHS) */
00135 /*          The componentwise relative backward error of each solution */
00136 /*          vector X(j) (i.e., the smallest relative change in */
00137 /*          any element of A or B that makes X(j) an exact solution). */
00138 
00139 /*  WORK    (workspace) DOUBLE PRECISION array, dimension (3*N) */
00140 
00141 /*  IWORK   (workspace) INTEGER array, dimension (N) */
00142 
00143 /*  INFO    (output) INTEGER */
00144 /*          = 0:  successful exit */
00145 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00146 
00147 /*  Internal Parameters */
00148 /*  =================== */
00149 
00150 /*  ITMAX is the maximum number of steps of iterative refinement. */
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     --ap;
00172     --afp;
00173     --ipiv;
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     if (! upper && ! lsame_(uplo, "L")) {
00189         *info = -1;
00190     } else if (*n < 0) {
00191         *info = -2;
00192     } else if (*nrhs < 0) {
00193         *info = -3;
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_("DSPRFS", &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.;
00211             berr[j] = 0.;
00212 /* L10: */
00213         }
00214         return 0;
00215     }
00216 
00217 /*     NZ = maximum number of nonzero elements in each row of A, plus 1 */
00218 
00219     nz = *n + 1;
00220     eps = dlamch_("Epsilon");
00221     safmin = dlamch_("Safe minimum");
00222     safe1 = nz * safmin;
00223     safe2 = safe1 / eps;
00224 
00225 /*     Do for each right hand side */
00226 
00227     i__1 = *nrhs;
00228     for (j = 1; j <= i__1; ++j) {
00229 
00230         count = 1;
00231         lstres = 3.;
00232 L20:
00233 
00234 /*        Loop until stopping criterion is satisfied. */
00235 
00236 /*        Compute residual R = B - A * X */
00237 
00238         dcopy_(n, &b[j * b_dim1 + 1], &c__1, &work[*n + 1], &c__1);
00239         dspmv_(uplo, n, &c_b12, &ap[1], &x[j * x_dim1 + 1], &c__1, &c_b14, &
00240                 work[*n + 1], &c__1);
00241 
00242 /*        Compute componentwise relative backward error from formula */
00243 
00244 /*        max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) */
00245 
00246 /*        where abs(Z) is the componentwise absolute value of the matrix */
00247 /*        or vector Z.  If the i-th component of the denominator is less */
00248 /*        than SAFE2, then SAFE1 is added to the i-th components of the */
00249 /*        numerator and denominator before dividing. */
00250 
00251         i__2 = *n;
00252         for (i__ = 1; i__ <= i__2; ++i__) {
00253             work[i__] = (d__1 = b[i__ + j * b_dim1], abs(d__1));
00254 /* L30: */
00255         }
00256 
00257 /*        Compute abs(A)*abs(X) + abs(B). */
00258 
00259         kk = 1;
00260         if (upper) {
00261             i__2 = *n;
00262             for (k = 1; k <= i__2; ++k) {
00263                 s = 0.;
00264                 xk = (d__1 = x[k + j * x_dim1], abs(d__1));
00265                 ik = kk;
00266                 i__3 = k - 1;
00267                 for (i__ = 1; i__ <= i__3; ++i__) {
00268                     work[i__] += (d__1 = ap[ik], abs(d__1)) * xk;
00269                     s += (d__1 = ap[ik], abs(d__1)) * (d__2 = x[i__ + j * 
00270                             x_dim1], abs(d__2));
00271                     ++ik;
00272 /* L40: */
00273                 }
00274                 work[k] = work[k] + (d__1 = ap[kk + k - 1], abs(d__1)) * xk + 
00275                         s;
00276                 kk += k;
00277 /* L50: */
00278             }
00279         } else {
00280             i__2 = *n;
00281             for (k = 1; k <= i__2; ++k) {
00282                 s = 0.;
00283                 xk = (d__1 = x[k + j * x_dim1], abs(d__1));
00284                 work[k] += (d__1 = ap[kk], abs(d__1)) * xk;
00285                 ik = kk + 1;
00286                 i__3 = *n;
00287                 for (i__ = k + 1; i__ <= i__3; ++i__) {
00288                     work[i__] += (d__1 = ap[ik], abs(d__1)) * xk;
00289                     s += (d__1 = ap[ik], abs(d__1)) * (d__2 = x[i__ + j * 
00290                             x_dim1], abs(d__2));
00291                     ++ik;
00292 /* L60: */
00293                 }
00294                 work[k] += s;
00295                 kk += *n - k + 1;
00296 /* L70: */
00297             }
00298         }
00299         s = 0.;
00300         i__2 = *n;
00301         for (i__ = 1; i__ <= i__2; ++i__) {
00302             if (work[i__] > safe2) {
00303 /* Computing MAX */
00304                 d__2 = s, d__3 = (d__1 = work[*n + i__], abs(d__1)) / work[
00305                         i__];
00306                 s = max(d__2,d__3);
00307             } else {
00308 /* Computing MAX */
00309                 d__2 = s, d__3 = ((d__1 = work[*n + i__], abs(d__1)) + safe1) 
00310                         / (work[i__] + safe1);
00311                 s = max(d__2,d__3);
00312             }
00313 /* L80: */
00314         }
00315         berr[j] = s;
00316 
00317 /*        Test stopping criterion. Continue iterating if */
00318 /*           1) The residual BERR(J) is larger than machine epsilon, and */
00319 /*           2) BERR(J) decreased by at least a factor of 2 during the */
00320 /*              last iteration, and */
00321 /*           3) At most ITMAX iterations tried. */
00322 
00323         if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) {
00324 
00325 /*           Update solution and try again. */
00326 
00327             dsptrs_(uplo, n, &c__1, &afp[1], &ipiv[1], &work[*n + 1], n, info);
00328             daxpy_(n, &c_b14, &work[*n + 1], &c__1, &x[j * x_dim1 + 1], &c__1)
00329                     ;
00330             lstres = berr[j];
00331             ++count;
00332             goto L20;
00333         }
00334 
00335 /*        Bound error from formula */
00336 
00337 /*        norm(X - XTRUE) / norm(X) .le. FERR = */
00338 /*        norm( abs(inv(A))* */
00339 /*           ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) */
00340 
00341 /*        where */
00342 /*          norm(Z) is the magnitude of the largest component of Z */
00343 /*          inv(A) is the inverse of A */
00344 /*          abs(Z) is the componentwise absolute value of the matrix or */
00345 /*             vector Z */
00346 /*          NZ is the maximum number of nonzeros in any row of A, plus 1 */
00347 /*          EPS is machine epsilon */
00348 
00349 /*        The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) */
00350 /*        is incremented by SAFE1 if the i-th component of */
00351 /*        abs(A)*abs(X) + abs(B) is less than SAFE2. */
00352 
00353 /*        Use DLACN2 to estimate the infinity-norm of the matrix */
00354 /*           inv(A) * diag(W), */
00355 /*        where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) */
00356 
00357         i__2 = *n;
00358         for (i__ = 1; i__ <= i__2; ++i__) {
00359             if (work[i__] > safe2) {
00360                 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps * 
00361                         work[i__];
00362             } else {
00363                 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps * 
00364                         work[i__] + safe1;
00365             }
00366 /* L90: */
00367         }
00368 
00369         kase = 0;
00370 L100:
00371         dlacn2_(n, &work[(*n << 1) + 1], &work[*n + 1], &iwork[1], &ferr[j], &
00372                 kase, isave);
00373         if (kase != 0) {
00374             if (kase == 1) {
00375 
00376 /*              Multiply by diag(W)*inv(A'). */
00377 
00378                 dsptrs_(uplo, n, &c__1, &afp[1], &ipiv[1], &work[*n + 1], n, 
00379                         info);
00380                 i__2 = *n;
00381                 for (i__ = 1; i__ <= i__2; ++i__) {
00382                     work[*n + i__] = work[i__] * work[*n + i__];
00383 /* L110: */
00384                 }
00385             } else if (kase == 2) {
00386 
00387 /*              Multiply by inv(A)*diag(W). */
00388 
00389                 i__2 = *n;
00390                 for (i__ = 1; i__ <= i__2; ++i__) {
00391                     work[*n + i__] = work[i__] * work[*n + i__];
00392 /* L120: */
00393                 }
00394                 dsptrs_(uplo, n, &c__1, &afp[1], &ipiv[1], &work[*n + 1], n, 
00395                         info);
00396             }
00397             goto L100;
00398         }
00399 
00400 /*        Normalize error. */
00401 
00402         lstres = 0.;
00403         i__2 = *n;
00404         for (i__ = 1; i__ <= i__2; ++i__) {
00405 /* Computing MAX */
00406             d__2 = lstres, d__3 = (d__1 = x[i__ + j * x_dim1], abs(d__1));
00407             lstres = max(d__2,d__3);
00408 /* L130: */
00409         }
00410         if (lstres != 0.) {
00411             ferr[j] /= lstres;
00412         }
00413 
00414 /* L140: */
00415     }
00416 
00417     return 0;
00418 
00419 /*     End of DSPRFS */
00420 
00421 } /* dsprfs_ */


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