dorgr2.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* dorgr2.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 _starpu_dorgr2_(integer *m, integer *n, integer *k, doublereal *
  14. a, integer *lda, doublereal *tau, doublereal *work, integer *info)
  15. {
  16. /* System generated locals */
  17. integer a_dim1, a_offset, i__1, i__2, i__3;
  18. doublereal d__1;
  19. /* Local variables */
  20. integer i__, j, l, ii;
  21. extern /* Subroutine */ int _starpu_dscal_(integer *, doublereal *, doublereal *,
  22. integer *), _starpu_dlarf_(char *, integer *, integer *, doublereal *,
  23. integer *, doublereal *, doublereal *, integer *, doublereal *), _starpu_xerbla_(char *, integer *);
  24. /* -- LAPACK routine (version 3.2) -- */
  25. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  26. /* November 2006 */
  27. /* .. Scalar Arguments .. */
  28. /* .. */
  29. /* .. Array Arguments .. */
  30. /* .. */
  31. /* Purpose */
  32. /* ======= */
  33. /* DORGR2 generates an m by n real matrix Q with orthonormal rows, */
  34. /* which is defined as the last m rows of a product of k elementary */
  35. /* reflectors of order n */
  36. /* Q = H(1) H(2) . . . H(k) */
  37. /* as returned by DGERQF. */
  38. /* Arguments */
  39. /* ========= */
  40. /* M (input) INTEGER */
  41. /* The number of rows of the matrix Q. M >= 0. */
  42. /* N (input) INTEGER */
  43. /* The number of columns of the matrix Q. N >= M. */
  44. /* K (input) INTEGER */
  45. /* The number of elementary reflectors whose product defines the */
  46. /* matrix Q. M >= K >= 0. */
  47. /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
  48. /* On entry, the (m-k+i)-th row must contain the vector which */
  49. /* defines the elementary reflector H(i), for i = 1,2,...,k, as */
  50. /* returned by DGERQF in the last k rows of its array argument */
  51. /* A. */
  52. /* On exit, the m by n matrix Q. */
  53. /* LDA (input) INTEGER */
  54. /* The first dimension of the array A. LDA >= max(1,M). */
  55. /* TAU (input) DOUBLE PRECISION array, dimension (K) */
  56. /* TAU(i) must contain the scalar factor of the elementary */
  57. /* reflector H(i), as returned by DGERQF. */
  58. /* WORK (workspace) DOUBLE PRECISION array, dimension (M) */
  59. /* INFO (output) INTEGER */
  60. /* = 0: successful exit */
  61. /* < 0: if INFO = -i, the i-th argument has an illegal value */
  62. /* ===================================================================== */
  63. /* .. Parameters .. */
  64. /* .. */
  65. /* .. Local Scalars .. */
  66. /* .. */
  67. /* .. External Subroutines .. */
  68. /* .. */
  69. /* .. Intrinsic Functions .. */
  70. /* .. */
  71. /* .. Executable Statements .. */
  72. /* Test the input arguments */
  73. /* Parameter adjustments */
  74. a_dim1 = *lda;
  75. a_offset = 1 + a_dim1;
  76. a -= a_offset;
  77. --tau;
  78. --work;
  79. /* Function Body */
  80. *info = 0;
  81. if (*m < 0) {
  82. *info = -1;
  83. } else if (*n < *m) {
  84. *info = -2;
  85. } else if (*k < 0 || *k > *m) {
  86. *info = -3;
  87. } else if (*lda < max(1,*m)) {
  88. *info = -5;
  89. }
  90. if (*info != 0) {
  91. i__1 = -(*info);
  92. _starpu_xerbla_("DORGR2", &i__1);
  93. return 0;
  94. }
  95. /* Quick return if possible */
  96. if (*m <= 0) {
  97. return 0;
  98. }
  99. if (*k < *m) {
  100. /* Initialise rows 1:m-k to rows of the unit matrix */
  101. i__1 = *n;
  102. for (j = 1; j <= i__1; ++j) {
  103. i__2 = *m - *k;
  104. for (l = 1; l <= i__2; ++l) {
  105. a[l + j * a_dim1] = 0.;
  106. /* L10: */
  107. }
  108. if (j > *n - *m && j <= *n - *k) {
  109. a[*m - *n + j + j * a_dim1] = 1.;
  110. }
  111. /* L20: */
  112. }
  113. }
  114. i__1 = *k;
  115. for (i__ = 1; i__ <= i__1; ++i__) {
  116. ii = *m - *k + i__;
  117. /* Apply H(i) to A(1:m-k+i,1:n-k+i) from the right */
  118. a[ii + (*n - *m + ii) * a_dim1] = 1.;
  119. i__2 = ii - 1;
  120. i__3 = *n - *m + ii;
  121. _starpu_dlarf_("Right", &i__2, &i__3, &a[ii + a_dim1], lda, &tau[i__], &a[
  122. a_offset], lda, &work[1]);
  123. i__2 = *n - *m + ii - 1;
  124. d__1 = -tau[i__];
  125. _starpu_dscal_(&i__2, &d__1, &a[ii + a_dim1], lda);
  126. a[ii + (*n - *m + ii) * a_dim1] = 1. - tau[i__];
  127. /* Set A(m-k+i,n-k+i+1:n) to zero */
  128. i__2 = *n;
  129. for (l = *n - *m + ii + 1; l <= i__2; ++l) {
  130. a[ii + l * a_dim1] = 0.;
  131. /* L30: */
  132. }
  133. /* L40: */
  134. }
  135. return 0;
  136. /* End of DORGR2 */
  137. } /* _starpu_dorgr2_ */