dstemr.c
Go to the documentation of this file.
00001 /* dstemr.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Table of constant values */
00017 
00018 static integer c__1 = 1;
00019 static doublereal c_b18 = .001;
00020 
00021 /* Subroutine */ int dstemr_(char *jobz, char *range, integer *n, doublereal *
00022         d__, doublereal *e, doublereal *vl, doublereal *vu, integer *il, 
00023         integer *iu, integer *m, doublereal *w, doublereal *z__, integer *ldz, 
00024          integer *nzc, integer *isuppz, logical *tryrac, doublereal *work, 
00025         integer *lwork, integer *iwork, integer *liwork, integer *info)
00026 {
00027     /* System generated locals */
00028     integer z_dim1, z_offset, i__1, i__2;
00029     doublereal d__1, d__2;
00030 
00031     /* Builtin functions */
00032     double sqrt(doublereal);
00033 
00034     /* Local variables */
00035     integer i__, j;
00036     doublereal r1, r2;
00037     integer jj;
00038     doublereal cs;
00039     integer in;
00040     doublereal sn, wl, wu;
00041     integer iil, iiu;
00042     doublereal eps, tmp;
00043     integer indd, iend, jblk, wend;
00044     doublereal rmin, rmax;
00045     integer itmp;
00046     doublereal tnrm;
00047     extern /* Subroutine */ int dlae2_(doublereal *, doublereal *, doublereal 
00048             *, doublereal *, doublereal *);
00049     integer inde2, itmp2;
00050     doublereal rtol1, rtol2;
00051     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
00052             integer *);
00053     doublereal scale;
00054     integer indgp;
00055     extern logical lsame_(char *, char *);
00056     integer iinfo, iindw, ilast;
00057     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, 
00058             doublereal *, integer *), dswap_(integer *, doublereal *, integer 
00059             *, doublereal *, integer *);
00060     integer lwmin;
00061     logical wantz;
00062     extern /* Subroutine */ int dlaev2_(doublereal *, doublereal *, 
00063             doublereal *, doublereal *, doublereal *, doublereal *, 
00064             doublereal *);
00065     extern doublereal dlamch_(char *);
00066     logical alleig;
00067     integer ibegin;
00068     logical indeig;
00069     integer iindbl;
00070     logical valeig;
00071     extern /* Subroutine */ int dlarrc_(char *, integer *, doublereal *, 
00072             doublereal *, doublereal *, doublereal *, doublereal *, integer *, 
00073              integer *, integer *, integer *), dlarre_(char *, 
00074             integer *, doublereal *, doublereal *, integer *, integer *, 
00075             doublereal *, doublereal *, doublereal *, doublereal *, 
00076             doublereal *, doublereal *, integer *, integer *, integer *, 
00077             doublereal *, doublereal *, doublereal *, integer *, integer *, 
00078             doublereal *, doublereal *, doublereal *, integer *, integer *);
00079     integer wbegin;
00080     doublereal safmin;
00081     extern /* Subroutine */ int dlarrj_(integer *, doublereal *, doublereal *, 
00082              integer *, integer *, doublereal *, integer *, doublereal *, 
00083             doublereal *, doublereal *, integer *, doublereal *, doublereal *, 
00084              integer *), xerbla_(char *, integer *);
00085     doublereal bignum;
00086     integer inderr, iindwk, indgrs, offset;
00087     extern doublereal dlanst_(char *, integer *, doublereal *, doublereal *);
00088     extern /* Subroutine */ int dlarrr_(integer *, doublereal *, doublereal *, 
00089              integer *), dlarrv_(integer *, doublereal *, doublereal *, 
00090             doublereal *, doublereal *, doublereal *, integer *, integer *, 
00091             integer *, integer *, doublereal *, doublereal *, doublereal *, 
00092             doublereal *, doublereal *, doublereal *, integer *, integer *, 
00093             doublereal *, doublereal *, integer *, integer *, doublereal *, 
00094             integer *, integer *), dlasrt_(char *, integer *, doublereal *, 
00095             integer *);
00096     doublereal thresh;
00097     integer iinspl, ifirst, indwrk, liwmin, nzcmin;
00098     doublereal pivmin;
00099     integer nsplit;
00100     doublereal smlnum;
00101     logical lquery, zquery;
00102 
00103 
00104 /*  -- LAPACK computational routine (version 3.2) -- */
00105 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00106 /*     November 2006 */
00107 
00108 /*     .. Scalar Arguments .. */
00109 /*     .. */
00110 /*     .. Array Arguments .. */
00111 /*     .. */
00112 
00113 /*  Purpose */
00114 /*  ======= */
00115 
00116 /*  DSTEMR computes selected eigenvalues and, optionally, eigenvectors */
00117 /*  of a real symmetric tridiagonal matrix T. Any such unreduced matrix has */
00118 /*  a well defined set of pairwise different real eigenvalues, the corresponding */
00119 /*  real eigenvectors are pairwise orthogonal. */
00120 
00121 /*  The spectrum may be computed either completely or partially by specifying */
00122 /*  either an interval (VL,VU] or a range of indices IL:IU for the desired */
00123 /*  eigenvalues. */
00124 
00125 /*  Depending on the number of desired eigenvalues, these are computed either */
00126 /*  by bisection or the dqds algorithm. Numerically orthogonal eigenvectors are */
00127 /*  computed by the use of various suitable L D L^T factorizations near clusters */
00128 /*  of close eigenvalues (referred to as RRRs, Relatively Robust */
00129 /*  Representations). An informal sketch of the algorithm follows. */
00130 
00131 /*  For each unreduced block (submatrix) of T, */
00132 /*     (a) Compute T - sigma I  = L D L^T, so that L and D */
00133 /*         define all the wanted eigenvalues to high relative accuracy. */
00134 /*         This means that small relative changes in the entries of D and L */
00135 /*         cause only small relative changes in the eigenvalues and */
00136 /*         eigenvectors. The standard (unfactored) representation of the */
00137 /*         tridiagonal matrix T does not have this property in general. */
00138 /*     (b) Compute the eigenvalues to suitable accuracy. */
00139 /*         If the eigenvectors are desired, the algorithm attains full */
00140 /*         accuracy of the computed eigenvalues only right before */
00141 /*         the corresponding vectors have to be computed, see steps c) and d). */
00142 /*     (c) For each cluster of close eigenvalues, select a new */
00143 /*         shift close to the cluster, find a new factorization, and refine */
00144 /*         the shifted eigenvalues to suitable accuracy. */
00145 /*     (d) For each eigenvalue with a large enough relative separation compute */
00146 /*         the corresponding eigenvector by forming a rank revealing twisted */
00147 /*         factorization. Go back to (c) for any clusters that remain. */
00148 
00149 /*  For more details, see: */
00150 /*  - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations */
00151 /*    to compute orthogonal eigenvectors of symmetric tridiagonal matrices," */
00152 /*    Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004. */
00153 /*  - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and */
00154 /*    Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25, */
00155 /*    2004.  Also LAPACK Working Note 154. */
00156 /*  - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric */
00157 /*    tridiagonal eigenvalue/eigenvector problem", */
00158 /*    Computer Science Division Technical Report No. UCB/CSD-97-971, */
00159 /*    UC Berkeley, May 1997. */
00160 
00161 /*  Notes: */
00162 /*  1.DSTEMR works only on machines which follow IEEE-754 */
00163 /*  floating-point standard in their handling of infinities and NaNs. */
00164 /*  This permits the use of efficient inner loops avoiding a check for */
00165 /*  zero divisors. */
00166 
00167 /*  Arguments */
00168 /*  ========= */
00169 
00170 /*  JOBZ    (input) CHARACTER*1 */
00171 /*          = 'N':  Compute eigenvalues only; */
00172 /*          = 'V':  Compute eigenvalues and eigenvectors. */
00173 
00174 /*  RANGE   (input) CHARACTER*1 */
00175 /*          = 'A': all eigenvalues will be found. */
00176 /*          = 'V': all eigenvalues in the half-open interval (VL,VU] */
00177 /*                 will be found. */
00178 /*          = 'I': the IL-th through IU-th eigenvalues will be found. */
00179 
00180 /*  N       (input) INTEGER */
00181 /*          The order of the matrix.  N >= 0. */
00182 
00183 /*  D       (input/output) DOUBLE PRECISION array, dimension (N) */
00184 /*          On entry, the N diagonal elements of the tridiagonal matrix */
00185 /*          T. On exit, D is overwritten. */
00186 
00187 /*  E       (input/output) DOUBLE PRECISION array, dimension (N) */
00188 /*          On entry, the (N-1) subdiagonal elements of the tridiagonal */
00189 /*          matrix T in elements 1 to N-1 of E. E(N) need not be set on */
00190 /*          input, but is used internally as workspace. */
00191 /*          On exit, E is overwritten. */
00192 
00193 /*  VL      (input) DOUBLE PRECISION */
00194 /*  VU      (input) DOUBLE PRECISION */
00195 /*          If RANGE='V', the lower and upper bounds of the interval to */
00196 /*          be searched for eigenvalues. VL < VU. */
00197 /*          Not referenced if RANGE = 'A' or 'I'. */
00198 
00199 /*  IL      (input) INTEGER */
00200 /*  IU      (input) INTEGER */
00201 /*          If RANGE='I', the indices (in ascending order) of the */
00202 /*          smallest and largest eigenvalues to be returned. */
00203 /*          1 <= IL <= IU <= N, if N > 0. */
00204 /*          Not referenced if RANGE = 'A' or 'V'. */
00205 
00206 /*  M       (output) INTEGER */
00207 /*          The total number of eigenvalues found.  0 <= M <= N. */
00208 /*          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
00209 
00210 /*  W       (output) DOUBLE PRECISION array, dimension (N) */
00211 /*          The first M elements contain the selected eigenvalues in */
00212 /*          ascending order. */
00213 
00214 /*  Z       (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M) ) */
00215 /*          If JOBZ = 'V', and if INFO = 0, then the first M columns of Z */
00216 /*          contain the orthonormal eigenvectors of the matrix T */
00217 /*          corresponding to the selected eigenvalues, with the i-th */
00218 /*          column of Z holding the eigenvector associated with W(i). */
00219 /*          If JOBZ = 'N', then Z is not referenced. */
00220 /*          Note: the user must ensure that at least max(1,M) columns are */
00221 /*          supplied in the array Z; if RANGE = 'V', the exact value of M */
00222 /*          is not known in advance and can be computed with a workspace */
00223 /*          query by setting NZC = -1, see below. */
00224 
00225 /*  LDZ     (input) INTEGER */
00226 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
00227 /*          JOBZ = 'V', then LDZ >= max(1,N). */
00228 
00229 /*  NZC     (input) INTEGER */
00230 /*          The number of eigenvectors to be held in the array Z. */
00231 /*          If RANGE = 'A', then NZC >= max(1,N). */
00232 /*          If RANGE = 'V', then NZC >= the number of eigenvalues in (VL,VU]. */
00233 /*          If RANGE = 'I', then NZC >= IU-IL+1. */
00234 /*          If NZC = -1, then a workspace query is assumed; the */
00235 /*          routine calculates the number of columns of the array Z that */
00236 /*          are needed to hold the eigenvectors. */
00237 /*          This value is returned as the first entry of the Z array, and */
00238 /*          no error message related to NZC is issued by XERBLA. */
00239 
00240 /*  ISUPPZ  (output) INTEGER ARRAY, dimension ( 2*max(1,M) ) */
00241 /*          The support of the eigenvectors in Z, i.e., the indices */
00242 /*          indicating the nonzero elements in Z. The i-th computed eigenvector */
00243 /*          is nonzero only in elements ISUPPZ( 2*i-1 ) through */
00244 /*          ISUPPZ( 2*i ). This is relevant in the case when the matrix */
00245 /*          is split. ISUPPZ is only accessed when JOBZ is 'V' and N > 0. */
00246 
00247 /*  TRYRAC  (input/output) LOGICAL */
00248 /*          If TRYRAC.EQ..TRUE., indicates that the code should check whether */
00249 /*          the tridiagonal matrix defines its eigenvalues to high relative */
00250 /*          accuracy.  If so, the code uses relative-accuracy preserving */
00251 /*          algorithms that might be (a bit) slower depending on the matrix. */
00252 /*          If the matrix does not define its eigenvalues to high relative */
00253 /*          accuracy, the code can uses possibly faster algorithms. */
00254 /*          If TRYRAC.EQ..FALSE., the code is not required to guarantee */
00255 /*          relatively accurate eigenvalues and can use the fastest possible */
00256 /*          techniques. */
00257 /*          On exit, a .TRUE. TRYRAC will be set to .FALSE. if the matrix */
00258 /*          does not define its eigenvalues to high relative accuracy. */
00259 
00260 /*  WORK    (workspace/output) DOUBLE PRECISION array, dimension (LWORK) */
00261 /*          On exit, if INFO = 0, WORK(1) returns the optimal */
00262 /*          (and minimal) LWORK. */
00263 
00264 /*  LWORK   (input) INTEGER */
00265 /*          The dimension of the array WORK. LWORK >= max(1,18*N) */
00266 /*          if JOBZ = 'V', and LWORK >= max(1,12*N) if JOBZ = 'N'. */
00267 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00268 /*          only calculates the optimal size of the WORK array, returns */
00269 /*          this value as the first entry of the WORK array, and no error */
00270 /*          message related to LWORK is issued by XERBLA. */
00271 
00272 /*  IWORK   (workspace/output) INTEGER array, dimension (LIWORK) */
00273 /*          On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
00274 
00275 /*  LIWORK  (input) INTEGER */
00276 /*          The dimension of the array IWORK.  LIWORK >= max(1,10*N) */
00277 /*          if the eigenvectors are desired, and LIWORK >= max(1,8*N) */
00278 /*          if only the eigenvalues are to be computed. */
00279 /*          If LIWORK = -1, then a workspace query is assumed; the */
00280 /*          routine only calculates the optimal size of the IWORK array, */
00281 /*          returns this value as the first entry of the IWORK array, and */
00282 /*          no error message related to LIWORK is issued by XERBLA. */
00283 
00284 /*  INFO    (output) INTEGER */
00285 /*          On exit, INFO */
00286 /*          = 0:  successful exit */
00287 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00288 /*          > 0:  if INFO = 1X, internal error in DLARRE, */
00289 /*                if INFO = 2X, internal error in DLARRV. */
00290 /*                Here, the digit X = ABS( IINFO ) < 10, where IINFO is */
00291 /*                the nonzero error code returned by DLARRE or */
00292 /*                DLARRV, respectively. */
00293 
00294 
00295 /*  Further Details */
00296 /*  =============== */
00297 
00298 /*  Based on contributions by */
00299 /*     Beresford Parlett, University of California, Berkeley, USA */
00300 /*     Jim Demmel, University of California, Berkeley, USA */
00301 /*     Inderjit Dhillon, University of Texas, Austin, USA */
00302 /*     Osni Marques, LBNL/NERSC, USA */
00303 /*     Christof Voemel, University of California, Berkeley, USA */
00304 
00305 /*  ===================================================================== */
00306 
00307 /*     .. Parameters .. */
00308 /*     .. */
00309 /*     .. Local Scalars .. */
00310 /*     .. */
00311 /*     .. */
00312 /*     .. External Functions .. */
00313 /*     .. */
00314 /*     .. External Subroutines .. */
00315 /*     .. */
00316 /*     .. Intrinsic Functions .. */
00317 /*     .. */
00318 /*     .. Executable Statements .. */
00319 
00320 /*     Test the input parameters. */
00321 
00322     /* Parameter adjustments */
00323     --d__;
00324     --e;
00325     --w;
00326     z_dim1 = *ldz;
00327     z_offset = 1 + z_dim1;
00328     z__ -= z_offset;
00329     --isuppz;
00330     --work;
00331     --iwork;
00332 
00333     /* Function Body */
00334     wantz = lsame_(jobz, "V");
00335     alleig = lsame_(range, "A");
00336     valeig = lsame_(range, "V");
00337     indeig = lsame_(range, "I");
00338 
00339     lquery = *lwork == -1 || *liwork == -1;
00340     zquery = *nzc == -1;
00341 /*     DSTEMR needs WORK of size 6*N, IWORK of size 3*N. */
00342 /*     In addition, DLARRE needs WORK of size 6*N, IWORK of size 5*N. */
00343 /*     Furthermore, DLARRV needs WORK of size 12*N, IWORK of size 7*N. */
00344     if (wantz) {
00345         lwmin = *n * 18;
00346         liwmin = *n * 10;
00347     } else {
00348 /*        need less workspace if only the eigenvalues are wanted */
00349         lwmin = *n * 12;
00350         liwmin = *n << 3;
00351     }
00352     wl = 0.;
00353     wu = 0.;
00354     iil = 0;
00355     iiu = 0;
00356     if (valeig) {
00357 /*        We do not reference VL, VU in the cases RANGE = 'I','A' */
00358 /*        The interval (WL, WU] contains all the wanted eigenvalues. */
00359 /*        It is either given by the user or computed in DLARRE. */
00360         wl = *vl;
00361         wu = *vu;
00362     } else if (indeig) {
00363 /*        We do not reference IL, IU in the cases RANGE = 'V','A' */
00364         iil = *il;
00365         iiu = *iu;
00366     }
00367 
00368     *info = 0;
00369     if (! (wantz || lsame_(jobz, "N"))) {
00370         *info = -1;
00371     } else if (! (alleig || valeig || indeig)) {
00372         *info = -2;
00373     } else if (*n < 0) {
00374         *info = -3;
00375     } else if (valeig && *n > 0 && wu <= wl) {
00376         *info = -7;
00377     } else if (indeig && (iil < 1 || iil > *n)) {
00378         *info = -8;
00379     } else if (indeig && (iiu < iil || iiu > *n)) {
00380         *info = -9;
00381     } else if (*ldz < 1 || wantz && *ldz < *n) {
00382         *info = -13;
00383     } else if (*lwork < lwmin && ! lquery) {
00384         *info = -17;
00385     } else if (*liwork < liwmin && ! lquery) {
00386         *info = -19;
00387     }
00388 
00389 /*     Get machine constants. */
00390 
00391     safmin = dlamch_("Safe minimum");
00392     eps = dlamch_("Precision");
00393     smlnum = safmin / eps;
00394     bignum = 1. / smlnum;
00395     rmin = sqrt(smlnum);
00396 /* Computing MIN */
00397     d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin));
00398     rmax = min(d__1,d__2);
00399 
00400     if (*info == 0) {
00401         work[1] = (doublereal) lwmin;
00402         iwork[1] = liwmin;
00403 
00404         if (wantz && alleig) {
00405             nzcmin = *n;
00406         } else if (wantz && valeig) {
00407             dlarrc_("T", n, vl, vu, &d__[1], &e[1], &safmin, &nzcmin, &itmp, &
00408                     itmp2, info);
00409         } else if (wantz && indeig) {
00410             nzcmin = iiu - iil + 1;
00411         } else {
00412 /*           WANTZ .EQ. FALSE. */
00413             nzcmin = 0;
00414         }
00415         if (zquery && *info == 0) {
00416             z__[z_dim1 + 1] = (doublereal) nzcmin;
00417         } else if (*nzc < nzcmin && ! zquery) {
00418             *info = -14;
00419         }
00420     }
00421     if (*info != 0) {
00422 
00423         i__1 = -(*info);
00424         xerbla_("DSTEMR", &i__1);
00425 
00426         return 0;
00427     } else if (lquery || zquery) {
00428         return 0;
00429     }
00430 
00431 /*     Handle N = 0, 1, and 2 cases immediately */
00432 
00433     *m = 0;
00434     if (*n == 0) {
00435         return 0;
00436     }
00437 
00438     if (*n == 1) {
00439         if (alleig || indeig) {
00440             *m = 1;
00441             w[1] = d__[1];
00442         } else {
00443             if (wl < d__[1] && wu >= d__[1]) {
00444                 *m = 1;
00445                 w[1] = d__[1];
00446             }
00447         }
00448         if (wantz && ! zquery) {
00449             z__[z_dim1 + 1] = 1.;
00450             isuppz[1] = 1;
00451             isuppz[2] = 1;
00452         }
00453         return 0;
00454     }
00455 
00456     if (*n == 2) {
00457         if (! wantz) {
00458             dlae2_(&d__[1], &e[1], &d__[2], &r1, &r2);
00459         } else if (wantz && ! zquery) {
00460             dlaev2_(&d__[1], &e[1], &d__[2], &r1, &r2, &cs, &sn);
00461         }
00462         if (alleig || valeig && r2 > wl && r2 <= wu || indeig && iil == 1) {
00463             ++(*m);
00464             w[*m] = r2;
00465             if (wantz && ! zquery) {
00466                 z__[*m * z_dim1 + 1] = -sn;
00467                 z__[*m * z_dim1 + 2] = cs;
00468 /*              Note: At most one of SN and CS can be zero. */
00469                 if (sn != 0.) {
00470                     if (cs != 0.) {
00471                         isuppz[(*m << 1) - 1] = 1;
00472                         isuppz[(*m << 1) - 1] = 2;
00473                     } else {
00474                         isuppz[(*m << 1) - 1] = 1;
00475                         isuppz[(*m << 1) - 1] = 1;
00476                     }
00477                 } else {
00478                     isuppz[(*m << 1) - 1] = 2;
00479                     isuppz[*m * 2] = 2;
00480                 }
00481             }
00482         }
00483         if (alleig || valeig && r1 > wl && r1 <= wu || indeig && iiu == 2) {
00484             ++(*m);
00485             w[*m] = r1;
00486             if (wantz && ! zquery) {
00487                 z__[*m * z_dim1 + 1] = cs;
00488                 z__[*m * z_dim1 + 2] = sn;
00489 /*              Note: At most one of SN and CS can be zero. */
00490                 if (sn != 0.) {
00491                     if (cs != 0.) {
00492                         isuppz[(*m << 1) - 1] = 1;
00493                         isuppz[(*m << 1) - 1] = 2;
00494                     } else {
00495                         isuppz[(*m << 1) - 1] = 1;
00496                         isuppz[(*m << 1) - 1] = 1;
00497                     }
00498                 } else {
00499                     isuppz[(*m << 1) - 1] = 2;
00500                     isuppz[*m * 2] = 2;
00501                 }
00502             }
00503         }
00504         return 0;
00505     }
00506 /*     Continue with general N */
00507     indgrs = 1;
00508     inderr = (*n << 1) + 1;
00509     indgp = *n * 3 + 1;
00510     indd = (*n << 2) + 1;
00511     inde2 = *n * 5 + 1;
00512     indwrk = *n * 6 + 1;
00513 
00514     iinspl = 1;
00515     iindbl = *n + 1;
00516     iindw = (*n << 1) + 1;
00517     iindwk = *n * 3 + 1;
00518 
00519 /*     Scale matrix to allowable range, if necessary. */
00520 /*     The allowable range is related to the PIVMIN parameter; see the */
00521 /*     comments in DLARRD.  The preference for scaling small values */
00522 /*     up is heuristic; we expect users' matrices not to be close to the */
00523 /*     RMAX threshold. */
00524 
00525     scale = 1.;
00526     tnrm = dlanst_("M", n, &d__[1], &e[1]);
00527     if (tnrm > 0. && tnrm < rmin) {
00528         scale = rmin / tnrm;
00529     } else if (tnrm > rmax) {
00530         scale = rmax / tnrm;
00531     }
00532     if (scale != 1.) {
00533         dscal_(n, &scale, &d__[1], &c__1);
00534         i__1 = *n - 1;
00535         dscal_(&i__1, &scale, &e[1], &c__1);
00536         tnrm *= scale;
00537         if (valeig) {
00538 /*           If eigenvalues in interval have to be found, */
00539 /*           scale (WL, WU] accordingly */
00540             wl *= scale;
00541             wu *= scale;
00542         }
00543     }
00544 
00545 /*     Compute the desired eigenvalues of the tridiagonal after splitting */
00546 /*     into smaller subblocks if the corresponding off-diagonal elements */
00547 /*     are small */
00548 /*     THRESH is the splitting parameter for DLARRE */
00549 /*     A negative THRESH forces the old splitting criterion based on the */
00550 /*     size of the off-diagonal. A positive THRESH switches to splitting */
00551 /*     which preserves relative accuracy. */
00552 
00553     if (*tryrac) {
00554 /*        Test whether the matrix warrants the more expensive relative approach. */
00555         dlarrr_(n, &d__[1], &e[1], &iinfo);
00556     } else {
00557 /*        The user does not care about relative accurately eigenvalues */
00558         iinfo = -1;
00559     }
00560 /*     Set the splitting criterion */
00561     if (iinfo == 0) {
00562         thresh = eps;
00563     } else {
00564         thresh = -eps;
00565 /*        relative accuracy is desired but T does not guarantee it */
00566         *tryrac = FALSE_;
00567     }
00568 
00569     if (*tryrac) {
00570 /*        Copy original diagonal, needed to guarantee relative accuracy */
00571         dcopy_(n, &d__[1], &c__1, &work[indd], &c__1);
00572     }
00573 /*     Store the squares of the offdiagonal values of T */
00574     i__1 = *n - 1;
00575     for (j = 1; j <= i__1; ++j) {
00576 /* Computing 2nd power */
00577         d__1 = e[j];
00578         work[inde2 + j - 1] = d__1 * d__1;
00579 /* L5: */
00580     }
00581 /*     Set the tolerance parameters for bisection */
00582     if (! wantz) {
00583 /*        DLARRE computes the eigenvalues to full precision. */
00584         rtol1 = eps * 4.;
00585         rtol2 = eps * 4.;
00586     } else {
00587 /*        DLARRE computes the eigenvalues to less than full precision. */
00588 /*        DLARRV will refine the eigenvalue approximations, and we can */
00589 /*        need less accurate initial bisection in DLARRE. */
00590 /*        Note: these settings do only affect the subset case and DLARRE */
00591         rtol1 = sqrt(eps);
00592 /* Computing MAX */
00593         d__1 = sqrt(eps) * .005, d__2 = eps * 4.;
00594         rtol2 = max(d__1,d__2);
00595     }
00596     dlarre_(range, n, &wl, &wu, &iil, &iiu, &d__[1], &e[1], &work[inde2], &
00597             rtol1, &rtol2, &thresh, &nsplit, &iwork[iinspl], m, &w[1], &work[
00598             inderr], &work[indgp], &iwork[iindbl], &iwork[iindw], &work[
00599             indgrs], &pivmin, &work[indwrk], &iwork[iindwk], &iinfo);
00600     if (iinfo != 0) {
00601         *info = abs(iinfo) + 10;
00602         return 0;
00603     }
00604 /*     Note that if RANGE .NE. 'V', DLARRE computes bounds on the desired */
00605 /*     part of the spectrum. All desired eigenvalues are contained in */
00606 /*     (WL,WU] */
00607     if (wantz) {
00608 
00609 /*        Compute the desired eigenvectors corresponding to the computed */
00610 /*        eigenvalues */
00611 
00612         dlarrv_(n, &wl, &wu, &d__[1], &e[1], &pivmin, &iwork[iinspl], m, &
00613                 c__1, m, &c_b18, &rtol1, &rtol2, &w[1], &work[inderr], &work[
00614                 indgp], &iwork[iindbl], &iwork[iindw], &work[indgrs], &z__[
00615                 z_offset], ldz, &isuppz[1], &work[indwrk], &iwork[iindwk], &
00616                 iinfo);
00617         if (iinfo != 0) {
00618             *info = abs(iinfo) + 20;
00619             return 0;
00620         }
00621     } else {
00622 /*        DLARRE computes eigenvalues of the (shifted) root representation */
00623 /*        DLARRV returns the eigenvalues of the unshifted matrix. */
00624 /*        However, if the eigenvectors are not desired by the user, we need */
00625 /*        to apply the corresponding shifts from DLARRE to obtain the */
00626 /*        eigenvalues of the original matrix. */
00627         i__1 = *m;
00628         for (j = 1; j <= i__1; ++j) {
00629             itmp = iwork[iindbl + j - 1];
00630             w[j] += e[iwork[iinspl + itmp - 1]];
00631 /* L20: */
00632         }
00633     }
00634 
00635     if (*tryrac) {
00636 /*        Refine computed eigenvalues so that they are relatively accurate */
00637 /*        with respect to the original matrix T. */
00638         ibegin = 1;
00639         wbegin = 1;
00640         i__1 = iwork[iindbl + *m - 1];
00641         for (jblk = 1; jblk <= i__1; ++jblk) {
00642             iend = iwork[iinspl + jblk - 1];
00643             in = iend - ibegin + 1;
00644             wend = wbegin - 1;
00645 /*           check if any eigenvalues have to be refined in this block */
00646 L36:
00647             if (wend < *m) {
00648                 if (iwork[iindbl + wend] == jblk) {
00649                     ++wend;
00650                     goto L36;
00651                 }
00652             }
00653             if (wend < wbegin) {
00654                 ibegin = iend + 1;
00655                 goto L39;
00656             }
00657             offset = iwork[iindw + wbegin - 1] - 1;
00658             ifirst = iwork[iindw + wbegin - 1];
00659             ilast = iwork[iindw + wend - 1];
00660             rtol2 = eps * 4.;
00661             dlarrj_(&in, &work[indd + ibegin - 1], &work[inde2 + ibegin - 1], 
00662                     &ifirst, &ilast, &rtol2, &offset, &w[wbegin], &work[
00663                     inderr + wbegin - 1], &work[indwrk], &iwork[iindwk], &
00664                     pivmin, &tnrm, &iinfo);
00665             ibegin = iend + 1;
00666             wbegin = wend + 1;
00667 L39:
00668             ;
00669         }
00670     }
00671 
00672 /*     If matrix was scaled, then rescale eigenvalues appropriately. */
00673 
00674     if (scale != 1.) {
00675         d__1 = 1. / scale;
00676         dscal_(m, &d__1, &w[1], &c__1);
00677     }
00678 
00679 /*     If eigenvalues are not in increasing order, then sort them, */
00680 /*     possibly along with eigenvectors. */
00681 
00682     if (nsplit > 1) {
00683         if (! wantz) {
00684             dlasrt_("I", m, &w[1], &iinfo);
00685             if (iinfo != 0) {
00686                 *info = 3;
00687                 return 0;
00688             }
00689         } else {
00690             i__1 = *m - 1;
00691             for (j = 1; j <= i__1; ++j) {
00692                 i__ = 0;
00693                 tmp = w[j];
00694                 i__2 = *m;
00695                 for (jj = j + 1; jj <= i__2; ++jj) {
00696                     if (w[jj] < tmp) {
00697                         i__ = jj;
00698                         tmp = w[jj];
00699                     }
00700 /* L50: */
00701                 }
00702                 if (i__ != 0) {
00703                     w[i__] = w[j];
00704                     w[j] = tmp;
00705                     if (wantz) {
00706                         dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * 
00707                                 z_dim1 + 1], &c__1);
00708                         itmp = isuppz[(i__ << 1) - 1];
00709                         isuppz[(i__ << 1) - 1] = isuppz[(j << 1) - 1];
00710                         isuppz[(j << 1) - 1] = itmp;
00711                         itmp = isuppz[i__ * 2];
00712                         isuppz[i__ * 2] = isuppz[j * 2];
00713                         isuppz[j * 2] = itmp;
00714                     }
00715                 }
00716 /* L60: */
00717             }
00718         }
00719     }
00720 
00721 
00722     work[1] = (doublereal) lwmin;
00723     iwork[1] = liwmin;
00724     return 0;
00725 
00726 /*     End of DSTEMR */
00727 
00728 } /* dstemr_ */


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