clarrv.c
Go to the documentation of this file.
00001 /* clarrv.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 complex c_b1 = {0.f,0.f};
00019 static integer c__1 = 1;
00020 static integer c__2 = 2;
00021 static real c_b28 = 0.f;
00022 
00023 /* Subroutine */ int clarrv_(integer *n, real *vl, real *vu, real *d__, real *
00024         l, real *pivmin, integer *isplit, integer *m, integer *dol, integer *
00025         dou, real *minrgp, real *rtol1, real *rtol2, real *w, real *werr, 
00026         real *wgap, integer *iblock, integer *indexw, real *gers, complex *
00027         z__, integer *ldz, integer *isuppz, real *work, integer *iwork, 
00028         integer *info)
00029 {
00030     /* System generated locals */
00031     integer z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5, i__6;
00032     real r__1, r__2;
00033     complex q__1;
00034     logical L__1;
00035 
00036     /* Builtin functions */
00037     double log(doublereal);
00038 
00039     /* Local variables */
00040     integer minwsize, i__, j, k, p, q, miniwsize, ii;
00041     real gl;
00042     integer im, in;
00043     real gu, gap, eps, tau, tol, tmp;
00044     integer zto;
00045     real ztz;
00046     integer iend, jblk;
00047     real lgap;
00048     integer done;
00049     real rgap, left;
00050     integer wend, iter;
00051     real bstw;
00052     integer itmp1, indld;
00053     real fudge;
00054     integer idone;
00055     real sigma;
00056     integer iinfo, iindr;
00057     real resid;
00058     logical eskip;
00059     real right;
00060     integer nclus, zfrom;
00061     extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *, 
00062             integer *);
00063     real rqtol;
00064     integer iindc1, iindc2, indin1, indin2;
00065     extern /* Subroutine */ int clar1v_(integer *, integer *, integer *, real 
00066             *, real *, real *, real *, real *, real *, real *, complex *, 
00067             logical *, integer *, real *, real *, integer *, integer *, real *
00068 , real *, real *, real *);
00069     logical stp2ii;
00070     real lambda;
00071     integer ibegin, indeig;
00072     logical needbs;
00073     integer indlld;
00074     real sgndef, mingma;
00075     extern doublereal slamch_(char *);
00076     integer oldien, oldncl, wbegin;
00077     real spdiam;
00078     integer negcnt;
00079     extern /* Subroutine */ int claset_(char *, integer *, integer *, complex 
00080             *, complex *, complex *, integer *);
00081     integer oldcls;
00082     real savgap;
00083     integer ndepth;
00084     real ssigma;
00085     extern /* Subroutine */ int csscal_(integer *, real *, complex *, integer 
00086             *);
00087     logical usedbs;
00088     integer iindwk, offset;
00089     real gaptol;
00090     extern /* Subroutine */ int slarrb_(integer *, real *, real *, integer *, 
00091             integer *, real *, real *, integer *, real *, real *, real *, 
00092             real *, integer *, real *, real *, integer *, integer *);
00093     integer newcls, oldfst, indwrk, windex, oldlst;
00094     logical usedrq;
00095     integer newfst, newftt, parity, windmn, windpl, isupmn, newlst, zusedl;
00096     real bstres;
00097     integer newsiz, zusedu, zusedw;
00098     real nrminv, rqcorr;
00099     logical tryrqc;
00100     integer isupmx;
00101     extern /* Subroutine */ int slarrf_(integer *, real *, real *, real *, 
00102             integer *, integer *, real *, real *, real *, real *, real *, 
00103             real *, real *, real *, real *, real *, real *, integer *);
00104 
00105 
00106 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00107 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00108 /*     November 2006 */
00109 
00110 /*     .. Scalar Arguments .. */
00111 /*     .. */
00112 /*     .. Array Arguments .. */
00113 /*     .. */
00114 
00115 /*  Purpose */
00116 /*  ======= */
00117 
00118 /*  CLARRV computes the eigenvectors of the tridiagonal matrix */
00119 /*  T = L D L^T given L, D and APPROXIMATIONS to the eigenvalues of L D L^T. */
00120 /*  The input eigenvalues should have been computed by SLARRE. */
00121 
00122 /*  Arguments */
00123 /*  ========= */
00124 
00125 /*  N       (input) INTEGER */
00126 /*          The order of the matrix.  N >= 0. */
00127 
00128 /*  VL      (input) REAL */
00129 /*  VU      (input) REAL */
00130 /*          Lower and upper bounds of the interval that contains the desired */
00131 /*          eigenvalues. VL < VU. Needed to compute gaps on the left or right */
00132 /*          end of the extremal eigenvalues in the desired RANGE. */
00133 
00134 /*  D       (input/output) REAL             array, dimension (N) */
00135 /*          On entry, the N diagonal elements of the diagonal matrix D. */
00136 /*          On exit, D may be overwritten. */
00137 
00138 /*  L       (input/output) REAL             array, dimension (N) */
00139 /*          On entry, the (N-1) subdiagonal elements of the unit */
00140 /*          bidiagonal matrix L are in elements 1 to N-1 of L */
00141 /*          (if the matrix is not splitted.) At the end of each block */
00142 /*          is stored the corresponding shift as given by SLARRE. */
00143 /*          On exit, L is overwritten. */
00144 
00145 /*  PIVMIN  (in) DOUBLE PRECISION */
00146 /*          The minimum pivot allowed in the Sturm sequence. */
00147 
00148 /*  ISPLIT  (input) INTEGER array, dimension (N) */
00149 /*          The splitting points, at which T breaks up into blocks. */
00150 /*          The first block consists of rows/columns 1 to */
00151 /*          ISPLIT( 1 ), the second of rows/columns ISPLIT( 1 )+1 */
00152 /*          through ISPLIT( 2 ), etc. */
00153 
00154 /*  M       (input) INTEGER */
00155 /*          The total number of input eigenvalues.  0 <= M <= N. */
00156 
00157 /*  DOL     (input) INTEGER */
00158 /*  DOU     (input) INTEGER */
00159 /*          If the user wants to compute only selected eigenvectors from all */
00160 /*          the eigenvalues supplied, he can specify an index range DOL:DOU. */
00161 /*          Or else the setting DOL=1, DOU=M should be applied. */
00162 /*          Note that DOL and DOU refer to the order in which the eigenvalues */
00163 /*          are stored in W. */
00164 /*          If the user wants to compute only selected eigenpairs, then */
00165 /*          the columns DOL-1 to DOU+1 of the eigenvector space Z contain the */
00166 /*          computed eigenvectors. All other columns of Z are set to zero. */
00167 
00168 /*  MINRGP  (input) REAL */
00169 
00170 /*  RTOL1   (input) REAL */
00171 /*  RTOL2   (input) REAL */
00172 /*           Parameters for bisection. */
00173 /*           An interval [LEFT,RIGHT] has converged if */
00174 /*           RIGHT-LEFT.LT.MAX( RTOL1*GAP, RTOL2*MAX(|LEFT|,|RIGHT|) ) */
00175 
00176 /*  W       (input/output) REAL             array, dimension (N) */
00177 /*          The first M elements of W contain the APPROXIMATE eigenvalues for */
00178 /*          which eigenvectors are to be computed.  The eigenvalues */
00179 /*          should be grouped by split-off block and ordered from */
00180 /*          smallest to largest within the block ( The output array */
00181 /*          W from SLARRE is expected here ). Furthermore, they are with */
00182 /*          respect to the shift of the corresponding root representation */
00183 /*          for their block. On exit, W holds the eigenvalues of the */
00184 /*          UNshifted matrix. */
00185 
00186 /*  WERR    (input/output) REAL             array, dimension (N) */
00187 /*          The first M elements contain the semiwidth of the uncertainty */
00188 /*          interval of the corresponding eigenvalue in W */
00189 
00190 /*  WGAP    (input/output) REAL             array, dimension (N) */
00191 /*          The separation from the right neighbor eigenvalue in W. */
00192 
00193 /*  IBLOCK  (input) INTEGER array, dimension (N) */
00194 /*          The indices of the blocks (submatrices) associated with the */
00195 /*          corresponding eigenvalues in W; IBLOCK(i)=1 if eigenvalue */
00196 /*          W(i) belongs to the first block from the top, =2 if W(i) */
00197 /*          belongs to the second block, etc. */
00198 
00199 /*  INDEXW  (input) INTEGER array, dimension (N) */
00200 /*          The indices of the eigenvalues within each block (submatrix); */
00201 /*          for example, INDEXW(i)= 10 and IBLOCK(i)=2 imply that the */
00202 /*          i-th eigenvalue W(i) is the 10-th eigenvalue in the second block. */
00203 
00204 /*  GERS    (input) REAL             array, dimension (2*N) */
00205 /*          The N Gerschgorin intervals (the i-th Gerschgorin interval */
00206 /*          is (GERS(2*i-1), GERS(2*i)). The Gerschgorin intervals should */
00207 /*          be computed from the original UNshifted matrix. */
00208 
00209 /*  Z       (output) COMPLEX          array, dimension (LDZ, max(1,M) ) */
00210 /*          If INFO = 0, the first M columns of Z contain the */
00211 /*          orthonormal eigenvectors of the matrix T */
00212 /*          corresponding to the input eigenvalues, with the i-th */
00213 /*          column of Z holding the eigenvector associated with W(i). */
00214 /*          Note: the user must ensure that at least max(1,M) columns are */
00215 /*          supplied in the array Z. */
00216 
00217 /*  LDZ     (input) INTEGER */
00218 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
00219 /*          JOBZ = 'V', LDZ >= max(1,N). */
00220 
00221 /*  ISUPPZ  (output) INTEGER array, dimension ( 2*max(1,M) ) */
00222 /*          The support of the eigenvectors in Z, i.e., the indices */
00223 /*          indicating the nonzero elements in Z. The I-th eigenvector */
00224 /*          is nonzero only in elements ISUPPZ( 2*I-1 ) through */
00225 /*          ISUPPZ( 2*I ). */
00226 
00227 /*  WORK    (workspace) REAL             array, dimension (12*N) */
00228 
00229 /*  IWORK   (workspace) INTEGER array, dimension (7*N) */
00230 
00231 /*  INFO    (output) INTEGER */
00232 /*          = 0:  successful exit */
00233 
00234 /*          > 0:  A problem occured in CLARRV. */
00235 /*          < 0:  One of the called subroutines signaled an internal problem. */
00236 /*                Needs inspection of the corresponding parameter IINFO */
00237 /*                for further information. */
00238 
00239 /*          =-1:  Problem in SLARRB when refining a child's eigenvalues. */
00240 /*          =-2:  Problem in SLARRF when computing the RRR of a child. */
00241 /*                When a child is inside a tight cluster, it can be difficult */
00242 /*                to find an RRR. A partial remedy from the user's point of */
00243 /*                view is to make the parameter MINRGP smaller and recompile. */
00244 /*                However, as the orthogonality of the computed vectors is */
00245 /*                proportional to 1/MINRGP, the user should be aware that */
00246 /*                he might be trading in precision when he decreases MINRGP. */
00247 /*          =-3:  Problem in SLARRB when refining a single eigenvalue */
00248 /*                after the Rayleigh correction was rejected. */
00249 /*          = 5:  The Rayleigh Quotient Iteration failed to converge to */
00250 /*                full accuracy in MAXITR steps. */
00251 
00252 /*  Further Details */
00253 /*  =============== */
00254 
00255 /*  Based on contributions by */
00256 /*     Beresford Parlett, University of California, Berkeley, USA */
00257 /*     Jim Demmel, University of California, Berkeley, USA */
00258 /*     Inderjit Dhillon, University of Texas, Austin, USA */
00259 /*     Osni Marques, LBNL/NERSC, USA */
00260 /*     Christof Voemel, University of California, Berkeley, USA */
00261 
00262 /*  ===================================================================== */
00263 
00264 /*     .. Parameters .. */
00265 /*     .. */
00266 /*     .. Local Scalars .. */
00267 /*     .. */
00268 /*     .. External Functions .. */
00269 /*     .. */
00270 /*     .. External Subroutines .. */
00271 /*     .. */
00272 /*     .. Intrinsic Functions .. */
00273 /*     .. */
00274 /*     .. Executable Statements .. */
00275 /*     .. */
00276 /*     The first N entries of WORK are reserved for the eigenvalues */
00277     /* Parameter adjustments */
00278     --d__;
00279     --l;
00280     --isplit;
00281     --w;
00282     --werr;
00283     --wgap;
00284     --iblock;
00285     --indexw;
00286     --gers;
00287     z_dim1 = *ldz;
00288     z_offset = 1 + z_dim1;
00289     z__ -= z_offset;
00290     --isuppz;
00291     --work;
00292     --iwork;
00293 
00294     /* Function Body */
00295     indld = *n + 1;
00296     indlld = (*n << 1) + 1;
00297     indin1 = *n * 3 + 1;
00298     indin2 = (*n << 2) + 1;
00299     indwrk = *n * 5 + 1;
00300     minwsize = *n * 12;
00301     i__1 = minwsize;
00302     for (i__ = 1; i__ <= i__1; ++i__) {
00303         work[i__] = 0.f;
00304 /* L5: */
00305     }
00306 /*     IWORK(IINDR+1:IINDR+N) hold the twist indices R for the */
00307 /*     factorization used to compute the FP vector */
00308     iindr = 0;
00309 /*     IWORK(IINDC1+1:IINC2+N) are used to store the clusters of the current */
00310 /*     layer and the one above. */
00311     iindc1 = *n;
00312     iindc2 = *n << 1;
00313     iindwk = *n * 3 + 1;
00314     miniwsize = *n * 7;
00315     i__1 = miniwsize;
00316     for (i__ = 1; i__ <= i__1; ++i__) {
00317         iwork[i__] = 0;
00318 /* L10: */
00319     }
00320     zusedl = 1;
00321     if (*dol > 1) {
00322 /*        Set lower bound for use of Z */
00323         zusedl = *dol - 1;
00324     }
00325     zusedu = *m;
00326     if (*dou < *m) {
00327 /*        Set lower bound for use of Z */
00328         zusedu = *dou + 1;
00329     }
00330 /*     The width of the part of Z that is used */
00331     zusedw = zusedu - zusedl + 1;
00332     claset_("Full", n, &zusedw, &c_b1, &c_b1, &z__[zusedl * z_dim1 + 1], ldz);
00333     eps = slamch_("Precision");
00334     rqtol = eps * 2.f;
00335 
00336 /*     Set expert flags for standard code. */
00337     tryrqc = TRUE_;
00338     if (*dol == 1 && *dou == *m) {
00339     } else {
00340 /*        Only selected eigenpairs are computed. Since the other evalues */
00341 /*        are not refined by RQ iteration, bisection has to compute to full */
00342 /*        accuracy. */
00343         *rtol1 = eps * 4.f;
00344         *rtol2 = eps * 4.f;
00345     }
00346 /*     The entries WBEGIN:WEND in W, WERR, WGAP correspond to the */
00347 /*     desired eigenvalues. The support of the nonzero eigenvector */
00348 /*     entries is contained in the interval IBEGIN:IEND. */
00349 /*     Remark that if k eigenpairs are desired, then the eigenvectors */
00350 /*     are stored in k contiguous columns of Z. */
00351 /*     DONE is the number of eigenvectors already computed */
00352     done = 0;
00353     ibegin = 1;
00354     wbegin = 1;
00355     i__1 = iblock[*m];
00356     for (jblk = 1; jblk <= i__1; ++jblk) {
00357         iend = isplit[jblk];
00358         sigma = l[iend];
00359 /*        Find the eigenvectors of the submatrix indexed IBEGIN */
00360 /*        through IEND. */
00361         wend = wbegin - 1;
00362 L15:
00363         if (wend < *m) {
00364             if (iblock[wend + 1] == jblk) {
00365                 ++wend;
00366                 goto L15;
00367             }
00368         }
00369         if (wend < wbegin) {
00370             ibegin = iend + 1;
00371             goto L170;
00372         } else if (wend < *dol || wbegin > *dou) {
00373             ibegin = iend + 1;
00374             wbegin = wend + 1;
00375             goto L170;
00376         }
00377 /*        Find local spectral diameter of the block */
00378         gl = gers[(ibegin << 1) - 1];
00379         gu = gers[ibegin * 2];
00380         i__2 = iend;
00381         for (i__ = ibegin + 1; i__ <= i__2; ++i__) {
00382 /* Computing MIN */
00383             r__1 = gers[(i__ << 1) - 1];
00384             gl = dmin(r__1,gl);
00385 /* Computing MAX */
00386             r__1 = gers[i__ * 2];
00387             gu = dmax(r__1,gu);
00388 /* L20: */
00389         }
00390         spdiam = gu - gl;
00391 /*        OLDIEN is the last index of the previous block */
00392         oldien = ibegin - 1;
00393 /*        Calculate the size of the current block */
00394         in = iend - ibegin + 1;
00395 /*        The number of eigenvalues in the current block */
00396         im = wend - wbegin + 1;
00397 /*        This is for a 1x1 block */
00398         if (ibegin == iend) {
00399             ++done;
00400             i__2 = ibegin + wbegin * z_dim1;
00401             z__[i__2].r = 1.f, z__[i__2].i = 0.f;
00402             isuppz[(wbegin << 1) - 1] = ibegin;
00403             isuppz[wbegin * 2] = ibegin;
00404             w[wbegin] += sigma;
00405             work[wbegin] = w[wbegin];
00406             ibegin = iend + 1;
00407             ++wbegin;
00408             goto L170;
00409         }
00410 /*        The desired (shifted) eigenvalues are stored in W(WBEGIN:WEND) */
00411 /*        Note that these can be approximations, in this case, the corresp. */
00412 /*        entries of WERR give the size of the uncertainty interval. */
00413 /*        The eigenvalue approximations will be refined when necessary as */
00414 /*        high relative accuracy is required for the computation of the */
00415 /*        corresponding eigenvectors. */
00416         scopy_(&im, &w[wbegin], &c__1, &work[wbegin], &c__1);
00417 /*        We store in W the eigenvalue approximations w.r.t. the original */
00418 /*        matrix T. */
00419         i__2 = im;
00420         for (i__ = 1; i__ <= i__2; ++i__) {
00421             w[wbegin + i__ - 1] += sigma;
00422 /* L30: */
00423         }
00424 /*        NDEPTH is the current depth of the representation tree */
00425         ndepth = 0;
00426 /*        PARITY is either 1 or 0 */
00427         parity = 1;
00428 /*        NCLUS is the number of clusters for the next level of the */
00429 /*        representation tree, we start with NCLUS = 1 for the root */
00430         nclus = 1;
00431         iwork[iindc1 + 1] = 1;
00432         iwork[iindc1 + 2] = im;
00433 /*        IDONE is the number of eigenvectors already computed in the current */
00434 /*        block */
00435         idone = 0;
00436 /*        loop while( IDONE.LT.IM ) */
00437 /*        generate the representation tree for the current block and */
00438 /*        compute the eigenvectors */
00439 L40:
00440         if (idone < im) {
00441 /*           This is a crude protection against infinitely deep trees */
00442             if (ndepth > *m) {
00443                 *info = -2;
00444                 return 0;
00445             }
00446 /*           breadth first processing of the current level of the representation */
00447 /*           tree: OLDNCL = number of clusters on current level */
00448             oldncl = nclus;
00449 /*           reset NCLUS to count the number of child clusters */
00450             nclus = 0;
00451 
00452             parity = 1 - parity;
00453             if (parity == 0) {
00454                 oldcls = iindc1;
00455                 newcls = iindc2;
00456             } else {
00457                 oldcls = iindc2;
00458                 newcls = iindc1;
00459             }
00460 /*           Process the clusters on the current level */
00461             i__2 = oldncl;
00462             for (i__ = 1; i__ <= i__2; ++i__) {
00463                 j = oldcls + (i__ << 1);
00464 /*              OLDFST, OLDLST = first, last index of current cluster. */
00465 /*                               cluster indices start with 1 and are relative */
00466 /*                               to WBEGIN when accessing W, WGAP, WERR, Z */
00467                 oldfst = iwork[j - 1];
00468                 oldlst = iwork[j];
00469                 if (ndepth > 0) {
00470 /*                 Retrieve relatively robust representation (RRR) of cluster */
00471 /*                 that has been computed at the previous level */
00472 /*                 The RRR is stored in Z and overwritten once the eigenvectors */
00473 /*                 have been computed or when the cluster is refined */
00474                     if (*dol == 1 && *dou == *m) {
00475 /*                    Get representation from location of the leftmost evalue */
00476 /*                    of the cluster */
00477                         j = wbegin + oldfst - 1;
00478                     } else {
00479                         if (wbegin + oldfst - 1 < *dol) {
00480 /*                       Get representation from the left end of Z array */
00481                             j = *dol - 1;
00482                         } else if (wbegin + oldfst - 1 > *dou) {
00483 /*                       Get representation from the right end of Z array */
00484                             j = *dou;
00485                         } else {
00486                             j = wbegin + oldfst - 1;
00487                         }
00488                     }
00489                     i__3 = in - 1;
00490                     for (k = 1; k <= i__3; ++k) {
00491                         i__4 = ibegin + k - 1 + j * z_dim1;
00492                         d__[ibegin + k - 1] = z__[i__4].r;
00493                         i__4 = ibegin + k - 1 + (j + 1) * z_dim1;
00494                         l[ibegin + k - 1] = z__[i__4].r;
00495 /* L45: */
00496                     }
00497                     i__3 = iend + j * z_dim1;
00498                     d__[iend] = z__[i__3].r;
00499                     i__3 = iend + (j + 1) * z_dim1;
00500                     sigma = z__[i__3].r;
00501 /*                 Set the corresponding entries in Z to zero */
00502                     claset_("Full", &in, &c__2, &c_b1, &c_b1, &z__[ibegin + j 
00503                             * z_dim1], ldz);
00504                 }
00505 /*              Compute DL and DLL of current RRR */
00506                 i__3 = iend - 1;
00507                 for (j = ibegin; j <= i__3; ++j) {
00508                     tmp = d__[j] * l[j];
00509                     work[indld - 1 + j] = tmp;
00510                     work[indlld - 1 + j] = tmp * l[j];
00511 /* L50: */
00512                 }
00513                 if (ndepth > 0) {
00514 /*                 P and Q are index of the first and last eigenvalue to compute */
00515 /*                 within the current block */
00516                     p = indexw[wbegin - 1 + oldfst];
00517                     q = indexw[wbegin - 1 + oldlst];
00518 /*                 Offset for the arrays WORK, WGAP and WERR, i.e., th P-OFFSET */
00519 /*                 thru' Q-OFFSET elements of these arrays are to be used. */
00520 /*                  OFFSET = P-OLDFST */
00521                     offset = indexw[wbegin] - 1;
00522 /*                 perform limited bisection (if necessary) to get approximate */
00523 /*                 eigenvalues to the precision needed. */
00524                     slarrb_(&in, &d__[ibegin], &work[indlld + ibegin - 1], &p, 
00525                              &q, rtol1, rtol2, &offset, &work[wbegin], &wgap[
00526                             wbegin], &werr[wbegin], &work[indwrk], &iwork[
00527                             iindwk], pivmin, &spdiam, &in, &iinfo);
00528                     if (iinfo != 0) {
00529                         *info = -1;
00530                         return 0;
00531                     }
00532 /*                 We also recompute the extremal gaps. W holds all eigenvalues */
00533 /*                 of the unshifted matrix and must be used for computation */
00534 /*                 of WGAP, the entries of WORK might stem from RRRs with */
00535 /*                 different shifts. The gaps from WBEGIN-1+OLDFST to */
00536 /*                 WBEGIN-1+OLDLST are correctly computed in SLARRB. */
00537 /*                 However, we only allow the gaps to become greater since */
00538 /*                 this is what should happen when we decrease WERR */
00539                     if (oldfst > 1) {
00540 /* Computing MAX */
00541                         r__1 = wgap[wbegin + oldfst - 2], r__2 = w[wbegin + 
00542                                 oldfst - 1] - werr[wbegin + oldfst - 1] - w[
00543                                 wbegin + oldfst - 2] - werr[wbegin + oldfst - 
00544                                 2];
00545                         wgap[wbegin + oldfst - 2] = dmax(r__1,r__2);
00546                     }
00547                     if (wbegin + oldlst - 1 < wend) {
00548 /* Computing MAX */
00549                         r__1 = wgap[wbegin + oldlst - 1], r__2 = w[wbegin + 
00550                                 oldlst] - werr[wbegin + oldlst] - w[wbegin + 
00551                                 oldlst - 1] - werr[wbegin + oldlst - 1];
00552                         wgap[wbegin + oldlst - 1] = dmax(r__1,r__2);
00553                     }
00554 /*                 Each time the eigenvalues in WORK get refined, we store */
00555 /*                 the newly found approximation with all shifts applied in W */
00556                     i__3 = oldlst;
00557                     for (j = oldfst; j <= i__3; ++j) {
00558                         w[wbegin + j - 1] = work[wbegin + j - 1] + sigma;
00559 /* L53: */
00560                     }
00561                 }
00562 /*              Process the current node. */
00563                 newfst = oldfst;
00564                 i__3 = oldlst;
00565                 for (j = oldfst; j <= i__3; ++j) {
00566                     if (j == oldlst) {
00567 /*                    we are at the right end of the cluster, this is also the */
00568 /*                    boundary of the child cluster */
00569                         newlst = j;
00570                     } else if (wgap[wbegin + j - 1] >= *minrgp * (r__1 = work[
00571                             wbegin + j - 1], dabs(r__1))) {
00572 /*                    the right relative gap is big enough, the child cluster */
00573 /*                    (NEWFST,..,NEWLST) is well separated from the following */
00574                         newlst = j;
00575                     } else {
00576 /*                    inside a child cluster, the relative gap is not */
00577 /*                    big enough. */
00578                         goto L140;
00579                     }
00580 /*                 Compute size of child cluster found */
00581                     newsiz = newlst - newfst + 1;
00582 /*                 NEWFTT is the place in Z where the new RRR or the computed */
00583 /*                 eigenvector is to be stored */
00584                     if (*dol == 1 && *dou == *m) {
00585 /*                    Store representation at location of the leftmost evalue */
00586 /*                    of the cluster */
00587                         newftt = wbegin + newfst - 1;
00588                     } else {
00589                         if (wbegin + newfst - 1 < *dol) {
00590 /*                       Store representation at the left end of Z array */
00591                             newftt = *dol - 1;
00592                         } else if (wbegin + newfst - 1 > *dou) {
00593 /*                       Store representation at the right end of Z array */
00594                             newftt = *dou;
00595                         } else {
00596                             newftt = wbegin + newfst - 1;
00597                         }
00598                     }
00599                     if (newsiz > 1) {
00600 
00601 /*                    Current child is not a singleton but a cluster. */
00602 /*                    Compute and store new representation of child. */
00603 
00604 
00605 /*                    Compute left and right cluster gap. */
00606 
00607 /*                    LGAP and RGAP are not computed from WORK because */
00608 /*                    the eigenvalue approximations may stem from RRRs */
00609 /*                    different shifts. However, W hold all eigenvalues */
00610 /*                    of the unshifted matrix. Still, the entries in WGAP */
00611 /*                    have to be computed from WORK since the entries */
00612 /*                    in W might be of the same order so that gaps are not */
00613 /*                    exhibited correctly for very close eigenvalues. */
00614                         if (newfst == 1) {
00615 /* Computing MAX */
00616                             r__1 = 0.f, r__2 = w[wbegin] - werr[wbegin] - *vl;
00617                             lgap = dmax(r__1,r__2);
00618                         } else {
00619                             lgap = wgap[wbegin + newfst - 2];
00620                         }
00621                         rgap = wgap[wbegin + newlst - 1];
00622 
00623 /*                    Compute left- and rightmost eigenvalue of child */
00624 /*                    to high precision in order to shift as close */
00625 /*                    as possible and obtain as large relative gaps */
00626 /*                    as possible */
00627 
00628                         for (k = 1; k <= 2; ++k) {
00629                             if (k == 1) {
00630                                 p = indexw[wbegin - 1 + newfst];
00631                             } else {
00632                                 p = indexw[wbegin - 1 + newlst];
00633                             }
00634                             offset = indexw[wbegin] - 1;
00635                             slarrb_(&in, &d__[ibegin], &work[indlld + ibegin 
00636                                     - 1], &p, &p, &rqtol, &rqtol, &offset, &
00637                                     work[wbegin], &wgap[wbegin], &werr[wbegin]
00638 , &work[indwrk], &iwork[iindwk], pivmin, &
00639                                     spdiam, &in, &iinfo);
00640 /* L55: */
00641                         }
00642 
00643                         if (wbegin + newlst - 1 < *dol || wbegin + newfst - 1 
00644                                 > *dou) {
00645 /*                       if the cluster contains no desired eigenvalues */
00646 /*                       skip the computation of that branch of the rep. tree */
00647 
00648 /*                       We could skip before the refinement of the extremal */
00649 /*                       eigenvalues of the child, but then the representation */
00650 /*                       tree could be different from the one when nothing is */
00651 /*                       skipped. For this reason we skip at this place. */
00652                             idone = idone + newlst - newfst + 1;
00653                             goto L139;
00654                         }
00655 
00656 /*                    Compute RRR of child cluster. */
00657 /*                    Note that the new RRR is stored in Z */
00658 
00659 /*                    SLARRF needs LWORK = 2*N */
00660                         slarrf_(&in, &d__[ibegin], &l[ibegin], &work[indld + 
00661                                 ibegin - 1], &newfst, &newlst, &work[wbegin], 
00662                                 &wgap[wbegin], &werr[wbegin], &spdiam, &lgap, 
00663                                 &rgap, pivmin, &tau, &work[indin1], &work[
00664                                 indin2], &work[indwrk], &iinfo);
00665 /*                    In the complex case, SLARRF cannot write */
00666 /*                    the new RRR directly into Z and needs an intermediate */
00667 /*                    workspace */
00668                         i__4 = in - 1;
00669                         for (k = 1; k <= i__4; ++k) {
00670                             i__5 = ibegin + k - 1 + newftt * z_dim1;
00671                             i__6 = indin1 + k - 1;
00672                             q__1.r = work[i__6], q__1.i = 0.f;
00673                             z__[i__5].r = q__1.r, z__[i__5].i = q__1.i;
00674                             i__5 = ibegin + k - 1 + (newftt + 1) * z_dim1;
00675                             i__6 = indin2 + k - 1;
00676                             q__1.r = work[i__6], q__1.i = 0.f;
00677                             z__[i__5].r = q__1.r, z__[i__5].i = q__1.i;
00678 /* L56: */
00679                         }
00680                         i__4 = iend + newftt * z_dim1;
00681                         i__5 = indin1 + in - 1;
00682                         q__1.r = work[i__5], q__1.i = 0.f;
00683                         z__[i__4].r = q__1.r, z__[i__4].i = q__1.i;
00684                         if (iinfo == 0) {
00685 /*                       a new RRR for the cluster was found by SLARRF */
00686 /*                       update shift and store it */
00687                             ssigma = sigma + tau;
00688                             i__4 = iend + (newftt + 1) * z_dim1;
00689                             q__1.r = ssigma, q__1.i = 0.f;
00690                             z__[i__4].r = q__1.r, z__[i__4].i = q__1.i;
00691 /*                       WORK() are the midpoints and WERR() the semi-width */
00692 /*                       Note that the entries in W are unchanged. */
00693                             i__4 = newlst;
00694                             for (k = newfst; k <= i__4; ++k) {
00695                                 fudge = eps * 3.f * (r__1 = work[wbegin + k - 
00696                                         1], dabs(r__1));
00697                                 work[wbegin + k - 1] -= tau;
00698                                 fudge += eps * 4.f * (r__1 = work[wbegin + k 
00699                                         - 1], dabs(r__1));
00700 /*                          Fudge errors */
00701                                 werr[wbegin + k - 1] += fudge;
00702 /*                          Gaps are not fudged. Provided that WERR is small */
00703 /*                          when eigenvalues are close, a zero gap indicates */
00704 /*                          that a new representation is needed for resolving */
00705 /*                          the cluster. A fudge could lead to a wrong decision */
00706 /*                          of judging eigenvalues 'separated' which in */
00707 /*                          reality are not. This could have a negative impact */
00708 /*                          on the orthogonality of the computed eigenvectors. */
00709 /* L116: */
00710                             }
00711                             ++nclus;
00712                             k = newcls + (nclus << 1);
00713                             iwork[k - 1] = newfst;
00714                             iwork[k] = newlst;
00715                         } else {
00716                             *info = -2;
00717                             return 0;
00718                         }
00719                     } else {
00720 
00721 /*                    Compute eigenvector of singleton */
00722 
00723                         iter = 0;
00724 
00725                         tol = log((real) in) * 4.f * eps;
00726 
00727                         k = newfst;
00728                         windex = wbegin + k - 1;
00729 /* Computing MAX */
00730                         i__4 = windex - 1;
00731                         windmn = max(i__4,1);
00732 /* Computing MIN */
00733                         i__4 = windex + 1;
00734                         windpl = min(i__4,*m);
00735                         lambda = work[windex];
00736                         ++done;
00737 /*                    Check if eigenvector computation is to be skipped */
00738                         if (windex < *dol || windex > *dou) {
00739                             eskip = TRUE_;
00740                             goto L125;
00741                         } else {
00742                             eskip = FALSE_;
00743                         }
00744                         left = work[windex] - werr[windex];
00745                         right = work[windex] + werr[windex];
00746                         indeig = indexw[windex];
00747 /*                    Note that since we compute the eigenpairs for a child, */
00748 /*                    all eigenvalue approximations are w.r.t the same shift. */
00749 /*                    In this case, the entries in WORK should be used for */
00750 /*                    computing the gaps since they exhibit even very small */
00751 /*                    differences in the eigenvalues, as opposed to the */
00752 /*                    entries in W which might "look" the same. */
00753                         if (k == 1) {
00754 /*                       In the case RANGE='I' and with not much initial */
00755 /*                       accuracy in LAMBDA and VL, the formula */
00756 /*                       LGAP = MAX( ZERO, (SIGMA - VL) + LAMBDA ) */
00757 /*                       can lead to an overestimation of the left gap and */
00758 /*                       thus to inadequately early RQI 'convergence'. */
00759 /*                       Prevent this by forcing a small left gap. */
00760 /* Computing MAX */
00761                             r__1 = dabs(left), r__2 = dabs(right);
00762                             lgap = eps * dmax(r__1,r__2);
00763                         } else {
00764                             lgap = wgap[windmn];
00765                         }
00766                         if (k == im) {
00767 /*                       In the case RANGE='I' and with not much initial */
00768 /*                       accuracy in LAMBDA and VU, the formula */
00769 /*                       can lead to an overestimation of the right gap and */
00770 /*                       thus to inadequately early RQI 'convergence'. */
00771 /*                       Prevent this by forcing a small right gap. */
00772 /* Computing MAX */
00773                             r__1 = dabs(left), r__2 = dabs(right);
00774                             rgap = eps * dmax(r__1,r__2);
00775                         } else {
00776                             rgap = wgap[windex];
00777                         }
00778                         gap = dmin(lgap,rgap);
00779                         if (k == 1 || k == im) {
00780 /*                       The eigenvector support can become wrong */
00781 /*                       because significant entries could be cut off due to a */
00782 /*                       large GAPTOL parameter in LAR1V. Prevent this. */
00783                             gaptol = 0.f;
00784                         } else {
00785                             gaptol = gap * eps;
00786                         }
00787                         isupmn = in;
00788                         isupmx = 1;
00789 /*                    Update WGAP so that it holds the minimum gap */
00790 /*                    to the left or the right. This is crucial in the */
00791 /*                    case where bisection is used to ensure that the */
00792 /*                    eigenvalue is refined up to the required precision. */
00793 /*                    The correct value is restored afterwards. */
00794                         savgap = wgap[windex];
00795                         wgap[windex] = gap;
00796 /*                    We want to use the Rayleigh Quotient Correction */
00797 /*                    as often as possible since it converges quadratically */
00798 /*                    when we are close enough to the desired eigenvalue. */
00799 /*                    However, the Rayleigh Quotient can have the wrong sign */
00800 /*                    and lead us away from the desired eigenvalue. In this */
00801 /*                    case, the best we can do is to use bisection. */
00802                         usedbs = FALSE_;
00803                         usedrq = FALSE_;
00804 /*                    Bisection is initially turned off unless it is forced */
00805                         needbs = ! tryrqc;
00806 L120:
00807 /*                    Check if bisection should be used to refine eigenvalue */
00808                         if (needbs) {
00809 /*                       Take the bisection as new iterate */
00810                             usedbs = TRUE_;
00811                             itmp1 = iwork[iindr + windex];
00812                             offset = indexw[wbegin] - 1;
00813                             r__1 = eps * 2.f;
00814                             slarrb_(&in, &d__[ibegin], &work[indlld + ibegin 
00815                                     - 1], &indeig, &indeig, &c_b28, &r__1, &
00816                                     offset, &work[wbegin], &wgap[wbegin], &
00817                                     werr[wbegin], &work[indwrk], &iwork[
00818                                     iindwk], pivmin, &spdiam, &itmp1, &iinfo);
00819                             if (iinfo != 0) {
00820                                 *info = -3;
00821                                 return 0;
00822                             }
00823                             lambda = work[windex];
00824 /*                       Reset twist index from inaccurate LAMBDA to */
00825 /*                       force computation of true MINGMA */
00826                             iwork[iindr + windex] = 0;
00827                         }
00828 /*                    Given LAMBDA, compute the eigenvector. */
00829                         L__1 = ! usedbs;
00830                         clar1v_(&in, &c__1, &in, &lambda, &d__[ibegin], &l[
00831                                 ibegin], &work[indld + ibegin - 1], &work[
00832                                 indlld + ibegin - 1], pivmin, &gaptol, &z__[
00833                                 ibegin + windex * z_dim1], &L__1, &negcnt, &
00834                                 ztz, &mingma, &iwork[iindr + windex], &isuppz[
00835                                 (windex << 1) - 1], &nrminv, &resid, &rqcorr, 
00836                                 &work[indwrk]);
00837                         if (iter == 0) {
00838                             bstres = resid;
00839                             bstw = lambda;
00840                         } else if (resid < bstres) {
00841                             bstres = resid;
00842                             bstw = lambda;
00843                         }
00844 /* Computing MIN */
00845                         i__4 = isupmn, i__5 = isuppz[(windex << 1) - 1];
00846                         isupmn = min(i__4,i__5);
00847 /* Computing MAX */
00848                         i__4 = isupmx, i__5 = isuppz[windex * 2];
00849                         isupmx = max(i__4,i__5);
00850                         ++iter;
00851 /*                    sin alpha <= |resid|/gap */
00852 /*                    Note that both the residual and the gap are */
00853 /*                    proportional to the matrix, so ||T|| doesn't play */
00854 /*                    a role in the quotient */
00855 
00856 /*                    Convergence test for Rayleigh-Quotient iteration */
00857 /*                    (omitted when Bisection has been used) */
00858 
00859                         if (resid > tol * gap && dabs(rqcorr) > rqtol * dabs(
00860                                 lambda) && ! usedbs) {
00861 /*                       We need to check that the RQCORR update doesn't */
00862 /*                       move the eigenvalue away from the desired one and */
00863 /*                       towards a neighbor. -> protection with bisection */
00864                             if (indeig <= negcnt) {
00865 /*                          The wanted eigenvalue lies to the left */
00866                                 sgndef = -1.f;
00867                             } else {
00868 /*                          The wanted eigenvalue lies to the right */
00869                                 sgndef = 1.f;
00870                             }
00871 /*                       We only use the RQCORR if it improves the */
00872 /*                       the iterate reasonably. */
00873                             if (rqcorr * sgndef >= 0.f && lambda + rqcorr <= 
00874                                     right && lambda + rqcorr >= left) {
00875                                 usedrq = TRUE_;
00876 /*                          Store new midpoint of bisection interval in WORK */
00877                                 if (sgndef == 1.f) {
00878 /*                             The current LAMBDA is on the left of the true */
00879 /*                             eigenvalue */
00880                                     left = lambda;
00881 /*                             We prefer to assume that the error estimate */
00882 /*                             is correct. We could make the interval not */
00883 /*                             as a bracket but to be modified if the RQCORR */
00884 /*                             chooses to. In this case, the RIGHT side should */
00885 /*                             be modified as follows: */
00886 /*                              RIGHT = MAX(RIGHT, LAMBDA + RQCORR) */
00887                                 } else {
00888 /*                             The current LAMBDA is on the right of the true */
00889 /*                             eigenvalue */
00890                                     right = lambda;
00891 /*                             See comment about assuming the error estimate is */
00892 /*                             correct above. */
00893 /*                              LEFT = MIN(LEFT, LAMBDA + RQCORR) */
00894                                 }
00895                                 work[windex] = (right + left) * .5f;
00896 /*                          Take RQCORR since it has the correct sign and */
00897 /*                          improves the iterate reasonably */
00898                                 lambda += rqcorr;
00899 /*                          Update width of error interval */
00900                                 werr[windex] = (right - left) * .5f;
00901                             } else {
00902                                 needbs = TRUE_;
00903                             }
00904                             if (right - left < rqtol * dabs(lambda)) {
00905 /*                             The eigenvalue is computed to bisection accuracy */
00906 /*                             compute eigenvector and stop */
00907                                 usedbs = TRUE_;
00908                                 goto L120;
00909                             } else if (iter < 10) {
00910                                 goto L120;
00911                             } else if (iter == 10) {
00912                                 needbs = TRUE_;
00913                                 goto L120;
00914                             } else {
00915                                 *info = 5;
00916                                 return 0;
00917                             }
00918                         } else {
00919                             stp2ii = FALSE_;
00920                             if (usedrq && usedbs && bstres <= resid) {
00921                                 lambda = bstw;
00922                                 stp2ii = TRUE_;
00923                             }
00924                             if (stp2ii) {
00925 /*                          improve error angle by second step */
00926                                 L__1 = ! usedbs;
00927                                 clar1v_(&in, &c__1, &in, &lambda, &d__[ibegin]
00928 , &l[ibegin], &work[indld + ibegin - 
00929                                         1], &work[indlld + ibegin - 1], 
00930                                         pivmin, &gaptol, &z__[ibegin + windex 
00931                                         * z_dim1], &L__1, &negcnt, &ztz, &
00932                                         mingma, &iwork[iindr + windex], &
00933                                         isuppz[(windex << 1) - 1], &nrminv, &
00934                                         resid, &rqcorr, &work[indwrk]);
00935                             }
00936                             work[windex] = lambda;
00937                         }
00938 
00939 /*                    Compute FP-vector support w.r.t. whole matrix */
00940 
00941                         isuppz[(windex << 1) - 1] += oldien;
00942                         isuppz[windex * 2] += oldien;
00943                         zfrom = isuppz[(windex << 1) - 1];
00944                         zto = isuppz[windex * 2];
00945                         isupmn += oldien;
00946                         isupmx += oldien;
00947 /*                    Ensure vector is ok if support in the RQI has changed */
00948                         if (isupmn < zfrom) {
00949                             i__4 = zfrom - 1;
00950                             for (ii = isupmn; ii <= i__4; ++ii) {
00951                                 i__5 = ii + windex * z_dim1;
00952                                 z__[i__5].r = 0.f, z__[i__5].i = 0.f;
00953 /* L122: */
00954                             }
00955                         }
00956                         if (isupmx > zto) {
00957                             i__4 = isupmx;
00958                             for (ii = zto + 1; ii <= i__4; ++ii) {
00959                                 i__5 = ii + windex * z_dim1;
00960                                 z__[i__5].r = 0.f, z__[i__5].i = 0.f;
00961 /* L123: */
00962                             }
00963                         }
00964                         i__4 = zto - zfrom + 1;
00965                         csscal_(&i__4, &nrminv, &z__[zfrom + windex * z_dim1], 
00966                                  &c__1);
00967 L125:
00968 /*                    Update W */
00969                         w[windex] = lambda + sigma;
00970 /*                    Recompute the gaps on the left and right */
00971 /*                    But only allow them to become larger and not */
00972 /*                    smaller (which can only happen through "bad" */
00973 /*                    cancellation and doesn't reflect the theory */
00974 /*                    where the initial gaps are underestimated due */
00975 /*                    to WERR being too crude.) */
00976                         if (! eskip) {
00977                             if (k > 1) {
00978 /* Computing MAX */
00979                                 r__1 = wgap[windmn], r__2 = w[windex] - werr[
00980                                         windex] - w[windmn] - werr[windmn];
00981                                 wgap[windmn] = dmax(r__1,r__2);
00982                             }
00983                             if (windex < wend) {
00984 /* Computing MAX */
00985                                 r__1 = savgap, r__2 = w[windpl] - werr[windpl]
00986                                          - w[windex] - werr[windex];
00987                                 wgap[windex] = dmax(r__1,r__2);
00988                             }
00989                         }
00990                         ++idone;
00991                     }
00992 /*                 here ends the code for the current child */
00993 
00994 L139:
00995 /*                 Proceed to any remaining child nodes */
00996                     newfst = j + 1;
00997 L140:
00998                     ;
00999                 }
01000 /* L150: */
01001             }
01002             ++ndepth;
01003             goto L40;
01004         }
01005         ibegin = iend + 1;
01006         wbegin = wend + 1;
01007 L170:
01008         ;
01009     }
01010 
01011     return 0;
01012 
01013 /*     End of CLARRV */
01014 
01015 } /* clarrv_ */


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