3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CUNCSD + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cuncsd.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cuncsd.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cuncsd.f">
21 * RECURSIVE SUBROUTINE CUNCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS,
22 * SIGNS, M, P, Q, X11, LDX11, X12,
23 * LDX12, X21, LDX21, X22, LDX22, THETA,
24 * U1, LDU1, U2, LDU2, V1T, LDV1T, V2T,
25 * LDV2T, WORK, LWORK, RWORK, LRWORK,
28 * .. Scalar Arguments ..
29 * CHARACTER JOBU1, JOBU2, JOBV1T, JOBV2T, SIGNS, TRANS
30 * INTEGER INFO, LDU1, LDU2, LDV1T, LDV2T, LDX11, LDX12,
31 * $ LDX21, LDX22, LRWORK, LWORK, M, P, Q
33 * .. Array Arguments ..
37 * COMPLEX U1( LDU1, * ), U2( LDU2, * ), V1T( LDV1T, * ),
38 * $ V2T( LDV2T, * ), WORK( * ), X11( LDX11, * ),
39 * $ X12( LDX12, * ), X21( LDX21, * ), X22( LDX22,
49 *> CUNCSD computes the CS decomposition of an M-by-M partitioned
54 *> [ X11 | X12 ] [ U1 | ] [ 0 0 0 | 0 0 -I ] [ V1 | ]**H
55 *> X = [-----------] = [---------] [---------------------] [---------] .
56 *> [ X21 | X22 ] [ | U2 ] [ 0 0 0 | I 0 0 ] [ | V2 ]
60 *> X11 is P-by-Q. The unitary matrices U1, U2, V1, and V2 are P-by-P,
61 *> (M-P)-by-(M-P), Q-by-Q, and (M-Q)-by-(M-Q), respectively. C and S are
62 *> R-by-R nonnegative diagonal matrices satisfying C^2 + S^2 = I, in
63 *> which R = MIN(P,M-P,Q,M-Q).
72 *> = 'Y': U1 is computed;
73 *> otherwise: U1 is not computed.
79 *> = 'Y': U2 is computed;
80 *> otherwise: U2 is not computed.
85 *> JOBV1T is CHARACTER
86 *> = 'Y': V1T is computed;
87 *> otherwise: V1T is not computed.
92 *> JOBV2T is CHARACTER
93 *> = 'Y': V2T is computed;
94 *> otherwise: V2T is not computed.
100 *> = 'T': X, U1, U2, V1T, and V2T are stored in row-major
102 *> otherwise: X, U1, U2, V1T, and V2T are stored in column-
108 *> SIGNS is CHARACTER
109 *> = 'O': The lower-left block is made nonpositive (the
110 *> "other" convention);
111 *> otherwise: The upper-right block is made nonpositive (the
112 *> "default" convention).
118 *> The number of rows and columns in X.
124 *> The number of rows in X11 and X12. 0 <= P <= M.
130 *> The number of columns in X11 and X21. 0 <= Q <= M.
133 *> \param[in,out] X11
135 *> X11 is COMPLEX array, dimension (LDX11,Q)
136 *> On entry, part of the unitary matrix whose CSD is desired.
142 *> The leading dimension of X11. LDX11 >= MAX(1,P).
145 *> \param[in,out] X12
147 *> X12 is COMPLEX array, dimension (LDX12,M-Q)
148 *> On entry, part of the unitary matrix whose CSD is desired.
154 *> The leading dimension of X12. LDX12 >= MAX(1,P).
157 *> \param[in,out] X21
159 *> X21 is COMPLEX array, dimension (LDX21,Q)
160 *> On entry, part of the unitary matrix whose CSD is desired.
166 *> The leading dimension of X11. LDX21 >= MAX(1,M-P).
169 *> \param[in,out] X22
171 *> X22 is COMPLEX array, dimension (LDX22,M-Q)
172 *> On entry, part of the unitary matrix whose CSD is desired.
178 *> The leading dimension of X11. LDX22 >= MAX(1,M-P).
183 *> THETA is REAL array, dimension (R), in which R =
185 *> C = DIAG( COS(THETA(1)), ... , COS(THETA(R)) ) and
186 *> S = DIAG( SIN(THETA(1)), ... , SIN(THETA(R)) ).
191 *> U1 is COMPLEX array, dimension (P)
192 *> If JOBU1 = 'Y', U1 contains the P-by-P unitary matrix U1.
198 *> The leading dimension of U1. If JOBU1 = 'Y', LDU1 >=
204 *> U2 is COMPLEX array, dimension (M-P)
205 *> If JOBU2 = 'Y', U2 contains the (M-P)-by-(M-P) unitary
212 *> The leading dimension of U2. If JOBU2 = 'Y', LDU2 >=
218 *> V1T is COMPLEX array, dimension (Q)
219 *> If JOBV1T = 'Y', V1T contains the Q-by-Q matrix unitary
226 *> The leading dimension of V1T. If JOBV1T = 'Y', LDV1T >=
232 *> V2T is COMPLEX array, dimension (M-Q)
233 *> If JOBV2T = 'Y', V2T contains the (M-Q)-by-(M-Q) unitary
240 *> The leading dimension of V2T. If JOBV2T = 'Y', LDV2T >=
246 *> WORK is COMPLEX array, dimension (MAX(1,LWORK))
247 *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
253 *> The dimension of the array WORK.
255 *> If LWORK = -1, then a workspace query is assumed; the routine
256 *> only calculates the optimal size of the WORK array, returns
257 *> this value as the first entry of the work array, and no error
258 *> message related to LWORK is issued by XERBLA.
263 *> RWORK is REAL array, dimension MAX(1,LRWORK)
264 *> On exit, if INFO = 0, RWORK(1) returns the optimal LRWORK.
265 *> If INFO > 0 on exit, RWORK(2:R) contains the values PHI(1),
266 *> ..., PHI(R-1) that, together with THETA(1), ..., THETA(R),
267 *> define the matrix in intermediate bidiagonal-block form
268 *> remaining after nonconvergence. INFO specifies the number
275 *> The dimension of the array RWORK.
277 *> If LRWORK = -1, then a workspace query is assumed; the routine
278 *> only calculates the optimal size of the RWORK array, returns
279 *> this value as the first entry of the work array, and no error
280 *> message related to LRWORK is issued by XERBLA.
285 *> IWORK is INTEGER array, dimension (M-MIN(P,M-P,Q,M-Q))
291 *> = 0: successful exit.
292 *> < 0: if INFO = -i, the i-th argument had an illegal value.
293 *> > 0: CBBCSD did not converge. See the description of RWORK
294 *> above for details.
300 *> [1] Brian D. Sutton. Computing the complete CS decomposition. Numer.
301 *> Algorithms, 50(1):33-65, 2009.
306 *> \author Univ. of Tennessee
307 *> \author Univ. of California Berkeley
308 *> \author Univ. of Colorado Denver
313 *> \ingroup complexOTHERcomputational
315 * =====================================================================
316 RECURSIVE SUBROUTINE CUNCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS,
317 $ SIGNS, M, P, Q, X11, LDX11, X12,
318 $ LDX12, X21, LDX21, X22, LDX22, THETA,
319 $ U1, LDU1, U2, LDU2, V1T, LDV1T, V2T,
320 $ LDV2T, WORK, LWORK, RWORK, LRWORK,
323 * -- LAPACK computational routine (version 3.6.1) --
324 * -- LAPACK is a software package provided by Univ. of Tennessee, --
325 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
328 * .. Scalar Arguments ..
329 CHARACTER JOBU1, JOBU2, JOBV1T, JOBV2T, SIGNS, TRANS
330 INTEGER INFO, LDU1, LDU2, LDV1T, LDV2T, LDX11, LDX12,
331 $ LDX21, LDX22, LRWORK, LWORK, M, P, Q
333 * .. Array Arguments ..
337 COMPLEX U1( LDU1, * ), U2( LDU2, * ), V1T( LDV1T, * ),
338 $ V2T( LDV2T, * ), WORK( * ), X11( LDX11, * ),
339 $ X12( LDX12, * ), X21( LDX21, * ), X22( LDX22,
343 * ===================================================================
347 PARAMETER ( ONE = (1.0E0,0.0E0),
348 $ ZERO = (0.0E0,0.0E0) )
350 * .. Local Scalars ..
351 CHARACTER TRANST, SIGNST
352 INTEGER CHILDINFO, I, IB11D, IB11E, IB12D, IB12E,
353 $ IB21D, IB21E, IB22D, IB22E, IBBCSD, IORBDB,
354 $ IORGLQ, IORGQR, IPHI, ITAUP1, ITAUP2, ITAUQ1,
355 $ ITAUQ2, J, LBBCSDWORK, LBBCSDWORKMIN,
356 $ LBBCSDWORKOPT, LORBDBWORK, LORBDBWORKMIN,
357 $ LORBDBWORKOPT, LORGLQWORK, LORGLQWORKMIN,
358 $ LORGLQWORKOPT, LORGQRWORK, LORGQRWORKMIN,
359 $ LORGQRWORKOPT, LWORKMIN, LWORKOPT, P1, Q1
360 LOGICAL COLMAJOR, DEFAULTSIGNS, LQUERY, WANTU1, WANTU2,
362 INTEGER LRWORKMIN, LRWORKOPT
365 * .. External Subroutines ..
366 EXTERNAL XERBLA, CBBCSD, CLACPY, CLAPMR, CLAPMT, CLASCL,
367 $ CLASET, CUNBDB, CUNGLQ, CUNGQR
369 * .. External Functions ..
373 * .. Intrinsic Functions
374 INTRINSIC INT, MAX, MIN
376 * .. Executable Statements ..
378 * Test input arguments
381 WANTU1 = LSAME( JOBU1, 'Y' )
382 WANTU2 = LSAME( JOBU2, 'Y' )
383 WANTV1T = LSAME( JOBV1T, 'Y' )
384 WANTV2T = LSAME( JOBV2T, 'Y' )
385 COLMAJOR = .NOT. LSAME( TRANS, 'T' )
386 DEFAULTSIGNS = .NOT. LSAME( SIGNS, 'O' )
387 LQUERY = LWORK .EQ. -1
388 LRQUERY = LRWORK .EQ. -1
391 ELSE IF( P .LT. 0 .OR. P .GT. M ) THEN
393 ELSE IF( Q .LT. 0 .OR. Q .GT. M ) THEN
395 ELSE IF ( COLMAJOR .AND. LDX11 .LT. MAX( 1, P ) ) THEN
397 ELSE IF (.NOT. COLMAJOR .AND. LDX11 .LT. MAX( 1, Q ) ) THEN
399 ELSE IF (COLMAJOR .AND. LDX12 .LT. MAX( 1, P ) ) THEN
401 ELSE IF (.NOT. COLMAJOR .AND. LDX12 .LT. MAX( 1, M-Q ) ) THEN
403 ELSE IF (COLMAJOR .AND. LDX21 .LT. MAX( 1, M-P ) ) THEN
405 ELSE IF (.NOT. COLMAJOR .AND. LDX21 .LT. MAX( 1, Q ) ) THEN
407 ELSE IF (COLMAJOR .AND. LDX22 .LT. MAX( 1, M-P ) ) THEN
409 ELSE IF (.NOT. COLMAJOR .AND. LDX22 .LT. MAX( 1, M-Q ) ) THEN
411 ELSE IF( WANTU1 .AND. LDU1 .LT. P ) THEN
413 ELSE IF( WANTU2 .AND. LDU2 .LT. M-P ) THEN
415 ELSE IF( WANTV1T .AND. LDV1T .LT. Q ) THEN
417 ELSE IF( WANTV2T .AND. LDV2T .LT. M-Q ) THEN
421 * Work with transpose if convenient
423 IF( INFO .EQ. 0 .AND. MIN( P, M-P ) .LT. MIN( Q, M-Q ) ) THEN
429 IF( DEFAULTSIGNS ) THEN
434 CALL CUNCSD( JOBV1T, JOBV2T, JOBU1, JOBU2, TRANST, SIGNST, M,
435 $ Q, P, X11, LDX11, X21, LDX21, X12, LDX12, X22,
436 $ LDX22, THETA, V1T, LDV1T, V2T, LDV2T, U1, LDU1,
437 $ U2, LDU2, WORK, LWORK, RWORK, LRWORK, IWORK,
442 * Work with permutation [ 0 I; I 0 ] * X * [ 0 I; I 0 ] if
445 IF( INFO .EQ. 0 .AND. M-Q .LT. Q ) THEN
446 IF( DEFAULTSIGNS ) THEN
451 CALL CUNCSD( JOBU2, JOBU1, JOBV2T, JOBV1T, TRANS, SIGNST, M,
452 $ M-P, M-Q, X22, LDX22, X21, LDX21, X12, LDX12, X11,
453 $ LDX11, THETA, U2, LDU2, U1, LDU1, V2T, LDV2T, V1T,
454 $ LDV1T, WORK, LWORK, RWORK, LRWORK, IWORK, INFO )
460 IF( INFO .EQ. 0 ) THEN
465 IB11D = IPHI + MAX( 1, Q - 1 )
466 IB11E = IB11D + MAX( 1, Q )
467 IB12D = IB11E + MAX( 1, Q - 1 )
468 IB12E = IB12D + MAX( 1, Q )
469 IB21D = IB12E + MAX( 1, Q - 1 )
470 IB21E = IB21D + MAX( 1, Q )
471 IB22D = IB21E + MAX( 1, Q - 1 )
472 IB22E = IB22D + MAX( 1, Q )
473 IBBCSD = IB22E + MAX( 1, Q - 1 )
474 CALL CBBCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS, M, P, Q,
475 $ THETA, THETA, U1, LDU1, U2, LDU2, V1T, LDV1T,
476 $ V2T, LDV2T, THETA, THETA, THETA, THETA, THETA,
477 $ THETA, THETA, THETA, RWORK, -1, CHILDINFO )
478 LBBCSDWORKOPT = INT( RWORK(1) )
479 LBBCSDWORKMIN = LBBCSDWORKOPT
480 LRWORKOPT = IBBCSD + LBBCSDWORKOPT - 1
481 LRWORKMIN = IBBCSD + LBBCSDWORKMIN - 1
487 ITAUP2 = ITAUP1 + MAX( 1, P )
488 ITAUQ1 = ITAUP2 + MAX( 1, M - P )
489 ITAUQ2 = ITAUQ1 + MAX( 1, Q )
490 IORGQR = ITAUQ2 + MAX( 1, M - Q )
491 CALL CUNGQR( M-Q, M-Q, M-Q, U1, MAX(1,M-Q), U1, WORK, -1,
493 LORGQRWORKOPT = INT( WORK(1) )
494 LORGQRWORKMIN = MAX( 1, M - Q )
495 IORGLQ = ITAUQ2 + MAX( 1, M - Q )
496 CALL CUNGLQ( M-Q, M-Q, M-Q, U1, MAX(1,M-Q), U1, WORK, -1,
498 LORGLQWORKOPT = INT( WORK(1) )
499 LORGLQWORKMIN = MAX( 1, M - Q )
500 IORBDB = ITAUQ2 + MAX( 1, M - Q )
501 CALL CUNBDB( TRANS, SIGNS, M, P, Q, X11, LDX11, X12, LDX12,
502 $ X21, LDX21, X22, LDX22, THETA, THETA, U1, U2,
503 $ V1T, V2T, WORK, -1, CHILDINFO )
504 LORBDBWORKOPT = INT( WORK(1) )
505 LORBDBWORKMIN = LORBDBWORKOPT
506 LWORKOPT = MAX( IORGQR + LORGQRWORKOPT, IORGLQ + LORGLQWORKOPT,
507 $ IORBDB + LORBDBWORKOPT ) - 1
508 LWORKMIN = MAX( IORGQR + LORGQRWORKMIN, IORGLQ + LORGLQWORKMIN,
509 $ IORBDB + LORBDBWORKMIN ) - 1
510 WORK(1) = MAX(LWORKOPT,LWORKMIN)
512 IF( LWORK .LT. LWORKMIN
513 $ .AND. .NOT. ( LQUERY .OR. LRQUERY ) ) THEN
515 ELSE IF( LRWORK .LT. LRWORKMIN
516 $ .AND. .NOT. ( LQUERY .OR. LRQUERY ) ) THEN
519 LORGQRWORK = LWORK - IORGQR + 1
520 LORGLQWORK = LWORK - IORGLQ + 1
521 LORBDBWORK = LWORK - IORBDB + 1
522 LBBCSDWORK = LRWORK - IBBCSD + 1
526 * Abort if any illegal arguments
528 IF( INFO .NE. 0 ) THEN
529 CALL XERBLA( 'CUNCSD', -INFO )
531 ELSE IF( LQUERY .OR. LRQUERY ) THEN
535 * Transform to bidiagonal block form
537 CALL CUNBDB( TRANS, SIGNS, M, P, Q, X11, LDX11, X12, LDX12, X21,
538 $ LDX21, X22, LDX22, THETA, RWORK(IPHI), WORK(ITAUP1),
539 $ WORK(ITAUP2), WORK(ITAUQ1), WORK(ITAUQ2),
540 $ WORK(IORBDB), LORBDBWORK, CHILDINFO )
542 * Accumulate Householder reflectors
545 IF( WANTU1 .AND. P .GT. 0 ) THEN
546 CALL CLACPY( 'L', P, Q, X11, LDX11, U1, LDU1 )
547 CALL CUNGQR( P, P, Q, U1, LDU1, WORK(ITAUP1), WORK(IORGQR),
550 IF( WANTU2 .AND. M-P .GT. 0 ) THEN
551 CALL CLACPY( 'L', M-P, Q, X21, LDX21, U2, LDU2 )
552 CALL CUNGQR( M-P, M-P, Q, U2, LDU2, WORK(ITAUP2),
553 $ WORK(IORGQR), LORGQRWORK, INFO )
555 IF( WANTV1T .AND. Q .GT. 0 ) THEN
556 CALL CLACPY( 'U', Q-1, Q-1, X11(1,2), LDX11, V1T(2,2),
563 CALL CUNGLQ( Q-1, Q-1, Q-1, V1T(2,2), LDV1T, WORK(ITAUQ1),
564 $ WORK(IORGLQ), LORGLQWORK, INFO )
566 IF( WANTV2T .AND. M-Q .GT. 0 ) THEN
567 CALL CLACPY( 'U', P, M-Q, X12, LDX12, V2T, LDV2T )
568 IF( M-P .GT. Q ) THEN
569 CALL CLACPY( 'U', M-P-Q, M-P-Q, X22(Q+1,P+1), LDX22,
570 $ V2T(P+1,P+1), LDV2T )
573 CALL CUNGLQ( M-Q, M-Q, M-Q, V2T, LDV2T, WORK(ITAUQ2),
574 $ WORK(IORGLQ), LORGLQWORK, INFO )
578 IF( WANTU1 .AND. P .GT. 0 ) THEN
579 CALL CLACPY( 'U', Q, P, X11, LDX11, U1, LDU1 )
580 CALL CUNGLQ( P, P, Q, U1, LDU1, WORK(ITAUP1), WORK(IORGLQ),
583 IF( WANTU2 .AND. M-P .GT. 0 ) THEN
584 CALL CLACPY( 'U', Q, M-P, X21, LDX21, U2, LDU2 )
585 CALL CUNGLQ( M-P, M-P, Q, U2, LDU2, WORK(ITAUP2),
586 $ WORK(IORGLQ), LORGLQWORK, INFO )
588 IF( WANTV1T .AND. Q .GT. 0 ) THEN
589 CALL CLACPY( 'L', Q-1, Q-1, X11(2,1), LDX11, V1T(2,2),
596 CALL CUNGQR( Q-1, Q-1, Q-1, V1T(2,2), LDV1T, WORK(ITAUQ1),
597 $ WORK(IORGQR), LORGQRWORK, INFO )
599 IF( WANTV2T .AND. M-Q .GT. 0 ) THEN
602 CALL CLACPY( 'L', M-Q, P, X12, LDX12, V2T, LDV2T )
603 IF ( M .GT. P+Q ) THEN
604 CALL CLACPY( 'L', M-P-Q, M-P-Q, X22(P1,Q1), LDX22,
605 $ V2T(P+1,P+1), LDV2T )
607 CALL CUNGQR( M-Q, M-Q, M-Q, V2T, LDV2T, WORK(ITAUQ2),
608 $ WORK(IORGQR), LORGQRWORK, INFO )
612 * Compute the CSD of the matrix in bidiagonal-block form
614 CALL CBBCSD( JOBU1, JOBU2, JOBV1T, JOBV2T, TRANS, M, P, Q, THETA,
615 $ RWORK(IPHI), U1, LDU1, U2, LDU2, V1T, LDV1T, V2T,
616 $ LDV2T, RWORK(IB11D), RWORK(IB11E), RWORK(IB12D),
617 $ RWORK(IB12E), RWORK(IB21D), RWORK(IB21E),
618 $ RWORK(IB22D), RWORK(IB22E), RWORK(IBBCSD),
621 * Permute rows and columns to place identity submatrices in top-
622 * left corner of (1,1)-block and/or bottom-right corner of (1,2)-
623 * block and/or bottom-right corner of (2,1)-block and/or top-left
624 * corner of (2,2)-block
626 IF( Q .GT. 0 .AND. WANTU2 ) THEN
628 IWORK(I) = M - P - Q + I
634 CALL CLAPMT( .FALSE., M-P, M-P, U2, LDU2, IWORK )
636 CALL CLAPMR( .FALSE., M-P, M-P, U2, LDU2, IWORK )
639 IF( M .GT. 0 .AND. WANTV2T ) THEN
641 IWORK(I) = M - P - Q + I
646 IF( .NOT. COLMAJOR ) THEN
647 CALL CLAPMT( .FALSE., M-Q, M-Q, V2T, LDV2T, IWORK )
649 CALL CLAPMR( .FALSE., M-Q, M-Q, V2T, LDV2T, IWORK )