Debian Codegraph @

Modules/ThirdParty/VNL/src/vxl/v3p/netlib/lapack/single/sgeqpf.f

raw
1 SUBROUTINE SGEQPF( M, N, A, LDA, JPVT, TAU, WORK, INFO )
2 *
3 * -- LAPACK test routine (version 3.0) --
4 * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
5 * Courant Institute, Argonne National Lab, and Rice University
6 * March 31, 1993
7 *
8 * .. Scalar Arguments ..
9 INTEGER INFO, LDA, M, N
10 * ..
11 * .. Array Arguments ..
12 INTEGER JPVT( * )
13 REAL A( LDA, * ), TAU( * ), WORK( * )
14 * ..
15 *
16 * Purpose
17 * =======
18 *
19 * This routine is deprecated and has been replaced by routine SGEQP3.
20 *
21 * SGEQPF computes a QR factorization with column pivoting of a
22 * real M-by-N matrix A: A*P = Q*R.
23 *
24 * Arguments
25 * =========
26 *
27 * M (input) INTEGER
28 * The number of rows of the matrix A. M >= 0.
29 *
30 * N (input) INTEGER
31 * The number of columns of the matrix A. N >= 0
32 *
33 * A (input/output) REAL array, dimension (LDA,N)
34 * On entry, the M-by-N matrix A.
35 * On exit, the upper triangle of the array contains the
36 * min(M,N)-by-N upper triangular matrix R; the elements
37 * below the diagonal, together with the array TAU,
38 * represent the orthogonal matrix Q as a product of
39 * min(m,n) elementary reflectors.
40 *
41 * LDA (input) INTEGER
42 * The leading dimension of the array A. LDA >= max(1,M).
43 *
44 * JPVT (input/output) INTEGER array, dimension (N)
45 * On entry, if JPVT(i) .ne. 0, the i-th column of A is permuted
46 * to the front of A*P (a leading column); if JPVT(i) = 0,
47 * the i-th column of A is a free column.
48 * On exit, if JPVT(i) = k, then the i-th column of A*P
49 * was the k-th column of A.
50 *
51 * TAU (output) REAL array, dimension (min(M,N))
52 * The scalar factors of the elementary reflectors.
53 *
54 * WORK (workspace) REAL array, dimension (3*N)
55 *
56 * INFO (output) INTEGER
57 * = 0: successful exit
58 * < 0: if INFO = -i, the i-th argument had an illegal value
59 *
60 * Further Details
61 * ===============
62 *
63 * The matrix Q is represented as a product of elementary reflectors
64 *
65 * Q = H(1) H(2) . . . H(n)
66 *
67 * Each H(i) has the form
68 *
69 * H = I - tau * v * v'
70 *
71 * where tau is a real scalar, and v is a real vector with
72 * v(1:i-1) = 0 and v(i) = 1; v(i+1:m) is stored on exit in A(i+1:m,i).
73 *
74 * The matrix P is represented in jpvt as follows: If
75 * jpvt(j) = i
76 * then the jth column of P is the ith canonical unit vector.
77 *
78 * =====================================================================
79 *
80 * .. Parameters ..
81 REAL ZERO, ONE
82 PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
83 * ..
84 * .. Local Scalars ..
85 INTEGER I, ITEMP, J, MA, MN, PVT
86 REAL AII, TEMP, TEMP2
87 * ..
88 * .. External Subroutines ..
89 EXTERNAL SGEQR2, SLARF, SLARFG, SORM2R, SSWAP, XERBLA
90 * ..
91 * .. Intrinsic Functions ..
92 INTRINSIC ABS, MAX, MIN, SQRT
93 * ..
94 * .. External Functions ..
95 INTEGER ISAMAX
96 REAL SNRM2
97 EXTERNAL ISAMAX, SNRM2
98 * ..
99 * .. Executable Statements ..
100 *
101 * Test the input arguments
102 *
103 INFO = 0
104 IF( M.LT.0 ) THEN
105 INFO = -1
106 ELSE IF( N.LT.0 ) THEN
107 INFO = -2
108 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
109 INFO = -4
110 END IF
111 IF( INFO.NE.0 ) THEN
112 CALL XERBLA( 'SGEQPF', -INFO )
113 RETURN
114 END IF
115 *
116 MN = MIN( M, N )
117 *
118 * Move initial columns up front
119 *
120 ITEMP = 1
121 DO 10 I = 1, N
122 IF( JPVT( I ).NE.0 ) THEN
123 IF( I.NE.ITEMP ) THEN
124 CALL SSWAP( M, A( 1, I ), 1, A( 1, ITEMP ), 1 )
125 JPVT( I ) = JPVT( ITEMP )
126 JPVT( ITEMP ) = I
127 ELSE
128 JPVT( I ) = I
129 END IF
130 ITEMP = ITEMP + 1
131 ELSE
132 JPVT( I ) = I
133 END IF
134 10 CONTINUE
135 ITEMP = ITEMP - 1
136 *
137 * Compute the QR factorization and update remaining columns
138 *
139 IF( ITEMP.GT.0 ) THEN
140 MA = MIN( ITEMP, M )
141 CALL SGEQR2( M, MA, A, LDA, TAU, WORK, INFO )
142 IF( MA.LT.N ) THEN
143 CALL SORM2R( 'Left', 'Transpose', M, N-MA, MA, A, LDA, TAU,
144 $ A( 1, MA+1 ), LDA, WORK, INFO )
145 END IF
146 END IF
147 *
148 IF( ITEMP.LT.MN ) THEN
149 *
150 * Initialize partial column norms. The first n elements of
151 * work store the exact column norms.
152 *
153 DO 20 I = ITEMP + 1, N
154 WORK( I ) = SNRM2( M-ITEMP, A( ITEMP+1, I ), 1 )
155 WORK( N+I ) = WORK( I )
156 20 CONTINUE
157 *
158 * Compute factorization
159 *
160 DO 40 I = ITEMP + 1, MN
161 *
162 * Determine ith pivot column and swap if necessary
163 *
164 PVT = ( I-1 ) + ISAMAX( N-I+1, WORK( I ), 1 )
165 *
166 IF( PVT.NE.I ) THEN
167 CALL SSWAP( M, A( 1, PVT ), 1, A( 1, I ), 1 )
168 ITEMP = JPVT( PVT )
169 JPVT( PVT ) = JPVT( I )
170 JPVT( I ) = ITEMP
171 WORK( PVT ) = WORK( I )
172 WORK( N+PVT ) = WORK( N+I )
173 END IF
174 *
175 * Generate elementary reflector H(i)
176 *
177 IF( I.LT.M ) THEN
178 CALL SLARFG( M-I+1, A( I, I ), A( I+1, I ), 1, TAU( I ) )
179 ELSE
180 CALL SLARFG( 1, A( M, M ), A( M, M ), 1, TAU( M ) )
181 END IF
182 *
183 IF( I.LT.N ) THEN
184 *
185 * Apply H(i) to A(i:m,i+1:n) from the left
186 *
187 AII = A( I, I )
188 A( I, I ) = ONE
189 CALL SLARF( 'LEFT', M-I+1, N-I, A( I, I ), 1, TAU( I ),
190 $ A( I, I+1 ), LDA, WORK( 2*N+1 ) )
191 A( I, I ) = AII
192 END IF
193 *
194 * Update partial column norms
195 *
196 DO 30 J = I + 1, N
197 IF( WORK( J ).NE.ZERO ) THEN
198 TEMP = ONE - ( ABS( A( I, J ) ) / WORK( J ) )**2
199 TEMP = MAX( TEMP, ZERO )
200 TEMP2 = ONE + 0.05*TEMP*( WORK( J ) / WORK( N+J ) )**2
201 IF( TEMP2.EQ.ONE ) THEN
202 IF( M-I.GT.0 ) THEN
203 WORK( J ) = SNRM2( M-I, A( I+1, J ), 1 )
204 WORK( N+J ) = WORK( J )
205 ELSE
206 WORK( J ) = ZERO
207 WORK( N+J ) = ZERO
208 END IF
209 ELSE
210 WORK( J ) = WORK( J )*SQRT( TEMP )
211 END IF
212 END IF
213 30 CONTINUE
214 *
215 40 CONTINUE
216 END IF
217 RETURN
218 *
219 * End of SGEQPF
220 *
221 END