dggqrf.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /* dggqrf.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_dggqrf_(integer *n, integer *m, integer *p, doublereal *
  17. a, integer *lda, doublereal *taua, doublereal *b, integer *ldb,
  18. doublereal *taub, doublereal *work, integer *lwork, integer *info)
  19. {
  20. /* System generated locals */
  21. integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2;
  22. /* Local variables */
  23. integer nb, nb1, nb2, nb3, lopt;
  24. extern /* Subroutine */ int _starpu_dgeqrf_(integer *, integer *, doublereal *,
  25. integer *, doublereal *, doublereal *, integer *, integer *),
  26. _starpu_dgerqf_(integer *, integer *, doublereal *, integer *, doublereal
  27. *, doublereal *, integer *, integer *), _starpu_xerbla_(char *, integer *);
  28. extern integer _starpu_ilaenv_(integer *, char *, char *, integer *, integer *,
  29. integer *, integer *);
  30. extern /* Subroutine */ int _starpu_dormqr_(char *, char *, integer *, integer *,
  31. integer *, doublereal *, integer *, doublereal *, doublereal *,
  32. integer *, doublereal *, integer *, integer *);
  33. integer lwkopt;
  34. logical lquery;
  35. /* -- LAPACK routine (version 3.2) -- */
  36. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  37. /* November 2006 */
  38. /* .. Scalar Arguments .. */
  39. /* .. */
  40. /* .. Array Arguments .. */
  41. /* .. */
  42. /* Purpose */
  43. /* ======= */
  44. /* DGGQRF computes a generalized QR factorization of an N-by-M matrix A */
  45. /* and an N-by-P matrix B: */
  46. /* A = Q*R, B = Q*T*Z, */
  47. /* where Q is an N-by-N orthogonal matrix, Z is a P-by-P orthogonal */
  48. /* matrix, and R and T assume one of the forms: */
  49. /* if N >= M, R = ( R11 ) M , or if N < M, R = ( R11 R12 ) N, */
  50. /* ( 0 ) N-M N M-N */
  51. /* M */
  52. /* where R11 is upper triangular, and */
  53. /* if N <= P, T = ( 0 T12 ) N, or if N > P, T = ( T11 ) N-P, */
  54. /* P-N N ( T21 ) P */
  55. /* P */
  56. /* where T12 or T21 is upper triangular. */
  57. /* In particular, if B is square and nonsingular, the GQR factorization */
  58. /* of A and B implicitly gives the QR factorization of inv(B)*A: */
  59. /* inv(B)*A = Z'*(inv(T)*R) */
  60. /* where inv(B) denotes the inverse of the matrix B, and Z' denotes the */
  61. /* transpose of the matrix Z. */
  62. /* Arguments */
  63. /* ========= */
  64. /* N (input) INTEGER */
  65. /* The number of rows of the matrices A and B. N >= 0. */
  66. /* M (input) INTEGER */
  67. /* The number of columns of the matrix A. M >= 0. */
  68. /* P (input) INTEGER */
  69. /* The number of columns of the matrix B. P >= 0. */
  70. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,M) */
  71. /* On entry, the N-by-M matrix A. */
  72. /* On exit, the elements on and above the diagonal of the array */
  73. /* contain the min(N,M)-by-M upper trapezoidal matrix R (R is */
  74. /* upper triangular if N >= M); the elements below the diagonal, */
  75. /* with the array TAUA, represent the orthogonal matrix Q as a */
  76. /* product of min(N,M) elementary reflectors (see Further */
  77. /* Details). */
  78. /* LDA (input) INTEGER */
  79. /* The leading dimension of the array A. LDA >= max(1,N). */
  80. /* TAUA (output) DOUBLE PRECISION array, dimension (min(N,M)) */
  81. /* The scalar factors of the elementary reflectors which */
  82. /* represent the orthogonal matrix Q (see Further Details). */
  83. /* B (input/output) DOUBLE PRECISION array, dimension (LDB,P) */
  84. /* On entry, the N-by-P matrix B. */
  85. /* On exit, if N <= P, the upper triangle of the subarray */
  86. /* B(1:N,P-N+1:P) contains the N-by-N upper triangular matrix T; */
  87. /* if N > P, the elements on and above the (N-P)-th subdiagonal */
  88. /* contain the N-by-P upper trapezoidal matrix T; the remaining */
  89. /* elements, with the array TAUB, represent the orthogonal */
  90. /* matrix Z as a product of elementary reflectors (see Further */
  91. /* Details). */
  92. /* LDB (input) INTEGER */
  93. /* The leading dimension of the array B. LDB >= max(1,N). */
  94. /* TAUB (output) DOUBLE PRECISION array, dimension (min(N,P)) */
  95. /* The scalar factors of the elementary reflectors which */
  96. /* represent the orthogonal matrix Z (see Further Details). */
  97. /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  98. /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  99. /* LWORK (input) INTEGER */
  100. /* The dimension of the array WORK. LWORK >= max(1,N,M,P). */
  101. /* For optimum performance LWORK >= max(N,M,P)*max(NB1,NB2,NB3), */
  102. /* where NB1 is the optimal blocksize for the QR factorization */
  103. /* of an N-by-M matrix, NB2 is the optimal blocksize for the */
  104. /* RQ factorization of an N-by-P matrix, and NB3 is the optimal */
  105. /* blocksize for a call of DORMQR. */
  106. /* If LWORK = -1, then a workspace query is assumed; the routine */
  107. /* only calculates the optimal size of the WORK array, returns */
  108. /* this value as the first entry of the WORK array, and no error */
  109. /* message related to LWORK is issued by XERBLA. */
  110. /* INFO (output) INTEGER */
  111. /* = 0: successful exit */
  112. /* < 0: if INFO = -i, the i-th argument had an illegal value. */
  113. /* Further Details */
  114. /* =============== */
  115. /* The matrix Q is represented as a product of elementary reflectors */
  116. /* Q = H(1) H(2) . . . H(k), where k = min(n,m). */
  117. /* Each H(i) has the form */
  118. /* H(i) = I - taua * v * v' */
  119. /* where taua is a real scalar, and v is a real vector with */
  120. /* v(1:i-1) = 0 and v(i) = 1; v(i+1:n) is stored on exit in A(i+1:n,i), */
  121. /* and taua in TAUA(i). */
  122. /* To form Q explicitly, use LAPACK subroutine DORGQR. */
  123. /* To use Q to update another matrix, use LAPACK subroutine DORMQR. */
  124. /* The matrix Z is represented as a product of elementary reflectors */
  125. /* Z = H(1) H(2) . . . H(k), where k = min(n,p). */
  126. /* Each H(i) has the form */
  127. /* H(i) = I - taub * v * v' */
  128. /* where taub is a real scalar, and v is a real vector with */
  129. /* v(p-k+i+1:p) = 0 and v(p-k+i) = 1; v(1:p-k+i-1) is stored on exit in */
  130. /* B(n-k+i,1:p-k+i-1), and taub in TAUB(i). */
  131. /* To form Z explicitly, use LAPACK subroutine DORGRQ. */
  132. /* To use Z to update another matrix, use LAPACK subroutine DORMRQ. */
  133. /* ===================================================================== */
  134. /* .. Local Scalars .. */
  135. /* .. */
  136. /* .. External Subroutines .. */
  137. /* .. */
  138. /* .. External Functions .. */
  139. /* .. */
  140. /* .. Intrinsic Functions .. */
  141. /* .. */
  142. /* .. Executable Statements .. */
  143. /* Test the input parameters */
  144. /* Parameter adjustments */
  145. a_dim1 = *lda;
  146. a_offset = 1 + a_dim1;
  147. a -= a_offset;
  148. --taua;
  149. b_dim1 = *ldb;
  150. b_offset = 1 + b_dim1;
  151. b -= b_offset;
  152. --taub;
  153. --work;
  154. /* Function Body */
  155. *info = 0;
  156. nb1 = _starpu_ilaenv_(&c__1, "DGEQRF", " ", n, m, &c_n1, &c_n1);
  157. nb2 = _starpu_ilaenv_(&c__1, "DGERQF", " ", n, p, &c_n1, &c_n1);
  158. nb3 = _starpu_ilaenv_(&c__1, "DORMQR", " ", n, m, p, &c_n1);
  159. /* Computing MAX */
  160. i__1 = max(nb1,nb2);
  161. nb = max(i__1,nb3);
  162. /* Computing MAX */
  163. i__1 = max(*n,*m);
  164. lwkopt = max(i__1,*p) * nb;
  165. work[1] = (doublereal) lwkopt;
  166. lquery = *lwork == -1;
  167. if (*n < 0) {
  168. *info = -1;
  169. } else if (*m < 0) {
  170. *info = -2;
  171. } else if (*p < 0) {
  172. *info = -3;
  173. } else if (*lda < max(1,*n)) {
  174. *info = -5;
  175. } else if (*ldb < max(1,*n)) {
  176. *info = -8;
  177. } else /* if(complicated condition) */ {
  178. /* Computing MAX */
  179. i__1 = max(1,*n), i__1 = max(i__1,*m);
  180. if (*lwork < max(i__1,*p) && ! lquery) {
  181. *info = -11;
  182. }
  183. }
  184. if (*info != 0) {
  185. i__1 = -(*info);
  186. _starpu_xerbla_("DGGQRF", &i__1);
  187. return 0;
  188. } else if (lquery) {
  189. return 0;
  190. }
  191. /* QR factorization of N-by-M matrix A: A = Q*R */
  192. _starpu_dgeqrf_(n, m, &a[a_offset], lda, &taua[1], &work[1], lwork, info);
  193. lopt = (integer) work[1];
  194. /* Update B := Q'*B. */
  195. i__1 = min(*n,*m);
  196. _starpu_dormqr_("Left", "Transpose", n, p, &i__1, &a[a_offset], lda, &taua[1], &b[
  197. b_offset], ldb, &work[1], lwork, info);
  198. /* Computing MAX */
  199. i__1 = lopt, i__2 = (integer) work[1];
  200. lopt = max(i__1,i__2);
  201. /* RQ factorization of N-by-P matrix B: B = T*Z. */
  202. _starpu_dgerqf_(n, p, &b[b_offset], ldb, &taub[1], &work[1], lwork, info);
  203. /* Computing MAX */
  204. i__1 = lopt, i__2 = (integer) work[1];
  205. work[1] = (doublereal) max(i__1,i__2);
  206. return 0;
  207. /* End of DGGQRF */
  208. } /* _starpu_dggqrf_ */