dsyrfs.c
Go to the documentation of this file.
00001 /* dsyrfs.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 dsyrfs_(char *uplo, integer *n, integer *nrhs, 
00023         doublereal *a, integer *lda, doublereal *af, integer *ldaf, integer *
00024         ipiv, doublereal *b, integer *ldb, doublereal *x, integer *ldx, 
00025         doublereal *ferr, doublereal *berr, doublereal *work, integer *iwork, 
00026         integer *info)
00027 {
00028     /* System generated locals */
00029     integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, x_dim1, 
00030             x_offset, i__1, i__2, i__3;
00031     doublereal d__1, d__2, d__3;
00032 
00033     /* Local variables */
00034     integer i__, j, k;
00035     doublereal s, 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     logical upper;
00047     extern /* Subroutine */ int dsymv_(char *, integer *, doublereal *, 
00048             doublereal *, integer *, doublereal *, integer *, doublereal *, 
00049             doublereal *, integer *), dlacn2_(integer *, doublereal *, 
00050              doublereal *, integer *, doublereal *, integer *, integer *);
00051     extern doublereal dlamch_(char *);
00052     doublereal safmin;
00053     extern /* Subroutine */ int xerbla_(char *, integer *);
00054     doublereal lstres;
00055     extern /* Subroutine */ int dsytrs_(char *, integer *, integer *, 
00056             doublereal *, integer *, integer *, doublereal *, integer *, 
00057             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 /*  DSYRFS improves the computed solution to a system of linear */
00075 /*  equations when the coefficient matrix is symmetric indefinite, and */
00076 /*  provides error bounds and backward error estimates for the solution. */
00077 
00078 /*  Arguments */
00079 /*  ========= */
00080 
00081 /*  UPLO    (input) CHARACTER*1 */
00082 /*          = 'U':  Upper triangle of A is stored; */
00083 /*          = 'L':  Lower triangle of A is stored. */
00084 
00085 /*  N       (input) INTEGER */
00086 /*          The order of the matrix A.  N >= 0. */
00087 
00088 /*  NRHS    (input) INTEGER */
00089 /*          The number of right hand sides, i.e., the number of columns */
00090 /*          of the matrices B and X.  NRHS >= 0. */
00091 
00092 /*  A       (input) DOUBLE PRECISION array, dimension (LDA,N) */
00093 /*          The symmetric matrix A.  If UPLO = 'U', the leading N-by-N */
00094 /*          upper triangular part of A contains the upper triangular part */
00095 /*          of the matrix A, and the strictly lower triangular part of A */
00096 /*          is not referenced.  If UPLO = 'L', the leading N-by-N lower */
00097 /*          triangular part of A contains the lower triangular part of */
00098 /*          the matrix A, and the strictly upper triangular part of A is */
00099 /*          not referenced. */
00100 
00101 /*  LDA     (input) INTEGER */
00102 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00103 
00104 /*  AF      (input) DOUBLE PRECISION array, dimension (LDAF,N) */
00105 /*          The factored form of the matrix A.  AF contains the block */
00106 /*          diagonal matrix D and the multipliers used to obtain the */
00107 /*          factor U or L from the factorization A = U*D*U**T or */
00108 /*          A = L*D*L**T as computed by DSYTRF. */
00109 
00110 /*  LDAF    (input) INTEGER */
00111 /*          The leading dimension of the array AF.  LDAF >= max(1,N). */
00112 
00113 /*  IPIV    (input) INTEGER array, dimension (N) */
00114 /*          Details of the interchanges and the block structure of D */
00115 /*          as determined by DSYTRF. */
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/output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
00124 /*          On entry, the solution matrix X, as computed by DSYTRS. */
00125 /*          On exit, the improved solution matrix X. */
00126 
00127 /*  LDX     (input) INTEGER */
00128 /*          The leading dimension of the array X.  LDX >= max(1,N). */
00129 
00130 /*  FERR    (output) DOUBLE PRECISION array, dimension (NRHS) */
00131 /*          The estimated forward error bound for each solution vector */
00132 /*          X(j) (the j-th column of the solution matrix X). */
00133 /*          If XTRUE is the true solution corresponding to X(j), FERR(j) */
00134 /*          is an estimated upper bound for the magnitude of the largest */
00135 /*          element in (X(j) - XTRUE) divided by the magnitude of the */
00136 /*          largest element in X(j).  The estimate is as reliable as */
00137 /*          the estimate for RCOND, and is almost always a slight */
00138 /*          overestimate of the true error. */
00139 
00140 /*  BERR    (output) DOUBLE PRECISION array, dimension (NRHS) */
00141 /*          The componentwise relative backward error of each solution */
00142 /*          vector X(j) (i.e., the smallest relative change in */
00143 /*          any element of A or B that makes X(j) an exact solution). */
00144 
00145 /*  WORK    (workspace) DOUBLE PRECISION array, dimension (3*N) */
00146 
00147 /*  IWORK   (workspace) INTEGER array, dimension (N) */
00148 
00149 /*  INFO    (output) INTEGER */
00150 /*          = 0:  successful exit */
00151 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00152 
00153 /*  Internal Parameters */
00154 /*  =================== */
00155 
00156 /*  ITMAX is the maximum number of steps of iterative refinement. */
00157 
00158 /*  ===================================================================== */
00159 
00160 /*     .. Parameters .. */
00161 /*     .. */
00162 /*     .. Local Scalars .. */
00163 /*     .. */
00164 /*     .. Local Arrays .. */
00165 /*     .. */
00166 /*     .. External Subroutines .. */
00167 /*     .. */
00168 /*     .. Intrinsic Functions .. */
00169 /*     .. */
00170 /*     .. External Functions .. */
00171 /*     .. */
00172 /*     .. Executable Statements .. */
00173 
00174 /*     Test the input parameters. */
00175 
00176     /* Parameter adjustments */
00177     a_dim1 = *lda;
00178     a_offset = 1 + a_dim1;
00179     a -= a_offset;
00180     af_dim1 = *ldaf;
00181     af_offset = 1 + af_dim1;
00182     af -= af_offset;
00183     --ipiv;
00184     b_dim1 = *ldb;
00185     b_offset = 1 + b_dim1;
00186     b -= b_offset;
00187     x_dim1 = *ldx;
00188     x_offset = 1 + x_dim1;
00189     x -= x_offset;
00190     --ferr;
00191     --berr;
00192     --work;
00193     --iwork;
00194 
00195     /* Function Body */
00196     *info = 0;
00197     upper = lsame_(uplo, "U");
00198     if (! upper && ! lsame_(uplo, "L")) {
00199         *info = -1;
00200     } else if (*n < 0) {
00201         *info = -2;
00202     } else if (*nrhs < 0) {
00203         *info = -3;
00204     } else if (*lda < max(1,*n)) {
00205         *info = -5;
00206     } else if (*ldaf < max(1,*n)) {
00207         *info = -7;
00208     } else if (*ldb < max(1,*n)) {
00209         *info = -10;
00210     } else if (*ldx < max(1,*n)) {
00211         *info = -12;
00212     }
00213     if (*info != 0) {
00214         i__1 = -(*info);
00215         xerbla_("DSYRFS", &i__1);
00216         return 0;
00217     }
00218 
00219 /*     Quick return if possible */
00220 
00221     if (*n == 0 || *nrhs == 0) {
00222         i__1 = *nrhs;
00223         for (j = 1; j <= i__1; ++j) {
00224             ferr[j] = 0.;
00225             berr[j] = 0.;
00226 /* L10: */
00227         }
00228         return 0;
00229     }
00230 
00231 /*     NZ = maximum number of nonzero elements in each row of A, plus 1 */
00232 
00233     nz = *n + 1;
00234     eps = dlamch_("Epsilon");
00235     safmin = dlamch_("Safe minimum");
00236     safe1 = nz * safmin;
00237     safe2 = safe1 / eps;
00238 
00239 /*     Do for each right hand side */
00240 
00241     i__1 = *nrhs;
00242     for (j = 1; j <= i__1; ++j) {
00243 
00244         count = 1;
00245         lstres = 3.;
00246 L20:
00247 
00248 /*        Loop until stopping criterion is satisfied. */
00249 
00250 /*        Compute residual R = B - A * X */
00251 
00252         dcopy_(n, &b[j * b_dim1 + 1], &c__1, &work[*n + 1], &c__1);
00253         dsymv_(uplo, n, &c_b12, &a[a_offset], lda, &x[j * x_dim1 + 1], &c__1, 
00254                 &c_b14, &work[*n + 1], &c__1);
00255 
00256 /*        Compute componentwise relative backward error from formula */
00257 
00258 /*        max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) */
00259 
00260 /*        where abs(Z) is the componentwise absolute value of the matrix */
00261 /*        or vector Z.  If the i-th component of the denominator is less */
00262 /*        than SAFE2, then SAFE1 is added to the i-th components of the */
00263 /*        numerator and denominator before dividing. */
00264 
00265         i__2 = *n;
00266         for (i__ = 1; i__ <= i__2; ++i__) {
00267             work[i__] = (d__1 = b[i__ + j * b_dim1], abs(d__1));
00268 /* L30: */
00269         }
00270 
00271 /*        Compute abs(A)*abs(X) + abs(B). */
00272 
00273         if (upper) {
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                 i__3 = k - 1;
00279                 for (i__ = 1; i__ <= i__3; ++i__) {
00280                     work[i__] += (d__1 = a[i__ + k * a_dim1], abs(d__1)) * xk;
00281                     s += (d__1 = a[i__ + k * a_dim1], abs(d__1)) * (d__2 = x[
00282                             i__ + j * x_dim1], abs(d__2));
00283 /* L40: */
00284                 }
00285                 work[k] = work[k] + (d__1 = a[k + k * a_dim1], abs(d__1)) * 
00286                         xk + s;
00287 /* L50: */
00288             }
00289         } else {
00290             i__2 = *n;
00291             for (k = 1; k <= i__2; ++k) {
00292                 s = 0.;
00293                 xk = (d__1 = x[k + j * x_dim1], abs(d__1));
00294                 work[k] += (d__1 = a[k + k * a_dim1], abs(d__1)) * xk;
00295                 i__3 = *n;
00296                 for (i__ = k + 1; i__ <= i__3; ++i__) {
00297                     work[i__] += (d__1 = a[i__ + k * a_dim1], abs(d__1)) * xk;
00298                     s += (d__1 = a[i__ + k * a_dim1], abs(d__1)) * (d__2 = x[
00299                             i__ + j * x_dim1], abs(d__2));
00300 /* L60: */
00301                 }
00302                 work[k] += s;
00303 /* L70: */
00304             }
00305         }
00306         s = 0.;
00307         i__2 = *n;
00308         for (i__ = 1; i__ <= i__2; ++i__) {
00309             if (work[i__] > safe2) {
00310 /* Computing MAX */
00311                 d__2 = s, d__3 = (d__1 = work[*n + i__], abs(d__1)) / work[
00312                         i__];
00313                 s = max(d__2,d__3);
00314             } else {
00315 /* Computing MAX */
00316                 d__2 = s, d__3 = ((d__1 = work[*n + i__], abs(d__1)) + safe1) 
00317                         / (work[i__] + safe1);
00318                 s = max(d__2,d__3);
00319             }
00320 /* L80: */
00321         }
00322         berr[j] = s;
00323 
00324 /*        Test stopping criterion. Continue iterating if */
00325 /*           1) The residual BERR(J) is larger than machine epsilon, and */
00326 /*           2) BERR(J) decreased by at least a factor of 2 during the */
00327 /*              last iteration, and */
00328 /*           3) At most ITMAX iterations tried. */
00329 
00330         if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) {
00331 
00332 /*           Update solution and try again. */
00333 
00334             dsytrs_(uplo, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[*n 
00335                     + 1], n, info);
00336             daxpy_(n, &c_b14, &work[*n + 1], &c__1, &x[j * x_dim1 + 1], &c__1)
00337                     ;
00338             lstres = berr[j];
00339             ++count;
00340             goto L20;
00341         }
00342 
00343 /*        Bound error from formula */
00344 
00345 /*        norm(X - XTRUE) / norm(X) .le. FERR = */
00346 /*        norm( abs(inv(A))* */
00347 /*           ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) */
00348 
00349 /*        where */
00350 /*          norm(Z) is the magnitude of the largest component of Z */
00351 /*          inv(A) is the inverse of A */
00352 /*          abs(Z) is the componentwise absolute value of the matrix or */
00353 /*             vector Z */
00354 /*          NZ is the maximum number of nonzeros in any row of A, plus 1 */
00355 /*          EPS is machine epsilon */
00356 
00357 /*        The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) */
00358 /*        is incremented by SAFE1 if the i-th component of */
00359 /*        abs(A)*abs(X) + abs(B) is less than SAFE2. */
00360 
00361 /*        Use DLACN2 to estimate the infinity-norm of the matrix */
00362 /*           inv(A) * diag(W), */
00363 /*        where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) */
00364 
00365         i__2 = *n;
00366         for (i__ = 1; i__ <= i__2; ++i__) {
00367             if (work[i__] > safe2) {
00368                 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps * 
00369                         work[i__];
00370             } else {
00371                 work[i__] = (d__1 = work[*n + i__], abs(d__1)) + nz * eps * 
00372                         work[i__] + safe1;
00373             }
00374 /* L90: */
00375         }
00376 
00377         kase = 0;
00378 L100:
00379         dlacn2_(n, &work[(*n << 1) + 1], &work[*n + 1], &iwork[1], &ferr[j], &
00380                 kase, isave);
00381         if (kase != 0) {
00382             if (kase == 1) {
00383 
00384 /*              Multiply by diag(W)*inv(A'). */
00385 
00386                 dsytrs_(uplo, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[
00387                         *n + 1], n, info);
00388                 i__2 = *n;
00389                 for (i__ = 1; i__ <= i__2; ++i__) {
00390                     work[*n + i__] = work[i__] * work[*n + i__];
00391 /* L110: */
00392                 }
00393             } else if (kase == 2) {
00394 
00395 /*              Multiply by inv(A)*diag(W). */
00396 
00397                 i__2 = *n;
00398                 for (i__ = 1; i__ <= i__2; ++i__) {
00399                     work[*n + i__] = work[i__] * work[*n + i__];
00400 /* L120: */
00401                 }
00402                 dsytrs_(uplo, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[
00403                         *n + 1], n, info);
00404             }
00405             goto L100;
00406         }
00407 
00408 /*        Normalize error. */
00409 
00410         lstres = 0.;
00411         i__2 = *n;
00412         for (i__ = 1; i__ <= i__2; ++i__) {
00413 /* Computing MAX */
00414             d__2 = lstres, d__3 = (d__1 = x[i__ + j * x_dim1], abs(d__1));
00415             lstres = max(d__2,d__3);
00416 /* L130: */
00417         }
00418         if (lstres != 0.) {
00419             ferr[j] /= lstres;
00420         }
00421 
00422 /* L140: */
00423     }
00424 
00425     return 0;
00426 
00427 /*     End of DSYRFS */
00428 
00429 } /* dsyrfs_ */


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