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