dlanv2.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /* dlanv2.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. /* Subroutine */ int _starpu_dlanv2_(doublereal *a, doublereal *b, doublereal *c__,
  16. doublereal *d__, doublereal *rt1r, doublereal *rt1i, doublereal *rt2r,
  17. doublereal *rt2i, doublereal *cs, doublereal *sn)
  18. {
  19. /* System generated locals */
  20. doublereal d__1, d__2;
  21. /* Builtin functions */
  22. double d_sign(doublereal *, doublereal *), sqrt(doublereal);
  23. /* Local variables */
  24. doublereal p, z__, aa, bb, cc, dd, cs1, sn1, sab, sac, eps, tau, temp,
  25. scale, bcmax, bcmis, sigma;
  26. extern doublereal _starpu_dlapy2_(doublereal *, doublereal *), _starpu_dlamch_(char *);
  27. /* -- LAPACK driver routine (version 3.2) -- */
  28. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  29. /* November 2006 */
  30. /* .. Scalar Arguments .. */
  31. /* .. */
  32. /* Purpose */
  33. /* ======= */
  34. /* DLANV2 computes the Schur factorization of a real 2-by-2 nonsymmetric */
  35. /* matrix in standard form: */
  36. /* [ A B ] = [ CS -SN ] [ AA BB ] [ CS SN ] */
  37. /* [ C D ] [ SN CS ] [ CC DD ] [-SN CS ] */
  38. /* where either */
  39. /* 1) CC = 0 so that AA and DD are real eigenvalues of the matrix, or */
  40. /* 2) AA = DD and BB*CC < 0, so that AA + or - sqrt(BB*CC) are complex */
  41. /* conjugate eigenvalues. */
  42. /* Arguments */
  43. /* ========= */
  44. /* A (input/output) DOUBLE PRECISION */
  45. /* B (input/output) DOUBLE PRECISION */
  46. /* C (input/output) DOUBLE PRECISION */
  47. /* D (input/output) DOUBLE PRECISION */
  48. /* On entry, the elements of the input matrix. */
  49. /* On exit, they are overwritten by the elements of the */
  50. /* standardised Schur form. */
  51. /* RT1R (output) DOUBLE PRECISION */
  52. /* RT1I (output) DOUBLE PRECISION */
  53. /* RT2R (output) DOUBLE PRECISION */
  54. /* RT2I (output) DOUBLE PRECISION */
  55. /* The real and imaginary parts of the eigenvalues. If the */
  56. /* eigenvalues are a complex conjugate pair, RT1I > 0. */
  57. /* CS (output) DOUBLE PRECISION */
  58. /* SN (output) DOUBLE PRECISION */
  59. /* Parameters of the rotation matrix. */
  60. /* Further Details */
  61. /* =============== */
  62. /* Modified by V. Sima, Research Institute for Informatics, Bucharest, */
  63. /* Romania, to reduce the risk of cancellation errors, */
  64. /* when computing real eigenvalues, and to ensure, if possible, that */
  65. /* abs(RT1R) >= abs(RT2R). */
  66. /* ===================================================================== */
  67. /* .. Parameters .. */
  68. /* .. */
  69. /* .. Local Scalars .. */
  70. /* .. */
  71. /* .. External Functions .. */
  72. /* .. */
  73. /* .. Intrinsic Functions .. */
  74. /* .. */
  75. /* .. Executable Statements .. */
  76. eps = _starpu_dlamch_("P");
  77. if (*c__ == 0.) {
  78. *cs = 1.;
  79. *sn = 0.;
  80. goto L10;
  81. } else if (*b == 0.) {
  82. /* Swap rows and columns */
  83. *cs = 0.;
  84. *sn = 1.;
  85. temp = *d__;
  86. *d__ = *a;
  87. *a = temp;
  88. *b = -(*c__);
  89. *c__ = 0.;
  90. goto L10;
  91. } else if (*a - *d__ == 0. && d_sign(&c_b4, b) != d_sign(&c_b4, c__)) {
  92. *cs = 1.;
  93. *sn = 0.;
  94. goto L10;
  95. } else {
  96. temp = *a - *d__;
  97. p = temp * .5;
  98. /* Computing MAX */
  99. d__1 = abs(*b), d__2 = abs(*c__);
  100. bcmax = max(d__1,d__2);
  101. /* Computing MIN */
  102. d__1 = abs(*b), d__2 = abs(*c__);
  103. bcmis = min(d__1,d__2) * d_sign(&c_b4, b) * d_sign(&c_b4, c__);
  104. /* Computing MAX */
  105. d__1 = abs(p);
  106. scale = max(d__1,bcmax);
  107. z__ = p / scale * p + bcmax / scale * bcmis;
  108. /* If Z is of the order of the machine accuracy, postpone the */
  109. /* decision on the nature of eigenvalues */
  110. if (z__ >= eps * 4.) {
  111. /* Real eigenvalues. Compute A and D. */
  112. d__1 = sqrt(scale) * sqrt(z__);
  113. z__ = p + d_sign(&d__1, &p);
  114. *a = *d__ + z__;
  115. *d__ -= bcmax / z__ * bcmis;
  116. /* Compute B and the rotation matrix */
  117. tau = _starpu_dlapy2_(c__, &z__);
  118. *cs = z__ / tau;
  119. *sn = *c__ / tau;
  120. *b -= *c__;
  121. *c__ = 0.;
  122. } else {
  123. /* Complex eigenvalues, or real (almost) equal eigenvalues. */
  124. /* Make diagonal elements equal. */
  125. sigma = *b + *c__;
  126. tau = _starpu_dlapy2_(&sigma, &temp);
  127. *cs = sqrt((abs(sigma) / tau + 1.) * .5);
  128. *sn = -(p / (tau * *cs)) * d_sign(&c_b4, &sigma);
  129. /* Compute [ AA BB ] = [ A B ] [ CS -SN ] */
  130. /* [ CC DD ] [ C D ] [ SN CS ] */
  131. aa = *a * *cs + *b * *sn;
  132. bb = -(*a) * *sn + *b * *cs;
  133. cc = *c__ * *cs + *d__ * *sn;
  134. dd = -(*c__) * *sn + *d__ * *cs;
  135. /* Compute [ A B ] = [ CS SN ] [ AA BB ] */
  136. /* [ C D ] [-SN CS ] [ CC DD ] */
  137. *a = aa * *cs + cc * *sn;
  138. *b = bb * *cs + dd * *sn;
  139. *c__ = -aa * *sn + cc * *cs;
  140. *d__ = -bb * *sn + dd * *cs;
  141. temp = (*a + *d__) * .5;
  142. *a = temp;
  143. *d__ = temp;
  144. if (*c__ != 0.) {
  145. if (*b != 0.) {
  146. if (d_sign(&c_b4, b) == d_sign(&c_b4, c__)) {
  147. /* Real eigenvalues: reduce to upper triangular form */
  148. sab = sqrt((abs(*b)));
  149. sac = sqrt((abs(*c__)));
  150. d__1 = sab * sac;
  151. p = d_sign(&d__1, c__);
  152. tau = 1. / sqrt((d__1 = *b + *c__, abs(d__1)));
  153. *a = temp + p;
  154. *d__ = temp - p;
  155. *b -= *c__;
  156. *c__ = 0.;
  157. cs1 = sab * tau;
  158. sn1 = sac * tau;
  159. temp = *cs * cs1 - *sn * sn1;
  160. *sn = *cs * sn1 + *sn * cs1;
  161. *cs = temp;
  162. }
  163. } else {
  164. *b = -(*c__);
  165. *c__ = 0.;
  166. temp = *cs;
  167. *cs = -(*sn);
  168. *sn = temp;
  169. }
  170. }
  171. }
  172. }
  173. L10:
  174. /* Store eigenvalues in (RT1R,RT1I) and (RT2R,RT2I). */
  175. *rt1r = *a;
  176. *rt2r = *d__;
  177. if (*c__ == 0.) {
  178. *rt1i = 0.;
  179. *rt2i = 0.;
  180. } else {
  181. *rt1i = sqrt((abs(*b))) * sqrt((abs(*c__)));
  182. *rt2i = -(*rt1i);
  183. }
  184. return 0;
  185. /* End of DLANV2 */
  186. } /* _starpu_dlanv2_ */