dspgv.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /* dspgv.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_dspgv_(integer *itype, char *jobz, char *uplo, integer *
  16. n, doublereal *ap, doublereal *bp, doublereal *w, doublereal *z__,
  17. integer *ldz, doublereal *work, integer *info)
  18. {
  19. /* System generated locals */
  20. integer z_dim1, z_offset, i__1;
  21. /* Local variables */
  22. integer j, neig;
  23. extern logical _starpu_lsame_(char *, char *);
  24. extern /* Subroutine */ int _starpu_dspev_(char *, char *, integer *, doublereal *
  25. , doublereal *, doublereal *, integer *, doublereal *, integer *);
  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;
  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. *);
  37. /* -- LAPACK driver routine (version 3.2) -- */
  38. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  39. /* November 2006 */
  40. /* .. Scalar Arguments .. */
  41. /* .. */
  42. /* .. Array Arguments .. */
  43. /* .. */
  44. /* Purpose */
  45. /* ======= */
  46. /* DSPGV computes all the eigenvalues and, optionally, the eigenvectors */
  47. /* of a real generalized symmetric-definite eigenproblem, of the form */
  48. /* A*x=(lambda)*B*x, A*Bx=(lambda)*x, or B*A*x=(lambda)*x. */
  49. /* Here A and B are assumed to be symmetric, stored in packed format, */
  50. /* and B is also positive definite. */
  51. /* Arguments */
  52. /* ========= */
  53. /* ITYPE (input) INTEGER */
  54. /* Specifies the problem type to be solved: */
  55. /* = 1: A*x = (lambda)*B*x */
  56. /* = 2: A*B*x = (lambda)*x */
  57. /* = 3: B*A*x = (lambda)*x */
  58. /* JOBZ (input) CHARACTER*1 */
  59. /* = 'N': Compute eigenvalues only; */
  60. /* = 'V': Compute eigenvalues and eigenvectors. */
  61. /* UPLO (input) CHARACTER*1 */
  62. /* = 'U': Upper triangles of A and B are stored; */
  63. /* = 'L': Lower triangles of A and B are stored. */
  64. /* N (input) INTEGER */
  65. /* The order of the matrices A and B. N >= 0. */
  66. /* AP (input/output) DOUBLE PRECISION array, dimension */
  67. /* (N*(N+1)/2) */
  68. /* On entry, the upper or lower triangle of the symmetric matrix */
  69. /* A, packed columnwise in a linear array. The j-th column of A */
  70. /* is stored in the array AP as follows: */
  71. /* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
  72. /* if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */
  73. /* On exit, the contents of AP are destroyed. */
  74. /* BP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
  75. /* On entry, the upper or lower triangle of the symmetric matrix */
  76. /* B, packed columnwise in a linear array. The j-th column of B */
  77. /* is stored in the array BP as follows: */
  78. /* if UPLO = 'U', BP(i + (j-1)*j/2) = B(i,j) for 1<=i<=j; */
  79. /* if UPLO = 'L', BP(i + (j-1)*(2*n-j)/2) = B(i,j) for j<=i<=n. */
  80. /* On exit, the triangular factor U or L from the Cholesky */
  81. /* factorization B = U**T*U or B = L*L**T, in the same storage */
  82. /* format as B. */
  83. /* W (output) DOUBLE PRECISION array, dimension (N) */
  84. /* If INFO = 0, the eigenvalues in ascending order. */
  85. /* Z (output) DOUBLE PRECISION array, dimension (LDZ, N) */
  86. /* If JOBZ = 'V', then if INFO = 0, Z contains the matrix Z of */
  87. /* eigenvectors. The eigenvectors are normalized as follows: */
  88. /* if ITYPE = 1 or 2, Z**T*B*Z = I; */
  89. /* if ITYPE = 3, Z**T*inv(B)*Z = I. */
  90. /* If JOBZ = 'N', then Z is not referenced. */
  91. /* LDZ (input) INTEGER */
  92. /* The leading dimension of the array Z. LDZ >= 1, and if */
  93. /* JOBZ = 'V', LDZ >= max(1,N). */
  94. /* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */
  95. /* INFO (output) INTEGER */
  96. /* = 0: successful exit */
  97. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  98. /* > 0: DPPTRF or DSPEV returned an error code: */
  99. /* <= N: if INFO = i, DSPEV failed to converge; */
  100. /* i off-diagonal elements of an intermediate */
  101. /* tridiagonal form did not converge to zero. */
  102. /* > N: if INFO = n + i, for 1 <= i <= n, then the leading */
  103. /* minor of order i of B is not positive definite. */
  104. /* The factorization of B could not be completed and */
  105. /* no eigenvalues or eigenvectors were computed. */
  106. /* ===================================================================== */
  107. /* .. Local Scalars .. */
  108. /* .. */
  109. /* .. External Functions .. */
  110. /* .. */
  111. /* .. External Subroutines .. */
  112. /* .. */
  113. /* .. Executable Statements .. */
  114. /* Test the input parameters. */
  115. /* Parameter adjustments */
  116. --ap;
  117. --bp;
  118. --w;
  119. z_dim1 = *ldz;
  120. z_offset = 1 + z_dim1;
  121. z__ -= z_offset;
  122. --work;
  123. /* Function Body */
  124. wantz = _starpu_lsame_(jobz, "V");
  125. upper = _starpu_lsame_(uplo, "U");
  126. *info = 0;
  127. if (*itype < 1 || *itype > 3) {
  128. *info = -1;
  129. } else if (! (wantz || _starpu_lsame_(jobz, "N"))) {
  130. *info = -2;
  131. } else if (! (upper || _starpu_lsame_(uplo, "L"))) {
  132. *info = -3;
  133. } else if (*n < 0) {
  134. *info = -4;
  135. } else if (*ldz < 1 || wantz && *ldz < *n) {
  136. *info = -9;
  137. }
  138. if (*info != 0) {
  139. i__1 = -(*info);
  140. _starpu_xerbla_("DSPGV ", &i__1);
  141. return 0;
  142. }
  143. /* Quick return if possible */
  144. if (*n == 0) {
  145. return 0;
  146. }
  147. /* Form a Cholesky factorization of B. */
  148. _starpu_dpptrf_(uplo, n, &bp[1], info);
  149. if (*info != 0) {
  150. *info = *n + *info;
  151. return 0;
  152. }
  153. /* Transform problem to standard eigenvalue problem and solve. */
  154. _starpu_dspgst_(itype, uplo, n, &ap[1], &bp[1], info);
  155. _starpu_dspev_(jobz, uplo, n, &ap[1], &w[1], &z__[z_offset], ldz, &work[1], info);
  156. if (wantz) {
  157. /* Backtransform eigenvectors to the original problem. */
  158. neig = *n;
  159. if (*info > 0) {
  160. neig = *info - 1;
  161. }
  162. if (*itype == 1 || *itype == 2) {
  163. /* For A*x=(lambda)*B*x and A*B*x=(lambda)*x; */
  164. /* backtransform eigenvectors: x = inv(L)'*y or inv(U)*y */
  165. if (upper) {
  166. *(unsigned char *)trans = 'N';
  167. } else {
  168. *(unsigned char *)trans = 'T';
  169. }
  170. i__1 = neig;
  171. for (j = 1; j <= i__1; ++j) {
  172. _starpu_dtpsv_(uplo, trans, "Non-unit", n, &bp[1], &z__[j * z_dim1 +
  173. 1], &c__1);
  174. /* L10: */
  175. }
  176. } else if (*itype == 3) {
  177. /* For B*A*x=(lambda)*x; */
  178. /* backtransform eigenvectors: x = L*y or U'*y */
  179. if (upper) {
  180. *(unsigned char *)trans = 'T';
  181. } else {
  182. *(unsigned char *)trans = 'N';
  183. }
  184. i__1 = neig;
  185. for (j = 1; j <= i__1; ++j) {
  186. _starpu_dtpmv_(uplo, trans, "Non-unit", n, &bp[1], &z__[j * z_dim1 +
  187. 1], &c__1);
  188. /* L20: */
  189. }
  190. }
  191. }
  192. return 0;
  193. /* End of DSPGV */
  194. } /* _starpu_dspgv_ */