3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download ZGGGLM + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zggglm.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zggglm.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zggglm.f">
21 * SUBROUTINE ZGGGLM( N, M, P, A, LDA, B, LDB, D, X, Y, WORK, LWORK,
24 * .. Scalar Arguments ..
25 * INTEGER INFO, LDA, LDB, LWORK, M, N, P
27 * .. Array Arguments ..
28 * COMPLEX*16 A( LDA, * ), B( LDB, * ), D( * ), WORK( * ),
38 *> ZGGGLM solves a general Gauss-Markov linear model (GLM) problem:
40 *> minimize || y ||_2 subject to d = A*x + B*y
43 *> where A is an N-by-M matrix, B is an N-by-P matrix, and d is a
44 *> given N-vector. It is assumed that M <= N <= M+P, and
46 *> rank(A) = M and rank( A B ) = N.
48 *> Under these assumptions, the constrained equation is always
49 *> consistent, and there is a unique solution x and a minimal 2-norm
50 *> solution y, which is obtained using a generalized QR factorization
51 *> of the matrices (A, B) given by
53 *> A = Q*(R), B = Q*T*Z.
56 *> In particular, if matrix B is square nonsingular, then the problem
57 *> GLM is equivalent to the following weighted linear least squares
60 *> minimize || inv(B)*(d-A*x) ||_2
63 *> where inv(B) denotes the inverse of B.
72 *> The number of rows of the matrices A and B. N >= 0.
78 *> The number of columns of the matrix A. 0 <= M <= N.
84 *> The number of columns of the matrix B. P >= N-M.
89 *> A is COMPLEX*16 array, dimension (LDA,M)
90 *> On entry, the N-by-M matrix A.
91 *> On exit, the upper triangular part of the array A contains
92 *> the M-by-M upper triangular matrix R.
98 *> The leading dimension of the array A. LDA >= max(1,N).
103 *> B is COMPLEX*16 array, dimension (LDB,P)
104 *> On entry, the N-by-P matrix B.
105 *> On exit, if N <= P, the upper triangle of the subarray
106 *> B(1:N,P-N+1:P) contains the N-by-N upper triangular matrix T;
107 *> if N > P, the elements on and above the (N-P)th subdiagonal
108 *> contain the N-by-P upper trapezoidal matrix T.
114 *> The leading dimension of the array B. LDB >= max(1,N).
119 *> D is COMPLEX*16 array, dimension (N)
120 *> On entry, D is the left hand side of the GLM equation.
121 *> On exit, D is destroyed.
126 *> X is COMPLEX*16 array, dimension (M)
131 *> Y is COMPLEX*16 array, dimension (P)
133 *> On exit, X and Y are the solutions of the GLM problem.
138 *> WORK is COMPLEX*16 array, dimension (MAX(1,LWORK))
139 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
145 *> The dimension of the array WORK. LWORK >= max(1,N+M+P).
146 *> For optimum performance, LWORK >= M+min(N,P)+max(N,P)*NB,
147 *> where NB is an upper bound for the optimal blocksizes for
148 *> ZGEQRF, ZGERQF, ZUNMQR and ZUNMRQ.
150 *> If LWORK = -1, then a workspace query is assumed; the routine
151 *> only calculates the optimal size of the WORK array, returns
152 *> this value as the first entry of the WORK array, and no error
153 *> message related to LWORK is issued by XERBLA.
159 *> = 0: successful exit.
160 *> < 0: if INFO = -i, the i-th argument had an illegal value.
161 *> = 1: the upper triangular factor R associated with A in the
162 *> generalized QR factorization of the pair (A, B) is
163 *> singular, so that rank(A) < M; the least squares
164 *> solution could not be computed.
165 *> = 2: the bottom (N-M) by (N-M) part of the upper trapezoidal
166 *> factor T associated with B in the generalized QR
167 *> factorization of the pair (A, B) is singular, so that
168 *> rank( A B ) < N; the least squares solution could not
175 *> \author Univ. of Tennessee
176 *> \author Univ. of California Berkeley
177 *> \author Univ. of Colorado Denver
180 *> \date November 2015
182 *> \ingroup complex16OTHEReigen
184 * =====================================================================
185 SUBROUTINE ZGGGLM( N, M, P, A, LDA, B, LDB, D, X, Y, WORK, LWORK,
188 * -- LAPACK driver routine (version 3.6.0) --
189 * -- LAPACK is a software package provided by Univ. of Tennessee, --
190 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
193 * .. Scalar Arguments ..
194 INTEGER INFO, LDA, LDB, LWORK, M, N, P
196 * .. Array Arguments ..
197 COMPLEX*16 A( LDA, * ), B( LDB, * ), D( * ), WORK( * ),
201 * ===================================================================
204 COMPLEX*16 CZERO, CONE
205 PARAMETER ( CZERO = ( 0.0D+0, 0.0D+0 ),
206 $ CONE = ( 1.0D+0, 0.0D+0 ) )
208 * .. Local Scalars ..
210 INTEGER I, LOPT, LWKMIN, LWKOPT, NB, NB1, NB2, NB3,
213 * .. External Subroutines ..
214 EXTERNAL XERBLA, ZCOPY, ZGEMV, ZGGQRF, ZTRTRS, ZUNMQR,
217 * .. External Functions ..
221 * .. Intrinsic Functions ..
222 INTRINSIC INT, MAX, MIN
224 * .. Executable Statements ..
226 * Test the input parameters
230 LQUERY = ( LWORK.EQ.-1 )
233 ELSE IF( M.LT.0 .OR. M.GT.N ) THEN
235 ELSE IF( P.LT.0 .OR. P.LT.N-M ) THEN
237 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
239 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
243 * Calculate workspace
250 NB1 = ILAENV( 1, 'ZGEQRF', ' ', N, M, -1, -1 )
251 NB2 = ILAENV( 1, 'ZGERQF', ' ', N, M, -1, -1 )
252 NB3 = ILAENV( 1, 'ZUNMQR', ' ', N, M, P, -1 )
253 NB4 = ILAENV( 1, 'ZUNMRQ', ' ', N, M, P, -1 )
254 NB = MAX( NB1, NB2, NB3, NB4 )
256 LWKOPT = M + NP + MAX( N, P )*NB
260 IF( LWORK.LT.LWKMIN .AND. .NOT.LQUERY ) THEN
266 CALL XERBLA( 'ZGGGLM', -INFO )
268 ELSE IF( LQUERY ) THEN
272 * Quick return if possible
277 * Compute the GQR factorization of matrices A and B:
279 * Q**H*A = ( R11 ) M, Q**H*B*Z**H = ( T11 T12 ) M
280 * ( 0 ) N-M ( 0 T22 ) N-M
283 * where R11 and T22 are upper triangular, and Q and Z are
286 CALL ZGGQRF( N, M, P, A, LDA, WORK, B, LDB, WORK( M+1 ),
287 $ WORK( M+NP+1 ), LWORK-M-NP, INFO )
288 LOPT = WORK( M+NP+1 )
290 * Update left-hand-side vector d = Q**H*d = ( d1 ) M
293 CALL ZUNMQR( 'Left', 'Conjugate transpose', N, 1, M, A, LDA, WORK,
294 $ D, MAX( 1, N ), WORK( M+NP+1 ), LWORK-M-NP, INFO )
295 LOPT = MAX( LOPT, INT( WORK( M+NP+1 ) ) )
297 * Solve T22*y2 = d2 for y2
300 CALL ZTRTRS( 'Upper', 'No transpose', 'Non unit', N-M, 1,
301 $ B( M+1, M+P-N+1 ), LDB, D( M+1 ), N-M, INFO )
308 CALL ZCOPY( N-M, D( M+1 ), 1, Y( M+P-N+1 ), 1 )
313 DO 10 I = 1, M + P - N
317 * Update d1 = d1 - T12*y2
319 CALL ZGEMV( 'No transpose', M, N-M, -CONE, B( 1, M+P-N+1 ), LDB,
320 $ Y( M+P-N+1 ), 1, CONE, D, 1 )
322 * Solve triangular system: R11*x = d1
325 CALL ZTRTRS( 'Upper', 'No Transpose', 'Non unit', M, 1, A, LDA,
335 CALL ZCOPY( M, D, 1, X, 1 )
338 * Backward transformation y = Z**H *y
340 CALL ZUNMRQ( 'Left', 'Conjugate transpose', P, 1, NP,
341 $ B( MAX( 1, N-P+1 ), 1 ), LDB, WORK( M+1 ), Y,
342 $ MAX( 1, P ), WORK( M+NP+1 ), LWORK-M-NP, INFO )
343 WORK( 1 ) = M + NP + MAX( LOPT, INT( WORK( M+NP+1 ) ) )