3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download SGGSVP3 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sggsvp3.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sggsvp3.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sggsvp3.f">
21 * SUBROUTINE SGGSVP3( JOBU, JOBV, JOBQ, M, P, N, A, LDA, B, LDB,
22 * TOLA, TOLB, K, L, U, LDU, V, LDV, Q, LDQ,
23 * IWORK, 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
30 * .. Array Arguments ..
32 * REAL A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
33 * $ TAU( * ), U( LDU, * ), V( LDV, * ), WORK( * )
42 *> SGGSVP3 computes orthogonal matrices U, V and Q such that
45 *> U**T*A*Q = K ( 0 A12 A13 ) if M-K-L >= 0;
50 *> = K ( 0 A12 A13 ) if M-K-L < 0;
54 *> V**T*B*Q = L ( 0 0 B13 )
57 *> where the K-by-K matrix A12 and L-by-L matrix B13 are nonsingular
58 *> upper triangular; A23 is L-by-L upper triangular if M-K-L >= 0,
59 *> otherwise A23 is (M-K)-by-L upper trapezoidal. K+L = the effective
60 *> numerical rank of the (M+P)-by-N matrix (A**T,B**T)**T.
62 *> This decomposition is the preprocessing step for computing the
63 *> Generalized Singular Value Decomposition (GSVD), see subroutine
72 *> JOBU is CHARACTER*1
73 *> = 'U': Orthogonal matrix U is computed;
74 *> = 'N': U is not computed.
79 *> JOBV is CHARACTER*1
80 *> = 'V': Orthogonal matrix V is computed;
81 *> = 'N': V is not computed.
86 *> JOBQ is CHARACTER*1
87 *> = 'Q': Orthogonal matrix Q is computed;
88 *> = 'N': Q is not computed.
94 *> The number of rows of the matrix A. M >= 0.
100 *> The number of rows of the matrix B. P >= 0.
106 *> The number of columns of the matrices A and B. N >= 0.
111 *> A is REAL array, dimension (LDA,N)
112 *> On entry, the M-by-N matrix A.
113 *> On exit, A contains the triangular (or trapezoidal) matrix
114 *> described in the Purpose section.
120 *> The leading dimension of the array A. LDA >= max(1,M).
125 *> B is REAL array, dimension (LDB,N)
126 *> On entry, the P-by-N matrix B.
127 *> On exit, B contains the triangular matrix described in
128 *> the Purpose section.
134 *> The leading dimension of the array B. LDB >= max(1,P).
146 *> TOLA and TOLB are the thresholds to determine the effective
147 *> numerical rank of matrix B and a subblock of A. Generally,
149 *> TOLA = MAX(M,N)*norm(A)*MACHEPS,
150 *> TOLB = MAX(P,N)*norm(B)*MACHEPS.
151 *> The size of TOLA and TOLB may affect the size of backward
152 *> errors of the decomposition.
164 *> On exit, K and L specify the dimension of the subblocks
165 *> described in Purpose section.
166 *> K + L = effective numerical rank of (A**T,B**T)**T.
171 *> U is REAL array, dimension (LDU,M)
172 *> If JOBU = 'U', U contains the orthogonal matrix U.
173 *> If JOBU = 'N', U is not referenced.
179 *> The leading dimension of the array U. LDU >= max(1,M) if
180 *> JOBU = 'U'; LDU >= 1 otherwise.
185 *> V is REAL array, dimension (LDV,P)
186 *> If JOBV = 'V', V contains the orthogonal matrix V.
187 *> If JOBV = 'N', V is not referenced.
193 *> The leading dimension of the array V. LDV >= max(1,P) if
194 *> JOBV = 'V'; LDV >= 1 otherwise.
199 *> Q is REAL array, dimension (LDQ,N)
200 *> If JOBQ = 'Q', Q contains the orthogonal matrix Q.
201 *> If JOBQ = 'N', Q is not referenced.
207 *> The leading dimension of the array Q. LDQ >= max(1,N) if
208 *> JOBQ = 'Q'; LDQ >= 1 otherwise.
213 *> IWORK is INTEGER array, dimension (N)
218 *> TAU is REAL array, dimension (N)
223 *> WORK is REAL array, dimension (MAX(1,LWORK))
224 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
230 *> The dimension of the array WORK.
232 *> If LWORK = -1, then a workspace query is assumed; the routine
233 *> only calculates the optimal size of the WORK array, returns
234 *> this value as the first entry of the WORK array, and no error
235 *> message related to LWORK is issued by XERBLA.
241 *> = 0: successful exit
242 *> < 0: if INFO = -i, the i-th argument had an illegal value.
248 *> \author Univ. of Tennessee
249 *> \author Univ. of California Berkeley
250 *> \author Univ. of Colorado Denver
255 *> \ingroup realOTHERcomputational
257 *> \par Further Details:
258 * =====================
262 *> The subroutine uses LAPACK subroutine SGEQP3 for the QR factorization
263 *> with column pivoting to detect the effective numerical rank of the
264 *> a matrix. It may be replaced by a better rank determination strategy.
266 *> SGGSVP3 replaces the deprecated subroutine SGGSVP.
270 * =====================================================================
271 SUBROUTINE SGGSVP3( JOBU, JOBV, JOBQ, M, P, N, A, LDA, B, LDB,
272 $ TOLA, TOLB, K, L, U, LDU, V, LDV, Q, LDQ,
273 $ IWORK, TAU, WORK, LWORK, INFO )
275 * -- LAPACK computational routine (version 3.6.1) --
276 * -- LAPACK is a software package provided by Univ. of Tennessee, --
277 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
282 * .. Scalar Arguments ..
283 CHARACTER JOBQ, JOBU, JOBV
284 INTEGER INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N, P,
288 * .. Array Arguments ..
290 REAL A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
291 $ TAU( * ), U( LDU, * ), V( LDV, * ), WORK( * )
294 * =====================================================================
298 PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
300 * .. Local Scalars ..
301 LOGICAL FORWRD, WANTQ, WANTU, WANTV, LQUERY
304 * .. External Functions ..
308 * .. External Subroutines ..
309 EXTERNAL SGEQP3, SGEQR2, SGERQ2, SLACPY, SLAPMT,
310 $ SLASET, SORG2R, SORM2R, SORMR2, XERBLA
312 * .. Intrinsic Functions ..
313 INTRINSIC ABS, MAX, MIN
315 * .. Executable Statements ..
317 * Test the input parameters
319 WANTU = LSAME( JOBU, 'U' )
320 WANTV = LSAME( JOBV, 'V' )
321 WANTQ = LSAME( JOBQ, 'Q' )
323 LQUERY = ( LWORK.EQ.-1 )
326 * Test the input arguments
329 IF( .NOT.( WANTU .OR. LSAME( JOBU, 'N' ) ) ) THEN
331 ELSE IF( .NOT.( WANTV .OR. LSAME( JOBV, 'N' ) ) ) THEN
333 ELSE IF( .NOT.( WANTQ .OR. LSAME( JOBQ, 'N' ) ) ) THEN
335 ELSE IF( M.LT.0 ) THEN
337 ELSE IF( P.LT.0 ) THEN
339 ELSE IF( N.LT.0 ) THEN
341 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
343 ELSE IF( LDB.LT.MAX( 1, P ) ) THEN
345 ELSE IF( LDU.LT.1 .OR. ( WANTU .AND. LDU.LT.M ) ) THEN
347 ELSE IF( LDV.LT.1 .OR. ( WANTV .AND. LDV.LT.P ) ) THEN
349 ELSE IF( LDQ.LT.1 .OR. ( WANTQ .AND. LDQ.LT.N ) ) THEN
351 ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN
358 CALL SGEQP3( P, N, B, LDB, IWORK, TAU, WORK, -1, INFO )
359 LWKOPT = INT( WORK ( 1 ) )
361 LWKOPT = MAX( LWKOPT, P )
363 LWKOPT = MAX( LWKOPT, MIN( N, P ) )
364 LWKOPT = MAX( LWKOPT, M )
366 LWKOPT = MAX( LWKOPT, N )
368 CALL SGEQP3( M, N, A, LDA, IWORK, TAU, WORK, -1, INFO )
369 LWKOPT = MAX( LWKOPT, INT( WORK ( 1 ) ) )
370 LWKOPT = MAX( 1, LWKOPT )
371 WORK( 1 ) = REAL( LWKOPT )
375 CALL XERBLA( 'SGGSVP3', -INFO )
382 * QR with column pivoting of B: B*P = V*( S11 S12 )
388 CALL SGEQP3( P, N, B, LDB, IWORK, TAU, WORK, LWORK, INFO )
392 CALL SLAPMT( FORWRD, M, N, A, LDA, IWORK )
394 * Determine the effective rank of matrix B.
397 DO 20 I = 1, MIN( P, N )
398 IF( ABS( B( I, I ) ).GT.TOLB )
404 * Copy the details of V, and form V.
406 CALL SLASET( 'Full', P, P, ZERO, ZERO, V, LDV )
408 $ CALL SLACPY( 'Lower', P-1, N, B( 2, 1 ), LDB, V( 2, 1 ),
410 CALL SORG2R( P, P, MIN( P, N ), V, LDV, TAU, WORK, INFO )
421 $ CALL SLASET( 'Full', P-L, N, ZERO, ZERO, B( L+1, 1 ), LDB )
425 * Set Q = I and Update Q := Q*P
427 CALL SLASET( 'Full', N, N, ZERO, ONE, Q, LDQ )
428 CALL SLAPMT( FORWRD, N, N, Q, LDQ, IWORK )
431 IF( P.GE.L .AND. N.NE.L ) THEN
433 * RQ factorization of (S11 S12): ( S11 S12 ) = ( 0 S12 )*Z
435 CALL SGERQ2( L, N, B, LDB, TAU, WORK, INFO )
439 CALL SORMR2( 'Right', 'Transpose', M, N, L, B, LDB, TAU, A,
446 CALL SORMR2( 'Right', 'Transpose', N, N, L, B, LDB, TAU, Q,
452 CALL SLASET( 'Full', L, N-L, ZERO, ZERO, B, LDB )
453 DO 60 J = N - L + 1, N
454 DO 50 I = J - N + L + 1, L
464 * then the following does the complete QR decomposition of A11:
466 * A11 = U*( 0 T12 )*P1**T
472 CALL SGEQP3( M, N-L, A, LDA, IWORK, TAU, WORK, LWORK, INFO )
474 * Determine the effective rank of A11
477 DO 80 I = 1, MIN( M, N-L )
478 IF( ABS( A( I, I ) ).GT.TOLA )
482 * Update A12 := U**T*A12, where A12 = A( 1:M, N-L+1:N )
484 CALL SORM2R( 'Left', 'Transpose', M, L, MIN( M, N-L ), A, LDA,
485 $ TAU, A( 1, N-L+1 ), LDA, WORK, INFO )
489 * Copy the details of U, and form U
491 CALL SLASET( 'Full', M, M, ZERO, ZERO, U, LDU )
493 $ CALL SLACPY( 'Lower', M-1, N-L, A( 2, 1 ), LDA, U( 2, 1 ),
495 CALL SORG2R( M, M, MIN( M, N-L ), U, LDU, TAU, WORK, INFO )
500 * Update Q( 1:N, 1:N-L ) = Q( 1:N, 1:N-L )*P1
502 CALL SLAPMT( FORWRD, N, N-L, Q, LDQ, IWORK )
505 * Clean up A: set the strictly lower triangular part of
506 * A(1:K, 1:K) = 0, and A( K+1:M, 1:N-L ) = 0.
514 $ CALL SLASET( 'Full', M-K, N-L, ZERO, ZERO, A( K+1, 1 ), LDA )
518 * RQ factorization of ( T11 T12 ) = ( 0 T12 )*Z1
520 CALL SGERQ2( K, N-L, A, LDA, TAU, WORK, INFO )
524 * Update Q( 1:N,1:N-L ) = Q( 1:N,1:N-L )*Z1**T
526 CALL SORMR2( 'Right', 'Transpose', N, N-L, K, A, LDA, TAU,
527 $ Q, LDQ, WORK, INFO )
532 CALL SLASET( 'Full', K, N-L-K, ZERO, ZERO, A, LDA )
533 DO 120 J = N - L - K + 1, N - L
534 DO 110 I = J - N + L + K + 1, K
543 * QR factorization of A( K+1:M,N-L+1:N )
545 CALL SGEQR2( M-K, L, A( K+1, N-L+1 ), LDA, TAU, WORK, INFO )
549 * Update U(:,K+1:M) := U(:,K+1:M)*U1
551 CALL SORM2R( 'Right', 'No transpose', M, M-K, MIN( M-K, L ),
552 $ A( K+1, N-L+1 ), LDA, TAU, U( 1, K+1 ), LDU,
558 DO 140 J = N - L + 1, N
559 DO 130 I = J - N + K + L + 1, M
566 WORK( 1 ) = REAL( LWKOPT )