dspgvx.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /* dspgvx.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_dspgvx_(integer *itype, char *jobz, char *range, char *
  16. uplo, integer *n, doublereal *ap, doublereal *bp, doublereal *vl,
  17. doublereal *vu, integer *il, integer *iu, doublereal *abstol, integer
  18. *m, doublereal *w, doublereal *z__, integer *ldz, doublereal *work,
  19. integer *iwork, integer *ifail, integer *info)
  20. {
  21. /* System generated locals */
  22. integer z_dim1, z_offset, i__1;
  23. /* Local variables */
  24. integer j;
  25. extern logical _starpu_lsame_(char *, char *);
  26. char trans[1];
  27. logical upper;
  28. extern /* Subroutine */ int _starpu_dtpmv_(char *, char *, char *, integer *,
  29. doublereal *, doublereal *, integer *),
  30. _starpu_dtpsv_(char *, char *, char *, integer *, doublereal *,
  31. doublereal *, integer *);
  32. logical wantz, alleig, indeig, valeig;
  33. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *), _starpu_dpptrf_(
  34. char *, integer *, doublereal *, integer *), _starpu_dspgst_(
  35. integer *, char *, integer *, doublereal *, doublereal *, integer
  36. *), _starpu_dspevx_(char *, char *, char *, integer *, doublereal
  37. *, doublereal *, doublereal *, integer *, integer *, doublereal *,
  38. integer *, doublereal *, doublereal *, integer *, doublereal *,
  39. integer *, integer *, integer *);
  40. /* -- LAPACK driver routine (version 3.2) -- */
  41. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  42. /* November 2006 */
  43. /* .. Scalar Arguments .. */
  44. /* .. */
  45. /* .. Array Arguments .. */
  46. /* .. */
  47. /* Purpose */
  48. /* ======= */
  49. /* DSPGVX computes selected eigenvalues, and optionally, eigenvectors */
  50. /* of a real generalized symmetric-definite eigenproblem, of the form */
  51. /* A*x=(lambda)*B*x, A*Bx=(lambda)*x, or B*A*x=(lambda)*x. Here A */
  52. /* and B are assumed to be symmetric, stored in packed storage, and B */
  53. /* is also positive definite. Eigenvalues and eigenvectors can be */
  54. /* selected by specifying either a range of values or a range of indices */
  55. /* for the desired eigenvalues. */
  56. /* Arguments */
  57. /* ========= */
  58. /* ITYPE (input) INTEGER */
  59. /* Specifies the problem type to be solved: */
  60. /* = 1: A*x = (lambda)*B*x */
  61. /* = 2: A*B*x = (lambda)*x */
  62. /* = 3: B*A*x = (lambda)*x */
  63. /* JOBZ (input) CHARACTER*1 */
  64. /* = 'N': Compute eigenvalues only; */
  65. /* = 'V': Compute eigenvalues and eigenvectors. */
  66. /* RANGE (input) CHARACTER*1 */
  67. /* = 'A': all eigenvalues will be found. */
  68. /* = 'V': all eigenvalues in the half-open interval (VL,VU] */
  69. /* will be found. */
  70. /* = 'I': the IL-th through IU-th eigenvalues will be found. */
  71. /* UPLO (input) CHARACTER*1 */
  72. /* = 'U': Upper triangle of A and B are stored; */
  73. /* = 'L': Lower triangle of A and B are stored. */
  74. /* N (input) INTEGER */
  75. /* The order of the matrix pencil (A,B). N >= 0. */
  76. /* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
  77. /* On entry, the upper or lower triangle of the symmetric matrix */
  78. /* A, packed columnwise in a linear array. The j-th column of A */
  79. /* is stored in the array AP as follows: */
  80. /* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
  81. /* if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */
  82. /* On exit, the contents of AP are destroyed. */
  83. /* BP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
  84. /* On entry, the upper or lower triangle of the symmetric matrix */
  85. /* B, packed columnwise in a linear array. The j-th column of B */
  86. /* is stored in the array BP as follows: */
  87. /* if UPLO = 'U', BP(i + (j-1)*j/2) = B(i,j) for 1<=i<=j; */
  88. /* if UPLO = 'L', BP(i + (j-1)*(2*n-j)/2) = B(i,j) for j<=i<=n. */
  89. /* On exit, the triangular factor U or L from the Cholesky */
  90. /* factorization B = U**T*U or B = L*L**T, in the same storage */
  91. /* format as B. */
  92. /* VL (input) DOUBLE PRECISION */
  93. /* VU (input) DOUBLE PRECISION */
  94. /* If RANGE='V', the lower and upper bounds of the interval to */
  95. /* be searched for eigenvalues. VL < VU. */
  96. /* Not referenced if RANGE = 'A' or 'I'. */
  97. /* IL (input) INTEGER */
  98. /* IU (input) INTEGER */
  99. /* If RANGE='I', the indices (in ascending order) of the */
  100. /* smallest and largest eigenvalues to be returned. */
  101. /* 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
  102. /* Not referenced if RANGE = 'A' or 'V'. */
  103. /* ABSTOL (input) DOUBLE PRECISION */
  104. /* The absolute error tolerance for the eigenvalues. */
  105. /* An approximate eigenvalue is accepted as converged */
  106. /* when it is determined to lie in an interval [a,b] */
  107. /* of width less than or equal to */
  108. /* ABSTOL + EPS * max( |a|,|b| ) , */
  109. /* where EPS is the machine precision. If ABSTOL is less than */
  110. /* or equal to zero, then EPS*|T| will be used in its place, */
  111. /* where |T| is the 1-norm of the tridiagonal matrix obtained */
  112. /* by reducing A to tridiagonal form. */
  113. /* Eigenvalues will be computed most accurately when ABSTOL is */
  114. /* set to twice the underflow threshold 2*DLAMCH('S'), not zero. */
  115. /* If this routine returns with INFO>0, indicating that some */
  116. /* eigenvectors did not converge, try setting ABSTOL to */
  117. /* 2*DLAMCH('S'). */
  118. /* M (output) INTEGER */
  119. /* The total number of eigenvalues found. 0 <= M <= N. */
  120. /* If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
  121. /* W (output) DOUBLE PRECISION array, dimension (N) */
  122. /* On normal exit, the first M elements contain the selected */
  123. /* eigenvalues in ascending order. */
  124. /* Z (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M)) */
  125. /* If JOBZ = 'N', then Z is not referenced. */
  126. /* If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
  127. /* contain the orthonormal eigenvectors of the matrix A */
  128. /* corresponding to the selected eigenvalues, with the i-th */
  129. /* column of Z holding the eigenvector associated with W(i). */
  130. /* The eigenvectors are normalized as follows: */
  131. /* if ITYPE = 1 or 2, Z**T*B*Z = I; */
  132. /* if ITYPE = 3, Z**T*inv(B)*Z = I. */
  133. /* If an eigenvector fails to converge, then that column of Z */
  134. /* contains the latest approximation to the eigenvector, and the */
  135. /* index of the eigenvector is returned in IFAIL. */
  136. /* Note: the user must ensure that at least max(1,M) columns are */
  137. /* supplied in the array Z; if RANGE = 'V', the exact value of M */
  138. /* is not known in advance and an upper bound must be used. */
  139. /* LDZ (input) INTEGER */
  140. /* The leading dimension of the array Z. LDZ >= 1, and if */
  141. /* JOBZ = 'V', LDZ >= max(1,N). */
  142. /* WORK (workspace) DOUBLE PRECISION array, dimension (8*N) */
  143. /* IWORK (workspace) INTEGER array, dimension (5*N) */
  144. /* IFAIL (output) INTEGER array, dimension (N) */
  145. /* If JOBZ = 'V', then if INFO = 0, the first M elements of */
  146. /* IFAIL are zero. If INFO > 0, then IFAIL contains the */
  147. /* indices of the eigenvectors that failed to converge. */
  148. /* If JOBZ = 'N', then IFAIL is not referenced. */
  149. /* INFO (output) INTEGER */
  150. /* = 0: successful exit */
  151. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  152. /* > 0: DPPTRF or DSPEVX returned an error code: */
  153. /* <= N: if INFO = i, DSPEVX failed to converge; */
  154. /* i eigenvectors failed to converge. Their indices */
  155. /* are stored in array IFAIL. */
  156. /* > N: if INFO = N + i, for 1 <= i <= N, then the leading */
  157. /* minor of order i of B is not positive definite. */
  158. /* The factorization of B could not be completed and */
  159. /* no eigenvalues or eigenvectors were computed. */
  160. /* Further Details */
  161. /* =============== */
  162. /* Based on contributions by */
  163. /* Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */
  164. /* ===================================================================== */
  165. /* .. Local Scalars .. */
  166. /* .. */
  167. /* .. External Functions .. */
  168. /* .. */
  169. /* .. External Subroutines .. */
  170. /* .. */
  171. /* .. Intrinsic Functions .. */
  172. /* .. */
  173. /* .. Executable Statements .. */
  174. /* Test the input parameters. */
  175. /* Parameter adjustments */
  176. --ap;
  177. --bp;
  178. --w;
  179. z_dim1 = *ldz;
  180. z_offset = 1 + z_dim1;
  181. z__ -= z_offset;
  182. --work;
  183. --iwork;
  184. --ifail;
  185. /* Function Body */
  186. upper = _starpu_lsame_(uplo, "U");
  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 (*itype < 1 || *itype > 3) {
  193. *info = -1;
  194. } else if (! (wantz || _starpu_lsame_(jobz, "N"))) {
  195. *info = -2;
  196. } else if (! (alleig || valeig || indeig)) {
  197. *info = -3;
  198. } else if (! (upper || _starpu_lsame_(uplo, "L"))) {
  199. *info = -4;
  200. } else if (*n < 0) {
  201. *info = -5;
  202. } else {
  203. if (valeig) {
  204. if (*n > 0 && *vu <= *vl) {
  205. *info = -9;
  206. }
  207. } else if (indeig) {
  208. if (*il < 1) {
  209. *info = -10;
  210. } else if (*iu < min(*n,*il) || *iu > *n) {
  211. *info = -11;
  212. }
  213. }
  214. }
  215. if (*info == 0) {
  216. if (*ldz < 1 || wantz && *ldz < *n) {
  217. *info = -16;
  218. }
  219. }
  220. if (*info != 0) {
  221. i__1 = -(*info);
  222. _starpu_xerbla_("DSPGVX", &i__1);
  223. return 0;
  224. }
  225. /* Quick return if possible */
  226. *m = 0;
  227. if (*n == 0) {
  228. return 0;
  229. }
  230. /* Form a Cholesky factorization of B. */
  231. _starpu_dpptrf_(uplo, n, &bp[1], info);
  232. if (*info != 0) {
  233. *info = *n + *info;
  234. return 0;
  235. }
  236. /* Transform problem to standard eigenvalue problem and solve. */
  237. _starpu_dspgst_(itype, uplo, n, &ap[1], &bp[1], info);
  238. _starpu_dspevx_(jobz, range, uplo, n, &ap[1], vl, vu, il, iu, abstol, m, &w[1], &
  239. z__[z_offset], ldz, &work[1], &iwork[1], &ifail[1], info);
  240. if (wantz) {
  241. /* Backtransform eigenvectors to the original problem. */
  242. if (*info > 0) {
  243. *m = *info - 1;
  244. }
  245. if (*itype == 1 || *itype == 2) {
  246. /* For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */
  247. /* backtransform eigenvectors: x = inv(L)'*y or inv(U)*y */
  248. if (upper) {
  249. *(unsigned char *)trans = 'N';
  250. } else {
  251. *(unsigned char *)trans = 'T';
  252. }
  253. i__1 = *m;
  254. for (j = 1; j <= i__1; ++j) {
  255. _starpu_dtpsv_(uplo, trans, "Non-unit", n, &bp[1], &z__[j * z_dim1 +
  256. 1], &c__1);
  257. /* L10: */
  258. }
  259. } else if (*itype == 3) {
  260. /* For B*A*x=(lambda)*x; */
  261. /* backtransform eigenvectors: x = L*y or U'*y */
  262. if (upper) {
  263. *(unsigned char *)trans = 'T';
  264. } else {
  265. *(unsigned char *)trans = 'N';
  266. }
  267. i__1 = *m;
  268. for (j = 1; j <= i__1; ++j) {
  269. _starpu_dtpmv_(uplo, trans, "Non-unit", n, &bp[1], &z__[j * z_dim1 +
  270. 1], &c__1);
  271. /* L20: */
  272. }
  273. }
  274. }
  275. return 0;
  276. /* End of DSPGVX */
  277. } /* _starpu_dspgvx_ */