dgghrd.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /* dgghrd.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_b10 = 0.;
  15. static doublereal c_b11 = 1.;
  16. static integer c__1 = 1;
  17. /* Subroutine */ int _starpu_dgghrd_(char *compq, char *compz, integer *n, integer *
  18. ilo, integer *ihi, doublereal *a, integer *lda, doublereal *b,
  19. integer *ldb, doublereal *q, integer *ldq, doublereal *z__, integer *
  20. ldz, integer *info)
  21. {
  22. /* System generated locals */
  23. integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, z_dim1,
  24. z_offset, i__1, i__2, i__3;
  25. /* Local variables */
  26. doublereal c__, s;
  27. logical ilq, ilz;
  28. integer jcol;
  29. doublereal temp;
  30. extern /* Subroutine */ int _starpu_drot_(integer *, doublereal *, integer *,
  31. doublereal *, integer *, doublereal *, doublereal *);
  32. integer jrow;
  33. extern logical _starpu_lsame_(char *, char *);
  34. extern /* Subroutine */ int _starpu_dlaset_(char *, integer *, integer *,
  35. doublereal *, doublereal *, doublereal *, integer *),
  36. _starpu_dlartg_(doublereal *, doublereal *, doublereal *, doublereal *,
  37. doublereal *), _starpu_xerbla_(char *, integer *);
  38. integer icompq, icompz;
  39. /* -- LAPACK routine (version 3.2) -- */
  40. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  41. /* November 2006 */
  42. /* .. Scalar Arguments .. */
  43. /* .. */
  44. /* .. Array Arguments .. */
  45. /* .. */
  46. /* Purpose */
  47. /* ======= */
  48. /* DGGHRD reduces a pair of real matrices (A,B) to generalized upper */
  49. /* Hessenberg form using orthogonal transformations, where A is a */
  50. /* general matrix and B is upper triangular. The form of the */
  51. /* generalized eigenvalue problem is */
  52. /* A*x = lambda*B*x, */
  53. /* and B is typically made upper triangular by computing its QR */
  54. /* factorization and moving the orthogonal matrix Q to the left side */
  55. /* of the equation. */
  56. /* This subroutine simultaneously reduces A to a Hessenberg matrix H: */
  57. /* Q**T*A*Z = H */
  58. /* and transforms B to another upper triangular matrix T: */
  59. /* Q**T*B*Z = T */
  60. /* in order to reduce the problem to its standard form */
  61. /* H*y = lambda*T*y */
  62. /* where y = Z**T*x. */
  63. /* The orthogonal matrices Q and Z are determined as products of Givens */
  64. /* rotations. They may either be formed explicitly, or they may be */
  65. /* postmultiplied into input matrices Q1 and Z1, so that */
  66. /* Q1 * A * Z1**T = (Q1*Q) * H * (Z1*Z)**T */
  67. /* Q1 * B * Z1**T = (Q1*Q) * T * (Z1*Z)**T */
  68. /* If Q1 is the orthogonal matrix from the QR factorization of B in the */
  69. /* original equation A*x = lambda*B*x, then DGGHRD reduces the original */
  70. /* problem to generalized Hessenberg form. */
  71. /* Arguments */
  72. /* ========= */
  73. /* COMPQ (input) CHARACTER*1 */
  74. /* = 'N': do not compute Q; */
  75. /* = 'I': Q is initialized to the unit matrix, and the */
  76. /* orthogonal matrix Q is returned; */
  77. /* = 'V': Q must contain an orthogonal matrix Q1 on entry, */
  78. /* and the product Q1*Q is returned. */
  79. /* COMPZ (input) CHARACTER*1 */
  80. /* = 'N': do not compute Z; */
  81. /* = 'I': Z is initialized to the unit matrix, and the */
  82. /* orthogonal matrix Z is returned; */
  83. /* = 'V': Z must contain an orthogonal matrix Z1 on entry, */
  84. /* and the product Z1*Z is returned. */
  85. /* N (input) INTEGER */
  86. /* The order of the matrices A and B. N >= 0. */
  87. /* ILO (input) INTEGER */
  88. /* IHI (input) INTEGER */
  89. /* ILO and IHI mark the rows and columns of A which are to be */
  90. /* reduced. It is assumed that A is already upper triangular */
  91. /* in rows and columns 1:ILO-1 and IHI+1:N. ILO and IHI are */
  92. /* normally set by a previous call to SGGBAL; otherwise they */
  93. /* should be set to 1 and N respectively. */
  94. /* 1 <= ILO <= IHI <= N, if N > 0; ILO=1 and IHI=0, if N=0. */
  95. /* A (input/output) DOUBLE PRECISION array, dimension (LDA, N) */
  96. /* On entry, the N-by-N general matrix to be reduced. */
  97. /* On exit, the upper triangle and the first subdiagonal of A */
  98. /* are overwritten with the upper Hessenberg matrix H, and the */
  99. /* rest is set to zero. */
  100. /* LDA (input) INTEGER */
  101. /* The leading dimension of the array A. LDA >= max(1,N). */
  102. /* B (input/output) DOUBLE PRECISION array, dimension (LDB, N) */
  103. /* On entry, the N-by-N upper triangular matrix B. */
  104. /* On exit, the upper triangular matrix T = Q**T B Z. The */
  105. /* elements below the diagonal are set to zero. */
  106. /* LDB (input) INTEGER */
  107. /* The leading dimension of the array B. LDB >= max(1,N). */
  108. /* Q (input/output) DOUBLE PRECISION array, dimension (LDQ, N) */
  109. /* On entry, if COMPQ = 'V', the orthogonal matrix Q1, */
  110. /* typically from the QR factorization of B. */
  111. /* On exit, if COMPQ='I', the orthogonal matrix Q, and if */
  112. /* COMPQ = 'V', the product Q1*Q. */
  113. /* Not referenced if COMPQ='N'. */
  114. /* LDQ (input) INTEGER */
  115. /* The leading dimension of the array Q. */
  116. /* LDQ >= N if COMPQ='V' or 'I'; LDQ >= 1 otherwise. */
  117. /* Z (input/output) DOUBLE PRECISION array, dimension (LDZ, N) */
  118. /* On entry, if COMPZ = 'V', the orthogonal matrix Z1. */
  119. /* On exit, if COMPZ='I', the orthogonal matrix Z, and if */
  120. /* COMPZ = 'V', the product Z1*Z. */
  121. /* Not referenced if COMPZ='N'. */
  122. /* LDZ (input) INTEGER */
  123. /* The leading dimension of the array Z. */
  124. /* LDZ >= N if COMPZ='V' or 'I'; LDZ >= 1 otherwise. */
  125. /* INFO (output) INTEGER */
  126. /* = 0: successful exit. */
  127. /* < 0: if INFO = -i, the i-th argument had an illegal value. */
  128. /* Further Details */
  129. /* =============== */
  130. /* This routine reduces A to Hessenberg and B to triangular form by */
  131. /* an unblocked reduction, as described in _Matrix_Computations_, */
  132. /* by Golub and Van Loan (Johns Hopkins Press.) */
  133. /* ===================================================================== */
  134. /* .. Parameters .. */
  135. /* .. */
  136. /* .. Local Scalars .. */
  137. /* .. */
  138. /* .. External Functions .. */
  139. /* .. */
  140. /* .. External Subroutines .. */
  141. /* .. */
  142. /* .. Intrinsic Functions .. */
  143. /* .. */
  144. /* .. Executable Statements .. */
  145. /* Decode COMPQ */
  146. /* Parameter adjustments */
  147. a_dim1 = *lda;
  148. a_offset = 1 + a_dim1;
  149. a -= a_offset;
  150. b_dim1 = *ldb;
  151. b_offset = 1 + b_dim1;
  152. b -= b_offset;
  153. q_dim1 = *ldq;
  154. q_offset = 1 + q_dim1;
  155. q -= q_offset;
  156. z_dim1 = *ldz;
  157. z_offset = 1 + z_dim1;
  158. z__ -= z_offset;
  159. /* Function Body */
  160. if (_starpu_lsame_(compq, "N")) {
  161. ilq = FALSE_;
  162. icompq = 1;
  163. } else if (_starpu_lsame_(compq, "V")) {
  164. ilq = TRUE_;
  165. icompq = 2;
  166. } else if (_starpu_lsame_(compq, "I")) {
  167. ilq = TRUE_;
  168. icompq = 3;
  169. } else {
  170. icompq = 0;
  171. }
  172. /* Decode COMPZ */
  173. if (_starpu_lsame_(compz, "N")) {
  174. ilz = FALSE_;
  175. icompz = 1;
  176. } else if (_starpu_lsame_(compz, "V")) {
  177. ilz = TRUE_;
  178. icompz = 2;
  179. } else if (_starpu_lsame_(compz, "I")) {
  180. ilz = TRUE_;
  181. icompz = 3;
  182. } else {
  183. icompz = 0;
  184. }
  185. /* Test the input parameters. */
  186. *info = 0;
  187. if (icompq <= 0) {
  188. *info = -1;
  189. } else if (icompz <= 0) {
  190. *info = -2;
  191. } else if (*n < 0) {
  192. *info = -3;
  193. } else if (*ilo < 1) {
  194. *info = -4;
  195. } else if (*ihi > *n || *ihi < *ilo - 1) {
  196. *info = -5;
  197. } else if (*lda < max(1,*n)) {
  198. *info = -7;
  199. } else if (*ldb < max(1,*n)) {
  200. *info = -9;
  201. } else if (ilq && *ldq < *n || *ldq < 1) {
  202. *info = -11;
  203. } else if (ilz && *ldz < *n || *ldz < 1) {
  204. *info = -13;
  205. }
  206. if (*info != 0) {
  207. i__1 = -(*info);
  208. _starpu_xerbla_("DGGHRD", &i__1);
  209. return 0;
  210. }
  211. /* Initialize Q and Z if desired. */
  212. if (icompq == 3) {
  213. _starpu_dlaset_("Full", n, n, &c_b10, &c_b11, &q[q_offset], ldq);
  214. }
  215. if (icompz == 3) {
  216. _starpu_dlaset_("Full", n, n, &c_b10, &c_b11, &z__[z_offset], ldz);
  217. }
  218. /* Quick return if possible */
  219. if (*n <= 1) {
  220. return 0;
  221. }
  222. /* Zero out lower triangle of B */
  223. i__1 = *n - 1;
  224. for (jcol = 1; jcol <= i__1; ++jcol) {
  225. i__2 = *n;
  226. for (jrow = jcol + 1; jrow <= i__2; ++jrow) {
  227. b[jrow + jcol * b_dim1] = 0.;
  228. /* L10: */
  229. }
  230. /* L20: */
  231. }
  232. /* Reduce A and B */
  233. i__1 = *ihi - 2;
  234. for (jcol = *ilo; jcol <= i__1; ++jcol) {
  235. i__2 = jcol + 2;
  236. for (jrow = *ihi; jrow >= i__2; --jrow) {
  237. /* Step 1: rotate rows JROW-1, JROW to kill A(JROW,JCOL) */
  238. temp = a[jrow - 1 + jcol * a_dim1];
  239. _starpu_dlartg_(&temp, &a[jrow + jcol * a_dim1], &c__, &s, &a[jrow - 1 +
  240. jcol * a_dim1]);
  241. a[jrow + jcol * a_dim1] = 0.;
  242. i__3 = *n - jcol;
  243. _starpu_drot_(&i__3, &a[jrow - 1 + (jcol + 1) * a_dim1], lda, &a[jrow + (
  244. jcol + 1) * a_dim1], lda, &c__, &s);
  245. i__3 = *n + 2 - jrow;
  246. _starpu_drot_(&i__3, &b[jrow - 1 + (jrow - 1) * b_dim1], ldb, &b[jrow + (
  247. jrow - 1) * b_dim1], ldb, &c__, &s);
  248. if (ilq) {
  249. _starpu_drot_(n, &q[(jrow - 1) * q_dim1 + 1], &c__1, &q[jrow * q_dim1
  250. + 1], &c__1, &c__, &s);
  251. }
  252. /* Step 2: rotate columns JROW, JROW-1 to kill B(JROW,JROW-1) */
  253. temp = b[jrow + jrow * b_dim1];
  254. _starpu_dlartg_(&temp, &b[jrow + (jrow - 1) * b_dim1], &c__, &s, &b[jrow
  255. + jrow * b_dim1]);
  256. b[jrow + (jrow - 1) * b_dim1] = 0.;
  257. _starpu_drot_(ihi, &a[jrow * a_dim1 + 1], &c__1, &a[(jrow - 1) * a_dim1 +
  258. 1], &c__1, &c__, &s);
  259. i__3 = jrow - 1;
  260. _starpu_drot_(&i__3, &b[jrow * b_dim1 + 1], &c__1, &b[(jrow - 1) * b_dim1
  261. + 1], &c__1, &c__, &s);
  262. if (ilz) {
  263. _starpu_drot_(n, &z__[jrow * z_dim1 + 1], &c__1, &z__[(jrow - 1) *
  264. z_dim1 + 1], &c__1, &c__, &s);
  265. }
  266. /* L30: */
  267. }
  268. /* L40: */
  269. }
  270. return 0;
  271. /* End of DGGHRD */
  272. } /* _starpu_dgghrd_ */