dlasv2.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /* dlasv2.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_b3 = 2.;
  15. static doublereal c_b4 = 1.;
  16. /* Subroutine */ int _starpu_dlasv2_(doublereal *f, doublereal *g, doublereal *h__,
  17. doublereal *ssmin, doublereal *ssmax, doublereal *snr, doublereal *
  18. csr, doublereal *snl, doublereal *csl)
  19. {
  20. /* System generated locals */
  21. doublereal d__1;
  22. /* Builtin functions */
  23. double sqrt(doublereal), d_sign(doublereal *, doublereal *);
  24. /* Local variables */
  25. doublereal a, d__, l, m, r__, s, t, fa, ga, ha, ft, gt, ht, mm, tt, clt,
  26. crt, slt, srt;
  27. integer pmax;
  28. doublereal temp;
  29. logical swap;
  30. doublereal tsign;
  31. extern doublereal _starpu_dlamch_(char *);
  32. logical gasmal;
  33. /* -- LAPACK auxiliary routine (version 3.2) -- */
  34. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  35. /* November 2006 */
  36. /* .. Scalar Arguments .. */
  37. /* .. */
  38. /* Purpose */
  39. /* ======= */
  40. /* DLASV2 computes the singular value decomposition of a 2-by-2 */
  41. /* triangular matrix */
  42. /* [ F G ] */
  43. /* [ 0 H ]. */
  44. /* On return, abs(SSMAX) is the larger singular value, abs(SSMIN) is the */
  45. /* smaller singular value, and (CSL,SNL) and (CSR,SNR) are the left and */
  46. /* right singular vectors for abs(SSMAX), giving the decomposition */
  47. /* [ CSL SNL ] [ F G ] [ CSR -SNR ] = [ SSMAX 0 ] */
  48. /* [-SNL CSL ] [ 0 H ] [ SNR CSR ] [ 0 SSMIN ]. */
  49. /* Arguments */
  50. /* ========= */
  51. /* F (input) DOUBLE PRECISION */
  52. /* The (1,1) element of the 2-by-2 matrix. */
  53. /* G (input) DOUBLE PRECISION */
  54. /* The (1,2) element of the 2-by-2 matrix. */
  55. /* H (input) DOUBLE PRECISION */
  56. /* The (2,2) element of the 2-by-2 matrix. */
  57. /* SSMIN (output) DOUBLE PRECISION */
  58. /* abs(SSMIN) is the smaller singular value. */
  59. /* SSMAX (output) DOUBLE PRECISION */
  60. /* abs(SSMAX) is the larger singular value. */
  61. /* SNL (output) DOUBLE PRECISION */
  62. /* CSL (output) DOUBLE PRECISION */
  63. /* The vector (CSL, SNL) is a unit left singular vector for the */
  64. /* singular value abs(SSMAX). */
  65. /* SNR (output) DOUBLE PRECISION */
  66. /* CSR (output) DOUBLE PRECISION */
  67. /* The vector (CSR, SNR) is a unit right singular vector for the */
  68. /* singular value abs(SSMAX). */
  69. /* Further Details */
  70. /* =============== */
  71. /* Any input parameter may be aliased with any output parameter. */
  72. /* Barring over/underflow and assuming a guard digit in subtraction, all */
  73. /* output quantities are correct to within a few units in the last */
  74. /* place (ulps). */
  75. /* In IEEE arithmetic, the code works correctly if one matrix element is */
  76. /* infinite. */
  77. /* Overflow will not occur unless the largest singular value itself */
  78. /* overflows or is within a few ulps of overflow. (On machines with */
  79. /* partial overflow, like the Cray, overflow may occur if the largest */
  80. /* singular value is within a factor of 2 of overflow.) */
  81. /* Underflow is harmless if underflow is gradual. Otherwise, results */
  82. /* may correspond to a matrix modified by perturbations of size near */
  83. /* the underflow threshold. */
  84. /* ===================================================================== */
  85. /* .. Parameters .. */
  86. /* .. */
  87. /* .. Local Scalars .. */
  88. /* .. */
  89. /* .. Intrinsic Functions .. */
  90. /* .. */
  91. /* .. External Functions .. */
  92. /* .. */
  93. /* .. Executable Statements .. */
  94. ft = *f;
  95. fa = abs(ft);
  96. ht = *h__;
  97. ha = abs(*h__);
  98. /* PMAX points to the maximum absolute element of matrix */
  99. /* PMAX = 1 if F largest in absolute values */
  100. /* PMAX = 2 if G largest in absolute values */
  101. /* PMAX = 3 if H largest in absolute values */
  102. pmax = 1;
  103. swap = ha > fa;
  104. if (swap) {
  105. pmax = 3;
  106. temp = ft;
  107. ft = ht;
  108. ht = temp;
  109. temp = fa;
  110. fa = ha;
  111. ha = temp;
  112. /* Now FA .ge. HA */
  113. }
  114. gt = *g;
  115. ga = abs(gt);
  116. if (ga == 0.) {
  117. /* Diagonal matrix */
  118. *ssmin = ha;
  119. *ssmax = fa;
  120. clt = 1.;
  121. crt = 1.;
  122. slt = 0.;
  123. srt = 0.;
  124. } else {
  125. gasmal = TRUE_;
  126. if (ga > fa) {
  127. pmax = 2;
  128. if (fa / ga < _starpu_dlamch_("EPS")) {
  129. /* Case of very large GA */
  130. gasmal = FALSE_;
  131. *ssmax = ga;
  132. if (ha > 1.) {
  133. *ssmin = fa / (ga / ha);
  134. } else {
  135. *ssmin = fa / ga * ha;
  136. }
  137. clt = 1.;
  138. slt = ht / gt;
  139. srt = 1.;
  140. crt = ft / gt;
  141. }
  142. }
  143. if (gasmal) {
  144. /* Normal case */
  145. d__ = fa - ha;
  146. if (d__ == fa) {
  147. /* Copes with infinite F or H */
  148. l = 1.;
  149. } else {
  150. l = d__ / fa;
  151. }
  152. /* Note that 0 .le. L .le. 1 */
  153. m = gt / ft;
  154. /* Note that abs(M) .le. 1/macheps */
  155. t = 2. - l;
  156. /* Note that T .ge. 1 */
  157. mm = m * m;
  158. tt = t * t;
  159. s = sqrt(tt + mm);
  160. /* Note that 1 .le. S .le. 1 + 1/macheps */
  161. if (l == 0.) {
  162. r__ = abs(m);
  163. } else {
  164. r__ = sqrt(l * l + mm);
  165. }
  166. /* Note that 0 .le. R .le. 1 + 1/macheps */
  167. a = (s + r__) * .5;
  168. /* Note that 1 .le. A .le. 1 + abs(M) */
  169. *ssmin = ha / a;
  170. *ssmax = fa * a;
  171. if (mm == 0.) {
  172. /* Note that M is very tiny */
  173. if (l == 0.) {
  174. t = d_sign(&c_b3, &ft) * d_sign(&c_b4, &gt);
  175. } else {
  176. t = gt / d_sign(&d__, &ft) + m / t;
  177. }
  178. } else {
  179. t = (m / (s + t) + m / (r__ + l)) * (a + 1.);
  180. }
  181. l = sqrt(t * t + 4.);
  182. crt = 2. / l;
  183. srt = t / l;
  184. clt = (crt + srt * m) / a;
  185. slt = ht / ft * srt / a;
  186. }
  187. }
  188. if (swap) {
  189. *csl = srt;
  190. *snl = crt;
  191. *csr = slt;
  192. *snr = clt;
  193. } else {
  194. *csl = clt;
  195. *snl = slt;
  196. *csr = crt;
  197. *snr = srt;
  198. }
  199. /* Correct signs of SSMAX and SSMIN */
  200. if (pmax == 1) {
  201. tsign = d_sign(&c_b4, csr) * d_sign(&c_b4, csl) * d_sign(&c_b4, f);
  202. }
  203. if (pmax == 2) {
  204. tsign = d_sign(&c_b4, snr) * d_sign(&c_b4, csl) * d_sign(&c_b4, g);
  205. }
  206. if (pmax == 3) {
  207. tsign = d_sign(&c_b4, snr) * d_sign(&c_b4, snl) * d_sign(&c_b4, h__);
  208. }
  209. *ssmax = d_sign(ssmax, &tsign);
  210. d__1 = tsign * d_sign(&c_b4, f) * d_sign(&c_b4, h__);
  211. *ssmin = d_sign(ssmin, &d__1);
  212. return 0;
  213. /* End of DLASV2 */
  214. } /* _starpu_dlasv2_ */