dpprfs.c
Go to the documentation of this file.
00001 /* dpprfs.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 dpprfs_(char *uplo, integer *n, integer *nrhs, 
00023         doublereal *ap, doublereal *afp, doublereal *b, integer *ldb, 
00024         doublereal *x, integer *ldx, doublereal *ferr, doublereal *berr, 
00025         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 dpptrs_(char *, integer *, integer *, 
00057             doublereal *, 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 /*  DPPRFS improves the computed solution to a system of linear */
00075 /*  equations when the coefficient matrix is symmetric positive definite */
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)*(2n-j)/2) = A(i,j) for j<=i<=n. */
00099 
00100 /*  AFP     (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
00101 /*          The triangular factor U or L from the Cholesky factorization */
00102 /*          A = U**T*U or A = L*L**T, as computed by DPPTRF/ZPPTRF, */
00103 /*          packed columnwise in a linear array in the same format as A */
00104 /*          (see AP). */
00105 
00106 /*  B       (input) DOUBLE PRECISION array, dimension (LDB,NRHS) */
00107 /*          The right hand side matrix B. */
00108 
00109 /*  LDB     (input) INTEGER */
00110 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00111 
00112 /*  X       (input/output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
00113 /*          On entry, the solution matrix X, as computed by DPPTRS. */
00114 /*          On exit, the improved solution matrix X. */
00115 
00116 /*  LDX     (input) INTEGER */
00117 /*          The leading dimension of the array X.  LDX >= max(1,N). */
00118 
00119 /*  FERR    (output) DOUBLE PRECISION array, dimension (NRHS) */
00120 /*          The estimated forward error bound for each solution vector */
00121 /*          X(j) (the j-th column of the solution matrix X). */
00122 /*          If XTRUE is the true solution corresponding to X(j), FERR(j) */
00123 /*          is an estimated upper bound for the magnitude of the largest */
00124 /*          element in (X(j) - XTRUE) divided by the magnitude of the */
00125 /*          largest element in X(j).  The estimate is as reliable as */
00126 /*          the estimate for RCOND, and is almost always a slight */
00127 /*          overestimate of the true error. */
00128 
00129 /*  BERR    (output) DOUBLE PRECISION array, dimension (NRHS) */
00130 /*          The componentwise relative backward error of each solution */
00131 /*          vector X(j) (i.e., the smallest relative change in */
00132 /*          any element of A or B that makes X(j) an exact solution). */
00133 
00134 /*  WORK    (workspace) DOUBLE PRECISION array, dimension (3*N) */
00135 
00136 /*  IWORK   (workspace) INTEGER array, dimension (N) */
00137 
00138 /*  INFO    (output) INTEGER */
00139 /*          = 0:  successful exit */
00140 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00141 
00142 /*  Internal Parameters */
00143 /*  =================== */
00144 
00145 /*  ITMAX is the maximum number of steps of iterative refinement. */
00146 
00147 /*  ===================================================================== */
00148 
00149 /*     .. Parameters .. */
00150 /*     .. */
00151 /*     .. Local Scalars .. */
00152 /*     .. */
00153 /*     .. Local Arrays .. */
00154 /*     .. */
00155 /*     .. External Subroutines .. */
00156 /*     .. */
00157 /*     .. Intrinsic Functions .. */
00158 /*     .. */
00159 /*     .. External Functions .. */
00160 /*     .. */
00161 /*     .. Executable Statements .. */
00162 
00163 /*     Test the input parameters. */
00164 
00165     /* Parameter adjustments */
00166     --ap;
00167     --afp;
00168     b_dim1 = *ldb;
00169     b_offset = 1 + b_dim1;
00170     b -= b_offset;
00171     x_dim1 = *ldx;
00172     x_offset = 1 + x_dim1;
00173     x -= x_offset;
00174     --ferr;
00175     --berr;
00176     --work;
00177     --iwork;
00178 
00179     /* Function Body */
00180     *info = 0;
00181     upper = lsame_(uplo, "U");
00182     if (! upper && ! lsame_(uplo, "L")) {
00183         *info = -1;
00184     } else if (*n < 0) {
00185         *info = -2;
00186     } else if (*nrhs < 0) {
00187         *info = -3;
00188     } else if (*ldb < max(1,*n)) {
00189         *info = -7;
00190     } else if (*ldx < max(1,*n)) {
00191         *info = -9;
00192     }
00193     if (*info != 0) {
00194         i__1 = -(*info);
00195         xerbla_("DPPRFS", &i__1);
00196         return 0;
00197     }
00198 
00199 /*     Quick return if possible */
00200 
00201     if (*n == 0 || *nrhs == 0) {
00202         i__1 = *nrhs;
00203         for (j = 1; j <= i__1; ++j) {
00204             ferr[j] = 0.;
00205             berr[j] = 0.;
00206 /* L10: */
00207         }
00208         return 0;
00209     }
00210 
00211 /*     NZ = maximum number of nonzero elements in each row of A, plus 1 */
00212 
00213     nz = *n + 1;
00214     eps = dlamch_("Epsilon");
00215     safmin = dlamch_("Safe minimum");
00216     safe1 = nz * safmin;
00217     safe2 = safe1 / eps;
00218 
00219 /*     Do for each right hand side */
00220 
00221     i__1 = *nrhs;
00222     for (j = 1; j <= i__1; ++j) {
00223 
00224         count = 1;
00225         lstres = 3.;
00226 L20:
00227 
00228 /*        Loop until stopping criterion is satisfied. */
00229 
00230 /*        Compute residual R = B - A * X */
00231 
00232         dcopy_(n, &b[j * b_dim1 + 1], &c__1, &work[*n + 1], &c__1);
00233         dspmv_(uplo, n, &c_b12, &ap[1], &x[j * x_dim1 + 1], &c__1, &c_b14, &
00234                 work[*n + 1], &c__1);
00235 
00236 /*        Compute componentwise relative backward error from formula */
00237 
00238 /*        max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) */
00239 
00240 /*        where abs(Z) is the componentwise absolute value of the matrix */
00241 /*        or vector Z.  If the i-th component of the denominator is less */
00242 /*        than SAFE2, then SAFE1 is added to the i-th components of the */
00243 /*        numerator and denominator before dividing. */
00244 
00245         i__2 = *n;
00246         for (i__ = 1; i__ <= i__2; ++i__) {
00247             work[i__] = (d__1 = b[i__ + j * b_dim1], abs(d__1));
00248 /* L30: */
00249         }
00250 
00251 /*        Compute abs(A)*abs(X) + abs(B). */
00252 
00253         kk = 1;
00254         if (upper) {
00255             i__2 = *n;
00256             for (k = 1; k <= i__2; ++k) {
00257                 s = 0.;
00258                 xk = (d__1 = x[k + j * x_dim1], abs(d__1));
00259                 ik = kk;
00260                 i__3 = k - 1;
00261                 for (i__ = 1; i__ <= i__3; ++i__) {
00262                     work[i__] += (d__1 = ap[ik], abs(d__1)) * xk;
00263                     s += (d__1 = ap[ik], abs(d__1)) * (d__2 = x[i__ + j * 
00264                             x_dim1], abs(d__2));
00265                     ++ik;
00266 /* L40: */
00267                 }
00268                 work[k] = work[k] + (d__1 = ap[kk + k - 1], abs(d__1)) * xk + 
00269                         s;
00270                 kk += k;
00271 /* L50: */
00272             }
00273         } else {
00274             i__2 = *n;
00275             for (k = 1; k <= i__2; ++k) {
00276                 s = 0.;
00277                 xk = (d__1 = x[k + j * x_dim1], abs(d__1));
00278                 work[k] += (d__1 = ap[kk], abs(d__1)) * xk;
00279                 ik = kk + 1;
00280                 i__3 = *n;
00281                 for (i__ = k + 1; i__ <= i__3; ++i__) {
00282                     work[i__] += (d__1 = ap[ik], abs(d__1)) * xk;
00283                     s += (d__1 = ap[ik], abs(d__1)) * (d__2 = x[i__ + j * 
00284                             x_dim1], abs(d__2));
00285                     ++ik;
00286 /* L60: */
00287                 }
00288                 work[k] += s;
00289                 kk += *n - k + 1;
00290 /* L70: */
00291             }
00292         }
00293         s = 0.;
00294         i__2 = *n;
00295         for (i__ = 1; i__ <= i__2; ++i__) {
00296             if (work[i__] > safe2) {
00297 /* Computing MAX */
00298                 d__2 = s, d__3 = (d__1 = work[*n + i__], abs(d__1)) / work[
00299                         i__];
00300                 s = max(d__2,d__3);
00301             } else {
00302 /* Computing MAX */
00303                 d__2 = s, d__3 = ((d__1 = work[*n + i__], abs(d__1)) + safe1) 
00304                         / (work[i__] + safe1);
00305                 s = max(d__2,d__3);
00306             }
00307 /* L80: */
00308         }
00309         berr[j] = s;
00310 
00311 /*        Test stopping criterion. Continue iterating if */
00312 /*           1) The residual BERR(J) is larger than machine epsilon, and */
00313 /*           2) BERR(J) decreased by at least a factor of 2 during the */
00314 /*              last iteration, and */
00315 /*           3) At most ITMAX iterations tried. */
00316 
00317         if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) {
00318 
00319 /*           Update solution and try again. */
00320 
00321             dpptrs_(uplo, n, &c__1, &afp[1], &work[*n + 1], n, info);
00322             daxpy_(n, &c_b14, &work[*n + 1], &c__1, &x[j * x_dim1 + 1], &c__1)
00323                     ;
00324             lstres = berr[j];
00325             ++count;
00326             goto L20;
00327         }
00328 
00329 /*        Bound error from formula */
00330 
00331 /*        norm(X - XTRUE) / norm(X) .le. FERR = */
00332 /*        norm( abs(inv(A))* */
00333 /*           ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) */
00334 
00335 /*        where */
00336 /*          norm(Z) is the magnitude of the largest component of Z */
00337 /*          inv(A) is the inverse of A */
00338 /*          abs(Z) is the componentwise absolute value of the matrix or */
00339 /*             vector Z */
00340 /*          NZ is the maximum number of nonzeros in any row of A, plus 1 */
00341 /*          EPS is machine epsilon */
00342 
00343 /*        The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) */
00344 /*        is incremented by SAFE1 if the i-th component of */
00345 /*        abs(A)*abs(X) + abs(B) is less than SAFE2. */
00346 
00347 /*        Use DLACN2 to estimate the infinity-norm of the matrix */
00348 /*           inv(A) * diag(W), */
00349 /*        where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) */
00350 
00351         i__2 = *n;
00352         for (i__ = 1; i__ <= i__2; ++i__) {
00353             if (work[i__] > safe2) {
00354                 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps * 
00355                         work[i__];
00356             } else {
00357                 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps * 
00358                         work[i__] + safe1;
00359             }
00360 /* L90: */
00361         }
00362 
00363         kase = 0;
00364 L100:
00365         dlacn2_(n, &work[(*n << 1) + 1], &work[*n + 1], &iwork[1], &ferr[j], &
00366                 kase, isave);
00367         if (kase != 0) {
00368             if (kase == 1) {
00369 
00370 /*              Multiply by diag(W)*inv(A'). */
00371 
00372                 dpptrs_(uplo, n, &c__1, &afp[1], &work[*n + 1], n, info);
00373                 i__2 = *n;
00374                 for (i__ = 1; i__ <= i__2; ++i__) {
00375                     work[*n + i__] = work[i__] * work[*n + i__];
00376 /* L110: */
00377                 }
00378             } else if (kase == 2) {
00379 
00380 /*              Multiply by inv(A)*diag(W). */
00381 
00382                 i__2 = *n;
00383                 for (i__ = 1; i__ <= i__2; ++i__) {
00384                     work[*n + i__] = work[i__] * work[*n + i__];
00385 /* L120: */
00386                 }
00387                 dpptrs_(uplo, n, &c__1, &afp[1], &work[*n + 1], n, info);
00388             }
00389             goto L100;
00390         }
00391 
00392 /*        Normalize error. */
00393 
00394         lstres = 0.;
00395         i__2 = *n;
00396         for (i__ = 1; i__ <= i__2; ++i__) {
00397 /* Computing MAX */
00398             d__2 = lstres, d__3 = (d__1 = x[i__ + j * x_dim1], abs(d__1));
00399             lstres = max(d__2,d__3);
00400 /* L130: */
00401         }
00402         if (lstres != 0.) {
00403             ferr[j] /= lstres;
00404         }
00405 
00406 /* L140: */
00407     }
00408 
00409     return 0;
00410 
00411 /*     End of DPPRFS */
00412 
00413 } /* dpprfs_ */


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