dspgst.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /* dspgst.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. static doublereal c_b9 = -1.;
  16. static doublereal c_b11 = 1.;
  17. /* Subroutine */ int _starpu_dspgst_(integer *itype, char *uplo, integer *n,
  18. doublereal *ap, doublereal *bp, integer *info)
  19. {
  20. /* System generated locals */
  21. integer i__1, i__2;
  22. doublereal d__1;
  23. /* Local variables */
  24. integer j, k, j1, k1, jj, kk;
  25. doublereal ct, ajj;
  26. integer j1j1;
  27. doublereal akk;
  28. integer k1k1;
  29. doublereal bjj, bkk;
  30. extern doublereal _starpu_ddot_(integer *, doublereal *, integer *, doublereal *,
  31. integer *);
  32. extern /* Subroutine */ int _starpu_dspr2_(char *, integer *, doublereal *,
  33. doublereal *, integer *, doublereal *, integer *, doublereal *), _starpu_dscal_(integer *, doublereal *, doublereal *, integer *);
  34. extern logical _starpu_lsame_(char *, char *);
  35. extern /* Subroutine */ int _starpu_daxpy_(integer *, doublereal *, doublereal *,
  36. integer *, doublereal *, integer *), _starpu_dspmv_(char *, integer *,
  37. doublereal *, doublereal *, doublereal *, integer *, doublereal *,
  38. doublereal *, integer *);
  39. logical upper;
  40. extern /* Subroutine */ int _starpu_dtpmv_(char *, char *, char *, integer *,
  41. doublereal *, doublereal *, integer *),
  42. _starpu_dtpsv_(char *, char *, char *, integer *, doublereal *,
  43. doublereal *, integer *), _starpu_xerbla_(char *,
  44. integer *);
  45. /* -- LAPACK routine (version 3.2) -- */
  46. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  47. /* November 2006 */
  48. /* .. Scalar Arguments .. */
  49. /* .. */
  50. /* .. Array Arguments .. */
  51. /* .. */
  52. /* Purpose */
  53. /* ======= */
  54. /* DSPGST reduces a real symmetric-definite generalized eigenproblem */
  55. /* to standard form, using packed storage. */
  56. /* If ITYPE = 1, the problem is A*x = lambda*B*x, */
  57. /* and A is overwritten by inv(U**T)*A*inv(U) or inv(L)*A*inv(L**T) */
  58. /* If ITYPE = 2 or 3, the problem is A*B*x = lambda*x or */
  59. /* B*A*x = lambda*x, and A is overwritten by U*A*U**T or L**T*A*L. */
  60. /* B must have been previously factorized as U**T*U or L*L**T by DPPTRF. */
  61. /* Arguments */
  62. /* ========= */
  63. /* ITYPE (input) INTEGER */
  64. /* = 1: compute inv(U**T)*A*inv(U) or inv(L)*A*inv(L**T); */
  65. /* = 2 or 3: compute U*A*U**T or L**T*A*L. */
  66. /* UPLO (input) CHARACTER*1 */
  67. /* = 'U': Upper triangle of A is stored and B is factored as */
  68. /* U**T*U; */
  69. /* = 'L': Lower triangle of A is stored and B is factored as */
  70. /* L*L**T. */
  71. /* N (input) INTEGER */
  72. /* The order of the matrices A and B. N >= 0. */
  73. /* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
  74. /* On entry, the upper or lower triangle of the symmetric matrix */
  75. /* A, packed columnwise in a linear array. The j-th column of A */
  76. /* is stored in the array AP as follows: */
  77. /* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
  78. /* if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */
  79. /* On exit, if INFO = 0, the transformed matrix, stored in the */
  80. /* same format as A. */
  81. /* BP (input) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
  82. /* The triangular factor from the Cholesky factorization of B, */
  83. /* stored in the same format as A, as returned by DPPTRF. */
  84. /* INFO (output) INTEGER */
  85. /* = 0: successful exit */
  86. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  87. /* ===================================================================== */
  88. /* .. Parameters .. */
  89. /* .. */
  90. /* .. Local Scalars .. */
  91. /* .. */
  92. /* .. External Subroutines .. */
  93. /* .. */
  94. /* .. External Functions .. */
  95. /* .. */
  96. /* .. Executable Statements .. */
  97. /* Test the input parameters. */
  98. /* Parameter adjustments */
  99. --bp;
  100. --ap;
  101. /* Function Body */
  102. *info = 0;
  103. upper = _starpu_lsame_(uplo, "U");
  104. if (*itype < 1 || *itype > 3) {
  105. *info = -1;
  106. } else if (! upper && ! _starpu_lsame_(uplo, "L")) {
  107. *info = -2;
  108. } else if (*n < 0) {
  109. *info = -3;
  110. }
  111. if (*info != 0) {
  112. i__1 = -(*info);
  113. _starpu_xerbla_("DSPGST", &i__1);
  114. return 0;
  115. }
  116. if (*itype == 1) {
  117. if (upper) {
  118. /* Compute inv(U')*A*inv(U) */
  119. /* J1 and JJ are the indices of A(1,j) and A(j,j) */
  120. jj = 0;
  121. i__1 = *n;
  122. for (j = 1; j <= i__1; ++j) {
  123. j1 = jj + 1;
  124. jj += j;
  125. /* Compute the j-th column of the upper triangle of A */
  126. bjj = bp[jj];
  127. _starpu_dtpsv_(uplo, "Transpose", "Nonunit", &j, &bp[1], &ap[j1], &
  128. c__1);
  129. i__2 = j - 1;
  130. _starpu_dspmv_(uplo, &i__2, &c_b9, &ap[1], &bp[j1], &c__1, &c_b11, &
  131. ap[j1], &c__1);
  132. i__2 = j - 1;
  133. d__1 = 1. / bjj;
  134. _starpu_dscal_(&i__2, &d__1, &ap[j1], &c__1);
  135. i__2 = j - 1;
  136. ap[jj] = (ap[jj] - _starpu_ddot_(&i__2, &ap[j1], &c__1, &bp[j1], &
  137. c__1)) / bjj;
  138. /* L10: */
  139. }
  140. } else {
  141. /* Compute inv(L)*A*inv(L') */
  142. /* KK and K1K1 are the indices of A(k,k) and A(k+1,k+1) */
  143. kk = 1;
  144. i__1 = *n;
  145. for (k = 1; k <= i__1; ++k) {
  146. k1k1 = kk + *n - k + 1;
  147. /* Update the lower triangle of A(k:n,k:n) */
  148. akk = ap[kk];
  149. bkk = bp[kk];
  150. /* Computing 2nd power */
  151. d__1 = bkk;
  152. akk /= d__1 * d__1;
  153. ap[kk] = akk;
  154. if (k < *n) {
  155. i__2 = *n - k;
  156. d__1 = 1. / bkk;
  157. _starpu_dscal_(&i__2, &d__1, &ap[kk + 1], &c__1);
  158. ct = akk * -.5;
  159. i__2 = *n - k;
  160. _starpu_daxpy_(&i__2, &ct, &bp[kk + 1], &c__1, &ap[kk + 1], &c__1)
  161. ;
  162. i__2 = *n - k;
  163. _starpu_dspr2_(uplo, &i__2, &c_b9, &ap[kk + 1], &c__1, &bp[kk + 1]
  164. , &c__1, &ap[k1k1]);
  165. i__2 = *n - k;
  166. _starpu_daxpy_(&i__2, &ct, &bp[kk + 1], &c__1, &ap[kk + 1], &c__1)
  167. ;
  168. i__2 = *n - k;
  169. _starpu_dtpsv_(uplo, "No transpose", "Non-unit", &i__2, &bp[k1k1],
  170. &ap[kk + 1], &c__1);
  171. }
  172. kk = k1k1;
  173. /* L20: */
  174. }
  175. }
  176. } else {
  177. if (upper) {
  178. /* Compute U*A*U' */
  179. /* K1 and KK are the indices of A(1,k) and A(k,k) */
  180. kk = 0;
  181. i__1 = *n;
  182. for (k = 1; k <= i__1; ++k) {
  183. k1 = kk + 1;
  184. kk += k;
  185. /* Update the upper triangle of A(1:k,1:k) */
  186. akk = ap[kk];
  187. bkk = bp[kk];
  188. i__2 = k - 1;
  189. _starpu_dtpmv_(uplo, "No transpose", "Non-unit", &i__2, &bp[1], &ap[
  190. k1], &c__1);
  191. ct = akk * .5;
  192. i__2 = k - 1;
  193. _starpu_daxpy_(&i__2, &ct, &bp[k1], &c__1, &ap[k1], &c__1);
  194. i__2 = k - 1;
  195. _starpu_dspr2_(uplo, &i__2, &c_b11, &ap[k1], &c__1, &bp[k1], &c__1, &
  196. ap[1]);
  197. i__2 = k - 1;
  198. _starpu_daxpy_(&i__2, &ct, &bp[k1], &c__1, &ap[k1], &c__1);
  199. i__2 = k - 1;
  200. _starpu_dscal_(&i__2, &bkk, &ap[k1], &c__1);
  201. /* Computing 2nd power */
  202. d__1 = bkk;
  203. ap[kk] = akk * (d__1 * d__1);
  204. /* L30: */
  205. }
  206. } else {
  207. /* Compute L'*A*L */
  208. /* JJ and J1J1 are the indices of A(j,j) and A(j+1,j+1) */
  209. jj = 1;
  210. i__1 = *n;
  211. for (j = 1; j <= i__1; ++j) {
  212. j1j1 = jj + *n - j + 1;
  213. /* Compute the j-th column of the lower triangle of A */
  214. ajj = ap[jj];
  215. bjj = bp[jj];
  216. i__2 = *n - j;
  217. ap[jj] = ajj * bjj + _starpu_ddot_(&i__2, &ap[jj + 1], &c__1, &bp[jj
  218. + 1], &c__1);
  219. i__2 = *n - j;
  220. _starpu_dscal_(&i__2, &bjj, &ap[jj + 1], &c__1);
  221. i__2 = *n - j;
  222. _starpu_dspmv_(uplo, &i__2, &c_b11, &ap[j1j1], &bp[jj + 1], &c__1, &
  223. c_b11, &ap[jj + 1], &c__1);
  224. i__2 = *n - j + 1;
  225. _starpu_dtpmv_(uplo, "Transpose", "Non-unit", &i__2, &bp[jj], &ap[jj],
  226. &c__1);
  227. jj = j1j1;
  228. /* L40: */
  229. }
  230. }
  231. }
  232. return 0;
  233. /* End of DSPGST */
  234. } /* _starpu_dspgst_ */