3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download SGEQP3 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgeqp3.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgeqp3.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgeqp3.f">
21 * SUBROUTINE SGEQP3( M, N, A, LDA, JPVT, TAU, WORK, LWORK, INFO )
23 * .. Scalar Arguments ..
24 * INTEGER INFO, LDA, LWORK, M, N
26 * .. Array Arguments ..
28 * REAL A( LDA, * ), TAU( * ), WORK( * )
37 *> SGEQP3 computes a QR factorization with column pivoting of a
38 *> matrix A: A*P = Q*R using Level 3 BLAS.
47 *> The number of rows of the matrix A. M >= 0.
53 *> The number of columns of the matrix A. N >= 0.
58 *> A is REAL array, dimension (LDA,N)
59 *> On entry, the M-by-N matrix A.
60 *> On exit, the upper triangle of the array contains the
61 *> min(M,N)-by-N upper trapezoidal matrix R; the elements below
62 *> the diagonal, together with the array TAU, represent the
63 *> orthogonal matrix Q as a product of min(M,N) elementary
70 *> The leading dimension of the array A. LDA >= max(1,M).
73 *> \param[in,out] JPVT
75 *> JPVT is INTEGER array, dimension (N)
76 *> On entry, if JPVT(J).ne.0, the J-th column of A is permuted
77 *> to the front of A*P (a leading column); if JPVT(J)=0,
78 *> the J-th column of A is a free column.
79 *> On exit, if JPVT(J)=K, then the J-th column of A*P was the
80 *> the K-th column of A.
85 *> TAU is REAL array, dimension (min(M,N))
86 *> The scalar factors of the elementary reflectors.
91 *> WORK is REAL array, dimension (MAX(1,LWORK))
92 *> On exit, if INFO=0, WORK(1) returns the optimal LWORK.
98 *> The dimension of the array WORK. LWORK >= 3*N+1.
99 *> For optimal performance LWORK >= 2*N+( N+1 )*NB, where NB
100 *> is the optimal blocksize.
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.
111 *> = 0: successful exit.
112 *> < 0: if INFO = -i, the i-th argument had an illegal value.
118 *> \author Univ. of Tennessee
119 *> \author Univ. of California Berkeley
120 *> \author Univ. of Colorado Denver
123 *> \date November 2015
125 *> \ingroup realGEcomputational
127 *> \par Further Details:
128 * =====================
132 *> The matrix Q is represented as a product of elementary reflectors
134 *> Q = H(1) H(2) . . . H(k), where k = min(m,n).
136 *> Each H(i) has the form
138 *> H(i) = I - tau * v * v**T
140 *> where tau is a real scalar, and v is a real/complex vector
141 *> with v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in
142 *> A(i+1:m,i), and tau in TAU(i).
145 *> \par Contributors:
148 *> G. Quintana-Orti, Depto. de Informatica, Universidad Jaime I, Spain
149 *> X. Sun, Computer Science Dept., Duke University, USA
151 * =====================================================================
152 SUBROUTINE SGEQP3( M, N, A, LDA, JPVT, TAU, WORK, LWORK, INFO )
154 * -- LAPACK computational routine (version 3.6.0) --
155 * -- LAPACK is a software package provided by Univ. of Tennessee, --
156 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
159 * .. Scalar Arguments ..
160 INTEGER INFO, LDA, LWORK, M, N
162 * .. Array Arguments ..
164 REAL A( LDA, * ), TAU( * ), WORK( * )
167 * =====================================================================
170 INTEGER INB, INBMIN, IXOVER
171 PARAMETER ( INB = 1, INBMIN = 2, IXOVER = 3 )
173 * .. Local Scalars ..
175 INTEGER FJB, IWS, J, JB, LWKOPT, MINMN, MINWS, NA, NB,
176 $ NBMIN, NFXD, NX, SM, SMINMN, SN, TOPBMN
178 * .. External Subroutines ..
179 EXTERNAL SGEQRF, SLAQP2, SLAQPS, SORMQR, SSWAP, XERBLA
181 * .. External Functions ..
184 EXTERNAL ILAENV, SNRM2
186 * .. Intrinsic Functions ..
187 INTRINSIC INT, MAX, MIN
188 * Test input arguments
189 * ====================
192 LQUERY = ( LWORK.EQ.-1 )
195 ELSE IF( N.LT.0 ) THEN
197 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
203 IF( MINMN.EQ.0 ) THEN
208 NB = ILAENV( INB, 'SGEQRF', ' ', M, N, -1, -1 )
209 LWKOPT = 2*N + ( N + 1 )*NB
213 IF( ( LWORK.LT.IWS ) .AND. .NOT.LQUERY ) THEN
219 CALL XERBLA( 'SGEQP3', -INFO )
221 ELSE IF( LQUERY ) THEN
225 * Move initial columns up front.
229 IF( JPVT( J ).NE.0 ) THEN
231 CALL SSWAP( M, A( 1, J ), 1, A( 1, NFXD ), 1 )
232 JPVT( J ) = JPVT( NFXD )
244 * Factorize fixed columns
245 * =======================
247 * Compute the QR factorization of fixed columns and update
252 *CC CALL SGEQR2( M, NA, A, LDA, TAU, WORK, INFO )
253 CALL SGEQRF( M, NA, A, LDA, TAU, WORK, LWORK, INFO )
254 IWS = MAX( IWS, INT( WORK( 1 ) ) )
256 *CC CALL SORM2R( 'Left', 'Transpose', M, N-NA, NA, A, LDA,
257 *CC $ TAU, A( 1, NA+1 ), LDA, WORK, INFO )
258 CALL SORMQR( 'Left', 'Transpose', M, N-NA, NA, A, LDA, TAU,
259 $ A( 1, NA+1 ), LDA, WORK, LWORK, INFO )
260 IWS = MAX( IWS, INT( WORK( 1 ) ) )
264 * Factorize free columns
265 * ======================
267 IF( NFXD.LT.MINMN ) THEN
271 SMINMN = MINMN - NFXD
273 * Determine the block size.
275 NB = ILAENV( INB, 'SGEQRF', ' ', SM, SN, -1, -1 )
279 IF( ( NB.GT.1 ) .AND. ( NB.LT.SMINMN ) ) THEN
281 * Determine when to cross over from blocked to unblocked code.
283 NX = MAX( 0, ILAENV( IXOVER, 'SGEQRF', ' ', SM, SN, -1,
287 IF( NX.LT.SMINMN ) THEN
289 * Determine if workspace is large enough for blocked code.
291 MINWS = 2*SN + ( SN+1 )*NB
292 IWS = MAX( IWS, MINWS )
293 IF( LWORK.LT.MINWS ) THEN
295 * Not enough workspace to use optimal NB: Reduce NB and
296 * determine the minimum value of NB.
298 NB = ( LWORK-2*SN ) / ( SN+1 )
299 NBMIN = MAX( 2, ILAENV( INBMIN, 'SGEQRF', ' ', SM, SN,
307 * Initialize partial column norms. The first N elements of work
308 * store the exact column norms.
310 DO 20 J = NFXD + 1, N
311 WORK( J ) = SNRM2( SM, A( NFXD+1, J ), 1 )
312 WORK( N+J ) = WORK( J )
315 IF( ( NB.GE.NBMIN ) .AND. ( NB.LT.SMINMN ) .AND.
316 $ ( NX.LT.SMINMN ) ) THEN
318 * Use blocked code initially.
322 * Compute factorization: while loop.
327 IF( J.LE.TOPBMN ) THEN
328 JB = MIN( NB, TOPBMN-J+1 )
330 * Factorize JB columns among columns J:N.
332 CALL SLAQPS( M, N-J+1, J-1, JB, FJB, A( 1, J ), LDA,
333 $ JPVT( J ), TAU( J ), WORK( J ), WORK( N+J ),
334 $ WORK( 2*N+1 ), WORK( 2*N+JB+1 ), N-J+1 )
343 * Use unblocked code to factor the last or only block.
347 $ CALL SLAQP2( M, N-J+1, J-1, A( 1, J ), LDA, JPVT( J ),
348 $ TAU( J ), WORK( J ), WORK( N+J ),