ctbt03.c
Go to the documentation of this file.
00001 /* ctbt03.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 ctbt03_(char *uplo, char *trans, char *diag, integer *n, 
00021         integer *kd, integer *nrhs, complex *ab, integer *ldab, real *scale, 
00022         real *cnorm, real *tscal, complex *x, integer *ldx, complex *b, 
00023         integer *ldb, complex *work, real *resid)
00024 {
00025     /* System generated locals */
00026     integer ab_dim1, ab_offset, b_dim1, b_offset, x_dim1, x_offset, i__1;
00027     real r__1, r__2;
00028     complex q__1;
00029 
00030     /* Builtin functions */
00031     double c_abs(complex *);
00032 
00033     /* Local variables */
00034     integer j, ix;
00035     real eps, err;
00036     extern logical lsame_(char *, char *);
00037     real xscal;
00038     extern /* Subroutine */ int ctbmv_(char *, char *, char *, integer *, 
00039             integer *, complex *, integer *, complex *, integer *), ccopy_(integer *, complex *, integer *, complex *
00040 , integer *), caxpy_(integer *, complex *, complex *, integer *, 
00041             complex *, integer *);
00042     real tnorm, xnorm;
00043     extern integer icamax_(integer *, complex *, integer *);
00044     extern doublereal slamch_(char *);
00045     extern /* Subroutine */ int csscal_(integer *, real *, complex *, integer 
00046             *);
00047     real smlnum;
00048 
00049 
00050 /*  -- LAPACK test routine (version 3.1) -- */
00051 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00052 /*     November 2006 */
00053 
00054 /*     .. Scalar Arguments .. */
00055 /*     .. */
00056 /*     .. Array Arguments .. */
00057 /*     .. */
00058 
00059 /*  Purpose */
00060 /*  ======= */
00061 
00062 /*  CTBT03 computes the residual for the solution to a scaled triangular */
00063 /*  system of equations  A*x = s*b,  A**T *x = s*b,  or  A**H *x = s*b */
00064 /*  when A is a triangular band matrix.  Here A**T  denotes the transpose */
00065 /*  of A, A**H denotes the conjugate transpose of A, s is a scalar, and */
00066 /*  x and b are N by NRHS matrices.  The test ratio is the maximum over */
00067 /*  the number of right hand sides of */
00068 /*     norm(s*b - op(A)*x) / ( norm(op(A)) * norm(x) * EPS ), */
00069 /*  where op(A) denotes A, A**T, or A**H, and EPS is the machine epsilon. */
00070 
00071 /*  Arguments */
00072 /*  ========= */
00073 
00074 /*  UPLO    (input) CHARACTER*1 */
00075 /*          Specifies whether the matrix A is upper or lower triangular. */
00076 /*          = 'U':  Upper triangular */
00077 /*          = 'L':  Lower triangular */
00078 
00079 /*  TRANS   (input) CHARACTER*1 */
00080 /*          Specifies the operation applied to A. */
00081 /*          = 'N':  A *x = s*b     (No transpose) */
00082 /*          = 'T':  A**T *x = s*b  (Transpose) */
00083 /*          = 'C':  A**H *x = s*b  (Conjugate transpose) */
00084 
00085 /*  DIAG    (input) CHARACTER*1 */
00086 /*          Specifies whether or not the matrix A is unit triangular. */
00087 /*          = 'N':  Non-unit triangular */
00088 /*          = 'U':  Unit triangular */
00089 
00090 /*  N       (input) INTEGER */
00091 /*          The order of the matrix A.  N >= 0. */
00092 
00093 /*  KD      (input) INTEGER */
00094 /*          The number of superdiagonals or subdiagonals of the */
00095 /*          triangular band matrix A.  KD >= 0. */
00096 
00097 /*  NRHS    (input) INTEGER */
00098 /*          The number of right hand sides, i.e., the number of columns */
00099 /*          of the matrices X and B.  NRHS >= 0. */
00100 
00101 /*  AB      (input) COMPLEX array, dimension (LDAB,N) */
00102 /*          The upper or lower triangular band matrix A, stored in the */
00103 /*          first kd+1 rows of the array. The j-th column of A is stored */
00104 /*          in the j-th column of the array AB as follows: */
00105 /*          if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; */
00106 /*          if UPLO = 'L', AB(1+i-j,j)    = A(i,j) for j<=i<=min(n,j+kd). */
00107 
00108 /*  LDAB    (input) INTEGER */
00109 /*          The leading dimension of the array AB.  LDAB >= KD+1. */
00110 
00111 /*  SCALE   (input) REAL */
00112 /*          The scaling factor s used in solving the triangular system. */
00113 
00114 /*  CNORM   (input) REAL array, dimension (N) */
00115 /*          The 1-norms of the columns of A, not counting the diagonal. */
00116 
00117 /*  TSCAL   (input) REAL */
00118 /*          The scaling factor used in computing the 1-norms in CNORM. */
00119 /*          CNORM actually contains the column norms of TSCAL*A. */
00120 
00121 /*  X       (input) COMPLEX array, dimension (LDX,NRHS) */
00122 /*          The computed solution vectors for the system of linear */
00123 /*          equations. */
00124 
00125 /*  LDX     (input) INTEGER */
00126 /*          The leading dimension of the array X.  LDX >= max(1,N). */
00127 
00128 /*  B       (input) COMPLEX array, dimension (LDB,NRHS) */
00129 /*          The right hand side vectors for the system of linear */
00130 /*          equations. */
00131 
00132 /*  LDB     (input) INTEGER */
00133 /*          The leading dimension of the array B.  LDB >= max(1,N). */
00134 
00135 /*  WORK    (workspace) COMPLEX array, dimension (N) */
00136 
00137 /*  RESID   (output) REAL */
00138 /*          The maximum over the number of right hand sides of */
00139 /*          norm(op(A)*x - s*b) / ( norm(op(A)) * norm(x) * EPS ). */
00140 
00141 /*  ===================================================================== */
00142 
00143 
00144 /*     .. Parameters .. */
00145 /*     .. */
00146 /*     .. Local Scalars .. */
00147 /*     .. */
00148 /*     .. External Functions .. */
00149 /*     .. */
00150 /*     .. External Subroutines .. */
00151 /*     .. */
00152 /*     .. Intrinsic Functions .. */
00153 /*     .. */
00154 /*     .. Executable Statements .. */
00155 
00156 /*     Quick exit if N = 0 */
00157 
00158     /* Parameter adjustments */
00159     ab_dim1 = *ldab;
00160     ab_offset = 1 + ab_dim1;
00161     ab -= ab_offset;
00162     --cnorm;
00163     x_dim1 = *ldx;
00164     x_offset = 1 + x_dim1;
00165     x -= x_offset;
00166     b_dim1 = *ldb;
00167     b_offset = 1 + b_dim1;
00168     b -= b_offset;
00169     --work;
00170 
00171     /* Function Body */
00172     if (*n <= 0 || *nrhs <= 0) {
00173         *resid = 0.f;
00174         return 0;
00175     }
00176     eps = slamch_("Epsilon");
00177     smlnum = slamch_("Safe minimum");
00178 
00179 /*     Compute the norm of the triangular matrix A using the column */
00180 /*     norms already computed by CLATBS. */
00181 
00182     tnorm = 0.f;
00183     if (lsame_(diag, "N")) {
00184         if (lsame_(uplo, "U")) {
00185             i__1 = *n;
00186             for (j = 1; j <= i__1; ++j) {
00187 /* Computing MAX */
00188                 r__1 = tnorm, r__2 = *tscal * c_abs(&ab[*kd + 1 + j * ab_dim1]
00189                         ) + cnorm[j];
00190                 tnorm = dmax(r__1,r__2);
00191 /* L10: */
00192             }
00193         } else {
00194             i__1 = *n;
00195             for (j = 1; j <= i__1; ++j) {
00196 /* Computing MAX */
00197                 r__1 = tnorm, r__2 = *tscal * c_abs(&ab[j * ab_dim1 + 1]) + 
00198                         cnorm[j];
00199                 tnorm = dmax(r__1,r__2);
00200 /* L20: */
00201             }
00202         }
00203     } else {
00204         i__1 = *n;
00205         for (j = 1; j <= i__1; ++j) {
00206 /* Computing MAX */
00207             r__1 = tnorm, r__2 = *tscal + cnorm[j];
00208             tnorm = dmax(r__1,r__2);
00209 /* L30: */
00210         }
00211     }
00212 
00213 /*     Compute the maximum over the number of right hand sides of */
00214 /*        norm(op(A)*x - s*b) / ( norm(op(A)) * norm(x) * EPS ). */
00215 
00216     *resid = 0.f;
00217     i__1 = *nrhs;
00218     for (j = 1; j <= i__1; ++j) {
00219         ccopy_(n, &x[j * x_dim1 + 1], &c__1, &work[1], &c__1);
00220         ix = icamax_(n, &work[1], &c__1);
00221 /* Computing MAX */
00222         r__1 = 1.f, r__2 = c_abs(&x[ix + j * x_dim1]);
00223         xnorm = dmax(r__1,r__2);
00224         xscal = 1.f / xnorm / (real) (*kd + 1);
00225         csscal_(n, &xscal, &work[1], &c__1);
00226         ctbmv_(uplo, trans, diag, n, kd, &ab[ab_offset], ldab, &work[1], &
00227                 c__1);
00228         r__1 = -(*scale) * xscal;
00229         q__1.r = r__1, q__1.i = 0.f;
00230         caxpy_(n, &q__1, &b[j * b_dim1 + 1], &c__1, &work[1], &c__1);
00231         ix = icamax_(n, &work[1], &c__1);
00232         err = *tscal * c_abs(&work[ix]);
00233         ix = icamax_(n, &x[j * x_dim1 + 1], &c__1);
00234         xnorm = c_abs(&x[ix + j * x_dim1]);
00235         if (err * smlnum <= xnorm) {
00236             if (xnorm > 0.f) {
00237                 err /= xnorm;
00238             }
00239         } else {
00240             if (err > 0.f) {
00241                 err = 1.f / eps;
00242             }
00243         }
00244         if (err * smlnum <= tnorm) {
00245             if (tnorm > 0.f) {
00246                 err /= tnorm;
00247             }
00248         } else {
00249             if (err > 0.f) {
00250                 err = 1.f / eps;
00251             }
00252         }
00253         *resid = dmax(*resid,err);
00254 /* L40: */
00255     }
00256 
00257     return 0;
00258 
00259 /*     End of CTBT03 */
00260 
00261 } /* ctbt03_ */


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