dstevx.c
Go to the documentation of this file.
00001 /* dstevx.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 
00020 /* Subroutine */ int dstevx_(char *jobz, char *range, integer *n, doublereal *
00021         d__, doublereal *e, doublereal *vl, doublereal *vu, integer *il, 
00022         integer *iu, doublereal *abstol, integer *m, doublereal *w, 
00023         doublereal *z__, integer *ldz, doublereal *work, integer *iwork, 
00024         integer *ifail, integer *info)
00025 {
00026     /* System generated locals */
00027     integer z_dim1, z_offset, i__1, i__2;
00028     doublereal d__1, d__2;
00029 
00030     /* Builtin functions */
00031     double sqrt(doublereal);
00032 
00033     /* Local variables */
00034     integer i__, j, jj;
00035     doublereal eps, vll, vuu, tmp1;
00036     integer imax;
00037     doublereal rmin, rmax;
00038     logical test;
00039     doublereal tnrm;
00040     integer itmp1;
00041     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
00042             integer *);
00043     doublereal sigma;
00044     extern logical lsame_(char *, char *);
00045     char order[1];
00046     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, 
00047             doublereal *, integer *), dswap_(integer *, doublereal *, integer 
00048             *, doublereal *, integer *);
00049     logical wantz;
00050     extern doublereal dlamch_(char *);
00051     logical alleig, indeig;
00052     integer iscale, indibl;
00053     logical valeig;
00054     doublereal safmin;
00055     extern /* Subroutine */ int xerbla_(char *, integer *);
00056     doublereal bignum;
00057     extern doublereal dlanst_(char *, integer *, doublereal *, doublereal *);
00058     integer indisp;
00059     extern /* Subroutine */ int dstein_(integer *, doublereal *, doublereal *, 
00060              integer *, doublereal *, integer *, integer *, doublereal *, 
00061             integer *, doublereal *, integer *, integer *, integer *), 
00062             dsterf_(integer *, doublereal *, doublereal *, integer *);
00063     integer indiwo;
00064     extern /* Subroutine */ int dstebz_(char *, char *, integer *, doublereal 
00065             *, doublereal *, integer *, integer *, doublereal *, doublereal *, 
00066              doublereal *, integer *, integer *, doublereal *, integer *, 
00067             integer *, doublereal *, integer *, integer *);
00068     integer indwrk;
00069     extern /* Subroutine */ int dsteqr_(char *, integer *, doublereal *, 
00070             doublereal *, doublereal *, integer *, doublereal *, integer *);
00071     integer nsplit;
00072     doublereal smlnum;
00073 
00074 
00075 /*  -- LAPACK driver routine (version 3.2) -- */
00076 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00077 /*     November 2006 */
00078 
00079 /*     .. Scalar Arguments .. */
00080 /*     .. */
00081 /*     .. Array Arguments .. */
00082 /*     .. */
00083 
00084 /*  Purpose */
00085 /*  ======= */
00086 
00087 /*  DSTEVX computes selected eigenvalues and, optionally, eigenvectors */
00088 /*  of a real symmetric tridiagonal matrix A.  Eigenvalues and */
00089 /*  eigenvectors can be selected by specifying either a range of values */
00090 /*  or a range of indices for the desired eigenvalues. */
00091 
00092 /*  Arguments */
00093 /*  ========= */
00094 
00095 /*  JOBZ    (input) CHARACTER*1 */
00096 /*          = 'N':  Compute eigenvalues only; */
00097 /*          = 'V':  Compute eigenvalues and eigenvectors. */
00098 
00099 /*  RANGE   (input) CHARACTER*1 */
00100 /*          = 'A': all eigenvalues will be found. */
00101 /*          = 'V': all eigenvalues in the half-open interval (VL,VU] */
00102 /*                 will be found. */
00103 /*          = 'I': the IL-th through IU-th eigenvalues will be found. */
00104 
00105 /*  N       (input) INTEGER */
00106 /*          The order of the matrix.  N >= 0. */
00107 
00108 /*  D       (input/output) DOUBLE PRECISION array, dimension (N) */
00109 /*          On entry, the n diagonal elements of the tridiagonal matrix */
00110 /*          A. */
00111 /*          On exit, D may be multiplied by a constant factor chosen */
00112 /*          to avoid over/underflow in computing the eigenvalues. */
00113 
00114 /*  E       (input/output) DOUBLE PRECISION array, dimension (max(1,N-1)) */
00115 /*          On entry, the (n-1) subdiagonal elements of the tridiagonal */
00116 /*          matrix A in elements 1 to N-1 of E. */
00117 /*          On exit, E may be multiplied by a constant factor chosen */
00118 /*          to avoid over/underflow in computing the eigenvalues. */
00119 
00120 /*  VL      (input) DOUBLE PRECISION */
00121 /*  VU      (input) DOUBLE PRECISION */
00122 /*          If RANGE='V', the lower and upper bounds of the interval to */
00123 /*          be searched for eigenvalues. VL < VU. */
00124 /*          Not referenced if RANGE = 'A' or 'I'. */
00125 
00126 /*  IL      (input) INTEGER */
00127 /*  IU      (input) INTEGER */
00128 /*          If RANGE='I', the indices (in ascending order) of the */
00129 /*          smallest and largest eigenvalues to be returned. */
00130 /*          1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
00131 /*          Not referenced if RANGE = 'A' or 'V'. */
00132 
00133 /*  ABSTOL  (input) DOUBLE PRECISION */
00134 /*          The absolute error tolerance for the eigenvalues. */
00135 /*          An approximate eigenvalue is accepted as converged */
00136 /*          when it is determined to lie in an interval [a,b] */
00137 /*          of width less than or equal to */
00138 
00139 /*                  ABSTOL + EPS *   max( |a|,|b| ) , */
00140 
00141 /*          where EPS is the machine precision.  If ABSTOL is less */
00142 /*          than or equal to zero, then  EPS*|T|  will be used in */
00143 /*          its place, where |T| is the 1-norm of the tridiagonal */
00144 /*          matrix. */
00145 
00146 /*          Eigenvalues will be computed most accurately when ABSTOL is */
00147 /*          set to twice the underflow threshold 2*DLAMCH('S'), not zero. */
00148 /*          If this routine returns with INFO>0, indicating that some */
00149 /*          eigenvectors did not converge, try setting ABSTOL to */
00150 /*          2*DLAMCH('S'). */
00151 
00152 /*          See "Computing Small Singular Values of Bidiagonal Matrices */
00153 /*          with Guaranteed High Relative Accuracy," by Demmel and */
00154 /*          Kahan, LAPACK Working Note #3. */
00155 
00156 /*  M       (output) INTEGER */
00157 /*          The total number of eigenvalues found.  0 <= M <= N. */
00158 /*          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
00159 
00160 /*  W       (output) DOUBLE PRECISION array, dimension (N) */
00161 /*          The first M elements contain the selected eigenvalues in */
00162 /*          ascending order. */
00163 
00164 /*  Z       (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M) ) */
00165 /*          If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
00166 /*          contain the orthonormal eigenvectors of the matrix A */
00167 /*          corresponding to the selected eigenvalues, with the i-th */
00168 /*          column of Z holding the eigenvector associated with W(i). */
00169 /*          If an eigenvector fails to converge (INFO > 0), then that */
00170 /*          column of Z contains the latest approximation to the */
00171 /*          eigenvector, and the index of the eigenvector is returned */
00172 /*          in IFAIL.  If JOBZ = 'N', then Z is not referenced. */
00173 /*          Note: the user must ensure that at least max(1,M) columns are */
00174 /*          supplied in the array Z; if RANGE = 'V', the exact value of M */
00175 /*          is not known in advance and an upper bound must be used. */
00176 
00177 /*  LDZ     (input) INTEGER */
00178 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
00179 /*          JOBZ = 'V', LDZ >= max(1,N). */
00180 
00181 /*  WORK    (workspace) DOUBLE PRECISION array, dimension (5*N) */
00182 
00183 /*  IWORK   (workspace) INTEGER array, dimension (5*N) */
00184 
00185 /*  IFAIL   (output) INTEGER array, dimension (N) */
00186 /*          If JOBZ = 'V', then if INFO = 0, the first M elements of */
00187 /*          IFAIL are zero.  If INFO > 0, then IFAIL contains the */
00188 /*          indices of the eigenvectors that failed to converge. */
00189 /*          If JOBZ = 'N', then IFAIL is not referenced. */
00190 
00191 /*  INFO    (output) INTEGER */
00192 /*          = 0:  successful exit */
00193 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00194 /*          > 0:  if INFO = i, then i eigenvectors failed to converge. */
00195 /*                Their indices are stored in array IFAIL. */
00196 
00197 /*  ===================================================================== */
00198 
00199 /*     .. Parameters .. */
00200 /*     .. */
00201 /*     .. Local Scalars .. */
00202 /*     .. */
00203 /*     .. External Functions .. */
00204 /*     .. */
00205 /*     .. External Subroutines .. */
00206 /*     .. */
00207 /*     .. Intrinsic Functions .. */
00208 /*     .. */
00209 /*     .. Executable Statements .. */
00210 
00211 /*     Test the input parameters. */
00212 
00213     /* Parameter adjustments */
00214     --d__;
00215     --e;
00216     --w;
00217     z_dim1 = *ldz;
00218     z_offset = 1 + z_dim1;
00219     z__ -= z_offset;
00220     --work;
00221     --iwork;
00222     --ifail;
00223 
00224     /* Function Body */
00225     wantz = lsame_(jobz, "V");
00226     alleig = lsame_(range, "A");
00227     valeig = lsame_(range, "V");
00228     indeig = lsame_(range, "I");
00229 
00230     *info = 0;
00231     if (! (wantz || lsame_(jobz, "N"))) {
00232         *info = -1;
00233     } else if (! (alleig || valeig || indeig)) {
00234         *info = -2;
00235     } else if (*n < 0) {
00236         *info = -3;
00237     } else {
00238         if (valeig) {
00239             if (*n > 0 && *vu <= *vl) {
00240                 *info = -7;
00241             }
00242         } else if (indeig) {
00243             if (*il < 1 || *il > max(1,*n)) {
00244                 *info = -8;
00245             } else if (*iu < min(*n,*il) || *iu > *n) {
00246                 *info = -9;
00247             }
00248         }
00249     }
00250     if (*info == 0) {
00251         if (*ldz < 1 || wantz && *ldz < *n) {
00252             *info = -14;
00253         }
00254     }
00255 
00256     if (*info != 0) {
00257         i__1 = -(*info);
00258         xerbla_("DSTEVX", &i__1);
00259         return 0;
00260     }
00261 
00262 /*     Quick return if possible */
00263 
00264     *m = 0;
00265     if (*n == 0) {
00266         return 0;
00267     }
00268 
00269     if (*n == 1) {
00270         if (alleig || indeig) {
00271             *m = 1;
00272             w[1] = d__[1];
00273         } else {
00274             if (*vl < d__[1] && *vu >= d__[1]) {
00275                 *m = 1;
00276                 w[1] = d__[1];
00277             }
00278         }
00279         if (wantz) {
00280             z__[z_dim1 + 1] = 1.;
00281         }
00282         return 0;
00283     }
00284 
00285 /*     Get machine constants. */
00286 
00287     safmin = dlamch_("Safe minimum");
00288     eps = dlamch_("Precision");
00289     smlnum = safmin / eps;
00290     bignum = 1. / smlnum;
00291     rmin = sqrt(smlnum);
00292 /* Computing MIN */
00293     d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin));
00294     rmax = min(d__1,d__2);
00295 
00296 /*     Scale matrix to allowable range, if necessary. */
00297 
00298     iscale = 0;
00299     if (valeig) {
00300         vll = *vl;
00301         vuu = *vu;
00302     } else {
00303         vll = 0.;
00304         vuu = 0.;
00305     }
00306     tnrm = dlanst_("M", n, &d__[1], &e[1]);
00307     if (tnrm > 0. && tnrm < rmin) {
00308         iscale = 1;
00309         sigma = rmin / tnrm;
00310     } else if (tnrm > rmax) {
00311         iscale = 1;
00312         sigma = rmax / tnrm;
00313     }
00314     if (iscale == 1) {
00315         dscal_(n, &sigma, &d__[1], &c__1);
00316         i__1 = *n - 1;
00317         dscal_(&i__1, &sigma, &e[1], &c__1);
00318         if (valeig) {
00319             vll = *vl * sigma;
00320             vuu = *vu * sigma;
00321         }
00322     }
00323 
00324 /*     If all eigenvalues are desired and ABSTOL is less than zero, then */
00325 /*     call DSTERF or SSTEQR.  If this fails for some eigenvalue, then */
00326 /*     try DSTEBZ. */
00327 
00328     test = FALSE_;
00329     if (indeig) {
00330         if (*il == 1 && *iu == *n) {
00331             test = TRUE_;
00332         }
00333     }
00334     if ((alleig || test) && *abstol <= 0.) {
00335         dcopy_(n, &d__[1], &c__1, &w[1], &c__1);
00336         i__1 = *n - 1;
00337         dcopy_(&i__1, &e[1], &c__1, &work[1], &c__1);
00338         indwrk = *n + 1;
00339         if (! wantz) {
00340             dsterf_(n, &w[1], &work[1], info);
00341         } else {
00342             dsteqr_("I", n, &w[1], &work[1], &z__[z_offset], ldz, &work[
00343                     indwrk], info);
00344             if (*info == 0) {
00345                 i__1 = *n;
00346                 for (i__ = 1; i__ <= i__1; ++i__) {
00347                     ifail[i__] = 0;
00348 /* L10: */
00349                 }
00350             }
00351         }
00352         if (*info == 0) {
00353             *m = *n;
00354             goto L20;
00355         }
00356         *info = 0;
00357     }
00358 
00359 /*     Otherwise, call DSTEBZ and, if eigenvectors are desired, SSTEIN. */
00360 
00361     if (wantz) {
00362         *(unsigned char *)order = 'B';
00363     } else {
00364         *(unsigned char *)order = 'E';
00365     }
00366     indwrk = 1;
00367     indibl = 1;
00368     indisp = indibl + *n;
00369     indiwo = indisp + *n;
00370     dstebz_(range, order, n, &vll, &vuu, il, iu, abstol, &d__[1], &e[1], m, &
00371             nsplit, &w[1], &iwork[indibl], &iwork[indisp], &work[indwrk], &
00372             iwork[indiwo], info);
00373 
00374     if (wantz) {
00375         dstein_(n, &d__[1], &e[1], m, &w[1], &iwork[indibl], &iwork[indisp], &
00376                 z__[z_offset], ldz, &work[indwrk], &iwork[indiwo], &ifail[1], 
00377                 info);
00378     }
00379 
00380 /*     If matrix was scaled, then rescale eigenvalues appropriately. */
00381 
00382 L20:
00383     if (iscale == 1) {
00384         if (*info == 0) {
00385             imax = *m;
00386         } else {
00387             imax = *info - 1;
00388         }
00389         d__1 = 1. / sigma;
00390         dscal_(&imax, &d__1, &w[1], &c__1);
00391     }
00392 
00393 /*     If eigenvalues are not in order, then sort them, along with */
00394 /*     eigenvectors. */
00395 
00396     if (wantz) {
00397         i__1 = *m - 1;
00398         for (j = 1; j <= i__1; ++j) {
00399             i__ = 0;
00400             tmp1 = w[j];
00401             i__2 = *m;
00402             for (jj = j + 1; jj <= i__2; ++jj) {
00403                 if (w[jj] < tmp1) {
00404                     i__ = jj;
00405                     tmp1 = w[jj];
00406                 }
00407 /* L30: */
00408             }
00409 
00410             if (i__ != 0) {
00411                 itmp1 = iwork[indibl + i__ - 1];
00412                 w[i__] = w[j];
00413                 iwork[indibl + i__ - 1] = iwork[indibl + j - 1];
00414                 w[j] = tmp1;
00415                 iwork[indibl + j - 1] = itmp1;
00416                 dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1], 
00417                          &c__1);
00418                 if (*info != 0) {
00419                     itmp1 = ifail[i__];
00420                     ifail[i__] = ifail[j];
00421                     ifail[j] = itmp1;
00422                 }
00423             }
00424 /* L40: */
00425         }
00426     }
00427 
00428     return 0;
00429 
00430 /*     End of DSTEVX */
00431 
00432 } /* dstevx_ */


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