dsytd2.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /* dsytd2.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_b8 = 0.;
  16. static doublereal c_b14 = -1.;
  17. /* Subroutine */ int _starpu_dsytd2_(char *uplo, integer *n, doublereal *a, integer *
  18. lda, doublereal *d__, doublereal *e, doublereal *tau, integer *info)
  19. {
  20. /* System generated locals */
  21. integer a_dim1, a_offset, i__1, i__2, i__3;
  22. /* Local variables */
  23. integer i__;
  24. extern doublereal _starpu_ddot_(integer *, doublereal *, integer *, doublereal *,
  25. integer *);
  26. doublereal taui;
  27. extern /* Subroutine */ int _starpu_dsyr2_(char *, integer *, doublereal *,
  28. doublereal *, integer *, doublereal *, integer *, doublereal *,
  29. integer *);
  30. doublereal alpha;
  31. extern logical _starpu_lsame_(char *, char *);
  32. extern /* Subroutine */ int _starpu_daxpy_(integer *, doublereal *, doublereal *,
  33. integer *, doublereal *, integer *);
  34. logical upper;
  35. extern /* Subroutine */ int _starpu_dsymv_(char *, integer *, doublereal *,
  36. doublereal *, integer *, doublereal *, integer *, doublereal *,
  37. doublereal *, integer *), _starpu_dlarfg_(integer *, doublereal *,
  38. doublereal *, integer *, doublereal *), _starpu_xerbla_(char *, integer *
  39. );
  40. /* -- LAPACK 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. /* DSYTD2 reduces a real symmetric matrix A to symmetric tridiagonal */
  50. /* form T by an orthogonal similarity transformation: Q' * A * Q = T. */
  51. /* Arguments */
  52. /* ========= */
  53. /* UPLO (input) CHARACTER*1 */
  54. /* Specifies whether the upper or lower triangular part of the */
  55. /* symmetric matrix A is stored: */
  56. /* = 'U': Upper triangular */
  57. /* = 'L': Lower triangular */
  58. /* N (input) INTEGER */
  59. /* The order of the matrix A. N >= 0. */
  60. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  61. /* On entry, the symmetric matrix A. If UPLO = 'U', the leading */
  62. /* n-by-n upper triangular part of A contains the upper */
  63. /* triangular part of the matrix A, and the strictly lower */
  64. /* triangular part of A is not referenced. If UPLO = 'L', the */
  65. /* leading n-by-n lower triangular part of A contains the lower */
  66. /* triangular part of the matrix A, and the strictly upper */
  67. /* triangular part of A is not referenced. */
  68. /* On exit, if UPLO = 'U', the diagonal and first superdiagonal */
  69. /* of A are overwritten by the corresponding elements of the */
  70. /* tridiagonal matrix T, and the elements above the first */
  71. /* superdiagonal, with the array TAU, represent the orthogonal */
  72. /* matrix Q as a product of elementary reflectors; if UPLO */
  73. /* = 'L', the diagonal and first subdiagonal of A are over- */
  74. /* written by the corresponding elements of the tridiagonal */
  75. /* matrix T, and the elements below the first subdiagonal, with */
  76. /* the array TAU, represent the orthogonal matrix Q as a product */
  77. /* of elementary reflectors. See Further Details. */
  78. /* LDA (input) INTEGER */
  79. /* The leading dimension of the array A. LDA >= max(1,N). */
  80. /* D (output) DOUBLE PRECISION array, dimension (N) */
  81. /* The diagonal elements of the tridiagonal matrix T: */
  82. /* D(i) = A(i,i). */
  83. /* E (output) DOUBLE PRECISION array, dimension (N-1) */
  84. /* The off-diagonal elements of the tridiagonal matrix T: */
  85. /* E(i) = A(i,i+1) if UPLO = 'U', E(i) = A(i+1,i) if UPLO = 'L'. */
  86. /* TAU (output) DOUBLE PRECISION array, dimension (N-1) */
  87. /* The scalar factors of the elementary reflectors (see Further */
  88. /* Details). */
  89. /* INFO (output) INTEGER */
  90. /* = 0: successful exit */
  91. /* < 0: if INFO = -i, the i-th argument had an illegal value. */
  92. /* Further Details */
  93. /* =============== */
  94. /* If UPLO = 'U', the matrix Q is represented as a product of elementary */
  95. /* reflectors */
  96. /* Q = H(n-1) . . . H(2) H(1). */
  97. /* Each H(i) has the form */
  98. /* H(i) = I - tau * v * v' */
  99. /* where tau is a real scalar, and v is a real vector with */
  100. /* v(i+1:n) = 0 and v(i) = 1; v(1:i-1) is stored on exit in */
  101. /* A(1:i-1,i+1), and tau in TAU(i). */
  102. /* If UPLO = 'L', the matrix Q is represented as a product of elementary */
  103. /* reflectors */
  104. /* Q = H(1) H(2) . . . H(n-1). */
  105. /* Each H(i) has the form */
  106. /* H(i) = I - tau * v * v' */
  107. /* where tau is a real scalar, and v is a real vector with */
  108. /* v(1:i) = 0 and v(i+1) = 1; v(i+2:n) is stored on exit in A(i+2:n,i), */
  109. /* and tau in TAU(i). */
  110. /* The contents of A on exit are illustrated by the following examples */
  111. /* with n = 5: */
  112. /* if UPLO = 'U': if UPLO = 'L': */
  113. /* ( d e v2 v3 v4 ) ( d ) */
  114. /* ( d e v3 v4 ) ( e d ) */
  115. /* ( d e v4 ) ( v1 e d ) */
  116. /* ( d e ) ( v1 v2 e d ) */
  117. /* ( d ) ( v1 v2 v3 e d ) */
  118. /* where d and e denote diagonal and off-diagonal elements of T, and vi */
  119. /* denotes an element of the vector defining H(i). */
  120. /* ===================================================================== */
  121. /* .. Parameters .. */
  122. /* .. */
  123. /* .. Local Scalars .. */
  124. /* .. */
  125. /* .. External Subroutines .. */
  126. /* .. */
  127. /* .. External Functions .. */
  128. /* .. */
  129. /* .. Intrinsic Functions .. */
  130. /* .. */
  131. /* .. Executable Statements .. */
  132. /* Test the input parameters */
  133. /* Parameter adjustments */
  134. a_dim1 = *lda;
  135. a_offset = 1 + a_dim1;
  136. a -= a_offset;
  137. --d__;
  138. --e;
  139. --tau;
  140. /* Function Body */
  141. *info = 0;
  142. upper = _starpu_lsame_(uplo, "U");
  143. if (! upper && ! _starpu_lsame_(uplo, "L")) {
  144. *info = -1;
  145. } else if (*n < 0) {
  146. *info = -2;
  147. } else if (*lda < max(1,*n)) {
  148. *info = -4;
  149. }
  150. if (*info != 0) {
  151. i__1 = -(*info);
  152. _starpu_xerbla_("DSYTD2", &i__1);
  153. return 0;
  154. }
  155. /* Quick return if possible */
  156. if (*n <= 0) {
  157. return 0;
  158. }
  159. if (upper) {
  160. /* Reduce the upper triangle of A */
  161. for (i__ = *n - 1; i__ >= 1; --i__) {
  162. /* Generate elementary reflector H(i) = I - tau * v * v' */
  163. /* to annihilate A(1:i-1,i+1) */
  164. _starpu_dlarfg_(&i__, &a[i__ + (i__ + 1) * a_dim1], &a[(i__ + 1) * a_dim1
  165. + 1], &c__1, &taui);
  166. e[i__] = a[i__ + (i__ + 1) * a_dim1];
  167. if (taui != 0.) {
  168. /* Apply H(i) from both sides to A(1:i,1:i) */
  169. a[i__ + (i__ + 1) * a_dim1] = 1.;
  170. /* Compute x := tau * A * v storing x in TAU(1:i) */
  171. _starpu_dsymv_(uplo, &i__, &taui, &a[a_offset], lda, &a[(i__ + 1) *
  172. a_dim1 + 1], &c__1, &c_b8, &tau[1], &c__1);
  173. /* Compute w := x - 1/2 * tau * (x'*v) * v */
  174. alpha = taui * -.5 * _starpu_ddot_(&i__, &tau[1], &c__1, &a[(i__ + 1)
  175. * a_dim1 + 1], &c__1);
  176. _starpu_daxpy_(&i__, &alpha, &a[(i__ + 1) * a_dim1 + 1], &c__1, &tau[
  177. 1], &c__1);
  178. /* Apply the transformation as a rank-2 update: */
  179. /* A := A - v * w' - w * v' */
  180. _starpu_dsyr2_(uplo, &i__, &c_b14, &a[(i__ + 1) * a_dim1 + 1], &c__1,
  181. &tau[1], &c__1, &a[a_offset], lda);
  182. a[i__ + (i__ + 1) * a_dim1] = e[i__];
  183. }
  184. d__[i__ + 1] = a[i__ + 1 + (i__ + 1) * a_dim1];
  185. tau[i__] = taui;
  186. /* L10: */
  187. }
  188. d__[1] = a[a_dim1 + 1];
  189. } else {
  190. /* Reduce the lower triangle of A */
  191. i__1 = *n - 1;
  192. for (i__ = 1; i__ <= i__1; ++i__) {
  193. /* Generate elementary reflector H(i) = I - tau * v * v' */
  194. /* to annihilate A(i+2:n,i) */
  195. i__2 = *n - i__;
  196. /* Computing MIN */
  197. i__3 = i__ + 2;
  198. _starpu_dlarfg_(&i__2, &a[i__ + 1 + i__ * a_dim1], &a[min(i__3, *n)+ i__ *
  199. a_dim1], &c__1, &taui);
  200. e[i__] = a[i__ + 1 + i__ * a_dim1];
  201. if (taui != 0.) {
  202. /* Apply H(i) from both sides to A(i+1:n,i+1:n) */
  203. a[i__ + 1 + i__ * a_dim1] = 1.;
  204. /* Compute x := tau * A * v storing y in TAU(i:n-1) */
  205. i__2 = *n - i__;
  206. _starpu_dsymv_(uplo, &i__2, &taui, &a[i__ + 1 + (i__ + 1) * a_dim1],
  207. lda, &a[i__ + 1 + i__ * a_dim1], &c__1, &c_b8, &tau[
  208. i__], &c__1);
  209. /* Compute w := x - 1/2 * tau * (x'*v) * v */
  210. i__2 = *n - i__;
  211. alpha = taui * -.5 * _starpu_ddot_(&i__2, &tau[i__], &c__1, &a[i__ +
  212. 1 + i__ * a_dim1], &c__1);
  213. i__2 = *n - i__;
  214. _starpu_daxpy_(&i__2, &alpha, &a[i__ + 1 + i__ * a_dim1], &c__1, &tau[
  215. i__], &c__1);
  216. /* Apply the transformation as a rank-2 update: */
  217. /* A := A - v * w' - w * v' */
  218. i__2 = *n - i__;
  219. _starpu_dsyr2_(uplo, &i__2, &c_b14, &a[i__ + 1 + i__ * a_dim1], &c__1,
  220. &tau[i__], &c__1, &a[i__ + 1 + (i__ + 1) * a_dim1],
  221. lda);
  222. a[i__ + 1 + i__ * a_dim1] = e[i__];
  223. }
  224. d__[i__] = a[i__ + i__ * a_dim1];
  225. tau[i__] = taui;
  226. /* L20: */
  227. }
  228. d__[*n] = a[*n + *n * a_dim1];
  229. }
  230. return 0;
  231. /* End of DSYTD2 */
  232. } /* _starpu_dsytd2_ */