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