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