ctprfs.c
Go to the documentation of this file.
00001 /* ctprfs.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 
00020 /* Subroutine */ int ctprfs_(char *uplo, char *trans, char *diag, integer *n, 
00021         integer *nrhs, complex *ap, complex *b, integer *ldb, complex *x, 
00022         integer *ldx, real *ferr, real *berr, complex *work, real *rwork, 
00023         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 kc;
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 *), caxpy_(integer *, complex *, complex *, 
00046             integer *, complex *, integer *), ctpmv_(char *, char *, char *, 
00047             integer *, complex *, complex *, integer *);
00048     logical upper;
00049     extern /* Subroutine */ int ctpsv_(char *, char *, char *, integer *, 
00050             complex *, complex *, integer *), clacn2_(
00051             integer *, complex *, complex *, real *, integer *, integer *);
00052     extern doublereal slamch_(char *);
00053     real safmin;
00054     extern /* Subroutine */ int xerbla_(char *, integer *);
00055     logical notran;
00056     char transn[1], transt[1];
00057     logical nounit;
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 /*  CTPRFS provides error bounds and backward error estimates for the */
00076 /*  solution to a system of linear equations with a triangular packed */
00077 /*  coefficient matrix. */
00078 
00079 /*  The solution matrix X must be computed by CTPTRS or some other */
00080 /*  means before entering this routine.  CTPRFS does not do iterative */
00081 /*  refinement because doing so cannot improve the backward error. */
00082 
00083 /*  Arguments */
00084 /*  ========= */
00085 
00086 /*  UPLO    (input) CHARACTER*1 */
00087 /*          = 'U':  A is upper triangular; */
00088 /*          = 'L':  A is lower triangular. */
00089 
00090 /*  TRANS   (input) CHARACTER*1 */
00091 /*          Specifies the form of the system of equations: */
00092 /*          = 'N':  A * X = B     (No transpose) */
00093 /*          = 'T':  A**T * X = B  (Transpose) */
00094 /*          = 'C':  A**H * X = B  (Conjugate transpose) */
00095 
00096 /*  DIAG    (input) CHARACTER*1 */
00097 /*          = 'N':  A is non-unit triangular; */
00098 /*          = 'U':  A is unit triangular. */
00099 
00100 /*  N       (input) INTEGER */
00101 /*          The order of the matrix A.  N >= 0. */
00102 
00103 /*  NRHS    (input) INTEGER */
00104 /*          The number of right hand sides, i.e., the number of columns */
00105 /*          of the matrices B and X.  NRHS >= 0. */
00106 
00107 /*  AP      (input) COMPLEX array, dimension (N*(N+1)/2) */
00108 /*          The upper or lower triangular matrix A, packed columnwise in */
00109 /*          a linear array.  The j-th column of A is stored in the array */
00110 /*          AP as follows: */
00111 /*          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
00112 /*          if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */
00113 /*          If DIAG = 'U', the diagonal elements of A are not referenced */
00114 /*          and are assumed to be 1. */
00115 
00116 /*  B       (input) COMPLEX array, dimension (LDB,NRHS) */
00117 /*          The right hand side matrix B. */
00118 
00119 /*  LDB     (input) INTEGER */
00120 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00121 
00122 /*  X       (input) COMPLEX array, dimension (LDX,NRHS) */
00123 /*          The solution matrix X. */
00124 
00125 /*  LDX     (input) INTEGER */
00126 /*          The leading dimension of the array X.  LDX >= max(1,N). */
00127 
00128 /*  FERR    (output) REAL array, dimension (NRHS) */
00129 /*          The estimated forward error bound for each solution vector */
00130 /*          X(j) (the j-th column of the solution matrix X). */
00131 /*          If XTRUE is the true solution corresponding to X(j), FERR(j) */
00132 /*          is an estimated upper bound for the magnitude of the largest */
00133 /*          element in (X(j) - XTRUE) divided by the magnitude of the */
00134 /*          largest element in X(j).  The estimate is as reliable as */
00135 /*          the estimate for RCOND, and is almost always a slight */
00136 /*          overestimate of the true error. */
00137 
00138 /*  BERR    (output) REAL array, dimension (NRHS) */
00139 /*          The componentwise relative backward error of each solution */
00140 /*          vector X(j) (i.e., the smallest relative change in */
00141 /*          any element of A or B that makes X(j) an exact solution). */
00142 
00143 /*  WORK    (workspace) COMPLEX array, dimension (2*N) */
00144 
00145 /*  RWORK   (workspace) REAL array, dimension (N) */
00146 
00147 /*  INFO    (output) INTEGER */
00148 /*          = 0:  successful exit */
00149 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00150 
00151 /*  ===================================================================== */
00152 
00153 /*     .. Parameters .. */
00154 /*     .. */
00155 /*     .. Local Scalars .. */
00156 /*     .. */
00157 /*     .. Local Arrays .. */
00158 /*     .. */
00159 /*     .. External Subroutines .. */
00160 /*     .. */
00161 /*     .. Intrinsic Functions .. */
00162 /*     .. */
00163 /*     .. External Functions .. */
00164 /*     .. */
00165 /*     .. Statement Functions .. */
00166 /*     .. */
00167 /*     .. Statement Function definitions .. */
00168 /*     .. */
00169 /*     .. Executable Statements .. */
00170 
00171 /*     Test the input parameters. */
00172 
00173     /* Parameter adjustments */
00174     --ap;
00175     b_dim1 = *ldb;
00176     b_offset = 1 + b_dim1;
00177     b -= b_offset;
00178     x_dim1 = *ldx;
00179     x_offset = 1 + x_dim1;
00180     x -= x_offset;
00181     --ferr;
00182     --berr;
00183     --work;
00184     --rwork;
00185 
00186     /* Function Body */
00187     *info = 0;
00188     upper = lsame_(uplo, "U");
00189     notran = lsame_(trans, "N");
00190     nounit = lsame_(diag, "N");
00191 
00192     if (! upper && ! lsame_(uplo, "L")) {
00193         *info = -1;
00194     } else if (! notran && ! lsame_(trans, "T") && ! 
00195             lsame_(trans, "C")) {
00196         *info = -2;
00197     } else if (! nounit && ! lsame_(diag, "U")) {
00198         *info = -3;
00199     } else if (*n < 0) {
00200         *info = -4;
00201     } else if (*nrhs < 0) {
00202         *info = -5;
00203     } else if (*ldb < max(1,*n)) {
00204         *info = -8;
00205     } else if (*ldx < max(1,*n)) {
00206         *info = -10;
00207     }
00208     if (*info != 0) {
00209         i__1 = -(*info);
00210         xerbla_("CTPRFS", &i__1);
00211         return 0;
00212     }
00213 
00214 /*     Quick return if possible */
00215 
00216     if (*n == 0 || *nrhs == 0) {
00217         i__1 = *nrhs;
00218         for (j = 1; j <= i__1; ++j) {
00219             ferr[j] = 0.f;
00220             berr[j] = 0.f;
00221 /* L10: */
00222         }
00223         return 0;
00224     }
00225 
00226     if (notran) {
00227         *(unsigned char *)transn = 'N';
00228         *(unsigned char *)transt = 'C';
00229     } else {
00230         *(unsigned char *)transn = 'C';
00231         *(unsigned char *)transt = 'N';
00232     }
00233 
00234 /*     NZ = maximum number of nonzero elements in each row of A, plus 1 */
00235 
00236     nz = *n + 1;
00237     eps = slamch_("Epsilon");
00238     safmin = slamch_("Safe minimum");
00239     safe1 = nz * safmin;
00240     safe2 = safe1 / eps;
00241 
00242 /*     Do for each right hand side */
00243 
00244     i__1 = *nrhs;
00245     for (j = 1; j <= i__1; ++j) {
00246 
00247 /*        Compute residual R = B - op(A) * X, */
00248 /*        where op(A) = A, A**T, or A**H, depending on TRANS. */
00249 
00250         ccopy_(n, &x[j * x_dim1 + 1], &c__1, &work[1], &c__1);
00251         ctpmv_(uplo, trans, diag, n, &ap[1], &work[1], &c__1);
00252         q__1.r = -1.f, q__1.i = -0.f;
00253         caxpy_(n, &q__1, &b[j * b_dim1 + 1], &c__1, &work[1], &c__1);
00254 
00255 /*        Compute componentwise relative backward error from formula */
00256 
00257 /*        max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) ) */
00258 
00259 /*        where abs(Z) is the componentwise absolute value of the matrix */
00260 /*        or vector Z.  If the i-th component of the denominator is less */
00261 /*        than SAFE2, then SAFE1 is added to the i-th components of the */
00262 /*        numerator and denominator before dividing. */
00263 
00264         i__2 = *n;
00265         for (i__ = 1; i__ <= i__2; ++i__) {
00266             i__3 = i__ + j * b_dim1;
00267             rwork[i__] = (r__1 = b[i__3].r, dabs(r__1)) + (r__2 = r_imag(&b[
00268                     i__ + j * b_dim1]), dabs(r__2));
00269 /* L20: */
00270         }
00271 
00272         if (notran) {
00273 
00274 /*           Compute abs(A)*abs(X) + abs(B). */
00275 
00276             if (upper) {
00277                 kc = 1;
00278                 if (nounit) {
00279                     i__2 = *n;
00280                     for (k = 1; k <= i__2; ++k) {
00281                         i__3 = k + j * x_dim1;
00282                         xk = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&
00283                                 x[k + j * x_dim1]), dabs(r__2));
00284                         i__3 = k;
00285                         for (i__ = 1; i__ <= i__3; ++i__) {
00286                             i__4 = kc + i__ - 1;
00287                             rwork[i__] += ((r__1 = ap[i__4].r, dabs(r__1)) + (
00288                                     r__2 = r_imag(&ap[kc + i__ - 1]), dabs(
00289                                     r__2))) * xk;
00290 /* L30: */
00291                         }
00292                         kc += k;
00293 /* L40: */
00294                     }
00295                 } else {
00296                     i__2 = *n;
00297                     for (k = 1; k <= i__2; ++k) {
00298                         i__3 = k + j * x_dim1;
00299                         xk = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&
00300                                 x[k + j * x_dim1]), dabs(r__2));
00301                         i__3 = k - 1;
00302                         for (i__ = 1; i__ <= i__3; ++i__) {
00303                             i__4 = kc + i__ - 1;
00304                             rwork[i__] += ((r__1 = ap[i__4].r, dabs(r__1)) + (
00305                                     r__2 = r_imag(&ap[kc + i__ - 1]), dabs(
00306                                     r__2))) * xk;
00307 /* L50: */
00308                         }
00309                         rwork[k] += xk;
00310                         kc += k;
00311 /* L60: */
00312                     }
00313                 }
00314             } else {
00315                 kc = 1;
00316                 if (nounit) {
00317                     i__2 = *n;
00318                     for (k = 1; k <= i__2; ++k) {
00319                         i__3 = k + j * x_dim1;
00320                         xk = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&
00321                                 x[k + j * x_dim1]), dabs(r__2));
00322                         i__3 = *n;
00323                         for (i__ = k; i__ <= i__3; ++i__) {
00324                             i__4 = kc + i__ - k;
00325                             rwork[i__] += ((r__1 = ap[i__4].r, dabs(r__1)) + (
00326                                     r__2 = r_imag(&ap[kc + i__ - k]), dabs(
00327                                     r__2))) * xk;
00328 /* L70: */
00329                         }
00330                         kc = kc + *n - k + 1;
00331 /* L80: */
00332                     }
00333                 } else {
00334                     i__2 = *n;
00335                     for (k = 1; k <= i__2; ++k) {
00336                         i__3 = k + j * x_dim1;
00337                         xk = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&
00338                                 x[k + j * x_dim1]), dabs(r__2));
00339                         i__3 = *n;
00340                         for (i__ = k + 1; i__ <= i__3; ++i__) {
00341                             i__4 = kc + i__ - k;
00342                             rwork[i__] += ((r__1 = ap[i__4].r, dabs(r__1)) + (
00343                                     r__2 = r_imag(&ap[kc + i__ - k]), dabs(
00344                                     r__2))) * xk;
00345 /* L90: */
00346                         }
00347                         rwork[k] += xk;
00348                         kc = kc + *n - k + 1;
00349 /* L100: */
00350                     }
00351                 }
00352             }
00353         } else {
00354 
00355 /*           Compute abs(A**H)*abs(X) + abs(B). */
00356 
00357             if (upper) {
00358                 kc = 1;
00359                 if (nounit) {
00360                     i__2 = *n;
00361                     for (k = 1; k <= i__2; ++k) {
00362                         s = 0.f;
00363                         i__3 = k;
00364                         for (i__ = 1; i__ <= i__3; ++i__) {
00365                             i__4 = kc + i__ - 1;
00366                             i__5 = i__ + j * x_dim1;
00367                             s += ((r__1 = ap[i__4].r, dabs(r__1)) + (r__2 = 
00368                                     r_imag(&ap[kc + i__ - 1]), dabs(r__2))) * 
00369                                     ((r__3 = x[i__5].r, dabs(r__3)) + (r__4 = 
00370                                     r_imag(&x[i__ + j * x_dim1]), dabs(r__4)))
00371                                     ;
00372 /* L110: */
00373                         }
00374                         rwork[k] += s;
00375                         kc += k;
00376 /* L120: */
00377                     }
00378                 } else {
00379                     i__2 = *n;
00380                     for (k = 1; k <= i__2; ++k) {
00381                         i__3 = k + j * x_dim1;
00382                         s = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&
00383                                 x[k + j * x_dim1]), dabs(r__2));
00384                         i__3 = k - 1;
00385                         for (i__ = 1; i__ <= i__3; ++i__) {
00386                             i__4 = kc + i__ - 1;
00387                             i__5 = i__ + j * x_dim1;
00388                             s += ((r__1 = ap[i__4].r, dabs(r__1)) + (r__2 = 
00389                                     r_imag(&ap[kc + i__ - 1]), dabs(r__2))) * 
00390                                     ((r__3 = x[i__5].r, dabs(r__3)) + (r__4 = 
00391                                     r_imag(&x[i__ + j * x_dim1]), dabs(r__4)))
00392                                     ;
00393 /* L130: */
00394                         }
00395                         rwork[k] += s;
00396                         kc += k;
00397 /* L140: */
00398                     }
00399                 }
00400             } else {
00401                 kc = 1;
00402                 if (nounit) {
00403                     i__2 = *n;
00404                     for (k = 1; k <= i__2; ++k) {
00405                         s = 0.f;
00406                         i__3 = *n;
00407                         for (i__ = k; i__ <= i__3; ++i__) {
00408                             i__4 = kc + i__ - k;
00409                             i__5 = i__ + j * x_dim1;
00410                             s += ((r__1 = ap[i__4].r, dabs(r__1)) + (r__2 = 
00411                                     r_imag(&ap[kc + i__ - k]), dabs(r__2))) * 
00412                                     ((r__3 = x[i__5].r, dabs(r__3)) + (r__4 = 
00413                                     r_imag(&x[i__ + j * x_dim1]), dabs(r__4)))
00414                                     ;
00415 /* L150: */
00416                         }
00417                         rwork[k] += s;
00418                         kc = kc + *n - k + 1;
00419 /* L160: */
00420                     }
00421                 } else {
00422                     i__2 = *n;
00423                     for (k = 1; k <= i__2; ++k) {
00424                         i__3 = k + j * x_dim1;
00425                         s = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&
00426                                 x[k + j * x_dim1]), dabs(r__2));
00427                         i__3 = *n;
00428                         for (i__ = k + 1; i__ <= i__3; ++i__) {
00429                             i__4 = kc + i__ - k;
00430                             i__5 = i__ + j * x_dim1;
00431                             s += ((r__1 = ap[i__4].r, dabs(r__1)) + (r__2 = 
00432                                     r_imag(&ap[kc + i__ - k]), dabs(r__2))) * 
00433                                     ((r__3 = x[i__5].r, dabs(r__3)) + (r__4 = 
00434                                     r_imag(&x[i__ + j * x_dim1]), dabs(r__4)))
00435                                     ;
00436 /* L170: */
00437                         }
00438                         rwork[k] += s;
00439                         kc = kc + *n - k + 1;
00440 /* L180: */
00441                     }
00442                 }
00443             }
00444         }
00445         s = 0.f;
00446         i__2 = *n;
00447         for (i__ = 1; i__ <= i__2; ++i__) {
00448             if (rwork[i__] > safe2) {
00449 /* Computing MAX */
00450                 i__3 = i__;
00451                 r__3 = s, r__4 = ((r__1 = work[i__3].r, dabs(r__1)) + (r__2 = 
00452                         r_imag(&work[i__]), dabs(r__2))) / rwork[i__];
00453                 s = dmax(r__3,r__4);
00454             } else {
00455 /* Computing MAX */
00456                 i__3 = i__;
00457                 r__3 = s, r__4 = ((r__1 = work[i__3].r, dabs(r__1)) + (r__2 = 
00458                         r_imag(&work[i__]), dabs(r__2)) + safe1) / (rwork[i__]
00459                          + safe1);
00460                 s = dmax(r__3,r__4);
00461             }
00462 /* L190: */
00463         }
00464         berr[j] = s;
00465 
00466 /*        Bound error from formula */
00467 
00468 /*        norm(X - XTRUE) / norm(X) .le. FERR = */
00469 /*        norm( abs(inv(op(A)))* */
00470 /*           ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X) */
00471 
00472 /*        where */
00473 /*          norm(Z) is the magnitude of the largest component of Z */
00474 /*          inv(op(A)) is the inverse of op(A) */
00475 /*          abs(Z) is the componentwise absolute value of the matrix or */
00476 /*             vector Z */
00477 /*          NZ is the maximum number of nonzeros in any row of A, plus 1 */
00478 /*          EPS is machine epsilon */
00479 
00480 /*        The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B)) */
00481 /*        is incremented by SAFE1 if the i-th component of */
00482 /*        abs(op(A))*abs(X) + abs(B) is less than SAFE2. */
00483 
00484 /*        Use CLACN2 to estimate the infinity-norm of the matrix */
00485 /*           inv(op(A)) * diag(W), */
00486 /*        where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) */
00487 
00488         i__2 = *n;
00489         for (i__ = 1; i__ <= i__2; ++i__) {
00490             if (rwork[i__] > safe2) {
00491                 i__3 = i__;
00492                 rwork[i__] = (r__1 = work[i__3].r, dabs(r__1)) + (r__2 = 
00493                         r_imag(&work[i__]), dabs(r__2)) + nz * eps * rwork[
00494                         i__];
00495             } else {
00496                 i__3 = i__;
00497                 rwork[i__] = (r__1 = work[i__3].r, dabs(r__1)) + (r__2 = 
00498                         r_imag(&work[i__]), dabs(r__2)) + nz * eps * rwork[
00499                         i__] + safe1;
00500             }
00501 /* L200: */
00502         }
00503 
00504         kase = 0;
00505 L210:
00506         clacn2_(n, &work[*n + 1], &work[1], &ferr[j], &kase, isave);
00507         if (kase != 0) {
00508             if (kase == 1) {
00509 
00510 /*              Multiply by diag(W)*inv(op(A)**H). */
00511 
00512                 ctpsv_(uplo, transt, diag, n, &ap[1], &work[1], &c__1);
00513                 i__2 = *n;
00514                 for (i__ = 1; i__ <= i__2; ++i__) {
00515                     i__3 = i__;
00516                     i__4 = i__;
00517                     i__5 = i__;
00518                     q__1.r = rwork[i__4] * work[i__5].r, q__1.i = rwork[i__4] 
00519                             * work[i__5].i;
00520                     work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00521 /* L220: */
00522                 }
00523             } else {
00524 
00525 /*              Multiply by inv(op(A))*diag(W). */
00526 
00527                 i__2 = *n;
00528                 for (i__ = 1; i__ <= i__2; ++i__) {
00529                     i__3 = i__;
00530                     i__4 = i__;
00531                     i__5 = i__;
00532                     q__1.r = rwork[i__4] * work[i__5].r, q__1.i = rwork[i__4] 
00533                             * work[i__5].i;
00534                     work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00535 /* L230: */
00536                 }
00537                 ctpsv_(uplo, transn, diag, n, &ap[1], &work[1], &c__1);
00538             }
00539             goto L210;
00540         }
00541 
00542 /*        Normalize error. */
00543 
00544         lstres = 0.f;
00545         i__2 = *n;
00546         for (i__ = 1; i__ <= i__2; ++i__) {
00547 /* Computing MAX */
00548             i__3 = i__ + j * x_dim1;
00549             r__3 = lstres, r__4 = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = 
00550                     r_imag(&x[i__ + j * x_dim1]), dabs(r__2));
00551             lstres = dmax(r__3,r__4);
00552 /* L240: */
00553         }
00554         if (lstres != 0.f) {
00555             ferr[j] /= lstres;
00556         }
00557 
00558 /* L250: */
00559     }
00560 
00561     return 0;
00562 
00563 /*     End of CTPRFS */
00564 
00565 } /* ctprfs_ */


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