dsbevx.c 16 KB

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