LAPACK 3.3.1
Linear Algebra PACKage
|
00001 SUBROUTINE CGGGLM( N, M, P, A, LDA, B, LDB, D, X, Y, WORK, LWORK, 00002 $ INFO ) 00003 * 00004 * -- LAPACK driver routine (version 3.3.1) -- 00005 * -- LAPACK is a software package provided by Univ. of Tennessee, -- 00006 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- 00007 * -- April 2011 -- 00008 * 00009 * .. Scalar Arguments .. 00010 INTEGER INFO, LDA, LDB, LWORK, M, N, P 00011 * .. 00012 * .. Array Arguments .. 00013 COMPLEX A( LDA, * ), B( LDB, * ), D( * ), WORK( * ), 00014 $ X( * ), Y( * ) 00015 * .. 00016 * 00017 * Purpose 00018 * ======= 00019 * 00020 * CGGGLM solves a general Gauss-Markov linear model (GLM) problem: 00021 * 00022 * minimize || y ||_2 subject to d = A*x + B*y 00023 * x 00024 * 00025 * where A is an N-by-M matrix, B is an N-by-P matrix, and d is a 00026 * given N-vector. It is assumed that M <= N <= M+P, and 00027 * 00028 * rank(A) = M and rank( A B ) = N. 00029 * 00030 * Under these assumptions, the constrained equation is always 00031 * consistent, and there is a unique solution x and a minimal 2-norm 00032 * solution y, which is obtained using a generalized QR factorization 00033 * of the matrices (A, B) given by 00034 * 00035 * A = Q*(R), B = Q*T*Z. 00036 * (0) 00037 * 00038 * In particular, if matrix B is square nonsingular, then the problem 00039 * GLM is equivalent to the following weighted linear least squares 00040 * problem 00041 * 00042 * minimize || inv(B)*(d-A*x) ||_2 00043 * x 00044 * 00045 * where inv(B) denotes the inverse of B. 00046 * 00047 * Arguments 00048 * ========= 00049 * 00050 * N (input) INTEGER 00051 * The number of rows of the matrices A and B. N >= 0. 00052 * 00053 * M (input) INTEGER 00054 * The number of columns of the matrix A. 0 <= M <= N. 00055 * 00056 * P (input) INTEGER 00057 * The number of columns of the matrix B. P >= N-M. 00058 * 00059 * A (input/output) COMPLEX array, dimension (LDA,M) 00060 * On entry, the N-by-M matrix A. 00061 * On exit, the upper triangular part of the array A contains 00062 * the M-by-M upper triangular matrix R. 00063 * 00064 * LDA (input) INTEGER 00065 * The leading dimension of the array A. LDA >= max(1,N). 00066 * 00067 * B (input/output) COMPLEX array, dimension (LDB,P) 00068 * On entry, the N-by-P matrix B. 00069 * On exit, if N <= P, the upper triangle of the subarray 00070 * B(1:N,P-N+1:P) contains the N-by-N upper triangular matrix T; 00071 * if N > P, the elements on and above the (N-P)th subdiagonal 00072 * contain the N-by-P upper trapezoidal matrix T. 00073 * 00074 * LDB (input) INTEGER 00075 * The leading dimension of the array B. LDB >= max(1,N). 00076 * 00077 * D (input/output) COMPLEX array, dimension (N) 00078 * On entry, D is the left hand side of the GLM equation. 00079 * On exit, D is destroyed. 00080 * 00081 * X (output) COMPLEX array, dimension (M) 00082 * Y (output) COMPLEX array, dimension (P) 00083 * On exit, X and Y are the solutions of the GLM problem. 00084 * 00085 * WORK (workspace/output) COMPLEX array, dimension (MAX(1,LWORK)) 00086 * On exit, if INFO = 0, WORK(1) returns the optimal LWORK. 00087 * 00088 * LWORK (input) INTEGER 00089 * The dimension of the array WORK. LWORK >= max(1,N+M+P). 00090 * For optimum performance, LWORK >= M+min(N,P)+max(N,P)*NB, 00091 * where NB is an upper bound for the optimal blocksizes for 00092 * CGEQRF, CGERQF, CUNMQR and CUNMRQ. 00093 * 00094 * If LWORK = -1, then a workspace query is assumed; the routine 00095 * only calculates the optimal size of the WORK array, returns 00096 * this value as the first entry of the WORK array, and no error 00097 * message related to LWORK is issued by XERBLA. 00098 * 00099 * INFO (output) INTEGER 00100 * = 0: successful exit. 00101 * < 0: if INFO = -i, the i-th argument had an illegal value. 00102 * = 1: the upper triangular factor R associated with A in the 00103 * generalized QR factorization of the pair (A, B) is 00104 * singular, so that rank(A) < M; the least squares 00105 * solution could not be computed. 00106 * = 2: the bottom (N-M) by (N-M) part of the upper trapezoidal 00107 * factor T associated with B in the generalized QR 00108 * factorization of the pair (A, B) is singular, so that 00109 * rank( A B ) < N; the least squares solution could not 00110 * be computed. 00111 * 00112 * =================================================================== 00113 * 00114 * .. Parameters .. 00115 COMPLEX CZERO, CONE 00116 PARAMETER ( CZERO = ( 0.0E+0, 0.0E+0 ), 00117 $ CONE = ( 1.0E+0, 0.0E+0 ) ) 00118 * .. 00119 * .. Local Scalars .. 00120 LOGICAL LQUERY 00121 INTEGER I, LOPT, LWKMIN, LWKOPT, NB, NB1, NB2, NB3, 00122 $ NB4, NP 00123 * .. 00124 * .. External Subroutines .. 00125 EXTERNAL CCOPY, CGEMV, CGGQRF, CTRTRS, CUNMQR, CUNMRQ, 00126 $ XERBLA 00127 * .. 00128 * .. External Functions .. 00129 INTEGER ILAENV 00130 EXTERNAL ILAENV 00131 * .. 00132 * .. Intrinsic Functions .. 00133 INTRINSIC INT, MAX, MIN 00134 * .. 00135 * .. Executable Statements .. 00136 * 00137 * Test the input parameters 00138 * 00139 INFO = 0 00140 NP = MIN( N, P ) 00141 LQUERY = ( LWORK.EQ.-1 ) 00142 IF( N.LT.0 ) THEN 00143 INFO = -1 00144 ELSE IF( M.LT.0 .OR. M.GT.N ) THEN 00145 INFO = -2 00146 ELSE IF( P.LT.0 .OR. P.LT.N-M ) THEN 00147 INFO = -3 00148 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN 00149 INFO = -5 00150 ELSE IF( LDB.LT.MAX( 1, N ) ) THEN 00151 INFO = -7 00152 END IF 00153 * 00154 * Calculate workspace 00155 * 00156 IF( INFO.EQ.0) THEN 00157 IF( N.EQ.0 ) THEN 00158 LWKMIN = 1 00159 LWKOPT = 1 00160 ELSE 00161 NB1 = ILAENV( 1, 'CGEQRF', ' ', N, M, -1, -1 ) 00162 NB2 = ILAENV( 1, 'CGERQF', ' ', N, M, -1, -1 ) 00163 NB3 = ILAENV( 1, 'CUNMQR', ' ', N, M, P, -1 ) 00164 NB4 = ILAENV( 1, 'CUNMRQ', ' ', N, M, P, -1 ) 00165 NB = MAX( NB1, NB2, NB3, NB4 ) 00166 LWKMIN = M + N + P 00167 LWKOPT = M + NP + MAX( N, P )*NB 00168 END IF 00169 WORK( 1 ) = LWKOPT 00170 * 00171 IF( LWORK.LT.LWKMIN .AND. .NOT.LQUERY ) THEN 00172 INFO = -12 00173 END IF 00174 END IF 00175 * 00176 IF( INFO.NE.0 ) THEN 00177 CALL XERBLA( 'CGGGLM', -INFO ) 00178 RETURN 00179 ELSE IF( LQUERY ) THEN 00180 RETURN 00181 END IF 00182 * 00183 * Quick return if possible 00184 * 00185 IF( N.EQ.0 ) 00186 $ RETURN 00187 * 00188 * Compute the GQR factorization of matrices A and B: 00189 * 00190 * Q**H*A = ( R11 ) M, Q**H*B*Z**H = ( T11 T12 ) M 00191 * ( 0 ) N-M ( 0 T22 ) N-M 00192 * M M+P-N N-M 00193 * 00194 * where R11 and T22 are upper triangular, and Q and Z are 00195 * unitary. 00196 * 00197 CALL CGGQRF( N, M, P, A, LDA, WORK, B, LDB, WORK( M+1 ), 00198 $ WORK( M+NP+1 ), LWORK-M-NP, INFO ) 00199 LOPT = WORK( M+NP+1 ) 00200 * 00201 * Update left-hand-side vector d = Q**H*d = ( d1 ) M 00202 * ( d2 ) N-M 00203 * 00204 CALL CUNMQR( 'Left', 'Conjugate transpose', N, 1, M, A, LDA, WORK, 00205 $ D, MAX( 1, N ), WORK( M+NP+1 ), LWORK-M-NP, INFO ) 00206 LOPT = MAX( LOPT, INT( WORK( M+NP+1 ) ) ) 00207 * 00208 * Solve T22*y2 = d2 for y2 00209 * 00210 IF( N.GT.M ) THEN 00211 CALL CTRTRS( 'Upper', 'No transpose', 'Non unit', N-M, 1, 00212 $ B( M+1, M+P-N+1 ), LDB, D( M+1 ), N-M, INFO ) 00213 * 00214 IF( INFO.GT.0 ) THEN 00215 INFO = 1 00216 RETURN 00217 END IF 00218 * 00219 CALL CCOPY( N-M, D( M+1 ), 1, Y( M+P-N+1 ), 1 ) 00220 END IF 00221 * 00222 * Set y1 = 0 00223 * 00224 DO 10 I = 1, M + P - N 00225 Y( I ) = CZERO 00226 10 CONTINUE 00227 * 00228 * Update d1 = d1 - T12*y2 00229 * 00230 CALL CGEMV( 'No transpose', M, N-M, -CONE, B( 1, M+P-N+1 ), LDB, 00231 $ Y( M+P-N+1 ), 1, CONE, D, 1 ) 00232 * 00233 * Solve triangular system: R11*x = d1 00234 * 00235 IF( M.GT.0 ) THEN 00236 CALL CTRTRS( 'Upper', 'No Transpose', 'Non unit', M, 1, A, LDA, 00237 $ D, M, INFO ) 00238 * 00239 IF( INFO.GT.0 ) THEN 00240 INFO = 2 00241 RETURN 00242 END IF 00243 * 00244 * Copy D to X 00245 * 00246 CALL CCOPY( M, D, 1, X, 1 ) 00247 END IF 00248 * 00249 * Backward transformation y = Z**H *y 00250 * 00251 CALL CUNMRQ( 'Left', 'Conjugate transpose', P, 1, NP, 00252 $ B( MAX( 1, N-P+1 ), 1 ), LDB, WORK( M+1 ), Y, 00253 $ MAX( 1, P ), WORK( M+NP+1 ), LWORK-M-NP, INFO ) 00254 WORK( 1 ) = M + NP + MAX( LOPT, INT( WORK( M+NP+1 ) ) ) 00255 * 00256 RETURN 00257 * 00258 * End of CGGGLM 00259 * 00260 END