dstevr.c
Go to the documentation of this file.
00001 /* dstevr.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__10 = 10;
00019 static integer c__1 = 1;
00020 static integer c__2 = 2;
00021 static integer c__3 = 3;
00022 static integer c__4 = 4;
00023 
00024 /* Subroutine */ int dstevr_(char *jobz, char *range, integer *n, doublereal *
00025         d__, doublereal *e, doublereal *vl, doublereal *vu, integer *il, 
00026         integer *iu, doublereal *abstol, integer *m, doublereal *w, 
00027         doublereal *z__, integer *ldz, integer *isuppz, doublereal *work, 
00028         integer *lwork, integer *iwork, integer *liwork, integer *info)
00029 {
00030     /* System generated locals */
00031     integer z_dim1, z_offset, i__1, i__2;
00032     doublereal d__1, d__2;
00033 
00034     /* Builtin functions */
00035     double sqrt(doublereal);
00036 
00037     /* Local variables */
00038     integer i__, j, jj;
00039     doublereal eps, vll, vuu, tmp1;
00040     integer imax;
00041     doublereal rmin, rmax;
00042     logical test;
00043     doublereal tnrm;
00044     integer itmp1;
00045     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
00046             integer *);
00047     doublereal sigma;
00048     extern logical lsame_(char *, char *);
00049     char order[1];
00050     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, 
00051             doublereal *, integer *), dswap_(integer *, doublereal *, integer 
00052             *, doublereal *, integer *);
00053     integer lwmin;
00054     logical wantz;
00055     extern doublereal dlamch_(char *);
00056     logical alleig, indeig;
00057     integer iscale, ieeeok, indibl, indifl;
00058     logical valeig;
00059     doublereal safmin;
00060     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00061             integer *, integer *);
00062     extern /* Subroutine */ int xerbla_(char *, integer *);
00063     doublereal bignum;
00064     extern doublereal dlanst_(char *, integer *, doublereal *, doublereal *);
00065     integer indisp;
00066     extern /* Subroutine */ int dstein_(integer *, doublereal *, doublereal *, 
00067              integer *, doublereal *, integer *, integer *, doublereal *, 
00068             integer *, doublereal *, integer *, integer *, integer *), 
00069             dsterf_(integer *, doublereal *, doublereal *, integer *);
00070     integer indiwo;
00071     extern /* Subroutine */ int dstebz_(char *, char *, integer *, doublereal 
00072             *, doublereal *, integer *, integer *, doublereal *, doublereal *, 
00073              doublereal *, integer *, integer *, doublereal *, integer *, 
00074             integer *, doublereal *, integer *, integer *), 
00075             dstemr_(char *, char *, integer *, doublereal *, doublereal *, 
00076             doublereal *, doublereal *, integer *, integer *, integer *, 
00077             doublereal *, doublereal *, integer *, integer *, integer *, 
00078             logical *, doublereal *, integer *, integer *, integer *, integer 
00079             *);
00080     integer liwmin;
00081     logical tryrac;
00082     integer nsplit;
00083     doublereal smlnum;
00084     logical lquery;
00085 
00086 
00087 /*  -- LAPACK driver routine (version 3.2) -- */
00088 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00089 /*     November 2006 */
00090 
00091 /*     .. Scalar Arguments .. */
00092 /*     .. */
00093 /*     .. Array Arguments .. */
00094 /*     .. */
00095 
00096 /*  Purpose */
00097 /*  ======= */
00098 
00099 /*  DSTEVR computes selected eigenvalues and, optionally, eigenvectors */
00100 /*  of a real symmetric tridiagonal matrix T.  Eigenvalues and */
00101 /*  eigenvectors can be selected by specifying either a range of values */
00102 /*  or a range of indices for the desired eigenvalues. */
00103 
00104 /*  Whenever possible, DSTEVR calls DSTEMR to compute the */
00105 /*  eigenspectrum using Relatively Robust Representations.  DSTEMR */
00106 /*  computes eigenvalues by the dqds algorithm, while orthogonal */
00107 /*  eigenvectors are computed from various "good" L D L^T representations */
00108 /*  (also known as Relatively Robust Representations). Gram-Schmidt */
00109 /*  orthogonalization is avoided as far as possible. More specifically, */
00110 /*  the various steps of the algorithm are as follows. For the i-th */
00111 /*  unreduced block of T, */
00112 /*     (a) Compute T - sigma_i = L_i D_i L_i^T, such that L_i D_i L_i^T */
00113 /*          is a relatively robust representation, */
00114 /*     (b) Compute the eigenvalues, lambda_j, of L_i D_i L_i^T to high */
00115 /*         relative accuracy by the dqds algorithm, */
00116 /*     (c) If there is a cluster of close eigenvalues, "choose" sigma_i */
00117 /*         close to the cluster, and go to step (a), */
00118 /*     (d) Given the approximate eigenvalue lambda_j of L_i D_i L_i^T, */
00119 /*         compute the corresponding eigenvector by forming a */
00120 /*         rank-revealing twisted factorization. */
00121 /*  The desired accuracy of the output can be specified by the input */
00122 /*  parameter ABSTOL. */
00123 
00124 /*  For more details, see "A new O(n^2) algorithm for the symmetric */
00125 /*  tridiagonal eigenvalue/eigenvector problem", by Inderjit Dhillon, */
00126 /*  Computer Science Division Technical Report No. UCB//CSD-97-971, */
00127 /*  UC Berkeley, May 1997. */
00128 
00129 
00130 /*  Note 1 : DSTEVR calls DSTEMR when the full spectrum is requested */
00131 /*  on machines which conform to the ieee-754 floating point standard. */
00132 /*  DSTEVR calls DSTEBZ and DSTEIN on non-ieee machines and */
00133 /*  when partial spectrum requests are made. */
00134 
00135 /*  Normal execution of DSTEMR may create NaNs and infinities and */
00136 /*  hence may abort due to a floating point exception in environments */
00137 /*  which do not handle NaNs and infinities in the ieee standard default */
00138 /*  manner. */
00139 
00140 /*  Arguments */
00141 /*  ========= */
00142 
00143 /*  JOBZ    (input) CHARACTER*1 */
00144 /*          = 'N':  Compute eigenvalues only; */
00145 /*          = 'V':  Compute eigenvalues and eigenvectors. */
00146 
00147 /*  RANGE   (input) CHARACTER*1 */
00148 /*          = 'A': all eigenvalues will be found. */
00149 /*          = 'V': all eigenvalues in the half-open interval (VL,VU] */
00150 /*                 will be found. */
00151 /*          = 'I': the IL-th through IU-th eigenvalues will be found. */
00152 /* ********* For RANGE = 'V' or 'I' and IU - IL < N - 1, DSTEBZ and */
00153 /* ********* DSTEIN are called */
00154 
00155 /*  N       (input) INTEGER */
00156 /*          The order of the matrix.  N >= 0. */
00157 
00158 /*  D       (input/output) DOUBLE PRECISION array, dimension (N) */
00159 /*          On entry, the n diagonal elements of the tridiagonal matrix */
00160 /*          A. */
00161 /*          On exit, D may be multiplied by a constant factor chosen */
00162 /*          to avoid over/underflow in computing the eigenvalues. */
00163 
00164 /*  E       (input/output) DOUBLE PRECISION array, dimension (max(1,N-1)) */
00165 /*          On entry, the (n-1) subdiagonal elements of the tridiagonal */
00166 /*          matrix A in elements 1 to N-1 of E. */
00167 /*          On exit, E may be multiplied by a constant factor chosen */
00168 /*          to avoid over/underflow in computing the eigenvalues. */
00169 
00170 /*  VL      (input) DOUBLE PRECISION */
00171 /*  VU      (input) DOUBLE PRECISION */
00172 /*          If RANGE='V', the lower and upper bounds of the interval to */
00173 /*          be searched for eigenvalues. VL < VU. */
00174 /*          Not referenced if RANGE = 'A' or 'I'. */
00175 
00176 /*  IL      (input) INTEGER */
00177 /*  IU      (input) INTEGER */
00178 /*          If RANGE='I', the indices (in ascending order) of the */
00179 /*          smallest and largest eigenvalues to be returned. */
00180 /*          1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
00181 /*          Not referenced if RANGE = 'A' or 'V'. */
00182 
00183 /*  ABSTOL  (input) DOUBLE PRECISION */
00184 /*          The absolute error tolerance for the eigenvalues. */
00185 /*          An approximate eigenvalue is accepted as converged */
00186 /*          when it is determined to lie in an interval [a,b] */
00187 /*          of width less than or equal to */
00188 
00189 /*                  ABSTOL + EPS *   max( |a|,|b| ) , */
00190 
00191 /*          where EPS is the machine precision.  If ABSTOL is less than */
00192 /*          or equal to zero, then  EPS*|T|  will be used in its place, */
00193 /*          where |T| is the 1-norm of the tridiagonal matrix obtained */
00194 /*          by reducing A to tridiagonal form. */
00195 
00196 /*          See "Computing Small Singular Values of Bidiagonal Matrices */
00197 /*          with Guaranteed High Relative Accuracy," by Demmel and */
00198 /*          Kahan, LAPACK Working Note #3. */
00199 
00200 /*          If high relative accuracy is important, set ABSTOL to */
00201 /*          DLAMCH( 'Safe minimum' ).  Doing so will guarantee that */
00202 /*          eigenvalues are computed to high relative accuracy when */
00203 /*          possible in future releases.  The current code does not */
00204 /*          make any guarantees about high relative accuracy, but */
00205 /*          future releases will. See J. Barlow and J. Demmel, */
00206 /*          "Computing Accurate Eigensystems of Scaled Diagonally */
00207 /*          Dominant Matrices", LAPACK Working Note #7, for a discussion */
00208 /*          of which matrices define their eigenvalues to high relative */
00209 /*          accuracy. */
00210 
00211 /*  M       (output) INTEGER */
00212 /*          The total number of eigenvalues found.  0 <= M <= N. */
00213 /*          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
00214 
00215 /*  W       (output) DOUBLE PRECISION array, dimension (N) */
00216 /*          The first M elements contain the selected eigenvalues in */
00217 /*          ascending order. */
00218 
00219 /*  Z       (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M) ) */
00220 /*          If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
00221 /*          contain the orthonormal eigenvectors of the matrix A */
00222 /*          corresponding to the selected eigenvalues, with the i-th */
00223 /*          column of Z holding the eigenvector associated with W(i). */
00224 /*          Note: the user must ensure that at least max(1,M) columns are */
00225 /*          supplied in the array Z; if RANGE = 'V', the exact value of M */
00226 /*          is not known in advance and an upper bound must be used. */
00227 
00228 /*  LDZ     (input) INTEGER */
00229 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
00230 /*          JOBZ = 'V', LDZ >= max(1,N). */
00231 
00232 /*  ISUPPZ  (output) INTEGER array, dimension ( 2*max(1,M) ) */
00233 /*          The support of the eigenvectors in Z, i.e., the indices */
00234 /*          indicating the nonzero elements in Z. The i-th eigenvector */
00235 /*          is nonzero only in elements ISUPPZ( 2*i-1 ) through */
00236 /*          ISUPPZ( 2*i ). */
00237 /* ********* Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1 */
00238 
00239 /*  WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
00240 /*          On exit, if INFO = 0, WORK(1) returns the optimal (and */
00241 /*          minimal) LWORK. */
00242 
00243 /*  LWORK   (input) INTEGER */
00244 /*          The dimension of the array WORK.  LWORK >= max(1,20*N). */
00245 
00246 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00247 /*          only calculates the optimal sizes of the WORK and IWORK */
00248 /*          arrays, returns these values as the first entries of the WORK */
00249 /*          and IWORK arrays, and no error message related to LWORK or */
00250 /*          LIWORK is issued by XERBLA. */
00251 
00252 /*  IWORK   (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */
00253 /*          On exit, if INFO = 0, IWORK(1) returns the optimal (and */
00254 /*          minimal) LIWORK. */
00255 
00256 /*  LIWORK  (input) INTEGER */
00257 /*          The dimension of the array IWORK.  LIWORK >= max(1,10*N). */
00258 
00259 /*          If LIWORK = -1, then a workspace query is assumed; the */
00260 /*          routine only calculates the optimal sizes of the WORK and */
00261 /*          IWORK arrays, returns these values as the first entries of */
00262 /*          the WORK and IWORK arrays, and no error message related to */
00263 /*          LWORK or LIWORK is issued by XERBLA. */
00264 
00265 /*  INFO    (output) INTEGER */
00266 /*          = 0:  successful exit */
00267 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00268 /*          > 0:  Internal error */
00269 
00270 /*  Further Details */
00271 /*  =============== */
00272 
00273 /*  Based on contributions by */
00274 /*     Inderjit Dhillon, IBM Almaden, USA */
00275 /*     Osni Marques, LBNL/NERSC, USA */
00276 /*     Ken Stanley, Computer Science Division, University of */
00277 /*       California at Berkeley, USA */
00278 
00279 /*  ===================================================================== */
00280 
00281 /*     .. Parameters .. */
00282 /*     .. */
00283 /*     .. Local Scalars .. */
00284 /*     .. */
00285 /*     .. External Functions .. */
00286 /*     .. */
00287 /*     .. External Subroutines .. */
00288 /*     .. */
00289 /*     .. Intrinsic Functions .. */
00290 /*     .. */
00291 /*     .. Executable Statements .. */
00292 
00293 
00294 /*     Test the input parameters. */
00295 
00296     /* Parameter adjustments */
00297     --d__;
00298     --e;
00299     --w;
00300     z_dim1 = *ldz;
00301     z_offset = 1 + z_dim1;
00302     z__ -= z_offset;
00303     --isuppz;
00304     --work;
00305     --iwork;
00306 
00307     /* Function Body */
00308     ieeeok = ilaenv_(&c__10, "DSTEVR", "N", &c__1, &c__2, &c__3, &c__4);
00309 
00310     wantz = lsame_(jobz, "V");
00311     alleig = lsame_(range, "A");
00312     valeig = lsame_(range, "V");
00313     indeig = lsame_(range, "I");
00314 
00315     lquery = *lwork == -1 || *liwork == -1;
00316 /* Computing MAX */
00317     i__1 = 1, i__2 = *n * 20;
00318     lwmin = max(i__1,i__2);
00319 /* Computing MAX */
00320     i__1 = 1, i__2 = *n * 10;
00321     liwmin = max(i__1,i__2);
00322 
00323 
00324     *info = 0;
00325     if (! (wantz || lsame_(jobz, "N"))) {
00326         *info = -1;
00327     } else if (! (alleig || valeig || indeig)) {
00328         *info = -2;
00329     } else if (*n < 0) {
00330         *info = -3;
00331     } else {
00332         if (valeig) {
00333             if (*n > 0 && *vu <= *vl) {
00334                 *info = -7;
00335             }
00336         } else if (indeig) {
00337             if (*il < 1 || *il > max(1,*n)) {
00338                 *info = -8;
00339             } else if (*iu < min(*n,*il) || *iu > *n) {
00340                 *info = -9;
00341             }
00342         }
00343     }
00344     if (*info == 0) {
00345         if (*ldz < 1 || wantz && *ldz < *n) {
00346             *info = -14;
00347         }
00348     }
00349 
00350     if (*info == 0) {
00351         work[1] = (doublereal) lwmin;
00352         iwork[1] = liwmin;
00353 
00354         if (*lwork < lwmin && ! lquery) {
00355             *info = -17;
00356         } else if (*liwork < liwmin && ! lquery) {
00357             *info = -19;
00358         }
00359     }
00360 
00361     if (*info != 0) {
00362         i__1 = -(*info);
00363         xerbla_("DSTEVR", &i__1);
00364         return 0;
00365     } else if (lquery) {
00366         return 0;
00367     }
00368 
00369 /*     Quick return if possible */
00370 
00371     *m = 0;
00372     if (*n == 0) {
00373         return 0;
00374     }
00375 
00376     if (*n == 1) {
00377         if (alleig || indeig) {
00378             *m = 1;
00379             w[1] = d__[1];
00380         } else {
00381             if (*vl < d__[1] && *vu >= d__[1]) {
00382                 *m = 1;
00383                 w[1] = d__[1];
00384             }
00385         }
00386         if (wantz) {
00387             z__[z_dim1 + 1] = 1.;
00388         }
00389         return 0;
00390     }
00391 
00392 /*     Get machine constants. */
00393 
00394     safmin = dlamch_("Safe minimum");
00395     eps = dlamch_("Precision");
00396     smlnum = safmin / eps;
00397     bignum = 1. / smlnum;
00398     rmin = sqrt(smlnum);
00399 /* Computing MIN */
00400     d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin));
00401     rmax = min(d__1,d__2);
00402 
00403 
00404 /*     Scale matrix to allowable range, if necessary. */
00405 
00406     iscale = 0;
00407     vll = *vl;
00408     vuu = *vu;
00409 
00410     tnrm = dlanst_("M", n, &d__[1], &e[1]);
00411     if (tnrm > 0. && tnrm < rmin) {
00412         iscale = 1;
00413         sigma = rmin / tnrm;
00414     } else if (tnrm > rmax) {
00415         iscale = 1;
00416         sigma = rmax / tnrm;
00417     }
00418     if (iscale == 1) {
00419         dscal_(n, &sigma, &d__[1], &c__1);
00420         i__1 = *n - 1;
00421         dscal_(&i__1, &sigma, &e[1], &c__1);
00422         if (valeig) {
00423             vll = *vl * sigma;
00424             vuu = *vu * sigma;
00425         }
00426     }
00427 /*     Initialize indices into workspaces.  Note: These indices are used only */
00428 /*     if DSTERF or DSTEMR fail. */
00429 /*     IWORK(INDIBL:INDIBL+M-1) corresponds to IBLOCK in DSTEBZ and */
00430 /*     stores the block indices of each of the M<=N eigenvalues. */
00431     indibl = 1;
00432 /*     IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in DSTEBZ and */
00433 /*     stores the starting and finishing indices of each block. */
00434     indisp = indibl + *n;
00435 /*     IWORK(INDIFL:INDIFL+N-1) stores the indices of eigenvectors */
00436 /*     that corresponding to eigenvectors that fail to converge in */
00437 /*     DSTEIN.  This information is discarded; if any fail, the driver */
00438 /*     returns INFO > 0. */
00439     indifl = indisp + *n;
00440 /*     INDIWO is the offset of the remaining integer workspace. */
00441     indiwo = indisp + *n;
00442 
00443 /*     If all eigenvalues are desired, then */
00444 /*     call DSTERF or DSTEMR.  If this fails for some eigenvalue, then */
00445 /*     try DSTEBZ. */
00446 
00447 
00448     test = FALSE_;
00449     if (indeig) {
00450         if (*il == 1 && *iu == *n) {
00451             test = TRUE_;
00452         }
00453     }
00454     if ((alleig || test) && ieeeok == 1) {
00455         i__1 = *n - 1;
00456         dcopy_(&i__1, &e[1], &c__1, &work[1], &c__1);
00457         if (! wantz) {
00458             dcopy_(n, &d__[1], &c__1, &w[1], &c__1);
00459             dsterf_(n, &w[1], &work[1], info);
00460         } else {
00461             dcopy_(n, &d__[1], &c__1, &work[*n + 1], &c__1);
00462             if (*abstol <= *n * 2. * eps) {
00463                 tryrac = TRUE_;
00464             } else {
00465                 tryrac = FALSE_;
00466             }
00467             i__1 = *lwork - (*n << 1);
00468             dstemr_(jobz, "A", n, &work[*n + 1], &work[1], vl, vu, il, iu, m, 
00469                     &w[1], &z__[z_offset], ldz, n, &isuppz[1], &tryrac, &work[
00470                     (*n << 1) + 1], &i__1, &iwork[1], liwork, info);
00471 
00472         }
00473         if (*info == 0) {
00474             *m = *n;
00475             goto L10;
00476         }
00477         *info = 0;
00478     }
00479 
00480 /*     Otherwise, call DSTEBZ and, if eigenvectors are desired, DSTEIN. */
00481 
00482     if (wantz) {
00483         *(unsigned char *)order = 'B';
00484     } else {
00485         *(unsigned char *)order = 'E';
00486     }
00487     dstebz_(range, order, n, &vll, &vuu, il, iu, abstol, &d__[1], &e[1], m, &
00488             nsplit, &w[1], &iwork[indibl], &iwork[indisp], &work[1], &iwork[
00489             indiwo], info);
00490 
00491     if (wantz) {
00492         dstein_(n, &d__[1], &e[1], m, &w[1], &iwork[indibl], &iwork[indisp], &
00493                 z__[z_offset], ldz, &work[1], &iwork[indiwo], &iwork[indifl], 
00494                 info);
00495     }
00496 
00497 /*     If matrix was scaled, then rescale eigenvalues appropriately. */
00498 
00499 L10:
00500     if (iscale == 1) {
00501         if (*info == 0) {
00502             imax = *m;
00503         } else {
00504             imax = *info - 1;
00505         }
00506         d__1 = 1. / sigma;
00507         dscal_(&imax, &d__1, &w[1], &c__1);
00508     }
00509 
00510 /*     If eigenvalues are not in order, then sort them, along with */
00511 /*     eigenvectors. */
00512 
00513     if (wantz) {
00514         i__1 = *m - 1;
00515         for (j = 1; j <= i__1; ++j) {
00516             i__ = 0;
00517             tmp1 = w[j];
00518             i__2 = *m;
00519             for (jj = j + 1; jj <= i__2; ++jj) {
00520                 if (w[jj] < tmp1) {
00521                     i__ = jj;
00522                     tmp1 = w[jj];
00523                 }
00524 /* L20: */
00525             }
00526 
00527             if (i__ != 0) {
00528                 itmp1 = iwork[i__];
00529                 w[i__] = w[j];
00530                 iwork[i__] = iwork[j];
00531                 w[j] = tmp1;
00532                 iwork[j] = itmp1;
00533                 dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1], 
00534                          &c__1);
00535             }
00536 /* L30: */
00537         }
00538     }
00539 
00540 /*      Causes problems with tests 19 & 20: */
00541 /*      IF (wantz .and. INDEIG ) Z( 1,1) = Z(1,1) / 1.002 + .002 */
00542 
00543 
00544     work[1] = (doublereal) lwmin;
00545     iwork[1] = liwmin;
00546     return 0;
00547 
00548 /*     End of DSTEVR */
00549 
00550 } /* dstevr_ */


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