LAPACK  3.6.1 LAPACK: Linear Algebra PACKage
dggsvp3.f
Go to the documentation of this file.
1 *> \brief \b DGGSVP3
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 *> \htmlonly
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dggsvp3.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dggsvp3.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dggsvp3.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 * Definition:
19 * ===========
20 *
21 * SUBROUTINE DGGSVP3( 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 )
24 *
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
29 * ..
30 * .. Array Arguments ..
31 * INTEGER IWORK( * )
32 * DOUBLE PRECISION A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
33 * \$ TAU( * ), U( LDU, * ), V( LDV, * ), WORK( * )
34 * ..
35 *
36 *
37 *> \par Purpose:
38 * =============
39 *>
40 *> \verbatim
41 *>
42 *> DGGSVP3 computes orthogonal matrices U, V and Q such that
43 *>
44 *> N-K-L K L
45 *> U**T*A*Q = K ( 0 A12 A13 ) if M-K-L >= 0;
46 *> L ( 0 0 A23 )
47 *> M-K-L ( 0 0 0 )
48 *>
49 *> N-K-L K L
50 *> = K ( 0 A12 A13 ) if M-K-L < 0;
51 *> M-K ( 0 0 A23 )
52 *>
53 *> N-K-L K L
54 *> V**T*B*Q = L ( 0 0 B13 )
55 *> P-L ( 0 0 0 )
56 *>
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.
61 *>
62 *> This decomposition is the preprocessing step for computing the
63 *> Generalized Singular Value Decomposition (GSVD), see subroutine
64 *> DGGSVD3.
65 *> \endverbatim
66 *
67 * Arguments:
68 * ==========
69 *
70 *> \param[in] JOBU
71 *> \verbatim
72 *> JOBU is CHARACTER*1
73 *> = 'U': Orthogonal matrix U is computed;
74 *> = 'N': U is not computed.
75 *> \endverbatim
76 *>
77 *> \param[in] JOBV
78 *> \verbatim
79 *> JOBV is CHARACTER*1
80 *> = 'V': Orthogonal matrix V is computed;
81 *> = 'N': V is not computed.
82 *> \endverbatim
83 *>
84 *> \param[in] JOBQ
85 *> \verbatim
86 *> JOBQ is CHARACTER*1
87 *> = 'Q': Orthogonal matrix Q is computed;
88 *> = 'N': Q is not computed.
89 *> \endverbatim
90 *>
91 *> \param[in] M
92 *> \verbatim
93 *> M is INTEGER
94 *> The number of rows of the matrix A. M >= 0.
95 *> \endverbatim
96 *>
97 *> \param[in] P
98 *> \verbatim
99 *> P is INTEGER
100 *> The number of rows of the matrix B. P >= 0.
101 *> \endverbatim
102 *>
103 *> \param[in] N
104 *> \verbatim
105 *> N is INTEGER
106 *> The number of columns of the matrices A and B. N >= 0.
107 *> \endverbatim
108 *>
109 *> \param[in,out] A
110 *> \verbatim
111 *> A is DOUBLE PRECISION 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.
115 *> \endverbatim
116 *>
117 *> \param[in] LDA
118 *> \verbatim
119 *> LDA is INTEGER
120 *> The leading dimension of the array A. LDA >= max(1,M).
121 *> \endverbatim
122 *>
123 *> \param[in,out] B
124 *> \verbatim
125 *> B is DOUBLE PRECISION 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.
129 *> \endverbatim
130 *>
131 *> \param[in] LDB
132 *> \verbatim
133 *> LDB is INTEGER
134 *> The leading dimension of the array B. LDB >= max(1,P).
135 *> \endverbatim
136 *>
137 *> \param[in] TOLA
138 *> \verbatim
139 *> TOLA is DOUBLE PRECISION
140 *> \endverbatim
141 *>
142 *> \param[in] TOLB
143 *> \verbatim
144 *> TOLB is DOUBLE PRECISION
145 *>
146 *> TOLA and TOLB are the thresholds to determine the effective
147 *> numerical rank of matrix B and a subblock of A. Generally,
148 *> they are set to
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.
153 *> \endverbatim
154 *>
155 *> \param[out] K
156 *> \verbatim
157 *> K is INTEGER
158 *> \endverbatim
159 *>
160 *> \param[out] L
161 *> \verbatim
162 *> L is INTEGER
163 *>
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.
167 *> \endverbatim
168 *>
169 *> \param[out] U
170 *> \verbatim
171 *> U is DOUBLE PRECISION array, dimension (LDU,M)
172 *> If JOBU = 'U', U contains the orthogonal matrix U.
173 *> If JOBU = 'N', U is not referenced.
174 *> \endverbatim
175 *>
176 *> \param[in] LDU
177 *> \verbatim
178 *> LDU is INTEGER
179 *> The leading dimension of the array U. LDU >= max(1,M) if
180 *> JOBU = 'U'; LDU >= 1 otherwise.
181 *> \endverbatim
182 *>
183 *> \param[out] V
184 *> \verbatim
185 *> V is DOUBLE PRECISION array, dimension (LDV,P)
186 *> If JOBV = 'V', V contains the orthogonal matrix V.
187 *> If JOBV = 'N', V is not referenced.
188 *> \endverbatim
189 *>
190 *> \param[in] LDV
191 *> \verbatim
192 *> LDV is INTEGER
193 *> The leading dimension of the array V. LDV >= max(1,P) if
194 *> JOBV = 'V'; LDV >= 1 otherwise.
195 *> \endverbatim
196 *>
197 *> \param[out] Q
198 *> \verbatim
199 *> Q is DOUBLE PRECISION array, dimension (LDQ,N)
200 *> If JOBQ = 'Q', Q contains the orthogonal matrix Q.
201 *> If JOBQ = 'N', Q is not referenced.
202 *> \endverbatim
203 *>
204 *> \param[in] LDQ
205 *> \verbatim
206 *> LDQ is INTEGER
207 *> The leading dimension of the array Q. LDQ >= max(1,N) if
208 *> JOBQ = 'Q'; LDQ >= 1 otherwise.
209 *> \endverbatim
210 *>
211 *> \param[out] IWORK
212 *> \verbatim
213 *> IWORK is INTEGER array, dimension (N)
214 *> \endverbatim
215 *>
216 *> \param[out] TAU
217 *> \verbatim
218 *> TAU is DOUBLE PRECISION array, dimension (N)
219 *> \endverbatim
220 *>
221 *> \param[out] WORK
222 *> \verbatim
223 *> WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK))
224 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
225 *> \endverbatim
226 *>
227 *> \param[in] LWORK
228 *> \verbatim
229 *> LWORK is INTEGER
230 *> The dimension of the array WORK.
231 *>
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.
236 *> \endverbatim
237 *>
238 *> \param[out] INFO
239 *> \verbatim
240 *> INFO is INTEGER
241 *> = 0: successful exit
242 *> < 0: if INFO = -i, the i-th argument had an illegal value.
243 *> \endverbatim
244 *
245 * Authors:
246 * ========
247 *
248 *> \author Univ. of Tennessee
249 *> \author Univ. of California Berkeley
250 *> \author Univ. of Colorado Denver
251 *> \author NAG Ltd.
252 *
253 *> \date August 2015
254 *
255 *> \ingroup doubleOTHERcomputational
256 *
257 *> \par Further Details:
258 * =====================
259 *>
260 *> \verbatim
261 *>
262 *> The subroutine uses LAPACK subroutine DGEQP3 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.
265 *>
266 *> DGGSVP3 replaces the deprecated subroutine DGGSVP.
267 *>
268 *> \endverbatim
269 *>
270 * =====================================================================
271  SUBROUTINE dggsvp3( 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 )
274 *
275 * -- LAPACK computational routine (version 3.6.0) --
276 * -- LAPACK is a software package provided by Univ. of Tennessee, --
277 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
278 * August 2015
279 *
280  IMPLICIT NONE
281 *
282 * .. Scalar Arguments ..
283  CHARACTER JOBQ, JOBU, JOBV
284  INTEGER INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N, P,
285  \$ lwork
286  DOUBLE PRECISION TOLA, TOLB
287 * ..
288 * .. Array Arguments ..
289  INTEGER IWORK( * )
290  DOUBLE PRECISION A( lda, * ), B( ldb, * ), Q( ldq, * ),
291  \$ tau( * ), u( ldu, * ), v( ldv, * ), work( * )
292 * ..
293 *
294 * =====================================================================
295 *
296 * .. Parameters ..
297  DOUBLE PRECISION ZERO, ONE
298  parameter ( zero = 0.0d+0, one = 1.0d+0 )
299 * ..
300 * .. Local Scalars ..
301  LOGICAL FORWRD, WANTQ, WANTU, WANTV, LQUERY
302  INTEGER I, J, LWKOPT
303 * ..
304 * .. External Functions ..
305  LOGICAL LSAME
306  EXTERNAL lsame
307 * ..
308 * .. External Subroutines ..
309  EXTERNAL dgeqp3, dgeqr2, dgerq2, dlacpy, dlapmt,
311 * ..
312 * .. Intrinsic Functions ..
313  INTRINSIC abs, max, min
314 * ..
315 * .. Executable Statements ..
316 *
317 * Test the input parameters
318 *
319  wantu = lsame( jobu, 'U' )
320  wantv = lsame( jobv, 'V' )
321  wantq = lsame( jobq, 'Q' )
322  forwrd = .true.
323  lquery = ( lwork.EQ.-1 )
324  lwkopt = 1
325 *
326 * Test the input arguments
327 *
328  info = 0
329  IF( .NOT.( wantu .OR. lsame( jobu, 'N' ) ) ) THEN
330  info = -1
331  ELSE IF( .NOT.( wantv .OR. lsame( jobv, 'N' ) ) ) THEN
332  info = -2
333  ELSE IF( .NOT.( wantq .OR. lsame( jobq, 'N' ) ) ) THEN
334  info = -3
335  ELSE IF( m.LT.0 ) THEN
336  info = -4
337  ELSE IF( p.LT.0 ) THEN
338  info = -5
339  ELSE IF( n.LT.0 ) THEN
340  info = -6
341  ELSE IF( lda.LT.max( 1, m ) ) THEN
342  info = -8
343  ELSE IF( ldb.LT.max( 1, p ) ) THEN
344  info = -10
345  ELSE IF( ldu.LT.1 .OR. ( wantu .AND. ldu.LT.m ) ) THEN
346  info = -16
347  ELSE IF( ldv.LT.1 .OR. ( wantv .AND. ldv.LT.p ) ) THEN
348  info = -18
349  ELSE IF( ldq.LT.1 .OR. ( wantq .AND. ldq.LT.n ) ) THEN
350  info = -20
351  ELSE IF( lwork.LT.1 .AND. .NOT.lquery ) THEN
352  info = -24
353  END IF
354 *
355 * Compute workspace
356 *
357  IF( info.EQ.0 ) THEN
358  CALL dgeqp3( p, n, b, ldb, iwork, tau, work, -1, info )
359  lwkopt = int( work( 1 ) )
360  IF( wantv ) THEN
361  lwkopt = max( lwkopt, p )
362  END IF
363  lwkopt = max( lwkopt, min( n, p ) )
364  lwkopt = max( lwkopt, m )
365  IF( wantq ) THEN
366  lwkopt = max( lwkopt, n )
367  END IF
368  CALL dgeqp3( m, n, a, lda, iwork, tau, work, -1, info )
369  lwkopt = max( lwkopt, int( work( 1 ) ) )
370  lwkopt = max( 1, lwkopt )
371  work( 1 ) = dble( lwkopt )
372  END IF
373 *
374  IF( info.NE.0 ) THEN
375  CALL xerbla( 'DGGSVP3', -info )
376  RETURN
377  END IF
378  IF( lquery ) THEN
379  RETURN
380  ENDIF
381 *
382 * QR with column pivoting of B: B*P = V*( S11 S12 )
383 * ( 0 0 )
384 *
385  DO 10 i = 1, n
386  iwork( i ) = 0
387  10 CONTINUE
388  CALL dgeqp3( p, n, b, ldb, iwork, tau, work, lwork, info )
389 *
390 * Update A := A*P
391 *
392  CALL dlapmt( forwrd, m, n, a, lda, iwork )
393 *
394 * Determine the effective rank of matrix B.
395 *
396  l = 0
397  DO 20 i = 1, min( p, n )
398  IF( abs( b( i, i ) ).GT.tolb )
399  \$ l = l + 1
400  20 CONTINUE
401 *
402  IF( wantv ) THEN
403 *
404 * Copy the details of V, and form V.
405 *
406  CALL dlaset( 'Full', p, p, zero, zero, v, ldv )
407  IF( p.GT.1 )
408  \$ CALL dlacpy( 'Lower', p-1, n, b( 2, 1 ), ldb, v( 2, 1 ),
409  \$ ldv )
410  CALL dorg2r( p, p, min( p, n ), v, ldv, tau, work, info )
411  END IF
412 *
413 * Clean up B
414 *
415  DO 40 j = 1, l - 1
416  DO 30 i = j + 1, l
417  b( i, j ) = zero
418  30 CONTINUE
419  40 CONTINUE
420  IF( p.GT.l )
421  \$ CALL dlaset( 'Full', p-l, n, zero, zero, b( l+1, 1 ), ldb )
422 *
423  IF( wantq ) THEN
424 *
425 * Set Q = I and Update Q := Q*P
426 *
427  CALL dlaset( 'Full', n, n, zero, one, q, ldq )
428  CALL dlapmt( forwrd, n, n, q, ldq, iwork )
429  END IF
430 *
431  IF( p.GE.l .AND. n.NE.l ) THEN
432 *
433 * RQ factorization of (S11 S12): ( S11 S12 ) = ( 0 S12 )*Z
434 *
435  CALL dgerq2( l, n, b, ldb, tau, work, info )
436 *
437 * Update A := A*Z**T
438 *
439  CALL dormr2( 'Right', 'Transpose', m, n, l, b, ldb, tau, a,
440  \$ lda, work, info )
441 *
442  IF( wantq ) THEN
443 *
444 * Update Q := Q*Z**T
445 *
446  CALL dormr2( 'Right', 'Transpose', n, n, l, b, ldb, tau, q,
447  \$ ldq, work, info )
448  END IF
449 *
450 * Clean up B
451 *
452  CALL dlaset( '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
455  b( i, j ) = zero
456  50 CONTINUE
457  60 CONTINUE
458 *
459  END IF
460 *
461 * Let N-L L
462 * A = ( A11 A12 ) M,
463 *
464 * then the following does the complete QR decomposition of A11:
465 *
466 * A11 = U*( 0 T12 )*P1**T
467 * ( 0 0 )
468 *
469  DO 70 i = 1, n - l
470  iwork( i ) = 0
471  70 CONTINUE
472  CALL dgeqp3( m, n-l, a, lda, iwork, tau, work, lwork, info )
473 *
474 * Determine the effective rank of A11
475 *
476  k = 0
477  DO 80 i = 1, min( m, n-l )
478  IF( abs( a( i, i ) ).GT.tola )
479  \$ k = k + 1
480  80 CONTINUE
481 *
482 * Update A12 := U**T*A12, where A12 = A( 1:M, N-L+1:N )
483 *
484  CALL dorm2r( 'Left', 'Transpose', m, l, min( m, n-l ), a, lda,
485  \$ tau, a( 1, n-l+1 ), lda, work, info )
486 *
487  IF( wantu ) THEN
488 *
489 * Copy the details of U, and form U
490 *
491  CALL dlaset( 'Full', m, m, zero, zero, u, ldu )
492  IF( m.GT.1 )
493  \$ CALL dlacpy( 'Lower', m-1, n-l, a( 2, 1 ), lda, u( 2, 1 ),
494  \$ ldu )
495  CALL dorg2r( m, m, min( m, n-l ), u, ldu, tau, work, info )
496  END IF
497 *
498  IF( wantq ) THEN
499 *
500 * Update Q( 1:N, 1:N-L ) = Q( 1:N, 1:N-L )*P1
501 *
502  CALL dlapmt( forwrd, n, n-l, q, ldq, iwork )
503  END IF
504 *
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.
507 *
508  DO 100 j = 1, k - 1
509  DO 90 i = j + 1, k
510  a( i, j ) = zero
511  90 CONTINUE
512  100 CONTINUE
513  IF( m.GT.k )
514  \$ CALL dlaset( 'Full', m-k, n-l, zero, zero, a( k+1, 1 ), lda )
515 *
516  IF( n-l.GT.k ) THEN
517 *
518 * RQ factorization of ( T11 T12 ) = ( 0 T12 )*Z1
519 *
520  CALL dgerq2( k, n-l, a, lda, tau, work, info )
521 *
522  IF( wantq ) THEN
523 *
524 * Update Q( 1:N,1:N-L ) = Q( 1:N,1:N-L )*Z1**T
525 *
526  CALL dormr2( 'Right', 'Transpose', n, n-l, k, a, lda, tau,
527  \$ q, ldq, work, info )
528  END IF
529 *
530 * Clean up A
531 *
532  CALL dlaset( '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
535  a( i, j ) = zero
536  110 CONTINUE
537  120 CONTINUE
538 *
539  END IF
540 *
541  IF( m.GT.k ) THEN
542 *
543 * QR factorization of A( K+1:M,N-L+1:N )
544 *
545  CALL dgeqr2( m-k, l, a( k+1, n-l+1 ), lda, tau, work, info )
546 *
547  IF( wantu ) THEN
548 *
549 * Update U(:,K+1:M) := U(:,K+1:M)*U1
550 *
551  CALL dorm2r( 'Right', 'No transpose', m, m-k, min( m-k, l ),
552  \$ a( k+1, n-l+1 ), lda, tau, u( 1, k+1 ), ldu,
553  \$ work, info )
554  END IF
555 *
556 * Clean up
557 *
558  DO 140 j = n - l + 1, n
559  DO 130 i = j - n + k + l + 1, m
560  a( i, j ) = zero
561  130 CONTINUE
562  140 CONTINUE
563 *
564  END IF
565 *
566  work( 1 ) = dble( lwkopt )
567  RETURN
568 *
569 * End of DGGSVP3
570 *
571  END
subroutine dlaset(UPLO, M, N, ALPHA, BETA, A, LDA)
DLASET initializes the off-diagonal elements and the diagonal elements of a matrix to given values...
Definition: dlaset.f:112
subroutine dgerq2(M, N, A, LDA, TAU, WORK, INFO)
DGERQ2 computes the RQ factorization of a general rectangular matrix using an unblocked algorithm...
Definition: dgerq2.f:125
subroutine dgeqp3(M, N, A, LDA, JPVT, TAU, WORK, LWORK, INFO)
DGEQP3
Definition: dgeqp3.f:153
subroutine dgeqr2(M, N, A, LDA, TAU, WORK, INFO)
DGEQR2 computes the QR factorization of a general rectangular matrix using an unblocked algorithm...
Definition: dgeqr2.f:123
subroutine dlacpy(UPLO, M, N, A, LDA, B, LDB)
DLACPY copies all or part of one two-dimensional array to another.
Definition: dlacpy.f:105
subroutine dlapmt(FORWRD, M, N, X, LDX, K)
DLAPMT performs a forward or backward permutation of the columns of a matrix.
Definition: dlapmt.f:106
subroutine xerbla(SRNAME, INFO)
XERBLA
Definition: xerbla.f:62
subroutine dormr2(SIDE, TRANS, M, N, K, A, LDA, TAU, C, LDC, WORK, INFO)
DORMR2 multiplies a general matrix by the orthogonal matrix from a RQ factorization determined by sge...
Definition: dormr2.f:161
subroutine dorm2r(SIDE, TRANS, M, N, K, A, LDA, TAU, C, LDC, WORK, INFO)
DORM2R multiplies a general matrix by the orthogonal matrix from a QR factorization determined by sge...
Definition: dorm2r.f:161
subroutine dorg2r(M, N, K, A, LDA, TAU, WORK, INFO)
DORG2R generates all or part of the orthogonal matrix Q from a QR factorization determined by sgeqrf ...
Definition: dorg2r.f:116
subroutine dggsvp3(JOBU, JOBV, JOBQ, M, P, N, A, LDA, B, LDB, TOLA, TOLB, K, L, U, LDU, V, LDV, Q, LDQ, IWORK, TAU, WORK, LWORK, INFO)
DGGSVP3
Definition: dggsvp3.f:274