dgeqpf.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /* dgeqpf.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_dgeqpf_(integer *m, integer *n, doublereal *a, integer *
  16. lda, integer *jpvt, doublereal *tau, doublereal *work, integer *info)
  17. {
  18. /* System generated locals */
  19. integer a_dim1, a_offset, i__1, i__2, i__3;
  20. doublereal d__1, d__2;
  21. /* Builtin functions */
  22. double sqrt(doublereal);
  23. /* Local variables */
  24. integer i__, j, ma, mn;
  25. doublereal aii;
  26. integer pvt;
  27. doublereal temp;
  28. extern doublereal _starpu_dnrm2_(integer *, doublereal *, integer *);
  29. doublereal temp2, tol3z;
  30. extern /* Subroutine */ int _starpu_dlarf_(char *, integer *, integer *,
  31. doublereal *, integer *, doublereal *, doublereal *, integer *,
  32. doublereal *);
  33. integer itemp;
  34. extern /* Subroutine */ int _starpu_dswap_(integer *, doublereal *, integer *,
  35. doublereal *, integer *), _starpu_dgeqr2_(integer *, integer *,
  36. doublereal *, integer *, doublereal *, doublereal *, integer *),
  37. _starpu_dorm2r_(char *, char *, integer *, integer *, integer *,
  38. doublereal *, integer *, doublereal *, doublereal *, integer *,
  39. doublereal *, integer *);
  40. extern doublereal _starpu_dlamch_(char *);
  41. extern integer _starpu_idamax_(integer *, doublereal *, integer *);
  42. extern /* Subroutine */ int _starpu_dlarfp_(integer *, doublereal *, doublereal *,
  43. integer *, doublereal *), _starpu_xerbla_(char *, integer *);
  44. /* -- LAPACK deprecated driver routine (version 3.2) -- */
  45. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  46. /* November 2006 */
  47. /* .. Scalar Arguments .. */
  48. /* .. */
  49. /* .. Array Arguments .. */
  50. /* .. */
  51. /* Purpose */
  52. /* ======= */
  53. /* This routine is deprecated and has been replaced by routine DGEQP3. */
  54. /* DGEQPF computes a QR factorization with column pivoting of a */
  55. /* real M-by-N matrix A: A*P = Q*R. */
  56. /* Arguments */
  57. /* ========= */
  58. /* M (input) INTEGER */
  59. /* The number of rows of the matrix A. M >= 0. */
  60. /* N (input) INTEGER */
  61. /* The number of columns of the matrix A. N >= 0 */
  62. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  63. /* On entry, the M-by-N matrix A. */
  64. /* On exit, the upper triangle of the array contains the */
  65. /* min(M,N)-by-N upper triangular matrix R; the elements */
  66. /* below the diagonal, together with the array TAU, */
  67. /* represent the orthogonal matrix Q as a product of */
  68. /* min(m,n) elementary reflectors. */
  69. /* LDA (input) INTEGER */
  70. /* The leading dimension of the array A. LDA >= max(1,M). */
  71. /* JPVT (input/output) INTEGER array, dimension (N) */
  72. /* On entry, if JPVT(i) .ne. 0, the i-th column of A is permuted */
  73. /* to the front of A*P (a leading column); if JPVT(i) = 0, */
  74. /* the i-th column of A is a free column. */
  75. /* On exit, if JPVT(i) = k, then the i-th column of A*P */
  76. /* was the k-th column of A. */
  77. /* TAU (output) DOUBLE PRECISION array, dimension (min(M,N)) */
  78. /* The scalar factors of the elementary reflectors. */
  79. /* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */
  80. /* INFO (output) INTEGER */
  81. /* = 0: successful exit */
  82. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  83. /* Further Details */
  84. /* =============== */
  85. /* The matrix Q is represented as a product of elementary reflectors */
  86. /* Q = H(1) H(2) . . . H(n) */
  87. /* Each H(i) has the form */
  88. /* H = I - tau * v * v' */
  89. /* where tau is a real scalar, and v is a real vector with */
  90. /* v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in A(i+1:m,i). */
  91. /* The matrix P is represented in jpvt as follows: If */
  92. /* jpvt(j) = i */
  93. /* then the jth column of P is the ith canonical unit vector. */
  94. /* Partial column norm updating strategy modified by */
  95. /* Z. Drmac and Z. Bujanovic, Dept. of Mathematics, */
  96. /* University of Zagreb, Croatia. */
  97. /* June 2006. */
  98. /* For more details see LAPACK Working Note 176. */
  99. /* ===================================================================== */
  100. /* .. Parameters .. */
  101. /* .. */
  102. /* .. Local Scalars .. */
  103. /* .. */
  104. /* .. External Subroutines .. */
  105. /* .. */
  106. /* .. Intrinsic Functions .. */
  107. /* .. */
  108. /* .. External Functions .. */
  109. /* .. */
  110. /* .. Executable Statements .. */
  111. /* Test the input arguments */
  112. /* Parameter adjustments */
  113. a_dim1 = *lda;
  114. a_offset = 1 + a_dim1;
  115. a -= a_offset;
  116. --jpvt;
  117. --tau;
  118. --work;
  119. /* Function Body */
  120. *info = 0;
  121. if (*m < 0) {
  122. *info = -1;
  123. } else if (*n < 0) {
  124. *info = -2;
  125. } else if (*lda < max(1,*m)) {
  126. *info = -4;
  127. }
  128. if (*info != 0) {
  129. i__1 = -(*info);
  130. _starpu_xerbla_("DGEQPF", &i__1);
  131. return 0;
  132. }
  133. mn = min(*m,*n);
  134. tol3z = sqrt(_starpu_dlamch_("Epsilon"));
  135. /* Move initial columns up front */
  136. itemp = 1;
  137. i__1 = *n;
  138. for (i__ = 1; i__ <= i__1; ++i__) {
  139. if (jpvt[i__] != 0) {
  140. if (i__ != itemp) {
  141. _starpu_dswap_(m, &a[i__ * a_dim1 + 1], &c__1, &a[itemp * a_dim1 + 1],
  142. &c__1);
  143. jpvt[i__] = jpvt[itemp];
  144. jpvt[itemp] = i__;
  145. } else {
  146. jpvt[i__] = i__;
  147. }
  148. ++itemp;
  149. } else {
  150. jpvt[i__] = i__;
  151. }
  152. /* L10: */
  153. }
  154. --itemp;
  155. /* Compute the QR factorization and update remaining columns */
  156. if (itemp > 0) {
  157. ma = min(itemp,*m);
  158. _starpu_dgeqr2_(m, &ma, &a[a_offset], lda, &tau[1], &work[1], info);
  159. if (ma < *n) {
  160. i__1 = *n - ma;
  161. _starpu_dorm2r_("Left", "Transpose", m, &i__1, &ma, &a[a_offset], lda, &
  162. tau[1], &a[(ma + 1) * a_dim1 + 1], lda, &work[1], info);
  163. }
  164. }
  165. if (itemp < mn) {
  166. /* Initialize partial column norms. The first n elements of */
  167. /* work store the exact column norms. */
  168. i__1 = *n;
  169. for (i__ = itemp + 1; i__ <= i__1; ++i__) {
  170. i__2 = *m - itemp;
  171. work[i__] = _starpu_dnrm2_(&i__2, &a[itemp + 1 + i__ * a_dim1], &c__1);
  172. work[*n + i__] = work[i__];
  173. /* L20: */
  174. }
  175. /* Compute factorization */
  176. i__1 = mn;
  177. for (i__ = itemp + 1; i__ <= i__1; ++i__) {
  178. /* Determine ith pivot column and swap if necessary */
  179. i__2 = *n - i__ + 1;
  180. pvt = i__ - 1 + _starpu_idamax_(&i__2, &work[i__], &c__1);
  181. if (pvt != i__) {
  182. _starpu_dswap_(m, &a[pvt * a_dim1 + 1], &c__1, &a[i__ * a_dim1 + 1], &
  183. c__1);
  184. itemp = jpvt[pvt];
  185. jpvt[pvt] = jpvt[i__];
  186. jpvt[i__] = itemp;
  187. work[pvt] = work[i__];
  188. work[*n + pvt] = work[*n + i__];
  189. }
  190. /* Generate elementary reflector H(i) */
  191. if (i__ < *m) {
  192. i__2 = *m - i__ + 1;
  193. _starpu_dlarfp_(&i__2, &a[i__ + i__ * a_dim1], &a[i__ + 1 + i__ *
  194. a_dim1], &c__1, &tau[i__]);
  195. } else {
  196. _starpu_dlarfp_(&c__1, &a[*m + *m * a_dim1], &a[*m + *m * a_dim1], &
  197. c__1, &tau[*m]);
  198. }
  199. if (i__ < *n) {
  200. /* Apply H(i) to A(i:m,i+1:n) from the left */
  201. aii = a[i__ + i__ * a_dim1];
  202. a[i__ + i__ * a_dim1] = 1.;
  203. i__2 = *m - i__ + 1;
  204. i__3 = *n - i__;
  205. _starpu_dlarf_("LEFT", &i__2, &i__3, &a[i__ + i__ * a_dim1], &c__1, &
  206. tau[i__], &a[i__ + (i__ + 1) * a_dim1], lda, &work[(*
  207. n << 1) + 1]);
  208. a[i__ + i__ * a_dim1] = aii;
  209. }
  210. /* Update partial column norms */
  211. i__2 = *n;
  212. for (j = i__ + 1; j <= i__2; ++j) {
  213. if (work[j] != 0.) {
  214. /* NOTE: The following 4 lines follow from the analysis in */
  215. /* Lapack Working Note 176. */
  216. temp = (d__1 = a[i__ + j * a_dim1], abs(d__1)) / work[j];
  217. /* Computing MAX */
  218. d__1 = 0., d__2 = (temp + 1.) * (1. - temp);
  219. temp = max(d__1,d__2);
  220. /* Computing 2nd power */
  221. d__1 = work[j] / work[*n + j];
  222. temp2 = temp * (d__1 * d__1);
  223. if (temp2 <= tol3z) {
  224. if (*m - i__ > 0) {
  225. i__3 = *m - i__;
  226. work[j] = _starpu_dnrm2_(&i__3, &a[i__ + 1 + j * a_dim1],
  227. &c__1);
  228. work[*n + j] = work[j];
  229. } else {
  230. work[j] = 0.;
  231. work[*n + j] = 0.;
  232. }
  233. } else {
  234. work[j] *= sqrt(temp);
  235. }
  236. }
  237. /* L30: */
  238. }
  239. /* L40: */
  240. }
  241. }
  242. return 0;
  243. /* End of DGEQPF */
  244. } /* _starpu_dgeqpf_ */