chprfs.c
Go to the documentation of this file.
00001 /* chprfs.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 chprfs_(char *uplo, integer *n, integer *nrhs, complex *
00022         ap, complex *afp, integer *ipiv, complex *b, integer *ldb, complex *x, 
00023          integer *ldx, real *ferr, real *berr, complex *work, real *rwork, 
00024         integer *info)
00025 {
00026     /* System generated locals */
00027     integer b_dim1, b_offset, x_dim1, x_offset, i__1, i__2, i__3, i__4, i__5;
00028     real r__1, r__2, r__3, r__4;
00029     complex q__1;
00030 
00031     /* Builtin functions */
00032     double r_imag(complex *);
00033 
00034     /* Local variables */
00035     integer i__, j, k;
00036     real s;
00037     integer ik, kk;
00038     real xk;
00039     integer nz;
00040     real eps;
00041     integer kase;
00042     real safe1, safe2;
00043     extern logical lsame_(char *, char *);
00044     integer isave[3];
00045     extern /* Subroutine */ int ccopy_(integer *, complex *, integer *, 
00046             complex *, integer *), chpmv_(char *, integer *, complex *, 
00047             complex *, complex *, integer *, complex *, complex *, integer *), caxpy_(integer *, complex *, complex *, integer *, 
00048             complex *, integer *);
00049     integer count;
00050     logical upper;
00051     extern /* Subroutine */ int clacn2_(integer *, complex *, complex *, real 
00052             *, integer *, integer *);
00053     extern doublereal slamch_(char *);
00054     real safmin;
00055     extern /* Subroutine */ int xerbla_(char *, integer *), chptrs_(
00056             char *, integer *, integer *, complex *, integer *, complex *, 
00057             integer *, integer *);
00058     real lstres;
00059 
00060 
00061 /*  -- LAPACK routine (version 3.2) -- */
00062 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00063 /*     November 2006 */
00064 
00065 /*     Modified to call CLACN2 in place of CLACON, 10 Feb 03, SJH. */
00066 
00067 /*     .. Scalar Arguments .. */
00068 /*     .. */
00069 /*     .. Array Arguments .. */
00070 /*     .. */
00071 
00072 /*  Purpose */
00073 /*  ======= */
00074 
00075 /*  CHPRFS improves the computed solution to a system of linear */
00076 /*  equations when the coefficient matrix is Hermitian indefinite */
00077 /*  and packed, and provides error bounds and backward error estimates */
00078 /*  for the solution. */
00079 
00080 /*  Arguments */
00081 /*  ========= */
00082 
00083 /*  UPLO    (input) CHARACTER*1 */
00084 /*          = 'U':  Upper triangle of A is stored; */
00085 /*          = 'L':  Lower triangle of A is stored. */
00086 
00087 /*  N       (input) INTEGER */
00088 /*          The order of the matrix A.  N >= 0. */
00089 
00090 /*  NRHS    (input) INTEGER */
00091 /*          The number of right hand sides, i.e., the number of columns */
00092 /*          of the matrices B and X.  NRHS >= 0. */
00093 
00094 /*  AP      (input) COMPLEX array, dimension (N*(N+1)/2) */
00095 /*          The upper or lower triangle of the Hermitian matrix A, packed */
00096 /*          columnwise in a linear array.  The j-th column of A is stored */
00097 /*          in the array AP as follows: */
00098 /*          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
00099 /*          if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */
00100 
00101 /*  AFP     (input) COMPLEX array, dimension (N*(N+1)/2) */
00102 /*          The factored form of the matrix A.  AFP contains the block */
00103 /*          diagonal matrix D and the multipliers used to obtain the */
00104 /*          factor U or L from the factorization A = U*D*U**H or */
00105 /*          A = L*D*L**H as computed by CHPTRF, stored as a packed */
00106 /*          triangular matrix. */
00107 
00108 /*  IPIV    (input) INTEGER array, dimension (N) */
00109 /*          Details of the interchanges and the block structure of D */
00110 /*          as determined by CHPTRF. */
00111 
00112 /*  B       (input) COMPLEX array, dimension (LDB,NRHS) */
00113 /*          The right hand side matrix B. */
00114 
00115 /*  LDB     (input) INTEGER */
00116 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00117 
00118 /*  X       (input/output) COMPLEX array, dimension (LDX,NRHS) */
00119 /*          On entry, the solution matrix X, as computed by CHPTRS. */
00120 /*          On exit, the improved solution matrix X. */
00121 
00122 /*  LDX     (input) INTEGER */
00123 /*          The leading dimension of the array X.  LDX >= max(1,N). */
00124 
00125 /*  FERR    (output) REAL array, dimension (NRHS) */
00126 /*          The estimated forward error bound for each solution vector */
00127 /*          X(j) (the j-th column of the solution matrix X). */
00128 /*          If XTRUE is the true solution corresponding to X(j), FERR(j) */
00129 /*          is an estimated upper bound for the magnitude of the largest */
00130 /*          element in (X(j) - XTRUE) divided by the magnitude of the */
00131 /*          largest element in X(j).  The estimate is as reliable as */
00132 /*          the estimate for RCOND, and is almost always a slight */
00133 /*          overestimate of the true error. */
00134 
00135 /*  BERR    (output) REAL array, dimension (NRHS) */
00136 /*          The componentwise relative backward error of each solution */
00137 /*          vector X(j) (i.e., the smallest relative change in */
00138 /*          any element of A or B that makes X(j) an exact solution). */
00139 
00140 /*  WORK    (workspace) COMPLEX array, dimension (2*N) */
00141 
00142 /*  RWORK   (workspace) REAL array, dimension (N) */
00143 
00144 /*  INFO    (output) INTEGER */
00145 /*          = 0:  successful exit */
00146 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00147 
00148 /*  Internal Parameters */
00149 /*  =================== */
00150 
00151 /*  ITMAX is the maximum number of steps of iterative refinement. */
00152 
00153 /*  ===================================================================== */
00154 
00155 /*     .. Parameters .. */
00156 /*     .. */
00157 /*     .. Local Scalars .. */
00158 /*     .. */
00159 /*     .. Local Arrays .. */
00160 /*     .. */
00161 /*     .. External Subroutines .. */
00162 /*     .. */
00163 /*     .. Intrinsic Functions .. */
00164 /*     .. */
00165 /*     .. External Functions .. */
00166 /*     .. */
00167 /*     .. Statement Functions .. */
00168 /*     .. */
00169 /*     .. Statement Function definitions .. */
00170 /*     .. */
00171 /*     .. Executable Statements .. */
00172 
00173 /*     Test the input parameters. */
00174 
00175     /* Parameter adjustments */
00176     --ap;
00177     --afp;
00178     --ipiv;
00179     b_dim1 = *ldb;
00180     b_offset = 1 + b_dim1;
00181     b -= b_offset;
00182     x_dim1 = *ldx;
00183     x_offset = 1 + x_dim1;
00184     x -= x_offset;
00185     --ferr;
00186     --berr;
00187     --work;
00188     --rwork;
00189 
00190     /* Function Body */
00191     *info = 0;
00192     upper = lsame_(uplo, "U");
00193     if (! upper && ! lsame_(uplo, "L")) {
00194         *info = -1;
00195     } else if (*n < 0) {
00196         *info = -2;
00197     } else if (*nrhs < 0) {
00198         *info = -3;
00199     } else if (*ldb < max(1,*n)) {
00200         *info = -8;
00201     } else if (*ldx < max(1,*n)) {
00202         *info = -10;
00203     }
00204     if (*info != 0) {
00205         i__1 = -(*info);
00206         xerbla_("CHPRFS", &i__1);
00207         return 0;
00208     }
00209 
00210 /*     Quick return if possible */
00211 
00212     if (*n == 0 || *nrhs == 0) {
00213         i__1 = *nrhs;
00214         for (j = 1; j <= i__1; ++j) {
00215             ferr[j] = 0.f;
00216             berr[j] = 0.f;
00217 /* L10: */
00218         }
00219         return 0;
00220     }
00221 
00222 /*     NZ = maximum number of nonzero elements in each row of A, plus 1 */
00223 
00224     nz = *n + 1;
00225     eps = slamch_("Epsilon");
00226     safmin = slamch_("Safe minimum");
00227     safe1 = nz * safmin;
00228     safe2 = safe1 / eps;
00229 
00230 /*     Do for each right hand side */
00231 
00232     i__1 = *nrhs;
00233     for (j = 1; j <= i__1; ++j) {
00234 
00235         count = 1;
00236         lstres = 3.f;
00237 L20:
00238 
00239 /*        Loop until stopping criterion is satisfied. */
00240 
00241 /*        Compute residual R = B - A * X */
00242 
00243         ccopy_(n, &b[j * b_dim1 + 1], &c__1, &work[1], &c__1);
00244         q__1.r = -1.f, q__1.i = -0.f;
00245         chpmv_(uplo, n, &q__1, &ap[1], &x[j * x_dim1 + 1], &c__1, &c_b1, &
00246                 work[1], &c__1);
00247 
00248 /*        Compute componentwise relative backward error from formula */
00249 
00250 /*        max(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) */
00251 
00252 /*        where abs(Z) is the componentwise absolute value of the matrix */
00253 /*        or vector Z.  If the i-th component of the denominator is less */
00254 /*        than SAFE2, then SAFE1 is added to the i-th components of the */
00255 /*        numerator and denominator before dividing. */
00256 
00257         i__2 = *n;
00258         for (i__ = 1; i__ <= i__2; ++i__) {
00259             i__3 = i__ + j * b_dim1;
00260             rwork[i__] = (r__1 = b[i__3].r, dabs(r__1)) + (r__2 = r_imag(&b[
00261                     i__ + j * b_dim1]), dabs(r__2));
00262 /* L30: */
00263         }
00264 
00265 /*        Compute abs(A)*abs(X) + abs(B). */
00266 
00267         kk = 1;
00268         if (upper) {
00269             i__2 = *n;
00270             for (k = 1; k <= i__2; ++k) {
00271                 s = 0.f;
00272                 i__3 = k + j * x_dim1;
00273                 xk = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&x[k + j 
00274                         * x_dim1]), dabs(r__2));
00275                 ik = kk;
00276                 i__3 = k - 1;
00277                 for (i__ = 1; i__ <= i__3; ++i__) {
00278                     i__4 = ik;
00279                     rwork[i__] += ((r__1 = ap[i__4].r, dabs(r__1)) + (r__2 = 
00280                             r_imag(&ap[ik]), dabs(r__2))) * xk;
00281                     i__4 = ik;
00282                     i__5 = i__ + j * x_dim1;
00283                     s += ((r__1 = ap[i__4].r, dabs(r__1)) + (r__2 = r_imag(&
00284                             ap[ik]), dabs(r__2))) * ((r__3 = x[i__5].r, dabs(
00285                             r__3)) + (r__4 = r_imag(&x[i__ + j * x_dim1]), 
00286                             dabs(r__4)));
00287                     ++ik;
00288 /* L40: */
00289                 }
00290                 i__3 = kk + k - 1;
00291                 rwork[k] = rwork[k] + (r__1 = ap[i__3].r, dabs(r__1)) * xk + 
00292                         s;
00293                 kk += k;
00294 /* L50: */
00295             }
00296         } else {
00297             i__2 = *n;
00298             for (k = 1; k <= i__2; ++k) {
00299                 s = 0.f;
00300                 i__3 = k + j * x_dim1;
00301                 xk = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&x[k + j 
00302                         * x_dim1]), dabs(r__2));
00303                 i__3 = kk;
00304                 rwork[k] += (r__1 = ap[i__3].r, dabs(r__1)) * xk;
00305                 ik = kk + 1;
00306                 i__3 = *n;
00307                 for (i__ = k + 1; i__ <= i__3; ++i__) {
00308                     i__4 = ik;
00309                     rwork[i__] += ((r__1 = ap[i__4].r, dabs(r__1)) + (r__2 = 
00310                             r_imag(&ap[ik]), dabs(r__2))) * xk;
00311                     i__4 = ik;
00312                     i__5 = i__ + j * x_dim1;
00313                     s += ((r__1 = ap[i__4].r, dabs(r__1)) + (r__2 = r_imag(&
00314                             ap[ik]), dabs(r__2))) * ((r__3 = x[i__5].r, dabs(
00315                             r__3)) + (r__4 = r_imag(&x[i__ + j * x_dim1]), 
00316                             dabs(r__4)));
00317                     ++ik;
00318 /* L60: */
00319                 }
00320                 rwork[k] += s;
00321                 kk += *n - k + 1;
00322 /* L70: */
00323             }
00324         }
00325         s = 0.f;
00326         i__2 = *n;
00327         for (i__ = 1; i__ <= i__2; ++i__) {
00328             if (rwork[i__] > safe2) {
00329 /* Computing MAX */
00330                 i__3 = i__;
00331                 r__3 = s, r__4 = ((r__1 = work[i__3].r, dabs(r__1)) + (r__2 = 
00332                         r_imag(&work[i__]), dabs(r__2))) / rwork[i__];
00333                 s = dmax(r__3,r__4);
00334             } else {
00335 /* Computing MAX */
00336                 i__3 = i__;
00337                 r__3 = s, r__4 = ((r__1 = work[i__3].r, dabs(r__1)) + (r__2 = 
00338                         r_imag(&work[i__]), dabs(r__2)) + safe1) / (rwork[i__]
00339                          + safe1);
00340                 s = dmax(r__3,r__4);
00341             }
00342 /* L80: */
00343         }
00344         berr[j] = s;
00345 
00346 /*        Test stopping criterion. Continue iterating if */
00347 /*           1) The residual BERR(J) is larger than machine epsilon, and */
00348 /*           2) BERR(J) decreased by at least a factor of 2 during the */
00349 /*              last iteration, and */
00350 /*           3) At most ITMAX iterations tried. */
00351 
00352         if (berr[j] > eps && berr[j] * 2.f <= lstres && count <= 5) {
00353 
00354 /*           Update solution and try again. */
00355 
00356             chptrs_(uplo, n, &c__1, &afp[1], &ipiv[1], &work[1], n, info);
00357             caxpy_(n, &c_b1, &work[1], &c__1, &x[j * x_dim1 + 1], &c__1);
00358             lstres = berr[j];
00359             ++count;
00360             goto L20;
00361         }
00362 
00363 /*        Bound error from formula */
00364 
00365 /*        norm(X - XTRUE) / norm(X) .le. FERR = */
00366 /*        norm( abs(inv(A))* */
00367 /*           ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) */
00368 
00369 /*        where */
00370 /*          norm(Z) is the magnitude of the largest component of Z */
00371 /*          inv(A) is the inverse of A */
00372 /*          abs(Z) is the componentwise absolute value of the matrix or */
00373 /*             vector Z */
00374 /*          NZ is the maximum number of nonzeros in any row of A, plus 1 */
00375 /*          EPS is machine epsilon */
00376 
00377 /*        The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) */
00378 /*        is incremented by SAFE1 if the i-th component of */
00379 /*        abs(A)*abs(X) + abs(B) is less than SAFE2. */
00380 
00381 /*        Use CLACN2 to estimate the infinity-norm of the matrix */
00382 /*           inv(A) * diag(W), */
00383 /*        where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) */
00384 
00385         i__2 = *n;
00386         for (i__ = 1; i__ <= i__2; ++i__) {
00387             if (rwork[i__] > safe2) {
00388                 i__3 = i__;
00389                 rwork[i__] = (r__1 = work[i__3].r, dabs(r__1)) + (r__2 = 
00390                         r_imag(&work[i__]), dabs(r__2)) + nz * eps * rwork[
00391                         i__];
00392             } else {
00393                 i__3 = i__;
00394                 rwork[i__] = (r__1 = work[i__3].r, dabs(r__1)) + (r__2 = 
00395                         r_imag(&work[i__]), dabs(r__2)) + nz * eps * rwork[
00396                         i__] + safe1;
00397             }
00398 /* L90: */
00399         }
00400 
00401         kase = 0;
00402 L100:
00403         clacn2_(n, &work[*n + 1], &work[1], &ferr[j], &kase, isave);
00404         if (kase != 0) {
00405             if (kase == 1) {
00406 
00407 /*              Multiply by diag(W)*inv(A'). */
00408 
00409                 chptrs_(uplo, n, &c__1, &afp[1], &ipiv[1], &work[1], n, info);
00410                 i__2 = *n;
00411                 for (i__ = 1; i__ <= i__2; ++i__) {
00412                     i__3 = i__;
00413                     i__4 = i__;
00414                     i__5 = i__;
00415                     q__1.r = rwork[i__4] * work[i__5].r, q__1.i = rwork[i__4] 
00416                             * work[i__5].i;
00417                     work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00418 /* L110: */
00419                 }
00420             } else if (kase == 2) {
00421 
00422 /*              Multiply by inv(A)*diag(W). */
00423 
00424                 i__2 = *n;
00425                 for (i__ = 1; i__ <= i__2; ++i__) {
00426                     i__3 = i__;
00427                     i__4 = i__;
00428                     i__5 = i__;
00429                     q__1.r = rwork[i__4] * work[i__5].r, q__1.i = rwork[i__4] 
00430                             * work[i__5].i;
00431                     work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00432 /* L120: */
00433                 }
00434                 chptrs_(uplo, n, &c__1, &afp[1], &ipiv[1], &work[1], n, info);
00435             }
00436             goto L100;
00437         }
00438 
00439 /*        Normalize error. */
00440 
00441         lstres = 0.f;
00442         i__2 = *n;
00443         for (i__ = 1; i__ <= i__2; ++i__) {
00444 /* Computing MAX */
00445             i__3 = i__ + j * x_dim1;
00446             r__3 = lstres, r__4 = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = 
00447                     r_imag(&x[i__ + j * x_dim1]), dabs(r__2));
00448             lstres = dmax(r__3,r__4);
00449 /* L130: */
00450         }
00451         if (lstres != 0.f) {
00452             ferr[j] /= lstres;
00453         }
00454 
00455 /* L140: */
00456     }
00457 
00458     return 0;
00459 
00460 /*     End of CHPRFS */
00461 
00462 } /* chprfs_ */


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