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


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