3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DORGQR + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dorgqr.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dorgqr.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dorgqr.f">
21 * SUBROUTINE DORGQR( M, N, K, A, LDA, TAU, WORK, LWORK, INFO )
23 * .. Scalar Arguments ..
24 * INTEGER INFO, K, LDA, LWORK, M, N
26 * .. Array Arguments ..
27 * DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * )
36 *> DORGQR generates an M-by-N real matrix Q with orthonormal columns,
37 *> which is defined as the first N columns of a product of K elementary
38 *> reflectors of order M
40 *> Q = H(1) H(2) . . . H(k)
42 *> as returned by DGEQRF.
51 *> The number of rows of the matrix Q. M >= 0.
57 *> The number of columns of the matrix Q. M >= N >= 0.
63 *> The number of elementary reflectors whose product defines the
64 *> matrix Q. N >= K >= 0.
69 *> A is DOUBLE PRECISION array, dimension (LDA,N)
70 *> On entry, the i-th column must contain the vector which
71 *> defines the elementary reflector H(i), for i = 1,2,...,k, as
72 *> returned by DGEQRF in the first k columns of its array
74 *> On exit, the M-by-N matrix Q.
80 *> The first dimension of the array A. LDA >= max(1,M).
85 *> TAU is DOUBLE PRECISION array, dimension (K)
86 *> TAU(i) must contain the scalar factor of the elementary
87 *> reflector H(i), as returned by DGEQRF.
92 *> WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK))
93 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
99 *> The dimension of the array WORK. LWORK >= max(1,N).
100 *> For optimum performance LWORK >= N*NB, where NB is the
101 *> optimal blocksize.
103 *> If LWORK = -1, then a workspace query is assumed; the routine
104 *> only calculates the optimal size of the WORK array, returns
105 *> this value as the first entry of the WORK array, and no error
106 *> message related to LWORK is issued by XERBLA.
112 *> = 0: successful exit
113 *> < 0: if INFO = -i, the i-th argument has an illegal value
119 *> \author Univ. of Tennessee
120 *> \author Univ. of California Berkeley
121 *> \author Univ. of Colorado Denver
124 *> \date November 2011
126 *> \ingroup doubleOTHERcomputational
128 * =====================================================================
129 SUBROUTINE DORGQR( M, N, K, A, LDA, TAU, WORK, LWORK, INFO )
131 * -- LAPACK computational routine (version 3.4.0) --
132 * -- LAPACK is a software package provided by Univ. of Tennessee, --
133 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
136 * .. Scalar Arguments ..
137 INTEGER INFO, K, LDA, LWORK, M, N
139 * .. Array Arguments ..
140 DOUBLE PRECISION A( LDA, * ), TAU( * ), WORK( * )
143 * =====================================================================
146 DOUBLE PRECISION ZERO
147 PARAMETER ( ZERO = 0.0D+0 )
149 * .. Local Scalars ..
151 INTEGER I, IB, IINFO, IWS, J, KI, KK, L, LDWORK,
152 $ LWKOPT, NB, NBMIN, NX
154 * .. External Subroutines ..
155 EXTERNAL DLARFB, DLARFT, DORG2R, XERBLA
157 * .. Intrinsic Functions ..
160 * .. External Functions ..
164 * .. Executable Statements ..
166 * Test the input arguments
169 NB = ILAENV( 1, 'DORGQR', ' ', M, N, K, -1 )
170 LWKOPT = MAX( 1, N )*NB
172 LQUERY = ( LWORK.EQ.-1 )
175 ELSE IF( N.LT.0 .OR. N.GT.M ) THEN
177 ELSE IF( K.LT.0 .OR. K.GT.N ) THEN
179 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
181 ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
185 CALL XERBLA( 'DORGQR', -INFO )
187 ELSE IF( LQUERY ) THEN
191 * Quick return if possible
201 IF( NB.GT.1 .AND. NB.LT.K ) THEN
203 * Determine when to cross over from blocked to unblocked code.
205 NX = MAX( 0, ILAENV( 3, 'DORGQR', ' ', M, N, K, -1 ) )
208 * Determine if workspace is large enough for blocked code.
212 IF( LWORK.LT.IWS ) THEN
214 * Not enough workspace to use optimal NB: reduce NB and
215 * determine the minimum value of NB.
218 NBMIN = MAX( 2, ILAENV( 2, 'DORGQR', ' ', M, N, K, -1 ) )
223 IF( NB.GE.NBMIN .AND. NB.LT.K .AND. NX.LT.K ) THEN
225 * Use blocked code after the last block.
226 * The first kk columns are handled by the block method.
228 KI = ( ( K-NX-1 ) / NB )*NB
231 * Set A(1:kk,kk+1:n) to zero.
242 * Use unblocked code for the last or only block.
245 $ CALL DORG2R( M-KK, N-KK, K-KK, A( KK+1, KK+1 ), LDA,
246 $ TAU( KK+1 ), WORK, IINFO )
252 DO 50 I = KI + 1, 1, -NB
253 IB = MIN( NB, K-I+1 )
256 * Form the triangular factor of the block reflector
257 * H = H(i) H(i+1) . . . H(i+ib-1)
259 CALL DLARFT( 'Forward', 'Columnwise', M-I+1, IB,
260 $ A( I, I ), LDA, TAU( I ), WORK, LDWORK )
262 * Apply H to A(i:m,i+ib:n) from the left
264 CALL DLARFB( 'Left', 'No transpose', 'Forward',
265 $ 'Columnwise', M-I+1, N-I-IB+1, IB,
266 $ A( I, I ), LDA, WORK, LDWORK, A( I, I+IB ),
267 $ LDA, WORK( IB+1 ), LDWORK )
270 * Apply H to rows i:m of current block
272 CALL DORG2R( M-I+1, IB, IB, A( I, I ), LDA, TAU( I ), WORK,
275 * Set rows 1:i-1 of current block to zero
277 DO 40 J = I, I + IB - 1