dspevx.c 15 KB

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