File:  [local] / rpl / lapack / lapack / dggsvp.f
Revision 1.7: download - view: text, annotated - select for diffs - revision graph
Tue Dec 21 13:53:27 2010 UTC (13 years, 5 months ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_1_0, rpl-4_0_24, rpl-4_0_22, rpl-4_0_21, rpl-4_0_20, rpl-4_0, HEAD
Mise à jour de lapack vers la version 3.3.0.

    1:       SUBROUTINE DGGSVP( JOBU, JOBV, JOBQ, M, P, N, A, LDA, B, LDB,
    2:      $                   TOLA, TOLB, K, L, U, LDU, V, LDV, Q, LDQ,
    3:      $                   IWORK, TAU, WORK, INFO )
    4: *
    5: *  -- LAPACK routine (version 3.2) --
    6: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
    7: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
    8: *     November 2006
    9: *
   10: *     .. Scalar Arguments ..
   11:       CHARACTER          JOBQ, JOBU, JOBV
   12:       INTEGER            INFO, K, L, LDA, LDB, LDQ, LDU, LDV, M, N, P
   13:       DOUBLE PRECISION   TOLA, TOLB
   14: *     ..
   15: *     .. Array Arguments ..
   16:       INTEGER            IWORK( * )
   17:       DOUBLE PRECISION   A( LDA, * ), B( LDB, * ), Q( LDQ, * ),
   18:      $                   TAU( * ), U( LDU, * ), V( LDV, * ), WORK( * )
   19: *     ..
   20: *
   21: *  Purpose
   22: *  =======
   23: *
   24: *  DGGSVP computes orthogonal matrices U, V and Q such that
   25: *
   26: *                   N-K-L  K    L
   27: *   U'*A*Q =     K ( 0    A12  A13 )  if M-K-L >= 0;
   28: *                L ( 0     0   A23 )
   29: *            M-K-L ( 0     0    0  )
   30: *
   31: *                   N-K-L  K    L
   32: *          =     K ( 0    A12  A13 )  if M-K-L < 0;
   33: *              M-K ( 0     0   A23 )
   34: *
   35: *                 N-K-L  K    L
   36: *   V'*B*Q =   L ( 0     0   B13 )
   37: *            P-L ( 0     0    0  )
   38: *
   39: *  where the K-by-K matrix A12 and L-by-L matrix B13 are nonsingular
   40: *  upper triangular; A23 is L-by-L upper triangular if M-K-L >= 0,
   41: *  otherwise A23 is (M-K)-by-L upper trapezoidal.  K+L = the effective
   42: *  numerical rank of the (M+P)-by-N matrix (A',B')'.  Z' denotes the
   43: *  transpose of Z.
   44: *
   45: *  This decomposition is the preprocessing step for computing the
   46: *  Generalized Singular Value Decomposition (GSVD), see subroutine
   47: *  DGGSVD.
   48: *
   49: *  Arguments
   50: *  =========
   51: *
   52: *  JOBU    (input) CHARACTER*1
   53: *          = 'U':  Orthogonal matrix U is computed;
   54: *          = 'N':  U is not computed.
   55: *
   56: *  JOBV    (input) CHARACTER*1
   57: *          = 'V':  Orthogonal matrix V is computed;
   58: *          = 'N':  V is not computed.
   59: *
   60: *  JOBQ    (input) CHARACTER*1
   61: *          = 'Q':  Orthogonal matrix Q is computed;
   62: *          = 'N':  Q is not computed.
   63: *
   64: *  M       (input) INTEGER
   65: *          The number of rows of the matrix A.  M >= 0.
   66: *
   67: *  P       (input) INTEGER
   68: *          The number of rows of the matrix B.  P >= 0.
   69: *
   70: *  N       (input) INTEGER
   71: *          The number of columns of the matrices A and B.  N >= 0.
   72: *
   73: *  A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
   74: *          On entry, the M-by-N matrix A.
   75: *          On exit, A contains the triangular (or trapezoidal) matrix
   76: *          described in the Purpose section.
   77: *
   78: *  LDA     (input) INTEGER
   79: *          The leading dimension of the array A. LDA >= max(1,M).
   80: *
   81: *  B       (input/output) DOUBLE PRECISION array, dimension (LDB,N)
   82: *          On entry, the P-by-N matrix B.
   83: *          On exit, B contains the triangular matrix described in
   84: *          the Purpose section.
   85: *
   86: *  LDB     (input) INTEGER
   87: *          The leading dimension of the array B. LDB >= max(1,P).
   88: *
   89: *  TOLA    (input) DOUBLE PRECISION
   90: *  TOLB    (input) DOUBLE PRECISION
   91: *          TOLA and TOLB are the thresholds to determine the effective
   92: *          numerical rank of matrix B and a subblock of A. Generally,
   93: *          they are set to
   94: *             TOLA = MAX(M,N)*norm(A)*MAZHEPS,
   95: *             TOLB = MAX(P,N)*norm(B)*MAZHEPS.
   96: *          The size of TOLA and TOLB may affect the size of backward
   97: *          errors of the decomposition.
   98: *
   99: *  K       (output) INTEGER
  100: *  L       (output) INTEGER
  101: *          On exit, K and L specify the dimension of the subblocks
  102: *          described in Purpose.
  103: *          K + L = effective numerical rank of (A',B')'.
  104: *
  105: *  U       (output) DOUBLE PRECISION array, dimension (LDU,M)
  106: *          If JOBU = 'U', U contains the orthogonal matrix U.
  107: *          If JOBU = 'N', U is not referenced.
  108: *
  109: *  LDU     (input) INTEGER
  110: *          The leading dimension of the array U. LDU >= max(1,M) if
  111: *          JOBU = 'U'; LDU >= 1 otherwise.
  112: *
  113: *  V       (output) DOUBLE PRECISION array, dimension (LDV,P)
  114: *          If JOBV = 'V', V contains the orthogonal matrix V.
  115: *          If JOBV = 'N', V is not referenced.
  116: *
  117: *  LDV     (input) INTEGER
  118: *          The leading dimension of the array V. LDV >= max(1,P) if
  119: *          JOBV = 'V'; LDV >= 1 otherwise.
  120: *
  121: *  Q       (output) DOUBLE PRECISION array, dimension (LDQ,N)
  122: *          If JOBQ = 'Q', Q contains the orthogonal matrix Q.
  123: *          If JOBQ = 'N', Q is not referenced.
  124: *
  125: *  LDQ     (input) INTEGER
  126: *          The leading dimension of the array Q. LDQ >= max(1,N) if
  127: *          JOBQ = 'Q'; LDQ >= 1 otherwise.
  128: *
  129: *  IWORK   (workspace) INTEGER array, dimension (N)
  130: *
  131: *  TAU     (workspace) DOUBLE PRECISION array, dimension (N)
  132: *
  133: *  WORK    (workspace) DOUBLE PRECISION array, dimension (max(3*N,M,P))
  134: *
  135: *  INFO    (output) INTEGER
  136: *          = 0:  successful exit
  137: *          < 0:  if INFO = -i, the i-th argument had an illegal value.
  138: *
  139: *
  140: *  Further Details
  141: *  ===============
  142: *
  143: *  The subroutine uses LAPACK subroutine DGEQPF for the QR factorization
  144: *  with column pivoting to detect the effective numerical rank of the
  145: *  a matrix. It may be replaced by a better rank determination strategy.
  146: *
  147: *  =====================================================================
  148: *
  149: *     .. Parameters ..
  150:       DOUBLE PRECISION   ZERO, ONE
  151:       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0 )
  152: *     ..
  153: *     .. Local Scalars ..
  154:       LOGICAL            FORWRD, WANTQ, WANTU, WANTV
  155:       INTEGER            I, J
  156: *     ..
  157: *     .. External Functions ..
  158:       LOGICAL            LSAME
  159:       EXTERNAL           LSAME
  160: *     ..
  161: *     .. External Subroutines ..
  162:       EXTERNAL           DGEQPF, DGEQR2, DGERQ2, DLACPY, DLAPMT, DLASET,
  163:      $                   DORG2R, DORM2R, DORMR2, XERBLA
  164: *     ..
  165: *     .. Intrinsic Functions ..
  166:       INTRINSIC          ABS, MAX, MIN
  167: *     ..
  168: *     .. Executable Statements ..
  169: *
  170: *     Test the input parameters
  171: *
  172:       WANTU = LSAME( JOBU, 'U' )
  173:       WANTV = LSAME( JOBV, 'V' )
  174:       WANTQ = LSAME( JOBQ, 'Q' )
  175:       FORWRD = .TRUE.
  176: *
  177:       INFO = 0
  178:       IF( .NOT.( WANTU .OR. LSAME( JOBU, 'N' ) ) ) THEN
  179:          INFO = -1
  180:       ELSE IF( .NOT.( WANTV .OR. LSAME( JOBV, 'N' ) ) ) THEN
  181:          INFO = -2
  182:       ELSE IF( .NOT.( WANTQ .OR. LSAME( JOBQ, 'N' ) ) ) THEN
  183:          INFO = -3
  184:       ELSE IF( M.LT.0 ) THEN
  185:          INFO = -4
  186:       ELSE IF( P.LT.0 ) THEN
  187:          INFO = -5
  188:       ELSE IF( N.LT.0 ) THEN
  189:          INFO = -6
  190:       ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
  191:          INFO = -8
  192:       ELSE IF( LDB.LT.MAX( 1, P ) ) THEN
  193:          INFO = -10
  194:       ELSE IF( LDU.LT.1 .OR. ( WANTU .AND. LDU.LT.M ) ) THEN
  195:          INFO = -16
  196:       ELSE IF( LDV.LT.1 .OR. ( WANTV .AND. LDV.LT.P ) ) THEN
  197:          INFO = -18
  198:       ELSE IF( LDQ.LT.1 .OR. ( WANTQ .AND. LDQ.LT.N ) ) THEN
  199:          INFO = -20
  200:       END IF
  201:       IF( INFO.NE.0 ) THEN
  202:          CALL XERBLA( 'DGGSVP', -INFO )
  203:          RETURN
  204:       END IF
  205: *
  206: *     QR with column pivoting of B: B*P = V*( S11 S12 )
  207: *                                           (  0   0  )
  208: *
  209:       DO 10 I = 1, N
  210:          IWORK( I ) = 0
  211:    10 CONTINUE
  212:       CALL DGEQPF( P, N, B, LDB, IWORK, TAU, WORK, INFO )
  213: *
  214: *     Update A := A*P
  215: *
  216:       CALL DLAPMT( FORWRD, M, N, A, LDA, IWORK )
  217: *
  218: *     Determine the effective rank of matrix B.
  219: *
  220:       L = 0
  221:       DO 20 I = 1, MIN( P, N )
  222:          IF( ABS( B( I, I ) ).GT.TOLB )
  223:      $      L = L + 1
  224:    20 CONTINUE
  225: *
  226:       IF( WANTV ) THEN
  227: *
  228: *        Copy the details of V, and form V.
  229: *
  230:          CALL DLASET( 'Full', P, P, ZERO, ZERO, V, LDV )
  231:          IF( P.GT.1 )
  232:      $      CALL DLACPY( 'Lower', P-1, N, B( 2, 1 ), LDB, V( 2, 1 ),
  233:      $                   LDV )
  234:          CALL DORG2R( P, P, MIN( P, N ), V, LDV, TAU, WORK, INFO )
  235:       END IF
  236: *
  237: *     Clean up B
  238: *
  239:       DO 40 J = 1, L - 1
  240:          DO 30 I = J + 1, L
  241:             B( I, J ) = ZERO
  242:    30    CONTINUE
  243:    40 CONTINUE
  244:       IF( P.GT.L )
  245:      $   CALL DLASET( 'Full', P-L, N, ZERO, ZERO, B( L+1, 1 ), LDB )
  246: *
  247:       IF( WANTQ ) THEN
  248: *
  249: *        Set Q = I and Update Q := Q*P
  250: *
  251:          CALL DLASET( 'Full', N, N, ZERO, ONE, Q, LDQ )
  252:          CALL DLAPMT( FORWRD, N, N, Q, LDQ, IWORK )
  253:       END IF
  254: *
  255:       IF( P.GE.L .AND. N.NE.L ) THEN
  256: *
  257: *        RQ factorization of (S11 S12): ( S11 S12 ) = ( 0 S12 )*Z
  258: *
  259:          CALL DGERQ2( L, N, B, LDB, TAU, WORK, INFO )
  260: *
  261: *        Update A := A*Z'
  262: *
  263:          CALL DORMR2( 'Right', 'Transpose', M, N, L, B, LDB, TAU, A,
  264:      $                LDA, WORK, INFO )
  265: *
  266:          IF( WANTQ ) THEN
  267: *
  268: *           Update Q := Q*Z'
  269: *
  270:             CALL DORMR2( 'Right', 'Transpose', N, N, L, B, LDB, TAU, Q,
  271:      $                   LDQ, WORK, INFO )
  272:          END IF
  273: *
  274: *        Clean up B
  275: *
  276:          CALL DLASET( 'Full', L, N-L, ZERO, ZERO, B, LDB )
  277:          DO 60 J = N - L + 1, N
  278:             DO 50 I = J - N + L + 1, L
  279:                B( I, J ) = ZERO
  280:    50       CONTINUE
  281:    60    CONTINUE
  282: *
  283:       END IF
  284: *
  285: *     Let              N-L     L
  286: *                A = ( A11    A12 ) M,
  287: *
  288: *     then the following does the complete QR decomposition of A11:
  289: *
  290: *              A11 = U*(  0  T12 )*P1'
  291: *                      (  0   0  )
  292: *
  293:       DO 70 I = 1, N - L
  294:          IWORK( I ) = 0
  295:    70 CONTINUE
  296:       CALL DGEQPF( M, N-L, A, LDA, IWORK, TAU, WORK, INFO )
  297: *
  298: *     Determine the effective rank of A11
  299: *
  300:       K = 0
  301:       DO 80 I = 1, MIN( M, N-L )
  302:          IF( ABS( A( I, I ) ).GT.TOLA )
  303:      $      K = K + 1
  304:    80 CONTINUE
  305: *
  306: *     Update A12 := U'*A12, where A12 = A( 1:M, N-L+1:N )
  307: *
  308:       CALL DORM2R( 'Left', 'Transpose', M, L, MIN( M, N-L ), A, LDA,
  309:      $             TAU, A( 1, N-L+1 ), LDA, WORK, INFO )
  310: *
  311:       IF( WANTU ) THEN
  312: *
  313: *        Copy the details of U, and form U
  314: *
  315:          CALL DLASET( 'Full', M, M, ZERO, ZERO, U, LDU )
  316:          IF( M.GT.1 )
  317:      $      CALL DLACPY( 'Lower', M-1, N-L, A( 2, 1 ), LDA, U( 2, 1 ),
  318:      $                   LDU )
  319:          CALL DORG2R( M, M, MIN( M, N-L ), U, LDU, TAU, WORK, INFO )
  320:       END IF
  321: *
  322:       IF( WANTQ ) THEN
  323: *
  324: *        Update Q( 1:N, 1:N-L )  = Q( 1:N, 1:N-L )*P1
  325: *
  326:          CALL DLAPMT( FORWRD, N, N-L, Q, LDQ, IWORK )
  327:       END IF
  328: *
  329: *     Clean up A: set the strictly lower triangular part of
  330: *     A(1:K, 1:K) = 0, and A( K+1:M, 1:N-L ) = 0.
  331: *
  332:       DO 100 J = 1, K - 1
  333:          DO 90 I = J + 1, K
  334:             A( I, J ) = ZERO
  335:    90    CONTINUE
  336:   100 CONTINUE
  337:       IF( M.GT.K )
  338:      $   CALL DLASET( 'Full', M-K, N-L, ZERO, ZERO, A( K+1, 1 ), LDA )
  339: *
  340:       IF( N-L.GT.K ) THEN
  341: *
  342: *        RQ factorization of ( T11 T12 ) = ( 0 T12 )*Z1
  343: *
  344:          CALL DGERQ2( K, N-L, A, LDA, TAU, WORK, INFO )
  345: *
  346:          IF( WANTQ ) THEN
  347: *
  348: *           Update Q( 1:N,1:N-L ) = Q( 1:N,1:N-L )*Z1'
  349: *
  350:             CALL DORMR2( 'Right', 'Transpose', N, N-L, K, A, LDA, TAU,
  351:      $                   Q, LDQ, WORK, INFO )
  352:          END IF
  353: *
  354: *        Clean up A
  355: *
  356:          CALL DLASET( 'Full', K, N-L-K, ZERO, ZERO, A, LDA )
  357:          DO 120 J = N - L - K + 1, N - L
  358:             DO 110 I = J - N + L + K + 1, K
  359:                A( I, J ) = ZERO
  360:   110       CONTINUE
  361:   120    CONTINUE
  362: *
  363:       END IF
  364: *
  365:       IF( M.GT.K ) THEN
  366: *
  367: *        QR factorization of A( K+1:M,N-L+1:N )
  368: *
  369:          CALL DGEQR2( M-K, L, A( K+1, N-L+1 ), LDA, TAU, WORK, INFO )
  370: *
  371:          IF( WANTU ) THEN
  372: *
  373: *           Update U(:,K+1:M) := U(:,K+1:M)*U1
  374: *
  375:             CALL DORM2R( 'Right', 'No transpose', M, M-K, MIN( M-K, L ),
  376:      $                   A( K+1, N-L+1 ), LDA, TAU, U( 1, K+1 ), LDU,
  377:      $                   WORK, INFO )
  378:          END IF
  379: *
  380: *        Clean up
  381: *
  382:          DO 140 J = N - L + 1, N
  383:             DO 130 I = J - N + K + L + 1, M
  384:                A( I, J ) = ZERO
  385:   130       CONTINUE
  386:   140    CONTINUE
  387: *
  388:       END IF
  389: *
  390:       RETURN
  391: *
  392: *     End of DGGSVP
  393: *
  394:       END

CVSweb interface <joel.bertrand@systella.fr>