dlasd8.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /* dlasd8.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__0 = 0;
  16. static doublereal c_b8 = 1.;
  17. /* Subroutine */ int _starpu_dlasd8_(integer *icompq, integer *k, doublereal *d__,
  18. doublereal *z__, doublereal *vf, doublereal *vl, doublereal *difl,
  19. doublereal *difr, integer *lddifr, doublereal *dsigma, doublereal *
  20. work, integer *info)
  21. {
  22. /* System generated locals */
  23. integer difr_dim1, difr_offset, i__1, i__2;
  24. doublereal d__1, d__2;
  25. /* Builtin functions */
  26. double sqrt(doublereal), d_sign(doublereal *, doublereal *);
  27. /* Local variables */
  28. integer i__, j;
  29. doublereal dj, rho;
  30. integer iwk1, iwk2, iwk3;
  31. extern doublereal _starpu_ddot_(integer *, doublereal *, integer *, doublereal *,
  32. integer *);
  33. doublereal temp;
  34. extern doublereal _starpu_dnrm2_(integer *, doublereal *, integer *);
  35. integer iwk2i, iwk3i;
  36. doublereal diflj, difrj, dsigj;
  37. extern /* Subroutine */ int _starpu_dcopy_(integer *, doublereal *, integer *,
  38. doublereal *, integer *);
  39. extern doublereal _starpu_dlamc3_(doublereal *, doublereal *);
  40. extern /* Subroutine */ int _starpu_dlasd4_(integer *, integer *, doublereal *,
  41. doublereal *, doublereal *, doublereal *, doublereal *,
  42. doublereal *, integer *), _starpu_dlascl_(char *, integer *, integer *,
  43. doublereal *, doublereal *, integer *, integer *, doublereal *,
  44. integer *, integer *), _starpu_dlaset_(char *, integer *, integer
  45. *, doublereal *, doublereal *, doublereal *, integer *),
  46. _starpu_xerbla_(char *, integer *);
  47. doublereal dsigjp;
  48. /* -- LAPACK auxiliary routine (version 3.2) -- */
  49. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  50. /* October 2006 */
  51. /* .. Scalar Arguments .. */
  52. /* .. */
  53. /* .. Array Arguments .. */
  54. /* .. */
  55. /* Purpose */
  56. /* ======= */
  57. /* DLASD8 finds the square roots of the roots of the secular equation, */
  58. /* as defined by the values in DSIGMA and Z. It makes the appropriate */
  59. /* calls to DLASD4, and stores, for each element in D, the distance */
  60. /* to its two nearest poles (elements in DSIGMA). It also updates */
  61. /* the arrays VF and VL, the first and last components of all the */
  62. /* right singular vectors of the original bidiagonal matrix. */
  63. /* DLASD8 is called from DLASD6. */
  64. /* Arguments */
  65. /* ========= */
  66. /* ICOMPQ (input) INTEGER */
  67. /* Specifies whether singular vectors are to be computed in */
  68. /* factored form in the calling routine: */
  69. /* = 0: Compute singular values only. */
  70. /* = 1: Compute singular vectors in factored form as well. */
  71. /* K (input) INTEGER */
  72. /* The number of terms in the rational function to be solved */
  73. /* by DLASD4. K >= 1. */
  74. /* D (output) DOUBLE PRECISION array, dimension ( K ) */
  75. /* On output, D contains the updated singular values. */
  76. /* Z (input/output) DOUBLE PRECISION array, dimension ( K ) */
  77. /* On entry, the first K elements of this array contain the */
  78. /* components of the deflation-adjusted updating row vector. */
  79. /* On exit, Z is updated. */
  80. /* VF (input/output) DOUBLE PRECISION array, dimension ( K ) */
  81. /* On entry, VF contains information passed through DBEDE8. */
  82. /* On exit, VF contains the first K components of the first */
  83. /* components of all right singular vectors of the bidiagonal */
  84. /* matrix. */
  85. /* VL (input/output) DOUBLE PRECISION array, dimension ( K ) */
  86. /* On entry, VL contains information passed through DBEDE8. */
  87. /* On exit, VL contains the first K components of the last */
  88. /* components of all right singular vectors of the bidiagonal */
  89. /* matrix. */
  90. /* DIFL (output) DOUBLE PRECISION array, dimension ( K ) */
  91. /* On exit, DIFL(I) = D(I) - DSIGMA(I). */
  92. /* DIFR (output) DOUBLE PRECISION array, */
  93. /* dimension ( LDDIFR, 2 ) if ICOMPQ = 1 and */
  94. /* dimension ( K ) if ICOMPQ = 0. */
  95. /* On exit, DIFR(I,1) = D(I) - DSIGMA(I+1), DIFR(K,1) is not */
  96. /* defined and will not be referenced. */
  97. /* If ICOMPQ = 1, DIFR(1:K,2) is an array containing the */
  98. /* normalizing factors for the right singular vector matrix. */
  99. /* LDDIFR (input) INTEGER */
  100. /* The leading dimension of DIFR, must be at least K. */
  101. /* DSIGMA (input/output) DOUBLE PRECISION array, dimension ( K ) */
  102. /* On entry, the first K elements of this array contain the old */
  103. /* roots of the deflated updating problem. These are the poles */
  104. /* of the secular equation. */
  105. /* On exit, the elements of DSIGMA may be very slightly altered */
  106. /* in value. */
  107. /* WORK (workspace) DOUBLE PRECISION array, dimension at least 3 * K */
  108. /* INFO (output) INTEGER */
  109. /* = 0: successful exit. */
  110. /* < 0: if INFO = -i, the i-th argument had an illegal value. */
  111. /* > 0: if INFO = 1, an singular value did not converge */
  112. /* Further Details */
  113. /* =============== */
  114. /* Based on contributions by */
  115. /* Ming Gu and Huan Ren, Computer Science Division, University of */
  116. /* California at Berkeley, USA */
  117. /* ===================================================================== */
  118. /* .. Parameters .. */
  119. /* .. */
  120. /* .. Local Scalars .. */
  121. /* .. */
  122. /* .. External Subroutines .. */
  123. /* .. */
  124. /* .. External Functions .. */
  125. /* .. */
  126. /* .. Intrinsic Functions .. */
  127. /* .. */
  128. /* .. Executable Statements .. */
  129. /* Test the input parameters. */
  130. /* Parameter adjustments */
  131. --d__;
  132. --z__;
  133. --vf;
  134. --vl;
  135. --difl;
  136. difr_dim1 = *lddifr;
  137. difr_offset = 1 + difr_dim1;
  138. difr -= difr_offset;
  139. --dsigma;
  140. --work;
  141. /* Function Body */
  142. *info = 0;
  143. if (*icompq < 0 || *icompq > 1) {
  144. *info = -1;
  145. } else if (*k < 1) {
  146. *info = -2;
  147. } else if (*lddifr < *k) {
  148. *info = -9;
  149. }
  150. if (*info != 0) {
  151. i__1 = -(*info);
  152. _starpu_xerbla_("DLASD8", &i__1);
  153. return 0;
  154. }
  155. /* Quick return if possible */
  156. if (*k == 1) {
  157. d__[1] = abs(z__[1]);
  158. difl[1] = d__[1];
  159. if (*icompq == 1) {
  160. difl[2] = 1.;
  161. difr[(difr_dim1 << 1) + 1] = 1.;
  162. }
  163. return 0;
  164. }
  165. /* Modify values DSIGMA(i) to make sure all DSIGMA(i)-DSIGMA(j) can */
  166. /* be computed with high relative accuracy (barring over/underflow). */
  167. /* This is a problem on machines without a guard digit in */
  168. /* add/subtract (Cray XMP, Cray YMP, Cray C 90 and Cray 2). */
  169. /* The following code replaces DSIGMA(I) by 2*DSIGMA(I)-DSIGMA(I), */
  170. /* which on any of these machines zeros out the bottommost */
  171. /* bit of DSIGMA(I) if it is 1; this makes the subsequent */
  172. /* subtractions DSIGMA(I)-DSIGMA(J) unproblematic when cancellation */
  173. /* occurs. On binary machines with a guard digit (almost all */
  174. /* machines) it does not change DSIGMA(I) at all. On hexadecimal */
  175. /* and decimal machines with a guard digit, it slightly */
  176. /* changes the bottommost bits of DSIGMA(I). It does not account */
  177. /* for hexadecimal or decimal machines without guard digits */
  178. /* (we know of none). We use a subroutine call to compute */
  179. /* 2*DLAMBDA(I) to prevent optimizing compilers from eliminating */
  180. /* this code. */
  181. i__1 = *k;
  182. for (i__ = 1; i__ <= i__1; ++i__) {
  183. dsigma[i__] = _starpu_dlamc3_(&dsigma[i__], &dsigma[i__]) - dsigma[i__];
  184. /* L10: */
  185. }
  186. /* Book keeping. */
  187. iwk1 = 1;
  188. iwk2 = iwk1 + *k;
  189. iwk3 = iwk2 + *k;
  190. iwk2i = iwk2 - 1;
  191. iwk3i = iwk3 - 1;
  192. /* Normalize Z. */
  193. rho = _starpu_dnrm2_(k, &z__[1], &c__1);
  194. _starpu_dlascl_("G", &c__0, &c__0, &rho, &c_b8, k, &c__1, &z__[1], k, info);
  195. rho *= rho;
  196. /* Initialize WORK(IWK3). */
  197. _starpu_dlaset_("A", k, &c__1, &c_b8, &c_b8, &work[iwk3], k);
  198. /* Compute the updated singular values, the arrays DIFL, DIFR, */
  199. /* and the updated Z. */
  200. i__1 = *k;
  201. for (j = 1; j <= i__1; ++j) {
  202. _starpu_dlasd4_(k, &j, &dsigma[1], &z__[1], &work[iwk1], &rho, &d__[j], &work[
  203. iwk2], info);
  204. /* If the root finder fails, the computation is terminated. */
  205. if (*info != 0) {
  206. return 0;
  207. }
  208. work[iwk3i + j] = work[iwk3i + j] * work[j] * work[iwk2i + j];
  209. difl[j] = -work[j];
  210. difr[j + difr_dim1] = -work[j + 1];
  211. i__2 = j - 1;
  212. for (i__ = 1; i__ <= i__2; ++i__) {
  213. work[iwk3i + i__] = work[iwk3i + i__] * work[i__] * work[iwk2i +
  214. i__] / (dsigma[i__] - dsigma[j]) / (dsigma[i__] + dsigma[
  215. j]);
  216. /* L20: */
  217. }
  218. i__2 = *k;
  219. for (i__ = j + 1; i__ <= i__2; ++i__) {
  220. work[iwk3i + i__] = work[iwk3i + i__] * work[i__] * work[iwk2i +
  221. i__] / (dsigma[i__] - dsigma[j]) / (dsigma[i__] + dsigma[
  222. j]);
  223. /* L30: */
  224. }
  225. /* L40: */
  226. }
  227. /* Compute updated Z. */
  228. i__1 = *k;
  229. for (i__ = 1; i__ <= i__1; ++i__) {
  230. d__2 = sqrt((d__1 = work[iwk3i + i__], abs(d__1)));
  231. z__[i__] = d_sign(&d__2, &z__[i__]);
  232. /* L50: */
  233. }
  234. /* Update VF and VL. */
  235. i__1 = *k;
  236. for (j = 1; j <= i__1; ++j) {
  237. diflj = difl[j];
  238. dj = d__[j];
  239. dsigj = -dsigma[j];
  240. if (j < *k) {
  241. difrj = -difr[j + difr_dim1];
  242. dsigjp = -dsigma[j + 1];
  243. }
  244. work[j] = -z__[j] / diflj / (dsigma[j] + dj);
  245. i__2 = j - 1;
  246. for (i__ = 1; i__ <= i__2; ++i__) {
  247. work[i__] = z__[i__] / (_starpu_dlamc3_(&dsigma[i__], &dsigj) - diflj) / (
  248. dsigma[i__] + dj);
  249. /* L60: */
  250. }
  251. i__2 = *k;
  252. for (i__ = j + 1; i__ <= i__2; ++i__) {
  253. work[i__] = z__[i__] / (_starpu_dlamc3_(&dsigma[i__], &dsigjp) + difrj) /
  254. (dsigma[i__] + dj);
  255. /* L70: */
  256. }
  257. temp = _starpu_dnrm2_(k, &work[1], &c__1);
  258. work[iwk2i + j] = _starpu_ddot_(k, &work[1], &c__1, &vf[1], &c__1) / temp;
  259. work[iwk3i + j] = _starpu_ddot_(k, &work[1], &c__1, &vl[1], &c__1) / temp;
  260. if (*icompq == 1) {
  261. difr[j + (difr_dim1 << 1)] = temp;
  262. }
  263. /* L80: */
  264. }
  265. _starpu_dcopy_(k, &work[iwk2], &c__1, &vf[1], &c__1);
  266. _starpu_dcopy_(k, &work[iwk3], &c__1, &vl[1], &c__1);
  267. return 0;
  268. /* End of DLASD8 */
  269. } /* _starpu_dlasd8_ */