sgbequb.c
Go to the documentation of this file.
00001 /* sgbequb.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 sgbequb_(integer *m, integer *n, integer *kl, integer *
00017         ku, real *ab, integer *ldab, real *r__, real *c__, real *rowcnd, real 
00018         *colcnd, real *amax, integer *info)
00019 {
00020     /* System generated locals */
00021     integer ab_dim1, ab_offset, i__1, i__2, i__3, i__4;
00022     real r__1, r__2, r__3;
00023 
00024     /* Builtin functions */
00025     double log(doublereal), pow_ri(real *, integer *);
00026 
00027     /* Local variables */
00028     integer i__, j, kd;
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 /*  SGBEQUB 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 SGEEQU 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 /*  KL      (input) INTEGER */
00080 /*          The number of subdiagonals within the band of A.  KL >= 0. */
00081 
00082 /*  KU      (input) INTEGER */
00083 /*          The number of superdiagonals within the band of A.  KU >= 0. */
00084 
00085 /*  AB      (input) DOUBLE PRECISION array, dimension (LDAB,N) */
00086 /*          On entry, the matrix A in band storage, in rows 1 to KL+KU+1. */
00087 /*          The j-th column of A is stored in the j-th column of the */
00088 /*          array AB as follows: */
00089 /*          AB(KU+1+i-j,j) = A(i,j) for max(1,j-KU)<=i<=min(N,j+kl) */
00090 
00091 /*  LDAB    (input) INTEGER */
00092 /*          The leading dimension of the array A.  LDAB >= max(1,M). */
00093 
00094 /*  R       (output) REAL array, dimension (M) */
00095 /*          If INFO = 0 or INFO > M, R contains the row scale factors */
00096 /*          for A. */
00097 
00098 /*  C       (output) REAL array, dimension (N) */
00099 /*          If INFO = 0,  C contains the column scale factors for A. */
00100 
00101 /*  ROWCND  (output) REAL */
00102 /*          If INFO = 0 or INFO > M, ROWCND contains the ratio of the */
00103 /*          smallest R(i) to the largest R(i).  If ROWCND >= 0.1 and */
00104 /*          AMAX is neither too large nor too small, it is not worth */
00105 /*          scaling by R. */
00106 
00107 /*  COLCND  (output) REAL */
00108 /*          If INFO = 0, COLCND contains the ratio of the smallest */
00109 /*          C(i) to the largest C(i).  If COLCND >= 0.1, it is not */
00110 /*          worth scaling by C. */
00111 
00112 /*  AMAX    (output) REAL */
00113 /*          Absolute value of largest matrix element.  If AMAX is very */
00114 /*          close to overflow or very close to underflow, the matrix */
00115 /*          should be scaled. */
00116 
00117 /*  INFO    (output) INTEGER */
00118 /*          = 0:  successful exit */
00119 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00120 /*          > 0:  if INFO = i,  and i is */
00121 /*                <= M:  the i-th row of A is exactly zero */
00122 /*                >  M:  the (i-M)-th column of A is exactly zero */
00123 
00124 /*  ===================================================================== */
00125 
00126 /*     .. Parameters .. */
00127 /*     .. */
00128 /*     .. Local Scalars .. */
00129 /*     .. */
00130 /*     .. External Functions .. */
00131 /*     .. */
00132 /*     .. External Subroutines .. */
00133 /*     .. */
00134 /*     .. Intrinsic Functions .. */
00135 /*     .. */
00136 /*     .. Executable Statements .. */
00137 
00138 /*     Test the input parameters. */
00139 
00140     /* Parameter adjustments */
00141     ab_dim1 = *ldab;
00142     ab_offset = 1 + ab_dim1;
00143     ab -= ab_offset;
00144     --r__;
00145     --c__;
00146 
00147     /* Function Body */
00148     *info = 0;
00149     if (*m < 0) {
00150         *info = -1;
00151     } else if (*n < 0) {
00152         *info = -2;
00153     } else if (*kl < 0) {
00154         *info = -3;
00155     } else if (*ku < 0) {
00156         *info = -4;
00157     } else if (*ldab < *kl + *ku + 1) {
00158         *info = -6;
00159     }
00160     if (*info != 0) {
00161         i__1 = -(*info);
00162         xerbla_("SGBEQUB", &i__1);
00163         return 0;
00164     }
00165 
00166 /*     Quick return if possible. */
00167 
00168     if (*m == 0 || *n == 0) {
00169         *rowcnd = 1.f;
00170         *colcnd = 1.f;
00171         *amax = 0.f;
00172         return 0;
00173     }
00174 
00175 /*     Get machine constants.  Assume SMLNUM is a power of the radix. */
00176 
00177     smlnum = slamch_("S");
00178     bignum = 1.f / smlnum;
00179     radix = slamch_("B");
00180     logrdx = log(radix);
00181 
00182 /*     Compute row scale factors. */
00183 
00184     i__1 = *m;
00185     for (i__ = 1; i__ <= i__1; ++i__) {
00186         r__[i__] = 0.f;
00187 /* L10: */
00188     }
00189 
00190 /*     Find the maximum element in each row. */
00191 
00192     kd = *ku + 1;
00193     i__1 = *n;
00194     for (j = 1; j <= i__1; ++j) {
00195 /* Computing MAX */
00196         i__2 = j - *ku;
00197 /* Computing MIN */
00198         i__4 = j + *kl;
00199         i__3 = min(i__4,*m);
00200         for (i__ = max(i__2,1); i__ <= i__3; ++i__) {
00201 /* Computing MAX */
00202             r__2 = r__[i__], r__3 = (r__1 = ab[kd + i__ - j + j * ab_dim1], 
00203                     dabs(r__1));
00204             r__[i__] = dmax(r__2,r__3);
00205 /* L20: */
00206         }
00207 /* L30: */
00208     }
00209     i__1 = *m;
00210     for (i__ = 1; i__ <= i__1; ++i__) {
00211         if (r__[i__] > 0.f) {
00212             i__3 = (integer) (log(r__[i__]) / logrdx);
00213             r__[i__] = pow_ri(&radix, &i__3);
00214         }
00215     }
00216 
00217 /*     Find the maximum and minimum scale factors. */
00218 
00219     rcmin = bignum;
00220     rcmax = 0.f;
00221     i__1 = *m;
00222     for (i__ = 1; i__ <= i__1; ++i__) {
00223 /* Computing MAX */
00224         r__1 = rcmax, r__2 = r__[i__];
00225         rcmax = dmax(r__1,r__2);
00226 /* Computing MIN */
00227         r__1 = rcmin, r__2 = r__[i__];
00228         rcmin = dmin(r__1,r__2);
00229 /* L40: */
00230     }
00231     *amax = rcmax;
00232 
00233     if (rcmin == 0.f) {
00234 
00235 /*        Find the first zero scale factor and return an error code. */
00236 
00237         i__1 = *m;
00238         for (i__ = 1; i__ <= i__1; ++i__) {
00239             if (r__[i__] == 0.f) {
00240                 *info = i__;
00241                 return 0;
00242             }
00243 /* L50: */
00244         }
00245     } else {
00246 
00247 /*        Invert the scale factors. */
00248 
00249         i__1 = *m;
00250         for (i__ = 1; i__ <= i__1; ++i__) {
00251 /* Computing MIN */
00252 /* Computing MAX */
00253             r__2 = r__[i__];
00254             r__1 = dmax(r__2,smlnum);
00255             r__[i__] = 1.f / dmin(r__1,bignum);
00256 /* L60: */
00257         }
00258 
00259 /*        Compute ROWCND = min(R(I)) / max(R(I)). */
00260 
00261         *rowcnd = dmax(rcmin,smlnum) / dmin(rcmax,bignum);
00262     }
00263 
00264 /*     Compute column scale factors. */
00265 
00266     i__1 = *n;
00267     for (j = 1; j <= i__1; ++j) {
00268         c__[j] = 0.f;
00269 /* L70: */
00270     }
00271 
00272 /*     Find the maximum element in each column, */
00273 /*     assuming the row scaling computed above. */
00274 
00275     i__1 = *n;
00276     for (j = 1; j <= i__1; ++j) {
00277 /* Computing MAX */
00278         i__3 = j - *ku;
00279 /* Computing MIN */
00280         i__4 = j + *kl;
00281         i__2 = min(i__4,*m);
00282         for (i__ = max(i__3,1); i__ <= i__2; ++i__) {
00283 /* Computing MAX */
00284             r__2 = c__[j], r__3 = (r__1 = ab[kd + i__ - j + j * ab_dim1], 
00285                     dabs(r__1)) * r__[i__];
00286             c__[j] = dmax(r__2,r__3);
00287 /* L80: */
00288         }
00289         if (c__[j] > 0.f) {
00290             i__2 = (integer) (log(c__[j]) / logrdx);
00291             c__[j] = pow_ri(&radix, &i__2);
00292         }
00293 /* L90: */
00294     }
00295 
00296 /*     Find the maximum and minimum scale factors. */
00297 
00298     rcmin = bignum;
00299     rcmax = 0.f;
00300     i__1 = *n;
00301     for (j = 1; j <= i__1; ++j) {
00302 /* Computing MIN */
00303         r__1 = rcmin, r__2 = c__[j];
00304         rcmin = dmin(r__1,r__2);
00305 /* Computing MAX */
00306         r__1 = rcmax, r__2 = c__[j];
00307         rcmax = dmax(r__1,r__2);
00308 /* L100: */
00309     }
00310 
00311     if (rcmin == 0.f) {
00312 
00313 /*        Find the first zero scale factor and return an error code. */
00314 
00315         i__1 = *n;
00316         for (j = 1; j <= i__1; ++j) {
00317             if (c__[j] == 0.f) {
00318                 *info = *m + j;
00319                 return 0;
00320             }
00321 /* L110: */
00322         }
00323     } else {
00324 
00325 /*        Invert the scale factors. */
00326 
00327         i__1 = *n;
00328         for (j = 1; j <= i__1; ++j) {
00329 /* Computing MIN */
00330 /* Computing MAX */
00331             r__2 = c__[j];
00332             r__1 = dmax(r__2,smlnum);
00333             c__[j] = 1.f / dmin(r__1,bignum);
00334 /* L120: */
00335         }
00336 
00337 /*        Compute COLCND = min(C(J)) / max(C(J)). */
00338 
00339         *colcnd = dmax(rcmin,smlnum) / dmin(rcmax,bignum);
00340     }
00341 
00342     return 0;
00343 
00344 /*     End of SGBEQUB */
00345 
00346 } /* sgbequb_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:05