dstevx.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. /* dstevx.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__1 = 1;
  15. /* Subroutine */ int _starpu_dstevx_(char *jobz, char *range, integer *n, doublereal *
  16. d__, doublereal *e, doublereal *vl, doublereal *vu, integer *il,
  17. integer *iu, doublereal *abstol, integer *m, doublereal *w,
  18. doublereal *z__, integer *ldz, doublereal *work, integer *iwork,
  19. integer *ifail, integer *info)
  20. {
  21. /* System generated locals */
  22. integer z_dim1, z_offset, i__1, i__2;
  23. doublereal d__1, d__2;
  24. /* Builtin functions */
  25. double sqrt(doublereal);
  26. /* Local variables */
  27. integer i__, j, jj;
  28. doublereal eps, vll, vuu, tmp1;
  29. integer imax;
  30. doublereal rmin, rmax;
  31. logical test;
  32. doublereal tnrm;
  33. integer itmp1;
  34. extern /* Subroutine */ int _starpu_dscal_(integer *, doublereal *, doublereal *,
  35. integer *);
  36. doublereal sigma;
  37. extern logical _starpu_lsame_(char *, char *);
  38. char order[1];
  39. extern /* Subroutine */ int _starpu_dcopy_(integer *, doublereal *, integer *,
  40. doublereal *, integer *), _starpu_dswap_(integer *, doublereal *, integer
  41. *, doublereal *, integer *);
  42. logical wantz;
  43. extern doublereal _starpu_dlamch_(char *);
  44. logical alleig, indeig;
  45. integer iscale, indibl;
  46. logical valeig;
  47. doublereal safmin;
  48. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  49. doublereal bignum;
  50. extern doublereal _starpu_dlanst_(char *, integer *, doublereal *, doublereal *);
  51. integer indisp;
  52. extern /* Subroutine */ int _starpu_dstein_(integer *, doublereal *, doublereal *,
  53. integer *, doublereal *, integer *, integer *, doublereal *,
  54. integer *, doublereal *, integer *, integer *, integer *),
  55. _starpu_dsterf_(integer *, doublereal *, doublereal *, integer *);
  56. integer indiwo;
  57. extern /* Subroutine */ int _starpu_dstebz_(char *, char *, integer *, doublereal
  58. *, doublereal *, integer *, integer *, doublereal *, doublereal *,
  59. doublereal *, integer *, integer *, doublereal *, integer *,
  60. integer *, doublereal *, integer *, integer *);
  61. integer indwrk;
  62. extern /* Subroutine */ int _starpu_dsteqr_(char *, integer *, doublereal *,
  63. doublereal *, doublereal *, integer *, doublereal *, integer *);
  64. integer nsplit;
  65. doublereal smlnum;
  66. /* -- LAPACK driver routine (version 3.2) -- */
  67. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  68. /* November 2006 */
  69. /* .. Scalar Arguments .. */
  70. /* .. */
  71. /* .. Array Arguments .. */
  72. /* .. */
  73. /* Purpose */
  74. /* ======= */
  75. /* DSTEVX computes selected eigenvalues and, optionally, eigenvectors */
  76. /* of a real symmetric tridiagonal matrix A. Eigenvalues and */
  77. /* eigenvectors can be selected by specifying either a range of values */
  78. /* or a range of indices for the desired eigenvalues. */
  79. /* Arguments */
  80. /* ========= */
  81. /* JOBZ (input) CHARACTER*1 */
  82. /* = 'N': Compute eigenvalues only; */
  83. /* = 'V': Compute eigenvalues and eigenvectors. */
  84. /* RANGE (input) CHARACTER*1 */
  85. /* = 'A': all eigenvalues will be found. */
  86. /* = 'V': all eigenvalues in the half-open interval (VL,VU] */
  87. /* will be found. */
  88. /* = 'I': the IL-th through IU-th eigenvalues will be found. */
  89. /* N (input) INTEGER */
  90. /* The order of the matrix. N >= 0. */
  91. /* D (input/output) DOUBLE PRECISION array, dimension (N) */
  92. /* On entry, the n diagonal elements of the tridiagonal matrix */
  93. /* A. */
  94. /* On exit, D may be multiplied by a constant factor chosen */
  95. /* to avoid over/underflow in computing the eigenvalues. */
  96. /* E (input/output) DOUBLE PRECISION array, dimension (max(1,N-1)) */
  97. /* On entry, the (n-1) subdiagonal elements of the tridiagonal */
  98. /* matrix A in elements 1 to N-1 of E. */
  99. /* On exit, E may be multiplied by a constant factor chosen */
  100. /* to avoid over/underflow in computing the eigenvalues. */
  101. /* VL (input) DOUBLE PRECISION */
  102. /* VU (input) DOUBLE PRECISION */
  103. /* If RANGE='V', the lower and upper bounds of the interval to */
  104. /* be searched for eigenvalues. VL < VU. */
  105. /* Not referenced if RANGE = 'A' or 'I'. */
  106. /* IL (input) INTEGER */
  107. /* IU (input) INTEGER */
  108. /* If RANGE='I', the indices (in ascending order) of the */
  109. /* smallest and largest eigenvalues to be returned. */
  110. /* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
  111. /* Not referenced if RANGE = 'A' or 'V'. */
  112. /* ABSTOL (input) DOUBLE PRECISION */
  113. /* The absolute error tolerance for the eigenvalues. */
  114. /* An approximate eigenvalue is accepted as converged */
  115. /* when it is determined to lie in an interval [a,b] */
  116. /* of width less than or equal to */
  117. /* ABSTOL + EPS * max( |a|,|b| ) , */
  118. /* where EPS is the machine precision. If ABSTOL is less */
  119. /* than or equal to zero, then EPS*|T| will be used in */
  120. /* its place, where |T| is the 1-norm of the tridiagonal */
  121. /* matrix. */
  122. /* Eigenvalues will be computed most accurately when ABSTOL is */
  123. /* set to twice the underflow threshold 2*DLAMCH('S'), not zero. */
  124. /* If this routine returns with INFO>0, indicating that some */
  125. /* eigenvectors did not converge, try setting ABSTOL to */
  126. /* 2*DLAMCH('S'). */
  127. /* See "Computing Small Singular Values of Bidiagonal Matrices */
  128. /* with Guaranteed High Relative Accuracy," by Demmel and */
  129. /* Kahan, LAPACK Working Note #3. */
  130. /* M (output) INTEGER */
  131. /* The total number of eigenvalues found. 0 <= M <= N. */
  132. /* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
  133. /* W (output) DOUBLE PRECISION array, dimension (N) */
  134. /* The first M elements contain the selected eigenvalues in */
  135. /* ascending order. */
  136. /* Z (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M) ) */
  137. /* If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
  138. /* contain the orthonormal eigenvectors of the matrix A */
  139. /* corresponding to the selected eigenvalues, with the i-th */
  140. /* column of Z holding the eigenvector associated with W(i). */
  141. /* If an eigenvector fails to converge (INFO > 0), then that */
  142. /* column of Z contains the latest approximation to the */
  143. /* eigenvector, and the index of the eigenvector is returned */
  144. /* in IFAIL. If JOBZ = 'N', then Z is not referenced. */
  145. /* Note: the user must ensure that at least max(1,M) columns are */
  146. /* supplied in the array Z; if RANGE = 'V', the exact value of M */
  147. /* is not known in advance and an upper bound must be used. */
  148. /* LDZ (input) INTEGER */
  149. /* The leading dimension of the array Z. LDZ >= 1, and if */
  150. /* JOBZ = 'V', LDZ >= max(1,N). */
  151. /* WORK (workspace) DOUBLE PRECISION array, dimension (5*N) */
  152. /* IWORK (workspace) INTEGER array, dimension (5*N) */
  153. /* IFAIL (output) INTEGER array, dimension (N) */
  154. /* If JOBZ = 'V', then if INFO = 0, the first M elements of */
  155. /* IFAIL are zero. If INFO > 0, then IFAIL contains the */
  156. /* indices of the eigenvectors that failed to converge. */
  157. /* If JOBZ = 'N', then IFAIL is not referenced. */
  158. /* INFO (output) INTEGER */
  159. /* = 0: successful exit */
  160. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  161. /* > 0: if INFO = i, then i eigenvectors failed to converge. */
  162. /* Their indices are stored in array IFAIL. */
  163. /* ===================================================================== */
  164. /* .. Parameters .. */
  165. /* .. */
  166. /* .. Local Scalars .. */
  167. /* .. */
  168. /* .. External Functions .. */
  169. /* .. */
  170. /* .. External Subroutines .. */
  171. /* .. */
  172. /* .. Intrinsic Functions .. */
  173. /* .. */
  174. /* .. Executable Statements .. */
  175. /* Test the input parameters. */
  176. /* Parameter adjustments */
  177. --d__;
  178. --e;
  179. --w;
  180. z_dim1 = *ldz;
  181. z_offset = 1 + z_dim1;
  182. z__ -= z_offset;
  183. --work;
  184. --iwork;
  185. --ifail;
  186. /* Function Body */
  187. wantz = _starpu_lsame_(jobz, "V");
  188. alleig = _starpu_lsame_(range, "A");
  189. valeig = _starpu_lsame_(range, "V");
  190. indeig = _starpu_lsame_(range, "I");
  191. *info = 0;
  192. if (! (wantz || _starpu_lsame_(jobz, "N"))) {
  193. *info = -1;
  194. } else if (! (alleig || valeig || indeig)) {
  195. *info = -2;
  196. } else if (*n < 0) {
  197. *info = -3;
  198. } else {
  199. if (valeig) {
  200. if (*n > 0 && *vu <= *vl) {
  201. *info = -7;
  202. }
  203. } else if (indeig) {
  204. if (*il < 1 || *il > max(1,*n)) {
  205. *info = -8;
  206. } else if (*iu < min(*n,*il) || *iu > *n) {
  207. *info = -9;
  208. }
  209. }
  210. }
  211. if (*info == 0) {
  212. if (*ldz < 1 || wantz && *ldz < *n) {
  213. *info = -14;
  214. }
  215. }
  216. if (*info != 0) {
  217. i__1 = -(*info);
  218. _starpu_xerbla_("DSTEVX", &i__1);
  219. return 0;
  220. }
  221. /* Quick return if possible */
  222. *m = 0;
  223. if (*n == 0) {
  224. return 0;
  225. }
  226. if (*n == 1) {
  227. if (alleig || indeig) {
  228. *m = 1;
  229. w[1] = d__[1];
  230. } else {
  231. if (*vl < d__[1] && *vu >= d__[1]) {
  232. *m = 1;
  233. w[1] = d__[1];
  234. }
  235. }
  236. if (wantz) {
  237. z__[z_dim1 + 1] = 1.;
  238. }
  239. return 0;
  240. }
  241. /* Get machine constants. */
  242. safmin = _starpu_dlamch_("Safe minimum");
  243. eps = _starpu_dlamch_("Precision");
  244. smlnum = safmin / eps;
  245. bignum = 1. / smlnum;
  246. rmin = sqrt(smlnum);
  247. /* Computing MIN */
  248. d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin));
  249. rmax = min(d__1,d__2);
  250. /* Scale matrix to allowable range, if necessary. */
  251. iscale = 0;
  252. if (valeig) {
  253. vll = *vl;
  254. vuu = *vu;
  255. } else {
  256. vll = 0.;
  257. vuu = 0.;
  258. }
  259. tnrm = _starpu_dlanst_("M", n, &d__[1], &e[1]);
  260. if (tnrm > 0. && tnrm < rmin) {
  261. iscale = 1;
  262. sigma = rmin / tnrm;
  263. } else if (tnrm > rmax) {
  264. iscale = 1;
  265. sigma = rmax / tnrm;
  266. }
  267. if (iscale == 1) {
  268. _starpu_dscal_(n, &sigma, &d__[1], &c__1);
  269. i__1 = *n - 1;
  270. _starpu_dscal_(&i__1, &sigma, &e[1], &c__1);
  271. if (valeig) {
  272. vll = *vl * sigma;
  273. vuu = *vu * sigma;
  274. }
  275. }
  276. /* If all eigenvalues are desired and ABSTOL is less than zero, then */
  277. /* call DSTERF or SSTEQR. If this fails for some eigenvalue, then */
  278. /* try DSTEBZ. */
  279. test = FALSE_;
  280. if (indeig) {
  281. if (*il == 1 && *iu == *n) {
  282. test = TRUE_;
  283. }
  284. }
  285. if ((alleig || test) && *abstol <= 0.) {
  286. _starpu_dcopy_(n, &d__[1], &c__1, &w[1], &c__1);
  287. i__1 = *n - 1;
  288. _starpu_dcopy_(&i__1, &e[1], &c__1, &work[1], &c__1);
  289. indwrk = *n + 1;
  290. if (! wantz) {
  291. _starpu_dsterf_(n, &w[1], &work[1], info);
  292. } else {
  293. _starpu_dsteqr_("I", n, &w[1], &work[1], &z__[z_offset], ldz, &work[
  294. indwrk], info);
  295. if (*info == 0) {
  296. i__1 = *n;
  297. for (i__ = 1; i__ <= i__1; ++i__) {
  298. ifail[i__] = 0;
  299. /* L10: */
  300. }
  301. }
  302. }
  303. if (*info == 0) {
  304. *m = *n;
  305. goto L20;
  306. }
  307. *info = 0;
  308. }
  309. /* Otherwise, call DSTEBZ and, if eigenvectors are desired, SSTEIN. */
  310. if (wantz) {
  311. *(unsigned char *)order = 'B';
  312. } else {
  313. *(unsigned char *)order = 'E';
  314. }
  315. indwrk = 1;
  316. indibl = 1;
  317. indisp = indibl + *n;
  318. indiwo = indisp + *n;
  319. _starpu_dstebz_(range, order, n, &vll, &vuu, il, iu, abstol, &d__[1], &e[1], m, &
  320. nsplit, &w[1], &iwork[indibl], &iwork[indisp], &work[indwrk], &
  321. iwork[indiwo], info);
  322. if (wantz) {
  323. _starpu_dstein_(n, &d__[1], &e[1], m, &w[1], &iwork[indibl], &iwork[indisp], &
  324. z__[z_offset], ldz, &work[indwrk], &iwork[indiwo], &ifail[1],
  325. info);
  326. }
  327. /* If matrix was scaled, then rescale eigenvalues appropriately. */
  328. L20:
  329. if (iscale == 1) {
  330. if (*info == 0) {
  331. imax = *m;
  332. } else {
  333. imax = *info - 1;
  334. }
  335. d__1 = 1. / sigma;
  336. _starpu_dscal_(&imax, &d__1, &w[1], &c__1);
  337. }
  338. /* If eigenvalues are not in order, then sort them, along with */
  339. /* eigenvectors. */
  340. if (wantz) {
  341. i__1 = *m - 1;
  342. for (j = 1; j <= i__1; ++j) {
  343. i__ = 0;
  344. tmp1 = w[j];
  345. i__2 = *m;
  346. for (jj = j + 1; jj <= i__2; ++jj) {
  347. if (w[jj] < tmp1) {
  348. i__ = jj;
  349. tmp1 = w[jj];
  350. }
  351. /* L30: */
  352. }
  353. if (i__ != 0) {
  354. itmp1 = iwork[indibl + i__ - 1];
  355. w[i__] = w[j];
  356. iwork[indibl + i__ - 1] = iwork[indibl + j - 1];
  357. w[j] = tmp1;
  358. iwork[indibl + j - 1] = itmp1;
  359. _starpu_dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1],
  360. &c__1);
  361. if (*info != 0) {
  362. itmp1 = ifail[i__];
  363. ifail[i__] = ifail[j];
  364. ifail[j] = itmp1;
  365. }
  366. }
  367. /* L40: */
  368. }
  369. }
  370. return 0;
  371. /* End of DSTEVX */
  372. } /* _starpu_dstevx_ */