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