slasq2.c
Go to the documentation of this file.
00001 /* slasq2.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 static integer c__2 = 2;
00020 
00021 /* Subroutine */ int slasq2_(integer *n, real *z__, integer *info)
00022 {
00023     /* System generated locals */
00024     integer i__1, i__2, i__3;
00025     real r__1, r__2;
00026 
00027     /* Builtin functions */
00028     double sqrt(doublereal);
00029 
00030     /* Local variables */
00031     real d__, e, g;
00032     integer k;
00033     real s, t;
00034     integer i0, i4, n0;
00035     real dn;
00036     integer pp;
00037     real dn1, dn2, dee, eps, tau, tol;
00038     integer ipn4;
00039     real tol2;
00040     logical ieee;
00041     integer nbig;
00042     real dmin__, emin, emax;
00043     integer kmin, ndiv, iter;
00044     real qmin, temp, qmax, zmax;
00045     integer splt;
00046     real dmin1, dmin2;
00047     integer nfail;
00048     real desig, trace, sigma;
00049     integer iinfo, ttype;
00050     extern /* Subroutine */ int slasq3_(integer *, integer *, real *, integer 
00051             *, real *, real *, real *, real *, integer *, integer *, integer *
00052 , logical *, integer *, real *, real *, real *, real *, real *, 
00053             real *, real *);
00054     real deemin;
00055     extern doublereal slamch_(char *);
00056     integer iwhila, iwhilb;
00057     real oldemn, safmin;
00058     extern /* Subroutine */ int xerbla_(char *, integer *), slasrt_(
00059             char *, integer *, real *, integer *);
00060 
00061 
00062 /*  -- LAPACK routine (version 3.2)                                    -- */
00063 
00064 /*  -- Contributed by Osni Marques of the Lawrence Berkeley National   -- */
00065 /*  -- Laboratory and Beresford Parlett of the Univ. of California at  -- */
00066 /*  -- Berkeley                                                        -- */
00067 /*  -- November 2008                                                   -- */
00068 
00069 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
00070 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
00071 
00072 /*     .. Scalar Arguments .. */
00073 /*     .. */
00074 /*     .. Array Arguments .. */
00075 /*     .. */
00076 
00077 /*  Purpose */
00078 /*  ======= */
00079 
00080 /*  SLASQ2 computes all the eigenvalues of the symmetric positive */
00081 /*  definite tridiagonal matrix associated with the qd array Z to high */
00082 /*  relative accuracy are computed to high relative accuracy, in the */
00083 /*  absence of denormalization, underflow and overflow. */
00084 
00085 /*  To see the relation of Z to the tridiagonal matrix, let L be a */
00086 /*  unit lower bidiagonal matrix with subdiagonals Z(2,4,6,,..) and */
00087 /*  let U be an upper bidiagonal matrix with 1's above and diagonal */
00088 /*  Z(1,3,5,,..). The tridiagonal is L*U or, if you prefer, the */
00089 /*  symmetric tridiagonal to which it is similar. */
00090 
00091 /*  Note : SLASQ2 defines a logical variable, IEEE, which is true */
00092 /*  on machines which follow ieee-754 floating-point standard in their */
00093 /*  handling of infinities and NaNs, and false otherwise. This variable */
00094 /*  is passed to SLASQ3. */
00095 
00096 /*  Arguments */
00097 /*  ========= */
00098 
00099 /*  N     (input) INTEGER */
00100 /*        The number of rows and columns in the matrix. N >= 0. */
00101 
00102 /*  Z     (input/output) REAL array, dimension ( 4*N ) */
00103 /*        On entry Z holds the qd array. On exit, entries 1 to N hold */
00104 /*        the eigenvalues in decreasing order, Z( 2*N+1 ) holds the */
00105 /*        trace, and Z( 2*N+2 ) holds the sum of the eigenvalues. If */
00106 /*        N > 2, then Z( 2*N+3 ) holds the iteration count, Z( 2*N+4 ) */
00107 /*        holds NDIVS/NIN^2, and Z( 2*N+5 ) holds the percentage of */
00108 /*        shifts that failed. */
00109 
00110 /*  INFO  (output) INTEGER */
00111 /*        = 0: successful exit */
00112 /*        < 0: if the i-th argument is a scalar and had an illegal */
00113 /*             value, then INFO = -i, if the i-th argument is an */
00114 /*             array and the j-entry had an illegal value, then */
00115 /*             INFO = -(i*100+j) */
00116 /*        > 0: the algorithm failed */
00117 /*              = 1, a split was marked by a positive value in E */
00118 /*              = 2, current block of Z not diagonalized after 30*N */
00119 /*                   iterations (in inner while loop) */
00120 /*              = 3, termination criterion of outer while loop not met */
00121 /*                   (program created more than N unreduced blocks) */
00122 
00123 /*  Further Details */
00124 /*  =============== */
00125 /*  Local Variables: I0:N0 defines a current unreduced segment of Z. */
00126 /*  The shifts are accumulated in SIGMA. Iteration count is in ITER. */
00127 /*  Ping-pong is controlled by PP (alternates between 0 and 1). */
00128 
00129 /*  ===================================================================== */
00130 
00131 /*     .. Parameters .. */
00132 /*     .. */
00133 /*     .. Local Scalars .. */
00134 /*     .. */
00135 /*     .. External Subroutines .. */
00136 /*     .. */
00137 /*     .. External Functions .. */
00138 /*     .. */
00139 /*     .. Intrinsic Functions .. */
00140 /*     .. */
00141 /*     .. Executable Statements .. */
00142 
00143 /*     Test the input arguments. */
00144 /*     (in case SLASQ2 is not called by SLASQ1) */
00145 
00146     /* Parameter adjustments */
00147     --z__;
00148 
00149     /* Function Body */
00150     *info = 0;
00151     eps = slamch_("Precision");
00152     safmin = slamch_("Safe minimum");
00153     tol = eps * 100.f;
00154 /* Computing 2nd power */
00155     r__1 = tol;
00156     tol2 = r__1 * r__1;
00157 
00158     if (*n < 0) {
00159         *info = -1;
00160         xerbla_("SLASQ2", &c__1);
00161         return 0;
00162     } else if (*n == 0) {
00163         return 0;
00164     } else if (*n == 1) {
00165 
00166 /*        1-by-1 case. */
00167 
00168         if (z__[1] < 0.f) {
00169             *info = -201;
00170             xerbla_("SLASQ2", &c__2);
00171         }
00172         return 0;
00173     } else if (*n == 2) {
00174 
00175 /*        2-by-2 case. */
00176 
00177         if (z__[2] < 0.f || z__[3] < 0.f) {
00178             *info = -2;
00179             xerbla_("SLASQ2", &c__2);
00180             return 0;
00181         } else if (z__[3] > z__[1]) {
00182             d__ = z__[3];
00183             z__[3] = z__[1];
00184             z__[1] = d__;
00185         }
00186         z__[5] = z__[1] + z__[2] + z__[3];
00187         if (z__[2] > z__[3] * tol2) {
00188             t = (z__[1] - z__[3] + z__[2]) * .5f;
00189             s = z__[3] * (z__[2] / t);
00190             if (s <= t) {
00191                 s = z__[3] * (z__[2] / (t * (sqrt(s / t + 1.f) + 1.f)));
00192             } else {
00193                 s = z__[3] * (z__[2] / (t + sqrt(t) * sqrt(t + s)));
00194             }
00195             t = z__[1] + (s + z__[2]);
00196             z__[3] *= z__[1] / t;
00197             z__[1] = t;
00198         }
00199         z__[2] = z__[3];
00200         z__[6] = z__[2] + z__[1];
00201         return 0;
00202     }
00203 
00204 /*     Check for negative data and compute sums of q's and e's. */
00205 
00206     z__[*n * 2] = 0.f;
00207     emin = z__[2];
00208     qmax = 0.f;
00209     zmax = 0.f;
00210     d__ = 0.f;
00211     e = 0.f;
00212 
00213     i__1 = *n - 1 << 1;
00214     for (k = 1; k <= i__1; k += 2) {
00215         if (z__[k] < 0.f) {
00216             *info = -(k + 200);
00217             xerbla_("SLASQ2", &c__2);
00218             return 0;
00219         } else if (z__[k + 1] < 0.f) {
00220             *info = -(k + 201);
00221             xerbla_("SLASQ2", &c__2);
00222             return 0;
00223         }
00224         d__ += z__[k];
00225         e += z__[k + 1];
00226 /* Computing MAX */
00227         r__1 = qmax, r__2 = z__[k];
00228         qmax = dmax(r__1,r__2);
00229 /* Computing MIN */
00230         r__1 = emin, r__2 = z__[k + 1];
00231         emin = dmin(r__1,r__2);
00232 /* Computing MAX */
00233         r__1 = max(qmax,zmax), r__2 = z__[k + 1];
00234         zmax = dmax(r__1,r__2);
00235 /* L10: */
00236     }
00237     if (z__[(*n << 1) - 1] < 0.f) {
00238         *info = -((*n << 1) + 199);
00239         xerbla_("SLASQ2", &c__2);
00240         return 0;
00241     }
00242     d__ += z__[(*n << 1) - 1];
00243 /* Computing MAX */
00244     r__1 = qmax, r__2 = z__[(*n << 1) - 1];
00245     qmax = dmax(r__1,r__2);
00246     zmax = dmax(qmax,zmax);
00247 
00248 /*     Check for diagonality. */
00249 
00250     if (e == 0.f) {
00251         i__1 = *n;
00252         for (k = 2; k <= i__1; ++k) {
00253             z__[k] = z__[(k << 1) - 1];
00254 /* L20: */
00255         }
00256         slasrt_("D", n, &z__[1], &iinfo);
00257         z__[(*n << 1) - 1] = d__;
00258         return 0;
00259     }
00260 
00261     trace = d__ + e;
00262 
00263 /*     Check for zero data. */
00264 
00265     if (trace == 0.f) {
00266         z__[(*n << 1) - 1] = 0.f;
00267         return 0;
00268     }
00269 
00270 /*     Check whether the machine is IEEE conformable. */
00271 
00272 /*     IEEE = ILAENV( 10, 'SLASQ2', 'N', 1, 2, 3, 4 ).EQ.1 .AND. */
00273 /*    $       ILAENV( 11, 'SLASQ2', 'N', 1, 2, 3, 4 ).EQ.1 */
00274 
00275 /*     [11/15/2008] The case IEEE=.TRUE. has a problem in single precision with */
00276 /*     some the test matrices of type 16. The double precision code is fine. */
00277 
00278     ieee = FALSE_;
00279 
00280 /*     Rearrange data for locality: Z=(q1,qq1,e1,ee1,q2,qq2,e2,ee2,...). */
00281 
00282     for (k = *n << 1; k >= 2; k += -2) {
00283         z__[k * 2] = 0.f;
00284         z__[(k << 1) - 1] = z__[k];
00285         z__[(k << 1) - 2] = 0.f;
00286         z__[(k << 1) - 3] = z__[k - 1];
00287 /* L30: */
00288     }
00289 
00290     i0 = 1;
00291     n0 = *n;
00292 
00293 /*     Reverse the qd-array, if warranted. */
00294 
00295     if (z__[(i0 << 2) - 3] * 1.5f < z__[(n0 << 2) - 3]) {
00296         ipn4 = i0 + n0 << 2;
00297         i__1 = i0 + n0 - 1 << 1;
00298         for (i4 = i0 << 2; i4 <= i__1; i4 += 4) {
00299             temp = z__[i4 - 3];
00300             z__[i4 - 3] = z__[ipn4 - i4 - 3];
00301             z__[ipn4 - i4 - 3] = temp;
00302             temp = z__[i4 - 1];
00303             z__[i4 - 1] = z__[ipn4 - i4 - 5];
00304             z__[ipn4 - i4 - 5] = temp;
00305 /* L40: */
00306         }
00307     }
00308 
00309 /*     Initial split checking via dqd and Li's test. */
00310 
00311     pp = 0;
00312 
00313     for (k = 1; k <= 2; ++k) {
00314 
00315         d__ = z__[(n0 << 2) + pp - 3];
00316         i__1 = (i0 << 2) + pp;
00317         for (i4 = (n0 - 1 << 2) + pp; i4 >= i__1; i4 += -4) {
00318             if (z__[i4 - 1] <= tol2 * d__) {
00319                 z__[i4 - 1] = -0.f;
00320                 d__ = z__[i4 - 3];
00321             } else {
00322                 d__ = z__[i4 - 3] * (d__ / (d__ + z__[i4 - 1]));
00323             }
00324 /* L50: */
00325         }
00326 
00327 /*        dqd maps Z to ZZ plus Li's test. */
00328 
00329         emin = z__[(i0 << 2) + pp + 1];
00330         d__ = z__[(i0 << 2) + pp - 3];
00331         i__1 = (n0 - 1 << 2) + pp;
00332         for (i4 = (i0 << 2) + pp; i4 <= i__1; i4 += 4) {
00333             z__[i4 - (pp << 1) - 2] = d__ + z__[i4 - 1];
00334             if (z__[i4 - 1] <= tol2 * d__) {
00335                 z__[i4 - 1] = -0.f;
00336                 z__[i4 - (pp << 1) - 2] = d__;
00337                 z__[i4 - (pp << 1)] = 0.f;
00338                 d__ = z__[i4 + 1];
00339             } else if (safmin * z__[i4 + 1] < z__[i4 - (pp << 1) - 2] && 
00340                     safmin * z__[i4 - (pp << 1) - 2] < z__[i4 + 1]) {
00341                 temp = z__[i4 + 1] / z__[i4 - (pp << 1) - 2];
00342                 z__[i4 - (pp << 1)] = z__[i4 - 1] * temp;
00343                 d__ *= temp;
00344             } else {
00345                 z__[i4 - (pp << 1)] = z__[i4 + 1] * (z__[i4 - 1] / z__[i4 - (
00346                         pp << 1) - 2]);
00347                 d__ = z__[i4 + 1] * (d__ / z__[i4 - (pp << 1) - 2]);
00348             }
00349 /* Computing MIN */
00350             r__1 = emin, r__2 = z__[i4 - (pp << 1)];
00351             emin = dmin(r__1,r__2);
00352 /* L60: */
00353         }
00354         z__[(n0 << 2) - pp - 2] = d__;
00355 
00356 /*        Now find qmax. */
00357 
00358         qmax = z__[(i0 << 2) - pp - 2];
00359         i__1 = (n0 << 2) - pp - 2;
00360         for (i4 = (i0 << 2) - pp + 2; i4 <= i__1; i4 += 4) {
00361 /* Computing MAX */
00362             r__1 = qmax, r__2 = z__[i4];
00363             qmax = dmax(r__1,r__2);
00364 /* L70: */
00365         }
00366 
00367 /*        Prepare for the next iteration on K. */
00368 
00369         pp = 1 - pp;
00370 /* L80: */
00371     }
00372 
00373 /*     Initialise variables to pass to SLASQ3. */
00374 
00375     ttype = 0;
00376     dmin1 = 0.f;
00377     dmin2 = 0.f;
00378     dn = 0.f;
00379     dn1 = 0.f;
00380     dn2 = 0.f;
00381     g = 0.f;
00382     tau = 0.f;
00383 
00384     iter = 2;
00385     nfail = 0;
00386     ndiv = n0 - i0 << 1;
00387 
00388     i__1 = *n + 1;
00389     for (iwhila = 1; iwhila <= i__1; ++iwhila) {
00390         if (n0 < 1) {
00391             goto L170;
00392         }
00393 
00394 /*        While array unfinished do */
00395 
00396 /*        E(N0) holds the value of SIGMA when submatrix in I0:N0 */
00397 /*        splits from the rest of the array, but is negated. */
00398 
00399         desig = 0.f;
00400         if (n0 == *n) {
00401             sigma = 0.f;
00402         } else {
00403             sigma = -z__[(n0 << 2) - 1];
00404         }
00405         if (sigma < 0.f) {
00406             *info = 1;
00407             return 0;
00408         }
00409 
00410 /*        Find last unreduced submatrix's top index I0, find QMAX and */
00411 /*        EMIN. Find Gershgorin-type bound if Q's much greater than E's. */
00412 
00413         emax = 0.f;
00414         if (n0 > i0) {
00415             emin = (r__1 = z__[(n0 << 2) - 5], dabs(r__1));
00416         } else {
00417             emin = 0.f;
00418         }
00419         qmin = z__[(n0 << 2) - 3];
00420         qmax = qmin;
00421         for (i4 = n0 << 2; i4 >= 8; i4 += -4) {
00422             if (z__[i4 - 5] <= 0.f) {
00423                 goto L100;
00424             }
00425             if (qmin >= emax * 4.f) {
00426 /* Computing MIN */
00427                 r__1 = qmin, r__2 = z__[i4 - 3];
00428                 qmin = dmin(r__1,r__2);
00429 /* Computing MAX */
00430                 r__1 = emax, r__2 = z__[i4 - 5];
00431                 emax = dmax(r__1,r__2);
00432             }
00433 /* Computing MAX */
00434             r__1 = qmax, r__2 = z__[i4 - 7] + z__[i4 - 5];
00435             qmax = dmax(r__1,r__2);
00436 /* Computing MIN */
00437             r__1 = emin, r__2 = z__[i4 - 5];
00438             emin = dmin(r__1,r__2);
00439 /* L90: */
00440         }
00441         i4 = 4;
00442 
00443 L100:
00444         i0 = i4 / 4;
00445         pp = 0;
00446 
00447         if (n0 - i0 > 1) {
00448             dee = z__[(i0 << 2) - 3];
00449             deemin = dee;
00450             kmin = i0;
00451             i__2 = (n0 << 2) - 3;
00452             for (i4 = (i0 << 2) + 1; i4 <= i__2; i4 += 4) {
00453                 dee = z__[i4] * (dee / (dee + z__[i4 - 2]));
00454                 if (dee <= deemin) {
00455                     deemin = dee;
00456                     kmin = (i4 + 3) / 4;
00457                 }
00458 /* L110: */
00459             }
00460             if (kmin - i0 << 1 < n0 - kmin && deemin <= z__[(n0 << 2) - 3] * 
00461                     .5f) {
00462                 ipn4 = i0 + n0 << 2;
00463                 pp = 2;
00464                 i__2 = i0 + n0 - 1 << 1;
00465                 for (i4 = i0 << 2; i4 <= i__2; i4 += 4) {
00466                     temp = z__[i4 - 3];
00467                     z__[i4 - 3] = z__[ipn4 - i4 - 3];
00468                     z__[ipn4 - i4 - 3] = temp;
00469                     temp = z__[i4 - 2];
00470                     z__[i4 - 2] = z__[ipn4 - i4 - 2];
00471                     z__[ipn4 - i4 - 2] = temp;
00472                     temp = z__[i4 - 1];
00473                     z__[i4 - 1] = z__[ipn4 - i4 - 5];
00474                     z__[ipn4 - i4 - 5] = temp;
00475                     temp = z__[i4];
00476                     z__[i4] = z__[ipn4 - i4 - 4];
00477                     z__[ipn4 - i4 - 4] = temp;
00478 /* L120: */
00479                 }
00480             }
00481         }
00482 
00483 /*        Put -(initial shift) into DMIN. */
00484 
00485 /* Computing MAX */
00486         r__1 = 0.f, r__2 = qmin - sqrt(qmin) * 2.f * sqrt(emax);
00487         dmin__ = -dmax(r__1,r__2);
00488 
00489 /*        Now I0:N0 is unreduced. */
00490 /*        PP = 0 for ping, PP = 1 for pong. */
00491 /*        PP = 2 indicates that flipping was applied to the Z array and */
00492 /*               and that the tests for deflation upon entry in SLASQ3 */
00493 /*               should not be performed. */
00494 
00495         nbig = (n0 - i0 + 1) * 30;
00496         i__2 = nbig;
00497         for (iwhilb = 1; iwhilb <= i__2; ++iwhilb) {
00498             if (i0 > n0) {
00499                 goto L150;
00500             }
00501 
00502 /*           While submatrix unfinished take a good dqds step. */
00503 
00504             slasq3_(&i0, &n0, &z__[1], &pp, &dmin__, &sigma, &desig, &qmax, &
00505                     nfail, &iter, &ndiv, &ieee, &ttype, &dmin1, &dmin2, &dn, &
00506                     dn1, &dn2, &g, &tau);
00507 
00508             pp = 1 - pp;
00509 
00510 /*           When EMIN is very small check for splits. */
00511 
00512             if (pp == 0 && n0 - i0 >= 3) {
00513                 if (z__[n0 * 4] <= tol2 * qmax || z__[(n0 << 2) - 1] <= tol2 *
00514                          sigma) {
00515                     splt = i0 - 1;
00516                     qmax = z__[(i0 << 2) - 3];
00517                     emin = z__[(i0 << 2) - 1];
00518                     oldemn = z__[i0 * 4];
00519                     i__3 = n0 - 3 << 2;
00520                     for (i4 = i0 << 2; i4 <= i__3; i4 += 4) {
00521                         if (z__[i4] <= tol2 * z__[i4 - 3] || z__[i4 - 1] <= 
00522                                 tol2 * sigma) {
00523                             z__[i4 - 1] = -sigma;
00524                             splt = i4 / 4;
00525                             qmax = 0.f;
00526                             emin = z__[i4 + 3];
00527                             oldemn = z__[i4 + 4];
00528                         } else {
00529 /* Computing MAX */
00530                             r__1 = qmax, r__2 = z__[i4 + 1];
00531                             qmax = dmax(r__1,r__2);
00532 /* Computing MIN */
00533                             r__1 = emin, r__2 = z__[i4 - 1];
00534                             emin = dmin(r__1,r__2);
00535 /* Computing MIN */
00536                             r__1 = oldemn, r__2 = z__[i4];
00537                             oldemn = dmin(r__1,r__2);
00538                         }
00539 /* L130: */
00540                     }
00541                     z__[(n0 << 2) - 1] = emin;
00542                     z__[n0 * 4] = oldemn;
00543                     i0 = splt + 1;
00544                 }
00545             }
00546 
00547 /* L140: */
00548         }
00549 
00550         *info = 2;
00551         return 0;
00552 
00553 /*        end IWHILB */
00554 
00555 L150:
00556 
00557 /* L160: */
00558         ;
00559     }
00560 
00561     *info = 3;
00562     return 0;
00563 
00564 /*     end IWHILA */
00565 
00566 L170:
00567 
00568 /*     Move q's to the front. */
00569 
00570     i__1 = *n;
00571     for (k = 2; k <= i__1; ++k) {
00572         z__[k] = z__[(k << 2) - 3];
00573 /* L180: */
00574     }
00575 
00576 /*     Sort and compute sum of eigenvalues. */
00577 
00578     slasrt_("D", n, &z__[1], &iinfo);
00579 
00580     e = 0.f;
00581     for (k = *n; k >= 1; --k) {
00582         e += z__[k];
00583 /* L190: */
00584     }
00585 
00586 /*     Store trace, sum(eigenvalues) and information on performance. */
00587 
00588     z__[(*n << 1) + 1] = trace;
00589     z__[(*n << 1) + 2] = e;
00590     z__[(*n << 1) + 3] = (real) iter;
00591 /* Computing 2nd power */
00592     i__1 = *n;
00593     z__[(*n << 1) + 4] = (real) ndiv / (real) (i__1 * i__1);
00594     z__[(*n << 1) + 5] = nfail * 100.f / (real) iter;
00595     return 0;
00596 
00597 /*     End of SLASQ2 */
00598 
00599 } /* slasq2_ */


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