dlagv2.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. /* dlagv2.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__2 = 2;
  15. static integer c__1 = 1;
  16. /* Subroutine */ int _starpu_dlagv2_(doublereal *a, integer *lda, doublereal *b,
  17. integer *ldb, doublereal *alphar, doublereal *alphai, doublereal *
  18. beta, doublereal *csl, doublereal *snl, doublereal *csr, doublereal *
  19. snr)
  20. {
  21. /* System generated locals */
  22. integer a_dim1, a_offset, b_dim1, b_offset;
  23. doublereal d__1, d__2, d__3, d__4, d__5, d__6;
  24. /* Local variables */
  25. doublereal r__, t, h1, h2, h3, wi, qq, rr, wr1, wr2, ulp;
  26. extern /* Subroutine */ int _starpu_drot_(integer *, doublereal *, integer *,
  27. doublereal *, integer *, doublereal *, doublereal *), _starpu_dlag2_(
  28. doublereal *, integer *, doublereal *, integer *, doublereal *,
  29. doublereal *, doublereal *, doublereal *, doublereal *,
  30. doublereal *);
  31. doublereal anorm, bnorm, scale1, scale2;
  32. extern /* Subroutine */ int _starpu_dlasv2_(doublereal *, doublereal *,
  33. doublereal *, doublereal *, doublereal *, doublereal *,
  34. doublereal *, doublereal *, doublereal *);
  35. extern doublereal _starpu_dlapy2_(doublereal *, doublereal *);
  36. doublereal ascale, bscale;
  37. extern doublereal _starpu_dlamch_(char *);
  38. doublereal safmin;
  39. extern /* Subroutine */ int _starpu_dlartg_(doublereal *, doublereal *,
  40. doublereal *, doublereal *, doublereal *);
  41. /* -- LAPACK auxiliary routine (version 3.2) -- */
  42. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  43. /* November 2006 */
  44. /* .. Scalar Arguments .. */
  45. /* .. */
  46. /* .. Array Arguments .. */
  47. /* .. */
  48. /* Purpose */
  49. /* ======= */
  50. /* DLAGV2 computes the Generalized Schur factorization of a real 2-by-2 */
  51. /* matrix pencil (A,B) where B is upper triangular. This routine */
  52. /* computes orthogonal (rotation) matrices given by CSL, SNL and CSR, */
  53. /* SNR such that */
  54. /* 1) if the pencil (A,B) has two real eigenvalues (include 0/0 or 1/0 */
  55. /* types), then */
  56. /* [ a11 a12 ] := [ CSL SNL ] [ a11 a12 ] [ CSR -SNR ] */
  57. /* [ 0 a22 ] [ -SNL CSL ] [ a21 a22 ] [ SNR CSR ] */
  58. /* [ b11 b12 ] := [ CSL SNL ] [ b11 b12 ] [ CSR -SNR ] */
  59. /* [ 0 b22 ] [ -SNL CSL ] [ 0 b22 ] [ SNR CSR ], */
  60. /* 2) if the pencil (A,B) has a pair of complex conjugate eigenvalues, */
  61. /* then */
  62. /* [ a11 a12 ] := [ CSL SNL ] [ a11 a12 ] [ CSR -SNR ] */
  63. /* [ a21 a22 ] [ -SNL CSL ] [ a21 a22 ] [ SNR CSR ] */
  64. /* [ b11 0 ] := [ CSL SNL ] [ b11 b12 ] [ CSR -SNR ] */
  65. /* [ 0 b22 ] [ -SNL CSL ] [ 0 b22 ] [ SNR CSR ] */
  66. /* where b11 >= b22 > 0. */
  67. /* Arguments */
  68. /* ========= */
  69. /* A (input/output) DOUBLE PRECISION array, dimension (LDA, 2) */
  70. /* On entry, the 2 x 2 matrix A. */
  71. /* On exit, A is overwritten by the ``A-part'' of the */
  72. /* generalized Schur form. */
  73. /* LDA (input) INTEGER */
  74. /* THe leading dimension of the array A. LDA >= 2. */
  75. /* B (input/output) DOUBLE PRECISION array, dimension (LDB, 2) */
  76. /* On entry, the upper triangular 2 x 2 matrix B. */
  77. /* On exit, B is overwritten by the ``B-part'' of the */
  78. /* generalized Schur form. */
  79. /* LDB (input) INTEGER */
  80. /* THe leading dimension of the array B. LDB >= 2. */
  81. /* ALPHAR (output) DOUBLE PRECISION array, dimension (2) */
  82. /* ALPHAI (output) DOUBLE PRECISION array, dimension (2) */
  83. /* BETA (output) DOUBLE PRECISION array, dimension (2) */
  84. /* (ALPHAR(k)+i*ALPHAI(k))/BETA(k) are the eigenvalues of the */
  85. /* pencil (A,B), k=1,2, i = sqrt(-1). Note that BETA(k) may */
  86. /* be zero. */
  87. /* CSL (output) DOUBLE PRECISION */
  88. /* The cosine of the left rotation matrix. */
  89. /* SNL (output) DOUBLE PRECISION */
  90. /* The sine of the left rotation matrix. */
  91. /* CSR (output) DOUBLE PRECISION */
  92. /* The cosine of the right rotation matrix. */
  93. /* SNR (output) DOUBLE PRECISION */
  94. /* The sine of the right rotation matrix. */
  95. /* Further Details */
  96. /* =============== */
  97. /* Based on contributions by */
  98. /* Mark Fahey, Department of Mathematics, Univ. of Kentucky, USA */
  99. /* ===================================================================== */
  100. /* .. Parameters .. */
  101. /* .. */
  102. /* .. Local Scalars .. */
  103. /* .. */
  104. /* .. External Subroutines .. */
  105. /* .. */
  106. /* .. External Functions .. */
  107. /* .. */
  108. /* .. Intrinsic Functions .. */
  109. /* .. */
  110. /* .. Executable Statements .. */
  111. /* Parameter adjustments */
  112. a_dim1 = *lda;
  113. a_offset = 1 + a_dim1;
  114. a -= a_offset;
  115. b_dim1 = *ldb;
  116. b_offset = 1 + b_dim1;
  117. b -= b_offset;
  118. --alphar;
  119. --alphai;
  120. --beta;
  121. /* Function Body */
  122. safmin = _starpu_dlamch_("S");
  123. ulp = _starpu_dlamch_("P");
  124. /* Scale A */
  125. /* Computing MAX */
  126. d__5 = (d__1 = a[a_dim1 + 1], abs(d__1)) + (d__2 = a[a_dim1 + 2], abs(
  127. d__2)), d__6 = (d__3 = a[(a_dim1 << 1) + 1], abs(d__3)) + (d__4 =
  128. a[(a_dim1 << 1) + 2], abs(d__4)), d__5 = max(d__5,d__6);
  129. anorm = max(d__5,safmin);
  130. ascale = 1. / anorm;
  131. a[a_dim1 + 1] = ascale * a[a_dim1 + 1];
  132. a[(a_dim1 << 1) + 1] = ascale * a[(a_dim1 << 1) + 1];
  133. a[a_dim1 + 2] = ascale * a[a_dim1 + 2];
  134. a[(a_dim1 << 1) + 2] = ascale * a[(a_dim1 << 1) + 2];
  135. /* Scale B */
  136. /* Computing MAX */
  137. d__4 = (d__3 = b[b_dim1 + 1], abs(d__3)), d__5 = (d__1 = b[(b_dim1 << 1)
  138. + 1], abs(d__1)) + (d__2 = b[(b_dim1 << 1) + 2], abs(d__2)), d__4
  139. = max(d__4,d__5);
  140. bnorm = max(d__4,safmin);
  141. bscale = 1. / bnorm;
  142. b[b_dim1 + 1] = bscale * b[b_dim1 + 1];
  143. b[(b_dim1 << 1) + 1] = bscale * b[(b_dim1 << 1) + 1];
  144. b[(b_dim1 << 1) + 2] = bscale * b[(b_dim1 << 1) + 2];
  145. /* Check if A can be deflated */
  146. if ((d__1 = a[a_dim1 + 2], abs(d__1)) <= ulp) {
  147. *csl = 1.;
  148. *snl = 0.;
  149. *csr = 1.;
  150. *snr = 0.;
  151. a[a_dim1 + 2] = 0.;
  152. b[b_dim1 + 2] = 0.;
  153. /* Check if B is singular */
  154. } else if ((d__1 = b[b_dim1 + 1], abs(d__1)) <= ulp) {
  155. _starpu_dlartg_(&a[a_dim1 + 1], &a[a_dim1 + 2], csl, snl, &r__);
  156. *csr = 1.;
  157. *snr = 0.;
  158. _starpu_drot_(&c__2, &a[a_dim1 + 1], lda, &a[a_dim1 + 2], lda, csl, snl);
  159. _starpu_drot_(&c__2, &b[b_dim1 + 1], ldb, &b[b_dim1 + 2], ldb, csl, snl);
  160. a[a_dim1 + 2] = 0.;
  161. b[b_dim1 + 1] = 0.;
  162. b[b_dim1 + 2] = 0.;
  163. } else if ((d__1 = b[(b_dim1 << 1) + 2], abs(d__1)) <= ulp) {
  164. _starpu_dlartg_(&a[(a_dim1 << 1) + 2], &a[a_dim1 + 2], csr, snr, &t);
  165. *snr = -(*snr);
  166. _starpu_drot_(&c__2, &a[a_dim1 + 1], &c__1, &a[(a_dim1 << 1) + 1], &c__1, csr,
  167. snr);
  168. _starpu_drot_(&c__2, &b[b_dim1 + 1], &c__1, &b[(b_dim1 << 1) + 1], &c__1, csr,
  169. snr);
  170. *csl = 1.;
  171. *snl = 0.;
  172. a[a_dim1 + 2] = 0.;
  173. b[b_dim1 + 2] = 0.;
  174. b[(b_dim1 << 1) + 2] = 0.;
  175. } else {
  176. /* B is nonsingular, first compute the eigenvalues of (A,B) */
  177. _starpu_dlag2_(&a[a_offset], lda, &b[b_offset], ldb, &safmin, &scale1, &
  178. scale2, &wr1, &wr2, &wi);
  179. if (wi == 0.) {
  180. /* two real eigenvalues, compute s*A-w*B */
  181. h1 = scale1 * a[a_dim1 + 1] - wr1 * b[b_dim1 + 1];
  182. h2 = scale1 * a[(a_dim1 << 1) + 1] - wr1 * b[(b_dim1 << 1) + 1];
  183. h3 = scale1 * a[(a_dim1 << 1) + 2] - wr1 * b[(b_dim1 << 1) + 2];
  184. rr = _starpu_dlapy2_(&h1, &h2);
  185. d__1 = scale1 * a[a_dim1 + 2];
  186. qq = _starpu_dlapy2_(&d__1, &h3);
  187. if (rr > qq) {
  188. /* find right rotation matrix to zero 1,1 element of */
  189. /* (sA - wB) */
  190. _starpu_dlartg_(&h2, &h1, csr, snr, &t);
  191. } else {
  192. /* find right rotation matrix to zero 2,1 element of */
  193. /* (sA - wB) */
  194. d__1 = scale1 * a[a_dim1 + 2];
  195. _starpu_dlartg_(&h3, &d__1, csr, snr, &t);
  196. }
  197. *snr = -(*snr);
  198. _starpu_drot_(&c__2, &a[a_dim1 + 1], &c__1, &a[(a_dim1 << 1) + 1], &c__1,
  199. csr, snr);
  200. _starpu_drot_(&c__2, &b[b_dim1 + 1], &c__1, &b[(b_dim1 << 1) + 1], &c__1,
  201. csr, snr);
  202. /* compute inf norms of A and B */
  203. /* Computing MAX */
  204. d__5 = (d__1 = a[a_dim1 + 1], abs(d__1)) + (d__2 = a[(a_dim1 << 1)
  205. + 1], abs(d__2)), d__6 = (d__3 = a[a_dim1 + 2], abs(d__3)
  206. ) + (d__4 = a[(a_dim1 << 1) + 2], abs(d__4));
  207. h1 = max(d__5,d__6);
  208. /* Computing MAX */
  209. d__5 = (d__1 = b[b_dim1 + 1], abs(d__1)) + (d__2 = b[(b_dim1 << 1)
  210. + 1], abs(d__2)), d__6 = (d__3 = b[b_dim1 + 2], abs(d__3)
  211. ) + (d__4 = b[(b_dim1 << 1) + 2], abs(d__4));
  212. h2 = max(d__5,d__6);
  213. if (scale1 * h1 >= abs(wr1) * h2) {
  214. /* find left rotation matrix Q to zero out B(2,1) */
  215. _starpu_dlartg_(&b[b_dim1 + 1], &b[b_dim1 + 2], csl, snl, &r__);
  216. } else {
  217. /* find left rotation matrix Q to zero out A(2,1) */
  218. _starpu_dlartg_(&a[a_dim1 + 1], &a[a_dim1 + 2], csl, snl, &r__);
  219. }
  220. _starpu_drot_(&c__2, &a[a_dim1 + 1], lda, &a[a_dim1 + 2], lda, csl, snl);
  221. _starpu_drot_(&c__2, &b[b_dim1 + 1], ldb, &b[b_dim1 + 2], ldb, csl, snl);
  222. a[a_dim1 + 2] = 0.;
  223. b[b_dim1 + 2] = 0.;
  224. } else {
  225. /* a pair of complex conjugate eigenvalues */
  226. /* first compute the SVD of the matrix B */
  227. _starpu_dlasv2_(&b[b_dim1 + 1], &b[(b_dim1 << 1) + 1], &b[(b_dim1 << 1) +
  228. 2], &r__, &t, snr, csr, snl, csl);
  229. /* Form (A,B) := Q(A,B)Z' where Q is left rotation matrix and */
  230. /* Z is right rotation matrix computed from DLASV2 */
  231. _starpu_drot_(&c__2, &a[a_dim1 + 1], lda, &a[a_dim1 + 2], lda, csl, snl);
  232. _starpu_drot_(&c__2, &b[b_dim1 + 1], ldb, &b[b_dim1 + 2], ldb, csl, snl);
  233. _starpu_drot_(&c__2, &a[a_dim1 + 1], &c__1, &a[(a_dim1 << 1) + 1], &c__1,
  234. csr, snr);
  235. _starpu_drot_(&c__2, &b[b_dim1 + 1], &c__1, &b[(b_dim1 << 1) + 1], &c__1,
  236. csr, snr);
  237. b[b_dim1 + 2] = 0.;
  238. b[(b_dim1 << 1) + 1] = 0.;
  239. }
  240. }
  241. /* Unscaling */
  242. a[a_dim1 + 1] = anorm * a[a_dim1 + 1];
  243. a[a_dim1 + 2] = anorm * a[a_dim1 + 2];
  244. a[(a_dim1 << 1) + 1] = anorm * a[(a_dim1 << 1) + 1];
  245. a[(a_dim1 << 1) + 2] = anorm * a[(a_dim1 << 1) + 2];
  246. b[b_dim1 + 1] = bnorm * b[b_dim1 + 1];
  247. b[b_dim1 + 2] = bnorm * b[b_dim1 + 2];
  248. b[(b_dim1 << 1) + 1] = bnorm * b[(b_dim1 << 1) + 1];
  249. b[(b_dim1 << 1) + 2] = bnorm * b[(b_dim1 << 1) + 2];
  250. if (wi == 0.) {
  251. alphar[1] = a[a_dim1 + 1];
  252. alphar[2] = a[(a_dim1 << 1) + 2];
  253. alphai[1] = 0.;
  254. alphai[2] = 0.;
  255. beta[1] = b[b_dim1 + 1];
  256. beta[2] = b[(b_dim1 << 1) + 2];
  257. } else {
  258. alphar[1] = anorm * wr1 / scale1 / bnorm;
  259. alphai[1] = anorm * wi / scale1 / bnorm;
  260. alphar[2] = alphar[1];
  261. alphai[2] = -alphai[1];
  262. beta[1] = 1.;
  263. beta[2] = 1.;
  264. }
  265. return 0;
  266. /* End of DLAGV2 */
  267. } /* _starpu_dlagv2_ */