zstemr.c
Go to the documentation of this file.
00001 /* zstemr.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 zstemr_(char *jobz, char *range, integer *n, doublereal *
00022         d__, doublereal *e, doublereal *vl, doublereal *vu, integer *il, 
00023         integer *iu, integer *m, doublereal *w, doublecomplex *z__, integer *
00024         ldz, 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 *);
00059     integer lwmin;
00060     logical wantz;
00061     extern /* Subroutine */ int zswap_(integer *, doublecomplex *, integer *, 
00062             doublecomplex *, integer *), 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 *), dlasrt_(char *, integer *, doublereal *, integer *);
00090     doublereal thresh;
00091     integer iinspl, indwrk, ifirst, liwmin, nzcmin;
00092     doublereal pivmin;
00093     integer nsplit;
00094     doublereal smlnum;
00095     extern /* Subroutine */ int zlarrv_(integer *, doublereal *, doublereal *, 
00096              doublereal *, doublereal *, doublereal *, integer *, integer *, 
00097             integer *, integer *, doublereal *, doublereal *, doublereal *, 
00098             doublereal *, doublereal *, doublereal *, integer *, integer *, 
00099             doublereal *, doublecomplex *, integer *, integer *, doublereal *, 
00100              integer *, integer *);
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 /*  ZSTEMR 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.ZSTEMR 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 /*  2. LAPACK routines can be used to reduce a complex Hermitean matrix to */
00168 /*  real symmetric tridiagonal form. */
00169 
00170 /*  (Any complex Hermitean tridiagonal matrix has real values on its diagonal */
00171 /*  and potentially complex numbers on its off-diagonals. By applying a */
00172 /*  similarity transform with an appropriate diagonal matrix */
00173 /*  diag(1,e^{i \phy_1}, ... , e^{i \phy_{n-1}}), the complex Hermitean */
00174 /*  matrix can be transformed into a real symmetric matrix and complex */
00175 /*  arithmetic can be entirely avoided.) */
00176 
00177 /*  While the eigenvectors of the real symmetric tridiagonal matrix are real, */
00178 /*  the eigenvectors of original complex Hermitean matrix have complex entries */
00179 /*  in general. */
00180 /*  Since LAPACK drivers overwrite the matrix data with the eigenvectors, */
00181 /*  ZSTEMR accepts complex workspace to facilitate interoperability */
00182 /*  with ZUNMTR or ZUPMTR. */
00183 
00184 /*  Arguments */
00185 /*  ========= */
00186 
00187 /*  JOBZ    (input) CHARACTER*1 */
00188 /*          = 'N':  Compute eigenvalues only; */
00189 /*          = 'V':  Compute eigenvalues and eigenvectors. */
00190 
00191 /*  RANGE   (input) CHARACTER*1 */
00192 /*          = 'A': all eigenvalues will be found. */
00193 /*          = 'V': all eigenvalues in the half-open interval (VL,VU] */
00194 /*                 will be found. */
00195 /*          = 'I': the IL-th through IU-th eigenvalues will be found. */
00196 
00197 /*  N       (input) INTEGER */
00198 /*          The order of the matrix.  N >= 0. */
00199 
00200 /*  D       (input/output) DOUBLE PRECISION array, dimension (N) */
00201 /*          On entry, the N diagonal elements of the tridiagonal matrix */
00202 /*          T. On exit, D is overwritten. */
00203 
00204 /*  E       (input/output) DOUBLE PRECISION array, dimension (N) */
00205 /*          On entry, the (N-1) subdiagonal elements of the tridiagonal */
00206 /*          matrix T in elements 1 to N-1 of E. E(N) need not be set on */
00207 /*          input, but is used internally as workspace. */
00208 /*          On exit, E is overwritten. */
00209 
00210 /*  VL      (input) DOUBLE PRECISION */
00211 /*  VU      (input) DOUBLE PRECISION */
00212 /*          If RANGE='V', the lower and upper bounds of the interval to */
00213 /*          be searched for eigenvalues. VL < VU. */
00214 /*          Not referenced if RANGE = 'A' or 'I'. */
00215 
00216 /*  IL      (input) INTEGER */
00217 /*  IU      (input) INTEGER */
00218 /*          If RANGE='I', the indices (in ascending order) of the */
00219 /*          smallest and largest eigenvalues to be returned. */
00220 /*          1 <= IL <= IU <= N, if N > 0. */
00221 /*          Not referenced if RANGE = 'A' or 'V'. */
00222 
00223 /*  M       (output) INTEGER */
00224 /*          The total number of eigenvalues found.  0 <= M <= N. */
00225 /*          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
00226 
00227 /*  W       (output) DOUBLE PRECISION array, dimension (N) */
00228 /*          The first M elements contain the selected eigenvalues in */
00229 /*          ascending order. */
00230 
00231 /*  Z       (output) COMPLEX*16 array, dimension (LDZ, max(1,M) ) */
00232 /*          If JOBZ = 'V', and if INFO = 0, then the first M columns of Z */
00233 /*          contain the orthonormal eigenvectors of the matrix T */
00234 /*          corresponding to the selected eigenvalues, with the i-th */
00235 /*          column of Z holding the eigenvector associated with W(i). */
00236 /*          If JOBZ = 'N', then Z is not referenced. */
00237 /*          Note: the user must ensure that at least max(1,M) columns are */
00238 /*          supplied in the array Z; if RANGE = 'V', the exact value of M */
00239 /*          is not known in advance and can be computed with a workspace */
00240 /*          query by setting NZC = -1, see below. */
00241 
00242 /*  LDZ     (input) INTEGER */
00243 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
00244 /*          JOBZ = 'V', then LDZ >= max(1,N). */
00245 
00246 /*  NZC     (input) INTEGER */
00247 /*          The number of eigenvectors to be held in the array Z. */
00248 /*          If RANGE = 'A', then NZC >= max(1,N). */
00249 /*          If RANGE = 'V', then NZC >= the number of eigenvalues in (VL,VU]. */
00250 /*          If RANGE = 'I', then NZC >= IU-IL+1. */
00251 /*          If NZC = -1, then a workspace query is assumed; the */
00252 /*          routine calculates the number of columns of the array Z that */
00253 /*          are needed to hold the eigenvectors. */
00254 /*          This value is returned as the first entry of the Z array, and */
00255 /*          no error message related to NZC is issued by XERBLA. */
00256 
00257 /*  ISUPPZ  (output) INTEGER ARRAY, dimension ( 2*max(1,M) ) */
00258 /*          The support of the eigenvectors in Z, i.e., the indices */
00259 /*          indicating the nonzero elements in Z. The i-th computed eigenvector */
00260 /*          is nonzero only in elements ISUPPZ( 2*i-1 ) through */
00261 /*          ISUPPZ( 2*i ). This is relevant in the case when the matrix */
00262 /*          is split. ISUPPZ is only accessed when JOBZ is 'V' and N > 0. */
00263 
00264 /*  TRYRAC  (input/output) LOGICAL */
00265 /*          If TRYRAC.EQ..TRUE., indicates that the code should check whether */
00266 /*          the tridiagonal matrix defines its eigenvalues to high relative */
00267 /*          accuracy.  If so, the code uses relative-accuracy preserving */
00268 /*          algorithms that might be (a bit) slower depending on the matrix. */
00269 /*          If the matrix does not define its eigenvalues to high relative */
00270 /*          accuracy, the code can uses possibly faster algorithms. */
00271 /*          If TRYRAC.EQ..FALSE., the code is not required to guarantee */
00272 /*          relatively accurate eigenvalues and can use the fastest possible */
00273 /*          techniques. */
00274 /*          On exit, a .TRUE. TRYRAC will be set to .FALSE. if the matrix */
00275 /*          does not define its eigenvalues to high relative accuracy. */
00276 
00277 /*  WORK    (workspace/output) DOUBLE PRECISION array, dimension (LWORK) */
00278 /*          On exit, if INFO = 0, WORK(1) returns the optimal */
00279 /*          (and minimal) LWORK. */
00280 
00281 /*  LWORK   (input) INTEGER */
00282 /*          The dimension of the array WORK. LWORK >= max(1,18*N) */
00283 /*          if JOBZ = 'V', and LWORK >= max(1,12*N) if JOBZ = 'N'. */
00284 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00285 /*          only calculates the optimal size of the WORK array, returns */
00286 /*          this value as the first entry of the WORK array, and no error */
00287 /*          message related to LWORK is issued by XERBLA. */
00288 
00289 /*  IWORK   (workspace/output) INTEGER array, dimension (LIWORK) */
00290 /*          On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
00291 
00292 /*  LIWORK  (input) INTEGER */
00293 /*          The dimension of the array IWORK.  LIWORK >= max(1,10*N) */
00294 /*          if the eigenvectors are desired, and LIWORK >= max(1,8*N) */
00295 /*          if only the eigenvalues are to be computed. */
00296 /*          If LIWORK = -1, then a workspace query is assumed; the */
00297 /*          routine only calculates the optimal size of the IWORK array, */
00298 /*          returns this value as the first entry of the IWORK array, and */
00299 /*          no error message related to LIWORK is issued by XERBLA. */
00300 
00301 /*  INFO    (output) INTEGER */
00302 /*          On exit, INFO */
00303 /*          = 0:  successful exit */
00304 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00305 /*          > 0:  if INFO = 1X, internal error in DLARRE, */
00306 /*                if INFO = 2X, internal error in ZLARRV. */
00307 /*                Here, the digit X = ABS( IINFO ) < 10, where IINFO is */
00308 /*                the nonzero error code returned by DLARRE or */
00309 /*                ZLARRV, respectively. */
00310 
00311 
00312 /*  Further Details */
00313 /*  =============== */
00314 
00315 /*  Based on contributions by */
00316 /*     Beresford Parlett, University of California, Berkeley, USA */
00317 /*     Jim Demmel, University of California, Berkeley, USA */
00318 /*     Inderjit Dhillon, University of Texas, Austin, USA */
00319 /*     Osni Marques, LBNL/NERSC, USA */
00320 /*     Christof Voemel, University of California, Berkeley, USA */
00321 
00322 /*  ===================================================================== */
00323 
00324 /*     .. Parameters .. */
00325 /*     .. */
00326 /*     .. Local Scalars .. */
00327 /*     .. */
00328 /*     .. */
00329 /*     .. External Functions .. */
00330 /*     .. */
00331 /*     .. External Subroutines .. */
00332 /*     .. */
00333 /*     .. Intrinsic Functions .. */
00334 /*     .. */
00335 /*     .. Executable Statements .. */
00336 
00337 /*     Test the input parameters. */
00338 
00339     /* Parameter adjustments */
00340     --d__;
00341     --e;
00342     --w;
00343     z_dim1 = *ldz;
00344     z_offset = 1 + z_dim1;
00345     z__ -= z_offset;
00346     --isuppz;
00347     --work;
00348     --iwork;
00349 
00350     /* Function Body */
00351     wantz = lsame_(jobz, "V");
00352     alleig = lsame_(range, "A");
00353     valeig = lsame_(range, "V");
00354     indeig = lsame_(range, "I");
00355 
00356     lquery = *lwork == -1 || *liwork == -1;
00357     zquery = *nzc == -1;
00358 /*     DSTEMR needs WORK of size 6*N, IWORK of size 3*N. */
00359 /*     In addition, DLARRE needs WORK of size 6*N, IWORK of size 5*N. */
00360 /*     Furthermore, ZLARRV needs WORK of size 12*N, IWORK of size 7*N. */
00361     if (wantz) {
00362         lwmin = *n * 18;
00363         liwmin = *n * 10;
00364     } else {
00365 /*        need less workspace if only the eigenvalues are wanted */
00366         lwmin = *n * 12;
00367         liwmin = *n << 3;
00368     }
00369     wl = 0.;
00370     wu = 0.;
00371     iil = 0;
00372     iiu = 0;
00373     if (valeig) {
00374 /*        We do not reference VL, VU in the cases RANGE = 'I','A' */
00375 /*        The interval (WL, WU] contains all the wanted eigenvalues. */
00376 /*        It is either given by the user or computed in DLARRE. */
00377         wl = *vl;
00378         wu = *vu;
00379     } else if (indeig) {
00380 /*        We do not reference IL, IU in the cases RANGE = 'V','A' */
00381         iil = *il;
00382         iiu = *iu;
00383     }
00384 
00385     *info = 0;
00386     if (! (wantz || lsame_(jobz, "N"))) {
00387         *info = -1;
00388     } else if (! (alleig || valeig || indeig)) {
00389         *info = -2;
00390     } else if (*n < 0) {
00391         *info = -3;
00392     } else if (valeig && *n > 0 && wu <= wl) {
00393         *info = -7;
00394     } else if (indeig && (iil < 1 || iil > *n)) {
00395         *info = -8;
00396     } else if (indeig && (iiu < iil || iiu > *n)) {
00397         *info = -9;
00398     } else if (*ldz < 1 || wantz && *ldz < *n) {
00399         *info = -13;
00400     } else if (*lwork < lwmin && ! lquery) {
00401         *info = -17;
00402     } else if (*liwork < liwmin && ! lquery) {
00403         *info = -19;
00404     }
00405 
00406 /*     Get machine constants. */
00407 
00408     safmin = dlamch_("Safe minimum");
00409     eps = dlamch_("Precision");
00410     smlnum = safmin / eps;
00411     bignum = 1. / smlnum;
00412     rmin = sqrt(smlnum);
00413 /* Computing MIN */
00414     d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin));
00415     rmax = min(d__1,d__2);
00416 
00417     if (*info == 0) {
00418         work[1] = (doublereal) lwmin;
00419         iwork[1] = liwmin;
00420 
00421         if (wantz && alleig) {
00422             nzcmin = *n;
00423         } else if (wantz && valeig) {
00424             dlarrc_("T", n, vl, vu, &d__[1], &e[1], &safmin, &nzcmin, &itmp, &
00425                     itmp2, info);
00426         } else if (wantz && indeig) {
00427             nzcmin = iiu - iil + 1;
00428         } else {
00429 /*           WANTZ .EQ. FALSE. */
00430             nzcmin = 0;
00431         }
00432         if (zquery && *info == 0) {
00433             i__1 = z_dim1 + 1;
00434             z__[i__1].r = (doublereal) nzcmin, z__[i__1].i = 0.;
00435         } else if (*nzc < nzcmin && ! zquery) {
00436             *info = -14;
00437         }
00438     }
00439     if (*info != 0) {
00440 
00441         i__1 = -(*info);
00442         xerbla_("ZSTEMR", &i__1);
00443 
00444         return 0;
00445     } else if (lquery || zquery) {
00446         return 0;
00447     }
00448 
00449 /*     Handle N = 0, 1, and 2 cases immediately */
00450 
00451     *m = 0;
00452     if (*n == 0) {
00453         return 0;
00454     }
00455 
00456     if (*n == 1) {
00457         if (alleig || indeig) {
00458             *m = 1;
00459             w[1] = d__[1];
00460         } else {
00461             if (wl < d__[1] && wu >= d__[1]) {
00462                 *m = 1;
00463                 w[1] = d__[1];
00464             }
00465         }
00466         if (wantz && ! zquery) {
00467             i__1 = z_dim1 + 1;
00468             z__[i__1].r = 1., z__[i__1].i = 0.;
00469             isuppz[1] = 1;
00470             isuppz[2] = 1;
00471         }
00472         return 0;
00473     }
00474 
00475     if (*n == 2) {
00476         if (! wantz) {
00477             dlae2_(&d__[1], &e[1], &d__[2], &r1, &r2);
00478         } else if (wantz && ! zquery) {
00479             dlaev2_(&d__[1], &e[1], &d__[2], &r1, &r2, &cs, &sn);
00480         }
00481         if (alleig || valeig && r2 > wl && r2 <= wu || indeig && iil == 1) {
00482             ++(*m);
00483             w[*m] = r2;
00484             if (wantz && ! zquery) {
00485                 i__1 = *m * z_dim1 + 1;
00486                 d__1 = -sn;
00487                 z__[i__1].r = d__1, z__[i__1].i = 0.;
00488                 i__1 = *m * z_dim1 + 2;
00489                 z__[i__1].r = cs, z__[i__1].i = 0.;
00490 /*              Note: At most one of SN and CS can be zero. */
00491                 if (sn != 0.) {
00492                     if (cs != 0.) {
00493                         isuppz[(*m << 1) - 1] = 1;
00494                         isuppz[(*m << 1) - 1] = 2;
00495                     } else {
00496                         isuppz[(*m << 1) - 1] = 1;
00497                         isuppz[(*m << 1) - 1] = 1;
00498                     }
00499                 } else {
00500                     isuppz[(*m << 1) - 1] = 2;
00501                     isuppz[*m * 2] = 2;
00502                 }
00503             }
00504         }
00505         if (alleig || valeig && r1 > wl && r1 <= wu || indeig && iiu == 2) {
00506             ++(*m);
00507             w[*m] = r1;
00508             if (wantz && ! zquery) {
00509                 i__1 = *m * z_dim1 + 1;
00510                 z__[i__1].r = cs, z__[i__1].i = 0.;
00511                 i__1 = *m * z_dim1 + 2;
00512                 z__[i__1].r = sn, z__[i__1].i = 0.;
00513 /*              Note: At most one of SN and CS can be zero. */
00514                 if (sn != 0.) {
00515                     if (cs != 0.) {
00516                         isuppz[(*m << 1) - 1] = 1;
00517                         isuppz[(*m << 1) - 1] = 2;
00518                     } else {
00519                         isuppz[(*m << 1) - 1] = 1;
00520                         isuppz[(*m << 1) - 1] = 1;
00521                     }
00522                 } else {
00523                     isuppz[(*m << 1) - 1] = 2;
00524                     isuppz[*m * 2] = 2;
00525                 }
00526             }
00527         }
00528         return 0;
00529     }
00530 /*     Continue with general N */
00531     indgrs = 1;
00532     inderr = (*n << 1) + 1;
00533     indgp = *n * 3 + 1;
00534     indd = (*n << 2) + 1;
00535     inde2 = *n * 5 + 1;
00536     indwrk = *n * 6 + 1;
00537 
00538     iinspl = 1;
00539     iindbl = *n + 1;
00540     iindw = (*n << 1) + 1;
00541     iindwk = *n * 3 + 1;
00542 
00543 /*     Scale matrix to allowable range, if necessary. */
00544 /*     The allowable range is related to the PIVMIN parameter; see the */
00545 /*     comments in DLARRD.  The preference for scaling small values */
00546 /*     up is heuristic; we expect users' matrices not to be close to the */
00547 /*     RMAX threshold. */
00548 
00549     scale = 1.;
00550     tnrm = dlanst_("M", n, &d__[1], &e[1]);
00551     if (tnrm > 0. && tnrm < rmin) {
00552         scale = rmin / tnrm;
00553     } else if (tnrm > rmax) {
00554         scale = rmax / tnrm;
00555     }
00556     if (scale != 1.) {
00557         dscal_(n, &scale, &d__[1], &c__1);
00558         i__1 = *n - 1;
00559         dscal_(&i__1, &scale, &e[1], &c__1);
00560         tnrm *= scale;
00561         if (valeig) {
00562 /*           If eigenvalues in interval have to be found, */
00563 /*           scale (WL, WU] accordingly */
00564             wl *= scale;
00565             wu *= scale;
00566         }
00567     }
00568 
00569 /*     Compute the desired eigenvalues of the tridiagonal after splitting */
00570 /*     into smaller subblocks if the corresponding off-diagonal elements */
00571 /*     are small */
00572 /*     THRESH is the splitting parameter for DLARRE */
00573 /*     A negative THRESH forces the old splitting criterion based on the */
00574 /*     size of the off-diagonal. A positive THRESH switches to splitting */
00575 /*     which preserves relative accuracy. */
00576 
00577     if (*tryrac) {
00578 /*        Test whether the matrix warrants the more expensive relative approach. */
00579         dlarrr_(n, &d__[1], &e[1], &iinfo);
00580     } else {
00581 /*        The user does not care about relative accurately eigenvalues */
00582         iinfo = -1;
00583     }
00584 /*     Set the splitting criterion */
00585     if (iinfo == 0) {
00586         thresh = eps;
00587     } else {
00588         thresh = -eps;
00589 /*        relative accuracy is desired but T does not guarantee it */
00590         *tryrac = FALSE_;
00591     }
00592 
00593     if (*tryrac) {
00594 /*        Copy original diagonal, needed to guarantee relative accuracy */
00595         dcopy_(n, &d__[1], &c__1, &work[indd], &c__1);
00596     }
00597 /*     Store the squares of the offdiagonal values of T */
00598     i__1 = *n - 1;
00599     for (j = 1; j <= i__1; ++j) {
00600 /* Computing 2nd power */
00601         d__1 = e[j];
00602         work[inde2 + j - 1] = d__1 * d__1;
00603 /* L5: */
00604     }
00605 /*     Set the tolerance parameters for bisection */
00606     if (! wantz) {
00607 /*        DLARRE computes the eigenvalues to full precision. */
00608         rtol1 = eps * 4.;
00609         rtol2 = eps * 4.;
00610     } else {
00611 /*        DLARRE computes the eigenvalues to less than full precision. */
00612 /*        ZLARRV will refine the eigenvalue approximations, and we only */
00613 /*        need less accurate initial bisection in DLARRE. */
00614 /*        Note: these settings do only affect the subset case and DLARRE */
00615         rtol1 = sqrt(eps);
00616 /* Computing MAX */
00617         d__1 = sqrt(eps) * .005, d__2 = eps * 4.;
00618         rtol2 = max(d__1,d__2);
00619     }
00620     dlarre_(range, n, &wl, &wu, &iil, &iiu, &d__[1], &e[1], &work[inde2], &
00621             rtol1, &rtol2, &thresh, &nsplit, &iwork[iinspl], m, &w[1], &work[
00622             inderr], &work[indgp], &iwork[iindbl], &iwork[iindw], &work[
00623             indgrs], &pivmin, &work[indwrk], &iwork[iindwk], &iinfo);
00624     if (iinfo != 0) {
00625         *info = abs(iinfo) + 10;
00626         return 0;
00627     }
00628 /*     Note that if RANGE .NE. 'V', DLARRE computes bounds on the desired */
00629 /*     part of the spectrum. All desired eigenvalues are contained in */
00630 /*     (WL,WU] */
00631     if (wantz) {
00632 
00633 /*        Compute the desired eigenvectors corresponding to the computed */
00634 /*        eigenvalues */
00635 
00636         zlarrv_(n, &wl, &wu, &d__[1], &e[1], &pivmin, &iwork[iinspl], m, &
00637                 c__1, m, &c_b18, &rtol1, &rtol2, &w[1], &work[inderr], &work[
00638                 indgp], &iwork[iindbl], &iwork[iindw], &work[indgrs], &z__[
00639                 z_offset], ldz, &isuppz[1], &work[indwrk], &iwork[iindwk], &
00640                 iinfo);
00641         if (iinfo != 0) {
00642             *info = abs(iinfo) + 20;
00643             return 0;
00644         }
00645     } else {
00646 /*        DLARRE computes eigenvalues of the (shifted) root representation */
00647 /*        ZLARRV returns the eigenvalues of the unshifted matrix. */
00648 /*        However, if the eigenvectors are not desired by the user, we need */
00649 /*        to apply the corresponding shifts from DLARRE to obtain the */
00650 /*        eigenvalues of the original matrix. */
00651         i__1 = *m;
00652         for (j = 1; j <= i__1; ++j) {
00653             itmp = iwork[iindbl + j - 1];
00654             w[j] += e[iwork[iinspl + itmp - 1]];
00655 /* L20: */
00656         }
00657     }
00658 
00659     if (*tryrac) {
00660 /*        Refine computed eigenvalues so that they are relatively accurate */
00661 /*        with respect to the original matrix T. */
00662         ibegin = 1;
00663         wbegin = 1;
00664         i__1 = iwork[iindbl + *m - 1];
00665         for (jblk = 1; jblk <= i__1; ++jblk) {
00666             iend = iwork[iinspl + jblk - 1];
00667             in = iend - ibegin + 1;
00668             wend = wbegin - 1;
00669 /*           check if any eigenvalues have to be refined in this block */
00670 L36:
00671             if (wend < *m) {
00672                 if (iwork[iindbl + wend] == jblk) {
00673                     ++wend;
00674                     goto L36;
00675                 }
00676             }
00677             if (wend < wbegin) {
00678                 ibegin = iend + 1;
00679                 goto L39;
00680             }
00681             offset = iwork[iindw + wbegin - 1] - 1;
00682             ifirst = iwork[iindw + wbegin - 1];
00683             ilast = iwork[iindw + wend - 1];
00684             rtol2 = eps * 4.;
00685             dlarrj_(&in, &work[indd + ibegin - 1], &work[inde2 + ibegin - 1], 
00686                     &ifirst, &ilast, &rtol2, &offset, &w[wbegin], &work[
00687                     inderr + wbegin - 1], &work[indwrk], &iwork[iindwk], &
00688                     pivmin, &tnrm, &iinfo);
00689             ibegin = iend + 1;
00690             wbegin = wend + 1;
00691 L39:
00692             ;
00693         }
00694     }
00695 
00696 /*     If matrix was scaled, then rescale eigenvalues appropriately. */
00697 
00698     if (scale != 1.) {
00699         d__1 = 1. / scale;
00700         dscal_(m, &d__1, &w[1], &c__1);
00701     }
00702 
00703 /*     If eigenvalues are not in increasing order, then sort them, */
00704 /*     possibly along with eigenvectors. */
00705 
00706     if (nsplit > 1) {
00707         if (! wantz) {
00708             dlasrt_("I", m, &w[1], &iinfo);
00709             if (iinfo != 0) {
00710                 *info = 3;
00711                 return 0;
00712             }
00713         } else {
00714             i__1 = *m - 1;
00715             for (j = 1; j <= i__1; ++j) {
00716                 i__ = 0;
00717                 tmp = w[j];
00718                 i__2 = *m;
00719                 for (jj = j + 1; jj <= i__2; ++jj) {
00720                     if (w[jj] < tmp) {
00721                         i__ = jj;
00722                         tmp = w[jj];
00723                     }
00724 /* L50: */
00725                 }
00726                 if (i__ != 0) {
00727                     w[i__] = w[j];
00728                     w[j] = tmp;
00729                     if (wantz) {
00730                         zswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * 
00731                                 z_dim1 + 1], &c__1);
00732                         itmp = isuppz[(i__ << 1) - 1];
00733                         isuppz[(i__ << 1) - 1] = isuppz[(j << 1) - 1];
00734                         isuppz[(j << 1) - 1] = itmp;
00735                         itmp = isuppz[i__ * 2];
00736                         isuppz[i__ * 2] = isuppz[j * 2];
00737                         isuppz[j * 2] = itmp;
00738                     }
00739                 }
00740 /* L60: */
00741             }
00742         }
00743     }
00744 
00745 
00746     work[1] = (doublereal) lwmin;
00747     iwork[1] = liwmin;
00748     return 0;
00749 
00750 /*     End of ZSTEMR */
00751 
00752 } /* zstemr_ */


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