dgebd2.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /* dgebd2.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. /* Subroutine */ int _starpu_dgebd2_(integer *m, integer *n, doublereal *a, integer *
  16. lda, doublereal *d__, doublereal *e, doublereal *tauq, doublereal *
  17. taup, doublereal *work, integer *info)
  18. {
  19. /* System generated locals */
  20. integer a_dim1, a_offset, i__1, i__2, i__3;
  21. /* Local variables */
  22. integer i__;
  23. extern /* Subroutine */ int _starpu_dlarf_(char *, integer *, integer *,
  24. doublereal *, integer *, doublereal *, doublereal *, integer *,
  25. doublereal *), _starpu_dlarfg_(integer *, doublereal *,
  26. doublereal *, integer *, doublereal *), _starpu_xerbla_(char *, integer *);
  27. /* -- LAPACK routine (version 3.2) -- */
  28. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  29. /* November 2006 */
  30. /* .. Scalar Arguments .. */
  31. /* .. */
  32. /* .. Array Arguments .. */
  33. /* .. */
  34. /* Purpose */
  35. /* ======= */
  36. /* DGEBD2 reduces a real general m by n matrix A to upper or lower */
  37. /* bidiagonal form B by an orthogonal transformation: Q' * A * P = B. */
  38. /* If m >= n, B is upper bidiagonal; if m < n, B is lower bidiagonal. */
  39. /* Arguments */
  40. /* ========= */
  41. /* M (input) INTEGER */
  42. /* The number of rows in the matrix A. M >= 0. */
  43. /* N (input) INTEGER */
  44. /* The number of columns in the matrix A. N >= 0. */
  45. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  46. /* On entry, the m by n general matrix to be reduced. */
  47. /* On exit, */
  48. /* if m >= n, the diagonal and the first superdiagonal are */
  49. /* overwritten with the upper bidiagonal matrix B; the */
  50. /* elements below the diagonal, with the array TAUQ, represent */
  51. /* the orthogonal matrix Q as a product of elementary */
  52. /* reflectors, and the elements above the first superdiagonal, */
  53. /* with the array TAUP, represent the orthogonal matrix P as */
  54. /* a product of elementary reflectors; */
  55. /* if m < n, the diagonal and the first subdiagonal are */
  56. /* overwritten with the lower bidiagonal matrix B; the */
  57. /* elements below the first subdiagonal, with the array TAUQ, */
  58. /* represent the orthogonal matrix Q as a product of */
  59. /* elementary reflectors, and the elements above the diagonal, */
  60. /* with the array TAUP, represent the orthogonal matrix P as */
  61. /* a product of elementary reflectors. */
  62. /* See Further Details. */
  63. /* LDA (input) INTEGER */
  64. /* The leading dimension of the array A. LDA >= max(1,M). */
  65. /* D (output) DOUBLE PRECISION array, dimension (min(M,N)) */
  66. /* The diagonal elements of the bidiagonal matrix B: */
  67. /* D(i) = A(i,i). */
  68. /* E (output) DOUBLE PRECISION array, dimension (min(M,N)-1) */
  69. /* The off-diagonal elements of the bidiagonal matrix B: */
  70. /* if m >= n, E(i) = A(i,i+1) for i = 1,2,...,n-1; */
  71. /* if m < n, E(i) = A(i+1,i) for i = 1,2,...,m-1. */
  72. /* TAUQ (output) DOUBLE PRECISION array dimension (min(M,N)) */
  73. /* The scalar factors of the elementary reflectors which */
  74. /* represent the orthogonal matrix Q. See Further Details. */
  75. /* TAUP (output) DOUBLE PRECISION array, dimension (min(M,N)) */
  76. /* The scalar factors of the elementary reflectors which */
  77. /* represent the orthogonal matrix P. See Further Details. */
  78. /* WORK (workspace) DOUBLE PRECISION array, dimension (max(M,N)) */
  79. /* INFO (output) INTEGER */
  80. /* = 0: successful exit. */
  81. /* < 0: if INFO = -i, the i-th argument had an illegal value. */
  82. /* Further Details */
  83. /* =============== */
  84. /* The matrices Q and P are represented as products of elementary */
  85. /* reflectors: */
  86. /* If m >= n, */
  87. /* Q = H(1) H(2) . . . H(n) and P = G(1) G(2) . . . G(n-1) */
  88. /* Each H(i) and G(i) has the form: */
  89. /* H(i) = I - tauq * v * v' and G(i) = I - taup * u * u' */
  90. /* where tauq and taup are real scalars, and v and u are real vectors; */
  91. /* v(1:i-1) = 0, v(i) = 1, and v(i+1:m) is stored on exit in A(i+1:m,i); */
  92. /* u(1:i) = 0, u(i+1) = 1, and u(i+2:n) is stored on exit in A(i,i+2:n); */
  93. /* tauq is stored in TAUQ(i) and taup in TAUP(i). */
  94. /* If m < n, */
  95. /* Q = H(1) H(2) . . . H(m-1) and P = G(1) G(2) . . . G(m) */
  96. /* Each H(i) and G(i) has the form: */
  97. /* H(i) = I - tauq * v * v' and G(i) = I - taup * u * u' */
  98. /* where tauq and taup are real scalars, and v and u are real vectors; */
  99. /* v(1:i) = 0, v(i+1) = 1, and v(i+2:m) is stored on exit in A(i+2:m,i); */
  100. /* u(1:i-1) = 0, u(i) = 1, and u(i+1:n) is stored on exit in A(i,i+1:n); */
  101. /* tauq is stored in TAUQ(i) and taup in TAUP(i). */
  102. /* The contents of A on exit are illustrated by the following examples: */
  103. /* m = 6 and n = 5 (m > n): m = 5 and n = 6 (m < n): */
  104. /* ( d e u1 u1 u1 ) ( d u1 u1 u1 u1 u1 ) */
  105. /* ( v1 d e u2 u2 ) ( e d u2 u2 u2 u2 ) */
  106. /* ( v1 v2 d e u3 ) ( v1 e d u3 u3 u3 ) */
  107. /* ( v1 v2 v3 d e ) ( v1 v2 e d u4 u4 ) */
  108. /* ( v1 v2 v3 v4 d ) ( v1 v2 v3 e d u5 ) */
  109. /* ( v1 v2 v3 v4 v5 ) */
  110. /* where d and e denote diagonal and off-diagonal elements of B, vi */
  111. /* denotes an element of the vector defining H(i), and ui an element of */
  112. /* the vector defining G(i). */
  113. /* ===================================================================== */
  114. /* .. Parameters .. */
  115. /* .. */
  116. /* .. Local Scalars .. */
  117. /* .. */
  118. /* .. External Subroutines .. */
  119. /* .. */
  120. /* .. Intrinsic Functions .. */
  121. /* .. */
  122. /* .. Executable Statements .. */
  123. /* Test the input parameters */
  124. /* Parameter adjustments */
  125. a_dim1 = *lda;
  126. a_offset = 1 + a_dim1;
  127. a -= a_offset;
  128. --d__;
  129. --e;
  130. --tauq;
  131. --taup;
  132. --work;
  133. /* Function Body */
  134. *info = 0;
  135. if (*m < 0) {
  136. *info = -1;
  137. } else if (*n < 0) {
  138. *info = -2;
  139. } else if (*lda < max(1,*m)) {
  140. *info = -4;
  141. }
  142. if (*info < 0) {
  143. i__1 = -(*info);
  144. _starpu_xerbla_("DGEBD2", &i__1);
  145. return 0;
  146. }
  147. if (*m >= *n) {
  148. /* Reduce to upper bidiagonal form */
  149. i__1 = *n;
  150. for (i__ = 1; i__ <= i__1; ++i__) {
  151. /* Generate elementary reflector H(i) to annihilate A(i+1:m,i) */
  152. i__2 = *m - i__ + 1;
  153. /* Computing MIN */
  154. i__3 = i__ + 1;
  155. _starpu_dlarfg_(&i__2, &a[i__ + i__ * a_dim1], &a[min(i__3, *m)+ i__ *
  156. a_dim1], &c__1, &tauq[i__]);
  157. d__[i__] = a[i__ + i__ * a_dim1];
  158. a[i__ + i__ * a_dim1] = 1.;
  159. /* Apply H(i) to A(i:m,i+1:n) from the left */
  160. if (i__ < *n) {
  161. i__2 = *m - i__ + 1;
  162. i__3 = *n - i__;
  163. _starpu_dlarf_("Left", &i__2, &i__3, &a[i__ + i__ * a_dim1], &c__1, &
  164. tauq[i__], &a[i__ + (i__ + 1) * a_dim1], lda, &work[1]
  165. );
  166. }
  167. a[i__ + i__ * a_dim1] = d__[i__];
  168. if (i__ < *n) {
  169. /* Generate elementary reflector G(i) to annihilate */
  170. /* A(i,i+2:n) */
  171. i__2 = *n - i__;
  172. /* Computing MIN */
  173. i__3 = i__ + 2;
  174. _starpu_dlarfg_(&i__2, &a[i__ + (i__ + 1) * a_dim1], &a[i__ + min(
  175. i__3, *n)* a_dim1], lda, &taup[i__]);
  176. e[i__] = a[i__ + (i__ + 1) * a_dim1];
  177. a[i__ + (i__ + 1) * a_dim1] = 1.;
  178. /* Apply G(i) to A(i+1:m,i+1:n) from the right */
  179. i__2 = *m - i__;
  180. i__3 = *n - i__;
  181. _starpu_dlarf_("Right", &i__2, &i__3, &a[i__ + (i__ + 1) * a_dim1],
  182. lda, &taup[i__], &a[i__ + 1 + (i__ + 1) * a_dim1],
  183. lda, &work[1]);
  184. a[i__ + (i__ + 1) * a_dim1] = e[i__];
  185. } else {
  186. taup[i__] = 0.;
  187. }
  188. /* L10: */
  189. }
  190. } else {
  191. /* Reduce to lower bidiagonal form */
  192. i__1 = *m;
  193. for (i__ = 1; i__ <= i__1; ++i__) {
  194. /* Generate elementary reflector G(i) to annihilate A(i,i+1:n) */
  195. i__2 = *n - i__ + 1;
  196. /* Computing MIN */
  197. i__3 = i__ + 1;
  198. _starpu_dlarfg_(&i__2, &a[i__ + i__ * a_dim1], &a[i__ + min(i__3, *n)*
  199. a_dim1], lda, &taup[i__]);
  200. d__[i__] = a[i__ + i__ * a_dim1];
  201. a[i__ + i__ * a_dim1] = 1.;
  202. /* Apply G(i) to A(i+1:m,i:n) from the right */
  203. if (i__ < *m) {
  204. i__2 = *m - i__;
  205. i__3 = *n - i__ + 1;
  206. _starpu_dlarf_("Right", &i__2, &i__3, &a[i__ + i__ * a_dim1], lda, &
  207. taup[i__], &a[i__ + 1 + i__ * a_dim1], lda, &work[1]);
  208. }
  209. a[i__ + i__ * a_dim1] = d__[i__];
  210. if (i__ < *m) {
  211. /* Generate elementary reflector H(i) to annihilate */
  212. /* A(i+2:m,i) */
  213. i__2 = *m - i__;
  214. /* Computing MIN */
  215. i__3 = i__ + 2;
  216. _starpu_dlarfg_(&i__2, &a[i__ + 1 + i__ * a_dim1], &a[min(i__3, *m)+
  217. i__ * a_dim1], &c__1, &tauq[i__]);
  218. e[i__] = a[i__ + 1 + i__ * a_dim1];
  219. a[i__ + 1 + i__ * a_dim1] = 1.;
  220. /* Apply H(i) to A(i+1:m,i+1:n) from the left */
  221. i__2 = *m - i__;
  222. i__3 = *n - i__;
  223. _starpu_dlarf_("Left", &i__2, &i__3, &a[i__ + 1 + i__ * a_dim1], &
  224. c__1, &tauq[i__], &a[i__ + 1 + (i__ + 1) * a_dim1],
  225. lda, &work[1]);
  226. a[i__ + 1 + i__ * a_dim1] = e[i__];
  227. } else {
  228. tauq[i__] = 0.;
  229. }
  230. /* L20: */
  231. }
  232. }
  233. return 0;
  234. /* End of DGEBD2 */
  235. } /* _starpu_dgebd2_ */