LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
cgeqrf.f
Go to the documentation of this file.
1*> \brief \b CGEQRF
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download CGEQRF + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cgeqrf.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cgeqrf.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cgeqrf.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE CGEQRF( M, N, A, LDA, TAU, WORK, LWORK, INFO )
20*
21* .. Scalar Arguments ..
22* INTEGER INFO, LDA, LWORK, M, N
23* ..
24* .. Array Arguments ..
25* COMPLEX A( LDA, * ), TAU( * ), WORK( * )
26* ..
27*
28*
29*> \par Purpose:
30* =============
31*>
32*> \verbatim
33*>
34*> CGEQRF computes a QR factorization of a complex M-by-N matrix A:
35*>
36*> A = Q * ( R ),
37*> ( 0 )
38*>
39*> where:
40*>
41*> Q is a M-by-M orthogonal matrix;
42*> R is an upper-triangular N-by-N matrix;
43*> 0 is a (M-N)-by-N zero matrix, if M > N.
44*>
45*> \endverbatim
46*
47* Arguments:
48* ==========
49*
50*> \param[in] M
51*> \verbatim
52*> M is INTEGER
53*> The number of rows of the matrix A. M >= 0.
54*> \endverbatim
55*>
56*> \param[in] N
57*> \verbatim
58*> N is INTEGER
59*> The number of columns of the matrix A. N >= 0.
60*> \endverbatim
61*>
62*> \param[in,out] A
63*> \verbatim
64*> A is COMPLEX array, dimension (LDA,N)
65*> On entry, the M-by-N matrix A.
66*> On exit, the elements on and above the diagonal of the array
67*> contain the min(M,N)-by-N upper trapezoidal matrix R (R is
68*> upper triangular if m >= n); the elements below the diagonal,
69*> with the array TAU, represent the unitary matrix Q as a
70*> product of min(m,n) elementary reflectors (see Further
71*> Details).
72*> \endverbatim
73*>
74*> \param[in] LDA
75*> \verbatim
76*> LDA is INTEGER
77*> The leading dimension of the array A. LDA >= max(1,M).
78*> \endverbatim
79*>
80*> \param[out] TAU
81*> \verbatim
82*> TAU is COMPLEX array, dimension (min(M,N))
83*> The scalar factors of the elementary reflectors (see Further
84*> Details).
85*> \endverbatim
86*>
87*> \param[out] WORK
88*> \verbatim
89*> WORK is COMPLEX array, dimension (MAX(1,LWORK))
90*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
91*> \endverbatim
92*>
93*> \param[in] LWORK
94*> \verbatim
95*> LWORK is INTEGER
96*> The dimension of the array WORK.
97*> LWORK >= 1, if MIN(M,N) = 0, and LWORK >= N, otherwise.
98*> For optimum performance LWORK >= N*NB, where NB is
99*> the optimal blocksize.
100*>
101*> If LWORK = -1, then a workspace query is assumed; the routine
102*> only calculates the optimal size of the WORK array, returns
103*> this value as the first entry of the WORK array, and no error
104*> message related to LWORK is issued by XERBLA.
105*> \endverbatim
106*>
107*> \param[out] INFO
108*> \verbatim
109*> INFO is INTEGER
110*> = 0: successful exit
111*> < 0: if INFO = -i, the i-th argument had an illegal value
112*> \endverbatim
113*
114* Authors:
115* ========
116*
117*> \author Univ. of Tennessee
118*> \author Univ. of California Berkeley
119*> \author Univ. of Colorado Denver
120*> \author NAG Ltd.
121*
122*> \ingroup geqrf
123*
124*> \par Further Details:
125* =====================
126*>
127*> \verbatim
128*>
129*> The matrix Q is represented as a product of elementary reflectors
130*>
131*> Q = H(1) H(2) . . . H(k), where k = min(m,n).
132*>
133*> Each H(i) has the form
134*>
135*> H(i) = I - tau * v * v**H
136*>
137*> where tau is a complex scalar, and v is a complex vector with
138*> v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in A(i+1:m,i),
139*> and tau in TAU(i).
140*> \endverbatim
141*>
142* =====================================================================
143 SUBROUTINE cgeqrf( M, N, A, LDA, TAU, WORK, LWORK, INFO )
144*
145* -- LAPACK computational routine --
146* -- LAPACK is a software package provided by Univ. of Tennessee, --
147* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
148*
149* .. Scalar Arguments ..
150 INTEGER INFO, LDA, LWORK, M, N
151* ..
152* .. Array Arguments ..
153 COMPLEX A( LDA, * ), TAU( * ), WORK( * )
154* ..
155*
156* =====================================================================
157*
158* .. Local Scalars ..
159 LOGICAL LQUERY
160 INTEGER I, IB, IINFO, IWS, K, LDWORK, LWKOPT, NB,
161 $ NBMIN, NX
162* ..
163* .. External Subroutines ..
164 EXTERNAL cgeqr2, clarfb, clarft, xerbla
165* ..
166* .. Intrinsic Functions ..
167 INTRINSIC max, min
168* ..
169* .. External Functions ..
170 INTEGER ILAENV
171 REAL SROUNDUP_LWORK
172 EXTERNAL ilaenv, sroundup_lwork
173* ..
174* .. Executable Statements ..
175*
176* Test the input arguments
177*
178 k = min( m, n )
179 info = 0
180 nb = ilaenv( 1, 'CGEQRF', ' ', m, n, -1, -1 )
181 lquery = ( lwork.EQ.-1 )
182 IF( m.LT.0 ) THEN
183 info = -1
184 ELSE IF( n.LT.0 ) THEN
185 info = -2
186 ELSE IF( lda.LT.max( 1, m ) ) THEN
187 info = -4
188 ELSE IF( .NOT.lquery ) THEN
189 IF( lwork.LE.0 .OR. ( m.GT.0 .AND. lwork.LT.max( 1, n ) ) )
190 $ info = -7
191 END IF
192 IF( info.NE.0 ) THEN
193 CALL xerbla( 'CGEQRF', -info )
194 RETURN
195 ELSE IF( lquery ) THEN
196 IF( k.EQ.0 ) THEN
197 lwkopt = 1
198 ELSE
199 lwkopt = n*nb
200 END IF
201 work( 1 ) = sroundup_lwork(lwkopt)
202 RETURN
203 END IF
204*
205* Quick return if possible
206*
207 IF( k.EQ.0 ) THEN
208 work( 1 ) = 1
209 RETURN
210 END IF
211*
212 nbmin = 2
213 nx = 0
214 iws = n
215 IF( nb.GT.1 .AND. nb.LT.k ) THEN
216*
217* Determine when to cross over from blocked to unblocked code.
218*
219 nx = max( 0, ilaenv( 3, 'CGEQRF', ' ', m, n, -1, -1 ) )
220 IF( nx.LT.k ) THEN
221*
222* Determine if workspace is large enough for blocked code.
223*
224 ldwork = n
225 iws = ldwork*nb
226 IF( lwork.LT.iws ) THEN
227*
228* Not enough workspace to use optimal NB: reduce NB and
229* determine the minimum value of NB.
230*
231 nb = lwork / ldwork
232 nbmin = max( 2, ilaenv( 2, 'CGEQRF', ' ', m, n, -1,
233 $ -1 ) )
234 END IF
235 END IF
236 END IF
237*
238 IF( nb.GE.nbmin .AND. nb.LT.k .AND. nx.LT.k ) THEN
239*
240* Use blocked code initially
241*
242 DO 10 i = 1, k - nx, nb
243 ib = min( k-i+1, nb )
244*
245* Compute the QR factorization of the current block
246* A(i:m,i:i+ib-1)
247*
248 CALL cgeqr2( m-i+1, ib, a( i, i ), lda, tau( i ), work,
249 $ iinfo )
250 IF( i+ib.LE.n ) THEN
251*
252* Form the triangular factor of the block reflector
253* H = H(i) H(i+1) . . . H(i+ib-1)
254*
255 CALL clarft( 'Forward', 'Columnwise', m-i+1, ib,
256 $ a( i, i ), lda, tau( i ), work, ldwork )
257*
258* Apply H**H to A(i:m,i+ib:n) from the left
259*
260 CALL clarfb( 'Left', 'Conjugate transpose', 'Forward',
261 $ 'Columnwise', m-i+1, n-i-ib+1, ib,
262 $ a( i, i ), lda, work, ldwork, a( i, i+ib ),
263 $ lda, work( ib+1 ), ldwork )
264 END IF
265 10 CONTINUE
266 ELSE
267 i = 1
268 END IF
269*
270* Use unblocked code to factor the last or only block.
271*
272 IF( i.LE.k )
273 $ CALL cgeqr2( m-i+1, n-i+1, a( i, i ), lda, tau( i ), work,
274 $ iinfo )
275*
276 work( 1 ) = sroundup_lwork(iws)
277 RETURN
278*
279* End of CGEQRF
280*
281 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine cgeqr2(m, n, a, lda, tau, work, info)
CGEQR2 computes the QR factorization of a general rectangular matrix using an unblocked algorithm.
Definition cgeqr2.f:128
subroutine cgeqrf(m, n, a, lda, tau, work, lwork, info)
CGEQRF
Definition cgeqrf.f:144
subroutine clarfb(side, trans, direct, storev, m, n, k, v, ldv, t, ldt, c, ldc, work, ldwork)
CLARFB applies a block reflector or its conjugate-transpose to a general rectangular matrix.
Definition clarfb.f:195
recursive subroutine clarft(direct, storev, n, k, v, ldv, tau, t, ldt)
CLARFT forms the triangular factor T of a block reflector H = I - vtvH
Definition clarft.f:162