dgeqr2.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* dgeqr2.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_dgeqr2_(integer *m, integer *n, doublereal *a, integer *
  16. lda, doublereal *tau, doublereal *work, integer *info)
  17. {
  18. /* System generated locals */
  19. integer a_dim1, a_offset, i__1, i__2, i__3;
  20. /* Local variables */
  21. integer i__, k;
  22. doublereal aii;
  23. extern /* Subroutine */ int _starpu_dlarf_(char *, integer *, integer *,
  24. doublereal *, integer *, doublereal *, doublereal *, integer *,
  25. doublereal *), _starpu_dlarfp_(integer *, doublereal *,
  26. doublereal *, integer *, doublereal *), _starpu_xerbla_(char *, integer *);
  27. /* -- LAPACK routine (version 3.2) -- */
  28. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  29. /* November 2006 */
  30. /* .. Scalar Arguments .. */
  31. /* .. */
  32. /* .. Array Arguments .. */
  33. /* .. */
  34. /* Purpose */
  35. /* ======= */
  36. /* DGEQR2 computes a QR factorization of a real m by n matrix A: */
  37. /* A = Q * R. */
  38. /* Arguments */
  39. /* ========= */
  40. /* M (input) INTEGER */
  41. /* The number of rows of the matrix A. M >= 0. */
  42. /* N (input) INTEGER */
  43. /* The number of columns of the matrix A. N >= 0. */
  44. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  45. /* On entry, the m by n matrix A. */
  46. /* On exit, the elements on and above the diagonal of the array */
  47. /* contain the min(m,n) by n upper trapezoidal matrix R (R is */
  48. /* upper triangular if m >= n); the elements below the diagonal, */
  49. /* with the array TAU, represent the orthogonal matrix Q as a */
  50. /* product of elementary reflectors (see Further Details). */
  51. /* LDA (input) INTEGER */
  52. /* The leading dimension of the array A. LDA >= max(1,M). */
  53. /* TAU (output) DOUBLE PRECISION array, dimension (min(M,N)) */
  54. /* The scalar factors of the elementary reflectors (see Further */
  55. /* Details). */
  56. /* WORK (workspace) DOUBLE PRECISION array, dimension (N) */
  57. /* INFO (output) INTEGER */
  58. /* = 0: successful exit */
  59. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  60. /* Further Details */
  61. /* =============== */
  62. /* The matrix Q is represented as a product of elementary reflectors */
  63. /* Q = H(1) H(2) . . . H(k), where k = min(m,n). */
  64. /* Each H(i) has the form */
  65. /* H(i) = I - tau * v * v' */
  66. /* where tau is a real scalar, and v is a real vector with */
  67. /* v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in A(i+1:m,i), */
  68. /* and tau in TAU(i). */
  69. /* ===================================================================== */
  70. /* .. Parameters .. */
  71. /* .. */
  72. /* .. Local Scalars .. */
  73. /* .. */
  74. /* .. External Subroutines .. */
  75. /* .. */
  76. /* .. Intrinsic Functions .. */
  77. /* .. */
  78. /* .. Executable Statements .. */
  79. /* Test the input arguments */
  80. /* Parameter adjustments */
  81. a_dim1 = *lda;
  82. a_offset = 1 + a_dim1;
  83. a -= a_offset;
  84. --tau;
  85. --work;
  86. /* Function Body */
  87. *info = 0;
  88. if (*m < 0) {
  89. *info = -1;
  90. } else if (*n < 0) {
  91. *info = -2;
  92. } else if (*lda < max(1,*m)) {
  93. *info = -4;
  94. }
  95. if (*info != 0) {
  96. i__1 = -(*info);
  97. _starpu_xerbla_("DGEQR2", &i__1);
  98. return 0;
  99. }
  100. k = min(*m,*n);
  101. i__1 = k;
  102. for (i__ = 1; i__ <= i__1; ++i__) {
  103. /* Generate elementary reflector H(i) to annihilate A(i+1:m,i) */
  104. i__2 = *m - i__ + 1;
  105. /* Computing MIN */
  106. i__3 = i__ + 1;
  107. _starpu_dlarfp_(&i__2, &a[i__ + i__ * a_dim1], &a[min(i__3, *m)+ i__ * a_dim1]
  108. , &c__1, &tau[i__]);
  109. if (i__ < *n) {
  110. /* Apply H(i) to A(i:m,i+1:n) from the left */
  111. aii = a[i__ + i__ * a_dim1];
  112. a[i__ + i__ * a_dim1] = 1.;
  113. i__2 = *m - i__ + 1;
  114. i__3 = *n - i__;
  115. _starpu_dlarf_("Left", &i__2, &i__3, &a[i__ + i__ * a_dim1], &c__1, &tau[
  116. i__], &a[i__ + (i__ + 1) * a_dim1], lda, &work[1]);
  117. a[i__ + i__ * a_dim1] = aii;
  118. }
  119. /* L10: */
  120. }
  121. return 0;
  122. /* End of DGEQR2 */
  123. } /* _starpu_dgeqr2_ */