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