ztprfs.c
Go to the documentation of this file.
00001 /* ztprfs.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 ztprfs_(char *uplo, char *trans, char *diag, integer *n, 
00021         integer *nrhs, doublecomplex *ap, doublecomplex *b, integer *ldb, 
00022         doublecomplex *x, integer *ldx, doublereal *ferr, doublereal *berr, 
00023         doublecomplex *work, doublereal *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     doublereal d__1, d__2, d__3, d__4;
00028     doublecomplex z__1;
00029 
00030     /* Builtin functions */
00031     double d_imag(doublecomplex *);
00032 
00033     /* Local variables */
00034     integer i__, j, k;
00035     doublereal s;
00036     integer kc;
00037     doublereal xk;
00038     integer nz;
00039     doublereal eps;
00040     integer kase;
00041     doublereal safe1, safe2;
00042     extern logical lsame_(char *, char *);
00043     integer isave[3];
00044     logical upper;
00045     extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *, 
00046             doublecomplex *, integer *), zaxpy_(integer *, doublecomplex *, 
00047             doublecomplex *, integer *, doublecomplex *, integer *), ztpmv_(
00048             char *, char *, char *, integer *, doublecomplex *, doublecomplex 
00049             *, integer *), ztpsv_(char *, char *, 
00050             char *, integer *, doublecomplex *, doublecomplex *, integer *), zlacn2_(integer *, doublecomplex *, 
00051             doublecomplex *, doublereal *, integer *, integer *);
00052     extern doublereal dlamch_(char *);
00053     doublereal safmin;
00054     extern /* Subroutine */ int xerbla_(char *, integer *);
00055     logical notran;
00056     char transn[1], transt[1];
00057     logical nounit;
00058     doublereal 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 ZLACN2 in place of ZLACON, 10 Feb 03, SJH. */
00066 
00067 /*     .. Scalar Arguments .. */
00068 /*     .. */
00069 /*     .. Array Arguments .. */
00070 /*     .. */
00071 
00072 /*  Purpose */
00073 /*  ======= */
00074 
00075 /*  ZTPRFS 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 ZTPTRS or some other */
00080 /*  means before entering this routine.  ZTPRFS 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*16 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*16 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*16 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) DOUBLE PRECISION 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) DOUBLE PRECISION 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*16 array, dimension (2*N) */
00144 
00145 /*  RWORK   (workspace) DOUBLE PRECISION 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_("ZTPRFS", &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.;
00220             berr[j] = 0.;
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 = dlamch_("Epsilon");
00238     safmin = dlamch_("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         zcopy_(n, &x[j * x_dim1 + 1], &c__1, &work[1], &c__1);
00251         ztpmv_(uplo, trans, diag, n, &ap[1], &work[1], &c__1);
00252         z__1.r = -1., z__1.i = -0.;
00253         zaxpy_(n, &z__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__] = (d__1 = b[i__3].r, abs(d__1)) + (d__2 = d_imag(&b[
00268                     i__ + j * b_dim1]), abs(d__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 = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&
00283                                 x[k + j * x_dim1]), abs(d__2));
00284                         i__3 = k;
00285                         for (i__ = 1; i__ <= i__3; ++i__) {
00286                             i__4 = kc + i__ - 1;
00287                             rwork[i__] += ((d__1 = ap[i__4].r, abs(d__1)) + (
00288                                     d__2 = d_imag(&ap[kc + i__ - 1]), abs(
00289                                     d__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 = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&
00300                                 x[k + j * x_dim1]), abs(d__2));
00301                         i__3 = k - 1;
00302                         for (i__ = 1; i__ <= i__3; ++i__) {
00303                             i__4 = kc + i__ - 1;
00304                             rwork[i__] += ((d__1 = ap[i__4].r, abs(d__1)) + (
00305                                     d__2 = d_imag(&ap[kc + i__ - 1]), abs(
00306                                     d__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 = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&
00321                                 x[k + j * x_dim1]), abs(d__2));
00322                         i__3 = *n;
00323                         for (i__ = k; i__ <= i__3; ++i__) {
00324                             i__4 = kc + i__ - k;
00325                             rwork[i__] += ((d__1 = ap[i__4].r, abs(d__1)) + (
00326                                     d__2 = d_imag(&ap[kc + i__ - k]), abs(
00327                                     d__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 = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&
00338                                 x[k + j * x_dim1]), abs(d__2));
00339                         i__3 = *n;
00340                         for (i__ = k + 1; i__ <= i__3; ++i__) {
00341                             i__4 = kc + i__ - k;
00342                             rwork[i__] += ((d__1 = ap[i__4].r, abs(d__1)) + (
00343                                     d__2 = d_imag(&ap[kc + i__ - k]), abs(
00344                                     d__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.;
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 += ((d__1 = ap[i__4].r, abs(d__1)) + (d__2 = 
00368                                     d_imag(&ap[kc + i__ - 1]), abs(d__2))) * (
00369                                     (d__3 = x[i__5].r, abs(d__3)) + (d__4 = 
00370                                     d_imag(&x[i__ + j * x_dim1]), abs(d__4)));
00371 /* L110: */
00372                         }
00373                         rwork[k] += s;
00374                         kc += k;
00375 /* L120: */
00376                     }
00377                 } else {
00378                     i__2 = *n;
00379                     for (k = 1; k <= i__2; ++k) {
00380                         i__3 = k + j * x_dim1;
00381                         s = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[
00382                                 k + j * x_dim1]), abs(d__2));
00383                         i__3 = k - 1;
00384                         for (i__ = 1; i__ <= i__3; ++i__) {
00385                             i__4 = kc + i__ - 1;
00386                             i__5 = i__ + j * x_dim1;
00387                             s += ((d__1 = ap[i__4].r, abs(d__1)) + (d__2 = 
00388                                     d_imag(&ap[kc + i__ - 1]), abs(d__2))) * (
00389                                     (d__3 = x[i__5].r, abs(d__3)) + (d__4 = 
00390                                     d_imag(&x[i__ + j * x_dim1]), abs(d__4)));
00391 /* L130: */
00392                         }
00393                         rwork[k] += s;
00394                         kc += k;
00395 /* L140: */
00396                     }
00397                 }
00398             } else {
00399                 kc = 1;
00400                 if (nounit) {
00401                     i__2 = *n;
00402                     for (k = 1; k <= i__2; ++k) {
00403                         s = 0.;
00404                         i__3 = *n;
00405                         for (i__ = k; i__ <= i__3; ++i__) {
00406                             i__4 = kc + i__ - k;
00407                             i__5 = i__ + j * x_dim1;
00408                             s += ((d__1 = ap[i__4].r, abs(d__1)) + (d__2 = 
00409                                     d_imag(&ap[kc + i__ - k]), abs(d__2))) * (
00410                                     (d__3 = x[i__5].r, abs(d__3)) + (d__4 = 
00411                                     d_imag(&x[i__ + j * x_dim1]), abs(d__4)));
00412 /* L150: */
00413                         }
00414                         rwork[k] += s;
00415                         kc = kc + *n - k + 1;
00416 /* L160: */
00417                     }
00418                 } else {
00419                     i__2 = *n;
00420                     for (k = 1; k <= i__2; ++k) {
00421                         i__3 = k + j * x_dim1;
00422                         s = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[
00423                                 k + j * x_dim1]), abs(d__2));
00424                         i__3 = *n;
00425                         for (i__ = k + 1; i__ <= i__3; ++i__) {
00426                             i__4 = kc + i__ - k;
00427                             i__5 = i__ + j * x_dim1;
00428                             s += ((d__1 = ap[i__4].r, abs(d__1)) + (d__2 = 
00429                                     d_imag(&ap[kc + i__ - k]), abs(d__2))) * (
00430                                     (d__3 = x[i__5].r, abs(d__3)) + (d__4 = 
00431                                     d_imag(&x[i__ + j * x_dim1]), abs(d__4)));
00432 /* L170: */
00433                         }
00434                         rwork[k] += s;
00435                         kc = kc + *n - k + 1;
00436 /* L180: */
00437                     }
00438                 }
00439             }
00440         }
00441         s = 0.;
00442         i__2 = *n;
00443         for (i__ = 1; i__ <= i__2; ++i__) {
00444             if (rwork[i__] > safe2) {
00445 /* Computing MAX */
00446                 i__3 = i__;
00447                 d__3 = s, d__4 = ((d__1 = work[i__3].r, abs(d__1)) + (d__2 = 
00448                         d_imag(&work[i__]), abs(d__2))) / rwork[i__];
00449                 s = max(d__3,d__4);
00450             } else {
00451 /* Computing MAX */
00452                 i__3 = i__;
00453                 d__3 = s, d__4 = ((d__1 = work[i__3].r, abs(d__1)) + (d__2 = 
00454                         d_imag(&work[i__]), abs(d__2)) + safe1) / (rwork[i__] 
00455                         + safe1);
00456                 s = max(d__3,d__4);
00457             }
00458 /* L190: */
00459         }
00460         berr[j] = s;
00461 
00462 /*        Bound error from formula */
00463 
00464 /*        norm(X - XTRUE) / norm(X) .le. FERR = */
00465 /*        norm( abs(inv(op(A)))* */
00466 /*           ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X) */
00467 
00468 /*        where */
00469 /*          norm(Z) is the magnitude of the largest component of Z */
00470 /*          inv(op(A)) is the inverse of op(A) */
00471 /*          abs(Z) is the componentwise absolute value of the matrix or */
00472 /*             vector Z */
00473 /*          NZ is the maximum number of nonzeros in any row of A, plus 1 */
00474 /*          EPS is machine epsilon */
00475 
00476 /*        The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B)) */
00477 /*        is incremented by SAFE1 if the i-th component of */
00478 /*        abs(op(A))*abs(X) + abs(B) is less than SAFE2. */
00479 
00480 /*        Use ZLACN2 to estimate the infinity-norm of the matrix */
00481 /*           inv(op(A)) * diag(W), */
00482 /*        where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) */
00483 
00484         i__2 = *n;
00485         for (i__ = 1; i__ <= i__2; ++i__) {
00486             if (rwork[i__] > safe2) {
00487                 i__3 = i__;
00488                 rwork[i__] = (d__1 = work[i__3].r, abs(d__1)) + (d__2 = 
00489                         d_imag(&work[i__]), abs(d__2)) + nz * eps * rwork[i__]
00490                         ;
00491             } else {
00492                 i__3 = i__;
00493                 rwork[i__] = (d__1 = work[i__3].r, abs(d__1)) + (d__2 = 
00494                         d_imag(&work[i__]), abs(d__2)) + nz * eps * rwork[i__]
00495                          + safe1;
00496             }
00497 /* L200: */
00498         }
00499 
00500         kase = 0;
00501 L210:
00502         zlacn2_(n, &work[*n + 1], &work[1], &ferr[j], &kase, isave);
00503         if (kase != 0) {
00504             if (kase == 1) {
00505 
00506 /*              Multiply by diag(W)*inv(op(A)**H). */
00507 
00508                 ztpsv_(uplo, transt, diag, n, &ap[1], &work[1], &c__1);
00509                 i__2 = *n;
00510                 for (i__ = 1; i__ <= i__2; ++i__) {
00511                     i__3 = i__;
00512                     i__4 = i__;
00513                     i__5 = i__;
00514                     z__1.r = rwork[i__4] * work[i__5].r, z__1.i = rwork[i__4] 
00515                             * work[i__5].i;
00516                     work[i__3].r = z__1.r, work[i__3].i = z__1.i;
00517 /* L220: */
00518                 }
00519             } else {
00520 
00521 /*              Multiply by inv(op(A))*diag(W). */
00522 
00523                 i__2 = *n;
00524                 for (i__ = 1; i__ <= i__2; ++i__) {
00525                     i__3 = i__;
00526                     i__4 = i__;
00527                     i__5 = i__;
00528                     z__1.r = rwork[i__4] * work[i__5].r, z__1.i = rwork[i__4] 
00529                             * work[i__5].i;
00530                     work[i__3].r = z__1.r, work[i__3].i = z__1.i;
00531 /* L230: */
00532                 }
00533                 ztpsv_(uplo, transn, diag, n, &ap[1], &work[1], &c__1);
00534             }
00535             goto L210;
00536         }
00537 
00538 /*        Normalize error. */
00539 
00540         lstres = 0.;
00541         i__2 = *n;
00542         for (i__ = 1; i__ <= i__2; ++i__) {
00543 /* Computing MAX */
00544             i__3 = i__ + j * x_dim1;
00545             d__3 = lstres, d__4 = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = 
00546                     d_imag(&x[i__ + j * x_dim1]), abs(d__2));
00547             lstres = max(d__3,d__4);
00548 /* L240: */
00549         }
00550         if (lstres != 0.) {
00551             ferr[j] /= lstres;
00552         }
00553 
00554 /* L250: */
00555     }
00556 
00557     return 0;
00558 
00559 /*     End of ZTPRFS */
00560 
00561 } /* ztprfs_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:44