00001 /* ctpt03.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 ctpt03_(char *uplo, char *trans, char *diag, integer *n, 00021 integer *nrhs, complex *ap, real *scale, real *cnorm, real *tscal, 00022 complex *x, integer *ldx, complex *b, integer *ldb, complex *work, 00023 real *resid) 00024 { 00025 /* System generated locals */ 00026 integer 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, jj, ix; 00035 real eps, err; 00036 extern logical lsame_(char *, char *); 00037 real xscal; 00038 extern /* Subroutine */ int ccopy_(integer *, complex *, integer *, 00039 complex *, integer *), caxpy_(integer *, complex *, complex *, 00040 integer *, complex *, integer *), ctpmv_(char *, char *, char *, 00041 integer *, complex *, 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 /* CTPT03 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 the triangular matrix A is stored in packed format. Here A**T */ 00065 /* denotes the transpose of A, A**H denotes the conjugate transpose of */ 00066 /* A, s is a scalar, and x and b are N by NRHS matrices. The test ratio */ 00067 /* is the maximum over 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 /* NRHS (input) INTEGER */ 00094 /* The number of right hand sides, i.e., the number of columns */ 00095 /* of the matrices X and B. NRHS >= 0. */ 00096 00097 /* AP (input) COMPLEX array, dimension (N*(N+1)/2) */ 00098 /* The upper or lower triangular matrix A, packed columnwise in */ 00099 /* a linear array. The j-th column of A is stored in the array */ 00100 /* AP as follows: */ 00101 /* if UPLO = 'U', AP((j-1)*j/2 + i) = A(i,j) for 1<=i<=j; */ 00102 /* if UPLO = 'L', */ 00103 /* AP((j-1)*(n-j) + j*(j+1)/2 + i-j) = A(i,j) for j<=i<=n. */ 00104 00105 /* SCALE (input) REAL */ 00106 /* The scaling factor s used in solving the triangular system. */ 00107 00108 /* CNORM (input) REAL array, dimension (N) */ 00109 /* The 1-norms of the columns of A, not counting the diagonal. */ 00110 00111 /* TSCAL (input) REAL */ 00112 /* The scaling factor used in computing the 1-norms in CNORM. */ 00113 /* CNORM actually contains the column norms of TSCAL*A. */ 00114 00115 /* X (input) COMPLEX array, dimension (LDX,NRHS) */ 00116 /* The computed solution vectors for the system of linear */ 00117 /* equations. */ 00118 00119 /* LDX (input) INTEGER */ 00120 /* The leading dimension of the array X. LDX >= max(1,N). */ 00121 00122 /* B (input) COMPLEX array, dimension (LDB,NRHS) */ 00123 /* The right hand side vectors for the system of linear */ 00124 /* equations. */ 00125 00126 /* LDB (input) INTEGER */ 00127 /* The leading dimension of the array B. LDB >= max(1,N). */ 00128 00129 /* WORK (workspace) COMPLEX array, dimension (N) */ 00130 00131 /* RESID (output) REAL */ 00132 /* The maximum over the number of right hand sides of */ 00133 /* norm(op(A)*x - s*b) / ( norm(op(A)) * norm(x) * EPS ). */ 00134 00135 /* ===================================================================== */ 00136 00137 /* .. Parameters .. */ 00138 /* .. */ 00139 /* .. Local Scalars .. */ 00140 /* .. */ 00141 /* .. External Functions .. */ 00142 /* .. */ 00143 /* .. External Subroutines .. */ 00144 /* .. */ 00145 /* .. Intrinsic Functions .. */ 00146 /* .. */ 00147 /* .. Executable Statements .. */ 00148 00149 /* Quick exit if N = 0. */ 00150 00151 /* Parameter adjustments */ 00152 --ap; 00153 --cnorm; 00154 x_dim1 = *ldx; 00155 x_offset = 1 + x_dim1; 00156 x -= x_offset; 00157 b_dim1 = *ldb; 00158 b_offset = 1 + b_dim1; 00159 b -= b_offset; 00160 --work; 00161 00162 /* Function Body */ 00163 if (*n <= 0 || *nrhs <= 0) { 00164 *resid = 0.f; 00165 return 0; 00166 } 00167 eps = slamch_("Epsilon"); 00168 smlnum = slamch_("Safe minimum"); 00169 00170 /* Compute the norm of the triangular matrix A using the column */ 00171 /* norms already computed by CLATPS. */ 00172 00173 tnorm = 0.f; 00174 if (lsame_(diag, "N")) { 00175 if (lsame_(uplo, "U")) { 00176 jj = 1; 00177 i__1 = *n; 00178 for (j = 1; j <= i__1; ++j) { 00179 /* Computing MAX */ 00180 r__1 = tnorm, r__2 = *tscal * c_abs(&ap[jj]) + cnorm[j]; 00181 tnorm = dmax(r__1,r__2); 00182 jj = jj + j + 1; 00183 /* L10: */ 00184 } 00185 } else { 00186 jj = 1; 00187 i__1 = *n; 00188 for (j = 1; j <= i__1; ++j) { 00189 /* Computing MAX */ 00190 r__1 = tnorm, r__2 = *tscal * c_abs(&ap[jj]) + cnorm[j]; 00191 tnorm = dmax(r__1,r__2); 00192 jj = jj + *n - j + 1; 00193 /* L20: */ 00194 } 00195 } 00196 } else { 00197 i__1 = *n; 00198 for (j = 1; j <= i__1; ++j) { 00199 /* Computing MAX */ 00200 r__1 = tnorm, r__2 = *tscal + cnorm[j]; 00201 tnorm = dmax(r__1,r__2); 00202 /* L30: */ 00203 } 00204 } 00205 00206 /* Compute the maximum over the number of right hand sides of */ 00207 /* norm(op(A)*x - s*b) / ( norm(A) * norm(x) * EPS ). */ 00208 00209 *resid = 0.f; 00210 i__1 = *nrhs; 00211 for (j = 1; j <= i__1; ++j) { 00212 ccopy_(n, &x[j * x_dim1 + 1], &c__1, &work[1], &c__1); 00213 ix = icamax_(n, &work[1], &c__1); 00214 /* Computing MAX */ 00215 r__1 = 1.f, r__2 = c_abs(&x[ix + j * x_dim1]); 00216 xnorm = dmax(r__1,r__2); 00217 xscal = 1.f / xnorm / (real) (*n); 00218 csscal_(n, &xscal, &work[1], &c__1); 00219 ctpmv_(uplo, trans, diag, n, &ap[1], &work[1], &c__1); 00220 r__1 = -(*scale) * xscal; 00221 q__1.r = r__1, q__1.i = 0.f; 00222 caxpy_(n, &q__1, &b[j * b_dim1 + 1], &c__1, &work[1], &c__1); 00223 ix = icamax_(n, &work[1], &c__1); 00224 err = *tscal * c_abs(&work[ix]); 00225 ix = icamax_(n, &x[j * x_dim1 + 1], &c__1); 00226 xnorm = c_abs(&x[ix + j * x_dim1]); 00227 if (err * smlnum <= xnorm) { 00228 if (xnorm > 0.f) { 00229 err /= xnorm; 00230 } 00231 } else { 00232 if (err > 0.f) { 00233 err = 1.f / eps; 00234 } 00235 } 00236 if (err * smlnum <= tnorm) { 00237 if (tnorm > 0.f) { 00238 err /= tnorm; 00239 } 00240 } else { 00241 if (err > 0.f) { 00242 err = 1.f / eps; 00243 } 00244 } 00245 *resid = dmax(*resid,err); 00246 /* L40: */ 00247 } 00248 00249 return 0; 00250 00251 /* End of CTPT03 */ 00252 00253 } /* ctpt03_ */