dsyequb.c
Go to the documentation of this file.
00001 /* dsyequb.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 dsyequb_(char *uplo, integer *n, doublereal *a, integer *
00021         lda, doublereal *s, doublereal *scond, doublereal *amax, doublereal *
00022         work, integer *info)
00023 {
00024     /* System generated locals */
00025     integer a_dim1, a_offset, i__1, i__2;
00026     doublereal d__1, d__2, d__3;
00027 
00028     /* Builtin functions */
00029     double sqrt(doublereal), log(doublereal), pow_di(doublereal *, integer *);
00030 
00031     /* Local variables */
00032     doublereal d__;
00033     integer i__, j;
00034     doublereal t, u, c0, c1, c2, si;
00035     logical up;
00036     doublereal avg, std, tol, base;
00037     integer iter;
00038     doublereal smin, smax, scale;
00039     extern logical lsame_(char *, char *);
00040     doublereal sumsq;
00041     extern doublereal dlamch_(char *);
00042     extern /* Subroutine */ int xerbla_(char *, integer *);
00043     doublereal bignum;
00044     extern /* Subroutine */ int dlassq_(integer *, doublereal *, integer *, 
00045             doublereal *, doublereal *);
00046     doublereal smlnum;
00047 
00048 
00049 /*     -- LAPACK routine (version 3.2)                                 -- */
00050 /*     -- Contributed by James Demmel, Deaglan Halligan, Yozo Hida and -- */
00051 /*     -- Jason Riedy of Univ. of California Berkeley.                 -- */
00052 /*     -- November 2008                                                -- */
00053 
00054 /*     -- LAPACK is a software package provided by Univ. of Tennessee, -- */
00055 /*     -- Univ. of California Berkeley and NAG Ltd.                    -- */
00056 
00057 /*     .. */
00058 /*     .. Scalar Arguments .. */
00059 /*     .. */
00060 /*     .. Array Arguments .. */
00061 /*     .. */
00062 
00063 /*  Purpose */
00064 /*  ======= */
00065 
00066 /*  DSYEQUB computes row and column scalings intended to equilibrate a */
00067 /*  symmetric matrix A and reduce its condition number */
00068 /*  (with respect to the two-norm).  S contains the scale factors, */
00069 /*  S(i) = 1/sqrt(A(i,i)), chosen so that the scaled matrix B with */
00070 /*  elements B(i,j) = S(i)*A(i,j)*S(j) has ones on the diagonal.  This */
00071 /*  choice of S puts the condition number of B within a factor N of the */
00072 /*  smallest possible condition number over all possible diagonal */
00073 /*  scalings. */
00074 
00075 /*  Arguments */
00076 /*  ========= */
00077 
00078 /*  N       (input) INTEGER */
00079 /*          The order of the matrix A.  N >= 0. */
00080 
00081 /*  A       (input) DOUBLE PRECISION array, dimension (LDA,N) */
00082 /*          The N-by-N symmetric matrix whose scaling */
00083 /*          factors are to be computed.  Only the diagonal elements of A */
00084 /*          are referenced. */
00085 
00086 /*  LDA     (input) INTEGER */
00087 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00088 
00089 /*  S       (output) DOUBLE PRECISION array, dimension (N) */
00090 /*          If INFO = 0, S contains the scale factors for A. */
00091 
00092 /*  SCOND   (output) DOUBLE PRECISION */
00093 /*          If INFO = 0, S contains the ratio of the smallest S(i) to */
00094 /*          the largest S(i).  If SCOND >= 0.1 and AMAX is neither too */
00095 /*          large nor too small, it is not worth scaling by S. */
00096 
00097 /*  AMAX    (output) DOUBLE PRECISION */
00098 /*          Absolute value of largest matrix element.  If AMAX is very */
00099 /*          close to overflow or very close to underflow, the matrix */
00100 /*          should be scaled. */
00101 /*  INFO    (output) INTEGER */
00102 /*          = 0:  successful exit */
00103 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00104 /*          > 0:  if INFO = i, the i-th diagonal element is nonpositive. */
00105 
00106 /*  Further Details */
00107 /*  ======= ======= */
00108 
00109 /*  Reference: Livne, O.E. and Golub, G.H., "Scaling by Binormalization", */
00110 /*  Numerical Algorithms, vol. 35, no. 1, pp. 97-120, January 2004. */
00111 /*  DOI 10.1023/B:NUMA.0000016606.32820.69 */
00112 /*  Tech report version: http://ruready.utah.edu/archive/papers/bin.pdf */
00113 
00114 /*  ===================================================================== */
00115 
00116 /*     .. Parameters .. */
00117 /*     .. */
00118 /*     .. Local Scalars .. */
00119 /*     .. */
00120 /*     .. External Functions .. */
00121 /*     .. */
00122 /*     .. External Subroutines .. */
00123 /*     .. */
00124 /*     .. Executable Statements .. */
00125 
00126 /*     Test input parameters. */
00127 
00128     /* Parameter adjustments */
00129     a_dim1 = *lda;
00130     a_offset = 1 + a_dim1;
00131     a -= a_offset;
00132     --s;
00133     --work;
00134 
00135     /* Function Body */
00136     *info = 0;
00137     if (! (lsame_(uplo, "U") || lsame_(uplo, "L"))) {
00138         *info = -1;
00139     } else if (*n < 0) {
00140         *info = -2;
00141     } else if (*lda < max(1,*n)) {
00142         *info = -4;
00143     }
00144     if (*info != 0) {
00145         i__1 = -(*info);
00146         xerbla_("DSYEQUB", &i__1);
00147         return 0;
00148     }
00149     up = lsame_(uplo, "U");
00150     *amax = 0.;
00151 
00152 /*     Quick return if possible. */
00153 
00154     if (*n == 0) {
00155         *scond = 1.;
00156         return 0;
00157     }
00158     i__1 = *n;
00159     for (i__ = 1; i__ <= i__1; ++i__) {
00160         s[i__] = 0.;
00161     }
00162     *amax = 0.;
00163     if (up) {
00164         i__1 = *n;
00165         for (j = 1; j <= i__1; ++j) {
00166             i__2 = j - 1;
00167             for (i__ = 1; i__ <= i__2; ++i__) {
00168 /* Computing MAX */
00169                 d__2 = s[i__], d__3 = (d__1 = a[i__ + j * a_dim1], abs(d__1));
00170                 s[i__] = max(d__2,d__3);
00171 /* Computing MAX */
00172                 d__2 = s[j], d__3 = (d__1 = a[i__ + j * a_dim1], abs(d__1));
00173                 s[j] = max(d__2,d__3);
00174 /* Computing MAX */
00175                 d__2 = *amax, d__3 = (d__1 = a[i__ + j * a_dim1], abs(d__1));
00176                 *amax = max(d__2,d__3);
00177             }
00178 /* Computing MAX */
00179             d__2 = s[j], d__3 = (d__1 = a[j + j * a_dim1], abs(d__1));
00180             s[j] = max(d__2,d__3);
00181 /* Computing MAX */
00182             d__2 = *amax, d__3 = (d__1 = a[j + j * a_dim1], abs(d__1));
00183             *amax = max(d__2,d__3);
00184         }
00185     } else {
00186         i__1 = *n;
00187         for (j = 1; j <= i__1; ++j) {
00188 /* Computing MAX */
00189             d__2 = s[j], d__3 = (d__1 = a[j + j * a_dim1], abs(d__1));
00190             s[j] = max(d__2,d__3);
00191 /* Computing MAX */
00192             d__2 = *amax, d__3 = (d__1 = a[j + j * a_dim1], abs(d__1));
00193             *amax = max(d__2,d__3);
00194             i__2 = *n;
00195             for (i__ = j + 1; i__ <= i__2; ++i__) {
00196 /* Computing MAX */
00197                 d__2 = s[i__], d__3 = (d__1 = a[i__ + j * a_dim1], abs(d__1));
00198                 s[i__] = max(d__2,d__3);
00199 /* Computing MAX */
00200                 d__2 = s[j], d__3 = (d__1 = a[i__ + j * a_dim1], abs(d__1));
00201                 s[j] = max(d__2,d__3);
00202 /* Computing MAX */
00203                 d__2 = *amax, d__3 = (d__1 = a[i__ + j * a_dim1], abs(d__1));
00204                 *amax = max(d__2,d__3);
00205             }
00206         }
00207     }
00208     i__1 = *n;
00209     for (j = 1; j <= i__1; ++j) {
00210         s[j] = 1. / s[j];
00211     }
00212     tol = 1. / sqrt(*n * 2.);
00213     for (iter = 1; iter <= 100; ++iter) {
00214         scale = 0.;
00215         sumsq = 0.;
00216 /*       BETA = |A|S */
00217         i__1 = *n;
00218         for (i__ = 1; i__ <= i__1; ++i__) {
00219             work[i__] = 0.;
00220         }
00221         if (up) {
00222             i__1 = *n;
00223             for (j = 1; j <= i__1; ++j) {
00224                 i__2 = j - 1;
00225                 for (i__ = 1; i__ <= i__2; ++i__) {
00226                     t = (d__1 = a[i__ + j * a_dim1], abs(d__1));
00227                     work[i__] += (d__1 = a[i__ + j * a_dim1], abs(d__1)) * s[
00228                             j];
00229                     work[j] += (d__1 = a[i__ + j * a_dim1], abs(d__1)) * s[
00230                             i__];
00231                 }
00232                 work[j] += (d__1 = a[j + j * a_dim1], abs(d__1)) * s[j];
00233             }
00234         } else {
00235             i__1 = *n;
00236             for (j = 1; j <= i__1; ++j) {
00237                 work[j] += (d__1 = a[j + j * a_dim1], abs(d__1)) * s[j];
00238                 i__2 = *n;
00239                 for (i__ = j + 1; i__ <= i__2; ++i__) {
00240                     t = (d__1 = a[i__ + j * a_dim1], abs(d__1));
00241                     work[i__] += (d__1 = a[i__ + j * a_dim1], abs(d__1)) * s[
00242                             j];
00243                     work[j] += (d__1 = a[i__ + j * a_dim1], abs(d__1)) * s[
00244                             i__];
00245                 }
00246             }
00247         }
00248 /*       avg = s^T beta / n */
00249         avg = 0.;
00250         i__1 = *n;
00251         for (i__ = 1; i__ <= i__1; ++i__) {
00252             avg += s[i__] * work[i__];
00253         }
00254         avg /= *n;
00255         std = 0.;
00256         i__1 = *n * 3;
00257         for (i__ = (*n << 1) + 1; i__ <= i__1; ++i__) {
00258             work[i__] = s[i__ - (*n << 1)] * work[i__ - (*n << 1)] - avg;
00259         }
00260         dlassq_(n, &work[(*n << 1) + 1], &c__1, &scale, &sumsq);
00261         std = scale * sqrt(sumsq / *n);
00262         if (std < tol * avg) {
00263             goto L999;
00264         }
00265         i__1 = *n;
00266         for (i__ = 1; i__ <= i__1; ++i__) {
00267             t = (d__1 = a[i__ + i__ * a_dim1], abs(d__1));
00268             si = s[i__];
00269             c2 = (*n - 1) * t;
00270             c1 = (*n - 2) * (work[i__] - t * si);
00271             c0 = -(t * si) * si + work[i__] * 2 * si - *n * avg;
00272             d__ = c1 * c1 - c0 * 4 * c2;
00273             if (d__ <= 0.) {
00274                 *info = -1;
00275                 return 0;
00276             }
00277             si = c0 * -2 / (c1 + sqrt(d__));
00278             d__ = si - s[i__];
00279             u = 0.;
00280             if (up) {
00281                 i__2 = i__;
00282                 for (j = 1; j <= i__2; ++j) {
00283                     t = (d__1 = a[j + i__ * a_dim1], abs(d__1));
00284                     u += s[j] * t;
00285                     work[j] += d__ * t;
00286                 }
00287                 i__2 = *n;
00288                 for (j = i__ + 1; j <= i__2; ++j) {
00289                     t = (d__1 = a[i__ + j * a_dim1], abs(d__1));
00290                     u += s[j] * t;
00291                     work[j] += d__ * t;
00292                 }
00293             } else {
00294                 i__2 = i__;
00295                 for (j = 1; j <= i__2; ++j) {
00296                     t = (d__1 = a[i__ + j * a_dim1], abs(d__1));
00297                     u += s[j] * t;
00298                     work[j] += d__ * t;
00299                 }
00300                 i__2 = *n;
00301                 for (j = i__ + 1; j <= i__2; ++j) {
00302                     t = (d__1 = a[j + i__ * a_dim1], abs(d__1));
00303                     u += s[j] * t;
00304                     work[j] += d__ * t;
00305                 }
00306             }
00307             avg += (u + work[i__]) * d__ / *n;
00308             s[i__] = si;
00309         }
00310     }
00311 L999:
00312     smlnum = dlamch_("SAFEMIN");
00313     bignum = 1. / smlnum;
00314     smin = bignum;
00315     smax = 0.;
00316     t = 1. / sqrt(avg);
00317     base = dlamch_("B");
00318     u = 1. / log(base);
00319     i__1 = *n;
00320     for (i__ = 1; i__ <= i__1; ++i__) {
00321         i__2 = (integer) (u * log(s[i__] * t));
00322         s[i__] = pow_di(&base, &i__2);
00323 /* Computing MIN */
00324         d__1 = smin, d__2 = s[i__];
00325         smin = min(d__1,d__2);
00326 /* Computing MAX */
00327         d__1 = smax, d__2 = s[i__];
00328         smax = max(d__1,d__2);
00329     }
00330     *scond = max(smin,smlnum) / min(smax,bignum);
00331 
00332     return 0;
00333 } /* dsyequb_ */


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