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


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