dlasd1.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /* dlasd1.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_dlasd1_(integer *nl, integer *nr, integer *sqre,
  19. doublereal *d__, doublereal *alpha, doublereal *beta, doublereal *u,
  20. integer *ldu, doublereal *vt, integer *ldvt, integer *idxq, integer *
  21. iwork, doublereal *work, integer *info)
  22. {
  23. /* System generated locals */
  24. integer u_dim1, u_offset, vt_dim1, vt_offset, i__1;
  25. doublereal d__1, d__2;
  26. /* Local variables */
  27. integer i__, k, m, n, n1, n2, iq, iz, iu2, ldq, idx, ldu2, ivt2, idxc,
  28. idxp, ldvt2;
  29. extern /* Subroutine */ int _starpu_dlasd2_(integer *, integer *, integer *,
  30. integer *, doublereal *, doublereal *, doublereal *, doublereal *,
  31. doublereal *, integer *, doublereal *, integer *, doublereal *,
  32. doublereal *, integer *, doublereal *, integer *, integer *,
  33. integer *, integer *, integer *, integer *, integer *), _starpu_dlasd3_(
  34. integer *, integer *, integer *, integer *, doublereal *,
  35. doublereal *, integer *, doublereal *, doublereal *, integer *,
  36. doublereal *, integer *, doublereal *, integer *, doublereal *,
  37. integer *, integer *, integer *, doublereal *, integer *),
  38. _starpu_dlascl_(char *, integer *, integer *, doublereal *, doublereal *,
  39. integer *, integer *, doublereal *, integer *, integer *),
  40. _starpu_dlamrg_(integer *, integer *, doublereal *, integer *, integer *,
  41. integer *);
  42. integer isigma;
  43. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  44. doublereal orgnrm;
  45. integer coltyp;
  46. /* -- LAPACK auxiliary routine (version 3.2) -- */
  47. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  48. /* November 2006 */
  49. /* .. Scalar Arguments .. */
  50. /* .. */
  51. /* .. Array Arguments .. */
  52. /* .. */
  53. /* Purpose */
  54. /* ======= */
  55. /* DLASD1 computes the SVD of an upper bidiagonal N-by-M matrix B, */
  56. /* where N = NL + NR + 1 and M = N + SQRE. DLASD1 is called from DLASD0. */
  57. /* A related subroutine DLASD7 handles the case in which the singular */
  58. /* values (and the singular vectors in factored form) are desired. */
  59. /* DLASD1 computes the SVD as follows: */
  60. /* ( D1(in) 0 0 0 ) */
  61. /* B = U(in) * ( Z1' a Z2' b ) * VT(in) */
  62. /* ( 0 0 D2(in) 0 ) */
  63. /* = U(out) * ( D(out) 0) * VT(out) */
  64. /* where Z' = (Z1' a Z2' b) = u' VT', and u is a vector of dimension M */
  65. /* with ALPHA and BETA in the NL+1 and NL+2 th entries and zeros */
  66. /* elsewhere; and the entry b is empty if SQRE = 0. */
  67. /* The left singular vectors of the original matrix are stored in U, and */
  68. /* the transpose of the right singular vectors are stored in VT, and the */
  69. /* singular values are in D. The algorithm consists of three stages: */
  70. /* The first stage consists of deflating the size of the problem */
  71. /* when there are multiple singular values or when there are zeros in */
  72. /* the Z vector. For each such occurence the dimension of the */
  73. /* secular equation problem is reduced by one. This stage is */
  74. /* performed by the routine DLASD2. */
  75. /* The second stage consists of calculating the updated */
  76. /* singular values. This is done by finding the square roots of the */
  77. /* roots of the secular equation via the routine DLASD4 (as called */
  78. /* by DLASD3). This routine also calculates the singular vectors of */
  79. /* the current problem. */
  80. /* The final stage consists of computing the updated singular vectors */
  81. /* directly using the updated singular values. The singular vectors */
  82. /* for the current problem are multiplied with the singular vectors */
  83. /* from the overall problem. */
  84. /* Arguments */
  85. /* ========= */
  86. /* NL (input) INTEGER */
  87. /* The row dimension of the upper block. NL >= 1. */
  88. /* NR (input) INTEGER */
  89. /* The row dimension of the lower block. NR >= 1. */
  90. /* SQRE (input) INTEGER */
  91. /* = 0: the lower block is an NR-by-NR square matrix. */
  92. /* = 1: the lower block is an NR-by-(NR+1) rectangular matrix. */
  93. /* The bidiagonal matrix has row dimension N = NL + NR + 1, */
  94. /* and column dimension M = N + SQRE. */
  95. /* D (input/output) DOUBLE PRECISION array, */
  96. /* dimension (N = NL+NR+1). */
  97. /* On entry D(1:NL,1:NL) contains the singular values of the */
  98. /* upper block; and D(NL+2:N) contains the singular values of */
  99. /* the lower block. On exit D(1:N) contains the singular values */
  100. /* of the modified matrix. */
  101. /* ALPHA (input/output) DOUBLE PRECISION */
  102. /* Contains the diagonal element associated with the added row. */
  103. /* BETA (input/output) DOUBLE PRECISION */
  104. /* Contains the off-diagonal element associated with the added */
  105. /* row. */
  106. /* U (input/output) DOUBLE PRECISION array, dimension(LDU,N) */
  107. /* On entry U(1:NL, 1:NL) contains the left singular vectors of */
  108. /* the upper block; U(NL+2:N, NL+2:N) contains the left singular */
  109. /* vectors of the lower block. On exit U contains the left */
  110. /* singular vectors of the bidiagonal matrix. */
  111. /* LDU (input) INTEGER */
  112. /* The leading dimension of the array U. LDU >= max( 1, N ). */
  113. /* VT (input/output) DOUBLE PRECISION array, dimension(LDVT,M) */
  114. /* where M = N + SQRE. */
  115. /* On entry VT(1:NL+1, 1:NL+1)' contains the right singular */
  116. /* vectors of the upper block; VT(NL+2:M, NL+2:M)' contains */
  117. /* the right singular vectors of the lower block. On exit */
  118. /* VT' contains the right singular vectors of the */
  119. /* bidiagonal matrix. */
  120. /* LDVT (input) INTEGER */
  121. /* The leading dimension of the array VT. LDVT >= max( 1, M ). */
  122. /* IDXQ (output) INTEGER array, dimension(N) */
  123. /* This contains the permutation which will reintegrate the */
  124. /* subproblem just solved back into sorted order, i.e. */
  125. /* D( IDXQ( I = 1, N ) ) will be in ascending order. */
  126. /* IWORK (workspace) INTEGER array, dimension( 4 * N ) */
  127. /* WORK (workspace) DOUBLE PRECISION array, dimension( 3*M**2 + 2*M ) */
  128. /* INFO (output) INTEGER */
  129. /* = 0: successful exit. */
  130. /* < 0: if INFO = -i, the i-th argument had an illegal value. */
  131. /* > 0: if INFO = 1, an singular value did not converge */
  132. /* Further Details */
  133. /* =============== */
  134. /* Based on contributions by */
  135. /* Ming Gu and Huan Ren, Computer Science Division, University of */
  136. /* California at Berkeley, USA */
  137. /* ===================================================================== */
  138. /* .. Parameters .. */
  139. /* .. */
  140. /* .. Local Scalars .. */
  141. /* .. */
  142. /* .. External Subroutines .. */
  143. /* .. */
  144. /* .. Intrinsic Functions .. */
  145. /* .. */
  146. /* .. Executable Statements .. */
  147. /* Test the input parameters. */
  148. /* Parameter adjustments */
  149. --d__;
  150. u_dim1 = *ldu;
  151. u_offset = 1 + u_dim1;
  152. u -= u_offset;
  153. vt_dim1 = *ldvt;
  154. vt_offset = 1 + vt_dim1;
  155. vt -= vt_offset;
  156. --idxq;
  157. --iwork;
  158. --work;
  159. /* Function Body */
  160. *info = 0;
  161. if (*nl < 1) {
  162. *info = -1;
  163. } else if (*nr < 1) {
  164. *info = -2;
  165. } else if (*sqre < 0 || *sqre > 1) {
  166. *info = -3;
  167. }
  168. if (*info != 0) {
  169. i__1 = -(*info);
  170. _starpu_xerbla_("DLASD1", &i__1);
  171. return 0;
  172. }
  173. n = *nl + *nr + 1;
  174. m = n + *sqre;
  175. /* The following values are for bookkeeping purposes only. They are */
  176. /* integer pointers which indicate the portion of the workspace */
  177. /* used by a particular array in DLASD2 and DLASD3. */
  178. ldu2 = n;
  179. ldvt2 = m;
  180. iz = 1;
  181. isigma = iz + m;
  182. iu2 = isigma + n;
  183. ivt2 = iu2 + ldu2 * n;
  184. iq = ivt2 + ldvt2 * m;
  185. idx = 1;
  186. idxc = idx + n;
  187. coltyp = idxc + n;
  188. idxp = coltyp + n;
  189. /* Scale. */
  190. /* Computing MAX */
  191. d__1 = abs(*alpha), d__2 = abs(*beta);
  192. orgnrm = max(d__1,d__2);
  193. d__[*nl + 1] = 0.;
  194. i__1 = n;
  195. for (i__ = 1; i__ <= i__1; ++i__) {
  196. if ((d__1 = d__[i__], abs(d__1)) > orgnrm) {
  197. orgnrm = (d__1 = d__[i__], abs(d__1));
  198. }
  199. /* L10: */
  200. }
  201. _starpu_dlascl_("G", &c__0, &c__0, &orgnrm, &c_b7, &n, &c__1, &d__[1], &n, info);
  202. *alpha /= orgnrm;
  203. *beta /= orgnrm;
  204. /* Deflate singular values. */
  205. _starpu_dlasd2_(nl, nr, sqre, &k, &d__[1], &work[iz], alpha, beta, &u[u_offset],
  206. ldu, &vt[vt_offset], ldvt, &work[isigma], &work[iu2], &ldu2, &
  207. work[ivt2], &ldvt2, &iwork[idxp], &iwork[idx], &iwork[idxc], &
  208. idxq[1], &iwork[coltyp], info);
  209. /* Solve Secular Equation and update singular vectors. */
  210. ldq = k;
  211. _starpu_dlasd3_(nl, nr, sqre, &k, &d__[1], &work[iq], &ldq, &work[isigma], &u[
  212. u_offset], ldu, &work[iu2], &ldu2, &vt[vt_offset], ldvt, &work[
  213. ivt2], &ldvt2, &iwork[idxc], &iwork[coltyp], &work[iz], info);
  214. if (*info != 0) {
  215. return 0;
  216. }
  217. /* Unscale. */
  218. _starpu_dlascl_("G", &c__0, &c__0, &c_b7, &orgnrm, &n, &c__1, &d__[1], &n, info);
  219. /* Prepare the IDXQ sorting permutation. */
  220. n1 = k;
  221. n2 = n - k;
  222. _starpu_dlamrg_(&n1, &n2, &d__[1], &c__1, &c_n1, &idxq[1]);
  223. return 0;
  224. /* End of DLASD1 */
  225. } /* _starpu_dlasd1_ */