LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
cggglm.f
Go to the documentation of this file.
1*> \brief \b CGGGLM
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download CGGGLM + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cggglm.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cggglm.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cggglm.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE CGGGLM( N, M, P, A, LDA, B, LDB, D, X, Y, WORK, LWORK,
20* INFO )
21*
22* .. Scalar Arguments ..
23* INTEGER INFO, LDA, LDB, LWORK, M, N, P
24* ..
25* .. Array Arguments ..
26* COMPLEX A( LDA, * ), B( LDB, * ), D( * ), WORK( * ),
27* $ X( * ), Y( * )
28* ..
29*
30*
31*> \par Purpose:
32* =============
33*>
34*> \verbatim
35*>
36*> CGGGLM solves a general Gauss-Markov linear model (GLM) problem:
37*>
38*> minimize || y ||_2 subject to d = A*x + B*y
39*> x
40*>
41*> where A is an N-by-M matrix, B is an N-by-P matrix, and d is a
42*> given N-vector. It is assumed that M <= N <= M+P, and
43*>
44*> rank(A) = M and rank( A B ) = N.
45*>
46*> Under these assumptions, the constrained equation is always
47*> consistent, and there is a unique solution x and a minimal 2-norm
48*> solution y, which is obtained using a generalized QR factorization
49*> of the matrices (A, B) given by
50*>
51*> A = Q*(R), B = Q*T*Z.
52*> (0)
53*>
54*> In particular, if matrix B is square nonsingular, then the problem
55*> GLM is equivalent to the following weighted linear least squares
56*> problem
57*>
58*> minimize || inv(B)*(d-A*x) ||_2
59*> x
60*>
61*> where inv(B) denotes the inverse of B.
62*>
63*> Callers of this subroutine should note that the singularity/rank-deficiency checks
64*> implemented in this subroutine are rudimentary. The CTRTRS subroutine called by this
65*> subroutine only signals a failure due to singularity if the problem is exactly singular.
66*>
67*> It is conceivable for one (or more) of the factors involved in the generalized QR
68*> factorization of the pair (A, B) to be subnormally close to singularity without this
69*> subroutine signalling an error. The solutions computed for such almost-rank-deficient
70*> problems may be less accurate due to a loss of numerical precision.
71*>
72*> \endverbatim
73*
74* Arguments:
75* ==========
76*
77*> \param[in] N
78*> \verbatim
79*> N is INTEGER
80*> The number of rows of the matrices A and B. N >= 0.
81*> \endverbatim
82*>
83*> \param[in] M
84*> \verbatim
85*> M is INTEGER
86*> The number of columns of the matrix A. 0 <= M <= N.
87*> \endverbatim
88*>
89*> \param[in] P
90*> \verbatim
91*> P is INTEGER
92*> The number of columns of the matrix B. P >= N-M.
93*> \endverbatim
94*>
95*> \param[in,out] A
96*> \verbatim
97*> A is COMPLEX array, dimension (LDA,M)
98*> On entry, the N-by-M matrix A.
99*> On exit, the upper triangular part of the array A contains
100*> the M-by-M upper triangular matrix R.
101*> \endverbatim
102*>
103*> \param[in] LDA
104*> \verbatim
105*> LDA is INTEGER
106*> The leading dimension of the array A. LDA >= max(1,N).
107*> \endverbatim
108*>
109*> \param[in,out] B
110*> \verbatim
111*> B is COMPLEX array, dimension (LDB,P)
112*> On entry, the N-by-P matrix B.
113*> On exit, if N <= P, the upper triangle of the subarray
114*> B(1:N,P-N+1:P) contains the N-by-N upper triangular matrix T;
115*> if N > P, the elements on and above the (N-P)th subdiagonal
116*> contain the N-by-P upper trapezoidal matrix T.
117*> \endverbatim
118*>
119*> \param[in] LDB
120*> \verbatim
121*> LDB is INTEGER
122*> The leading dimension of the array B. LDB >= max(1,N).
123*> \endverbatim
124*>
125*> \param[in,out] D
126*> \verbatim
127*> D is COMPLEX array, dimension (N)
128*> On entry, D is the left hand side of the GLM equation.
129*> On exit, D is destroyed.
130*> \endverbatim
131*>
132*> \param[out] X
133*> \verbatim
134*> X is COMPLEX array, dimension (M)
135*> \endverbatim
136*>
137*> \param[out] Y
138*> \verbatim
139*> Y is COMPLEX array, dimension (P)
140*>
141*> On exit, X and Y are the solutions of the GLM problem.
142*> \endverbatim
143*>
144*> \param[out] WORK
145*> \verbatim
146*> WORK is COMPLEX array, dimension (MAX(1,LWORK))
147*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
148*> \endverbatim
149*>
150*> \param[in] LWORK
151*> \verbatim
152*> LWORK is INTEGER
153*> The dimension of the array WORK. LWORK >= max(1,N+M+P).
154*> For optimum performance, LWORK >= M+min(N,P)+max(N,P)*NB,
155*> where NB is an upper bound for the optimal blocksizes for
156*> CGEQRF, CGERQF, CUNMQR and CUNMRQ.
157*>
158*> If LWORK = -1, then a workspace query is assumed; the routine
159*> only calculates the optimal size of the WORK array, returns
160*> this value as the first entry of the WORK array, and no error
161*> message related to LWORK is issued by XERBLA.
162*> \endverbatim
163*>
164*> \param[out] INFO
165*> \verbatim
166*> INFO is INTEGER
167*> = 0: successful exit.
168*> < 0: if INFO = -i, the i-th argument had an illegal value.
169*> = 1: the upper triangular factor R associated with A in the
170*> generalized QR factorization of the pair (A, B) is exactly
171*> singular, so that rank(A) < M; the least squares
172*> solution could not be computed.
173*> = 2: the bottom (N-M) by (N-M) part of the upper trapezoidal
174*> factor T associated with B in the generalized QR
175*> factorization of the pair (A, B) is exactly singular, so that
176*> rank( A B ) < N; the least squares solution could not
177*> be computed.
178*> \endverbatim
179*
180* Authors:
181* ========
182*
183*> \author Univ. of Tennessee
184*> \author Univ. of California Berkeley
185*> \author Univ. of Colorado Denver
186*> \author NAG Ltd.
187*
188*> \ingroup ggglm
189*
190* =====================================================================
191 SUBROUTINE cggglm( N, M, P, A, LDA, B, LDB, D, X, Y, WORK,
192 $ LWORK,
193 $ INFO )
194*
195* -- LAPACK driver routine --
196* -- LAPACK is a software package provided by Univ. of Tennessee, --
197* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
198*
199* .. Scalar Arguments ..
200 INTEGER INFO, LDA, LDB, LWORK, M, N, P
201* ..
202* .. Array Arguments ..
203 COMPLEX A( LDA, * ), B( LDB, * ), D( * ), WORK( * ),
204 $ X( * ), Y( * )
205* ..
206*
207* ===================================================================
208*
209* .. Parameters ..
210 COMPLEX CZERO, CONE
211 PARAMETER ( CZERO = ( 0.0e+0, 0.0e+0 ),
212 $ cone = ( 1.0e+0, 0.0e+0 ) )
213* ..
214* .. Local Scalars ..
215 LOGICAL LQUERY
216 INTEGER I, LOPT, LWKMIN, LWKOPT, NB, NB1, NB2, NB3,
217 $ nb4, np
218* ..
219* .. External Subroutines ..
220 EXTERNAL ccopy, cgemv, cggqrf, ctrtrs, cunmqr,
221 $ cunmrq,
222 $ xerbla
223* ..
224* .. External Functions ..
225 INTEGER ILAENV
226 REAL SROUNDUP_LWORK
227 EXTERNAL ilaenv, sroundup_lwork
228* ..
229* .. Intrinsic Functions ..
230 INTRINSIC int, max, min
231* ..
232* .. Executable Statements ..
233*
234* Test the input parameters
235*
236 info = 0
237 np = min( n, p )
238 lquery = ( lwork.EQ.-1 )
239 IF( n.LT.0 ) THEN
240 info = -1
241 ELSE IF( m.LT.0 .OR. m.GT.n ) THEN
242 info = -2
243 ELSE IF( p.LT.0 .OR. p.LT.n-m ) THEN
244 info = -3
245 ELSE IF( lda.LT.max( 1, n ) ) THEN
246 info = -5
247 ELSE IF( ldb.LT.max( 1, n ) ) THEN
248 info = -7
249 END IF
250*
251* Calculate workspace
252*
253 IF( info.EQ.0) THEN
254 IF( n.EQ.0 ) THEN
255 lwkmin = 1
256 lwkopt = 1
257 ELSE
258 nb1 = ilaenv( 1, 'CGEQRF', ' ', n, m, -1, -1 )
259 nb2 = ilaenv( 1, 'CGERQF', ' ', n, m, -1, -1 )
260 nb3 = ilaenv( 1, 'CUNMQR', ' ', n, m, p, -1 )
261 nb4 = ilaenv( 1, 'CUNMRQ', ' ', n, m, p, -1 )
262 nb = max( nb1, nb2, nb3, nb4 )
263 lwkmin = m + n + p
264 lwkopt = m + np + max( n, p )*nb
265 END IF
266 work( 1 ) = sroundup_lwork(lwkopt)
267*
268 IF( lwork.LT.lwkmin .AND. .NOT.lquery ) THEN
269 info = -12
270 END IF
271 END IF
272*
273 IF( info.NE.0 ) THEN
274 CALL xerbla( 'CGGGLM', -info )
275 RETURN
276 ELSE IF( lquery ) THEN
277 RETURN
278 END IF
279*
280* Quick return if possible
281*
282 IF( n.EQ.0 ) THEN
283 DO i = 1, m
284 x(i) = czero
285 END DO
286 DO i = 1, p
287 y(i) = czero
288 END DO
289 RETURN
290 END IF
291*
292* Compute the GQR factorization of matrices A and B:
293*
294* Q**H*A = ( R11 ) M, Q**H*B*Z**H = ( T11 T12 ) M
295* ( 0 ) N-M ( 0 T22 ) N-M
296* M M+P-N N-M
297*
298* where R11 and T22 are upper triangular, and Q and Z are
299* unitary.
300*
301 CALL cggqrf( n, m, p, a, lda, work, b, ldb, work( m+1 ),
302 $ work( m+np+1 ), lwork-m-np, info )
303 lopt = int( work( m+np+1 ) )
304*
305* Update left-hand-side vector d = Q**H*d = ( d1 ) M
306* ( d2 ) N-M
307*
308 CALL cunmqr( 'Left', 'Conjugate transpose', n, 1, m, a, lda,
309 $ work,
310 $ d, max( 1, n ), work( m+np+1 ), lwork-m-np, info )
311 lopt = max( lopt, int( work( m+np+1 ) ) )
312*
313* Solve T22*y2 = d2 for y2
314*
315 IF( n.GT.m ) THEN
316 CALL ctrtrs( 'Upper', 'No transpose', 'Non unit', n-m, 1,
317 $ b( m+1, m+p-n+1 ), ldb, d( m+1 ), n-m, info )
318*
319 IF( info.GT.0 ) THEN
320 info = 1
321 RETURN
322 END IF
323*
324 CALL ccopy( n-m, d( m+1 ), 1, y( m+p-n+1 ), 1 )
325 END IF
326*
327* Set y1 = 0
328*
329 DO 10 i = 1, m + p - n
330 y( i ) = czero
331 10 CONTINUE
332*
333* Update d1 = d1 - T12*y2
334*
335 CALL cgemv( 'No transpose', m, n-m, -cone, b( 1, m+p-n+1 ),
336 $ ldb,
337 $ y( m+p-n+1 ), 1, cone, d, 1 )
338*
339* Solve triangular system: R11*x = d1
340*
341 IF( m.GT.0 ) THEN
342 CALL ctrtrs( 'Upper', 'No Transpose', 'Non unit', m, 1, a,
343 $ lda,
344 $ d, m, info )
345*
346 IF( info.GT.0 ) THEN
347 info = 2
348 RETURN
349 END IF
350*
351* Copy D to X
352*
353 CALL ccopy( m, d, 1, x, 1 )
354 END IF
355*
356* Backward transformation y = Z**H *y
357*
358 CALL cunmrq( 'Left', 'Conjugate transpose', p, 1, np,
359 $ b( max( 1, n-p+1 ), 1 ), ldb, work( m+1 ), y,
360 $ max( 1, p ), work( m+np+1 ), lwork-m-np, info )
361 work( 1 ) = cmplx( m + np + max( lopt, int( work( m+np+1 ) ) ) )
362*
363 RETURN
364*
365* End of CGGGLM
366*
367 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine ccopy(n, cx, incx, cy, incy)
CCOPY
Definition ccopy.f:81
subroutine cgemv(trans, m, n, alpha, a, lda, x, incx, beta, y, incy)
CGEMV
Definition cgemv.f:160
subroutine cggglm(n, m, p, a, lda, b, ldb, d, x, y, work, lwork, info)
CGGGLM
Definition cggglm.f:194
subroutine cggqrf(n, m, p, a, lda, taua, b, ldb, taub, work, lwork, info)
CGGQRF
Definition cggqrf.f:213
subroutine ctrtrs(uplo, trans, diag, n, nrhs, a, lda, b, ldb, info)
CTRTRS
Definition ctrtrs.f:144
subroutine cunmqr(side, trans, m, n, k, a, lda, tau, c, ldc, work, lwork, info)
CUNMQR
Definition cunmqr.f:166
subroutine cunmrq(side, trans, m, n, k, a, lda, tau, c, ldc, work, lwork, info)
CUNMRQ
Definition cunmrq.f:166