dorgbr.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /* dorgbr.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_n1 = -1;
  16. /* Subroutine */ int _starpu_dorgbr_(char *vect, integer *m, integer *n, integer *k,
  17. doublereal *a, integer *lda, doublereal *tau, doublereal *work,
  18. integer *lwork, integer *info)
  19. {
  20. /* System generated locals */
  21. integer a_dim1, a_offset, i__1, i__2, i__3;
  22. /* Local variables */
  23. integer i__, j, nb, mn;
  24. extern logical _starpu_lsame_(char *, char *);
  25. integer iinfo;
  26. logical wantq;
  27. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  28. extern integer _starpu_ilaenv_(integer *, char *, char *, integer *, integer *,
  29. integer *, integer *);
  30. extern /* Subroutine */ int _starpu_dorglq_(integer *, integer *, integer *,
  31. doublereal *, integer *, doublereal *, doublereal *, integer *,
  32. integer *), _starpu_dorgqr_(integer *, integer *, integer *, doublereal *,
  33. integer *, doublereal *, doublereal *, integer *, integer *);
  34. integer lwkopt;
  35. logical lquery;
  36. /* -- LAPACK routine (version 3.2) -- */
  37. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  38. /* November 2006 */
  39. /* .. Scalar Arguments .. */
  40. /* .. */
  41. /* .. Array Arguments .. */
  42. /* .. */
  43. /* Purpose */
  44. /* ======= */
  45. /* DORGBR generates one of the real orthogonal matrices Q or P**T */
  46. /* determined by DGEBRD when reducing a real matrix A to bidiagonal */
  47. /* form: A = Q * B * P**T. Q and P**T are defined as products of */
  48. /* elementary reflectors H(i) or G(i) respectively. */
  49. /* If VECT = 'Q', A is assumed to have been an M-by-K matrix, and Q */
  50. /* is of order M: */
  51. /* if m >= k, Q = H(1) H(2) . . . H(k) and DORGBR returns the first n */
  52. /* columns of Q, where m >= n >= k; */
  53. /* if m < k, Q = H(1) H(2) . . . H(m-1) and DORGBR returns Q as an */
  54. /* M-by-M matrix. */
  55. /* If VECT = 'P', A is assumed to have been a K-by-N matrix, and P**T */
  56. /* is of order N: */
  57. /* if k < n, P**T = G(k) . . . G(2) G(1) and DORGBR returns the first m */
  58. /* rows of P**T, where n >= m >= k; */
  59. /* if k >= n, P**T = G(n-1) . . . G(2) G(1) and DORGBR returns P**T as */
  60. /* an N-by-N matrix. */
  61. /* Arguments */
  62. /* ========= */
  63. /* VECT (input) CHARACTER*1 */
  64. /* Specifies whether the matrix Q or the matrix P**T is */
  65. /* required, as defined in the transformation applied by DGEBRD: */
  66. /* = 'Q': generate Q; */
  67. /* = 'P': generate P**T. */
  68. /* M (input) INTEGER */
  69. /* The number of rows of the matrix Q or P**T to be returned. */
  70. /* M >= 0. */
  71. /* N (input) INTEGER */
  72. /* The number of columns of the matrix Q or P**T to be returned. */
  73. /* N >= 0. */
  74. /* If VECT = 'Q', M >= N >= min(M,K); */
  75. /* if VECT = 'P', N >= M >= min(N,K). */
  76. /* K (input) INTEGER */
  77. /* If VECT = 'Q', the number of columns in the original M-by-K */
  78. /* matrix reduced by DGEBRD. */
  79. /* If VECT = 'P', the number of rows in the original K-by-N */
  80. /* matrix reduced by DGEBRD. */
  81. /* K >= 0. */
  82. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  83. /* On entry, the vectors which define the elementary reflectors, */
  84. /* as returned by DGEBRD. */
  85. /* On exit, the M-by-N matrix Q or P**T. */
  86. /* LDA (input) INTEGER */
  87. /* The leading dimension of the array A. LDA >= max(1,M). */
  88. /* TAU (input) DOUBLE PRECISION array, dimension */
  89. /* (min(M,K)) if VECT = 'Q' */
  90. /* (min(N,K)) if VECT = 'P' */
  91. /* TAU(i) must contain the scalar factor of the elementary */
  92. /* reflector H(i) or G(i), which determines Q or P**T, as */
  93. /* returned by DGEBRD in its array argument TAUQ or TAUP. */
  94. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  95. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  96. /* LWORK (input) INTEGER */
  97. /* The dimension of the array WORK. LWORK >= max(1,min(M,N)). */
  98. /* For optimum performance LWORK >= min(M,N)*NB, where NB */
  99. /* is the optimal blocksize. */
  100. /* If LWORK = -1, then a workspace query is assumed; the routine */
  101. /* only calculates the optimal size of the WORK array, returns */
  102. /* this value as the first entry of the WORK array, and no error */
  103. /* message related to LWORK is issued by XERBLA. */
  104. /* INFO (output) INTEGER */
  105. /* = 0: successful exit */
  106. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  107. /* ===================================================================== */
  108. /* .. Parameters .. */
  109. /* .. */
  110. /* .. Local Scalars .. */
  111. /* .. */
  112. /* .. External Functions .. */
  113. /* .. */
  114. /* .. External Subroutines .. */
  115. /* .. */
  116. /* .. Intrinsic Functions .. */
  117. /* .. */
  118. /* .. Executable Statements .. */
  119. /* Test the input arguments */
  120. /* Parameter adjustments */
  121. a_dim1 = *lda;
  122. a_offset = 1 + a_dim1;
  123. a -= a_offset;
  124. --tau;
  125. --work;
  126. /* Function Body */
  127. *info = 0;
  128. wantq = _starpu_lsame_(vect, "Q");
  129. mn = min(*m,*n);
  130. lquery = *lwork == -1;
  131. if (! wantq && ! _starpu_lsame_(vect, "P")) {
  132. *info = -1;
  133. } else if (*m < 0) {
  134. *info = -2;
  135. } else if (*n < 0 || wantq && (*n > *m || *n < min(*m,*k)) || ! wantq && (
  136. *m > *n || *m < min(*n,*k))) {
  137. *info = -3;
  138. } else if (*k < 0) {
  139. *info = -4;
  140. } else if (*lda < max(1,*m)) {
  141. *info = -6;
  142. } else if (*lwork < max(1,mn) && ! lquery) {
  143. *info = -9;
  144. }
  145. if (*info == 0) {
  146. if (wantq) {
  147. nb = _starpu_ilaenv_(&c__1, "DORGQR", " ", m, n, k, &c_n1);
  148. } else {
  149. nb = _starpu_ilaenv_(&c__1, "DORGLQ", " ", m, n, k, &c_n1);
  150. }
  151. lwkopt = max(1,mn) * nb;
  152. work[1] = (doublereal) lwkopt;
  153. }
  154. if (*info != 0) {
  155. i__1 = -(*info);
  156. _starpu_xerbla_("DORGBR", &i__1);
  157. return 0;
  158. } else if (lquery) {
  159. return 0;
  160. }
  161. /* Quick return if possible */
  162. if (*m == 0 || *n == 0) {
  163. work[1] = 1.;
  164. return 0;
  165. }
  166. if (wantq) {
  167. /* Form Q, determined by a call to DGEBRD to reduce an m-by-k */
  168. /* matrix */
  169. if (*m >= *k) {
  170. /* If m >= k, assume m >= n >= k */
  171. _starpu_dorgqr_(m, n, k, &a[a_offset], lda, &tau[1], &work[1], lwork, &
  172. iinfo);
  173. } else {
  174. /* If m < k, assume m = n */
  175. /* Shift the vectors which define the elementary reflectors one */
  176. /* column to the right, and set the first row and column of Q */
  177. /* to those of the unit matrix */
  178. for (j = *m; j >= 2; --j) {
  179. a[j * a_dim1 + 1] = 0.;
  180. i__1 = *m;
  181. for (i__ = j + 1; i__ <= i__1; ++i__) {
  182. a[i__ + j * a_dim1] = a[i__ + (j - 1) * a_dim1];
  183. /* L10: */
  184. }
  185. /* L20: */
  186. }
  187. a[a_dim1 + 1] = 1.;
  188. i__1 = *m;
  189. for (i__ = 2; i__ <= i__1; ++i__) {
  190. a[i__ + a_dim1] = 0.;
  191. /* L30: */
  192. }
  193. if (*m > 1) {
  194. /* Form Q(2:m,2:m) */
  195. i__1 = *m - 1;
  196. i__2 = *m - 1;
  197. i__3 = *m - 1;
  198. _starpu_dorgqr_(&i__1, &i__2, &i__3, &a[(a_dim1 << 1) + 2], lda, &tau[
  199. 1], &work[1], lwork, &iinfo);
  200. }
  201. }
  202. } else {
  203. /* Form P', determined by a call to DGEBRD to reduce a k-by-n */
  204. /* matrix */
  205. if (*k < *n) {
  206. /* If k < n, assume k <= m <= n */
  207. _starpu_dorglq_(m, n, k, &a[a_offset], lda, &tau[1], &work[1], lwork, &
  208. iinfo);
  209. } else {
  210. /* If k >= n, assume m = n */
  211. /* Shift the vectors which define the elementary reflectors one */
  212. /* row downward, and set the first row and column of P' to */
  213. /* those of the unit matrix */
  214. a[a_dim1 + 1] = 1.;
  215. i__1 = *n;
  216. for (i__ = 2; i__ <= i__1; ++i__) {
  217. a[i__ + a_dim1] = 0.;
  218. /* L40: */
  219. }
  220. i__1 = *n;
  221. for (j = 2; j <= i__1; ++j) {
  222. for (i__ = j - 1; i__ >= 2; --i__) {
  223. a[i__ + j * a_dim1] = a[i__ - 1 + j * a_dim1];
  224. /* L50: */
  225. }
  226. a[j * a_dim1 + 1] = 0.;
  227. /* L60: */
  228. }
  229. if (*n > 1) {
  230. /* Form P'(2:n,2:n) */
  231. i__1 = *n - 1;
  232. i__2 = *n - 1;
  233. i__3 = *n - 1;
  234. _starpu_dorglq_(&i__1, &i__2, &i__3, &a[(a_dim1 << 1) + 2], lda, &tau[
  235. 1], &work[1], lwork, &iinfo);
  236. }
  237. }
  238. }
  239. work[1] = (doublereal) lwkopt;
  240. return 0;
  241. /* End of DORGBR */
  242. } /* _starpu_dorgbr_ */