LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
sgetsqrhrt.f
Go to the documentation of this file.
1*> \brief \b SGETSQRHRT
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download SGETSQRHRT + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgetsqrhrt.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgetsqrhrt.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgetsqrhrt.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE SGETSQRHRT( M, N, MB1, NB1, NB2, A, LDA, T, LDT, WORK,
20* $ LWORK, INFO )
21* IMPLICIT NONE
22*
23* .. Scalar Arguments ..
24* INTEGER INFO, LDA, LDT, LWORK, M, N, NB1, NB2, MB1
25* ..
26* .. Array Arguments ..
27* REAL A( LDA, * ), T( LDT, * ), WORK( * )
28* ..
29*
30*
31*> \par Purpose:
32* =============
33*>
34*> \verbatim
35*>
36*> SGETSQRHRT computes a NB2-sized column blocked QR-factorization
37*> of a complex M-by-N matrix A with M >= N,
38*>
39*> A = Q * R.
40*>
41*> The routine uses internally a NB1-sized column blocked and MB1-sized
42*> row blocked TSQR-factorization and perfors the reconstruction
43*> of the Householder vectors from the TSQR output. The routine also
44*> converts the R_tsqr factor from the TSQR-factorization output into
45*> the R factor that corresponds to the Householder QR-factorization,
46*>
47*> A = Q_tsqr * R_tsqr = Q * R.
48*>
49*> The output Q and R factors are stored in the same format as in SGEQRT
50*> (Q is in blocked compact WY-representation). See the documentation
51*> of SGEQRT for more details on the format.
52*> \endverbatim
53*
54* Arguments:
55* ==========
56*
57*> \param[in] M
58*> \verbatim
59*> M is INTEGER
60*> The number of rows of the matrix A. M >= 0.
61*> \endverbatim
62*>
63*> \param[in] N
64*> \verbatim
65*> N is INTEGER
66*> The number of columns of the matrix A. M >= N >= 0.
67*> \endverbatim
68*>
69*> \param[in] MB1
70*> \verbatim
71*> MB1 is INTEGER
72*> The row block size to be used in the blocked TSQR.
73*> MB1 > N.
74*> \endverbatim
75*>
76*> \param[in] NB1
77*> \verbatim
78*> NB1 is INTEGER
79*> The column block size to be used in the blocked TSQR.
80*> N >= NB1 >= 1.
81*> \endverbatim
82*>
83*> \param[in] NB2
84*> \verbatim
85*> NB2 is INTEGER
86*> The block size to be used in the blocked QR that is
87*> output. NB2 >= 1.
88*> \endverbatim
89*>
90*> \param[in,out] A
91*> \verbatim
92*> A is REAL array, dimension (LDA,N)
93*>
94*> On entry: an M-by-N matrix A.
95*>
96*> On exit:
97*> a) the elements on and above the diagonal
98*> of the array contain the N-by-N upper-triangular
99*> matrix R corresponding to the Householder QR;
100*> b) the elements below the diagonal represent Q by
101*> the columns of blocked V (compact WY-representation).
102*> \endverbatim
103*>
104*> \param[in] LDA
105*> \verbatim
106*> LDA is INTEGER
107*> The leading dimension of the array A. LDA >= max(1,M).
108*> \endverbatim
109*>
110*> \param[out] T
111*> \verbatim
112*> T is REAL array, dimension (LDT,N))
113*> The upper triangular block reflectors stored in compact form
114*> as a sequence of upper triangular blocks.
115*> \endverbatim
116*>
117*> \param[in] LDT
118*> \verbatim
119*> LDT is INTEGER
120*> The leading dimension of the array T. LDT >= NB2.
121*> \endverbatim
122*>
123*> \param[out] WORK
124*> \verbatim
125*> (workspace) REAL array, dimension (MAX(1,LWORK))
126*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
127*> \endverbatim
128*>
129*> \param[in] LWORK
130*> \verbatim
131*> LWORK is INTEGER
132*> The dimension of the array WORK.
133*> If MIN(M,N) = 0, LWORK >= 1, else
134*> LWORK >= MAX( 1, LWT + LW1, MAX( LWT+N*N+LW2, LWT+N*N+N ) ),
135*> where
136*> NUM_ALL_ROW_BLOCKS = CEIL((M-N)/(MB1-N)),
137*> NB1LOCAL = MIN(NB1,N).
138*> LWT = NUM_ALL_ROW_BLOCKS * N * NB1LOCAL,
139*> LW1 = NB1LOCAL * N,
140*> LW2 = NB1LOCAL * MAX( NB1LOCAL, ( N - NB1LOCAL ) ).
141*>
142*> If LWORK = -1, then a workspace query is assumed.
143*> The routine only calculates the optimal size of the WORK
144*> array, returns this value as the first entry of the WORK
145*> array, and no error message related to LWORK is issued
146*> by XERBLA.
147*> \endverbatim
148*>
149*> \param[out] INFO
150*> \verbatim
151*> INFO is INTEGER
152*> = 0: successful exit
153*> < 0: if INFO = -i, the i-th argument had an illegal value
154*> \endverbatim
155*
156* Authors:
157* ========
158*
159*> \author Univ. of Tennessee
160*> \author Univ. of California Berkeley
161*> \author Univ. of Colorado Denver
162*> \author NAG Ltd.
163*
164*> \ingroup getsqrhrt
165*
166*> \par Contributors:
167* ==================
168*>
169*> \verbatim
170*>
171*> November 2020, Igor Kozachenko,
172*> Computer Science Division,
173*> University of California, Berkeley
174*>
175*> \endverbatim
176*>
177* =====================================================================
178 SUBROUTINE sgetsqrhrt( M, N, MB1, NB1, NB2, A, LDA, T, LDT,
179 $ WORK,
180 $ LWORK, INFO )
181 IMPLICIT NONE
182*
183* -- LAPACK computational routine --
184* -- LAPACK is a software package provided by Univ. of Tennessee, --
185* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
186*
187* .. Scalar Arguments ..
188 INTEGER INFO, LDA, LDT, LWORK, M, N, NB1, NB2, MB1
189* ..
190* .. Array Arguments ..
191 REAL A( LDA, * ), T( LDT, * ), WORK( * )
192* ..
193*
194* =====================================================================
195*
196* .. Parameters ..
197 REAL ONE
198 PARAMETER ( ONE = 1.0e+0 )
199* ..
200* .. Local Scalars ..
201 LOGICAL LQUERY
202 INTEGER I, IINFO, J, LW1, LW2, LWT, LDWT, LWORKOPT,
203 $ nb1local, nb2local, num_all_row_blocks
204* ..
205* .. External Functions ..
206 REAL SROUNDUP_LWORK
207 EXTERNAL SROUNDUP_LWORK
208* ..
209* .. External Subroutines ..
210 EXTERNAL scopy, slatsqr, sorgtsqr_row,
211 $ sorhr_col,
212 $ xerbla
213* ..
214* .. Intrinsic Functions ..
215 INTRINSIC ceiling, max, min
216* ..
217* .. Executable Statements ..
218*
219* Test the input arguments
220*
221 info = 0
222 lquery = ( lwork.EQ.-1 )
223 IF( m.LT.0 ) THEN
224 info = -1
225 ELSE IF( n.LT.0 .OR. m.LT.n ) THEN
226 info = -2
227 ELSE IF( mb1.LE.n ) THEN
228 info = -3
229 ELSE IF( nb1.LT.1 ) THEN
230 info = -4
231 ELSE IF( nb2.LT.1 ) THEN
232 info = -5
233 ELSE IF( lda.LT.max( 1, m ) ) THEN
234 info = -7
235 ELSE IF( ldt.LT.max( 1, min( nb2, n ) ) ) THEN
236 info = -9
237 ELSE
238*
239* Test the input LWORK for the dimension of the array WORK.
240* This workspace is used to store array:
241* a) Matrix T and WORK for SLATSQR;
242* b) N-by-N upper-triangular factor R_tsqr;
243* c) Matrix T and array WORK for SORGTSQR_ROW;
244* d) Diagonal D for SORHR_COL.
245*
246 IF( lwork.LT.n*n+1 .AND. .NOT.lquery ) THEN
247 info = -11
248 ELSE
249*
250* Set block size for column blocks
251*
252 nb1local = min( nb1, n )
253*
254 num_all_row_blocks = max( 1,
255 $ ceiling( real( m - n ) / real( mb1 - n ) ) )
256*
257* Length and leading dimension of WORK array to place
258* T array in TSQR.
259*
260 lwt = num_all_row_blocks * n * nb1local
261
262 ldwt = nb1local
263*
264* Length of TSQR work array
265*
266 lw1 = nb1local * n
267*
268* Length of SORGTSQR_ROW work array.
269*
270 lw2 = nb1local * max( nb1local, ( n - nb1local ) )
271*
272 lworkopt = max( lwt + lw1, max( lwt+n*n+lw2, lwt+n*n+n ) )
273 lworkopt = max( 1, lworkopt )
274*
275 IF( lwork.LT.lworkopt .AND. .NOT.lquery ) THEN
276 info = -11
277 END IF
278*
279 END IF
280 END IF
281*
282* Handle error in the input parameters and return workspace query.
283*
284 IF( info.NE.0 ) THEN
285 CALL xerbla( 'SGETSQRHRT', -info )
286 RETURN
287 ELSE IF ( lquery ) THEN
288 work( 1 ) = sroundup_lwork( lworkopt )
289 RETURN
290 END IF
291*
292* Quick return if possible
293*
294 IF( min( m, n ).EQ.0 ) THEN
295 work( 1 ) = sroundup_lwork( lworkopt )
296 RETURN
297 END IF
298*
299 nb2local = min( nb2, n )
300*
301*
302* (1) Perform TSQR-factorization of the M-by-N matrix A.
303*
304 CALL slatsqr( m, n, mb1, nb1local, a, lda, work, ldwt,
305 $ work(lwt+1), lw1, iinfo )
306*
307* (2) Copy the factor R_tsqr stored in the upper-triangular part
308* of A into the square matrix in the work array
309* WORK(LWT+1:LWT+N*N) column-by-column.
310*
311 DO j = 1, n
312 CALL scopy( j, a( 1, j ), 1, work( lwt + n*(j-1)+1 ), 1 )
313 END DO
314*
315* (3) Generate a M-by-N matrix Q with orthonormal columns from
316* the result stored below the diagonal in the array A in place.
317*
318
319 CALL sorgtsqr_row( m, n, mb1, nb1local, a, lda, work, ldwt,
320 $ work( lwt+n*n+1 ), lw2, iinfo )
321*
322* (4) Perform the reconstruction of Householder vectors from
323* the matrix Q (stored in A) in place.
324*
325 CALL sorhr_col( m, n, nb2local, a, lda, t, ldt,
326 $ work( lwt+n*n+1 ), iinfo )
327*
328* (5) Copy the factor R_tsqr stored in the square matrix in the
329* work array WORK(LWT+1:LWT+N*N) into the upper-triangular
330* part of A.
331*
332* (6) Compute from R_tsqr the factor R_hr corresponding to
333* the reconstructed Householder vectors, i.e. R_hr = S * R_tsqr.
334* This multiplication by the sign matrix S on the left means
335* changing the sign of I-th row of the matrix R_tsqr according
336* to sign of the I-th diagonal element DIAG(I) of the matrix S.
337* DIAG is stored in WORK( LWT+N*N+1 ) from the SORHR_COL output.
338*
339* (5) and (6) can be combined in a single loop, so the rows in A
340* are accessed only once.
341*
342 DO i = 1, n
343 IF( work( lwt+n*n+i ).EQ.-one ) THEN
344 DO j = i, n
345 a( i, j ) = -one * work( lwt+n*(j-1)+i )
346 END DO
347 ELSE
348 CALL scopy( n-i+1, work(lwt+n*(i-1)+i), n, a( i, i ),
349 $ lda )
350 END IF
351 END DO
352*
353 work( 1 ) = sroundup_lwork( lworkopt )
354 RETURN
355*
356* End of SGETSQRHRT
357*
358 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine scopy(n, sx, incx, sy, incy)
SCOPY
Definition scopy.f:82
subroutine sgetsqrhrt(m, n, mb1, nb1, nb2, a, lda, t, ldt, work, lwork, info)
SGETSQRHRT
Definition sgetsqrhrt.f:181
subroutine slatsqr(m, n, mb, nb, a, lda, t, ldt, work, lwork, info)
SLATSQR
Definition slatsqr.f:172
subroutine sorgtsqr_row(m, n, mb, nb, a, lda, t, ldt, work, lwork, info)
SORGTSQR_ROW
subroutine sorhr_col(m, n, nb, a, lda, t, ldt, d, info)
SORHR_COL
Definition sorhr_col.f:257