3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download ZGGSVP3 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zggsvp3.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zggsvp3.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zggsvp3.f">
21 * SUBROUTINE ZGGSVP3( JOBU, JOBV, JOBQ, M, P, N, A, LDA, B, LDB,
22 * TOLA, TOLB, K, L, U, LDU, V, LDV, Q, LDQ,
23 * IWORK, RWORK, TAU, WORK, LWORK, INFO )
25 * .. Scalar Arguments ..
26 * CHARACTER JOBQ, JOBU, JOBV
27 * INTEGER INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N, P, LWORK
28 * DOUBLE PRECISION TOLA, TOLB
30 * .. Array Arguments ..
32 * DOUBLE PRECISION RWORK( * )
33 * COMPLEX*16 A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
34 * $ TAU( * ), U( LDU, * ), V( LDV, * ), WORK( * )
43 *> ZGGSVP3 computes unitary matrices U, V and Q such that
46 *> U**H*A*Q = K ( 0 A12 A13 ) if M-K-L >= 0;
51 *> = K ( 0 A12 A13 ) if M-K-L < 0;
55 *> V**H*B*Q = L ( 0 0 B13 )
58 *> where the K-by-K matrix A12 and L-by-L matrix B13 are nonsingular
59 *> upper triangular; A23 is L-by-L upper triangular if M-K-L >= 0,
60 *> otherwise A23 is (M-K)-by-L upper trapezoidal. K+L = the effective
61 *> numerical rank of the (M+P)-by-N matrix (A**H,B**H)**H.
63 *> This decomposition is the preprocessing step for computing the
64 *> Generalized Singular Value Decomposition (GSVD), see subroutine
73 *> JOBU is CHARACTER*1
74 *> = 'U': Unitary matrix U is computed;
75 *> = 'N': U is not computed.
80 *> JOBV is CHARACTER*1
81 *> = 'V': Unitary matrix V is computed;
82 *> = 'N': V is not computed.
87 *> JOBQ is CHARACTER*1
88 *> = 'Q': Unitary matrix Q is computed;
89 *> = 'N': Q is not computed.
95 *> The number of rows of the matrix A. M >= 0.
101 *> The number of rows of the matrix B. P >= 0.
107 *> The number of columns of the matrices A and B. N >= 0.
112 *> A is COMPLEX*16 array, dimension (LDA,N)
113 *> On entry, the M-by-N matrix A.
114 *> On exit, A contains the triangular (or trapezoidal) matrix
115 *> described in the Purpose section.
121 *> The leading dimension of the array A. LDA >= max(1,M).
126 *> B is COMPLEX*16 array, dimension (LDB,N)
127 *> On entry, the P-by-N matrix B.
128 *> On exit, B contains the triangular matrix described in
129 *> the Purpose section.
135 *> The leading dimension of the array B. LDB >= max(1,P).
140 *> TOLA is DOUBLE PRECISION
145 *> TOLB is DOUBLE PRECISION
147 *> TOLA and TOLB are the thresholds to determine the effective
148 *> numerical rank of matrix B and a subblock of A. Generally,
150 *> TOLA = MAX(M,N)*norm(A)*MAZHEPS,
151 *> TOLB = MAX(P,N)*norm(B)*MAZHEPS.
152 *> The size of TOLA and TOLB may affect the size of backward
153 *> errors of the decomposition.
165 *> On exit, K and L specify the dimension of the subblocks
166 *> described in Purpose section.
167 *> K + L = effective numerical rank of (A**H,B**H)**H.
172 *> U is COMPLEX*16 array, dimension (LDU,M)
173 *> If JOBU = 'U', U contains the unitary matrix U.
174 *> If JOBU = 'N', U is not referenced.
180 *> The leading dimension of the array U. LDU >= max(1,M) if
181 *> JOBU = 'U'; LDU >= 1 otherwise.
186 *> V is COMPLEX*16 array, dimension (LDV,P)
187 *> If JOBV = 'V', V contains the unitary matrix V.
188 *> If JOBV = 'N', V is not referenced.
194 *> The leading dimension of the array V. LDV >= max(1,P) if
195 *> JOBV = 'V'; LDV >= 1 otherwise.
200 *> Q is COMPLEX*16 array, dimension (LDQ,N)
201 *> If JOBQ = 'Q', Q contains the unitary matrix Q.
202 *> If JOBQ = 'N', Q is not referenced.
208 *> The leading dimension of the array Q. LDQ >= max(1,N) if
209 *> JOBQ = 'Q'; LDQ >= 1 otherwise.
214 *> IWORK is INTEGER array, dimension (N)
219 *> RWORK is DOUBLE PRECISION array, dimension (2*N)
224 *> TAU is COMPLEX*16 array, dimension (N)
229 *> WORK is COMPLEX*16 array, dimension (MAX(1,LWORK))
230 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
236 *> The dimension of the array WORK.
238 *> If LWORK = -1, then a workspace query is assumed; the routine
239 *> only calculates the optimal size of the WORK array, returns
240 *> this value as the first entry of the WORK array, and no error
241 *> message related to LWORK is issued by XERBLA.
247 *> = 0: successful exit
248 *> < 0: if INFO = -i, the i-th argument had an illegal value.
254 *> \author Univ. of Tennessee
255 *> \author Univ. of California Berkeley
256 *> \author Univ. of Colorado Denver
261 *> \ingroup complex16OTHERcomputational
263 *> \par Further Details:
264 * =====================
268 *> The subroutine uses LAPACK subroutine ZGEQP3 for the QR factorization
269 *> with column pivoting to detect the effective numerical rank of the
270 *> a matrix. It may be replaced by a better rank determination strategy.
272 *> ZGGSVP3 replaces the deprecated subroutine ZGGSVP.
276 * =====================================================================
277 SUBROUTINE ZGGSVP3( JOBU, JOBV, JOBQ, M, P, N, A, LDA, B, LDB,
278 $ TOLA, TOLB, K, L, U, LDU, V, LDV, Q, LDQ,
279 $ IWORK, RWORK, TAU, WORK, LWORK, INFO )
281 * -- LAPACK computational routine (version 3.6.1) --
282 * -- LAPACK is a software package provided by Univ. of Tennessee, --
283 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
288 * .. Scalar Arguments ..
289 CHARACTER JOBQ, JOBU, JOBV
290 INTEGER INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N, P,
292 DOUBLE PRECISION TOLA, TOLB
294 * .. Array Arguments ..
296 DOUBLE PRECISION RWORK( * )
297 COMPLEX*16 A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
298 $ TAU( * ), U( LDU, * ), V( LDV, * ), WORK( * )
301 * =====================================================================
304 COMPLEX*16 CZERO, CONE
305 PARAMETER ( CZERO = ( 0.0D+0, 0.0D+0 ),
306 $ CONE = ( 1.0D+0, 0.0D+0 ) )
308 * .. Local Scalars ..
309 LOGICAL FORWRD, WANTQ, WANTU, WANTV, LQUERY
312 * .. External Functions ..
316 * .. External Subroutines ..
317 EXTERNAL XERBLA, ZGEQP3, ZGEQR2, ZGERQ2, ZLACPY, ZLAPMT,
318 $ ZLASET, ZUNG2R, ZUNM2R, ZUNMR2
320 * .. Intrinsic Functions ..
321 INTRINSIC ABS, DBLE, DIMAG, MAX, MIN
323 * .. Executable Statements ..
325 * Test the input parameters
327 WANTU = LSAME( JOBU, 'U' )
328 WANTV = LSAME( JOBV, 'V' )
329 WANTQ = LSAME( JOBQ, 'Q' )
331 LQUERY = ( LWORK.EQ.-1 )
334 * Test the input arguments
337 IF( .NOT.( WANTU .OR. LSAME( JOBU, 'N' ) ) ) THEN
339 ELSE IF( .NOT.( WANTV .OR. LSAME( JOBV, 'N' ) ) ) THEN
341 ELSE IF( .NOT.( WANTQ .OR. LSAME( JOBQ, 'N' ) ) ) THEN
343 ELSE IF( M.LT.0 ) THEN
345 ELSE IF( P.LT.0 ) THEN
347 ELSE IF( N.LT.0 ) THEN
349 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
351 ELSE IF( LDB.LT.MAX( 1, P ) ) THEN
353 ELSE IF( LDU.LT.1 .OR. ( WANTU .AND. LDU.LT.M ) ) THEN
355 ELSE IF( LDV.LT.1 .OR. ( WANTV .AND. LDV.LT.P ) ) THEN
357 ELSE IF( LDQ.LT.1 .OR. ( WANTQ .AND. LDQ.LT.N ) ) THEN
359 ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN
366 CALL ZGEQP3( P, N, B, LDB, IWORK, TAU, WORK, -1, RWORK, INFO )
367 LWKOPT = INT( WORK ( 1 ) )
369 LWKOPT = MAX( LWKOPT, P )
371 LWKOPT = MAX( LWKOPT, MIN( N, P ) )
372 LWKOPT = MAX( LWKOPT, M )
374 LWKOPT = MAX( LWKOPT, N )
376 CALL ZGEQP3( M, N, A, LDA, IWORK, TAU, WORK, -1, RWORK, INFO )
377 LWKOPT = MAX( LWKOPT, INT( WORK ( 1 ) ) )
378 LWKOPT = MAX( 1, LWKOPT )
379 WORK( 1 ) = DCMPLX( LWKOPT )
383 CALL XERBLA( 'ZGGSVP3', -INFO )
390 * QR with column pivoting of B: B*P = V*( S11 S12 )
396 CALL ZGEQP3( P, N, B, LDB, IWORK, TAU, WORK, LWORK, RWORK, INFO )
400 CALL ZLAPMT( FORWRD, M, N, A, LDA, IWORK )
402 * Determine the effective rank of matrix B.
405 DO 20 I = 1, MIN( P, N )
406 IF( ABS( B( I, I ) ).GT.TOLB )
412 * Copy the details of V, and form V.
414 CALL ZLASET( 'Full', P, P, CZERO, CZERO, V, LDV )
416 $ CALL ZLACPY( 'Lower', P-1, N, B( 2, 1 ), LDB, V( 2, 1 ),
418 CALL ZUNG2R( P, P, MIN( P, N ), V, LDV, TAU, WORK, INFO )
429 $ CALL ZLASET( 'Full', P-L, N, CZERO, CZERO, B( L+1, 1 ), LDB )
433 * Set Q = I and Update Q := Q*P
435 CALL ZLASET( 'Full', N, N, CZERO, CONE, Q, LDQ )
436 CALL ZLAPMT( FORWRD, N, N, Q, LDQ, IWORK )
439 IF( P.GE.L .AND. N.NE.L ) THEN
441 * RQ factorization of ( S11 S12 ) = ( 0 S12 )*Z
443 CALL ZGERQ2( L, N, B, LDB, TAU, WORK, INFO )
447 CALL ZUNMR2( 'Right', 'Conjugate transpose', M, N, L, B, LDB,
448 $ TAU, A, LDA, WORK, INFO )
453 CALL ZUNMR2( 'Right', 'Conjugate transpose', N, N, L, B,
454 $ LDB, TAU, Q, LDQ, WORK, INFO )
459 CALL ZLASET( 'Full', L, N-L, CZERO, CZERO, B, LDB )
460 DO 60 J = N - L + 1, N
461 DO 50 I = J - N + L + 1, L
471 * then the following does the complete QR decomposition of A11:
473 * A11 = U*( 0 T12 )*P1**H
479 CALL ZGEQP3( M, N-L, A, LDA, IWORK, TAU, WORK, LWORK, RWORK,
482 * Determine the effective rank of A11
485 DO 80 I = 1, MIN( M, N-L )
486 IF( ABS( A( I, I ) ).GT.TOLA )
490 * Update A12 := U**H*A12, where A12 = A( 1:M, N-L+1:N )
492 CALL ZUNM2R( 'Left', 'Conjugate transpose', M, L, MIN( M, N-L ),
493 $ A, LDA, TAU, A( 1, N-L+1 ), LDA, WORK, INFO )
497 * Copy the details of U, and form U
499 CALL ZLASET( 'Full', M, M, CZERO, CZERO, U, LDU )
501 $ CALL ZLACPY( 'Lower', M-1, N-L, A( 2, 1 ), LDA, U( 2, 1 ),
503 CALL ZUNG2R( M, M, MIN( M, N-L ), U, LDU, TAU, WORK, INFO )
508 * Update Q( 1:N, 1:N-L ) = Q( 1:N, 1:N-L )*P1
510 CALL ZLAPMT( FORWRD, N, N-L, Q, LDQ, IWORK )
513 * Clean up A: set the strictly lower triangular part of
514 * A(1:K, 1:K) = 0, and A( K+1:M, 1:N-L ) = 0.
522 $ CALL ZLASET( 'Full', M-K, N-L, CZERO, CZERO, A( K+1, 1 ), LDA )
526 * RQ factorization of ( T11 T12 ) = ( 0 T12 )*Z1
528 CALL ZGERQ2( K, N-L, A, LDA, TAU, WORK, INFO )
532 * Update Q( 1:N,1:N-L ) = Q( 1:N,1:N-L )*Z1**H
534 CALL ZUNMR2( 'Right', 'Conjugate transpose', N, N-L, K, A,
535 $ LDA, TAU, Q, LDQ, WORK, INFO )
540 CALL ZLASET( 'Full', K, N-L-K, CZERO, CZERO, A, LDA )
541 DO 120 J = N - L - K + 1, N - L
542 DO 110 I = J - N + L + K + 1, K
551 * QR factorization of A( K+1:M,N-L+1:N )
553 CALL ZGEQR2( M-K, L, A( K+1, N-L+1 ), LDA, TAU, WORK, INFO )
557 * Update U(:,K+1:M) := U(:,K+1:M)*U1
559 CALL ZUNM2R( 'Right', 'No transpose', M, M-K, MIN( M-K, L ),
560 $ A( K+1, N-L+1 ), LDA, TAU, U( 1, K+1 ), LDU,
566 DO 140 J = N - L + 1, N
567 DO 130 I = J - N + K + L + 1, M
574 WORK( 1 ) = DCMPLX( LWKOPT )