dgebal.c
Go to the documentation of this file.
00001 /* dgebal.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 dgebal_(char *job, integer *n, doublereal *a, integer *
00021         lda, integer *ilo, integer *ihi, doublereal *scale, integer *info)
00022 {
00023     /* System generated locals */
00024     integer a_dim1, a_offset, i__1, i__2;
00025     doublereal d__1, d__2;
00026 
00027     /* Local variables */
00028     doublereal c__, f, g;
00029     integer i__, j, k, l, m;
00030     doublereal r__, s, ca, ra;
00031     integer ica, ira, iexc;
00032     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
00033             integer *);
00034     extern logical lsame_(char *, char *);
00035     extern /* Subroutine */ int dswap_(integer *, doublereal *, integer *, 
00036             doublereal *, integer *);
00037     doublereal sfmin1, sfmin2, sfmax1, sfmax2;
00038     extern doublereal dlamch_(char *);
00039     extern integer idamax_(integer *, doublereal *, integer *);
00040     extern /* Subroutine */ int xerbla_(char *, integer *);
00041     logical noconv;
00042 
00043 
00044 /*  -- LAPACK routine (version 3.2) -- */
00045 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00046 /*     November 2006 */
00047 
00048 /*     .. Scalar Arguments .. */
00049 /*     .. */
00050 /*     .. Array Arguments .. */
00051 /*     .. */
00052 
00053 /*  Purpose */
00054 /*  ======= */
00055 
00056 /*  DGEBAL balances a general real matrix A.  This involves, first, */
00057 /*  permuting A by a similarity transformation to isolate eigenvalues */
00058 /*  in the first 1 to ILO-1 and last IHI+1 to N elements on the */
00059 /*  diagonal; and second, applying a diagonal similarity transformation */
00060 /*  to rows and columns ILO to IHI to make the rows and columns as */
00061 /*  close in norm as possible.  Both steps are optional. */
00062 
00063 /*  Balancing may reduce the 1-norm of the matrix, and improve the */
00064 /*  accuracy of the computed eigenvalues and/or eigenvectors. */
00065 
00066 /*  Arguments */
00067 /*  ========= */
00068 
00069 /*  JOB     (input) CHARACTER*1 */
00070 /*          Specifies the operations to be performed on A: */
00071 /*          = 'N':  none:  simply set ILO = 1, IHI = N, SCALE(I) = 1.0 */
00072 /*                  for i = 1,...,N; */
00073 /*          = 'P':  permute only; */
00074 /*          = 'S':  scale only; */
00075 /*          = 'B':  both permute and scale. */
00076 
00077 /*  N       (input) INTEGER */
00078 /*          The order of the matrix A.  N >= 0. */
00079 
00080 /*  A       (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
00081 /*          On entry, the input matrix A. */
00082 /*          On exit,  A is overwritten by the balanced matrix. */
00083 /*          If JOB = 'N', A is not referenced. */
00084 /*          See Further Details. */
00085 
00086 /*  LDA     (input) INTEGER */
00087 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00088 
00089 /*  ILO     (output) INTEGER */
00090 /*  IHI     (output) INTEGER */
00091 /*          ILO and IHI are set to integers such that on exit */
00092 /*          A(i,j) = 0 if i > j and j = 1,...,ILO-1 or I = IHI+1,...,N. */
00093 /*          If JOB = 'N' or 'S', ILO = 1 and IHI = N. */
00094 
00095 /*  SCALE   (output) DOUBLE PRECISION array, dimension (N) */
00096 /*          Details of the permutations and scaling factors applied to */
00097 /*          A.  If P(j) is the index of the row and column interchanged */
00098 /*          with row and column j and D(j) is the scaling factor */
00099 /*          applied to row and column j, then */
00100 /*          SCALE(j) = P(j)    for j = 1,...,ILO-1 */
00101 /*                   = D(j)    for j = ILO,...,IHI */
00102 /*                   = P(j)    for j = IHI+1,...,N. */
00103 /*          The order in which the interchanges are made is N to IHI+1, */
00104 /*          then 1 to ILO-1. */
00105 
00106 /*  INFO    (output) INTEGER */
00107 /*          = 0:  successful exit. */
00108 /*          < 0:  if INFO = -i, the i-th argument had an illegal value. */
00109 
00110 /*  Further Details */
00111 /*  =============== */
00112 
00113 /*  The permutations consist of row and column interchanges which put */
00114 /*  the matrix in the form */
00115 
00116 /*             ( T1   X   Y  ) */
00117 /*     P A P = (  0   B   Z  ) */
00118 /*             (  0   0   T2 ) */
00119 
00120 /*  where T1 and T2 are upper triangular matrices whose eigenvalues lie */
00121 /*  along the diagonal.  The column indices ILO and IHI mark the starting */
00122 /*  and ending columns of the submatrix B. Balancing consists of applying */
00123 /*  a diagonal similarity transformation inv(D) * B * D to make the */
00124 /*  1-norms of each row of B and its corresponding column nearly equal. */
00125 /*  The output matrix is */
00126 
00127 /*     ( T1     X*D          Y    ) */
00128 /*     (  0  inv(D)*B*D  inv(D)*Z ). */
00129 /*     (  0      0           T2   ) */
00130 
00131 /*  Information about the permutations P and the diagonal matrix D is */
00132 /*  returned in the vector SCALE. */
00133 
00134 /*  This subroutine is based on the EISPACK routine BALANC. */
00135 
00136 /*  Modified by Tzu-Yi Chen, Computer Science Division, University of */
00137 /*    California at Berkeley, USA */
00138 
00139 /*  ===================================================================== */
00140 
00141 /*     .. Parameters .. */
00142 /*     .. */
00143 /*     .. Local Scalars .. */
00144 /*     .. */
00145 /*     .. External Functions .. */
00146 /*     .. */
00147 /*     .. External Subroutines .. */
00148 /*     .. */
00149 /*     .. Intrinsic Functions .. */
00150 /*     .. */
00151 /*     .. Executable Statements .. */
00152 
00153 /*     Test the input parameters */
00154 
00155     /* Parameter adjustments */
00156     a_dim1 = *lda;
00157     a_offset = 1 + a_dim1;
00158     a -= a_offset;
00159     --scale;
00160 
00161     /* Function Body */
00162     *info = 0;
00163     if (! lsame_(job, "N") && ! lsame_(job, "P") && ! lsame_(job, "S") 
00164             && ! lsame_(job, "B")) {
00165         *info = -1;
00166     } else if (*n < 0) {
00167         *info = -2;
00168     } else if (*lda < max(1,*n)) {
00169         *info = -4;
00170     }
00171     if (*info != 0) {
00172         i__1 = -(*info);
00173         xerbla_("DGEBAL", &i__1);
00174         return 0;
00175     }
00176 
00177     k = 1;
00178     l = *n;
00179 
00180     if (*n == 0) {
00181         goto L210;
00182     }
00183 
00184     if (lsame_(job, "N")) {
00185         i__1 = *n;
00186         for (i__ = 1; i__ <= i__1; ++i__) {
00187             scale[i__] = 1.;
00188 /* L10: */
00189         }
00190         goto L210;
00191     }
00192 
00193     if (lsame_(job, "S")) {
00194         goto L120;
00195     }
00196 
00197 /*     Permutation to isolate eigenvalues if possible */
00198 
00199     goto L50;
00200 
00201 /*     Row and column exchange. */
00202 
00203 L20:
00204     scale[m] = (doublereal) j;
00205     if (j == m) {
00206         goto L30;
00207     }
00208 
00209     dswap_(&l, &a[j * a_dim1 + 1], &c__1, &a[m * a_dim1 + 1], &c__1);
00210     i__1 = *n - k + 1;
00211     dswap_(&i__1, &a[j + k * a_dim1], lda, &a[m + k * a_dim1], lda);
00212 
00213 L30:
00214     switch (iexc) {
00215         case 1:  goto L40;
00216         case 2:  goto L80;
00217     }
00218 
00219 /*     Search for rows isolating an eigenvalue and push them down. */
00220 
00221 L40:
00222     if (l == 1) {
00223         goto L210;
00224     }
00225     --l;
00226 
00227 L50:
00228     for (j = l; j >= 1; --j) {
00229 
00230         i__1 = l;
00231         for (i__ = 1; i__ <= i__1; ++i__) {
00232             if (i__ == j) {
00233                 goto L60;
00234             }
00235             if (a[j + i__ * a_dim1] != 0.) {
00236                 goto L70;
00237             }
00238 L60:
00239             ;
00240         }
00241 
00242         m = l;
00243         iexc = 1;
00244         goto L20;
00245 L70:
00246         ;
00247     }
00248 
00249     goto L90;
00250 
00251 /*     Search for columns isolating an eigenvalue and push them left. */
00252 
00253 L80:
00254     ++k;
00255 
00256 L90:
00257     i__1 = l;
00258     for (j = k; j <= i__1; ++j) {
00259 
00260         i__2 = l;
00261         for (i__ = k; i__ <= i__2; ++i__) {
00262             if (i__ == j) {
00263                 goto L100;
00264             }
00265             if (a[i__ + j * a_dim1] != 0.) {
00266                 goto L110;
00267             }
00268 L100:
00269             ;
00270         }
00271 
00272         m = k;
00273         iexc = 2;
00274         goto L20;
00275 L110:
00276         ;
00277     }
00278 
00279 L120:
00280     i__1 = l;
00281     for (i__ = k; i__ <= i__1; ++i__) {
00282         scale[i__] = 1.;
00283 /* L130: */
00284     }
00285 
00286     if (lsame_(job, "P")) {
00287         goto L210;
00288     }
00289 
00290 /*     Balance the submatrix in rows K to L. */
00291 
00292 /*     Iterative loop for norm reduction */
00293 
00294     sfmin1 = dlamch_("S") / dlamch_("P");
00295     sfmax1 = 1. / sfmin1;
00296     sfmin2 = sfmin1 * 2.;
00297     sfmax2 = 1. / sfmin2;
00298 L140:
00299     noconv = FALSE_;
00300 
00301     i__1 = l;
00302     for (i__ = k; i__ <= i__1; ++i__) {
00303         c__ = 0.;
00304         r__ = 0.;
00305 
00306         i__2 = l;
00307         for (j = k; j <= i__2; ++j) {
00308             if (j == i__) {
00309                 goto L150;
00310             }
00311             c__ += (d__1 = a[j + i__ * a_dim1], abs(d__1));
00312             r__ += (d__1 = a[i__ + j * a_dim1], abs(d__1));
00313 L150:
00314             ;
00315         }
00316         ica = idamax_(&l, &a[i__ * a_dim1 + 1], &c__1);
00317         ca = (d__1 = a[ica + i__ * a_dim1], abs(d__1));
00318         i__2 = *n - k + 1;
00319         ira = idamax_(&i__2, &a[i__ + k * a_dim1], lda);
00320         ra = (d__1 = a[i__ + (ira + k - 1) * a_dim1], abs(d__1));
00321 
00322 /*        Guard against zero C or R due to underflow. */
00323 
00324         if (c__ == 0. || r__ == 0.) {
00325             goto L200;
00326         }
00327         g = r__ / 2.;
00328         f = 1.;
00329         s = c__ + r__;
00330 L160:
00331 /* Computing MAX */
00332         d__1 = max(f,c__);
00333 /* Computing MIN */
00334         d__2 = min(r__,g);
00335         if (c__ >= g || max(d__1,ca) >= sfmax2 || min(d__2,ra) <= sfmin2) {
00336             goto L170;
00337         }
00338         f *= 2.;
00339         c__ *= 2.;
00340         ca *= 2.;
00341         r__ /= 2.;
00342         g /= 2.;
00343         ra /= 2.;
00344         goto L160;
00345 
00346 L170:
00347         g = c__ / 2.;
00348 L180:
00349 /* Computing MIN */
00350         d__1 = min(f,c__), d__1 = min(d__1,g);
00351         if (g < r__ || max(r__,ra) >= sfmax2 || min(d__1,ca) <= sfmin2) {
00352             goto L190;
00353         }
00354         f /= 2.;
00355         c__ /= 2.;
00356         g /= 2.;
00357         ca /= 2.;
00358         r__ *= 2.;
00359         ra *= 2.;
00360         goto L180;
00361 
00362 /*        Now balance. */
00363 
00364 L190:
00365         if (c__ + r__ >= s * .95) {
00366             goto L200;
00367         }
00368         if (f < 1. && scale[i__] < 1.) {
00369             if (f * scale[i__] <= sfmin1) {
00370                 goto L200;
00371             }
00372         }
00373         if (f > 1. && scale[i__] > 1.) {
00374             if (scale[i__] >= sfmax1 / f) {
00375                 goto L200;
00376             }
00377         }
00378         g = 1. / f;
00379         scale[i__] *= f;
00380         noconv = TRUE_;
00381 
00382         i__2 = *n - k + 1;
00383         dscal_(&i__2, &g, &a[i__ + k * a_dim1], lda);
00384         dscal_(&l, &f, &a[i__ * a_dim1 + 1], &c__1);
00385 
00386 L200:
00387         ;
00388     }
00389 
00390     if (noconv) {
00391         goto L140;
00392     }
00393 
00394 L210:
00395     *ilo = k;
00396     *ihi = l;
00397 
00398     return 0;
00399 
00400 /*     End of DGEBAL */
00401 
00402 } /* dgebal_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:43