LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches

◆ ztgsja()

subroutine ztgsja ( character jobu,
character jobv,
character jobq,
integer m,
integer p,
integer n,
integer k,
integer l,
complex*16, dimension( lda, * ) a,
integer lda,
complex*16, dimension( ldb, * ) b,
integer ldb,
double precision tola,
double precision tolb,
double precision, dimension( * ) alpha,
double precision, dimension( * ) beta,
complex*16, dimension( ldu, * ) u,
integer ldu,
complex*16, dimension( ldv, * ) v,
integer ldv,
complex*16, dimension( ldq, * ) q,
integer ldq,
complex*16, dimension( * ) work,
integer ncycle,
integer info )

ZTGSJA

Download ZTGSJA + dependencies [TGZ] [ZIP] [TXT]

Purpose:
!>
!> ZTGSJA computes the generalized singular value decomposition (GSVD)
!> of two complex upper triangular (or trapezoidal) matrices A and B.
!>
!> On entry, it is assumed that matrices A and B have the following
!> forms, which may be obtained by the preprocessing subroutine ZGGSVP
!> from a general M-by-N matrix A and P-by-N matrix B:
!>
!>              N-K-L  K    L
!>    A =    K ( 0    A12  A13 ) if M-K-L >= 0;
!>           L ( 0     0   A23 )
!>       M-K-L ( 0     0    0  )
!>
!>            N-K-L  K    L
!>    A =  K ( 0    A12  A13 ) if M-K-L < 0;
!>       M-K ( 0     0   A23 )
!>
!>            N-K-L  K    L
!>    B =  L ( 0     0   B13 )
!>       P-L ( 0     0    0  )
!>
!> where the K-by-K matrix A12 and L-by-L matrix B13 are nonsingular
!> upper triangular; A23 is L-by-L upper triangular if M-K-L >= 0,
!> otherwise A23 is (M-K)-by-L upper trapezoidal.
!>
!> On exit,
!>
!>        U**H *A*Q = D1*( 0 R ),    V**H *B*Q = D2*( 0 R ),
!>
!> where U, V and Q are unitary matrices.
!> R is a nonsingular upper triangular matrix, and D1
!> and D2 are ``diagonal'' matrices, which are of the following
!> structures:
!>
!> If M-K-L >= 0,
!>
!>                     K  L
!>        D1 =     K ( I  0 )
!>                 L ( 0  C )
!>             M-K-L ( 0  0 )
!>
!>                    K  L
!>        D2 = L   ( 0  S )
!>             P-L ( 0  0 )
!>
!>                N-K-L  K    L
!>   ( 0 R ) = K (  0   R11  R12 ) K
!>             L (  0    0   R22 ) L
!>
!> where
!>
!>   C = diag( ALPHA(K+1), ... , ALPHA(K+L) ),
!>   S = diag( BETA(K+1),  ... , BETA(K+L) ),
!>   C**2 + S**2 = I.
!>
!>   R is stored in A(1:K+L,N-K-L+1:N) on exit.
!>
!> If M-K-L < 0,
!>
!>                K M-K K+L-M
!>     D1 =   K ( I  0    0   )
!>          M-K ( 0  C    0   )
!>
!>                  K M-K K+L-M
!>     D2 =   M-K ( 0  S    0   )
!>          K+L-M ( 0  0    I   )
!>            P-L ( 0  0    0   )
!>
!>                N-K-L  K   M-K  K+L-M
!> ( 0 R ) =    K ( 0    R11  R12  R13  )
!>           M-K ( 0     0   R22  R23  )
!>         K+L-M ( 0     0    0   R33  )
!>
!> where
!> C = diag( ALPHA(K+1), ... , ALPHA(M) ),
!> S = diag( BETA(K+1),  ... , BETA(M) ),
!> C**2 + S**2 = I.
!>
!> R = ( R11 R12 R13 ) is stored in A(1:M, N-K-L+1:N) and R33 is stored
!>     (  0  R22 R23 )
!> in B(M-K+1:L,N+M-K-L+1:N) on exit.
!>
!> The computation of the unitary transformation matrices U, V or Q
!> is optional.  These matrices may either be formed explicitly, or they
!> may be postmultiplied into input matrices U1, V1, or Q1.
!> 
Parameters
[in]JOBU
!>          JOBU is CHARACTER*1
!>          = 'U':  U must contain a unitary matrix U1 on entry, and
!>                  the product U1*U is returned;
!>          = 'I':  U is initialized to the unit matrix, and the
!>                  unitary matrix U is returned;
!>          = 'N':  U is not computed.
!> 
[in]JOBV
!>          JOBV is CHARACTER*1
!>          = 'V':  V must contain a unitary matrix V1 on entry, and
!>                  the product V1*V is returned;
!>          = 'I':  V is initialized to the unit matrix, and the
!>                  unitary matrix V is returned;
!>          = 'N':  V is not computed.
!> 
[in]JOBQ
!>          JOBQ is CHARACTER*1
!>          = 'Q':  Q must contain a unitary matrix Q1 on entry, and
!>                  the product Q1*Q is returned;
!>          = 'I':  Q is initialized to the unit matrix, and the
!>                  unitary matrix Q is returned;
!>          = 'N':  Q is not computed.
!> 
[in]M
!>          M is INTEGER
!>          The number of rows of the matrix A.  M >= 0.
!> 
[in]P
!>          P is INTEGER
!>          The number of rows of the matrix B.  P >= 0.
!> 
[in]N
!>          N is INTEGER
!>          The number of columns of the matrices A and B.  N >= 0.
!> 
[in]K
!>          K is INTEGER
!> 
[in]L
!>          L is INTEGER
!>
!>          K and L specify the subblocks in the input matrices A and B:
!>          A23 = A(K+1:MIN(K+L,M),N-L+1:N) and B13 = B(1:L,,N-L+1:N)
!>          of A and B, whose GSVD is going to be computed by ZTGSJA.
!>          See Further Details.
!> 
[in,out]A
!>          A is COMPLEX*16 array, dimension (LDA,N)
!>          On entry, the M-by-N matrix A.
!>          On exit, A(N-K+1:N,1:MIN(K+L,M) ) contains the triangular
!>          matrix R or part of R.  See Purpose for details.
!> 
[in]LDA
!>          LDA is INTEGER
!>          The leading dimension of the array A. LDA >= max(1,M).
!> 
[in,out]B
!>          B is COMPLEX*16 array, dimension (LDB,N)
!>          On entry, the P-by-N matrix B.
!>          On exit, if necessary, B(M-K+1:L,N+M-K-L+1:N) contains
!>          a part of R.  See Purpose for details.
!> 
[in]LDB
!>          LDB is INTEGER
!>          The leading dimension of the array B. LDB >= max(1,P).
!> 
[in]TOLA
!>          TOLA is DOUBLE PRECISION
!> 
[in]TOLB
!>          TOLB is DOUBLE PRECISION
!>
!>          TOLA and TOLB are the convergence criteria for the Jacobi-
!>          Kogbetliantz iteration procedure. Generally, they are the
!>          same as used in the preprocessing step, say
!>              TOLA = MAX(M,N)*norm(A)*MAZHEPS,
!>              TOLB = MAX(P,N)*norm(B)*MAZHEPS.
!> 
[out]ALPHA
!>          ALPHA is DOUBLE PRECISION array, dimension (N)
!> 
[out]BETA
!>          BETA is DOUBLE PRECISION array, dimension (N)
!>
!>          On exit, ALPHA and BETA contain the generalized singular
!>          value pairs of A and B;
!>            ALPHA(1:K) = 1,
!>            BETA(1:K)  = 0,
!>          and if M-K-L >= 0,
!>            ALPHA(K+1:K+L) = diag(C),
!>            BETA(K+1:K+L)  = diag(S),
!>          or if M-K-L < 0,
!>            ALPHA(K+1:M)= C, ALPHA(M+1:K+L)= 0
!>            BETA(K+1:M) = S, BETA(M+1:K+L) = 1.
!>          Furthermore, if K+L < N,
!>            ALPHA(K+L+1:N) = 0 and
!>            BETA(K+L+1:N)  = 0.
!> 
[in,out]U
!>          U is COMPLEX*16 array, dimension (LDU,M)
!>          On entry, if JOBU = 'U', U must contain a matrix U1 (usually
!>          the unitary matrix returned by ZGGSVP).
!>          On exit,
!>          if JOBU = 'I', U contains the unitary matrix U;
!>          if JOBU = 'U', U contains the product U1*U.
!>          If JOBU = 'N', U is not referenced.
!> 
[in]LDU
!>          LDU is INTEGER
!>          The leading dimension of the array U. LDU >= max(1,M) if
!>          JOBU = 'U'; LDU >= 1 otherwise.
!> 
[in,out]V
!>          V is COMPLEX*16 array, dimension (LDV,P)
!>          On entry, if JOBV = 'V', V must contain a matrix V1 (usually
!>          the unitary matrix returned by ZGGSVP).
!>          On exit,
!>          if JOBV = 'I', V contains the unitary matrix V;
!>          if JOBV = 'V', V contains the product V1*V.
!>          If JOBV = 'N', V is not referenced.
!> 
[in]LDV
!>          LDV is INTEGER
!>          The leading dimension of the array V. LDV >= max(1,P) if
!>          JOBV = 'V'; LDV >= 1 otherwise.
!> 
[in,out]Q
!>          Q is COMPLEX*16 array, dimension (LDQ,N)
!>          On entry, if JOBQ = 'Q', Q must contain a matrix Q1 (usually
!>          the unitary matrix returned by ZGGSVP).
!>          On exit,
!>          if JOBQ = 'I', Q contains the unitary matrix Q;
!>          if JOBQ = 'Q', Q contains the product Q1*Q.
!>          If JOBQ = 'N', Q is not referenced.
!> 
[in]LDQ
!>          LDQ is INTEGER
!>          The leading dimension of the array Q. LDQ >= max(1,N) if
!>          JOBQ = 'Q'; LDQ >= 1 otherwise.
!> 
[out]WORK
!>          WORK is COMPLEX*16 array, dimension (2*N)
!> 
[out]NCYCLE
!>          NCYCLE is INTEGER
!>          The number of cycles required for convergence.
!> 
[out]INFO
!>          INFO is INTEGER
!>          = 0:  successful exit
!>          < 0:  if INFO = -i, the i-th argument had an illegal value.
!>          = 1:  the procedure does not converge after MAXIT cycles.
!> 
Internal Parameters:
!>  MAXIT   INTEGER
!>          MAXIT specifies the total loops that the iterative procedure
!>          may take. If after MAXIT cycles, the routine fails to
!>          converge, we return INFO = 1.
!> 
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.
Further Details:
!>
!>  ZTGSJA essentially uses a variant of Kogbetliantz algorithm to reduce
!>  min(L,M-K)-by-L triangular (or trapezoidal) matrix A23 and L-by-L
!>  matrix B13 to the form:
!>
!>           U1**H *A13*Q1 = C1*R1; V1**H *B13*Q1 = S1*R1,
!>
!>  where U1, V1 and Q1 are unitary matrix.
!>  C1 and S1 are diagonal matrices satisfying
!>
!>                C1**2 + S1**2 = I,
!>
!>  and R1 is an L-by-L nonsingular upper triangular matrix.
!> 

Definition at line 374 of file ztgsja.f.

377*
378* -- LAPACK computational routine --
379* -- LAPACK is a software package provided by Univ. of Tennessee, --
380* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
381*
382* .. Scalar Arguments ..
383 CHARACTER JOBQ, JOBU, JOBV
384 INTEGER INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N,
385 $ NCYCLE, P
386 DOUBLE PRECISION TOLA, TOLB
387* ..
388* .. Array Arguments ..
389 DOUBLE PRECISION ALPHA( * ), BETA( * )
390 COMPLEX*16 A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
391 $ U( LDU, * ), V( LDV, * ), WORK( * )
392* ..
393*
394* =====================================================================
395*
396* .. Parameters ..
397 INTEGER MAXIT
398 parameter( maxit = 40 )
399 DOUBLE PRECISION ZERO, ONE, HUGENUM
400 parameter( zero = 0.0d+0, one = 1.0d+0 )
401 COMPLEX*16 CZERO, CONE
402 parameter( czero = ( 0.0d+0, 0.0d+0 ),
403 $ cone = ( 1.0d+0, 0.0d+0 ) )
404* ..
405* .. Local Scalars ..
406*
407 LOGICAL INITQ, INITU, INITV, UPPER, WANTQ, WANTU, WANTV
408 INTEGER I, J, KCYCLE
409 DOUBLE PRECISION A1, A3, B1, B3, CSQ, CSU, CSV, ERROR, GAMMA,
410 $ RWK, SSMIN
411 COMPLEX*16 A2, B2, SNQ, SNU, SNV
412* ..
413* .. External Functions ..
414 LOGICAL LSAME
415 EXTERNAL lsame
416* ..
417* .. External Subroutines ..
418 EXTERNAL dlartg, xerbla, zcopy, zdscal, zlags2,
419 $ zlapll,
420 $ zlaset, zrot
421* ..
422* .. Intrinsic Functions ..
423 INTRINSIC abs, dble, dconjg, max, min, huge
424 parameter( hugenum = huge(zero) )
425* ..
426* .. Executable Statements ..
427*
428* Decode and test the input parameters
429*
430 initu = lsame( jobu, 'I' )
431 wantu = initu .OR. lsame( jobu, 'U' )
432*
433 initv = lsame( jobv, 'I' )
434 wantv = initv .OR. lsame( jobv, 'V' )
435*
436 initq = lsame( jobq, 'I' )
437 wantq = initq .OR. lsame( jobq, 'Q' )
438*
439 info = 0
440 IF( .NOT.( initu .OR. wantu .OR. lsame( jobu, 'N' ) ) ) THEN
441 info = -1
442 ELSE IF( .NOT.( initv .OR.
443 $ wantv .OR.
444 $ lsame( jobv, 'N' ) ) ) THEN
445 info = -2
446 ELSE IF( .NOT.( initq .OR.
447 $ wantq .OR.
448 $ lsame( jobq, 'N' ) ) ) THEN
449 info = -3
450 ELSE IF( m.LT.0 ) THEN
451 info = -4
452 ELSE IF( p.LT.0 ) THEN
453 info = -5
454 ELSE IF( n.LT.0 ) THEN
455 info = -6
456 ELSE IF( lda.LT.max( 1, m ) ) THEN
457 info = -10
458 ELSE IF( ldb.LT.max( 1, p ) ) THEN
459 info = -12
460 ELSE IF( ldu.LT.1 .OR. ( wantu .AND. ldu.LT.m ) ) THEN
461 info = -18
462 ELSE IF( ldv.LT.1 .OR. ( wantv .AND. ldv.LT.p ) ) THEN
463 info = -20
464 ELSE IF( ldq.LT.1 .OR. ( wantq .AND. ldq.LT.n ) ) THEN
465 info = -22
466 END IF
467 IF( info.NE.0 ) THEN
468 CALL xerbla( 'ZTGSJA', -info )
469 RETURN
470 END IF
471*
472* Initialize U, V and Q, if necessary
473*
474 IF( initu )
475 $ CALL zlaset( 'Full', m, m, czero, cone, u, ldu )
476 IF( initv )
477 $ CALL zlaset( 'Full', p, p, czero, cone, v, ldv )
478 IF( initq )
479 $ CALL zlaset( 'Full', n, n, czero, cone, q, ldq )
480*
481* Loop until convergence
482*
483 upper = .false.
484 DO 40 kcycle = 1, maxit
485*
486 upper = .NOT.upper
487*
488 DO 20 i = 1, l - 1
489 DO 10 j = i + 1, l
490*
491 a1 = zero
492 a2 = czero
493 a3 = zero
494 IF( k+i.LE.m )
495 $ a1 = dble( a( k+i, n-l+i ) )
496 IF( k+j.LE.m )
497 $ a3 = dble( a( k+j, n-l+j ) )
498*
499 b1 = dble( b( i, n-l+i ) )
500 b3 = dble( b( j, n-l+j ) )
501*
502 IF( upper ) THEN
503 IF( k+i.LE.m )
504 $ a2 = a( k+i, n-l+j )
505 b2 = b( i, n-l+j )
506 ELSE
507 IF( k+j.LE.m )
508 $ a2 = a( k+j, n-l+i )
509 b2 = b( j, n-l+i )
510 END IF
511*
512 CALL zlags2( upper, a1, a2, a3, b1, b2, b3, csu, snu,
513 $ csv, snv, csq, snq )
514*
515* Update (K+I)-th and (K+J)-th rows of matrix A: U**H *A
516*
517 IF( k+j.LE.m )
518 $ CALL zrot( l, a( k+j, n-l+1 ), lda, a( k+i,
519 $ n-l+1 ),
520 $ lda, csu, dconjg( snu ) )
521*
522* Update I-th and J-th rows of matrix B: V**H *B
523*
524 CALL zrot( l, b( j, n-l+1 ), ldb, b( i, n-l+1 ), ldb,
525 $ csv, dconjg( snv ) )
526*
527* Update (N-L+I)-th and (N-L+J)-th columns of matrices
528* A and B: A*Q and B*Q
529*
530 CALL zrot( min( k+l, m ), a( 1, n-l+j ), 1,
531 $ a( 1, n-l+i ), 1, csq, snq )
532*
533 CALL zrot( l, b( 1, n-l+j ), 1, b( 1, n-l+i ), 1, csq,
534 $ snq )
535*
536 IF( upper ) THEN
537 IF( k+i.LE.m )
538 $ a( k+i, n-l+j ) = czero
539 b( i, n-l+j ) = czero
540 ELSE
541 IF( k+j.LE.m )
542 $ a( k+j, n-l+i ) = czero
543 b( j, n-l+i ) = czero
544 END IF
545*
546* Ensure that the diagonal elements of A and B are real.
547*
548 IF( k+i.LE.m )
549 $ a( k+i, n-l+i ) = dble( a( k+i, n-l+i ) )
550 IF( k+j.LE.m )
551 $ a( k+j, n-l+j ) = dble( a( k+j, n-l+j ) )
552 b( i, n-l+i ) = dble( b( i, n-l+i ) )
553 b( j, n-l+j ) = dble( b( j, n-l+j ) )
554*
555* Update unitary matrices U, V, Q, if desired.
556*
557 IF( wantu .AND. k+j.LE.m )
558 $ CALL zrot( m, u( 1, k+j ), 1, u( 1, k+i ), 1, csu,
559 $ snu )
560*
561 IF( wantv )
562 $ CALL zrot( p, v( 1, j ), 1, v( 1, i ), 1, csv,
563 $ snv )
564*
565 IF( wantq )
566 $ CALL zrot( n, q( 1, n-l+j ), 1, q( 1, n-l+i ), 1,
567 $ csq,
568 $ snq )
569*
570 10 CONTINUE
571 20 CONTINUE
572*
573 IF( .NOT.upper ) THEN
574*
575* The matrices A13 and B13 were lower triangular at the start
576* of the cycle, and are now upper triangular.
577*
578* Convergence test: test the parallelism of the corresponding
579* rows of A and B.
580*
581 error = zero
582 DO 30 i = 1, min( l, m-k )
583 CALL zcopy( l-i+1, a( k+i, n-l+i ), lda, work, 1 )
584 CALL zcopy( l-i+1, b( i, n-l+i ), ldb, work( l+1 ),
585 $ 1 )
586 CALL zlapll( l-i+1, work, 1, work( l+1 ), 1, ssmin )
587 error = max( error, ssmin )
588 30 CONTINUE
589*
590 IF( abs( error ).LE.min( tola, tolb ) )
591 $ GO TO 50
592 END IF
593*
594* End of cycle loop
595*
596 40 CONTINUE
597*
598* The algorithm has not converged after MAXIT cycles.
599*
600 info = 1
601 GO TO 100
602*
603 50 CONTINUE
604*
605* If ERROR <= MIN(TOLA,TOLB), then the algorithm has converged.
606* Compute the generalized singular value pairs (ALPHA, BETA), and
607* set the triangular matrix R to array A.
608*
609 DO 60 i = 1, k
610 alpha( i ) = one
611 beta( i ) = zero
612 60 CONTINUE
613*
614 DO 70 i = 1, min( l, m-k )
615*
616 a1 = dble( a( k+i, n-l+i ) )
617 b1 = dble( b( i, n-l+i ) )
618 gamma = b1 / a1
619*
620 IF( (gamma.LE.hugenum).AND.(gamma.GE.-hugenum) ) THEN
621*
622 IF( gamma.LT.zero ) THEN
623 CALL zdscal( l-i+1, -one, b( i, n-l+i ), ldb )
624 IF( wantv )
625 $ CALL zdscal( p, -one, v( 1, i ), 1 )
626 END IF
627*
628 CALL dlartg( abs( gamma ), one, beta( k+i ),
629 $ alpha( k+i ),
630 $ rwk )
631*
632 IF( alpha( k+i ).GE.beta( k+i ) ) THEN
633 CALL zdscal( l-i+1, one / alpha( k+i ), a( k+i,
634 $ n-l+i ),
635 $ lda )
636 ELSE
637 CALL zdscal( l-i+1, one / beta( k+i ), b( i, n-l+i ),
638 $ ldb )
639 CALL zcopy( l-i+1, b( i, n-l+i ), ldb, a( k+i,
640 $ n-l+i ),
641 $ lda )
642 END IF
643*
644 ELSE
645*
646 alpha( k+i ) = zero
647 beta( k+i ) = one
648 CALL zcopy( l-i+1, b( i, n-l+i ), ldb, a( k+i, n-l+i ),
649 $ lda )
650 END IF
651 70 CONTINUE
652*
653* Post-assignment
654*
655 DO 80 i = m + 1, k + l
656 alpha( i ) = zero
657 beta( i ) = one
658 80 CONTINUE
659*
660 IF( k+l.LT.n ) THEN
661 DO 90 i = k + l + 1, n
662 alpha( i ) = zero
663 beta( i ) = zero
664 90 CONTINUE
665 END IF
666*
667 100 CONTINUE
668 ncycle = kcycle
669*
670 RETURN
671*
672* End of ZTGSJA
673*
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine zcopy(n, zx, incx, zy, incy)
ZCOPY
Definition zcopy.f:81
subroutine zlags2(upper, a1, a2, a3, b1, b2, b3, csu, snu, csv, snv, csq, snq)
ZLAGS2
Definition zlags2.f:157
subroutine zlapll(n, x, incx, y, incy, ssmin)
ZLAPLL measures the linear dependence of two vectors.
Definition zlapll.f:98
subroutine dlartg(f, g, c, s, r)
DLARTG generates a plane rotation with real cosine and real sine.
Definition dlartg.f90:111
subroutine zlaset(uplo, m, n, alpha, beta, a, lda)
ZLASET initializes the off-diagonal elements and the diagonal elements of a matrix to given values.
Definition zlaset.f:104
logical function lsame(ca, cb)
LSAME
Definition lsame.f:48
subroutine zrot(n, cx, incx, cy, incy, c, s)
ZROT applies a plane rotation with real cosine and complex sine to a pair of complex vectors.
Definition zrot.f:101
subroutine zdscal(n, da, zx, incx)
ZDSCAL
Definition zdscal.f:78
Here is the call graph for this function:
Here is the caller graph for this function: