LAPACK  3.4.2
LAPACK: Linear Algebra PACKage
 All Files Functions Groups
cggsvd.f
Go to the documentation of this file.
1 *> \brief <b> CGGSVD computes the singular value decomposition (SVD) for OTHER matrices</b>
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 *> \htmlonly
9 *> Download CGGSVD + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cggsvd.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cggsvd.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cggsvd.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 * Definition:
19 * ===========
20 *
21 * SUBROUTINE CGGSVD( JOBU, JOBV, JOBQ, M, N, P, K, L, A, LDA, B,
22 * LDB, ALPHA, BETA, U, LDU, V, LDV, Q, LDQ, WORK,
23 * RWORK, IWORK, INFO )
24 *
25 * .. Scalar Arguments ..
26 * CHARACTER JOBQ, JOBU, JOBV
27 * INTEGER INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N, P
28 * ..
29 * .. Array Arguments ..
30 * INTEGER IWORK( * )
31 * REAL ALPHA( * ), BETA( * ), RWORK( * )
32 * COMPLEX A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
33 * $ U( LDU, * ), V( LDV, * ), WORK( * )
34 * ..
35 *
36 *
37 *> \par Purpose:
38 * =============
39 *>
40 *> \verbatim
41 *>
42 *> CGGSVD computes the generalized singular value decomposition (GSVD)
43 *> of an M-by-N complex matrix A and P-by-N complex matrix B:
44 *>
45 *> U**H*A*Q = D1*( 0 R ), V**H*B*Q = D2*( 0 R )
46 *>
47 *> where U, V and Q are unitary matrices.
48 *> Let K+L = the effective numerical rank of the
49 *> matrix (A**H,B**H)**H, then R is a (K+L)-by-(K+L) nonsingular upper
50 *> triangular matrix, D1 and D2 are M-by-(K+L) and P-by-(K+L) "diagonal"
51 *> matrices and of the following structures, respectively:
52 *>
53 *> If M-K-L >= 0,
54 *>
55 *> K L
56 *> D1 = K ( I 0 )
57 *> L ( 0 C )
58 *> M-K-L ( 0 0 )
59 *>
60 *> K L
61 *> D2 = L ( 0 S )
62 *> P-L ( 0 0 )
63 *>
64 *> N-K-L K L
65 *> ( 0 R ) = K ( 0 R11 R12 )
66 *> L ( 0 0 R22 )
67 *>
68 *> where
69 *>
70 *> C = diag( ALPHA(K+1), ... , ALPHA(K+L) ),
71 *> S = diag( BETA(K+1), ... , BETA(K+L) ),
72 *> C**2 + S**2 = I.
73 *>
74 *> R is stored in A(1:K+L,N-K-L+1:N) on exit.
75 *>
76 *> If M-K-L < 0,
77 *>
78 *> K M-K K+L-M
79 *> D1 = K ( I 0 0 )
80 *> M-K ( 0 C 0 )
81 *>
82 *> K M-K K+L-M
83 *> D2 = M-K ( 0 S 0 )
84 *> K+L-M ( 0 0 I )
85 *> P-L ( 0 0 0 )
86 *>
87 *> N-K-L K M-K K+L-M
88 *> ( 0 R ) = K ( 0 R11 R12 R13 )
89 *> M-K ( 0 0 R22 R23 )
90 *> K+L-M ( 0 0 0 R33 )
91 *>
92 *> where
93 *>
94 *> C = diag( ALPHA(K+1), ... , ALPHA(M) ),
95 *> S = diag( BETA(K+1), ... , BETA(M) ),
96 *> C**2 + S**2 = I.
97 *>
98 *> (R11 R12 R13 ) is stored in A(1:M, N-K-L+1:N), and R33 is stored
99 *> ( 0 R22 R23 )
100 *> in B(M-K+1:L,N+M-K-L+1:N) on exit.
101 *>
102 *> The routine computes C, S, R, and optionally the unitary
103 *> transformation matrices U, V and Q.
104 *>
105 *> In particular, if B is an N-by-N nonsingular matrix, then the GSVD of
106 *> A and B implicitly gives the SVD of A*inv(B):
107 *> A*inv(B) = U*(D1*inv(D2))*V**H.
108 *> If ( A**H,B**H)**H has orthnormal columns, then the GSVD of A and B is also
109 *> equal to the CS decomposition of A and B. Furthermore, the GSVD can
110 *> be used to derive the solution of the eigenvalue problem:
111 *> A**H*A x = lambda* B**H*B x.
112 *> In some literature, the GSVD of A and B is presented in the form
113 *> U**H*A*X = ( 0 D1 ), V**H*B*X = ( 0 D2 )
114 *> where U and V are orthogonal and X is nonsingular, and D1 and D2 are
115 *> ``diagonal''. The former GSVD form can be converted to the latter
116 *> form by taking the nonsingular matrix X as
117 *>
118 *> X = Q*( I 0 )
119 *> ( 0 inv(R) )
120 *> \endverbatim
121 *
122 * Arguments:
123 * ==========
124 *
125 *> \param[in] JOBU
126 *> \verbatim
127 *> JOBU is CHARACTER*1
128 *> = 'U': Unitary matrix U is computed;
129 *> = 'N': U is not computed.
130 *> \endverbatim
131 *>
132 *> \param[in] JOBV
133 *> \verbatim
134 *> JOBV is CHARACTER*1
135 *> = 'V': Unitary matrix V is computed;
136 *> = 'N': V is not computed.
137 *> \endverbatim
138 *>
139 *> \param[in] JOBQ
140 *> \verbatim
141 *> JOBQ is CHARACTER*1
142 *> = 'Q': Unitary matrix Q is computed;
143 *> = 'N': Q is not computed.
144 *> \endverbatim
145 *>
146 *> \param[in] M
147 *> \verbatim
148 *> M is INTEGER
149 *> The number of rows of the matrix A. M >= 0.
150 *> \endverbatim
151 *>
152 *> \param[in] N
153 *> \verbatim
154 *> N is INTEGER
155 *> The number of columns of the matrices A and B. N >= 0.
156 *> \endverbatim
157 *>
158 *> \param[in] P
159 *> \verbatim
160 *> P is INTEGER
161 *> The number of rows of the matrix B. P >= 0.
162 *> \endverbatim
163 *>
164 *> \param[out] K
165 *> \verbatim
166 *> K is INTEGER
167 *> \endverbatim
168 *>
169 *> \param[out] L
170 *> \verbatim
171 *> L is INTEGER
172 *>
173 *> On exit, K and L specify the dimension of the subblocks
174 *> described in Purpose.
175 *> K + L = effective numerical rank of (A**H,B**H)**H.
176 *> \endverbatim
177 *>
178 *> \param[in,out] A
179 *> \verbatim
180 *> A is COMPLEX array, dimension (LDA,N)
181 *> On entry, the M-by-N matrix A.
182 *> On exit, A contains the triangular matrix R, or part of R.
183 *> See Purpose for details.
184 *> \endverbatim
185 *>
186 *> \param[in] LDA
187 *> \verbatim
188 *> LDA is INTEGER
189 *> The leading dimension of the array A. LDA >= max(1,M).
190 *> \endverbatim
191 *>
192 *> \param[in,out] B
193 *> \verbatim
194 *> B is COMPLEX array, dimension (LDB,N)
195 *> On entry, the P-by-N matrix B.
196 *> On exit, B contains part of the triangular matrix R if
197 *> M-K-L < 0. See Purpose for details.
198 *> \endverbatim
199 *>
200 *> \param[in] LDB
201 *> \verbatim
202 *> LDB is INTEGER
203 *> The leading dimension of the array B. LDB >= max(1,P).
204 *> \endverbatim
205 *>
206 *> \param[out] ALPHA
207 *> \verbatim
208 *> ALPHA is REAL array, dimension (N)
209 *> \endverbatim
210 *>
211 *> \param[out] BETA
212 *> \verbatim
213 *> BETA is REAL array, dimension (N)
214 *>
215 *> On exit, ALPHA and BETA contain the generalized singular
216 *> value pairs of A and B;
217 *> ALPHA(1:K) = 1,
218 *> BETA(1:K) = 0,
219 *> and if M-K-L >= 0,
220 *> ALPHA(K+1:K+L) = C,
221 *> BETA(K+1:K+L) = S,
222 *> or if M-K-L < 0,
223 *> ALPHA(K+1:M)=C, ALPHA(M+1:K+L)=0
224 *> BETA(K+1:M) =S, BETA(M+1:K+L) =1
225 *> and
226 *> ALPHA(K+L+1:N) = 0
227 *> BETA(K+L+1:N) = 0
228 *> \endverbatim
229 *>
230 *> \param[out] U
231 *> \verbatim
232 *> U is COMPLEX array, dimension (LDU,M)
233 *> If JOBU = 'U', U contains the M-by-M unitary matrix U.
234 *> If JOBU = 'N', U is not referenced.
235 *> \endverbatim
236 *>
237 *> \param[in] LDU
238 *> \verbatim
239 *> LDU is INTEGER
240 *> The leading dimension of the array U. LDU >= max(1,M) if
241 *> JOBU = 'U'; LDU >= 1 otherwise.
242 *> \endverbatim
243 *>
244 *> \param[out] V
245 *> \verbatim
246 *> V is COMPLEX array, dimension (LDV,P)
247 *> If JOBV = 'V', V contains the P-by-P unitary matrix V.
248 *> If JOBV = 'N', V is not referenced.
249 *> \endverbatim
250 *>
251 *> \param[in] LDV
252 *> \verbatim
253 *> LDV is INTEGER
254 *> The leading dimension of the array V. LDV >= max(1,P) if
255 *> JOBV = 'V'; LDV >= 1 otherwise.
256 *> \endverbatim
257 *>
258 *> \param[out] Q
259 *> \verbatim
260 *> Q is COMPLEX array, dimension (LDQ,N)
261 *> If JOBQ = 'Q', Q contains the N-by-N unitary matrix Q.
262 *> If JOBQ = 'N', Q is not referenced.
263 *> \endverbatim
264 *>
265 *> \param[in] LDQ
266 *> \verbatim
267 *> LDQ is INTEGER
268 *> The leading dimension of the array Q. LDQ >= max(1,N) if
269 *> JOBQ = 'Q'; LDQ >= 1 otherwise.
270 *> \endverbatim
271 *>
272 *> \param[out] WORK
273 *> \verbatim
274 *> WORK is COMPLEX array, dimension (max(3*N,M,P)+N)
275 *> \endverbatim
276 *>
277 *> \param[out] RWORK
278 *> \verbatim
279 *> RWORK is REAL array, dimension (2*N)
280 *> \endverbatim
281 *>
282 *> \param[out] IWORK
283 *> \verbatim
284 *> IWORK is INTEGER array, dimension (N)
285 *> On exit, IWORK stores the sorting information. More
286 *> precisely, the following loop will sort ALPHA
287 *> for I = K+1, min(M,K+L)
288 *> swap ALPHA(I) and ALPHA(IWORK(I))
289 *> endfor
290 *> such that ALPHA(1) >= ALPHA(2) >= ... >= ALPHA(N).
291 *> \endverbatim
292 *>
293 *> \param[out] INFO
294 *> \verbatim
295 *> INFO is INTEGER
296 *> = 0: successful exit.
297 *> < 0: if INFO = -i, the i-th argument had an illegal value.
298 *> > 0: if INFO = 1, the Jacobi-type procedure failed to
299 *> converge. For further details, see subroutine CTGSJA.
300 *> \endverbatim
301 *
302 *> \par Internal Parameters:
303 * =========================
304 *>
305 *> \verbatim
306 *> TOLA REAL
307 *> TOLB REAL
308 *> TOLA and TOLB are the thresholds to determine the effective
309 *> rank of (A**H,B**H)**H. Generally, they are set to
310 *> TOLA = MAX(M,N)*norm(A)*MACHEPS,
311 *> TOLB = MAX(P,N)*norm(B)*MACHEPS.
312 *> The size of TOLA and TOLB may affect the size of backward
313 *> errors of the decomposition.
314 *> \endverbatim
315 *
316 * Authors:
317 * ========
318 *
319 *> \author Univ. of Tennessee
320 *> \author Univ. of California Berkeley
321 *> \author Univ. of Colorado Denver
322 *> \author NAG Ltd.
323 *
324 *> \date November 2011
325 *
326 *> \ingroup complexOTHERsing
327 *
328 *> \par Contributors:
329 * ==================
330 *>
331 *> Ming Gu and Huan Ren, Computer Science Division, University of
332 *> California at Berkeley, USA
333 *>
334 * =====================================================================
335  SUBROUTINE cggsvd( JOBU, JOBV, JOBQ, M, N, P, K, L, A, LDA, B,
336  $ ldb, alpha, beta, u, ldu, v, ldv, q, ldq, work,
337  $ rwork, iwork, info )
338 *
339 * -- LAPACK driver routine (version 3.4.0) --
340 * -- LAPACK is a software package provided by Univ. of Tennessee, --
341 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
342 * November 2011
343 *
344 * .. Scalar Arguments ..
345  CHARACTER jobq, jobu, jobv
346  INTEGER info, k, l, lda, ldb, ldq, ldu, ldv, m, n, p
347 * ..
348 * .. Array Arguments ..
349  INTEGER iwork( * )
350  REAL alpha( * ), beta( * ), rwork( * )
351  COMPLEX a( lda, * ), b( ldb, * ), q( ldq, * ),
352  $ u( ldu, * ), v( ldv, * ), work( * )
353 * ..
354 *
355 * =====================================================================
356 *
357 * .. Local Scalars ..
358  LOGICAL wantq, wantu, wantv
359  INTEGER i, ibnd, isub, j, ncycle
360  REAL anorm, bnorm, smax, temp, tola, tolb, ulp, unfl
361 * ..
362 * .. External Functions ..
363  LOGICAL lsame
364  REAL clange, slamch
365  EXTERNAL lsame, clange, slamch
366 * ..
367 * .. External Subroutines ..
368  EXTERNAL cggsvp, ctgsja, scopy, xerbla
369 * ..
370 * .. Intrinsic Functions ..
371  INTRINSIC max, min
372 * ..
373 * .. Executable Statements ..
374 *
375 * Decode and test the input parameters
376 *
377  wantu = lsame( jobu, 'U' )
378  wantv = lsame( jobv, 'V' )
379  wantq = lsame( jobq, 'Q' )
380 *
381  info = 0
382  IF( .NOT.( wantu .OR. lsame( jobu, 'N' ) ) ) THEN
383  info = -1
384  ELSE IF( .NOT.( wantv .OR. lsame( jobv, 'N' ) ) ) THEN
385  info = -2
386  ELSE IF( .NOT.( wantq .OR. lsame( jobq, 'N' ) ) ) THEN
387  info = -3
388  ELSE IF( m.LT.0 ) THEN
389  info = -4
390  ELSE IF( n.LT.0 ) THEN
391  info = -5
392  ELSE IF( p.LT.0 ) THEN
393  info = -6
394  ELSE IF( lda.LT.max( 1, m ) ) THEN
395  info = -10
396  ELSE IF( ldb.LT.max( 1, p ) ) THEN
397  info = -12
398  ELSE IF( ldu.LT.1 .OR. ( wantu .AND. ldu.LT.m ) ) THEN
399  info = -16
400  ELSE IF( ldv.LT.1 .OR. ( wantv .AND. ldv.LT.p ) ) THEN
401  info = -18
402  ELSE IF( ldq.LT.1 .OR. ( wantq .AND. ldq.LT.n ) ) THEN
403  info = -20
404  END IF
405  IF( info.NE.0 ) THEN
406  CALL xerbla( 'CGGSVD', -info )
407  return
408  END IF
409 *
410 * Compute the Frobenius norm of matrices A and B
411 *
412  anorm = clange( '1', m, n, a, lda, rwork )
413  bnorm = clange( '1', p, n, b, ldb, rwork )
414 *
415 * Get machine precision and set up threshold for determining
416 * the effective numerical rank of the matrices A and B.
417 *
418  ulp = slamch( 'Precision' )
419  unfl = slamch( 'Safe Minimum' )
420  tola = max( m, n )*max( anorm, unfl )*ulp
421  tolb = max( p, n )*max( bnorm, unfl )*ulp
422 *
423  CALL cggsvp( jobu, jobv, jobq, m, p, n, a, lda, b, ldb, tola,
424  $ tolb, k, l, u, ldu, v, ldv, q, ldq, iwork, rwork,
425  $ work, work( n+1 ), info )
426 *
427 * Compute the GSVD of two upper "triangular" matrices
428 *
429  CALL ctgsja( jobu, jobv, jobq, m, p, n, k, l, a, lda, b, ldb,
430  $ tola, tolb, alpha, beta, u, ldu, v, ldv, q, ldq,
431  $ work, ncycle, info )
432 *
433 * Sort the singular values and store the pivot indices in IWORK
434 * Copy ALPHA to RWORK, then sort ALPHA in RWORK
435 *
436  CALL scopy( n, alpha, 1, rwork, 1 )
437  ibnd = min( l, m-k )
438  DO 20 i = 1, ibnd
439 *
440 * Scan for largest ALPHA(K+I)
441 *
442  isub = i
443  smax = rwork( k+i )
444  DO 10 j = i + 1, ibnd
445  temp = rwork( k+j )
446  IF( temp.GT.smax ) THEN
447  isub = j
448  smax = temp
449  END IF
450  10 continue
451  IF( isub.NE.i ) THEN
452  rwork( k+isub ) = rwork( k+i )
453  rwork( k+i ) = smax
454  iwork( k+i ) = k + isub
455  ELSE
456  iwork( k+i ) = k + i
457  END IF
458  20 continue
459 *
460  return
461 *
462 * End of CGGSVD
463 *
464  END