dgerq2.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /* dgerq2.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. /* Subroutine */ int dgerq2_(integer *m, integer *n, doublereal *a, integer *
  14. lda, doublereal *tau, doublereal *work, integer *info)
  15. {
  16. /* System generated locals */
  17. integer a_dim1, a_offset, i__1, i__2;
  18. /* Local variables */
  19. integer i__, k;
  20. doublereal aii;
  21. extern /* Subroutine */ int dlarf_(char *, integer *, integer *,
  22. doublereal *, integer *, doublereal *, doublereal *, integer *,
  23. doublereal *), dlarfp_(integer *, doublereal *,
  24. doublereal *, integer *, doublereal *), xerbla_(char *, integer *);
  25. /* -- LAPACK routine (version 3.2) -- */
  26. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  27. /* November 2006 */
  28. /* .. Scalar Arguments .. */
  29. /* .. */
  30. /* .. Array Arguments .. */
  31. /* .. */
  32. /* Purpose */
  33. /* ======= */
  34. /* DGERQ2 computes an RQ factorization of a real m by n matrix A: */
  35. /* A = R * Q. */
  36. /* Arguments */
  37. /* ========= */
  38. /* M (input) INTEGER */
  39. /* The number of rows of the matrix A. M >= 0. */
  40. /* N (input) INTEGER */
  41. /* The number of columns of the matrix A. N >= 0. */
  42. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  43. /* On entry, the m by n matrix A. */
  44. /* On exit, if m <= n, the upper triangle of the subarray */
  45. /* A(1:m,n-m+1:n) contains the m by m upper triangular matrix R; */
  46. /* if m >= n, the elements on and above the (m-n)-th subdiagonal */
  47. /* contain the m by n upper trapezoidal matrix R; the remaining */
  48. /* elements, with the array TAU, represent the orthogonal matrix */
  49. /* Q as a product of elementary reflectors (see Further */
  50. /* 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 (M) */
  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(n-k+i+1:n) = 0 and v(n-k+i) = 1; v(1:n-k+i-1) is stored on exit in */
  68. /* A(m-k+i,1:n-k+i-1), 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. xerbla_("DGERQ2", &i__1);
  98. return 0;
  99. }
  100. k = min(*m,*n);
  101. for (i__ = k; i__ >= 1; --i__) {
  102. /* Generate elementary reflector H(i) to annihilate */
  103. /* A(m-k+i,1:n-k+i-1) */
  104. i__1 = *n - k + i__;
  105. dlarfp_(&i__1, &a[*m - k + i__ + (*n - k + i__) * a_dim1], &a[*m - k
  106. + i__ + a_dim1], lda, &tau[i__]);
  107. /* Apply H(i) to A(1:m-k+i-1,1:n-k+i) from the right */
  108. aii = a[*m - k + i__ + (*n - k + i__) * a_dim1];
  109. a[*m - k + i__ + (*n - k + i__) * a_dim1] = 1.;
  110. i__1 = *m - k + i__ - 1;
  111. i__2 = *n - k + i__;
  112. dlarf_("Right", &i__1, &i__2, &a[*m - k + i__ + a_dim1], lda, &tau[
  113. i__], &a[a_offset], lda, &work[1]);
  114. a[*m - k + i__ + (*n - k + i__) * a_dim1] = aii;
  115. /* L10: */
  116. }
  117. return 0;
  118. /* End of DGERQ2 */
  119. } /* dgerq2_ */