File:  [local] / rpl / lapack / lapack / dgbbrd.f
Revision 1.18: download - view: text, annotated - select for diffs - revision graph
Mon Aug 7 08:38:47 2023 UTC (9 months, 1 week ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_1_35, rpl-4_1_34, HEAD
Première mise à jour de lapack et blas.

    1: *> \brief \b DGBBRD
    2: *
    3: *  =========== DOCUMENTATION ===========
    4: *
    5: * Online html documentation available at
    6: *            http://www.netlib.org/lapack/explore-html/
    7: *
    8: *> \htmlonly
    9: *> Download DGBBRD + dependencies
   10: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgbbrd.f">
   11: *> [TGZ]</a>
   12: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgbbrd.f">
   13: *> [ZIP]</a>
   14: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgbbrd.f">
   15: *> [TXT]</a>
   16: *> \endhtmlonly
   17: *
   18: *  Definition:
   19: *  ===========
   20: *
   21: *       SUBROUTINE DGBBRD( VECT, M, N, NCC, KL, KU, AB, LDAB, D, E, Q,
   22: *                          LDQ, PT, LDPT, C, LDC, WORK, INFO )
   23: *
   24: *       .. Scalar Arguments ..
   25: *       CHARACTER          VECT
   26: *       INTEGER            INFO, KL, KU, LDAB, LDC, LDPT, LDQ, M, N, NCC
   27: *       ..
   28: *       .. Array Arguments ..
   29: *       DOUBLE PRECISION   AB( LDAB, * ), C( LDC, * ), D( * ), E( * ),
   30: *      $                   PT( LDPT, * ), Q( LDQ, * ), WORK( * )
   31: *       ..
   32: *
   33: *
   34: *> \par Purpose:
   35: *  =============
   36: *>
   37: *> \verbatim
   38: *>
   39: *> DGBBRD reduces a real general m-by-n band matrix A to upper
   40: *> bidiagonal form B by an orthogonal transformation: Q**T * A * P = B.
   41: *>
   42: *> The routine computes B, and optionally forms Q or P**T, or computes
   43: *> Q**T*C for a given matrix C.
   44: *> \endverbatim
   45: *
   46: *  Arguments:
   47: *  ==========
   48: *
   49: *> \param[in] VECT
   50: *> \verbatim
   51: *>          VECT is CHARACTER*1
   52: *>          Specifies whether or not the matrices Q and P**T are to be
   53: *>          formed.
   54: *>          = 'N': do not form Q or P**T;
   55: *>          = 'Q': form Q only;
   56: *>          = 'P': form P**T only;
   57: *>          = 'B': form both.
   58: *> \endverbatim
   59: *>
   60: *> \param[in] M
   61: *> \verbatim
   62: *>          M is INTEGER
   63: *>          The number of rows of the matrix A.  M >= 0.
   64: *> \endverbatim
   65: *>
   66: *> \param[in] N
   67: *> \verbatim
   68: *>          N is INTEGER
   69: *>          The number of columns of the matrix A.  N >= 0.
   70: *> \endverbatim
   71: *>
   72: *> \param[in] NCC
   73: *> \verbatim
   74: *>          NCC is INTEGER
   75: *>          The number of columns of the matrix C.  NCC >= 0.
   76: *> \endverbatim
   77: *>
   78: *> \param[in] KL
   79: *> \verbatim
   80: *>          KL is INTEGER
   81: *>          The number of subdiagonals of the matrix A. KL >= 0.
   82: *> \endverbatim
   83: *>
   84: *> \param[in] KU
   85: *> \verbatim
   86: *>          KU is INTEGER
   87: *>          The number of superdiagonals of the matrix A. KU >= 0.
   88: *> \endverbatim
   89: *>
   90: *> \param[in,out] AB
   91: *> \verbatim
   92: *>          AB is DOUBLE PRECISION array, dimension (LDAB,N)
   93: *>          On entry, the m-by-n band matrix A, stored in rows 1 to
   94: *>          KL+KU+1. The j-th column of A is stored in the j-th column of
   95: *>          the array AB as follows:
   96: *>          AB(ku+1+i-j,j) = A(i,j) for max(1,j-ku)<=i<=min(m,j+kl).
   97: *>          On exit, A is overwritten by values generated during the
   98: *>          reduction.
   99: *> \endverbatim
  100: *>
  101: *> \param[in] LDAB
  102: *> \verbatim
  103: *>          LDAB is INTEGER
  104: *>          The leading dimension of the array A. LDAB >= KL+KU+1.
  105: *> \endverbatim
  106: *>
  107: *> \param[out] D
  108: *> \verbatim
  109: *>          D is DOUBLE PRECISION array, dimension (min(M,N))
  110: *>          The diagonal elements of the bidiagonal matrix B.
  111: *> \endverbatim
  112: *>
  113: *> \param[out] E
  114: *> \verbatim
  115: *>          E is DOUBLE PRECISION array, dimension (min(M,N)-1)
  116: *>          The superdiagonal elements of the bidiagonal matrix B.
  117: *> \endverbatim
  118: *>
  119: *> \param[out] Q
  120: *> \verbatim
  121: *>          Q is DOUBLE PRECISION array, dimension (LDQ,M)
  122: *>          If VECT = 'Q' or 'B', the m-by-m orthogonal matrix Q.
  123: *>          If VECT = 'N' or 'P', the array Q is not referenced.
  124: *> \endverbatim
  125: *>
  126: *> \param[in] LDQ
  127: *> \verbatim
  128: *>          LDQ is INTEGER
  129: *>          The leading dimension of the array Q.
  130: *>          LDQ >= max(1,M) if VECT = 'Q' or 'B'; LDQ >= 1 otherwise.
  131: *> \endverbatim
  132: *>
  133: *> \param[out] PT
  134: *> \verbatim
  135: *>          PT is DOUBLE PRECISION array, dimension (LDPT,N)
  136: *>          If VECT = 'P' or 'B', the n-by-n orthogonal matrix P'.
  137: *>          If VECT = 'N' or 'Q', the array PT is not referenced.
  138: *> \endverbatim
  139: *>
  140: *> \param[in] LDPT
  141: *> \verbatim
  142: *>          LDPT is INTEGER
  143: *>          The leading dimension of the array PT.
  144: *>          LDPT >= max(1,N) if VECT = 'P' or 'B'; LDPT >= 1 otherwise.
  145: *> \endverbatim
  146: *>
  147: *> \param[in,out] C
  148: *> \verbatim
  149: *>          C is DOUBLE PRECISION array, dimension (LDC,NCC)
  150: *>          On entry, an m-by-ncc matrix C.
  151: *>          On exit, C is overwritten by Q**T*C.
  152: *>          C is not referenced if NCC = 0.
  153: *> \endverbatim
  154: *>
  155: *> \param[in] LDC
  156: *> \verbatim
  157: *>          LDC is INTEGER
  158: *>          The leading dimension of the array C.
  159: *>          LDC >= max(1,M) if NCC > 0; LDC >= 1 if NCC = 0.
  160: *> \endverbatim
  161: *>
  162: *> \param[out] WORK
  163: *> \verbatim
  164: *>          WORK is DOUBLE PRECISION array, dimension (2*max(M,N))
  165: *> \endverbatim
  166: *>
  167: *> \param[out] INFO
  168: *> \verbatim
  169: *>          INFO is INTEGER
  170: *>          = 0:  successful exit.
  171: *>          < 0:  if INFO = -i, the i-th argument had an illegal value.
  172: *> \endverbatim
  173: *
  174: *  Authors:
  175: *  ========
  176: *
  177: *> \author Univ. of Tennessee
  178: *> \author Univ. of California Berkeley
  179: *> \author Univ. of Colorado Denver
  180: *> \author NAG Ltd.
  181: *
  182: *> \ingroup doubleGBcomputational
  183: *
  184: *  =====================================================================
  185:       SUBROUTINE DGBBRD( VECT, M, N, NCC, KL, KU, AB, LDAB, D, E, Q,
  186:      $                   LDQ, PT, LDPT, C, LDC, WORK, INFO )
  187: *
  188: *  -- LAPACK computational routine --
  189: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
  190: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  191: *
  192: *     .. Scalar Arguments ..
  193:       CHARACTER          VECT
  194:       INTEGER            INFO, KL, KU, LDAB, LDC, LDPT, LDQ, M, N, NCC
  195: *     ..
  196: *     .. Array Arguments ..
  197:       DOUBLE PRECISION   AB( LDAB, * ), C( LDC, * ), D( * ), E( * ),
  198:      $                   PT( LDPT, * ), Q( LDQ, * ), WORK( * )
  199: *     ..
  200: *
  201: *  =====================================================================
  202: *
  203: *     .. Parameters ..
  204:       DOUBLE PRECISION   ZERO, ONE
  205:       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0 )
  206: *     ..
  207: *     .. Local Scalars ..
  208:       LOGICAL            WANTB, WANTC, WANTPT, WANTQ
  209:       INTEGER            I, INCA, J, J1, J2, KB, KB1, KK, KLM, KLU1,
  210:      $                   KUN, L, MINMN, ML, ML0, MN, MU, MU0, NR, NRT
  211:       DOUBLE PRECISION   RA, RB, RC, RS
  212: *     ..
  213: *     .. External Subroutines ..
  214:       EXTERNAL           DLARGV, DLARTG, DLARTV, DLASET, DROT, XERBLA
  215: *     ..
  216: *     .. Intrinsic Functions ..
  217:       INTRINSIC          MAX, MIN
  218: *     ..
  219: *     .. External Functions ..
  220:       LOGICAL            LSAME
  221:       EXTERNAL           LSAME
  222: *     ..
  223: *     .. Executable Statements ..
  224: *
  225: *     Test the input parameters
  226: *
  227:       WANTB = LSAME( VECT, 'B' )
  228:       WANTQ = LSAME( VECT, 'Q' ) .OR. WANTB
  229:       WANTPT = LSAME( VECT, 'P' ) .OR. WANTB
  230:       WANTC = NCC.GT.0
  231:       KLU1 = KL + KU + 1
  232:       INFO = 0
  233:       IF( .NOT.WANTQ .AND. .NOT.WANTPT .AND. .NOT.LSAME( VECT, 'N' ) )
  234:      $     THEN
  235:          INFO = -1
  236:       ELSE IF( M.LT.0 ) THEN
  237:          INFO = -2
  238:       ELSE IF( N.LT.0 ) THEN
  239:          INFO = -3
  240:       ELSE IF( NCC.LT.0 ) THEN
  241:          INFO = -4
  242:       ELSE IF( KL.LT.0 ) THEN
  243:          INFO = -5
  244:       ELSE IF( KU.LT.0 ) THEN
  245:          INFO = -6
  246:       ELSE IF( LDAB.LT.KLU1 ) THEN
  247:          INFO = -8
  248:       ELSE IF( LDQ.LT.1 .OR. WANTQ .AND. LDQ.LT.MAX( 1, M ) ) THEN
  249:          INFO = -12
  250:       ELSE IF( LDPT.LT.1 .OR. WANTPT .AND. LDPT.LT.MAX( 1, N ) ) THEN
  251:          INFO = -14
  252:       ELSE IF( LDC.LT.1 .OR. WANTC .AND. LDC.LT.MAX( 1, M ) ) THEN
  253:          INFO = -16
  254:       END IF
  255:       IF( INFO.NE.0 ) THEN
  256:          CALL XERBLA( 'DGBBRD', -INFO )
  257:          RETURN
  258:       END IF
  259: *
  260: *     Initialize Q and P**T to the unit matrix, if needed
  261: *
  262:       IF( WANTQ )
  263:      $   CALL DLASET( 'Full', M, M, ZERO, ONE, Q, LDQ )
  264:       IF( WANTPT )
  265:      $   CALL DLASET( 'Full', N, N, ZERO, ONE, PT, LDPT )
  266: *
  267: *     Quick return if possible.
  268: *
  269:       IF( M.EQ.0 .OR. N.EQ.0 )
  270:      $   RETURN
  271: *
  272:       MINMN = MIN( M, N )
  273: *
  274:       IF( KL+KU.GT.1 ) THEN
  275: *
  276: *        Reduce to upper bidiagonal form if KU > 0; if KU = 0, reduce
  277: *        first to lower bidiagonal form and then transform to upper
  278: *        bidiagonal
  279: *
  280:          IF( KU.GT.0 ) THEN
  281:             ML0 = 1
  282:             MU0 = 2
  283:          ELSE
  284:             ML0 = 2
  285:             MU0 = 1
  286:          END IF
  287: *
  288: *        Wherever possible, plane rotations are generated and applied in
  289: *        vector operations of length NR over the index set J1:J2:KLU1.
  290: *
  291: *        The sines of the plane rotations are stored in WORK(1:max(m,n))
  292: *        and the cosines in WORK(max(m,n)+1:2*max(m,n)).
  293: *
  294:          MN = MAX( M, N )
  295:          KLM = MIN( M-1, KL )
  296:          KUN = MIN( N-1, KU )
  297:          KB = KLM + KUN
  298:          KB1 = KB + 1
  299:          INCA = KB1*LDAB
  300:          NR = 0
  301:          J1 = KLM + 2
  302:          J2 = 1 - KUN
  303: *
  304:          DO 90 I = 1, MINMN
  305: *
  306: *           Reduce i-th column and i-th row of matrix to bidiagonal form
  307: *
  308:             ML = KLM + 1
  309:             MU = KUN + 1
  310:             DO 80 KK = 1, KB
  311:                J1 = J1 + KB
  312:                J2 = J2 + KB
  313: *
  314: *              generate plane rotations to annihilate nonzero elements
  315: *              which have been created below the band
  316: *
  317:                IF( NR.GT.0 )
  318:      $            CALL DLARGV( NR, AB( KLU1, J1-KLM-1 ), INCA,
  319:      $                         WORK( J1 ), KB1, WORK( MN+J1 ), KB1 )
  320: *
  321: *              apply plane rotations from the left
  322: *
  323:                DO 10 L = 1, KB
  324:                   IF( J2-KLM+L-1.GT.N ) THEN
  325:                      NRT = NR - 1
  326:                   ELSE
  327:                      NRT = NR
  328:                   END IF
  329:                   IF( NRT.GT.0 )
  330:      $               CALL DLARTV( NRT, AB( KLU1-L, J1-KLM+L-1 ), INCA,
  331:      $                            AB( KLU1-L+1, J1-KLM+L-1 ), INCA,
  332:      $                            WORK( MN+J1 ), WORK( J1 ), KB1 )
  333:    10          CONTINUE
  334: *
  335:                IF( ML.GT.ML0 ) THEN
  336:                   IF( ML.LE.M-I+1 ) THEN
  337: *
  338: *                    generate plane rotation to annihilate a(i+ml-1,i)
  339: *                    within the band, and apply rotation from the left
  340: *
  341:                      CALL DLARTG( AB( KU+ML-1, I ), AB( KU+ML, I ),
  342:      $                            WORK( MN+I+ML-1 ), WORK( I+ML-1 ),
  343:      $                            RA )
  344:                      AB( KU+ML-1, I ) = RA
  345:                      IF( I.LT.N )
  346:      $                  CALL DROT( MIN( KU+ML-2, N-I ),
  347:      $                             AB( KU+ML-2, I+1 ), LDAB-1,
  348:      $                             AB( KU+ML-1, I+1 ), LDAB-1,
  349:      $                             WORK( MN+I+ML-1 ), WORK( I+ML-1 ) )
  350:                   END IF
  351:                   NR = NR + 1
  352:                   J1 = J1 - KB1
  353:                END IF
  354: *
  355:                IF( WANTQ ) THEN
  356: *
  357: *                 accumulate product of plane rotations in Q
  358: *
  359:                   DO 20 J = J1, J2, KB1
  360:                      CALL DROT( M, Q( 1, J-1 ), 1, Q( 1, J ), 1,
  361:      $                          WORK( MN+J ), WORK( J ) )
  362:    20             CONTINUE
  363:                END IF
  364: *
  365:                IF( WANTC ) THEN
  366: *
  367: *                 apply plane rotations to C
  368: *
  369:                   DO 30 J = J1, J2, KB1
  370:                      CALL DROT( NCC, C( J-1, 1 ), LDC, C( J, 1 ), LDC,
  371:      $                          WORK( MN+J ), WORK( J ) )
  372:    30             CONTINUE
  373:                END IF
  374: *
  375:                IF( J2+KUN.GT.N ) THEN
  376: *
  377: *                 adjust J2 to keep within the bounds of the matrix
  378: *
  379:                   NR = NR - 1
  380:                   J2 = J2 - KB1
  381:                END IF
  382: *
  383:                DO 40 J = J1, J2, KB1
  384: *
  385: *                 create nonzero element a(j-1,j+ku) above the band
  386: *                 and store it in WORK(n+1:2*n)
  387: *
  388:                   WORK( J+KUN ) = WORK( J )*AB( 1, J+KUN )
  389:                   AB( 1, J+KUN ) = WORK( MN+J )*AB( 1, J+KUN )
  390:    40          CONTINUE
  391: *
  392: *              generate plane rotations to annihilate nonzero elements
  393: *              which have been generated above the band
  394: *
  395:                IF( NR.GT.0 )
  396:      $            CALL DLARGV( NR, AB( 1, J1+KUN-1 ), INCA,
  397:      $                         WORK( J1+KUN ), KB1, WORK( MN+J1+KUN ),
  398:      $                         KB1 )
  399: *
  400: *              apply plane rotations from the right
  401: *
  402:                DO 50 L = 1, KB
  403:                   IF( J2+L-1.GT.M ) THEN
  404:                      NRT = NR - 1
  405:                   ELSE
  406:                      NRT = NR
  407:                   END IF
  408:                   IF( NRT.GT.0 )
  409:      $               CALL DLARTV( NRT, AB( L+1, J1+KUN-1 ), INCA,
  410:      $                            AB( L, J1+KUN ), INCA,
  411:      $                            WORK( MN+J1+KUN ), WORK( J1+KUN ),
  412:      $                            KB1 )
  413:    50          CONTINUE
  414: *
  415:                IF( ML.EQ.ML0 .AND. MU.GT.MU0 ) THEN
  416:                   IF( MU.LE.N-I+1 ) THEN
  417: *
  418: *                    generate plane rotation to annihilate a(i,i+mu-1)
  419: *                    within the band, and apply rotation from the right
  420: *
  421:                      CALL DLARTG( AB( KU-MU+3, I+MU-2 ),
  422:      $                            AB( KU-MU+2, I+MU-1 ),
  423:      $                            WORK( MN+I+MU-1 ), WORK( I+MU-1 ),
  424:      $                            RA )
  425:                      AB( KU-MU+3, I+MU-2 ) = RA
  426:                      CALL DROT( MIN( KL+MU-2, M-I ),
  427:      $                          AB( KU-MU+4, I+MU-2 ), 1,
  428:      $                          AB( KU-MU+3, I+MU-1 ), 1,
  429:      $                          WORK( MN+I+MU-1 ), WORK( I+MU-1 ) )
  430:                   END IF
  431:                   NR = NR + 1
  432:                   J1 = J1 - KB1
  433:                END IF
  434: *
  435:                IF( WANTPT ) THEN
  436: *
  437: *                 accumulate product of plane rotations in P**T
  438: *
  439:                   DO 60 J = J1, J2, KB1
  440:                      CALL DROT( N, PT( J+KUN-1, 1 ), LDPT,
  441:      $                          PT( J+KUN, 1 ), LDPT, WORK( MN+J+KUN ),
  442:      $                          WORK( J+KUN ) )
  443:    60             CONTINUE
  444:                END IF
  445: *
  446:                IF( J2+KB.GT.M ) THEN
  447: *
  448: *                 adjust J2 to keep within the bounds of the matrix
  449: *
  450:                   NR = NR - 1
  451:                   J2 = J2 - KB1
  452:                END IF
  453: *
  454:                DO 70 J = J1, J2, KB1
  455: *
  456: *                 create nonzero element a(j+kl+ku,j+ku-1) below the
  457: *                 band and store it in WORK(1:n)
  458: *
  459:                   WORK( J+KB ) = WORK( J+KUN )*AB( KLU1, J+KUN )
  460:                   AB( KLU1, J+KUN ) = WORK( MN+J+KUN )*AB( KLU1, J+KUN )
  461:    70          CONTINUE
  462: *
  463:                IF( ML.GT.ML0 ) THEN
  464:                   ML = ML - 1
  465:                ELSE
  466:                   MU = MU - 1
  467:                END IF
  468:    80       CONTINUE
  469:    90    CONTINUE
  470:       END IF
  471: *
  472:       IF( KU.EQ.0 .AND. KL.GT.0 ) THEN
  473: *
  474: *        A has been reduced to lower bidiagonal form
  475: *
  476: *        Transform lower bidiagonal form to upper bidiagonal by applying
  477: *        plane rotations from the left, storing diagonal elements in D
  478: *        and off-diagonal elements in E
  479: *
  480:          DO 100 I = 1, MIN( M-1, N )
  481:             CALL DLARTG( AB( 1, I ), AB( 2, I ), RC, RS, RA )
  482:             D( I ) = RA
  483:             IF( I.LT.N ) THEN
  484:                E( I ) = RS*AB( 1, I+1 )
  485:                AB( 1, I+1 ) = RC*AB( 1, I+1 )
  486:             END IF
  487:             IF( WANTQ )
  488:      $         CALL DROT( M, Q( 1, I ), 1, Q( 1, I+1 ), 1, RC, RS )
  489:             IF( WANTC )
  490:      $         CALL DROT( NCC, C( I, 1 ), LDC, C( I+1, 1 ), LDC, RC,
  491:      $                    RS )
  492:   100    CONTINUE
  493:          IF( M.LE.N )
  494:      $      D( M ) = AB( 1, M )
  495:       ELSE IF( KU.GT.0 ) THEN
  496: *
  497: *        A has been reduced to upper bidiagonal form
  498: *
  499:          IF( M.LT.N ) THEN
  500: *
  501: *           Annihilate a(m,m+1) by applying plane rotations from the
  502: *           right, storing diagonal elements in D and off-diagonal
  503: *           elements in E
  504: *
  505:             RB = AB( KU, M+1 )
  506:             DO 110 I = M, 1, -1
  507:                CALL DLARTG( AB( KU+1, I ), RB, RC, RS, RA )
  508:                D( I ) = RA
  509:                IF( I.GT.1 ) THEN
  510:                   RB = -RS*AB( KU, I )
  511:                   E( I-1 ) = RC*AB( KU, I )
  512:                END IF
  513:                IF( WANTPT )
  514:      $            CALL DROT( N, PT( I, 1 ), LDPT, PT( M+1, 1 ), LDPT,
  515:      $                       RC, RS )
  516:   110       CONTINUE
  517:          ELSE
  518: *
  519: *           Copy off-diagonal elements to E and diagonal elements to D
  520: *
  521:             DO 120 I = 1, MINMN - 1
  522:                E( I ) = AB( KU, I+1 )
  523:   120       CONTINUE
  524:             DO 130 I = 1, MINMN
  525:                D( I ) = AB( KU+1, I )
  526:   130       CONTINUE
  527:          END IF
  528:       ELSE
  529: *
  530: *        A is diagonal. Set elements of E to zero and copy diagonal
  531: *        elements to D.
  532: *
  533:          DO 140 I = 1, MINMN - 1
  534:             E( I ) = ZERO
  535:   140    CONTINUE
  536:          DO 150 I = 1, MINMN
  537:             D( I ) = AB( 1, I )
  538:   150    CONTINUE
  539:       END IF
  540:       RETURN
  541: *
  542: *     End of DGBBRD
  543: *
  544:       END

CVSweb interface <joel.bertrand@systella.fr>