dlasq1.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /* dlasq1.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__1 = 1;
  15. static integer c__2 = 2;
  16. static integer c__0 = 0;
  17. /* Subroutine */ int _starpu_dlasq1_(integer *n, doublereal *d__, doublereal *e,
  18. doublereal *work, integer *info)
  19. {
  20. /* System generated locals */
  21. integer i__1, i__2;
  22. doublereal d__1, d__2, d__3;
  23. /* Builtin functions */
  24. double sqrt(doublereal);
  25. /* Local variables */
  26. integer i__;
  27. doublereal eps;
  28. extern /* Subroutine */ int _starpu_dlas2_(doublereal *, doublereal *, doublereal
  29. *, doublereal *, doublereal *);
  30. doublereal scale;
  31. integer iinfo;
  32. doublereal sigmn;
  33. extern /* Subroutine */ int _starpu_dcopy_(integer *, doublereal *, integer *,
  34. doublereal *, integer *);
  35. doublereal sigmx;
  36. extern /* Subroutine */ int _starpu_dlasq2_(integer *, doublereal *, integer *);
  37. extern doublereal _starpu_dlamch_(char *);
  38. extern /* Subroutine */ int _starpu_dlascl_(char *, integer *, integer *,
  39. doublereal *, doublereal *, integer *, integer *, doublereal *,
  40. integer *, integer *);
  41. doublereal safmin;
  42. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *), _starpu_dlasrt_(
  43. char *, integer *, doublereal *, integer *);
  44. /* -- LAPACK routine (version 3.2) -- */
  45. /* -- Contributed by Osni Marques of the Lawrence Berkeley National -- */
  46. /* -- Laboratory and Beresford Parlett of the Univ. of California at -- */
  47. /* -- Berkeley -- */
  48. /* -- November 2008 -- */
  49. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  50. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  51. /* .. Scalar Arguments .. */
  52. /* .. */
  53. /* .. Array Arguments .. */
  54. /* .. */
  55. /* Purpose */
  56. /* ======= */
  57. /* DLASQ1 computes the singular values of a real N-by-N bidiagonal */
  58. /* matrix with diagonal D and off-diagonal E. The singular values */
  59. /* are computed to high relative accuracy, in the absence of */
  60. /* denormalization, underflow and overflow. The algorithm was first */
  61. /* presented in */
  62. /* "Accurate singular values and differential qd algorithms" by K. V. */
  63. /* Fernando and B. N. Parlett, Numer. Math., Vol-67, No. 2, pp. 191-230, */
  64. /* 1994, */
  65. /* and the present implementation is described in "An implementation of */
  66. /* the dqds Algorithm (Positive Case)", LAPACK Working Note. */
  67. /* Arguments */
  68. /* ========= */
  69. /* N (input) INTEGER */
  70. /* The number of rows and columns in the matrix. N >= 0. */
  71. /* D (input/output) DOUBLE PRECISION array, dimension (N) */
  72. /* On entry, D contains the diagonal elements of the */
  73. /* bidiagonal matrix whose SVD is desired. On normal exit, */
  74. /* D contains the singular values in decreasing order. */
  75. /* E (input/output) DOUBLE PRECISION array, dimension (N) */
  76. /* On entry, elements E(1:N-1) contain the off-diagonal elements */
  77. /* of the bidiagonal matrix whose SVD is desired. */
  78. /* On exit, E is overwritten. */
  79. /* WORK (workspace) DOUBLE PRECISION array, dimension (4*N) */
  80. /* INFO (output) INTEGER */
  81. /* = 0: successful exit */
  82. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  83. /* > 0: the algorithm failed */
  84. /* = 1, a split was marked by a positive value in E */
  85. /* = 2, current block of Z not diagonalized after 30*N */
  86. /* iterations (in inner while loop) */
  87. /* = 3, termination criterion of outer while loop not met */
  88. /* (program created more than N unreduced blocks) */
  89. /* ===================================================================== */
  90. /* .. Parameters .. */
  91. /* .. */
  92. /* .. Local Scalars .. */
  93. /* .. */
  94. /* .. External Subroutines .. */
  95. /* .. */
  96. /* .. External Functions .. */
  97. /* .. */
  98. /* .. Intrinsic Functions .. */
  99. /* .. */
  100. /* .. Executable Statements .. */
  101. /* Parameter adjustments */
  102. --work;
  103. --e;
  104. --d__;
  105. /* Function Body */
  106. *info = 0;
  107. if (*n < 0) {
  108. *info = -2;
  109. i__1 = -(*info);
  110. _starpu_xerbla_("DLASQ1", &i__1);
  111. return 0;
  112. } else if (*n == 0) {
  113. return 0;
  114. } else if (*n == 1) {
  115. d__[1] = abs(d__[1]);
  116. return 0;
  117. } else if (*n == 2) {
  118. _starpu_dlas2_(&d__[1], &e[1], &d__[2], &sigmn, &sigmx);
  119. d__[1] = sigmx;
  120. d__[2] = sigmn;
  121. return 0;
  122. }
  123. /* Estimate the largest singular value. */
  124. sigmx = 0.;
  125. i__1 = *n - 1;
  126. for (i__ = 1; i__ <= i__1; ++i__) {
  127. d__[i__] = (d__1 = d__[i__], abs(d__1));
  128. /* Computing MAX */
  129. d__2 = sigmx, d__3 = (d__1 = e[i__], abs(d__1));
  130. sigmx = max(d__2,d__3);
  131. /* L10: */
  132. }
  133. d__[*n] = (d__1 = d__[*n], abs(d__1));
  134. /* Early return if SIGMX is zero (matrix is already diagonal). */
  135. if (sigmx == 0.) {
  136. _starpu_dlasrt_("D", n, &d__[1], &iinfo);
  137. return 0;
  138. }
  139. i__1 = *n;
  140. for (i__ = 1; i__ <= i__1; ++i__) {
  141. /* Computing MAX */
  142. d__1 = sigmx, d__2 = d__[i__];
  143. sigmx = max(d__1,d__2);
  144. /* L20: */
  145. }
  146. /* Copy D and E into WORK (in the Z format) and scale (squaring the */
  147. /* input data makes scaling by a power of the radix pointless). */
  148. eps = _starpu_dlamch_("Precision");
  149. safmin = _starpu_dlamch_("Safe minimum");
  150. scale = sqrt(eps / safmin);
  151. _starpu_dcopy_(n, &d__[1], &c__1, &work[1], &c__2);
  152. i__1 = *n - 1;
  153. _starpu_dcopy_(&i__1, &e[1], &c__1, &work[2], &c__2);
  154. i__1 = (*n << 1) - 1;
  155. i__2 = (*n << 1) - 1;
  156. _starpu_dlascl_("G", &c__0, &c__0, &sigmx, &scale, &i__1, &c__1, &work[1], &i__2,
  157. &iinfo);
  158. /* Compute the q's and e's. */
  159. i__1 = (*n << 1) - 1;
  160. for (i__ = 1; i__ <= i__1; ++i__) {
  161. /* Computing 2nd power */
  162. d__1 = work[i__];
  163. work[i__] = d__1 * d__1;
  164. /* L30: */
  165. }
  166. work[*n * 2] = 0.;
  167. _starpu_dlasq2_(n, &work[1], info);
  168. if (*info == 0) {
  169. i__1 = *n;
  170. for (i__ = 1; i__ <= i__1; ++i__) {
  171. d__[i__] = sqrt(work[i__]);
  172. /* L40: */
  173. }
  174. _starpu_dlascl_("G", &c__0, &c__0, &scale, &sigmx, n, &c__1, &d__[1], n, &
  175. iinfo);
  176. }
  177. return 0;
  178. /* End of DLASQ1 */
  179. } /* _starpu_dlasq1_ */