00001 /* sgeequ.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 /* Subroutine */ int sgeequ_(integer *m, integer *n, real *a, integer *lda, 00017 real *r__, real *c__, real *rowcnd, real *colcnd, real *amax, integer 00018 *info) 00019 { 00020 /* System generated locals */ 00021 integer a_dim1, a_offset, i__1, i__2; 00022 real r__1, r__2, r__3; 00023 00024 /* Local variables */ 00025 integer i__, j; 00026 real rcmin, rcmax; 00027 extern doublereal slamch_(char *); 00028 extern /* Subroutine */ int xerbla_(char *, integer *); 00029 real bignum, smlnum; 00030 00031 00032 /* -- LAPACK routine (version 3.2) -- */ 00033 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ 00034 /* November 2006 */ 00035 00036 /* .. Scalar Arguments .. */ 00037 /* .. */ 00038 /* .. Array Arguments .. */ 00039 /* .. */ 00040 00041 /* Purpose */ 00042 /* ======= */ 00043 00044 /* SGEEQU computes row and column scalings intended to equilibrate an */ 00045 /* M-by-N matrix A and reduce its condition number. R returns the row */ 00046 /* scale factors and C the column scale factors, chosen to try to make */ 00047 /* the largest element in each row and column of the matrix B with */ 00048 /* elements B(i,j)=R(i)*A(i,j)*C(j) have absolute value 1. */ 00049 00050 /* R(i) and C(j) are restricted to be between SMLNUM = smallest safe */ 00051 /* number and BIGNUM = largest safe number. Use of these scaling */ 00052 /* factors is not guaranteed to reduce the condition number of A but */ 00053 /* works well in practice. */ 00054 00055 /* Arguments */ 00056 /* ========= */ 00057 00058 /* M (input) INTEGER */ 00059 /* The number of rows of the matrix A. M >= 0. */ 00060 00061 /* N (input) INTEGER */ 00062 /* The number of columns of the matrix A. N >= 0. */ 00063 00064 /* A (input) REAL array, dimension (LDA,N) */ 00065 /* The M-by-N matrix whose equilibration factors are */ 00066 /* to be computed. */ 00067 00068 /* LDA (input) INTEGER */ 00069 /* The leading dimension of the array A. LDA >= max(1,M). */ 00070 00071 /* R (output) REAL array, dimension (M) */ 00072 /* If INFO = 0 or INFO > M, R contains the row scale factors */ 00073 /* for A. */ 00074 00075 /* C (output) REAL array, dimension (N) */ 00076 /* If INFO = 0, C contains the column scale factors for A. */ 00077 00078 /* ROWCND (output) REAL */ 00079 /* If INFO = 0 or INFO > M, ROWCND contains the ratio of the */ 00080 /* smallest R(i) to the largest R(i). If ROWCND >= 0.1 and */ 00081 /* AMAX is neither too large nor too small, it is not worth */ 00082 /* scaling by R. */ 00083 00084 /* COLCND (output) REAL */ 00085 /* If INFO = 0, COLCND contains the ratio of the smallest */ 00086 /* C(i) to the largest C(i). If COLCND >= 0.1, it is not */ 00087 /* worth scaling by C. */ 00088 00089 /* AMAX (output) REAL */ 00090 /* Absolute value of largest matrix element. If AMAX is very */ 00091 /* close to overflow or very close to underflow, the matrix */ 00092 /* should be scaled. */ 00093 00094 /* INFO (output) INTEGER */ 00095 /* = 0: successful exit */ 00096 /* < 0: if INFO = -i, the i-th argument had an illegal value */ 00097 /* > 0: if INFO = i, and i is */ 00098 /* <= M: the i-th row of A is exactly zero */ 00099 /* > M: the (i-M)-th column of A is exactly zero */ 00100 00101 /* ===================================================================== */ 00102 00103 /* .. Parameters .. */ 00104 /* .. */ 00105 /* .. Local Scalars .. */ 00106 /* .. */ 00107 /* .. External Functions .. */ 00108 /* .. */ 00109 /* .. External Subroutines .. */ 00110 /* .. */ 00111 /* .. Intrinsic Functions .. */ 00112 /* .. */ 00113 /* .. Executable Statements .. */ 00114 00115 /* Test the input parameters. */ 00116 00117 /* Parameter adjustments */ 00118 a_dim1 = *lda; 00119 a_offset = 1 + a_dim1; 00120 a -= a_offset; 00121 --r__; 00122 --c__; 00123 00124 /* Function Body */ 00125 *info = 0; 00126 if (*m < 0) { 00127 *info = -1; 00128 } else if (*n < 0) { 00129 *info = -2; 00130 } else if (*lda < max(1,*m)) { 00131 *info = -4; 00132 } 00133 if (*info != 0) { 00134 i__1 = -(*info); 00135 xerbla_("SGEEQU", &i__1); 00136 return 0; 00137 } 00138 00139 /* Quick return if possible */ 00140 00141 if (*m == 0 || *n == 0) { 00142 *rowcnd = 1.f; 00143 *colcnd = 1.f; 00144 *amax = 0.f; 00145 return 0; 00146 } 00147 00148 /* Get machine constants. */ 00149 00150 smlnum = slamch_("S"); 00151 bignum = 1.f / smlnum; 00152 00153 /* Compute row scale factors. */ 00154 00155 i__1 = *m; 00156 for (i__ = 1; i__ <= i__1; ++i__) { 00157 r__[i__] = 0.f; 00158 /* L10: */ 00159 } 00160 00161 /* Find the maximum element in each row. */ 00162 00163 i__1 = *n; 00164 for (j = 1; j <= i__1; ++j) { 00165 i__2 = *m; 00166 for (i__ = 1; i__ <= i__2; ++i__) { 00167 /* Computing MAX */ 00168 r__2 = r__[i__], r__3 = (r__1 = a[i__ + j * a_dim1], dabs(r__1)); 00169 r__[i__] = dmax(r__2,r__3); 00170 /* L20: */ 00171 } 00172 /* L30: */ 00173 } 00174 00175 /* Find the maximum and minimum scale factors. */ 00176 00177 rcmin = bignum; 00178 rcmax = 0.f; 00179 i__1 = *m; 00180 for (i__ = 1; i__ <= i__1; ++i__) { 00181 /* Computing MAX */ 00182 r__1 = rcmax, r__2 = r__[i__]; 00183 rcmax = dmax(r__1,r__2); 00184 /* Computing MIN */ 00185 r__1 = rcmin, r__2 = r__[i__]; 00186 rcmin = dmin(r__1,r__2); 00187 /* L40: */ 00188 } 00189 *amax = rcmax; 00190 00191 if (rcmin == 0.f) { 00192 00193 /* Find the first zero scale factor and return an error code. */ 00194 00195 i__1 = *m; 00196 for (i__ = 1; i__ <= i__1; ++i__) { 00197 if (r__[i__] == 0.f) { 00198 *info = i__; 00199 return 0; 00200 } 00201 /* L50: */ 00202 } 00203 } else { 00204 00205 /* Invert the scale factors. */ 00206 00207 i__1 = *m; 00208 for (i__ = 1; i__ <= i__1; ++i__) { 00209 /* Computing MIN */ 00210 /* Computing MAX */ 00211 r__2 = r__[i__]; 00212 r__1 = dmax(r__2,smlnum); 00213 r__[i__] = 1.f / dmin(r__1,bignum); 00214 /* L60: */ 00215 } 00216 00217 /* Compute ROWCND = min(R(I)) / max(R(I)) */ 00218 00219 *rowcnd = dmax(rcmin,smlnum) / dmin(rcmax,bignum); 00220 } 00221 00222 /* Compute column scale factors */ 00223 00224 i__1 = *n; 00225 for (j = 1; j <= i__1; ++j) { 00226 c__[j] = 0.f; 00227 /* L70: */ 00228 } 00229 00230 /* Find the maximum element in each column, */ 00231 /* assuming the row scaling computed above. */ 00232 00233 i__1 = *n; 00234 for (j = 1; j <= i__1; ++j) { 00235 i__2 = *m; 00236 for (i__ = 1; i__ <= i__2; ++i__) { 00237 /* Computing MAX */ 00238 r__2 = c__[j], r__3 = (r__1 = a[i__ + j * a_dim1], dabs(r__1)) * 00239 r__[i__]; 00240 c__[j] = dmax(r__2,r__3); 00241 /* L80: */ 00242 } 00243 /* L90: */ 00244 } 00245 00246 /* Find the maximum and minimum scale factors. */ 00247 00248 rcmin = bignum; 00249 rcmax = 0.f; 00250 i__1 = *n; 00251 for (j = 1; j <= i__1; ++j) { 00252 /* Computing MIN */ 00253 r__1 = rcmin, r__2 = c__[j]; 00254 rcmin = dmin(r__1,r__2); 00255 /* Computing MAX */ 00256 r__1 = rcmax, r__2 = c__[j]; 00257 rcmax = dmax(r__1,r__2); 00258 /* L100: */ 00259 } 00260 00261 if (rcmin == 0.f) { 00262 00263 /* Find the first zero scale factor and return an error code. */ 00264 00265 i__1 = *n; 00266 for (j = 1; j <= i__1; ++j) { 00267 if (c__[j] == 0.f) { 00268 *info = *m + j; 00269 return 0; 00270 } 00271 /* L110: */ 00272 } 00273 } else { 00274 00275 /* Invert the scale factors. */ 00276 00277 i__1 = *n; 00278 for (j = 1; j <= i__1; ++j) { 00279 /* Computing MIN */ 00280 /* Computing MAX */ 00281 r__2 = c__[j]; 00282 r__1 = dmax(r__2,smlnum); 00283 c__[j] = 1.f / dmin(r__1,bignum); 00284 /* L120: */ 00285 } 00286 00287 /* Compute COLCND = min(C(J)) / max(C(J)) */ 00288 00289 *colcnd = dmax(rcmin,smlnum) / dmin(rcmax,bignum); 00290 } 00291 00292 return 0; 00293 00294 /* End of SGEEQU */ 00295 00296 } /* sgeequ_ */