slarre.c
Go to the documentation of this file.
00001 /* slarre.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 slarre_(char *range, integer *n, real *vl, real *vu, 
00022         integer *il, integer *iu, real *d__, real *e, real *e2, real *rtol1, 
00023         real *rtol2, real *spltol, integer *nsplit, integer *isplit, integer *
00024         m, real *w, real *werr, real *wgap, integer *iblock, integer *indexw, 
00025         real *gers, real *pivmin, real *work, integer *iwork, integer *info)
00026 {
00027     /* System generated locals */
00028     integer i__1, i__2;
00029     real r__1, r__2, r__3;
00030 
00031     /* Builtin functions */
00032     double sqrt(doublereal), log(doublereal);
00033 
00034     /* Local variables */
00035     integer i__, j;
00036     real s1, s2;
00037     integer mb;
00038     real gl;
00039     integer in, mm;
00040     real gu;
00041     integer cnt;
00042     real eps, tau, tmp, rtl;
00043     integer cnt1, cnt2;
00044     real tmp1, eabs;
00045     integer iend, jblk;
00046     real eold;
00047     integer indl;
00048     real dmax__, emax;
00049     integer wend, idum, indu;
00050     real rtol;
00051     integer iseed[4];
00052     real avgap, sigma;
00053     extern logical lsame_(char *, char *);
00054     integer iinfo;
00055     logical norep;
00056     extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, 
00057             integer *), slasq2_(integer *, real *, integer *);
00058     integer ibegin;
00059     logical forceb;
00060     integer irange;
00061     real sgndef;
00062     extern doublereal slamch_(char *);
00063     integer wbegin;
00064     real safmin, spdiam;
00065     extern /* Subroutine */ int slarra_(integer *, real *, real *, real *, 
00066             real *, real *, integer *, integer *, integer *);
00067     logical usedqd;
00068     real clwdth, isleft;
00069     extern /* Subroutine */ int slarrb_(integer *, real *, real *, integer *, 
00070             integer *, real *, real *, integer *, real *, real *, real *, 
00071             real *, integer *, real *, real *, integer *, integer *), slarrc_(
00072             char *, integer *, real *, real *, real *, real *, real *, 
00073             integer *, integer *, integer *, integer *), slarrd_(char 
00074             *, char *, integer *, real *, real *, integer *, integer *, real *
00075 , real *, real *, real *, real *, real *, integer *, integer *, 
00076             integer *, real *, real *, real *, real *, integer *, integer *, 
00077             real *, integer *, integer *), slarrk_(integer *, 
00078             integer *, real *, real *, real *, real *, real *, real *, real *, 
00079              real *, integer *);
00080     real isrght, bsrtol, dpivot;
00081     extern /* Subroutine */ int slarnv_(integer *, integer *, integer *, real 
00082             *);
00083 
00084 
00085 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00086 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00087 /*     November 2006 */
00088 
00089 /*     .. Scalar Arguments .. */
00090 /*     .. */
00091 /*     .. Array Arguments .. */
00092 /*     .. */
00093 
00094 /*  Purpose */
00095 /*  ======= */
00096 
00097 /*  To find the desired eigenvalues of a given real symmetric */
00098 /*  tridiagonal matrix T, SLARRE sets any "small" off-diagonal */
00099 /*  elements to zero, and for each unreduced block T_i, it finds */
00100 /*  (a) a suitable shift at one end of the block's spectrum, */
00101 /*  (b) the base representation, T_i - sigma_i I = L_i D_i L_i^T, and */
00102 /*  (c) eigenvalues of each L_i D_i L_i^T. */
00103 /*  The representations and eigenvalues found are then used by */
00104 /*  SSTEMR to compute the eigenvectors of T. */
00105 /*  The accuracy varies depending on whether bisection is used to */
00106 /*  find a few eigenvalues or the dqds algorithm (subroutine SLASQ2) to */
00107 /*  conpute all and then discard any unwanted one. */
00108 /*  As an added benefit, SLARRE also outputs the n */
00109 /*  Gerschgorin intervals for the matrices L_i D_i L_i^T. */
00110 
00111 /*  Arguments */
00112 /*  ========= */
00113 
00114 /*  RANGE   (input) CHARACTER */
00115 /*          = 'A': ("All")   all eigenvalues will be found. */
00116 /*          = 'V': ("Value") all eigenvalues in the half-open interval */
00117 /*                           (VL, VU] will be found. */
00118 /*          = 'I': ("Index") the IL-th through IU-th eigenvalues (of the */
00119 /*                           entire matrix) will be found. */
00120 
00121 /*  N       (input) INTEGER */
00122 /*          The order of the matrix. N > 0. */
00123 
00124 /*  VL      (input/output) REAL */
00125 /*  VU      (input/output) REAL */
00126 /*          If RANGE='V', the lower and upper bounds for the eigenvalues. */
00127 /*          Eigenvalues less than or equal to VL, or greater than VU, */
00128 /*          will not be returned.  VL < VU. */
00129 /*          If RANGE='I' or ='A', SLARRE computes bounds on the desired */
00130 /*          part of the spectrum. */
00131 
00132 /*  IL      (input) INTEGER */
00133 /*  IU      (input) INTEGER */
00134 /*          If RANGE='I', the indices (in ascending order) of the */
00135 /*          smallest and largest eigenvalues to be returned. */
00136 /*          1 <= IL <= IU <= N. */
00137 
00138 /*  D       (input/output) REAL             array, dimension (N) */
00139 /*          On entry, the N diagonal elements of the tridiagonal */
00140 /*          matrix T. */
00141 /*          On exit, the N diagonal elements of the diagonal */
00142 /*          matrices D_i. */
00143 
00144 /*  E       (input/output) REAL             array, dimension (N) */
00145 /*          On entry, the first (N-1) entries contain the subdiagonal */
00146 /*          elements of the tridiagonal matrix T; E(N) need not be set. */
00147 /*          On exit, E contains the subdiagonal elements of the unit */
00148 /*          bidiagonal matrices L_i. The entries E( ISPLIT( I ) ), */
00149 /*          1 <= I <= NSPLIT, contain the base points sigma_i on output. */
00150 
00151 /*  E2      (input/output) REAL             array, dimension (N) */
00152 /*          On entry, the first (N-1) entries contain the SQUARES of the */
00153 /*          subdiagonal elements of the tridiagonal matrix T; */
00154 /*          E2(N) need not be set. */
00155 /*          On exit, the entries E2( ISPLIT( I ) ), */
00156 /*          1 <= I <= NSPLIT, have been set to zero */
00157 
00158 /*  RTOL1   (input) REAL */
00159 /*  RTOL2   (input) REAL */
00160 /*           Parameters for bisection. */
00161 /*           An interval [LEFT,RIGHT] has converged if */
00162 /*           RIGHT-LEFT.LT.MAX( RTOL1*GAP, RTOL2*MAX(|LEFT|,|RIGHT|) ) */
00163 
00164 /*  SPLTOL (input) REAL */
00165 /*          The threshold for splitting. */
00166 
00167 /*  NSPLIT  (output) INTEGER */
00168 /*          The number of blocks T splits into. 1 <= NSPLIT <= N. */
00169 
00170 /*  ISPLIT  (output) INTEGER array, dimension (N) */
00171 /*          The splitting points, at which T breaks up into blocks. */
00172 /*          The first block consists of rows/columns 1 to ISPLIT(1), */
00173 /*          the second of rows/columns ISPLIT(1)+1 through ISPLIT(2), */
00174 /*          etc., and the NSPLIT-th consists of rows/columns */
00175 /*          ISPLIT(NSPLIT-1)+1 through ISPLIT(NSPLIT)=N. */
00176 
00177 /*  M       (output) INTEGER */
00178 /*          The total number of eigenvalues (of all L_i D_i L_i^T) */
00179 /*          found. */
00180 
00181 /*  W       (output) REAL             array, dimension (N) */
00182 /*          The first M elements contain the eigenvalues. The */
00183 /*          eigenvalues of each of the blocks, L_i D_i L_i^T, are */
00184 /*          sorted in ascending order ( SLARRE may use the */
00185 /*          remaining N-M elements as workspace). */
00186 
00187 /*  WERR    (output) REAL             array, dimension (N) */
00188 /*          The error bound on the corresponding eigenvalue in W. */
00189 
00190 /*  WGAP    (output) REAL             array, dimension (N) */
00191 /*          The separation from the right neighbor eigenvalue in W. */
00192 /*          The gap is only with respect to the eigenvalues of the same block */
00193 /*          as each block has its own representation tree. */
00194 /*          Exception: at the right end of a block we store the left gap */
00195 
00196 /*  IBLOCK  (output) INTEGER array, dimension (N) */
00197 /*          The indices of the blocks (submatrices) associated with the */
00198 /*          corresponding eigenvalues in W; IBLOCK(i)=1 if eigenvalue */
00199 /*          W(i) belongs to the first block from the top, =2 if W(i) */
00200 /*          belongs to the second block, etc. */
00201 
00202 /*  INDEXW  (output) INTEGER array, dimension (N) */
00203 /*          The indices of the eigenvalues within each block (submatrix); */
00204 /*          for example, INDEXW(i)= 10 and IBLOCK(i)=2 imply that the */
00205 /*          i-th eigenvalue W(i) is the 10-th eigenvalue in block 2 */
00206 
00207 /*  GERS    (output) REAL             array, dimension (2*N) */
00208 /*          The N Gerschgorin intervals (the i-th Gerschgorin interval */
00209 /*          is (GERS(2*i-1), GERS(2*i)). */
00210 
00211 /*  PIVMIN  (output) DOUBLE PRECISION */
00212 /*          The minimum pivot in the Sturm sequence for T. */
00213 
00214 /*  WORK    (workspace) REAL             array, dimension (6*N) */
00215 /*          Workspace. */
00216 
00217 /*  IWORK   (workspace) INTEGER array, dimension (5*N) */
00218 /*          Workspace. */
00219 
00220 /*  INFO    (output) INTEGER */
00221 /*          = 0:  successful exit */
00222 /*          > 0:  A problem occured in SLARRE. */
00223 /*          < 0:  One of the called subroutines signaled an internal problem. */
00224 /*                Needs inspection of the corresponding parameter IINFO */
00225 /*                for further information. */
00226 
00227 /*          =-1:  Problem in SLARRD. */
00228 /*          = 2:  No base representation could be found in MAXTRY iterations. */
00229 /*                Increasing MAXTRY and recompilation might be a remedy. */
00230 /*          =-3:  Problem in SLARRB when computing the refined root */
00231 /*                representation for SLASQ2. */
00232 /*          =-4:  Problem in SLARRB when preforming bisection on the */
00233 /*                desired part of the spectrum. */
00234 /*          =-5:  Problem in SLASQ2. */
00235 /*          =-6:  Problem in SLASQ2. */
00236 
00237 /*  Further Details */
00238 /*  The base representations are required to suffer very little */
00239 /*  element growth and consequently define all their eigenvalues to */
00240 /*  high relative accuracy. */
00241 /*  =============== */
00242 
00243 /*  Based on contributions by */
00244 /*     Beresford Parlett, University of California, Berkeley, USA */
00245 /*     Jim Demmel, University of California, Berkeley, USA */
00246 /*     Inderjit Dhillon, University of Texas, Austin, USA */
00247 /*     Osni Marques, LBNL/NERSC, USA */
00248 /*     Christof Voemel, University of California, Berkeley, USA */
00249 
00250 /*  ===================================================================== */
00251 
00252 /*     .. Parameters .. */
00253 /*     .. */
00254 /*     .. Local Scalars .. */
00255 /*     .. */
00256 /*     .. Local Arrays .. */
00257 /*     .. */
00258 /*     .. External Functions .. */
00259 /*     .. */
00260 /*     .. External Subroutines .. */
00261 /*     .. */
00262 /*     .. Intrinsic Functions .. */
00263 /*     .. */
00264 /*     .. Executable Statements .. */
00265 
00266     /* Parameter adjustments */
00267     --iwork;
00268     --work;
00269     --gers;
00270     --indexw;
00271     --iblock;
00272     --wgap;
00273     --werr;
00274     --w;
00275     --isplit;
00276     --e2;
00277     --e;
00278     --d__;
00279 
00280     /* Function Body */
00281     *info = 0;
00282 
00283 /*     Decode RANGE */
00284 
00285     if (lsame_(range, "A")) {
00286         irange = 1;
00287     } else if (lsame_(range, "V")) {
00288         irange = 3;
00289     } else if (lsame_(range, "I")) {
00290         irange = 2;
00291     }
00292     *m = 0;
00293 /*     Get machine constants */
00294     safmin = slamch_("S");
00295     eps = slamch_("P");
00296 /*     Set parameters */
00297     rtl = eps * 100.f;
00298 /*     If one were ever to ask for less initial precision in BSRTOL, */
00299 /*     one should keep in mind that for the subset case, the extremal */
00300 /*     eigenvalues must be at least as accurate as the current setting */
00301 /*     (eigenvalues in the middle need not as much accuracy) */
00302     bsrtol = sqrt(eps) * 5e-4f;
00303 /*     Treat case of 1x1 matrix for quick return */
00304     if (*n == 1) {
00305         if (irange == 1 || irange == 3 && d__[1] > *vl && d__[1] <= *vu || 
00306                 irange == 2 && *il == 1 && *iu == 1) {
00307             *m = 1;
00308             w[1] = d__[1];
00309 /*           The computation error of the eigenvalue is zero */
00310             werr[1] = 0.f;
00311             wgap[1] = 0.f;
00312             iblock[1] = 1;
00313             indexw[1] = 1;
00314             gers[1] = d__[1];
00315             gers[2] = d__[1];
00316         }
00317 /*        store the shift for the initial RRR, which is zero in this case */
00318         e[1] = 0.f;
00319         return 0;
00320     }
00321 /*     General case: tridiagonal matrix of order > 1 */
00322 
00323 /*     Init WERR, WGAP. Compute Gerschgorin intervals and spectral diameter. */
00324 /*     Compute maximum off-diagonal entry and pivmin. */
00325     gl = d__[1];
00326     gu = d__[1];
00327     eold = 0.f;
00328     emax = 0.f;
00329     e[*n] = 0.f;
00330     i__1 = *n;
00331     for (i__ = 1; i__ <= i__1; ++i__) {
00332         werr[i__] = 0.f;
00333         wgap[i__] = 0.f;
00334         eabs = (r__1 = e[i__], dabs(r__1));
00335         if (eabs >= emax) {
00336             emax = eabs;
00337         }
00338         tmp1 = eabs + eold;
00339         gers[(i__ << 1) - 1] = d__[i__] - tmp1;
00340 /* Computing MIN */
00341         r__1 = gl, r__2 = gers[(i__ << 1) - 1];
00342         gl = dmin(r__1,r__2);
00343         gers[i__ * 2] = d__[i__] + tmp1;
00344 /* Computing MAX */
00345         r__1 = gu, r__2 = gers[i__ * 2];
00346         gu = dmax(r__1,r__2);
00347         eold = eabs;
00348 /* L5: */
00349     }
00350 /*     The minimum pivot allowed in the Sturm sequence for T */
00351 /* Computing MAX */
00352 /* Computing 2nd power */
00353     r__3 = emax;
00354     r__1 = 1.f, r__2 = r__3 * r__3;
00355     *pivmin = safmin * dmax(r__1,r__2);
00356 /*     Compute spectral diameter. The Gerschgorin bounds give an */
00357 /*     estimate that is wrong by at most a factor of SQRT(2) */
00358     spdiam = gu - gl;
00359 /*     Compute splitting points */
00360     slarra_(n, &d__[1], &e[1], &e2[1], spltol, &spdiam, nsplit, &isplit[1], &
00361             iinfo);
00362 /*     Can force use of bisection instead of faster DQDS. */
00363 /*     Option left in the code for future multisection work. */
00364     forceb = FALSE_;
00365 /*     Initialize USEDQD, DQDS should be used for ALLRNG unless someone */
00366 /*     explicitly wants bisection. */
00367     usedqd = irange == 1 && ! forceb;
00368     if (irange == 1 && ! forceb) {
00369 /*        Set interval [VL,VU] that contains all eigenvalues */
00370         *vl = gl;
00371         *vu = gu;
00372     } else {
00373 /*        We call SLARRD to find crude approximations to the eigenvalues */
00374 /*        in the desired range. In case IRANGE = INDRNG, we also obtain the */
00375 /*        interval (VL,VU] that contains all the wanted eigenvalues. */
00376 /*        An interval [LEFT,RIGHT] has converged if */
00377 /*        RIGHT-LEFT.LT.RTOL*MAX(ABS(LEFT),ABS(RIGHT)) */
00378 /*        SLARRD needs a WORK of size 4*N, IWORK of size 3*N */
00379         slarrd_(range, "B", n, vl, vu, il, iu, &gers[1], &bsrtol, &d__[1], &e[
00380                 1], &e2[1], pivmin, nsplit, &isplit[1], &mm, &w[1], &werr[1], 
00381                 vl, vu, &iblock[1], &indexw[1], &work[1], &iwork[1], &iinfo);
00382         if (iinfo != 0) {
00383             *info = -1;
00384             return 0;
00385         }
00386 /*        Make sure that the entries M+1 to N in W, WERR, IBLOCK, INDEXW are 0 */
00387         i__1 = *n;
00388         for (i__ = mm + 1; i__ <= i__1; ++i__) {
00389             w[i__] = 0.f;
00390             werr[i__] = 0.f;
00391             iblock[i__] = 0;
00392             indexw[i__] = 0;
00393 /* L14: */
00394         }
00395     }
00396 /* ** */
00397 /*     Loop over unreduced blocks */
00398     ibegin = 1;
00399     wbegin = 1;
00400     i__1 = *nsplit;
00401     for (jblk = 1; jblk <= i__1; ++jblk) {
00402         iend = isplit[jblk];
00403         in = iend - ibegin + 1;
00404 /*        1 X 1 block */
00405         if (in == 1) {
00406             if (irange == 1 || irange == 3 && d__[ibegin] > *vl && d__[ibegin]
00407                      <= *vu || irange == 2 && iblock[wbegin] == jblk) {
00408                 ++(*m);
00409                 w[*m] = d__[ibegin];
00410                 werr[*m] = 0.f;
00411 /*              The gap for a single block doesn't matter for the later */
00412 /*              algorithm and is assigned an arbitrary large value */
00413                 wgap[*m] = 0.f;
00414                 iblock[*m] = jblk;
00415                 indexw[*m] = 1;
00416                 ++wbegin;
00417             }
00418 /*           E( IEND ) holds the shift for the initial RRR */
00419             e[iend] = 0.f;
00420             ibegin = iend + 1;
00421             goto L170;
00422         }
00423 
00424 /*        Blocks of size larger than 1x1 */
00425 
00426 /*        E( IEND ) will hold the shift for the initial RRR, for now set it =0 */
00427         e[iend] = 0.f;
00428 
00429 /*        Find local outer bounds GL,GU for the block */
00430         gl = d__[ibegin];
00431         gu = d__[ibegin];
00432         i__2 = iend;
00433         for (i__ = ibegin; i__ <= i__2; ++i__) {
00434 /* Computing MIN */
00435             r__1 = gers[(i__ << 1) - 1];
00436             gl = dmin(r__1,gl);
00437 /* Computing MAX */
00438             r__1 = gers[i__ * 2];
00439             gu = dmax(r__1,gu);
00440 /* L15: */
00441         }
00442         spdiam = gu - gl;
00443         if (! (irange == 1 && ! forceb)) {
00444 /*           Count the number of eigenvalues in the current block. */
00445             mb = 0;
00446             i__2 = mm;
00447             for (i__ = wbegin; i__ <= i__2; ++i__) {
00448                 if (iblock[i__] == jblk) {
00449                     ++mb;
00450                 } else {
00451                     goto L21;
00452                 }
00453 /* L20: */
00454             }
00455 L21:
00456             if (mb == 0) {
00457 /*              No eigenvalue in the current block lies in the desired range */
00458 /*              E( IEND ) holds the shift for the initial RRR */
00459                 e[iend] = 0.f;
00460                 ibegin = iend + 1;
00461                 goto L170;
00462             } else {
00463 /*              Decide whether dqds or bisection is more efficient */
00464                 usedqd = (real) mb > in * .5f && ! forceb;
00465                 wend = wbegin + mb - 1;
00466 /*              Calculate gaps for the current block */
00467 /*              In later stages, when representations for individual */
00468 /*              eigenvalues are different, we use SIGMA = E( IEND ). */
00469                 sigma = 0.f;
00470                 i__2 = wend - 1;
00471                 for (i__ = wbegin; i__ <= i__2; ++i__) {
00472 /* Computing MAX */
00473                     r__1 = 0.f, r__2 = w[i__ + 1] - werr[i__ + 1] - (w[i__] + 
00474                             werr[i__]);
00475                     wgap[i__] = dmax(r__1,r__2);
00476 /* L30: */
00477                 }
00478 /* Computing MAX */
00479                 r__1 = 0.f, r__2 = *vu - sigma - (w[wend] + werr[wend]);
00480                 wgap[wend] = dmax(r__1,r__2);
00481 /*              Find local index of the first and last desired evalue. */
00482                 indl = indexw[wbegin];
00483                 indu = indexw[wend];
00484             }
00485         }
00486         if (irange == 1 && ! forceb || usedqd) {
00487 /*           Case of DQDS */
00488 /*           Find approximations to the extremal eigenvalues of the block */
00489             slarrk_(&in, &c__1, &gl, &gu, &d__[ibegin], &e2[ibegin], pivmin, &
00490                     rtl, &tmp, &tmp1, &iinfo);
00491             if (iinfo != 0) {
00492                 *info = -1;
00493                 return 0;
00494             }
00495 /* Computing MAX */
00496             r__2 = gl, r__3 = tmp - tmp1 - eps * 100.f * (r__1 = tmp - tmp1, 
00497                     dabs(r__1));
00498             isleft = dmax(r__2,r__3);
00499             slarrk_(&in, &in, &gl, &gu, &d__[ibegin], &e2[ibegin], pivmin, &
00500                     rtl, &tmp, &tmp1, &iinfo);
00501             if (iinfo != 0) {
00502                 *info = -1;
00503                 return 0;
00504             }
00505 /* Computing MIN */
00506             r__2 = gu, r__3 = tmp + tmp1 + eps * 100.f * (r__1 = tmp + tmp1, 
00507                     dabs(r__1));
00508             isrght = dmin(r__2,r__3);
00509 /*           Improve the estimate of the spectral diameter */
00510             spdiam = isrght - isleft;
00511         } else {
00512 /*           Case of bisection */
00513 /*           Find approximations to the wanted extremal eigenvalues */
00514 /* Computing MAX */
00515             r__2 = gl, r__3 = w[wbegin] - werr[wbegin] - eps * 100.f * (r__1 =
00516                      w[wbegin] - werr[wbegin], dabs(r__1));
00517             isleft = dmax(r__2,r__3);
00518 /* Computing MIN */
00519             r__2 = gu, r__3 = w[wend] + werr[wend] + eps * 100.f * (r__1 = w[
00520                     wend] + werr[wend], dabs(r__1));
00521             isrght = dmin(r__2,r__3);
00522         }
00523 /*        Decide whether the base representation for the current block */
00524 /*        L_JBLK D_JBLK L_JBLK^T = T_JBLK - sigma_JBLK I */
00525 /*        should be on the left or the right end of the current block. */
00526 /*        The strategy is to shift to the end which is "more populated" */
00527 /*        Furthermore, decide whether to use DQDS for the computation of */
00528 /*        the eigenvalue approximations at the end of SLARRE or bisection. */
00529 /*        dqds is chosen if all eigenvalues are desired or the number of */
00530 /*        eigenvalues to be computed is large compared to the blocksize. */
00531         if (irange == 1 && ! forceb) {
00532 /*           If all the eigenvalues have to be computed, we use dqd */
00533             usedqd = TRUE_;
00534 /*           INDL is the local index of the first eigenvalue to compute */
00535             indl = 1;
00536             indu = in;
00537 /*           MB =  number of eigenvalues to compute */
00538             mb = in;
00539             wend = wbegin + mb - 1;
00540 /*           Define 1/4 and 3/4 points of the spectrum */
00541             s1 = isleft + spdiam * .25f;
00542             s2 = isrght - spdiam * .25f;
00543         } else {
00544 /*           SLARRD has computed IBLOCK and INDEXW for each eigenvalue */
00545 /*           approximation. */
00546 /*           choose sigma */
00547             if (usedqd) {
00548                 s1 = isleft + spdiam * .25f;
00549                 s2 = isrght - spdiam * .25f;
00550             } else {
00551                 tmp = dmin(isrght,*vu) - dmax(isleft,*vl);
00552                 s1 = dmax(isleft,*vl) + tmp * .25f;
00553                 s2 = dmin(isrght,*vu) - tmp * .25f;
00554             }
00555         }
00556 /*        Compute the negcount at the 1/4 and 3/4 points */
00557         if (mb > 1) {
00558             slarrc_("T", &in, &s1, &s2, &d__[ibegin], &e[ibegin], pivmin, &
00559                     cnt, &cnt1, &cnt2, &iinfo);
00560         }
00561         if (mb == 1) {
00562             sigma = gl;
00563             sgndef = 1.f;
00564         } else if (cnt1 - indl >= indu - cnt2) {
00565             if (irange == 1 && ! forceb) {
00566                 sigma = dmax(isleft,gl);
00567             } else if (usedqd) {
00568 /*              use Gerschgorin bound as shift to get pos def matrix */
00569 /*              for dqds */
00570                 sigma = isleft;
00571             } else {
00572 /*              use approximation of the first desired eigenvalue of the */
00573 /*              block as shift */
00574                 sigma = dmax(isleft,*vl);
00575             }
00576             sgndef = 1.f;
00577         } else {
00578             if (irange == 1 && ! forceb) {
00579                 sigma = dmin(isrght,gu);
00580             } else if (usedqd) {
00581 /*              use Gerschgorin bound as shift to get neg def matrix */
00582 /*              for dqds */
00583                 sigma = isrght;
00584             } else {
00585 /*              use approximation of the first desired eigenvalue of the */
00586 /*              block as shift */
00587                 sigma = dmin(isrght,*vu);
00588             }
00589             sgndef = -1.f;
00590         }
00591 /*        An initial SIGMA has been chosen that will be used for computing */
00592 /*        T - SIGMA I = L D L^T */
00593 /*        Define the increment TAU of the shift in case the initial shift */
00594 /*        needs to be refined to obtain a factorization with not too much */
00595 /*        element growth. */
00596         if (usedqd) {
00597 /*           The initial SIGMA was to the outer end of the spectrum */
00598 /*           the matrix is definite and we need not retreat. */
00599             tau = spdiam * eps * *n + *pivmin * 2.f;
00600         } else {
00601             if (mb > 1) {
00602                 clwdth = w[wend] + werr[wend] - w[wbegin] - werr[wbegin];
00603                 avgap = (r__1 = clwdth / (real) (wend - wbegin), dabs(r__1));
00604                 if (sgndef == 1.f) {
00605 /* Computing MAX */
00606                     r__1 = wgap[wbegin];
00607                     tau = dmax(r__1,avgap) * .5f;
00608 /* Computing MAX */
00609                     r__1 = tau, r__2 = werr[wbegin];
00610                     tau = dmax(r__1,r__2);
00611                 } else {
00612 /* Computing MAX */
00613                     r__1 = wgap[wend - 1];
00614                     tau = dmax(r__1,avgap) * .5f;
00615 /* Computing MAX */
00616                     r__1 = tau, r__2 = werr[wend];
00617                     tau = dmax(r__1,r__2);
00618                 }
00619             } else {
00620                 tau = werr[wbegin];
00621             }
00622         }
00623 
00624         for (idum = 1; idum <= 6; ++idum) {
00625 /*           Compute L D L^T factorization of tridiagonal matrix T - sigma I. */
00626 /*           Store D in WORK(1:IN), L in WORK(IN+1:2*IN), and reciprocals of */
00627 /*           pivots in WORK(2*IN+1:3*IN) */
00628             dpivot = d__[ibegin] - sigma;
00629             work[1] = dpivot;
00630             dmax__ = dabs(work[1]);
00631             j = ibegin;
00632             i__2 = in - 1;
00633             for (i__ = 1; i__ <= i__2; ++i__) {
00634                 work[(in << 1) + i__] = 1.f / work[i__];
00635                 tmp = e[j] * work[(in << 1) + i__];
00636                 work[in + i__] = tmp;
00637                 dpivot = d__[j + 1] - sigma - tmp * e[j];
00638                 work[i__ + 1] = dpivot;
00639 /* Computing MAX */
00640                 r__1 = dmax__, r__2 = dabs(dpivot);
00641                 dmax__ = dmax(r__1,r__2);
00642                 ++j;
00643 /* L70: */
00644             }
00645 /*           check for element growth */
00646             if (dmax__ > spdiam * 64.f) {
00647                 norep = TRUE_;
00648             } else {
00649                 norep = FALSE_;
00650             }
00651             if (usedqd && ! norep) {
00652 /*              Ensure the definiteness of the representation */
00653 /*              All entries of D (of L D L^T) must have the same sign */
00654                 i__2 = in;
00655                 for (i__ = 1; i__ <= i__2; ++i__) {
00656                     tmp = sgndef * work[i__];
00657                     if (tmp < 0.f) {
00658                         norep = TRUE_;
00659                     }
00660 /* L71: */
00661                 }
00662             }
00663             if (norep) {
00664 /*              Note that in the case of IRANGE=ALLRNG, we use the Gerschgorin */
00665 /*              shift which makes the matrix definite. So we should end up */
00666 /*              here really only in the case of IRANGE = VALRNG or INDRNG. */
00667                 if (idum == 5) {
00668                     if (sgndef == 1.f) {
00669 /*                    The fudged Gerschgorin shift should succeed */
00670                         sigma = gl - spdiam * 2.f * eps * *n - *pivmin * 4.f;
00671                     } else {
00672                         sigma = gu + spdiam * 2.f * eps * *n + *pivmin * 4.f;
00673                     }
00674                 } else {
00675                     sigma -= sgndef * tau;
00676                     tau *= 2.f;
00677                 }
00678             } else {
00679 /*              an initial RRR is found */
00680                 goto L83;
00681             }
00682 /* L80: */
00683         }
00684 /*        if the program reaches this point, no base representation could be */
00685 /*        found in MAXTRY iterations. */
00686         *info = 2;
00687         return 0;
00688 L83:
00689 /*        At this point, we have found an initial base representation */
00690 /*        T - SIGMA I = L D L^T with not too much element growth. */
00691 /*        Store the shift. */
00692         e[iend] = sigma;
00693 /*        Store D and L. */
00694         scopy_(&in, &work[1], &c__1, &d__[ibegin], &c__1);
00695         i__2 = in - 1;
00696         scopy_(&i__2, &work[in + 1], &c__1, &e[ibegin], &c__1);
00697         if (mb > 1) {
00698 
00699 /*           Perturb each entry of the base representation by a small */
00700 /*           (but random) relative amount to overcome difficulties with */
00701 /*           glued matrices. */
00702 
00703             for (i__ = 1; i__ <= 4; ++i__) {
00704                 iseed[i__ - 1] = 1;
00705 /* L122: */
00706             }
00707             i__2 = (in << 1) - 1;
00708             slarnv_(&c__2, iseed, &i__2, &work[1]);
00709             i__2 = in - 1;
00710             for (i__ = 1; i__ <= i__2; ++i__) {
00711                 d__[ibegin + i__ - 1] *= eps * 4.f * work[i__] + 1.f;
00712                 e[ibegin + i__ - 1] *= eps * 4.f * work[in + i__] + 1.f;
00713 /* L125: */
00714             }
00715             d__[iend] *= eps * 4.f * work[in] + 1.f;
00716 
00717         }
00718 
00719 /*        Don't update the Gerschgorin intervals because keeping track */
00720 /*        of the updates would be too much work in SLARRV. */
00721 /*        We update W instead and use it to locate the proper Gerschgorin */
00722 /*        intervals. */
00723 /*        Compute the required eigenvalues of L D L' by bisection or dqds */
00724         if (! usedqd) {
00725 /*           If SLARRD has been used, shift the eigenvalue approximations */
00726 /*           according to their representation. This is necessary for */
00727 /*           a uniform SLARRV since dqds computes eigenvalues of the */
00728 /*           shifted representation. In SLARRV, W will always hold the */
00729 /*           UNshifted eigenvalue approximation. */
00730             i__2 = wend;
00731             for (j = wbegin; j <= i__2; ++j) {
00732                 w[j] -= sigma;
00733                 werr[j] += (r__1 = w[j], dabs(r__1)) * eps;
00734 /* L134: */
00735             }
00736 /*           call SLARRB to reduce eigenvalue error of the approximations */
00737 /*           from SLARRD */
00738             i__2 = iend - 1;
00739             for (i__ = ibegin; i__ <= i__2; ++i__) {
00740 /* Computing 2nd power */
00741                 r__1 = e[i__];
00742                 work[i__] = d__[i__] * (r__1 * r__1);
00743 /* L135: */
00744             }
00745 /*           use bisection to find EV from INDL to INDU */
00746             i__2 = indl - 1;
00747             slarrb_(&in, &d__[ibegin], &work[ibegin], &indl, &indu, rtol1, 
00748                     rtol2, &i__2, &w[wbegin], &wgap[wbegin], &werr[wbegin], &
00749                     work[(*n << 1) + 1], &iwork[1], pivmin, &spdiam, &in, &
00750                     iinfo);
00751             if (iinfo != 0) {
00752                 *info = -4;
00753                 return 0;
00754             }
00755 /*           SLARRB computes all gaps correctly except for the last one */
00756 /*           Record distance to VU/GU */
00757 /* Computing MAX */
00758             r__1 = 0.f, r__2 = *vu - sigma - (w[wend] + werr[wend]);
00759             wgap[wend] = dmax(r__1,r__2);
00760             i__2 = indu;
00761             for (i__ = indl; i__ <= i__2; ++i__) {
00762                 ++(*m);
00763                 iblock[*m] = jblk;
00764                 indexw[*m] = i__;
00765 /* L138: */
00766             }
00767         } else {
00768 /*           Call dqds to get all eigs (and then possibly delete unwanted */
00769 /*           eigenvalues). */
00770 /*           Note that dqds finds the eigenvalues of the L D L^T representation */
00771 /*           of T to high relative accuracy. High relative accuracy */
00772 /*           might be lost when the shift of the RRR is subtracted to obtain */
00773 /*           the eigenvalues of T. However, T is not guaranteed to define its */
00774 /*           eigenvalues to high relative accuracy anyway. */
00775 /*           Set RTOL to the order of the tolerance used in SLASQ2 */
00776 /*           This is an ESTIMATED error, the worst case bound is 4*N*EPS */
00777 /*           which is usually too large and requires unnecessary work to be */
00778 /*           done by bisection when computing the eigenvectors */
00779             rtol = log((real) in) * 4.f * eps;
00780             j = ibegin;
00781             i__2 = in - 1;
00782             for (i__ = 1; i__ <= i__2; ++i__) {
00783                 work[(i__ << 1) - 1] = (r__1 = d__[j], dabs(r__1));
00784                 work[i__ * 2] = e[j] * e[j] * work[(i__ << 1) - 1];
00785                 ++j;
00786 /* L140: */
00787             }
00788             work[(in << 1) - 1] = (r__1 = d__[iend], dabs(r__1));
00789             work[in * 2] = 0.f;
00790             slasq2_(&in, &work[1], &iinfo);
00791             if (iinfo != 0) {
00792 /*              If IINFO = -5 then an index is part of a tight cluster */
00793 /*              and should be changed. The index is in IWORK(1) and the */
00794 /*              gap is in WORK(N+1) */
00795                 *info = -5;
00796                 return 0;
00797             } else {
00798 /*              Test that all eigenvalues are positive as expected */
00799                 i__2 = in;
00800                 for (i__ = 1; i__ <= i__2; ++i__) {
00801                     if (work[i__] < 0.f) {
00802                         *info = -6;
00803                         return 0;
00804                     }
00805 /* L149: */
00806                 }
00807             }
00808             if (sgndef > 0.f) {
00809                 i__2 = indu;
00810                 for (i__ = indl; i__ <= i__2; ++i__) {
00811                     ++(*m);
00812                     w[*m] = work[in - i__ + 1];
00813                     iblock[*m] = jblk;
00814                     indexw[*m] = i__;
00815 /* L150: */
00816                 }
00817             } else {
00818                 i__2 = indu;
00819                 for (i__ = indl; i__ <= i__2; ++i__) {
00820                     ++(*m);
00821                     w[*m] = -work[i__];
00822                     iblock[*m] = jblk;
00823                     indexw[*m] = i__;
00824 /* L160: */
00825                 }
00826             }
00827             i__2 = *m;
00828             for (i__ = *m - mb + 1; i__ <= i__2; ++i__) {
00829 /*              the value of RTOL below should be the tolerance in SLASQ2 */
00830                 werr[i__] = rtol * (r__1 = w[i__], dabs(r__1));
00831 /* L165: */
00832             }
00833             i__2 = *m - 1;
00834             for (i__ = *m - mb + 1; i__ <= i__2; ++i__) {
00835 /*              compute the right gap between the intervals */
00836 /* Computing MAX */
00837                 r__1 = 0.f, r__2 = w[i__ + 1] - werr[i__ + 1] - (w[i__] + 
00838                         werr[i__]);
00839                 wgap[i__] = dmax(r__1,r__2);
00840 /* L166: */
00841             }
00842 /* Computing MAX */
00843             r__1 = 0.f, r__2 = *vu - sigma - (w[*m] + werr[*m]);
00844             wgap[*m] = dmax(r__1,r__2);
00845         }
00846 /*        proceed with next block */
00847         ibegin = iend + 1;
00848         wbegin = wend + 1;
00849 L170:
00850         ;
00851     }
00852 
00853     return 0;
00854 
00855 /*     end of SLARRE */
00856 
00857 } /* slarre_ */


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