dlasd6.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /* dlasd6.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__0 = 0;
  15. static doublereal c_b7 = 1.;
  16. static integer c__1 = 1;
  17. static integer c_n1 = -1;
  18. /* Subroutine */ int _starpu_dlasd6_(integer *icompq, integer *nl, integer *nr,
  19. integer *sqre, doublereal *d__, doublereal *vf, doublereal *vl,
  20. doublereal *alpha, doublereal *beta, integer *idxq, integer *perm,
  21. integer *givptr, integer *givcol, integer *ldgcol, doublereal *givnum,
  22. integer *ldgnum, doublereal *poles, doublereal *difl, doublereal *
  23. difr, doublereal *z__, integer *k, doublereal *c__, doublereal *s,
  24. doublereal *work, integer *iwork, integer *info)
  25. {
  26. /* System generated locals */
  27. integer givcol_dim1, givcol_offset, givnum_dim1, givnum_offset,
  28. poles_dim1, poles_offset, i__1;
  29. doublereal d__1, d__2;
  30. /* Local variables */
  31. integer i__, m, n, n1, n2, iw, idx, idxc, idxp, ivfw, ivlw;
  32. extern /* Subroutine */ int _starpu_dcopy_(integer *, doublereal *, integer *,
  33. doublereal *, integer *), _starpu_dlasd7_(integer *, integer *, integer *,
  34. integer *, integer *, doublereal *, doublereal *, doublereal *,
  35. doublereal *, doublereal *, doublereal *, doublereal *,
  36. doublereal *, doublereal *, doublereal *, integer *, integer *,
  37. integer *, integer *, integer *, integer *, integer *, doublereal
  38. *, integer *, doublereal *, doublereal *, integer *), _starpu_dlasd8_(
  39. integer *, integer *, doublereal *, doublereal *, doublereal *,
  40. doublereal *, doublereal *, doublereal *, integer *, doublereal *,
  41. doublereal *, integer *), _starpu_dlascl_(char *, integer *, integer *,
  42. doublereal *, doublereal *, integer *, integer *, doublereal *,
  43. integer *, integer *), _starpu_dlamrg_(integer *, integer *,
  44. doublereal *, integer *, integer *, integer *);
  45. integer isigma;
  46. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  47. doublereal orgnrm;
  48. /* -- LAPACK auxiliary routine (version 3.2) -- */
  49. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  50. /* November 2006 */
  51. /* .. Scalar Arguments .. */
  52. /* .. */
  53. /* .. Array Arguments .. */
  54. /* .. */
  55. /* Purpose */
  56. /* ======= */
  57. /* DLASD6 computes the SVD of an updated upper bidiagonal matrix B */
  58. /* obtained by merging two smaller ones by appending a row. This */
  59. /* routine is used only for the problem which requires all singular */
  60. /* values and optionally singular vector matrices in factored form. */
  61. /* B is an N-by-M matrix with N = NL + NR + 1 and M = N + SQRE. */
  62. /* A related subroutine, DLASD1, handles the case in which all singular */
  63. /* values and singular vectors of the bidiagonal matrix are desired. */
  64. /* DLASD6 computes the SVD as follows: */
  65. /* ( D1(in) 0 0 0 ) */
  66. /* B = U(in) * ( Z1' a Z2' b ) * VT(in) */
  67. /* ( 0 0 D2(in) 0 ) */
  68. /* = U(out) * ( D(out) 0) * VT(out) */
  69. /* where Z' = (Z1' a Z2' b) = u' VT', and u is a vector of dimension M */
  70. /* with ALPHA and BETA in the NL+1 and NL+2 th entries and zeros */
  71. /* elsewhere; and the entry b is empty if SQRE = 0. */
  72. /* The singular values of B can be computed using D1, D2, the first */
  73. /* components of all the right singular vectors of the lower block, and */
  74. /* the last components of all the right singular vectors of the upper */
  75. /* block. These components are stored and updated in VF and VL, */
  76. /* respectively, in DLASD6. Hence U and VT are not explicitly */
  77. /* referenced. */
  78. /* The singular values are stored in D. The algorithm consists of two */
  79. /* stages: */
  80. /* The first stage consists of deflating the size of the problem */
  81. /* when there are multiple singular values or if there is a zero */
  82. /* in the Z vector. For each such occurence the dimension of the */
  83. /* secular equation problem is reduced by one. This stage is */
  84. /* performed by the routine DLASD7. */
  85. /* The second stage consists of calculating the updated */
  86. /* singular values. This is done by finding the roots of the */
  87. /* secular equation via the routine DLASD4 (as called by DLASD8). */
  88. /* This routine also updates VF and VL and computes the distances */
  89. /* between the updated singular values and the old singular */
  90. /* values. */
  91. /* DLASD6 is called from DLASDA. */
  92. /* Arguments */
  93. /* ========= */
  94. /* ICOMPQ (input) INTEGER */
  95. /* Specifies whether singular vectors are to be computed in */
  96. /* factored form: */
  97. /* = 0: Compute singular values only. */
  98. /* = 1: Compute singular vectors in factored form as well. */
  99. /* NL (input) INTEGER */
  100. /* The row dimension of the upper block. NL >= 1. */
  101. /* NR (input) INTEGER */
  102. /* The row dimension of the lower block. NR >= 1. */
  103. /* SQRE (input) INTEGER */
  104. /* = 0: the lower block is an NR-by-NR square matrix. */
  105. /* = 1: the lower block is an NR-by-(NR+1) rectangular matrix. */
  106. /* The bidiagonal matrix has row dimension N = NL + NR + 1, */
  107. /* and column dimension M = N + SQRE. */
  108. /* D (input/output) DOUBLE PRECISION array, dimension ( NL+NR+1 ). */
  109. /* On entry D(1:NL,1:NL) contains the singular values of the */
  110. /* upper block, and D(NL+2:N) contains the singular values */
  111. /* of the lower block. On exit D(1:N) contains the singular */
  112. /* values of the modified matrix. */
  113. /* VF (input/output) DOUBLE PRECISION array, dimension ( M ) */
  114. /* On entry, VF(1:NL+1) contains the first components of all */
  115. /* right singular vectors of the upper block; and VF(NL+2:M) */
  116. /* contains the first components of all right singular vectors */
  117. /* of the lower block. On exit, VF contains the first components */
  118. /* of all right singular vectors of the bidiagonal matrix. */
  119. /* VL (input/output) DOUBLE PRECISION array, dimension ( M ) */
  120. /* On entry, VL(1:NL+1) contains the last components of all */
  121. /* right singular vectors of the upper block; and VL(NL+2:M) */
  122. /* contains the last components of all right singular vectors of */
  123. /* the lower block. On exit, VL contains the last components of */
  124. /* all right singular vectors of the bidiagonal matrix. */
  125. /* ALPHA (input/output) DOUBLE PRECISION */
  126. /* Contains the diagonal element associated with the added row. */
  127. /* BETA (input/output) DOUBLE PRECISION */
  128. /* Contains the off-diagonal element associated with the added */
  129. /* row. */
  130. /* IDXQ (output) INTEGER array, dimension ( N ) */
  131. /* This contains the permutation which will reintegrate the */
  132. /* subproblem just solved back into sorted order, i.e. */
  133. /* D( IDXQ( I = 1, N ) ) will be in ascending order. */
  134. /* PERM (output) INTEGER array, dimension ( N ) */
  135. /* The permutations (from deflation and sorting) to be applied */
  136. /* to each block. Not referenced if ICOMPQ = 0. */
  137. /* GIVPTR (output) INTEGER */
  138. /* The number of Givens rotations which took place in this */
  139. /* subproblem. Not referenced if ICOMPQ = 0. */
  140. /* GIVCOL (output) INTEGER array, dimension ( LDGCOL, 2 ) */
  141. /* Each pair of numbers indicates a pair of columns to take place */
  142. /* in a Givens rotation. Not referenced if ICOMPQ = 0. */
  143. /* LDGCOL (input) INTEGER */
  144. /* leading dimension of GIVCOL, must be at least N. */
  145. /* GIVNUM (output) DOUBLE PRECISION array, dimension ( LDGNUM, 2 ) */
  146. /* Each number indicates the C or S value to be used in the */
  147. /* corresponding Givens rotation. Not referenced if ICOMPQ = 0. */
  148. /* LDGNUM (input) INTEGER */
  149. /* The leading dimension of GIVNUM and POLES, must be at least N. */
  150. /* POLES (output) DOUBLE PRECISION array, dimension ( LDGNUM, 2 ) */
  151. /* On exit, POLES(1,*) is an array containing the new singular */
  152. /* values obtained from solving the secular equation, and */
  153. /* POLES(2,*) is an array containing the poles in the secular */
  154. /* equation. Not referenced if ICOMPQ = 0. */
  155. /* DIFL (output) DOUBLE PRECISION array, dimension ( N ) */
  156. /* On exit, DIFL(I) is the distance between I-th updated */
  157. /* (undeflated) singular value and the I-th (undeflated) old */
  158. /* singular value. */
  159. /* DIFR (output) DOUBLE PRECISION array, */
  160. /* dimension ( LDGNUM, 2 ) if ICOMPQ = 1 and */
  161. /* dimension ( N ) if ICOMPQ = 0. */
  162. /* On exit, DIFR(I, 1) is the distance between I-th updated */
  163. /* (undeflated) singular value and the I+1-th (undeflated) old */
  164. /* singular value. */
  165. /* If ICOMPQ = 1, DIFR(1:K,2) is an array containing the */
  166. /* normalizing factors for the right singular vector matrix. */
  167. /* See DLASD8 for details on DIFL and DIFR. */
  168. /* Z (output) DOUBLE PRECISION array, dimension ( M ) */
  169. /* The first elements of this array contain the components */
  170. /* of the deflation-adjusted updating row vector. */
  171. /* K (output) INTEGER */
  172. /* Contains the dimension of the non-deflated matrix, */
  173. /* This is the order of the related secular equation. 1 <= K <=N. */
  174. /* C (output) DOUBLE PRECISION */
  175. /* C contains garbage if SQRE =0 and the C-value of a Givens */
  176. /* rotation related to the right null space if SQRE = 1. */
  177. /* S (output) DOUBLE PRECISION */
  178. /* S contains garbage if SQRE =0 and the S-value of a Givens */
  179. /* rotation related to the right null space if SQRE = 1. */
  180. /* WORK (workspace) DOUBLE PRECISION array, dimension ( 4 * M ) */
  181. /* IWORK (workspace) INTEGER array, dimension ( 3 * N ) */
  182. /* INFO (output) INTEGER */
  183. /* = 0: successful exit. */
  184. /* < 0: if INFO = -i, the i-th argument had an illegal value. */
  185. /* > 0: if INFO = 1, an singular value did not converge */
  186. /* Further Details */
  187. /* =============== */
  188. /* Based on contributions by */
  189. /* Ming Gu and Huan Ren, Computer Science Division, University of */
  190. /* California at Berkeley, USA */
  191. /* ===================================================================== */
  192. /* .. Parameters .. */
  193. /* .. */
  194. /* .. Local Scalars .. */
  195. /* .. */
  196. /* .. External Subroutines .. */
  197. /* .. */
  198. /* .. Intrinsic Functions .. */
  199. /* .. */
  200. /* .. Executable Statements .. */
  201. /* Test the input parameters. */
  202. /* Parameter adjustments */
  203. --d__;
  204. --vf;
  205. --vl;
  206. --idxq;
  207. --perm;
  208. givcol_dim1 = *ldgcol;
  209. givcol_offset = 1 + givcol_dim1;
  210. givcol -= givcol_offset;
  211. poles_dim1 = *ldgnum;
  212. poles_offset = 1 + poles_dim1;
  213. poles -= poles_offset;
  214. givnum_dim1 = *ldgnum;
  215. givnum_offset = 1 + givnum_dim1;
  216. givnum -= givnum_offset;
  217. --difl;
  218. --difr;
  219. --z__;
  220. --work;
  221. --iwork;
  222. /* Function Body */
  223. *info = 0;
  224. n = *nl + *nr + 1;
  225. m = n + *sqre;
  226. if (*icompq < 0 || *icompq > 1) {
  227. *info = -1;
  228. } else if (*nl < 1) {
  229. *info = -2;
  230. } else if (*nr < 1) {
  231. *info = -3;
  232. } else if (*sqre < 0 || *sqre > 1) {
  233. *info = -4;
  234. } else if (*ldgcol < n) {
  235. *info = -14;
  236. } else if (*ldgnum < n) {
  237. *info = -16;
  238. }
  239. if (*info != 0) {
  240. i__1 = -(*info);
  241. _starpu_xerbla_("DLASD6", &i__1);
  242. return 0;
  243. }
  244. /* The following values are for bookkeeping purposes only. They are */
  245. /* integer pointers which indicate the portion of the workspace */
  246. /* used by a particular array in DLASD7 and DLASD8. */
  247. isigma = 1;
  248. iw = isigma + n;
  249. ivfw = iw + m;
  250. ivlw = ivfw + m;
  251. idx = 1;
  252. idxc = idx + n;
  253. idxp = idxc + n;
  254. /* Scale. */
  255. /* Computing MAX */
  256. d__1 = abs(*alpha), d__2 = abs(*beta);
  257. orgnrm = max(d__1,d__2);
  258. d__[*nl + 1] = 0.;
  259. i__1 = n;
  260. for (i__ = 1; i__ <= i__1; ++i__) {
  261. if ((d__1 = d__[i__], abs(d__1)) > orgnrm) {
  262. orgnrm = (d__1 = d__[i__], abs(d__1));
  263. }
  264. /* L10: */
  265. }
  266. _starpu_dlascl_("G", &c__0, &c__0, &orgnrm, &c_b7, &n, &c__1, &d__[1], &n, info);
  267. *alpha /= orgnrm;
  268. *beta /= orgnrm;
  269. /* Sort and Deflate singular values. */
  270. _starpu_dlasd7_(icompq, nl, nr, sqre, k, &d__[1], &z__[1], &work[iw], &vf[1], &
  271. work[ivfw], &vl[1], &work[ivlw], alpha, beta, &work[isigma], &
  272. iwork[idx], &iwork[idxp], &idxq[1], &perm[1], givptr, &givcol[
  273. givcol_offset], ldgcol, &givnum[givnum_offset], ldgnum, c__, s,
  274. info);
  275. /* Solve Secular Equation, compute DIFL, DIFR, and update VF, VL. */
  276. _starpu_dlasd8_(icompq, k, &d__[1], &z__[1], &vf[1], &vl[1], &difl[1], &difr[1],
  277. ldgnum, &work[isigma], &work[iw], info);
  278. /* Save the poles if ICOMPQ = 1. */
  279. if (*icompq == 1) {
  280. _starpu_dcopy_(k, &d__[1], &c__1, &poles[poles_dim1 + 1], &c__1);
  281. _starpu_dcopy_(k, &work[isigma], &c__1, &poles[(poles_dim1 << 1) + 1], &c__1);
  282. }
  283. /* Unscale. */
  284. _starpu_dlascl_("G", &c__0, &c__0, &c_b7, &orgnrm, &n, &c__1, &d__[1], &n, info);
  285. /* Prepare the IDXQ sorting permutation. */
  286. n1 = *k;
  287. n2 = n - *k;
  288. _starpu_dlamrg_(&n1, &n2, &d__[1], &c__1, &c_n1, &idxq[1]);
  289. return 0;
  290. /* End of DLASD6 */
  291. } /* _starpu_dlasd6_ */