dorglq.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /* dorglq.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. static integer c__3 = 3;
  17. static integer c__2 = 2;
  18. /* Subroutine */ int dorglq_(integer *m, integer *n, integer *k, doublereal *
  19. a, integer *lda, doublereal *tau, doublereal *work, integer *lwork,
  20. integer *info)
  21. {
  22. /* System generated locals */
  23. integer a_dim1, a_offset, i__1, i__2, i__3;
  24. /* Local variables */
  25. integer i__, j, l, ib, nb, ki, kk, nx, iws, nbmin, iinfo;
  26. extern /* Subroutine */ int dorgl2_(integer *, integer *, integer *,
  27. doublereal *, integer *, doublereal *, doublereal *, integer *),
  28. dlarfb_(char *, char *, char *, char *, integer *, integer *,
  29. integer *, doublereal *, integer *, doublereal *, integer *,
  30. doublereal *, integer *, doublereal *, integer *), dlarft_(char *, char *, integer *, integer *,
  31. doublereal *, integer *, doublereal *, doublereal *, integer *), xerbla_(char *, integer *);
  32. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  33. integer *, integer *);
  34. integer ldwork, 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. /* DORGLQ generates an M-by-N real matrix Q with orthonormal rows, */
  46. /* which is defined as the first M rows of a product of K elementary */
  47. /* reflectors of order N */
  48. /* Q = H(k) . . . H(2) H(1) */
  49. /* as returned by DGELQF. */
  50. /* Arguments */
  51. /* ========= */
  52. /* M (input) INTEGER */
  53. /* The number of rows of the matrix Q. M >= 0. */
  54. /* N (input) INTEGER */
  55. /* The number of columns of the matrix Q. N >= M. */
  56. /* K (input) INTEGER */
  57. /* The number of elementary reflectors whose product defines the */
  58. /* matrix Q. M >= K >= 0. */
  59. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  60. /* On entry, the i-th row must contain the vector which defines */
  61. /* the elementary reflector H(i), for i = 1,2,...,k, as returned */
  62. /* by DGELQF in the first k rows of its array argument A. */
  63. /* On exit, the M-by-N matrix Q. */
  64. /* LDA (input) INTEGER */
  65. /* The first dimension of the array A. LDA >= max(1,M). */
  66. /* TAU (input) DOUBLE PRECISION array, dimension (K) */
  67. /* TAU(i) must contain the scalar factor of the elementary */
  68. /* reflector H(i), as returned by DGELQF. */
  69. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  70. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  71. /* LWORK (input) INTEGER */
  72. /* The dimension of the array WORK. LWORK >= max(1,M). */
  73. /* For optimum performance LWORK >= M*NB, where NB is */
  74. /* the optimal blocksize. */
  75. /* If LWORK = -1, then a workspace query is assumed; the routine */
  76. /* only calculates the optimal size of the WORK array, returns */
  77. /* this value as the first entry of the WORK array, and no error */
  78. /* message related to LWORK is issued by XERBLA. */
  79. /* INFO (output) INTEGER */
  80. /* = 0: successful exit */
  81. /* < 0: if INFO = -i, the i-th argument has an illegal value */
  82. /* ===================================================================== */
  83. /* .. Parameters .. */
  84. /* .. */
  85. /* .. Local Scalars .. */
  86. /* .. */
  87. /* .. External Subroutines .. */
  88. /* .. */
  89. /* .. Intrinsic Functions .. */
  90. /* .. */
  91. /* .. External Functions .. */
  92. /* .. */
  93. /* .. Executable Statements .. */
  94. /* Test the input arguments */
  95. /* Parameter adjustments */
  96. a_dim1 = *lda;
  97. a_offset = 1 + a_dim1;
  98. a -= a_offset;
  99. --tau;
  100. --work;
  101. /* Function Body */
  102. *info = 0;
  103. nb = ilaenv_(&c__1, "DORGLQ", " ", m, n, k, &c_n1);
  104. lwkopt = max(1,*m) * nb;
  105. work[1] = (doublereal) lwkopt;
  106. lquery = *lwork == -1;
  107. if (*m < 0) {
  108. *info = -1;
  109. } else if (*n < *m) {
  110. *info = -2;
  111. } else if (*k < 0 || *k > *m) {
  112. *info = -3;
  113. } else if (*lda < max(1,*m)) {
  114. *info = -5;
  115. } else if (*lwork < max(1,*m) && ! lquery) {
  116. *info = -8;
  117. }
  118. if (*info != 0) {
  119. i__1 = -(*info);
  120. xerbla_("DORGLQ", &i__1);
  121. return 0;
  122. } else if (lquery) {
  123. return 0;
  124. }
  125. /* Quick return if possible */
  126. if (*m <= 0) {
  127. work[1] = 1.;
  128. return 0;
  129. }
  130. nbmin = 2;
  131. nx = 0;
  132. iws = *m;
  133. if (nb > 1 && nb < *k) {
  134. /* Determine when to cross over from blocked to unblocked code. */
  135. /* Computing MAX */
  136. i__1 = 0, i__2 = ilaenv_(&c__3, "DORGLQ", " ", m, n, k, &c_n1);
  137. nx = max(i__1,i__2);
  138. if (nx < *k) {
  139. /* Determine if workspace is large enough for blocked code. */
  140. ldwork = *m;
  141. iws = ldwork * nb;
  142. if (*lwork < iws) {
  143. /* Not enough workspace to use optimal NB: reduce NB and */
  144. /* determine the minimum value of NB. */
  145. nb = *lwork / ldwork;
  146. /* Computing MAX */
  147. i__1 = 2, i__2 = ilaenv_(&c__2, "DORGLQ", " ", m, n, k, &c_n1);
  148. nbmin = max(i__1,i__2);
  149. }
  150. }
  151. }
  152. if (nb >= nbmin && nb < *k && nx < *k) {
  153. /* Use blocked code after the last block. */
  154. /* The first kk rows are handled by the block method. */
  155. ki = (*k - nx - 1) / nb * nb;
  156. /* Computing MIN */
  157. i__1 = *k, i__2 = ki + nb;
  158. kk = min(i__1,i__2);
  159. /* Set A(kk+1:m,1:kk) to zero. */
  160. i__1 = kk;
  161. for (j = 1; j <= i__1; ++j) {
  162. i__2 = *m;
  163. for (i__ = kk + 1; i__ <= i__2; ++i__) {
  164. a[i__ + j * a_dim1] = 0.;
  165. /* L10: */
  166. }
  167. /* L20: */
  168. }
  169. } else {
  170. kk = 0;
  171. }
  172. /* Use unblocked code for the last or only block. */
  173. if (kk < *m) {
  174. i__1 = *m - kk;
  175. i__2 = *n - kk;
  176. i__3 = *k - kk;
  177. dorgl2_(&i__1, &i__2, &i__3, &a[kk + 1 + (kk + 1) * a_dim1], lda, &
  178. tau[kk + 1], &work[1], &iinfo);
  179. }
  180. if (kk > 0) {
  181. /* Use blocked code */
  182. i__1 = -nb;
  183. for (i__ = ki + 1; i__1 < 0 ? i__ >= 1 : i__ <= 1; i__ += i__1) {
  184. /* Computing MIN */
  185. i__2 = nb, i__3 = *k - i__ + 1;
  186. ib = min(i__2,i__3);
  187. if (i__ + ib <= *m) {
  188. /* Form the triangular factor of the block reflector */
  189. /* H = H(i) H(i+1) . . . H(i+ib-1) */
  190. i__2 = *n - i__ + 1;
  191. dlarft_("Forward", "Rowwise", &i__2, &ib, &a[i__ + i__ *
  192. a_dim1], lda, &tau[i__], &work[1], &ldwork);
  193. /* Apply H' to A(i+ib:m,i:n) from the right */
  194. i__2 = *m - i__ - ib + 1;
  195. i__3 = *n - i__ + 1;
  196. dlarfb_("Right", "Transpose", "Forward", "Rowwise", &i__2, &
  197. i__3, &ib, &a[i__ + i__ * a_dim1], lda, &work[1], &
  198. ldwork, &a[i__ + ib + i__ * a_dim1], lda, &work[ib +
  199. 1], &ldwork);
  200. }
  201. /* Apply H' to columns i:n of current block */
  202. i__2 = *n - i__ + 1;
  203. dorgl2_(&ib, &i__2, &ib, &a[i__ + i__ * a_dim1], lda, &tau[i__], &
  204. work[1], &iinfo);
  205. /* Set columns 1:i-1 of current block to zero */
  206. i__2 = i__ - 1;
  207. for (j = 1; j <= i__2; ++j) {
  208. i__3 = i__ + ib - 1;
  209. for (l = i__; l <= i__3; ++l) {
  210. a[l + j * a_dim1] = 0.;
  211. /* L30: */
  212. }
  213. /* L40: */
  214. }
  215. /* L50: */
  216. }
  217. }
  218. work[1] = (doublereal) iws;
  219. return 0;
  220. /* End of DORGLQ */
  221. } /* dorglq_ */