dlahr2.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /* dlahr2.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 doublereal c_b4 = -1.;
  15. static doublereal c_b5 = 1.;
  16. static integer c__1 = 1;
  17. static doublereal c_b38 = 0.;
  18. /* Subroutine */ int dlahr2_(integer *n, integer *k, integer *nb, doublereal *
  19. a, integer *lda, doublereal *tau, doublereal *t, integer *ldt,
  20. doublereal *y, integer *ldy)
  21. {
  22. /* System generated locals */
  23. integer a_dim1, a_offset, t_dim1, t_offset, y_dim1, y_offset, i__1, i__2,
  24. i__3;
  25. doublereal d__1;
  26. /* Local variables */
  27. integer i__;
  28. doublereal ei;
  29. extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
  30. integer *), dgemm_(char *, char *, integer *, integer *, integer *
  31. , doublereal *, doublereal *, integer *, doublereal *, integer *,
  32. doublereal *, doublereal *, integer *), dgemv_(
  33. char *, integer *, integer *, doublereal *, doublereal *, integer
  34. *, doublereal *, integer *, doublereal *, doublereal *, integer *), dcopy_(integer *, doublereal *, integer *, doublereal *,
  35. integer *), dtrmm_(char *, char *, char *, char *, integer *,
  36. integer *, doublereal *, doublereal *, integer *, doublereal *,
  37. integer *), daxpy_(integer *,
  38. doublereal *, doublereal *, integer *, doublereal *, integer *),
  39. dtrmv_(char *, char *, char *, integer *, doublereal *, integer *,
  40. doublereal *, integer *), dlarfg_(
  41. integer *, doublereal *, doublereal *, integer *, doublereal *),
  42. dlacpy_(char *, integer *, integer *, doublereal *, integer *,
  43. doublereal *, integer *);
  44. /* -- LAPACK auxiliary routine (version 3.2) -- */
  45. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  46. /* November 2006 */
  47. /* .. Scalar Arguments .. */
  48. /* .. */
  49. /* .. Array Arguments .. */
  50. /* .. */
  51. /* Purpose */
  52. /* ======= */
  53. /* DLAHR2 reduces the first NB columns of A real general n-BY-(n-k+1) */
  54. /* matrix A so that elements below the k-th subdiagonal are zero. The */
  55. /* reduction is performed by an orthogonal similarity transformation */
  56. /* Q' * A * Q. The routine returns the matrices V and T which determine */
  57. /* Q as a block reflector I - V*T*V', and also the matrix Y = A * V * T. */
  58. /* This is an auxiliary routine called by DGEHRD. */
  59. /* Arguments */
  60. /* ========= */
  61. /* N (input) INTEGER */
  62. /* The order of the matrix A. */
  63. /* K (input) INTEGER */
  64. /* The offset for the reduction. Elements below the k-th */
  65. /* subdiagonal in the first NB columns are reduced to zero. */
  66. /* K < N. */
  67. /* NB (input) INTEGER */
  68. /* The number of columns to be reduced. */
  69. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N-K+1) */
  70. /* On entry, the n-by-(n-k+1) general matrix A. */
  71. /* On exit, the elements on and above the k-th subdiagonal in */
  72. /* the first NB columns are overwritten with the corresponding */
  73. /* elements of the reduced matrix; the elements below the k-th */
  74. /* subdiagonal, with the array TAU, represent the matrix Q as a */
  75. /* product of elementary reflectors. The other columns of A are */
  76. /* unchanged. See Further Details. */
  77. /* LDA (input) INTEGER */
  78. /* The leading dimension of the array A. LDA >= max(1,N). */
  79. /* TAU (output) DOUBLE PRECISION array, dimension (NB) */
  80. /* The scalar factors of the elementary reflectors. See Further */
  81. /* Details. */
  82. /* T (output) DOUBLE PRECISION array, dimension (LDT,NB) */
  83. /* The upper triangular matrix T. */
  84. /* LDT (input) INTEGER */
  85. /* The leading dimension of the array T. LDT >= NB. */
  86. /* Y (output) DOUBLE PRECISION array, dimension (LDY,NB) */
  87. /* The n-by-nb matrix Y. */
  88. /* LDY (input) INTEGER */
  89. /* The leading dimension of the array Y. LDY >= N. */
  90. /* Further Details */
  91. /* =============== */
  92. /* The matrix Q is represented as a product of nb elementary reflectors */
  93. /* Q = H(1) H(2) . . . H(nb). */
  94. /* Each H(i) has the form */
  95. /* H(i) = I - tau * v * v' */
  96. /* where tau is a real scalar, and v is a real vector with */
  97. /* v(1:i+k-1) = 0, v(i+k) = 1; v(i+k+1:n) is stored on exit in */
  98. /* A(i+k+1:n,i), and tau in TAU(i). */
  99. /* The elements of the vectors v together form the (n-k+1)-by-nb matrix */
  100. /* V which is needed, with T and Y, to apply the transformation to the */
  101. /* unreduced part of the matrix, using an update of the form: */
  102. /* A := (I - V*T*V') * (A - Y*V'). */
  103. /* The contents of A on exit are illustrated by the following example */
  104. /* with n = 7, k = 3 and nb = 2: */
  105. /* ( a a a a a ) */
  106. /* ( a a a a a ) */
  107. /* ( a a a a a ) */
  108. /* ( h h a a a ) */
  109. /* ( v1 h a a a ) */
  110. /* ( v1 v2 a a a ) */
  111. /* ( v1 v2 a a a ) */
  112. /* where a denotes an element of the original matrix A, h denotes a */
  113. /* modified element of the upper Hessenberg matrix H, and vi denotes an */
  114. /* element of the vector defining H(i). */
  115. /* This file is a slight modification of LAPACK-3.0's DLAHRD */
  116. /* incorporating improvements proposed by Quintana-Orti and Van de */
  117. /* Gejin. Note that the entries of A(1:K,2:NB) differ from those */
  118. /* returned by the original LAPACK routine. This function is */
  119. /* not backward compatible with LAPACK3.0. */
  120. /* ===================================================================== */
  121. /* .. Parameters .. */
  122. /* .. */
  123. /* .. Local Scalars .. */
  124. /* .. */
  125. /* .. External Subroutines .. */
  126. /* .. */
  127. /* .. Intrinsic Functions .. */
  128. /* .. */
  129. /* .. Executable Statements .. */
  130. /* Quick return if possible */
  131. /* Parameter adjustments */
  132. --tau;
  133. a_dim1 = *lda;
  134. a_offset = 1 + a_dim1;
  135. a -= a_offset;
  136. t_dim1 = *ldt;
  137. t_offset = 1 + t_dim1;
  138. t -= t_offset;
  139. y_dim1 = *ldy;
  140. y_offset = 1 + y_dim1;
  141. y -= y_offset;
  142. /* Function Body */
  143. if (*n <= 1) {
  144. return 0;
  145. }
  146. i__1 = *nb;
  147. for (i__ = 1; i__ <= i__1; ++i__) {
  148. if (i__ > 1) {
  149. /* Update A(K+1:N,I) */
  150. /* Update I-th column of A - Y * V' */
  151. i__2 = *n - *k;
  152. i__3 = i__ - 1;
  153. dgemv_("NO TRANSPOSE", &i__2, &i__3, &c_b4, &y[*k + 1 + y_dim1],
  154. ldy, &a[*k + i__ - 1 + a_dim1], lda, &c_b5, &a[*k + 1 +
  155. i__ * a_dim1], &c__1);
  156. /* Apply I - V * T' * V' to this column (call it b) from the */
  157. /* left, using the last column of T as workspace */
  158. /* Let V = ( V1 ) and b = ( b1 ) (first I-1 rows) */
  159. /* ( V2 ) ( b2 ) */
  160. /* where V1 is unit lower triangular */
  161. /* w := V1' * b1 */
  162. i__2 = i__ - 1;
  163. dcopy_(&i__2, &a[*k + 1 + i__ * a_dim1], &c__1, &t[*nb * t_dim1 +
  164. 1], &c__1);
  165. i__2 = i__ - 1;
  166. dtrmv_("Lower", "Transpose", "UNIT", &i__2, &a[*k + 1 + a_dim1],
  167. lda, &t[*nb * t_dim1 + 1], &c__1);
  168. /* w := w + V2'*b2 */
  169. i__2 = *n - *k - i__ + 1;
  170. i__3 = i__ - 1;
  171. dgemv_("Transpose", &i__2, &i__3, &c_b5, &a[*k + i__ + a_dim1],
  172. lda, &a[*k + i__ + i__ * a_dim1], &c__1, &c_b5, &t[*nb *
  173. t_dim1 + 1], &c__1);
  174. /* w := T'*w */
  175. i__2 = i__ - 1;
  176. dtrmv_("Upper", "Transpose", "NON-UNIT", &i__2, &t[t_offset], ldt,
  177. &t[*nb * t_dim1 + 1], &c__1);
  178. /* b2 := b2 - V2*w */
  179. i__2 = *n - *k - i__ + 1;
  180. i__3 = i__ - 1;
  181. dgemv_("NO TRANSPOSE", &i__2, &i__3, &c_b4, &a[*k + i__ + a_dim1],
  182. lda, &t[*nb * t_dim1 + 1], &c__1, &c_b5, &a[*k + i__ +
  183. i__ * a_dim1], &c__1);
  184. /* b1 := b1 - V1*w */
  185. i__2 = i__ - 1;
  186. dtrmv_("Lower", "NO TRANSPOSE", "UNIT", &i__2, &a[*k + 1 + a_dim1]
  187. , lda, &t[*nb * t_dim1 + 1], &c__1);
  188. i__2 = i__ - 1;
  189. daxpy_(&i__2, &c_b4, &t[*nb * t_dim1 + 1], &c__1, &a[*k + 1 + i__
  190. * a_dim1], &c__1);
  191. a[*k + i__ - 1 + (i__ - 1) * a_dim1] = ei;
  192. }
  193. /* Generate the elementary reflector H(I) to annihilate */
  194. /* A(K+I+1:N,I) */
  195. i__2 = *n - *k - i__ + 1;
  196. /* Computing MIN */
  197. i__3 = *k + i__ + 1;
  198. dlarfg_(&i__2, &a[*k + i__ + i__ * a_dim1], &a[min(i__3, *n)+ i__ *
  199. a_dim1], &c__1, &tau[i__]);
  200. ei = a[*k + i__ + i__ * a_dim1];
  201. a[*k + i__ + i__ * a_dim1] = 1.;
  202. /* Compute Y(K+1:N,I) */
  203. i__2 = *n - *k;
  204. i__3 = *n - *k - i__ + 1;
  205. dgemv_("NO TRANSPOSE", &i__2, &i__3, &c_b5, &a[*k + 1 + (i__ + 1) *
  206. a_dim1], lda, &a[*k + i__ + i__ * a_dim1], &c__1, &c_b38, &y[*
  207. k + 1 + i__ * y_dim1], &c__1);
  208. i__2 = *n - *k - i__ + 1;
  209. i__3 = i__ - 1;
  210. dgemv_("Transpose", &i__2, &i__3, &c_b5, &a[*k + i__ + a_dim1], lda, &
  211. a[*k + i__ + i__ * a_dim1], &c__1, &c_b38, &t[i__ * t_dim1 +
  212. 1], &c__1);
  213. i__2 = *n - *k;
  214. i__3 = i__ - 1;
  215. dgemv_("NO TRANSPOSE", &i__2, &i__3, &c_b4, &y[*k + 1 + y_dim1], ldy,
  216. &t[i__ * t_dim1 + 1], &c__1, &c_b5, &y[*k + 1 + i__ * y_dim1],
  217. &c__1);
  218. i__2 = *n - *k;
  219. dscal_(&i__2, &tau[i__], &y[*k + 1 + i__ * y_dim1], &c__1);
  220. /* Compute T(1:I,I) */
  221. i__2 = i__ - 1;
  222. d__1 = -tau[i__];
  223. dscal_(&i__2, &d__1, &t[i__ * t_dim1 + 1], &c__1);
  224. i__2 = i__ - 1;
  225. dtrmv_("Upper", "No Transpose", "NON-UNIT", &i__2, &t[t_offset], ldt,
  226. &t[i__ * t_dim1 + 1], &c__1)
  227. ;
  228. t[i__ + i__ * t_dim1] = tau[i__];
  229. /* L10: */
  230. }
  231. a[*k + *nb + *nb * a_dim1] = ei;
  232. /* Compute Y(1:K,1:NB) */
  233. dlacpy_("ALL", k, nb, &a[(a_dim1 << 1) + 1], lda, &y[y_offset], ldy);
  234. dtrmm_("RIGHT", "Lower", "NO TRANSPOSE", "UNIT", k, nb, &c_b5, &a[*k + 1
  235. + a_dim1], lda, &y[y_offset], ldy);
  236. if (*n > *k + *nb) {
  237. i__1 = *n - *k - *nb;
  238. dgemm_("NO TRANSPOSE", "NO TRANSPOSE", k, nb, &i__1, &c_b5, &a[(*nb +
  239. 2) * a_dim1 + 1], lda, &a[*k + 1 + *nb + a_dim1], lda, &c_b5,
  240. &y[y_offset], ldy);
  241. }
  242. dtrmm_("RIGHT", "Upper", "NO TRANSPOSE", "NON-UNIT", k, nb, &c_b5, &t[
  243. t_offset], ldt, &y[y_offset], ldy);
  244. return 0;
  245. /* End of DLAHR2 */
  246. } /* dlahr2_ */