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


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