3 /* Table of constant values */
5 static integer c__1 = 1;
6 static integer c_n1 = -1;
7 static integer c__3 = 3;
8 static integer c__2 = 2;
10 /* Subroutine */ int dorgqr_(integer *m, integer *n, integer *k, doublereal *
11 a, integer *lda, doublereal *tau, doublereal *work, integer *lwork,
14 /* System generated locals */
15 integer a_dim1, a_offset, i__1, i__2, i__3;
18 integer i__, j, l, ib, nb, ki, kk, nx, iws, nbmin, iinfo;
19 extern /* Subroutine */ int dorg2r_(integer *, integer *, integer *,
20 doublereal *, integer *, doublereal *, doublereal *, integer *),
21 dlarfb_(char *, char *, char *, char *, integer *, integer *,
22 integer *, doublereal *, integer *, doublereal *, integer *,
23 doublereal *, integer *, doublereal *, integer *), dlarft_(char *, char *, integer *, integer *,
24 doublereal *, integer *, doublereal *, doublereal *, integer *), xerbla_(char *, integer *);
25 extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
26 integer *, integer *);
27 integer ldwork, lwkopt;
31 /* -- LAPACK routine (version 3.1) -- */
32 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
35 /* .. Scalar Arguments .. */
37 /* .. Array Arguments .. */
43 /* DORGQR generates an M-by-N real matrix Q with orthonormal columns, */
44 /* which is defined as the first N columns of a product of K elementary */
45 /* reflectors of order M */
47 /* Q = H(1) H(2) . . . H(k) */
49 /* as returned by DGEQRF. */
54 /* M (input) INTEGER */
55 /* The number of rows of the matrix Q. M >= 0. */
57 /* N (input) INTEGER */
58 /* The number of columns of the matrix Q. M >= N >= 0. */
60 /* K (input) INTEGER */
61 /* The number of elementary reflectors whose product defines the */
62 /* matrix Q. N >= K >= 0. */
64 /* A (input/output) DOUBLE PRECISION array, dimension (LDA,N) */
65 /* On entry, the i-th column must contain the vector which */
66 /* defines the elementary reflector H(i), for i = 1,2,...,k, as */
67 /* returned by DGEQRF in the first k columns of its array */
69 /* On exit, the M-by-N matrix Q. */
71 /* LDA (input) INTEGER */
72 /* The first dimension of the array A. LDA >= max(1,M). */
74 /* TAU (input) DOUBLE PRECISION array, dimension (K) */
75 /* TAU(i) must contain the scalar factor of the elementary */
76 /* reflector H(i), as returned by DGEQRF. */
78 /* WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
79 /* On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
81 /* LWORK (input) INTEGER */
82 /* The dimension of the array WORK. LWORK >= max(1,N). */
83 /* For optimum performance LWORK >= N*NB, where NB is the */
84 /* optimal blocksize. */
86 /* If LWORK = -1, then a workspace query is assumed; the routine */
87 /* only calculates the optimal size of the WORK array, returns */
88 /* this value as the first entry of the WORK array, and no error */
89 /* message related to LWORK is issued by XERBLA. */
91 /* INFO (output) INTEGER */
92 /* = 0: successful exit */
93 /* < 0: if INFO = -i, the i-th argument has an illegal value */
95 /* ===================================================================== */
97 /* .. Parameters .. */
99 /* .. Local Scalars .. */
101 /* .. External Subroutines .. */
103 /* .. Intrinsic Functions .. */
105 /* .. External Functions .. */
107 /* .. Executable Statements .. */
109 /* Test the input arguments */
111 /* Parameter adjustments */
113 a_offset = 1 + a_dim1;
120 nb = ilaenv_(&c__1, "DORGQR", " ", m, n, k, &c_n1);
121 lwkopt = max(1,*n) * nb;
122 work[1] = (doublereal) lwkopt;
123 lquery = *lwork == -1;
126 } else if (*n < 0 || *n > *m) {
128 } else if (*k < 0 || *k > *n) {
130 } else if (*lda < max(1,*m)) {
132 } else if (*lwork < max(1,*n) && ! lquery) {
137 xerbla_("DORGQR", &i__1);
143 /* Quick return if possible */
153 if (nb > 1 && nb < *k) {
155 /* Determine when to cross over from blocked to unblocked code. */
158 i__1 = 0, i__2 = ilaenv_(&c__3, "DORGQR", " ", m, n, k, &c_n1);
162 /* Determine if workspace is large enough for blocked code. */
168 /* Not enough workspace to use optimal NB: reduce NB and */
169 /* determine the minimum value of NB. */
171 nb = *lwork / ldwork;
173 i__1 = 2, i__2 = ilaenv_(&c__2, "DORGQR", " ", m, n, k, &c_n1);
174 nbmin = max(i__1,i__2);
179 if (nb >= nbmin && nb < *k && nx < *k) {
181 /* Use blocked code after the last block. */
182 /* The first kk columns are handled by the block method. */
184 ki = (*k - nx - 1) / nb * nb;
186 i__1 = *k, i__2 = ki + nb;
189 /* Set A(1:kk,kk+1:n) to zero. */
192 for (j = kk + 1; j <= i__1; ++j) {
194 for (i__ = 1; i__ <= i__2; ++i__) {
195 a[i__ + j * a_dim1] = 0.;
204 /* Use unblocked code for the last or only block. */
210 dorg2r_(&i__1, &i__2, &i__3, &a[kk + 1 + (kk + 1) * a_dim1], lda, &
211 tau[kk + 1], &work[1], &iinfo);
216 /* Use blocked code */
219 for (i__ = ki + 1; i__1 < 0 ? i__ >= 1 : i__ <= 1; i__ += i__1) {
221 i__2 = nb, i__3 = *k - i__ + 1;
223 if (i__ + ib <= *n) {
225 /* Form the triangular factor of the block reflector */
226 /* H = H(i) H(i+1) . . . H(i+ib-1) */
229 dlarft_("Forward", "Columnwise", &i__2, &ib, &a[i__ + i__ *
230 a_dim1], lda, &tau[i__], &work[1], &ldwork);
232 /* Apply H to A(i:m,i+ib:n) from the left */
235 i__3 = *n - i__ - ib + 1;
236 dlarfb_("Left", "No transpose", "Forward", "Columnwise", &
237 i__2, &i__3, &ib, &a[i__ + i__ * a_dim1], lda, &work[
238 1], &ldwork, &a[i__ + (i__ + ib) * a_dim1], lda, &
239 work[ib + 1], &ldwork);
242 /* Apply H to rows i:m of current block */
245 dorg2r_(&i__2, &ib, &ib, &a[i__ + i__ * a_dim1], lda, &tau[i__], &
248 /* Set rows 1:i-1 of current block to zero */
251 for (j = i__; j <= i__2; ++j) {
253 for (l = 1; l <= i__3; ++l) {
254 a[l + j * a_dim1] = 0.;
263 work[1] = (doublereal) iws;