cpprfs.c
Go to the documentation of this file.
00001 /* cpprfs.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 complex c_b1 = {1.f,0.f};
00019 static integer c__1 = 1;
00020 
00021 /* Subroutine */ int cpprfs_(char *uplo, integer *n, integer *nrhs, complex *
00022         ap, complex *afp, complex *b, integer *ldb, complex *x, integer *ldx, 
00023         real *ferr, real *berr, complex *work, real *rwork, integer *info)
00024 {
00025     /* System generated locals */
00026     integer b_dim1, b_offset, x_dim1, x_offset, i__1, i__2, i__3, i__4, i__5;
00027     real r__1, r__2, r__3, r__4;
00028     complex q__1;
00029 
00030     /* Builtin functions */
00031     double r_imag(complex *);
00032 
00033     /* Local variables */
00034     integer i__, j, k;
00035     real s;
00036     integer ik, kk;
00037     real xk;
00038     integer nz;
00039     real eps;
00040     integer kase;
00041     real safe1, safe2;
00042     extern logical lsame_(char *, char *);
00043     integer isave[3];
00044     extern /* Subroutine */ int ccopy_(integer *, complex *, integer *, 
00045             complex *, integer *), chpmv_(char *, integer *, complex *, 
00046             complex *, complex *, integer *, complex *, complex *, integer *), caxpy_(integer *, complex *, complex *, integer *, 
00047             complex *, integer *);
00048     integer count;
00049     logical upper;
00050     extern /* Subroutine */ int clacn2_(integer *, complex *, complex *, real 
00051             *, integer *, integer *);
00052     extern doublereal slamch_(char *);
00053     real safmin;
00054     extern /* Subroutine */ int xerbla_(char *, integer *), cpptrs_(
00055             char *, integer *, integer *, complex *, complex *, integer *, 
00056             integer *);
00057     real lstres;
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 CLACN2 in place of CLACON, 10 Feb 03, SJH. */
00065 
00066 /*     .. Scalar Arguments .. */
00067 /*     .. */
00068 /*     .. Array Arguments .. */
00069 /*     .. */
00070 
00071 /*  Purpose */
00072 /*  ======= */
00073 
00074 /*  CPPRFS improves the computed solution to a system of linear */
00075 /*  equations when the coefficient matrix is Hermitian 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) COMPLEX array, dimension (N*(N+1)/2) */
00094 /*          The upper or lower triangle of the Hermitian 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) COMPLEX array, dimension (N*(N+1)/2) */
00101 /*          The triangular factor U or L from the Cholesky factorization */
00102 /*          A = U**H*U or A = L*L**H, as computed by SPPTRF/CPPTRF, */
00103 /*          packed columnwise in a linear array in the same format as A */
00104 /*          (see AP). */
00105 
00106 /*  B       (input) COMPLEX 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) COMPLEX array, dimension (LDX,NRHS) */
00113 /*          On entry, the solution matrix X, as computed by CPPTRS. */
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) REAL 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) REAL 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) COMPLEX array, dimension (2*N) */
00135 
00136 /*  RWORK   (workspace) REAL 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 /*     .. Statement Functions .. */
00162 /*     .. */
00163 /*     .. Statement Function definitions .. */
00164 /*     .. */
00165 /*     .. Executable Statements .. */
00166 
00167 /*     Test the input parameters. */
00168 
00169     /* Parameter adjustments */
00170     --ap;
00171     --afp;
00172     b_dim1 = *ldb;
00173     b_offset = 1 + b_dim1;
00174     b -= b_offset;
00175     x_dim1 = *ldx;
00176     x_offset = 1 + x_dim1;
00177     x -= x_offset;
00178     --ferr;
00179     --berr;
00180     --work;
00181     --rwork;
00182 
00183     /* Function Body */
00184     *info = 0;
00185     upper = lsame_(uplo, "U");
00186     if (! upper && ! lsame_(uplo, "L")) {
00187         *info = -1;
00188     } else if (*n < 0) {
00189         *info = -2;
00190     } else if (*nrhs < 0) {
00191         *info = -3;
00192     } else if (*ldb < max(1,*n)) {
00193         *info = -7;
00194     } else if (*ldx < max(1,*n)) {
00195         *info = -9;
00196     }
00197     if (*info != 0) {
00198         i__1 = -(*info);
00199         xerbla_("CPPRFS", &i__1);
00200         return 0;
00201     }
00202 
00203 /*     Quick return if possible */
00204 
00205     if (*n == 0 || *nrhs == 0) {
00206         i__1 = *nrhs;
00207         for (j = 1; j <= i__1; ++j) {
00208             ferr[j] = 0.f;
00209             berr[j] = 0.f;
00210 /* L10: */
00211         }
00212         return 0;
00213     }
00214 
00215 /*     NZ = maximum number of nonzero elements in each row of A, plus 1 */
00216 
00217     nz = *n + 1;
00218     eps = slamch_("Epsilon");
00219     safmin = slamch_("Safe minimum");
00220     safe1 = nz * safmin;
00221     safe2 = safe1 / eps;
00222 
00223 /*     Do for each right hand side */
00224 
00225     i__1 = *nrhs;
00226     for (j = 1; j <= i__1; ++j) {
00227 
00228         count = 1;
00229         lstres = 3.f;
00230 L20:
00231 
00232 /*        Loop until stopping criterion is satisfied. */
00233 
00234 /*        Compute residual R = B - A * X */
00235 
00236         ccopy_(n, &b[j * b_dim1 + 1], &c__1, &work[1], &c__1);
00237         q__1.r = -1.f, q__1.i = -0.f;
00238         chpmv_(uplo, n, &q__1, &ap[1], &x[j * x_dim1 + 1], &c__1, &c_b1, &
00239                 work[1], &c__1);
00240 
00241 /*        Compute componentwise relative backward error from formula */
00242 
00243 /*        max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) */
00244 
00245 /*        where abs(Z) is the componentwise absolute value of the matrix */
00246 /*        or vector Z.  If the i-th component of the denominator is less */
00247 /*        than SAFE2, then SAFE1 is added to the i-th components of the */
00248 /*        numerator and denominator before dividing. */
00249 
00250         i__2 = *n;
00251         for (i__ = 1; i__ <= i__2; ++i__) {
00252             i__3 = i__ + j * b_dim1;
00253             rwork[i__] = (r__1 = b[i__3].r, dabs(r__1)) + (r__2 = r_imag(&b[
00254                     i__ + j * b_dim1]), dabs(r__2));
00255 /* L30: */
00256         }
00257 
00258 /*        Compute abs(A)*abs(X) + abs(B). */
00259 
00260         kk = 1;
00261         if (upper) {
00262             i__2 = *n;
00263             for (k = 1; k <= i__2; ++k) {
00264                 s = 0.f;
00265                 i__3 = k + j * x_dim1;
00266                 xk = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&x[k + j 
00267                         * x_dim1]), dabs(r__2));
00268                 ik = kk;
00269                 i__3 = k - 1;
00270                 for (i__ = 1; i__ <= i__3; ++i__) {
00271                     i__4 = ik;
00272                     rwork[i__] += ((r__1 = ap[i__4].r, dabs(r__1)) + (r__2 = 
00273                             r_imag(&ap[ik]), dabs(r__2))) * xk;
00274                     i__4 = ik;
00275                     i__5 = i__ + j * x_dim1;
00276                     s += ((r__1 = ap[i__4].r, dabs(r__1)) + (r__2 = r_imag(&
00277                             ap[ik]), dabs(r__2))) * ((r__3 = x[i__5].r, dabs(
00278                             r__3)) + (r__4 = r_imag(&x[i__ + j * x_dim1]), 
00279                             dabs(r__4)));
00280                     ++ik;
00281 /* L40: */
00282                 }
00283                 i__3 = kk + k - 1;
00284                 rwork[k] = rwork[k] + (r__1 = ap[i__3].r, dabs(r__1)) * xk + 
00285                         s;
00286                 kk += k;
00287 /* L50: */
00288             }
00289         } else {
00290             i__2 = *n;
00291             for (k = 1; k <= i__2; ++k) {
00292                 s = 0.f;
00293                 i__3 = k + j * x_dim1;
00294                 xk = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&x[k + j 
00295                         * x_dim1]), dabs(r__2));
00296                 i__3 = kk;
00297                 rwork[k] += (r__1 = ap[i__3].r, dabs(r__1)) * xk;
00298                 ik = kk + 1;
00299                 i__3 = *n;
00300                 for (i__ = k + 1; i__ <= i__3; ++i__) {
00301                     i__4 = ik;
00302                     rwork[i__] += ((r__1 = ap[i__4].r, dabs(r__1)) + (r__2 = 
00303                             r_imag(&ap[ik]), dabs(r__2))) * xk;
00304                     i__4 = ik;
00305                     i__5 = i__ + j * x_dim1;
00306                     s += ((r__1 = ap[i__4].r, dabs(r__1)) + (r__2 = r_imag(&
00307                             ap[ik]), dabs(r__2))) * ((r__3 = x[i__5].r, dabs(
00308                             r__3)) + (r__4 = r_imag(&x[i__ + j * x_dim1]), 
00309                             dabs(r__4)));
00310                     ++ik;
00311 /* L60: */
00312                 }
00313                 rwork[k] += s;
00314                 kk += *n - k + 1;
00315 /* L70: */
00316             }
00317         }
00318         s = 0.f;
00319         i__2 = *n;
00320         for (i__ = 1; i__ <= i__2; ++i__) {
00321             if (rwork[i__] > safe2) {
00322 /* Computing MAX */
00323                 i__3 = i__;
00324                 r__3 = s, r__4 = ((r__1 = work[i__3].r, dabs(r__1)) + (r__2 = 
00325                         r_imag(&work[i__]), dabs(r__2))) / rwork[i__];
00326                 s = dmax(r__3,r__4);
00327             } else {
00328 /* Computing MAX */
00329                 i__3 = i__;
00330                 r__3 = s, r__4 = ((r__1 = work[i__3].r, dabs(r__1)) + (r__2 = 
00331                         r_imag(&work[i__]), dabs(r__2)) + safe1) / (rwork[i__]
00332                          + safe1);
00333                 s = dmax(r__3,r__4);
00334             }
00335 /* L80: */
00336         }
00337         berr[j] = s;
00338 
00339 /*        Test stopping criterion. Continue iterating if */
00340 /*           1) The residual BERR(J) is larger than machine epsilon, and */
00341 /*           2) BERR(J) decreased by at least a factor of 2 during the */
00342 /*              last iteration, and */
00343 /*           3) At most ITMAX iterations tried. */
00344 
00345         if (berr[j] > eps && berr[j] * 2.f <= lstres && count <= 5) {
00346 
00347 /*           Update solution and try again. */
00348 
00349             cpptrs_(uplo, n, &c__1, &afp[1], &work[1], n, info);
00350             caxpy_(n, &c_b1, &work[1], &c__1, &x[j * x_dim1 + 1], &c__1);
00351             lstres = berr[j];
00352             ++count;
00353             goto L20;
00354         }
00355 
00356 /*        Bound error from formula */
00357 
00358 /*        norm(X - XTRUE) / norm(X) .le. FERR = */
00359 /*        norm( abs(inv(A))* */
00360 /*           ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) */
00361 
00362 /*        where */
00363 /*          norm(Z) is the magnitude of the largest component of Z */
00364 /*          inv(A) is the inverse of A */
00365 /*          abs(Z) is the componentwise absolute value of the matrix or */
00366 /*             vector Z */
00367 /*          NZ is the maximum number of nonzeros in any row of A, plus 1 */
00368 /*          EPS is machine epsilon */
00369 
00370 /*        The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) */
00371 /*        is incremented by SAFE1 if the i-th component of */
00372 /*        abs(A)*abs(X) + abs(B) is less than SAFE2. */
00373 
00374 /*        Use CLACN2 to estimate the infinity-norm of the matrix */
00375 /*           inv(A) * diag(W), */
00376 /*        where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) */
00377 
00378         i__2 = *n;
00379         for (i__ = 1; i__ <= i__2; ++i__) {
00380             if (rwork[i__] > safe2) {
00381                 i__3 = i__;
00382                 rwork[i__] = (r__1 = work[i__3].r, dabs(r__1)) + (r__2 = 
00383                         r_imag(&work[i__]), dabs(r__2)) + nz * eps * rwork[
00384                         i__];
00385             } else {
00386                 i__3 = i__;
00387                 rwork[i__] = (r__1 = work[i__3].r, dabs(r__1)) + (r__2 = 
00388                         r_imag(&work[i__]), dabs(r__2)) + nz * eps * rwork[
00389                         i__] + safe1;
00390             }
00391 /* L90: */
00392         }
00393 
00394         kase = 0;
00395 L100:
00396         clacn2_(n, &work[*n + 1], &work[1], &ferr[j], &kase, isave);
00397         if (kase != 0) {
00398             if (kase == 1) {
00399 
00400 /*              Multiply by diag(W)*inv(A'). */
00401 
00402                 cpptrs_(uplo, n, &c__1, &afp[1], &work[1], n, info)
00403                         ;
00404                 i__2 = *n;
00405                 for (i__ = 1; i__ <= i__2; ++i__) {
00406                     i__3 = i__;
00407                     i__4 = i__;
00408                     i__5 = i__;
00409                     q__1.r = rwork[i__4] * work[i__5].r, q__1.i = rwork[i__4] 
00410                             * work[i__5].i;
00411                     work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00412 /* L110: */
00413                 }
00414             } else if (kase == 2) {
00415 
00416 /*              Multiply by inv(A)*diag(W). */
00417 
00418                 i__2 = *n;
00419                 for (i__ = 1; i__ <= i__2; ++i__) {
00420                     i__3 = i__;
00421                     i__4 = i__;
00422                     i__5 = i__;
00423                     q__1.r = rwork[i__4] * work[i__5].r, q__1.i = rwork[i__4] 
00424                             * work[i__5].i;
00425                     work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00426 /* L120: */
00427                 }
00428                 cpptrs_(uplo, n, &c__1, &afp[1], &work[1], n, info)
00429                         ;
00430             }
00431             goto L100;
00432         }
00433 
00434 /*        Normalize error. */
00435 
00436         lstres = 0.f;
00437         i__2 = *n;
00438         for (i__ = 1; i__ <= i__2; ++i__) {
00439 /* Computing MAX */
00440             i__3 = i__ + j * x_dim1;
00441             r__3 = lstres, r__4 = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = 
00442                     r_imag(&x[i__ + j * x_dim1]), dabs(r__2));
00443             lstres = dmax(r__3,r__4);
00444 /* L130: */
00445         }
00446         if (lstres != 0.f) {
00447             ferr[j] /= lstres;
00448         }
00449 
00450 /* L140: */
00451     }
00452 
00453     return 0;
00454 
00455 /*     End of CPPRFS */
00456 
00457 } /* cpprfs_ */


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