LAPACK  3.6.1
LAPACK: Linear Algebra PACKage
subroutine stgsja ( character  JOBU,
character  JOBV,
character  JOBQ,
integer  M,
integer  P,
integer  N,
integer  K,
integer  L,
real, dimension( lda, * )  A,
integer  LDA,
real, dimension( ldb, * )  B,
integer  LDB,
real  TOLA,
real  TOLB,
real, dimension( * )  ALPHA,
real, dimension( * )  BETA,
real, dimension( ldu, * )  U,
integer  LDU,
real, dimension( ldv, * )  V,
integer  LDV,
real, dimension( ldq, * )  Q,
integer  LDQ,
real, dimension( * )  WORK,
integer  NCYCLE,
integer  INFO 
)

STGSJA

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

Purpose:
 STGSJA computes the generalized singular value decomposition (GSVD)
 of two real 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 SGGSVP
 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**T *A*Q = D1*( 0 R ),    V**T *B*Q = D2*( 0 R ),

 where U, V and Q are orthogonal 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 orthogonal 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 an orthogonal matrix U1 on entry, and
                  the product U1*U is returned;
          = 'I':  U is initialized to the unit matrix, and the
                  orthogonal matrix U is returned;
          = 'N':  U is not computed.
[in]JOBV
          JOBV is CHARACTER*1
          = 'V':  V must contain an orthogonal matrix V1 on entry, and
                  the product V1*V is returned;
          = 'I':  V is initialized to the unit matrix, and the
                  orthogonal matrix V is returned;
          = 'N':  V is not computed.
[in]JOBQ
          JOBQ is CHARACTER*1
          = 'Q':  Q must contain an orthogonal matrix Q1 on entry, and
                  the product Q1*Q is returned;
          = 'I':  Q is initialized to the unit matrix, and the
                  orthogonal 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 STGSJA.
          See Further Details.
[in,out]A
          A is REAL 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 REAL 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 and
            BETA(K+L+1:N)  = 0.
[in,out]U
          U is REAL array, dimension (LDU,M)
          On entry, if JOBU = 'U', U must contain a matrix U1 (usually
          the orthogonal matrix returned by SGGSVP).
          On exit,
          if JOBU = 'I', U contains the orthogonal 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 REAL array, dimension (LDV,P)
          On entry, if JOBV = 'V', V must contain a matrix V1 (usually
          the orthogonal matrix returned by SGGSVP).
          On exit,
          if JOBV = 'I', V contains the orthogonal 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 REAL array, dimension (LDQ,N)
          On entry, if JOBQ = 'Q', Q must contain a matrix Q1 (usually
          the orthogonal matrix returned by SGGSVP).
          On exit,
          if JOBQ = 'I', Q contains the orthogonal 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 REAL 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.
Date
November 2011
Further Details:
  STGSJA 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**T *A13*Q1 = C1*R1; V1**T *B13*Q1 = S1*R1,

  where U1, V1 and Q1 are orthogonal matrix, and Z**T is the transpose
  of Z.  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 380 of file stgsja.f.

380 *
381 * -- LAPACK computational routine (version 3.4.0) --
382 * -- LAPACK is a software package provided by Univ. of Tennessee, --
383 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
384 * November 2011
385 *
386 * .. Scalar Arguments ..
387  CHARACTER jobq, jobu, jobv
388  INTEGER info, k, l, lda, ldb, ldq, ldu, ldv, m, n,
389  $ ncycle, p
390  REAL tola, tolb
391 * ..
392 * .. Array Arguments ..
393  REAL a( lda, * ), alpha( * ), b( ldb, * ),
394  $ beta( * ), q( ldq, * ), u( ldu, * ),
395  $ v( ldv, * ), work( * )
396 * ..
397 *
398 * =====================================================================
399 *
400 * .. Parameters ..
401  INTEGER maxit
402  parameter ( maxit = 40 )
403  REAL zero, one
404  parameter ( zero = 0.0e+0, one = 1.0e+0 )
405 * ..
406 * .. Local Scalars ..
407 *
408  LOGICAL initq, initu, initv, upper, wantq, wantu, wantv
409  INTEGER i, j, kcycle
410  REAL a1, a2, a3, b1, b2, b3, csq, csu, csv, error,
411  $ gamma, rwk, snq, snu, snv, ssmin
412 * ..
413 * .. External Functions ..
414  LOGICAL lsame
415  EXTERNAL lsame
416 * ..
417 * .. External Subroutines ..
418  EXTERNAL scopy, slags2, slapll, slartg, slaset, srot,
419  $ sscal, xerbla
420 * ..
421 * .. Intrinsic Functions ..
422  INTRINSIC abs, max, min
423 * ..
424 * .. Executable Statements ..
425 *
426 * Decode and test the input parameters
427 *
428  initu = lsame( jobu, 'I' )
429  wantu = initu .OR. lsame( jobu, 'U' )
430 *
431  initv = lsame( jobv, 'I' )
432  wantv = initv .OR. lsame( jobv, 'V' )
433 *
434  initq = lsame( jobq, 'I' )
435  wantq = initq .OR. lsame( jobq, 'Q' )
436 *
437  info = 0
438  IF( .NOT.( initu .OR. wantu .OR. lsame( jobu, 'N' ) ) ) THEN
439  info = -1
440  ELSE IF( .NOT.( initv .OR. wantv .OR. lsame( jobv, 'N' ) ) ) THEN
441  info = -2
442  ELSE IF( .NOT.( initq .OR. wantq .OR. lsame( jobq, 'N' ) ) ) THEN
443  info = -3
444  ELSE IF( m.LT.0 ) THEN
445  info = -4
446  ELSE IF( p.LT.0 ) THEN
447  info = -5
448  ELSE IF( n.LT.0 ) THEN
449  info = -6
450  ELSE IF( lda.LT.max( 1, m ) ) THEN
451  info = -10
452  ELSE IF( ldb.LT.max( 1, p ) ) THEN
453  info = -12
454  ELSE IF( ldu.LT.1 .OR. ( wantu .AND. ldu.LT.m ) ) THEN
455  info = -18
456  ELSE IF( ldv.LT.1 .OR. ( wantv .AND. ldv.LT.p ) ) THEN
457  info = -20
458  ELSE IF( ldq.LT.1 .OR. ( wantq .AND. ldq.LT.n ) ) THEN
459  info = -22
460  END IF
461  IF( info.NE.0 ) THEN
462  CALL xerbla( 'STGSJA', -info )
463  RETURN
464  END IF
465 *
466 * Initialize U, V and Q, if necessary
467 *
468  IF( initu )
469  $ CALL slaset( 'Full', m, m, zero, one, u, ldu )
470  IF( initv )
471  $ CALL slaset( 'Full', p, p, zero, one, v, ldv )
472  IF( initq )
473  $ CALL slaset( 'Full', n, n, zero, one, q, ldq )
474 *
475 * Loop until convergence
476 *
477  upper = .false.
478  DO 40 kcycle = 1, maxit
479 *
480  upper = .NOT.upper
481 *
482  DO 20 i = 1, l - 1
483  DO 10 j = i + 1, l
484 *
485  a1 = zero
486  a2 = zero
487  a3 = zero
488  IF( k+i.LE.m )
489  $ a1 = a( k+i, n-l+i )
490  IF( k+j.LE.m )
491  $ a3 = a( k+j, n-l+j )
492 *
493  b1 = b( i, n-l+i )
494  b3 = b( j, n-l+j )
495 *
496  IF( upper ) THEN
497  IF( k+i.LE.m )
498  $ a2 = a( k+i, n-l+j )
499  b2 = b( i, n-l+j )
500  ELSE
501  IF( k+j.LE.m )
502  $ a2 = a( k+j, n-l+i )
503  b2 = b( j, n-l+i )
504  END IF
505 *
506  CALL slags2( upper, a1, a2, a3, b1, b2, b3, csu, snu,
507  $ csv, snv, csq, snq )
508 *
509 * Update (K+I)-th and (K+J)-th rows of matrix A: U**T *A
510 *
511  IF( k+j.LE.m )
512  $ CALL srot( l, a( k+j, n-l+1 ), lda, a( k+i, n-l+1 ),
513  $ lda, csu, snu )
514 *
515 * Update I-th and J-th rows of matrix B: V**T *B
516 *
517  CALL srot( l, b( j, n-l+1 ), ldb, b( i, n-l+1 ), ldb,
518  $ csv, snv )
519 *
520 * Update (N-L+I)-th and (N-L+J)-th columns of matrices
521 * A and B: A*Q and B*Q
522 *
523  CALL srot( min( k+l, m ), a( 1, n-l+j ), 1,
524  $ a( 1, n-l+i ), 1, csq, snq )
525 *
526  CALL srot( l, b( 1, n-l+j ), 1, b( 1, n-l+i ), 1, csq,
527  $ snq )
528 *
529  IF( upper ) THEN
530  IF( k+i.LE.m )
531  $ a( k+i, n-l+j ) = zero
532  b( i, n-l+j ) = zero
533  ELSE
534  IF( k+j.LE.m )
535  $ a( k+j, n-l+i ) = zero
536  b( j, n-l+i ) = zero
537  END IF
538 *
539 * Update orthogonal matrices U, V, Q, if desired.
540 *
541  IF( wantu .AND. k+j.LE.m )
542  $ CALL srot( m, u( 1, k+j ), 1, u( 1, k+i ), 1, csu,
543  $ snu )
544 *
545  IF( wantv )
546  $ CALL srot( p, v( 1, j ), 1, v( 1, i ), 1, csv, snv )
547 *
548  IF( wantq )
549  $ CALL srot( n, q( 1, n-l+j ), 1, q( 1, n-l+i ), 1, csq,
550  $ snq )
551 *
552  10 CONTINUE
553  20 CONTINUE
554 *
555  IF( .NOT.upper ) THEN
556 *
557 * The matrices A13 and B13 were lower triangular at the start
558 * of the cycle, and are now upper triangular.
559 *
560 * Convergence test: test the parallelism of the corresponding
561 * rows of A and B.
562 *
563  error = zero
564  DO 30 i = 1, min( l, m-k )
565  CALL scopy( l-i+1, a( k+i, n-l+i ), lda, work, 1 )
566  CALL scopy( l-i+1, b( i, n-l+i ), ldb, work( l+1 ), 1 )
567  CALL slapll( l-i+1, work, 1, work( l+1 ), 1, ssmin )
568  error = max( error, ssmin )
569  30 CONTINUE
570 *
571  IF( abs( error ).LE.min( tola, tolb ) )
572  $ GO TO 50
573  END IF
574 *
575 * End of cycle loop
576 *
577  40 CONTINUE
578 *
579 * The algorithm has not converged after MAXIT cycles.
580 *
581  info = 1
582  GO TO 100
583 *
584  50 CONTINUE
585 *
586 * If ERROR <= MIN(TOLA,TOLB), then the algorithm has converged.
587 * Compute the generalized singular value pairs (ALPHA, BETA), and
588 * set the triangular matrix R to array A.
589 *
590  DO 60 i = 1, k
591  alpha( i ) = one
592  beta( i ) = zero
593  60 CONTINUE
594 *
595  DO 70 i = 1, min( l, m-k )
596 *
597  a1 = a( k+i, n-l+i )
598  b1 = b( i, n-l+i )
599 *
600  IF( a1.NE.zero ) THEN
601  gamma = b1 / a1
602 *
603 * change sign if necessary
604 *
605  IF( gamma.LT.zero ) THEN
606  CALL sscal( l-i+1, -one, b( i, n-l+i ), ldb )
607  IF( wantv )
608  $ CALL sscal( p, -one, v( 1, i ), 1 )
609  END IF
610 *
611  CALL slartg( abs( gamma ), one, beta( k+i ), alpha( k+i ),
612  $ rwk )
613 *
614  IF( alpha( k+i ).GE.beta( k+i ) ) THEN
615  CALL sscal( l-i+1, one / alpha( k+i ), a( k+i, n-l+i ),
616  $ lda )
617  ELSE
618  CALL sscal( l-i+1, one / beta( k+i ), b( i, n-l+i ),
619  $ ldb )
620  CALL scopy( l-i+1, b( i, n-l+i ), ldb, a( k+i, n-l+i ),
621  $ lda )
622  END IF
623 *
624  ELSE
625 *
626  alpha( k+i ) = zero
627  beta( k+i ) = one
628  CALL scopy( l-i+1, b( i, n-l+i ), ldb, a( k+i, n-l+i ),
629  $ lda )
630 *
631  END IF
632 *
633  70 CONTINUE
634 *
635 * Post-assignment
636 *
637  DO 80 i = m + 1, k + l
638  alpha( i ) = zero
639  beta( i ) = one
640  80 CONTINUE
641 *
642  IF( k+l.LT.n ) THEN
643  DO 90 i = k + l + 1, n
644  alpha( i ) = zero
645  beta( i ) = zero
646  90 CONTINUE
647  END IF
648 *
649  100 CONTINUE
650  ncycle = kcycle
651  RETURN
652 *
653 * End of STGSJA
654 *
subroutine xerbla(SRNAME, INFO)
XERBLA
Definition: xerbla.f:62
subroutine srot(N, SX, INCX, SY, INCY, C, S)
SROT
Definition: srot.f:53
subroutine slartg(F, G, CS, SN, R)
SLARTG generates a plane rotation with real cosine and real sine.
Definition: slartg.f:99
subroutine slapll(N, X, INCX, Y, INCY, SSMIN)
SLAPLL measures the linear dependence of two vectors.
Definition: slapll.f:104
subroutine slaset(UPLO, M, N, ALPHA, BETA, A, LDA)
SLASET initializes the off-diagonal elements and the diagonal elements of a matrix to given values...
Definition: slaset.f:112
subroutine sscal(N, SA, SX, INCX)
SSCAL
Definition: sscal.f:55
subroutine slags2(UPPER, A1, A2, A3, B1, B2, B3, CSU, SNU, CSV, SNV, CSQ, SNQ)
SLAGS2 computes 2-by-2 orthogonal matrices U, V, and Q, and applies them to matrices A and B such tha...
Definition: slags2.f:154
logical function lsame(CA, CB)
LSAME
Definition: lsame.f:55
subroutine scopy(N, SX, INCX, SY, INCY)
SCOPY
Definition: scopy.f:53

Here is the call graph for this function:

Here is the caller graph for this function: