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

◆ ctgsja()

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

CTGSJA

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

Purpose:
 CTGSJA 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 CGGSVP
 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 CTGSJA.
          See Further Details.
[in,out]A
          A is COMPLEX 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 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 REAL
[in]TOLB
          TOLB is REAL

          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)*MACHEPS,
              TOLB = MAX(P,N)*norm(B)*MACHEPS.
[out]ALPHA
          ALPHA is REAL array, dimension (N)
[out]BETA
          BETA is REAL 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
            BETA(K+L+1:N)  = 0.
[in,out]U
          U is COMPLEX array, dimension (LDU,M)
          On entry, if JOBU = 'U', U must contain a matrix U1 (usually
          the unitary matrix returned by CGGSVP).
          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 array, dimension (LDV,P)
          On entry, if JOBV = 'V', V must contain a matrix V1 (usually
          the unitary matrix returned by CGGSVP).
          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 array, dimension (LDQ,N)
          On entry, if JOBQ = 'Q', Q must contain a matrix Q1 (usually
          the unitary matrix returned by CGGSVP).
          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 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:
  CTGSJA 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 376 of file ctgsja.f.

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