dsyevx.c
Go to the documentation of this file.
00001 /* dsyevx.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 integer c_n1 = -1;
00020 
00021 /* Subroutine */ int dsyevx_(char *jobz, char *range, char *uplo, integer *n, 
00022         doublereal *a, integer *lda, doublereal *vl, doublereal *vu, integer *
00023         il, integer *iu, doublereal *abstol, integer *m, doublereal *w, 
00024         doublereal *z__, integer *ldz, doublereal *work, integer *lwork, 
00025         integer *iwork, integer *ifail, integer *info)
00026 {
00027     /* System generated locals */
00028     integer a_dim1, a_offset, 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, nb, jj;
00036     doublereal eps, vll, vuu, tmp1;
00037     integer indd, inde;
00038     doublereal anrm;
00039     integer imax;
00040     doublereal rmin, rmax;
00041     logical test;
00042     integer itmp1, indee;
00043     extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, 
00044             integer *);
00045     doublereal sigma;
00046     extern logical lsame_(char *, char *);
00047     integer iinfo;
00048     char order[1];
00049     extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *, 
00050             doublereal *, integer *), dswap_(integer *, doublereal *, integer 
00051             *, doublereal *, integer *);
00052     logical lower, wantz;
00053     extern doublereal dlamch_(char *);
00054     logical alleig, indeig;
00055     integer iscale, indibl;
00056     logical valeig;
00057     extern /* Subroutine */ int dlacpy_(char *, integer *, integer *, 
00058             doublereal *, integer *, doublereal *, integer *);
00059     doublereal safmin;
00060     extern integer ilaenv_(integer *, char *, char *, integer *, integer *, 
00061             integer *, integer *);
00062     extern /* Subroutine */ int xerbla_(char *, integer *);
00063     doublereal abstll, bignum;
00064     integer indtau, indisp;
00065     extern /* Subroutine */ int dstein_(integer *, doublereal *, doublereal *, 
00066              integer *, doublereal *, integer *, integer *, doublereal *, 
00067             integer *, doublereal *, integer *, integer *, integer *), 
00068             dsterf_(integer *, doublereal *, doublereal *, integer *);
00069     integer indiwo, indwkn;
00070     extern doublereal dlansy_(char *, char *, integer *, doublereal *, 
00071             integer *, doublereal *);
00072     extern /* Subroutine */ int dstebz_(char *, char *, integer *, doublereal 
00073             *, doublereal *, integer *, integer *, doublereal *, doublereal *, 
00074              doublereal *, integer *, integer *, doublereal *, integer *, 
00075             integer *, doublereal *, integer *, integer *);
00076     integer indwrk, lwkmin;
00077     extern /* Subroutine */ int dorgtr_(char *, integer *, doublereal *, 
00078             integer *, doublereal *, doublereal *, integer *, integer *), dsteqr_(char *, integer *, doublereal *, doublereal *, 
00079             doublereal *, integer *, doublereal *, integer *), 
00080             dormtr_(char *, char *, char *, integer *, integer *, doublereal *
00081 , integer *, doublereal *, doublereal *, integer *, doublereal *, 
00082             integer *, integer *);
00083     integer llwrkn, llwork, nsplit;
00084     doublereal smlnum;
00085     extern /* Subroutine */ int dsytrd_(char *, integer *, doublereal *, 
00086             integer *, doublereal *, doublereal *, doublereal *, doublereal *, 
00087              integer *, integer *);
00088     integer lwkopt;
00089     logical lquery;
00090 
00091 
00092 /*  -- LAPACK driver routine (version 3.2) -- */
00093 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00094 /*     November 2006 */
00095 
00096 /*     .. Scalar Arguments .. */
00097 /*     .. */
00098 /*     .. Array Arguments .. */
00099 /*     .. */
00100 
00101 /*  Purpose */
00102 /*  ======= */
00103 
00104 /*  DSYEVX computes selected eigenvalues and, optionally, eigenvectors */
00105 /*  of a real symmetric matrix A.  Eigenvalues and eigenvectors can be */
00106 /*  selected by specifying either a range of values or a range of indices */
00107 /*  for the desired eigenvalues. */
00108 
00109 /*  Arguments */
00110 /*  ========= */
00111 
00112 /*  JOBZ    (input) CHARACTER*1 */
00113 /*          = 'N':  Compute eigenvalues only; */
00114 /*          = 'V':  Compute eigenvalues and eigenvectors. */
00115 
00116 /*  RANGE   (input) CHARACTER*1 */
00117 /*          = 'A': all eigenvalues will be found. */
00118 /*          = 'V': all eigenvalues in the half-open interval (VL,VU] */
00119 /*                 will be found. */
00120 /*          = 'I': the IL-th through IU-th eigenvalues will be found. */
00121 
00122 /*  UPLO    (input) CHARACTER*1 */
00123 /*          = 'U':  Upper triangle of A is stored; */
00124 /*          = 'L':  Lower triangle of A is stored. */
00125 
00126 /*  N       (input) INTEGER */
00127 /*          The order of the matrix A.  N >= 0. */
00128 
00129 /*  A       (input/output) DOUBLE PRECISION array, dimension (LDA, N) */
00130 /*          On entry, the symmetric matrix A.  If UPLO = 'U', the */
00131 /*          leading N-by-N upper triangular part of A contains the */
00132 /*          upper triangular part of the matrix A.  If UPLO = 'L', */
00133 /*          the leading N-by-N lower triangular part of A contains */
00134 /*          the lower triangular part of the matrix A. */
00135 /*          On exit, the lower triangle (if UPLO='L') or the upper */
00136 /*          triangle (if UPLO='U') of A, including the diagonal, is */
00137 /*          destroyed. */
00138 
00139 /*  LDA     (input) INTEGER */
00140 /*          The leading dimension of the array A.  LDA >= max(1,N). */
00141 
00142 /*  VL      (input) DOUBLE PRECISION */
00143 /*  VU      (input) DOUBLE PRECISION */
00144 /*          If RANGE='V', the lower and upper bounds of the interval to */
00145 /*          be searched for eigenvalues. VL < VU. */
00146 /*          Not referenced if RANGE = 'A' or 'I'. */
00147 
00148 /*  IL      (input) INTEGER */
00149 /*  IU      (input) INTEGER */
00150 /*          If RANGE='I', the indices (in ascending order) of the */
00151 /*          smallest and largest eigenvalues to be returned. */
00152 /*          1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
00153 /*          Not referenced if RANGE = 'A' or 'V'. */
00154 
00155 /*  ABSTOL  (input) DOUBLE PRECISION */
00156 /*          The absolute error tolerance for the eigenvalues. */
00157 /*          An approximate eigenvalue is accepted as converged */
00158 /*          when it is determined to lie in an interval [a,b] */
00159 /*          of width less than or equal to */
00160 
00161 /*                  ABSTOL + EPS *   max( |a|,|b| ) , */
00162 
00163 /*          where EPS is the machine precision.  If ABSTOL is less than */
00164 /*          or equal to zero, then  EPS*|T|  will be used in its place, */
00165 /*          where |T| is the 1-norm of the tridiagonal matrix obtained */
00166 /*          by reducing A to tridiagonal form. */
00167 
00168 /*          Eigenvalues will be computed most accurately when ABSTOL is */
00169 /*          set to twice the underflow threshold 2*DLAMCH('S'), not zero. */
00170 /*          If this routine returns with INFO>0, indicating that some */
00171 /*          eigenvectors did not converge, try setting ABSTOL to */
00172 /*          2*DLAMCH('S'). */
00173 
00174 /*          See "Computing Small Singular Values of Bidiagonal Matrices */
00175 /*          with Guaranteed High Relative Accuracy," by Demmel and */
00176 /*          Kahan, LAPACK Working Note #3. */
00177 
00178 /*  M       (output) INTEGER */
00179 /*          The total number of eigenvalues found.  0 <= M <= N. */
00180 /*          If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
00181 
00182 /*  W       (output) DOUBLE PRECISION array, dimension (N) */
00183 /*          On normal exit, the first M elements contain the selected */
00184 /*          eigenvalues in ascending order. */
00185 
00186 /*  Z       (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M)) */
00187 /*          If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
00188 /*          contain the orthonormal eigenvectors of the matrix A */
00189 /*          corresponding to the selected eigenvalues, with the i-th */
00190 /*          column of Z holding the eigenvector associated with W(i). */
00191 /*          If an eigenvector fails to converge, then that column of Z */
00192 /*          contains the latest approximation to the eigenvector, and the */
00193 /*          index of the eigenvector is returned in IFAIL. */
00194 /*          If JOBZ = 'N', then Z is not referenced. */
00195 /*          Note: the user must ensure that at least max(1,M) columns are */
00196 /*          supplied in the array Z; if RANGE = 'V', the exact value of M */
00197 /*          is not known in advance and an upper bound must be used. */
00198 
00199 /*  LDZ     (input) INTEGER */
00200 /*          The leading dimension of the array Z.  LDZ >= 1, and if */
00201 /*          JOBZ = 'V', LDZ >= max(1,N). */
00202 
00203 /*  WORK    (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
00204 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00205 
00206 /*  LWORK   (input) INTEGER */
00207 /*          The length of the array WORK.  LWORK >= 1, when N <= 1; */
00208 /*          otherwise 8*N. */
00209 /*          For optimal efficiency, LWORK >= (NB+3)*N, */
00210 /*          where NB is the max of the blocksize for DSYTRD and DORMTR */
00211 /*          returned by ILAENV. */
00212 
00213 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00214 /*          only calculates the optimal size of the WORK array, returns */
00215 /*          this value as the first entry of the WORK array, and no error */
00216 /*          message related to LWORK is issued by XERBLA. */
00217 
00218 /*  IWORK   (workspace) INTEGER array, dimension (5*N) */
00219 
00220 /*  IFAIL   (output) INTEGER array, dimension (N) */
00221 /*          If JOBZ = 'V', then if INFO = 0, the first M elements of */
00222 /*          IFAIL are zero.  If INFO > 0, then IFAIL contains the */
00223 /*          indices of the eigenvectors that failed to converge. */
00224 /*          If JOBZ = 'N', then IFAIL is not referenced. */
00225 
00226 /*  INFO    (output) INTEGER */
00227 /*          = 0:  successful exit */
00228 /*          < 0:  if INFO = -i, the i-th argument had an illegal value */
00229 /*          > 0:  if INFO = i, then i eigenvectors failed to converge. */
00230 /*                Their indices are stored in array IFAIL. */
00231 
00232 /* ===================================================================== */
00233 
00234 /*     .. Parameters .. */
00235 /*     .. */
00236 /*     .. Local Scalars .. */
00237 /*     .. */
00238 /*     .. External Functions .. */
00239 /*     .. */
00240 /*     .. External Subroutines .. */
00241 /*     .. */
00242 /*     .. Intrinsic Functions .. */
00243 /*     .. */
00244 /*     .. Executable Statements .. */
00245 
00246 /*     Test the input parameters. */
00247 
00248     /* Parameter adjustments */
00249     a_dim1 = *lda;
00250     a_offset = 1 + a_dim1;
00251     a -= a_offset;
00252     --w;
00253     z_dim1 = *ldz;
00254     z_offset = 1 + z_dim1;
00255     z__ -= z_offset;
00256     --work;
00257     --iwork;
00258     --ifail;
00259 
00260     /* Function Body */
00261     lower = lsame_(uplo, "L");
00262     wantz = lsame_(jobz, "V");
00263     alleig = lsame_(range, "A");
00264     valeig = lsame_(range, "V");
00265     indeig = lsame_(range, "I");
00266     lquery = *lwork == -1;
00267 
00268     *info = 0;
00269     if (! (wantz || lsame_(jobz, "N"))) {
00270         *info = -1;
00271     } else if (! (alleig || valeig || indeig)) {
00272         *info = -2;
00273     } else if (! (lower || lsame_(uplo, "U"))) {
00274         *info = -3;
00275     } else if (*n < 0) {
00276         *info = -4;
00277     } else if (*lda < max(1,*n)) {
00278         *info = -6;
00279     } else {
00280         if (valeig) {
00281             if (*n > 0 && *vu <= *vl) {
00282                 *info = -8;
00283             }
00284         } else if (indeig) {
00285             if (*il < 1 || *il > max(1,*n)) {
00286                 *info = -9;
00287             } else if (*iu < min(*n,*il) || *iu > *n) {
00288                 *info = -10;
00289             }
00290         }
00291     }
00292     if (*info == 0) {
00293         if (*ldz < 1 || wantz && *ldz < *n) {
00294             *info = -15;
00295         }
00296     }
00297 
00298     if (*info == 0) {
00299         if (*n <= 1) {
00300             lwkmin = 1;
00301             work[1] = (doublereal) lwkmin;
00302         } else {
00303             lwkmin = *n << 3;
00304             nb = ilaenv_(&c__1, "DSYTRD", uplo, n, &c_n1, &c_n1, &c_n1);
00305 /* Computing MAX */
00306             i__1 = nb, i__2 = ilaenv_(&c__1, "DORMTR", uplo, n, &c_n1, &c_n1, 
00307                     &c_n1);
00308             nb = max(i__1,i__2);
00309 /* Computing MAX */
00310             i__1 = lwkmin, i__2 = (nb + 3) * *n;
00311             lwkopt = max(i__1,i__2);
00312             work[1] = (doublereal) lwkopt;
00313         }
00314 
00315         if (*lwork < lwkmin && ! lquery) {
00316             *info = -17;
00317         }
00318     }
00319 
00320     if (*info != 0) {
00321         i__1 = -(*info);
00322         xerbla_("DSYEVX", &i__1);
00323         return 0;
00324     } else if (lquery) {
00325         return 0;
00326     }
00327 
00328 /*     Quick return if possible */
00329 
00330     *m = 0;
00331     if (*n == 0) {
00332         return 0;
00333     }
00334 
00335     if (*n == 1) {
00336         if (alleig || indeig) {
00337             *m = 1;
00338             w[1] = a[a_dim1 + 1];
00339         } else {
00340             if (*vl < a[a_dim1 + 1] && *vu >= a[a_dim1 + 1]) {
00341                 *m = 1;
00342                 w[1] = a[a_dim1 + 1];
00343             }
00344         }
00345         if (wantz) {
00346             z__[z_dim1 + 1] = 1.;
00347         }
00348         return 0;
00349     }
00350 
00351 /*     Get machine constants. */
00352 
00353     safmin = dlamch_("Safe minimum");
00354     eps = dlamch_("Precision");
00355     smlnum = safmin / eps;
00356     bignum = 1. / smlnum;
00357     rmin = sqrt(smlnum);
00358 /* Computing MIN */
00359     d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin));
00360     rmax = min(d__1,d__2);
00361 
00362 /*     Scale matrix to allowable range, if necessary. */
00363 
00364     iscale = 0;
00365     abstll = *abstol;
00366     if (valeig) {
00367         vll = *vl;
00368         vuu = *vu;
00369     }
00370     anrm = dlansy_("M", uplo, n, &a[a_offset], lda, &work[1]);
00371     if (anrm > 0. && anrm < rmin) {
00372         iscale = 1;
00373         sigma = rmin / anrm;
00374     } else if (anrm > rmax) {
00375         iscale = 1;
00376         sigma = rmax / anrm;
00377     }
00378     if (iscale == 1) {
00379         if (lower) {
00380             i__1 = *n;
00381             for (j = 1; j <= i__1; ++j) {
00382                 i__2 = *n - j + 1;
00383                 dscal_(&i__2, &sigma, &a[j + j * a_dim1], &c__1);
00384 /* L10: */
00385             }
00386         } else {
00387             i__1 = *n;
00388             for (j = 1; j <= i__1; ++j) {
00389                 dscal_(&j, &sigma, &a[j * a_dim1 + 1], &c__1);
00390 /* L20: */
00391             }
00392         }
00393         if (*abstol > 0.) {
00394             abstll = *abstol * sigma;
00395         }
00396         if (valeig) {
00397             vll = *vl * sigma;
00398             vuu = *vu * sigma;
00399         }
00400     }
00401 
00402 /*     Call DSYTRD to reduce symmetric matrix to tridiagonal form. */
00403 
00404     indtau = 1;
00405     inde = indtau + *n;
00406     indd = inde + *n;
00407     indwrk = indd + *n;
00408     llwork = *lwork - indwrk + 1;
00409     dsytrd_(uplo, n, &a[a_offset], lda, &work[indd], &work[inde], &work[
00410             indtau], &work[indwrk], &llwork, &iinfo);
00411 
00412 /*     If all eigenvalues are desired and ABSTOL is less than or equal to */
00413 /*     zero, then call DSTERF or DORGTR and SSTEQR.  If this fails for */
00414 /*     some eigenvalue, then try DSTEBZ. */
00415 
00416     test = FALSE_;
00417     if (indeig) {
00418         if (*il == 1 && *iu == *n) {
00419             test = TRUE_;
00420         }
00421     }
00422     if ((alleig || test) && *abstol <= 0.) {
00423         dcopy_(n, &work[indd], &c__1, &w[1], &c__1);
00424         indee = indwrk + (*n << 1);
00425         if (! wantz) {
00426             i__1 = *n - 1;
00427             dcopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1);
00428             dsterf_(n, &w[1], &work[indee], info);
00429         } else {
00430             dlacpy_("A", n, n, &a[a_offset], lda, &z__[z_offset], ldz);
00431             dorgtr_(uplo, n, &z__[z_offset], ldz, &work[indtau], &work[indwrk]
00432 , &llwork, &iinfo);
00433             i__1 = *n - 1;
00434             dcopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1);
00435             dsteqr_(jobz, n, &w[1], &work[indee], &z__[z_offset], ldz, &work[
00436                     indwrk], info);
00437             if (*info == 0) {
00438                 i__1 = *n;
00439                 for (i__ = 1; i__ <= i__1; ++i__) {
00440                     ifail[i__] = 0;
00441 /* L30: */
00442                 }
00443             }
00444         }
00445         if (*info == 0) {
00446             *m = *n;
00447             goto L40;
00448         }
00449         *info = 0;
00450     }
00451 
00452 /*     Otherwise, call DSTEBZ and, if eigenvectors are desired, SSTEIN. */
00453 
00454     if (wantz) {
00455         *(unsigned char *)order = 'B';
00456     } else {
00457         *(unsigned char *)order = 'E';
00458     }
00459     indibl = 1;
00460     indisp = indibl + *n;
00461     indiwo = indisp + *n;
00462     dstebz_(range, order, n, &vll, &vuu, il, iu, &abstll, &work[indd], &work[
00463             inde], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &work[
00464             indwrk], &iwork[indiwo], info);
00465 
00466     if (wantz) {
00467         dstein_(n, &work[indd], &work[inde], m, &w[1], &iwork[indibl], &iwork[
00468                 indisp], &z__[z_offset], ldz, &work[indwrk], &iwork[indiwo], &
00469                 ifail[1], info);
00470 
00471 /*        Apply orthogonal matrix used in reduction to tridiagonal */
00472 /*        form to eigenvectors returned by DSTEIN. */
00473 
00474         indwkn = inde;
00475         llwrkn = *lwork - indwkn + 1;
00476         dormtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau], &z__[
00477                 z_offset], ldz, &work[indwkn], &llwrkn, &iinfo);
00478     }
00479 
00480 /*     If matrix was scaled, then rescale eigenvalues appropriately. */
00481 
00482 L40:
00483     if (iscale == 1) {
00484         if (*info == 0) {
00485             imax = *m;
00486         } else {
00487             imax = *info - 1;
00488         }
00489         d__1 = 1. / sigma;
00490         dscal_(&imax, &d__1, &w[1], &c__1);
00491     }
00492 
00493 /*     If eigenvalues are not in order, then sort them, along with */
00494 /*     eigenvectors. */
00495 
00496     if (wantz) {
00497         i__1 = *m - 1;
00498         for (j = 1; j <= i__1; ++j) {
00499             i__ = 0;
00500             tmp1 = w[j];
00501             i__2 = *m;
00502             for (jj = j + 1; jj <= i__2; ++jj) {
00503                 if (w[jj] < tmp1) {
00504                     i__ = jj;
00505                     tmp1 = w[jj];
00506                 }
00507 /* L50: */
00508             }
00509 
00510             if (i__ != 0) {
00511                 itmp1 = iwork[indibl + i__ - 1];
00512                 w[i__] = w[j];
00513                 iwork[indibl + i__ - 1] = iwork[indibl + j - 1];
00514                 w[j] = tmp1;
00515                 iwork[indibl + j - 1] = itmp1;
00516                 dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1], 
00517                          &c__1);
00518                 if (*info != 0) {
00519                     itmp1 = ifail[i__];
00520                     ifail[i__] = ifail[j];
00521                     ifail[j] = itmp1;
00522                 }
00523             }
00524 /* L60: */
00525         }
00526     }
00527 
00528 /*     Set WORK(1) to optimal workspace size. */
00529 
00530     work[1] = (doublereal) lwkopt;
00531 
00532     return 0;
00533 
00534 /*     End of DSYEVX */
00535 
00536 } /* dsyevx_ */


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