3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download SGEQRF + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgeqrf.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgeqrf.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgeqrf.f">
21 * SUBROUTINE SGEQRF( M, N, A, LDA, TAU, WORK, LWORK, INFO )
23 * .. Scalar Arguments ..
24 * INTEGER INFO, LDA, LWORK, M, N
26 * .. Array Arguments ..
27 * REAL A( LDA, * ), TAU( * ), WORK( * )
36 *> SGEQRF computes a QR factorization of a real M-by-N matrix A:
46 *> The number of rows of the matrix A. M >= 0.
52 *> The number of columns of the matrix A. N >= 0.
57 *> A is REAL array, dimension (LDA,N)
58 *> On entry, the M-by-N matrix A.
59 *> On exit, the elements on and above the diagonal of the array
60 *> contain the min(M,N)-by-N upper trapezoidal matrix R (R is
61 *> upper triangular if m >= n); the elements below the diagonal,
62 *> with the array TAU, represent the orthogonal matrix Q as a
63 *> product of min(m,n) elementary reflectors (see Further
70 *> The leading dimension of the array A. LDA >= max(1,M).
75 *> TAU is REAL array, dimension (min(M,N))
76 *> The scalar factors of the elementary reflectors (see Further
82 *> WORK is REAL array, dimension (MAX(1,LWORK))
83 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
89 *> The dimension of the array WORK. LWORK >= max(1,N).
90 *> For optimum performance LWORK >= N*NB, where NB is
91 *> the optimal blocksize.
93 *> If LWORK = -1, then a workspace query is assumed; the routine
94 *> only calculates the optimal size of the WORK array, returns
95 *> this value as the first entry of the WORK array, and no error
96 *> message related to LWORK is issued by XERBLA.
102 *> = 0: successful exit
103 *> < 0: if INFO = -i, the i-th argument had an illegal value
109 *> \author Univ. of Tennessee
110 *> \author Univ. of California Berkeley
111 *> \author Univ. of Colorado Denver
114 *> \date November 2011
116 *> \ingroup realGEcomputational
118 *> \par Further Details:
119 * =====================
123 *> The matrix Q is represented as a product of elementary reflectors
125 *> Q = H(1) H(2) . . . H(k), where k = min(m,n).
127 *> Each H(i) has the form
129 *> H(i) = I - tau * v * v**T
131 *> where tau is a real scalar, and v is a real vector with
132 *> v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in A(i+1:m,i),
133 *> and tau in TAU(i).
136 * =====================================================================
137 SUBROUTINE SGEQRF( M, N, A, LDA, TAU, WORK, LWORK, INFO )
139 * -- LAPACK computational routine (version 3.4.0) --
140 * -- LAPACK is a software package provided by Univ. of Tennessee, --
141 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
144 * .. Scalar Arguments ..
145 INTEGER INFO, LDA, LWORK, M, N
147 * .. Array Arguments ..
148 REAL A( LDA, * ), TAU( * ), WORK( * )
151 * =====================================================================
153 * .. Local Scalars ..
155 INTEGER I, IB, IINFO, IWS, K, LDWORK, LWKOPT, NB,
158 * .. External Subroutines ..
159 EXTERNAL SGEQR2, SLARFB, SLARFT, XERBLA
161 * .. Intrinsic Functions ..
164 * .. External Functions ..
168 * .. Executable Statements ..
170 * Test the input arguments
173 NB = ILAENV( 1, 'SGEQRF', ' ', M, N, -1, -1 )
176 LQUERY = ( LWORK.EQ.-1 )
179 ELSE IF( N.LT.0 ) THEN
181 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
183 ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
187 CALL XERBLA( 'SGEQRF', -INFO )
189 ELSE IF( LQUERY ) THEN
193 * Quick return if possible
204 IF( NB.GT.1 .AND. NB.LT.K ) THEN
206 * Determine when to cross over from blocked to unblocked code.
208 NX = MAX( 0, ILAENV( 3, 'SGEQRF', ' ', M, N, -1, -1 ) )
211 * Determine if workspace is large enough for blocked code.
215 IF( LWORK.LT.IWS ) THEN
217 * Not enough workspace to use optimal NB: reduce NB and
218 * determine the minimum value of NB.
221 NBMIN = MAX( 2, ILAENV( 2, 'SGEQRF', ' ', M, N, -1,
227 IF( NB.GE.NBMIN .AND. NB.LT.K .AND. NX.LT.K ) THEN
229 * Use blocked code initially
231 DO 10 I = 1, K - NX, NB
232 IB = MIN( K-I+1, NB )
234 * Compute the QR factorization of the current block
237 CALL SGEQR2( M-I+1, IB, A( I, I ), LDA, TAU( I ), WORK,
241 * Form the triangular factor of the block reflector
242 * H = H(i) H(i+1) . . . H(i+ib-1)
244 CALL SLARFT( 'Forward', 'Columnwise', M-I+1, IB,
245 $ A( I, I ), LDA, TAU( I ), WORK, LDWORK )
247 * Apply H**T to A(i:m,i+ib:n) from the left
249 CALL SLARFB( 'Left', 'Transpose', 'Forward',
250 $ 'Columnwise', M-I+1, N-I-IB+1, IB,
251 $ A( I, I ), LDA, WORK, LDWORK, A( I, I+IB ),
252 $ LDA, WORK( IB+1 ), LDWORK )
259 * Use unblocked code to factor the last or only block.
262 $ CALL SGEQR2( M-I+1, N-I+1, A( I, I ), LDA, TAU( I ), WORK,