dsyevr.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. /* dsyevr.f -- translated by f2c (version 20061008).
  2. You must link the resulting object file with libf2c:
  3. on Microsoft Windows system, link with libf2c.lib;
  4. on Linux or Unix systems, link with .../path/to/libf2c.a -lm
  5. or, if you install libf2c.a in a standard place, with -lf2c -lm
  6. -- in that order, at the end of the command line, as in
  7. cc *.o -lf2c -lm
  8. Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
  9. http://www.netlib.org/f2c/libf2c.zip
  10. */
  11. #include "f2c.h"
  12. #include "blaswrap.h"
  13. /* Table of constant values */
  14. static integer c__10 = 10;
  15. static integer c__1 = 1;
  16. static integer c__2 = 2;
  17. static integer c__3 = 3;
  18. static integer c__4 = 4;
  19. static integer c_n1 = -1;
  20. /* Subroutine */ int dsyevr_(char *jobz, char *range, char *uplo, integer *n,
  21. doublereal *a, integer *lda, doublereal *vl, doublereal *vu, integer *
  22. il, integer *iu, doublereal *abstol, integer *m, doublereal *w,
  23. doublereal *z__, integer *ldz, integer *isuppz, doublereal *work,
  24. integer *lwork, integer *iwork, integer *liwork, integer *info)
  25. {
  26. /* System generated locals */
  27. integer a_dim1, a_offset, z_dim1, z_offset, i__1, i__2;
  28. doublereal d__1, d__2;
  29. /* Builtin functions */
  30. double sqrt(doublereal);
  31. /* Local variables */
  32. integer i__, j, nb, jj;
  33. doublereal eps, vll, vuu, tmp1;
  34. integer indd, inde;
  35. doublereal anrm;
  36. integer imax;
  37. doublereal rmin, rmax;
  38. integer inddd, indee;
  39. extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
  40. integer *);
  41. doublereal sigma;
  42. extern logical lsame_(char *, char *);
  43. integer iinfo;
  44. char order[1];
  45. integer indwk;
  46. extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
  47. doublereal *, integer *), dswap_(integer *, doublereal *, integer
  48. *, doublereal *, integer *);
  49. integer lwmin;
  50. logical lower, wantz;
  51. extern doublereal dlamch_(char *);
  52. logical alleig, indeig;
  53. integer iscale, ieeeok, indibl, indifl;
  54. logical valeig;
  55. doublereal safmin;
  56. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  57. integer *, integer *);
  58. extern /* Subroutine */ int xerbla_(char *, integer *);
  59. doublereal abstll, bignum;
  60. integer indtau, indisp;
  61. extern /* Subroutine */ int dstein_(integer *, doublereal *, doublereal *,
  62. integer *, doublereal *, integer *, integer *, doublereal *,
  63. integer *, doublereal *, integer *, integer *, integer *),
  64. dsterf_(integer *, doublereal *, doublereal *, integer *);
  65. integer indiwo, indwkn;
  66. extern doublereal dlansy_(char *, char *, integer *, doublereal *,
  67. integer *, doublereal *);
  68. extern /* Subroutine */ int dstebz_(char *, char *, integer *, doublereal
  69. *, doublereal *, integer *, integer *, doublereal *, doublereal *,
  70. doublereal *, integer *, integer *, doublereal *, integer *,
  71. integer *, doublereal *, integer *, integer *),
  72. dstemr_(char *, char *, integer *, doublereal *, doublereal *,
  73. doublereal *, doublereal *, integer *, integer *, integer *,
  74. doublereal *, doublereal *, integer *, integer *, integer *,
  75. logical *, doublereal *, integer *, integer *, integer *, integer
  76. *);
  77. integer liwmin;
  78. logical tryrac;
  79. extern /* Subroutine */ int dormtr_(char *, char *, char *, integer *,
  80. integer *, doublereal *, integer *, doublereal *, doublereal *,
  81. integer *, doublereal *, integer *, integer *);
  82. integer llwrkn, llwork, nsplit;
  83. doublereal smlnum;
  84. extern /* Subroutine */ int dsytrd_(char *, integer *, doublereal *,
  85. integer *, doublereal *, doublereal *, doublereal *, doublereal *,
  86. integer *, integer *);
  87. integer lwkopt;
  88. logical lquery;
  89. /* -- LAPACK driver routine (version 3.2) -- */
  90. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  91. /* November 2006 */
  92. /* .. Scalar Arguments .. */
  93. /* .. */
  94. /* .. Array Arguments .. */
  95. /* .. */
  96. /* Purpose */
  97. /* ======= */
  98. /* DSYEVR computes selected eigenvalues and, optionally, eigenvectors */
  99. /* of a real symmetric matrix A. Eigenvalues and eigenvectors can be */
  100. /* selected by specifying either a range of values or a range of */
  101. /* indices for the desired eigenvalues. */
  102. /* DSYEVR first reduces the matrix A to tridiagonal form T with a call */
  103. /* to DSYTRD. Then, whenever possible, DSYEVR calls DSTEMR to compute */
  104. /* the eigenspectrum using Relatively Robust Representations. DSTEMR */
  105. /* computes eigenvalues by the dqds algorithm, while orthogonal */
  106. /* eigenvectors are computed from various "good" L D L^T representations */
  107. /* (also known as Relatively Robust Representations). Gram-Schmidt */
  108. /* orthogonalization is avoided as far as possible. More specifically, */
  109. /* the various steps of the algorithm are as follows. */
  110. /* For each unreduced block (submatrix) of T, */
  111. /* (a) Compute T - sigma I = L D L^T, so that L and D */
  112. /* define all the wanted eigenvalues to high relative accuracy. */
  113. /* This means that small relative changes in the entries of D and L */
  114. /* cause only small relative changes in the eigenvalues and */
  115. /* eigenvectors. The standard (unfactored) representation of the */
  116. /* tridiagonal matrix T does not have this property in general. */
  117. /* (b) Compute the eigenvalues to suitable accuracy. */
  118. /* If the eigenvectors are desired, the algorithm attains full */
  119. /* accuracy of the computed eigenvalues only right before */
  120. /* the corresponding vectors have to be computed, see steps c) and d). */
  121. /* (c) For each cluster of close eigenvalues, select a new */
  122. /* shift close to the cluster, find a new factorization, and refine */
  123. /* the shifted eigenvalues to suitable accuracy. */
  124. /* (d) For each eigenvalue with a large enough relative separation compute */
  125. /* the corresponding eigenvector by forming a rank revealing twisted */
  126. /* factorization. Go back to (c) for any clusters that remain. */
  127. /* The desired accuracy of the output can be specified by the input */
  128. /* parameter ABSTOL. */
  129. /* For more details, see DSTEMR's documentation and: */
  130. /* - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations */
  131. /* to compute orthogonal eigenvectors of symmetric tridiagonal matrices," */
  132. /* Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004. */
  133. /* - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and */
  134. /* Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25, */
  135. /* 2004. Also LAPACK Working Note 154. */
  136. /* - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric */
  137. /* tridiagonal eigenvalue/eigenvector problem", */
  138. /* Computer Science Division Technical Report No. UCB/CSD-97-971, */
  139. /* UC Berkeley, May 1997. */
  140. /* Note 1 : DSYEVR calls DSTEMR when the full spectrum is requested */
  141. /* on machines which conform to the ieee-754 floating point standard. */
  142. /* DSYEVR calls DSTEBZ and SSTEIN on non-ieee machines and */
  143. /* when partial spectrum requests are made. */
  144. /* Normal execution of DSTEMR may create NaNs and infinities and */
  145. /* hence may abort due to a floating point exception in environments */
  146. /* which do not handle NaNs and infinities in the ieee standard default */
  147. /* manner. */
  148. /* Arguments */
  149. /* ========= */
  150. /* JOBZ (input) CHARACTER*1 */
  151. /* = 'N': Compute eigenvalues only; */
  152. /* = 'V': Compute eigenvalues and eigenvectors. */
  153. /* RANGE (input) CHARACTER*1 */
  154. /* = 'A': all eigenvalues will be found. */
  155. /* = 'V': all eigenvalues in the half-open interval (VL,VU] */
  156. /* will be found. */
  157. /* = 'I': the IL-th through IU-th eigenvalues will be found. */
  158. /* ********* For RANGE = 'V' or 'I' and IU - IL < N - 1, DSTEBZ and */
  159. /* ********* DSTEIN are called */
  160. /* UPLO (input) CHARACTER*1 */
  161. /* = 'U': Upper triangle of A is stored; */
  162. /* = 'L': Lower triangle of A is stored. */
  163. /* N (input) INTEGER */
  164. /* The order of the matrix A. N >= 0. */
  165. /* A (input/output) DOUBLE PRECISION array, dimension (LDA, N) */
  166. /* On entry, the symmetric matrix A. If UPLO = 'U', the */
  167. /* leading N-by-N upper triangular part of A contains the */
  168. /* upper triangular part of the matrix A. If UPLO = 'L', */
  169. /* the leading N-by-N lower triangular part of A contains */
  170. /* the lower triangular part of the matrix A. */
  171. /* On exit, the lower triangle (if UPLO='L') or the upper */
  172. /* triangle (if UPLO='U') of A, including the diagonal, is */
  173. /* destroyed. */
  174. /* LDA (input) INTEGER */
  175. /* The leading dimension of the array A. LDA >= max(1,N). */
  176. /* VL (input) DOUBLE PRECISION */
  177. /* VU (input) DOUBLE PRECISION */
  178. /* If RANGE='V', the lower and upper bounds of the interval to */
  179. /* be searched for eigenvalues. VL < VU. */
  180. /* Not referenced if RANGE = 'A' or 'I'. */
  181. /* IL (input) INTEGER */
  182. /* IU (input) INTEGER */
  183. /* If RANGE='I', the indices (in ascending order) of the */
  184. /* smallest and largest eigenvalues to be returned. */
  185. /* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
  186. /* Not referenced if RANGE = 'A' or 'V'. */
  187. /* ABSTOL (input) DOUBLE PRECISION */
  188. /* The absolute error tolerance for the eigenvalues. */
  189. /* An approximate eigenvalue is accepted as converged */
  190. /* when it is determined to lie in an interval [a,b] */
  191. /* of width less than or equal to */
  192. /* ABSTOL + EPS * max( |a|,|b| ) , */
  193. /* where EPS is the machine precision. If ABSTOL is less than */
  194. /* or equal to zero, then EPS*|T| will be used in its place, */
  195. /* where |T| is the 1-norm of the tridiagonal matrix obtained */
  196. /* by reducing A to tridiagonal form. */
  197. /* See "Computing Small Singular Values of Bidiagonal Matrices */
  198. /* with Guaranteed High Relative Accuracy," by Demmel and */
  199. /* Kahan, LAPACK Working Note #3. */
  200. /* If high relative accuracy is important, set ABSTOL to */
  201. /* DLAMCH( 'Safe minimum' ). Doing so will guarantee that */
  202. /* eigenvalues are computed to high relative accuracy when */
  203. /* possible in future releases. The current code does not */
  204. /* make any guarantees about high relative accuracy, but */
  205. /* future releases will. See J. Barlow and J. Demmel, */
  206. /* "Computing Accurate Eigensystems of Scaled Diagonally */
  207. /* Dominant Matrices", LAPACK Working Note #7, for a discussion */
  208. /* of which matrices define their eigenvalues to high relative */
  209. /* accuracy. */
  210. /* M (output) INTEGER */
  211. /* The total number of eigenvalues found. 0 <= M <= N. */
  212. /* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
  213. /* W (output) DOUBLE PRECISION array, dimension (N) */
  214. /* The first M elements contain the selected eigenvalues in */
  215. /* ascending order. */
  216. /* Z (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M)) */
  217. /* If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
  218. /* contain the orthonormal eigenvectors of the matrix A */
  219. /* corresponding to the selected eigenvalues, with the i-th */
  220. /* column of Z holding the eigenvector associated with W(i). */
  221. /* If JOBZ = 'N', then Z is not referenced. */
  222. /* Note: the user must ensure that at least max(1,M) columns are */
  223. /* supplied in the array Z; if RANGE = 'V', the exact value of M */
  224. /* is not known in advance and an upper bound must be used. */
  225. /* Supplying N columns is always safe. */
  226. /* LDZ (input) INTEGER */
  227. /* The leading dimension of the array Z. LDZ >= 1, and if */
  228. /* JOBZ = 'V', LDZ >= max(1,N). */
  229. /* ISUPPZ (output) INTEGER array, dimension ( 2*max(1,M) ) */
  230. /* The support of the eigenvectors in Z, i.e., the indices */
  231. /* indicating the nonzero elements in Z. The i-th eigenvector */
  232. /* is nonzero only in elements ISUPPZ( 2*i-1 ) through */
  233. /* ISUPPZ( 2*i ). */
  234. /* ********* Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1 */
  235. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  236. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  237. /* LWORK (input) INTEGER */
  238. /* The dimension of the array WORK. LWORK >= max(1,26*N). */
  239. /* For optimal efficiency, LWORK >= (NB+6)*N, */
  240. /* where NB is the max of the blocksize for DSYTRD and DORMTR */
  241. /* returned by ILAENV. */
  242. /* If LWORK = -1, then a workspace query is assumed; the routine */
  243. /* only calculates the optimal size of the WORK array, returns */
  244. /* this value as the first entry of the WORK array, and no error */
  245. /* message related to LWORK is issued by XERBLA. */
  246. /* IWORK (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */
  247. /* On exit, if INFO = 0, IWORK(1) returns the optimal LWORK. */
  248. /* LIWORK (input) INTEGER */
  249. /* The dimension of the array IWORK. LIWORK >= max(1,10*N). */
  250. /* If LIWORK = -1, then a workspace query is assumed; the */
  251. /* routine only calculates the optimal size of the IWORK array, */
  252. /* returns this value as the first entry of the IWORK array, and */
  253. /* no error message related to LIWORK is issued by XERBLA. */
  254. /* INFO (output) INTEGER */
  255. /* = 0: successful exit */
  256. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  257. /* > 0: Internal error */
  258. /* Further Details */
  259. /* =============== */
  260. /* Based on contributions by */
  261. /* Inderjit Dhillon, IBM Almaden, USA */
  262. /* Osni Marques, LBNL/NERSC, USA */
  263. /* Ken Stanley, Computer Science Division, University of */
  264. /* California at Berkeley, USA */
  265. /* Jason Riedy, Computer Science Division, University of */
  266. /* California at Berkeley, USA */
  267. /* ===================================================================== */
  268. /* .. Parameters .. */
  269. /* .. */
  270. /* .. Local Scalars .. */
  271. /* .. */
  272. /* .. External Functions .. */
  273. /* .. */
  274. /* .. External Subroutines .. */
  275. /* .. */
  276. /* .. Intrinsic Functions .. */
  277. /* .. */
  278. /* .. Executable Statements .. */
  279. /* Test the input parameters. */
  280. /* Parameter adjustments */
  281. a_dim1 = *lda;
  282. a_offset = 1 + a_dim1;
  283. a -= a_offset;
  284. --w;
  285. z_dim1 = *ldz;
  286. z_offset = 1 + z_dim1;
  287. z__ -= z_offset;
  288. --isuppz;
  289. --work;
  290. --iwork;
  291. /* Function Body */
  292. ieeeok = ilaenv_(&c__10, "DSYEVR", "N", &c__1, &c__2, &c__3, &c__4);
  293. lower = lsame_(uplo, "L");
  294. wantz = lsame_(jobz, "V");
  295. alleig = lsame_(range, "A");
  296. valeig = lsame_(range, "V");
  297. indeig = lsame_(range, "I");
  298. lquery = *lwork == -1 || *liwork == -1;
  299. /* Computing MAX */
  300. i__1 = 1, i__2 = *n * 26;
  301. lwmin = max(i__1,i__2);
  302. /* Computing MAX */
  303. i__1 = 1, i__2 = *n * 10;
  304. liwmin = max(i__1,i__2);
  305. *info = 0;
  306. if (! (wantz || lsame_(jobz, "N"))) {
  307. *info = -1;
  308. } else if (! (alleig || valeig || indeig)) {
  309. *info = -2;
  310. } else if (! (lower || lsame_(uplo, "U"))) {
  311. *info = -3;
  312. } else if (*n < 0) {
  313. *info = -4;
  314. } else if (*lda < max(1,*n)) {
  315. *info = -6;
  316. } else {
  317. if (valeig) {
  318. if (*n > 0 && *vu <= *vl) {
  319. *info = -8;
  320. }
  321. } else if (indeig) {
  322. if (*il < 1 || *il > max(1,*n)) {
  323. *info = -9;
  324. } else if (*iu < min(*n,*il) || *iu > *n) {
  325. *info = -10;
  326. }
  327. }
  328. }
  329. if (*info == 0) {
  330. if (*ldz < 1 || wantz && *ldz < *n) {
  331. *info = -15;
  332. } else if (*lwork < lwmin && ! lquery) {
  333. *info = -18;
  334. } else if (*liwork < liwmin && ! lquery) {
  335. *info = -20;
  336. }
  337. }
  338. if (*info == 0) {
  339. nb = ilaenv_(&c__1, "DSYTRD", uplo, n, &c_n1, &c_n1, &c_n1);
  340. /* Computing MAX */
  341. i__1 = nb, i__2 = ilaenv_(&c__1, "DORMTR", uplo, n, &c_n1, &c_n1, &
  342. c_n1);
  343. nb = max(i__1,i__2);
  344. /* Computing MAX */
  345. i__1 = (nb + 1) * *n;
  346. lwkopt = max(i__1,lwmin);
  347. work[1] = (doublereal) lwkopt;
  348. iwork[1] = liwmin;
  349. }
  350. if (*info != 0) {
  351. i__1 = -(*info);
  352. xerbla_("DSYEVR", &i__1);
  353. return 0;
  354. } else if (lquery) {
  355. return 0;
  356. }
  357. /* Quick return if possible */
  358. *m = 0;
  359. if (*n == 0) {
  360. work[1] = 1.;
  361. return 0;
  362. }
  363. if (*n == 1) {
  364. work[1] = 7.;
  365. if (alleig || indeig) {
  366. *m = 1;
  367. w[1] = a[a_dim1 + 1];
  368. } else {
  369. if (*vl < a[a_dim1 + 1] && *vu >= a[a_dim1 + 1]) {
  370. *m = 1;
  371. w[1] = a[a_dim1 + 1];
  372. }
  373. }
  374. if (wantz) {
  375. z__[z_dim1 + 1] = 1.;
  376. }
  377. return 0;
  378. }
  379. /* Get machine constants. */
  380. safmin = dlamch_("Safe minimum");
  381. eps = dlamch_("Precision");
  382. smlnum = safmin / eps;
  383. bignum = 1. / smlnum;
  384. rmin = sqrt(smlnum);
  385. /* Computing MIN */
  386. d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin));
  387. rmax = min(d__1,d__2);
  388. /* Scale matrix to allowable range, if necessary. */
  389. iscale = 0;
  390. abstll = *abstol;
  391. vll = *vl;
  392. vuu = *vu;
  393. anrm = dlansy_("M", uplo, n, &a[a_offset], lda, &work[1]);
  394. if (anrm > 0. && anrm < rmin) {
  395. iscale = 1;
  396. sigma = rmin / anrm;
  397. } else if (anrm > rmax) {
  398. iscale = 1;
  399. sigma = rmax / anrm;
  400. }
  401. if (iscale == 1) {
  402. if (lower) {
  403. i__1 = *n;
  404. for (j = 1; j <= i__1; ++j) {
  405. i__2 = *n - j + 1;
  406. dscal_(&i__2, &sigma, &a[j + j * a_dim1], &c__1);
  407. /* L10: */
  408. }
  409. } else {
  410. i__1 = *n;
  411. for (j = 1; j <= i__1; ++j) {
  412. dscal_(&j, &sigma, &a[j * a_dim1 + 1], &c__1);
  413. /* L20: */
  414. }
  415. }
  416. if (*abstol > 0.) {
  417. abstll = *abstol * sigma;
  418. }
  419. if (valeig) {
  420. vll = *vl * sigma;
  421. vuu = *vu * sigma;
  422. }
  423. }
  424. /* Initialize indices into workspaces. Note: The IWORK indices are */
  425. /* used only if DSTERF or DSTEMR fail. */
  426. /* WORK(INDTAU:INDTAU+N-1) stores the scalar factors of the */
  427. /* elementary reflectors used in DSYTRD. */
  428. indtau = 1;
  429. /* WORK(INDD:INDD+N-1) stores the tridiagonal's diagonal entries. */
  430. indd = indtau + *n;
  431. /* WORK(INDE:INDE+N-1) stores the off-diagonal entries of the */
  432. /* tridiagonal matrix from DSYTRD. */
  433. inde = indd + *n;
  434. /* WORK(INDDD:INDDD+N-1) is a copy of the diagonal entries over */
  435. /* -written by DSTEMR (the DSTERF path copies the diagonal to W). */
  436. inddd = inde + *n;
  437. /* WORK(INDEE:INDEE+N-1) is a copy of the off-diagonal entries over */
  438. /* -written while computing the eigenvalues in DSTERF and DSTEMR. */
  439. indee = inddd + *n;
  440. /* INDWK is the starting offset of the left-over workspace, and */
  441. /* LLWORK is the remaining workspace size. */
  442. indwk = indee + *n;
  443. llwork = *lwork - indwk + 1;
  444. /* IWORK(INDIBL:INDIBL+M-1) corresponds to IBLOCK in DSTEBZ and */
  445. /* stores the block indices of each of the M<=N eigenvalues. */
  446. indibl = 1;
  447. /* IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in DSTEBZ and */
  448. /* stores the starting and finishing indices of each block. */
  449. indisp = indibl + *n;
  450. /* IWORK(INDIFL:INDIFL+N-1) stores the indices of eigenvectors */
  451. /* that corresponding to eigenvectors that fail to converge in */
  452. /* DSTEIN. This information is discarded; if any fail, the driver */
  453. /* returns INFO > 0. */
  454. indifl = indisp + *n;
  455. /* INDIWO is the offset of the remaining integer workspace. */
  456. indiwo = indisp + *n;
  457. /* Call DSYTRD to reduce symmetric matrix to tridiagonal form. */
  458. dsytrd_(uplo, n, &a[a_offset], lda, &work[indd], &work[inde], &work[
  459. indtau], &work[indwk], &llwork, &iinfo);
  460. /* If all eigenvalues are desired */
  461. /* then call DSTERF or DSTEMR and DORMTR. */
  462. if ((alleig || indeig && *il == 1 && *iu == *n) && ieeeok == 1) {
  463. if (! wantz) {
  464. dcopy_(n, &work[indd], &c__1, &w[1], &c__1);
  465. i__1 = *n - 1;
  466. dcopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1);
  467. dsterf_(n, &w[1], &work[indee], info);
  468. } else {
  469. i__1 = *n - 1;
  470. dcopy_(&i__1, &work[inde], &c__1, &work[indee], &c__1);
  471. dcopy_(n, &work[indd], &c__1, &work[inddd], &c__1);
  472. if (*abstol <= *n * 2. * eps) {
  473. tryrac = TRUE_;
  474. } else {
  475. tryrac = FALSE_;
  476. }
  477. dstemr_(jobz, "A", n, &work[inddd], &work[indee], vl, vu, il, iu,
  478. m, &w[1], &z__[z_offset], ldz, n, &isuppz[1], &tryrac, &
  479. work[indwk], lwork, &iwork[1], liwork, info);
  480. /* Apply orthogonal matrix used in reduction to tridiagonal */
  481. /* form to eigenvectors returned by DSTEIN. */
  482. if (wantz && *info == 0) {
  483. indwkn = inde;
  484. llwrkn = *lwork - indwkn + 1;
  485. dormtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau]
  486. , &z__[z_offset], ldz, &work[indwkn], &llwrkn, &iinfo);
  487. }
  488. }
  489. if (*info == 0) {
  490. /* Everything worked. Skip DSTEBZ/DSTEIN. IWORK(:) are */
  491. /* undefined. */
  492. *m = *n;
  493. goto L30;
  494. }
  495. *info = 0;
  496. }
  497. /* Otherwise, call DSTEBZ and, if eigenvectors are desired, DSTEIN. */
  498. /* Also call DSTEBZ and DSTEIN if DSTEMR fails. */
  499. if (wantz) {
  500. *(unsigned char *)order = 'B';
  501. } else {
  502. *(unsigned char *)order = 'E';
  503. }
  504. dstebz_(range, order, n, &vll, &vuu, il, iu, &abstll, &work[indd], &work[
  505. inde], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &work[
  506. indwk], &iwork[indiwo], info);
  507. if (wantz) {
  508. dstein_(n, &work[indd], &work[inde], m, &w[1], &iwork[indibl], &iwork[
  509. indisp], &z__[z_offset], ldz, &work[indwk], &iwork[indiwo], &
  510. iwork[indifl], info);
  511. /* Apply orthogonal matrix used in reduction to tridiagonal */
  512. /* form to eigenvectors returned by DSTEIN. */
  513. indwkn = inde;
  514. llwrkn = *lwork - indwkn + 1;
  515. dormtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau], &z__[
  516. z_offset], ldz, &work[indwkn], &llwrkn, &iinfo);
  517. }
  518. /* If matrix was scaled, then rescale eigenvalues appropriately. */
  519. /* Jump here if DSTEMR/DSTEIN succeeded. */
  520. L30:
  521. if (iscale == 1) {
  522. if (*info == 0) {
  523. imax = *m;
  524. } else {
  525. imax = *info - 1;
  526. }
  527. d__1 = 1. / sigma;
  528. dscal_(&imax, &d__1, &w[1], &c__1);
  529. }
  530. /* If eigenvalues are not in order, then sort them, along with */
  531. /* eigenvectors. Note: We do not sort the IFAIL portion of IWORK. */
  532. /* It may not be initialized (if DSTEMR/DSTEIN succeeded), and we do */
  533. /* not return this detailed information to the user. */
  534. if (wantz) {
  535. i__1 = *m - 1;
  536. for (j = 1; j <= i__1; ++j) {
  537. i__ = 0;
  538. tmp1 = w[j];
  539. i__2 = *m;
  540. for (jj = j + 1; jj <= i__2; ++jj) {
  541. if (w[jj] < tmp1) {
  542. i__ = jj;
  543. tmp1 = w[jj];
  544. }
  545. /* L40: */
  546. }
  547. if (i__ != 0) {
  548. w[i__] = w[j];
  549. w[j] = tmp1;
  550. dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1],
  551. &c__1);
  552. }
  553. /* L50: */
  554. }
  555. }
  556. /* Set WORK(1) to optimal workspace size. */
  557. work[1] = (doublereal) lwkopt;
  558. iwork[1] = liwmin;
  559. return 0;
  560. /* End of DSYEVR */
  561. } /* dsyevr_ */