00001 /* stpt01.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 stpt01_(char *uplo, char *diag, integer *n, real *ap, 00021 real *ainvp, real *rcond, real *work, real *resid) 00022 { 00023 /* System generated locals */ 00024 integer i__1, i__2; 00025 00026 /* Local variables */ 00027 integer j, jc; 00028 real eps; 00029 extern logical lsame_(char *, char *); 00030 real anorm; 00031 logical unitd; 00032 extern /* Subroutine */ int stpmv_(char *, char *, char *, integer *, 00033 real *, real *, integer *); 00034 extern doublereal slamch_(char *); 00035 real ainvnm; 00036 extern doublereal slantp_(char *, char *, char *, integer *, real *, real 00037 *); 00038 00039 00040 /* -- LAPACK test routine (version 3.1) -- */ 00041 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ 00042 /* November 2006 */ 00043 00044 /* .. Scalar Arguments .. */ 00045 /* .. */ 00046 /* .. Array Arguments .. */ 00047 /* .. */ 00048 00049 /* Purpose */ 00050 /* ======= */ 00051 00052 /* STPT01 computes the residual for a triangular matrix A times its */ 00053 /* inverse when A is stored in packed format: */ 00054 /* RESID = norm(A*AINV - I) / ( N * norm(A) * norm(AINV) * EPS ), */ 00055 /* where EPS is the machine epsilon. */ 00056 00057 /* Arguments */ 00058 /* ========== */ 00059 00060 /* UPLO (input) CHARACTER*1 */ 00061 /* Specifies whether the matrix A is upper or lower triangular. */ 00062 /* = 'U': Upper triangular */ 00063 /* = 'L': Lower triangular */ 00064 00065 /* DIAG (input) CHARACTER*1 */ 00066 /* Specifies whether or not the matrix A is unit triangular. */ 00067 /* = 'N': Non-unit triangular */ 00068 /* = 'U': Unit triangular */ 00069 00070 /* N (input) INTEGER */ 00071 /* The order of the matrix A. N >= 0. */ 00072 00073 /* AP (input) REAL array, dimension (N*(N+1)/2) */ 00074 /* The original upper or lower triangular matrix A, packed */ 00075 /* columnwise in a linear array. The j-th column of A is stored */ 00076 /* in the array AP as follows: */ 00077 /* if UPLO = 'U', AP((j-1)*j/2 + i) = A(i,j) for 1<=i<=j; */ 00078 /* if UPLO = 'L', */ 00079 /* AP((j-1)*(n-j) + j*(j+1)/2 + i-j) = A(i,j) for j<=i<=n. */ 00080 00081 /* AINVP (input/output) REAL array, dimension (N*(N+1)/2) */ 00082 /* On entry, the (triangular) inverse of the matrix A, packed */ 00083 /* columnwise in a linear array as in AP. */ 00084 /* On exit, the contents of AINVP are destroyed. */ 00085 00086 /* RCOND (output) REAL */ 00087 /* The reciprocal condition number of A, computed as */ 00088 /* 1/(norm(A) * norm(AINV)). */ 00089 00090 /* WORK (workspace) REAL array, dimension (N) */ 00091 00092 /* RESID (output) REAL */ 00093 /* norm(A*AINV - I) / ( N * norm(A) * norm(AINV) * EPS ) */ 00094 00095 /* ===================================================================== */ 00096 00097 /* .. Parameters .. */ 00098 /* .. */ 00099 /* .. Local Scalars .. */ 00100 /* .. */ 00101 /* .. External Functions .. */ 00102 /* .. */ 00103 /* .. External Subroutines .. */ 00104 /* .. */ 00105 /* .. Intrinsic Functions .. */ 00106 /* .. */ 00107 /* .. Executable Statements .. */ 00108 00109 /* Quick exit if N = 0. */ 00110 00111 /* Parameter adjustments */ 00112 --work; 00113 --ainvp; 00114 --ap; 00115 00116 /* Function Body */ 00117 if (*n <= 0) { 00118 *rcond = 1.f; 00119 *resid = 0.f; 00120 return 0; 00121 } 00122 00123 /* Exit with RESID = 1/EPS if ANORM = 0 or AINVNM = 0. */ 00124 00125 eps = slamch_("Epsilon"); 00126 anorm = slantp_("1", uplo, diag, n, &ap[1], &work[1]); 00127 ainvnm = slantp_("1", uplo, diag, n, &ainvp[1], &work[1]); 00128 if (anorm <= 0.f || ainvnm <= 0.f) { 00129 *rcond = 0.f; 00130 *resid = 1.f / eps; 00131 return 0; 00132 } 00133 *rcond = 1.f / anorm / ainvnm; 00134 00135 /* Compute A * AINV, overwriting AINV. */ 00136 00137 unitd = lsame_(diag, "U"); 00138 if (lsame_(uplo, "U")) { 00139 jc = 1; 00140 i__1 = *n; 00141 for (j = 1; j <= i__1; ++j) { 00142 if (unitd) { 00143 ainvp[jc + j - 1] = 1.f; 00144 } 00145 00146 /* Form the j-th column of A*AINV */ 00147 00148 stpmv_("Upper", "No transpose", diag, &j, &ap[1], &ainvp[jc], & 00149 c__1); 00150 00151 /* Subtract 1 from the diagonal */ 00152 00153 ainvp[jc + j - 1] += -1.f; 00154 jc += j; 00155 /* L10: */ 00156 } 00157 } else { 00158 jc = 1; 00159 i__1 = *n; 00160 for (j = 1; j <= i__1; ++j) { 00161 if (unitd) { 00162 ainvp[jc] = 1.f; 00163 } 00164 00165 /* Form the j-th column of A*AINV */ 00166 00167 i__2 = *n - j + 1; 00168 stpmv_("Lower", "No transpose", diag, &i__2, &ap[jc], &ainvp[jc], 00169 &c__1); 00170 00171 /* Subtract 1 from the diagonal */ 00172 00173 ainvp[jc] += -1.f; 00174 jc = jc + *n - j + 1; 00175 /* L20: */ 00176 } 00177 } 00178 00179 /* Compute norm(A*AINV - I) / (N * norm(A) * norm(AINV) * EPS) */ 00180 00181 *resid = slantp_("1", uplo, "Non-unit", n, &ainvp[1], &work[1]); 00182 00183 *resid = *resid * *rcond / (real) (*n) / eps; 00184 00185 return 0; 00186 00187 /* End of STPT01 */ 00188 00189 } /* stpt01_ */