dlaqp2.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /* dlaqp2.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_dlaqp2_(integer *m, integer *n, integer *offset,
  16. doublereal *a, integer *lda, integer *jpvt, doublereal *tau,
  17. doublereal *vn1, doublereal *vn2, doublereal *work)
  18. {
  19. /* System generated locals */
  20. integer a_dim1, a_offset, i__1, i__2, i__3;
  21. doublereal d__1, d__2;
  22. /* Builtin functions */
  23. double sqrt(doublereal);
  24. /* Local variables */
  25. integer i__, j, mn;
  26. doublereal aii;
  27. integer pvt;
  28. doublereal temp;
  29. extern doublereal _starpu_dnrm2_(integer *, doublereal *, integer *);
  30. doublereal temp2, tol3z;
  31. extern /* Subroutine */ int _starpu_dlarf_(char *, integer *, integer *,
  32. doublereal *, integer *, doublereal *, doublereal *, integer *,
  33. doublereal *);
  34. integer offpi, itemp;
  35. extern /* Subroutine */ int _starpu_dswap_(integer *, doublereal *, integer *,
  36. doublereal *, integer *);
  37. extern doublereal _starpu_dlamch_(char *);
  38. extern integer _starpu_idamax_(integer *, doublereal *, integer *);
  39. extern /* Subroutine */ int _starpu_dlarfp_(integer *, doublereal *, doublereal *,
  40. integer *, doublereal *);
  41. /* -- LAPACK auxiliary routine (version 3.2) -- */
  42. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  43. /* November 2006 */
  44. /* .. Scalar Arguments .. */
  45. /* .. */
  46. /* .. Array Arguments .. */
  47. /* .. */
  48. /* Purpose */
  49. /* ======= */
  50. /* DLAQP2 computes a QR factorization with column pivoting of */
  51. /* the block A(OFFSET+1:M,1:N). */
  52. /* The block A(1:OFFSET,1:N) is accordingly pivoted, but not factorized. */
  53. /* Arguments */
  54. /* ========= */
  55. /* M (input) INTEGER */
  56. /* The number of rows of the matrix A. M >= 0. */
  57. /* N (input) INTEGER */
  58. /* The number of columns of the matrix A. N >= 0. */
  59. /* OFFSET (input) INTEGER */
  60. /* The number of rows of the matrix A that must be pivoted */
  61. /* but no factorized. OFFSET >= 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 block A(OFFSET+1:M,1:N) is */
  65. /* the triangular factor obtained; the elements in block */
  66. /* A(OFFSET+1:M,1:N) below the diagonal, together with the */
  67. /* array TAU, represent the orthogonal matrix Q as a product of */
  68. /* elementary reflectors. Block A(1:OFFSET,1:N) has been */
  69. /* accordingly pivoted, but no factorized. */
  70. /* LDA (input) INTEGER */
  71. /* The leading dimension of the array A. LDA >= max(1,M). */
  72. /* JPVT (input/output) INTEGER array, dimension (N) */
  73. /* On entry, if JPVT(i) .ne. 0, the i-th column of A is permuted */
  74. /* to the front of A*P (a leading column); if JPVT(i) = 0, */
  75. /* the i-th column of A is a free column. */
  76. /* On exit, if JPVT(i) = k, then the i-th column of A*P */
  77. /* was the k-th column of A. */
  78. /* TAU (output) DOUBLE PRECISION array, dimension (min(M,N)) */
  79. /* The scalar factors of the elementary reflectors. */
  80. /* VN1 (input/output) DOUBLE PRECISION array, dimension (N) */
  81. /* The vector with the partial column norms. */
  82. /* VN2 (input/output) DOUBLE PRECISION array, dimension (N) */
  83. /* The vector with the exact column norms. */
  84. /* WORK (workspace) DOUBLE PRECISION array, dimension (N) */
  85. /* Further Details */
  86. /* =============== */
  87. /* Based on contributions by */
  88. /* G. Quintana-Orti, Depto. de Informatica, Universidad Jaime I, Spain */
  89. /* X. Sun, Computer Science Dept., Duke University, USA */
  90. /* Partial column norm updating strategy modified by */
  91. /* Z. Drmac and Z. Bujanovic, Dept. of Mathematics, */
  92. /* University of Zagreb, Croatia. */
  93. /* June 2006. */
  94. /* For more details see LAPACK Working Note 176. */
  95. /* ===================================================================== */
  96. /* .. Parameters .. */
  97. /* .. */
  98. /* .. Local Scalars .. */
  99. /* .. */
  100. /* .. External Subroutines .. */
  101. /* .. */
  102. /* .. Intrinsic Functions .. */
  103. /* .. */
  104. /* .. External Functions .. */
  105. /* .. */
  106. /* .. Executable Statements .. */
  107. /* Parameter adjustments */
  108. a_dim1 = *lda;
  109. a_offset = 1 + a_dim1;
  110. a -= a_offset;
  111. --jpvt;
  112. --tau;
  113. --vn1;
  114. --vn2;
  115. --work;
  116. /* Function Body */
  117. /* Computing MIN */
  118. i__1 = *m - *offset;
  119. mn = min(i__1,*n);
  120. tol3z = sqrt(_starpu_dlamch_("Epsilon"));
  121. /* Compute factorization. */
  122. i__1 = mn;
  123. for (i__ = 1; i__ <= i__1; ++i__) {
  124. offpi = *offset + i__;
  125. /* Determine ith pivot column and swap if necessary. */
  126. i__2 = *n - i__ + 1;
  127. pvt = i__ - 1 + _starpu_idamax_(&i__2, &vn1[i__], &c__1);
  128. if (pvt != i__) {
  129. _starpu_dswap_(m, &a[pvt * a_dim1 + 1], &c__1, &a[i__ * a_dim1 + 1], &
  130. c__1);
  131. itemp = jpvt[pvt];
  132. jpvt[pvt] = jpvt[i__];
  133. jpvt[i__] = itemp;
  134. vn1[pvt] = vn1[i__];
  135. vn2[pvt] = vn2[i__];
  136. }
  137. /* Generate elementary reflector H(i). */
  138. if (offpi < *m) {
  139. i__2 = *m - offpi + 1;
  140. _starpu_dlarfp_(&i__2, &a[offpi + i__ * a_dim1], &a[offpi + 1 + i__ *
  141. a_dim1], &c__1, &tau[i__]);
  142. } else {
  143. _starpu_dlarfp_(&c__1, &a[*m + i__ * a_dim1], &a[*m + i__ * a_dim1], &
  144. c__1, &tau[i__]);
  145. }
  146. if (i__ <= *n) {
  147. /* Apply H(i)' to A(offset+i:m,i+1:n) from the left. */
  148. aii = a[offpi + i__ * a_dim1];
  149. a[offpi + i__ * a_dim1] = 1.;
  150. i__2 = *m - offpi + 1;
  151. i__3 = *n - i__;
  152. _starpu_dlarf_("Left", &i__2, &i__3, &a[offpi + i__ * a_dim1], &c__1, &
  153. tau[i__], &a[offpi + (i__ + 1) * a_dim1], lda, &work[1]);
  154. a[offpi + i__ * a_dim1] = aii;
  155. }
  156. /* Update partial column norms. */
  157. i__2 = *n;
  158. for (j = i__ + 1; j <= i__2; ++j) {
  159. if (vn1[j] != 0.) {
  160. /* NOTE: The following 4 lines follow from the analysis in */
  161. /* Lapack Working Note 176. */
  162. /* Computing 2nd power */
  163. d__2 = (d__1 = a[offpi + j * a_dim1], abs(d__1)) / vn1[j];
  164. temp = 1. - d__2 * d__2;
  165. temp = max(temp,0.);
  166. /* Computing 2nd power */
  167. d__1 = vn1[j] / vn2[j];
  168. temp2 = temp * (d__1 * d__1);
  169. if (temp2 <= tol3z) {
  170. if (offpi < *m) {
  171. i__3 = *m - offpi;
  172. vn1[j] = _starpu_dnrm2_(&i__3, &a[offpi + 1 + j * a_dim1], &
  173. c__1);
  174. vn2[j] = vn1[j];
  175. } else {
  176. vn1[j] = 0.;
  177. vn2[j] = 0.;
  178. }
  179. } else {
  180. vn1[j] *= sqrt(temp);
  181. }
  182. }
  183. /* L10: */
  184. }
  185. /* L20: */
  186. }
  187. return 0;
  188. /* End of DLAQP2 */
  189. } /* _starpu_dlaqp2_ */