dsptrd.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /* dsptrd.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_dsptrd_(char *uplo, integer *n, doublereal *ap,
  18. doublereal *d__, doublereal *e, doublereal *tau, integer *info)
  19. {
  20. /* System generated locals */
  21. integer i__1, i__2;
  22. /* Local variables */
  23. integer i__, i1, ii, i1i1;
  24. extern doublereal _starpu_ddot_(integer *, doublereal *, integer *, doublereal *,
  25. integer *);
  26. doublereal taui;
  27. extern /* Subroutine */ int _starpu_dspr2_(char *, integer *, doublereal *,
  28. doublereal *, integer *, doublereal *, integer *, doublereal *);
  29. doublereal alpha;
  30. extern logical _starpu_lsame_(char *, char *);
  31. extern /* Subroutine */ int _starpu_daxpy_(integer *, doublereal *, doublereal *,
  32. integer *, doublereal *, integer *), _starpu_dspmv_(char *, integer *,
  33. doublereal *, doublereal *, doublereal *, integer *, doublereal *,
  34. doublereal *, integer *);
  35. logical upper;
  36. extern /* Subroutine */ int _starpu_dlarfg_(integer *, doublereal *, doublereal *,
  37. integer *, doublereal *), _starpu_xerbla_(char *, integer *);
  38. /* -- LAPACK routine (version 3.2) -- */
  39. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  40. /* November 2006 */
  41. /* .. Scalar Arguments .. */
  42. /* .. */
  43. /* .. Array Arguments .. */
  44. /* .. */
  45. /* Purpose */
  46. /* ======= */
  47. /* DSPTRD reduces a real symmetric matrix A stored in packed form to */
  48. /* symmetric tridiagonal form T by an orthogonal similarity */
  49. /* transformation: Q**T * A * Q = T. */
  50. /* Arguments */
  51. /* ========= */
  52. /* UPLO (input) CHARACTER*1 */
  53. /* = 'U': Upper triangle of A is stored; */
  54. /* = 'L': Lower triangle of A is stored. */
  55. /* N (input) INTEGER */
  56. /* The order of the matrix A. N >= 0. */
  57. /* AP (input/output) DOUBLE PRECISION array, dimension (N*(N+1)/2) */
  58. /* On entry, the upper or lower triangle of the symmetric matrix */
  59. /* A, packed columnwise in a linear array. The j-th column of A */
  60. /* is stored in the array AP as follows: */
  61. /* if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
  62. /* if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */
  63. /* On exit, if UPLO = 'U', the diagonal and first superdiagonal */
  64. /* of A are overwritten by the corresponding elements of the */
  65. /* tridiagonal matrix T, and the elements above the first */
  66. /* superdiagonal, with the array TAU, represent the orthogonal */
  67. /* matrix Q as a product of elementary reflectors; if UPLO */
  68. /* = 'L', the diagonal and first subdiagonal of A are over- */
  69. /* written by the corresponding elements of the tridiagonal */
  70. /* matrix T, and the elements below the first subdiagonal, with */
  71. /* the array TAU, represent the orthogonal matrix Q as a product */
  72. /* of elementary reflectors. See Further Details. */
  73. /* D (output) DOUBLE PRECISION array, dimension (N) */
  74. /* The diagonal elements of the tridiagonal matrix T: */
  75. /* D(i) = A(i,i). */
  76. /* E (output) DOUBLE PRECISION array, dimension (N-1) */
  77. /* The off-diagonal elements of the tridiagonal matrix T: */
  78. /* E(i) = A(i,i+1) if UPLO = 'U', E(i) = A(i+1,i) if UPLO = 'L'. */
  79. /* TAU (output) DOUBLE PRECISION array, dimension (N-1) */
  80. /* The scalar factors of the elementary reflectors (see Further */
  81. /* Details). */
  82. /* INFO (output) INTEGER */
  83. /* = 0: successful exit */
  84. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  85. /* Further Details */
  86. /* =============== */
  87. /* If UPLO = 'U', the matrix Q is represented as a product of elementary */
  88. /* reflectors */
  89. /* Q = H(n-1) . . . H(2) H(1). */
  90. /* Each H(i) has the form */
  91. /* H(i) = I - tau * v * v' */
  92. /* where tau is a real scalar, and v is a real vector with */
  93. /* v(i+1:n) = 0 and v(i) = 1; v(1:i-1) is stored on exit in AP, */
  94. /* overwriting A(1:i-1,i+1), and tau is stored in TAU(i). */
  95. /* If UPLO = 'L', the matrix Q is represented as a product of elementary */
  96. /* reflectors */
  97. /* Q = H(1) H(2) . . . H(n-1). */
  98. /* Each H(i) has the form */
  99. /* H(i) = I - tau * v * v' */
  100. /* where tau is a real scalar, and v is a real vector with */
  101. /* v(1:i) = 0 and v(i+1) = 1; v(i+2:n) is stored on exit in AP, */
  102. /* overwriting A(i+2:n,i), and tau is stored in TAU(i). */
  103. /* ===================================================================== */
  104. /* .. Parameters .. */
  105. /* .. */
  106. /* .. Local Scalars .. */
  107. /* .. */
  108. /* .. External Subroutines .. */
  109. /* .. */
  110. /* .. External Functions .. */
  111. /* .. */
  112. /* .. Executable Statements .. */
  113. /* Test the input parameters */
  114. /* Parameter adjustments */
  115. --tau;
  116. --e;
  117. --d__;
  118. --ap;
  119. /* Function Body */
  120. *info = 0;
  121. upper = _starpu_lsame_(uplo, "U");
  122. if (! upper && ! _starpu_lsame_(uplo, "L")) {
  123. *info = -1;
  124. } else if (*n < 0) {
  125. *info = -2;
  126. }
  127. if (*info != 0) {
  128. i__1 = -(*info);
  129. _starpu_xerbla_("DSPTRD", &i__1);
  130. return 0;
  131. }
  132. /* Quick return if possible */
  133. if (*n <= 0) {
  134. return 0;
  135. }
  136. if (upper) {
  137. /* Reduce the upper triangle of A. */
  138. /* I1 is the index in AP of A(1,I+1). */
  139. i1 = *n * (*n - 1) / 2 + 1;
  140. for (i__ = *n - 1; i__ >= 1; --i__) {
  141. /* Generate elementary reflector H(i) = I - tau * v * v' */
  142. /* to annihilate A(1:i-1,i+1) */
  143. _starpu_dlarfg_(&i__, &ap[i1 + i__ - 1], &ap[i1], &c__1, &taui);
  144. e[i__] = ap[i1 + i__ - 1];
  145. if (taui != 0.) {
  146. /* Apply H(i) from both sides to A(1:i,1:i) */
  147. ap[i1 + i__ - 1] = 1.;
  148. /* Compute y := tau * A * v storing y in TAU(1:i) */
  149. _starpu_dspmv_(uplo, &i__, &taui, &ap[1], &ap[i1], &c__1, &c_b8, &tau[
  150. 1], &c__1);
  151. /* Compute w := y - 1/2 * tau * (y'*v) * v */
  152. alpha = taui * -.5 * _starpu_ddot_(&i__, &tau[1], &c__1, &ap[i1], &
  153. c__1);
  154. _starpu_daxpy_(&i__, &alpha, &ap[i1], &c__1, &tau[1], &c__1);
  155. /* Apply the transformation as a rank-2 update: */
  156. /* A := A - v * w' - w * v' */
  157. _starpu_dspr2_(uplo, &i__, &c_b14, &ap[i1], &c__1, &tau[1], &c__1, &
  158. ap[1]);
  159. ap[i1 + i__ - 1] = e[i__];
  160. }
  161. d__[i__ + 1] = ap[i1 + i__];
  162. tau[i__] = taui;
  163. i1 -= i__;
  164. /* L10: */
  165. }
  166. d__[1] = ap[1];
  167. } else {
  168. /* Reduce the lower triangle of A. II is the index in AP of */
  169. /* A(i,i) and I1I1 is the index of A(i+1,i+1). */
  170. ii = 1;
  171. i__1 = *n - 1;
  172. for (i__ = 1; i__ <= i__1; ++i__) {
  173. i1i1 = ii + *n - i__ + 1;
  174. /* Generate elementary reflector H(i) = I - tau * v * v' */
  175. /* to annihilate A(i+2:n,i) */
  176. i__2 = *n - i__;
  177. _starpu_dlarfg_(&i__2, &ap[ii + 1], &ap[ii + 2], &c__1, &taui);
  178. e[i__] = ap[ii + 1];
  179. if (taui != 0.) {
  180. /* Apply H(i) from both sides to A(i+1:n,i+1:n) */
  181. ap[ii + 1] = 1.;
  182. /* Compute y := tau * A * v storing y in TAU(i:n-1) */
  183. i__2 = *n - i__;
  184. _starpu_dspmv_(uplo, &i__2, &taui, &ap[i1i1], &ap[ii + 1], &c__1, &
  185. c_b8, &tau[i__], &c__1);
  186. /* Compute w := y - 1/2 * tau * (y'*v) * v */
  187. i__2 = *n - i__;
  188. alpha = taui * -.5 * _starpu_ddot_(&i__2, &tau[i__], &c__1, &ap[ii +
  189. 1], &c__1);
  190. i__2 = *n - i__;
  191. _starpu_daxpy_(&i__2, &alpha, &ap[ii + 1], &c__1, &tau[i__], &c__1);
  192. /* Apply the transformation as a rank-2 update: */
  193. /* A := A - v * w' - w * v' */
  194. i__2 = *n - i__;
  195. _starpu_dspr2_(uplo, &i__2, &c_b14, &ap[ii + 1], &c__1, &tau[i__], &
  196. c__1, &ap[i1i1]);
  197. ap[ii + 1] = e[i__];
  198. }
  199. d__[i__] = ap[ii];
  200. tau[i__] = taui;
  201. ii = i1i1;
  202. /* L20: */
  203. }
  204. d__[*n] = ap[ii];
  205. }
  206. return 0;
  207. /* End of DSPTRD */
  208. } /* _starpu_dsptrd_ */