Annotation of rpl/lapack/lapack/dgsvj1.f, revision 1.22

1.15      bertrand    1: *> \brief \b DGSVJ1 pre-processor for the routine dgesvj, applies Jacobi rotations targeting only particular pivots.
1.7       bertrand    2: *
                      3: *  =========== DOCUMENTATION ===========
                      4: *
1.17      bertrand    5: * Online html documentation available at
                      6: *            http://www.netlib.org/lapack/explore-html/
1.7       bertrand    7: *
                      8: *> \htmlonly
1.17      bertrand    9: *> Download DGSVJ1 + dependencies
                     10: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgsvj1.f">
                     11: *> [TGZ]</a>
                     12: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgsvj1.f">
                     13: *> [ZIP]</a>
                     14: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgsvj1.f">
1.7       bertrand   15: *> [TXT]</a>
1.17      bertrand   16: *> \endhtmlonly
1.7       bertrand   17: *
                     18: *  Definition:
                     19: *  ===========
                     20: *
                     21: *       SUBROUTINE DGSVJ1( JOBV, M, N, N1, A, LDA, D, SVA, MV, V, LDV,
                     22: *                          EPS, SFMIN, TOL, NSWEEP, WORK, LWORK, INFO )
1.17      bertrand   23: *
1.7       bertrand   24: *       .. Scalar Arguments ..
                     25: *       DOUBLE PRECISION   EPS, SFMIN, TOL
                     26: *       INTEGER            INFO, LDA, LDV, LWORK, M, MV, N, N1, NSWEEP
                     27: *       CHARACTER*1        JOBV
                     28: *       ..
                     29: *       .. Array Arguments ..
                     30: *       DOUBLE PRECISION   A( LDA, * ), D( N ), SVA( N ), V( LDV, * ),
                     31: *      $                   WORK( LWORK )
                     32: *       ..
1.17      bertrand   33: *
1.7       bertrand   34: *
                     35: *> \par Purpose:
                     36: *  =============
                     37: *>
                     38: *> \verbatim
                     39: *>
1.14      bertrand   40: *> DGSVJ1 is called from DGESVJ as a pre-processor and that is its main
                     41: *> purpose. It applies Jacobi rotations in the same way as DGESVJ does, but
1.7       bertrand   42: *> it targets only particular pivots and it does not check convergence
1.22    ! bertrand   43: *> (stopping criterion). Few tuning parameters (marked by [TP]) are
1.7       bertrand   44: *> available for the implementer.
                     45: *>
                     46: *> Further Details
                     47: *> ~~~~~~~~~~~~~~~
                     48: *> DGSVJ1 applies few sweeps of Jacobi rotations in the column space of
                     49: *> the input M-by-N matrix A. The pivot pairs are taken from the (1,2)
                     50: *> off-diagonal block in the corresponding N-by-N Gram matrix A^T * A. The
                     51: *> block-entries (tiles) of the (1,2) off-diagonal block are marked by the
                     52: *> [x]'s in the following scheme:
                     53: *>
                     54: *>    | *  *  * [x] [x] [x]|
                     55: *>    | *  *  * [x] [x] [x]|    Row-cycling in the nblr-by-nblc [x] blocks.
                     56: *>    | *  *  * [x] [x] [x]|    Row-cyclic pivoting inside each [x] block.
                     57: *>    |[x] [x] [x] *  *  * |
                     58: *>    |[x] [x] [x] *  *  * |
                     59: *>    |[x] [x] [x] *  *  * |
                     60: *>
                     61: *> In terms of the columns of A, the first N1 columns are rotated 'against'
                     62: *> the remaining N-N1 columns, trying to increase the angle between the
                     63: *> corresponding subspaces. The off-diagonal block is N1-by(N-N1) and it is
1.22    ! bertrand   64: *> tiled using quadratic tiles of side KBL. Here, KBL is a tuning parameter.
1.7       bertrand   65: *> The number of sweeps is given in NSWEEP and the orthogonality threshold
                     66: *> is given in TOL.
                     67: *> \endverbatim
                     68: *
                     69: *  Arguments:
                     70: *  ==========
                     71: *
                     72: *> \param[in] JOBV
                     73: *> \verbatim
                     74: *>          JOBV is CHARACTER*1
                     75: *>          Specifies whether the output from this procedure is used
                     76: *>          to compute the matrix V:
                     77: *>          = 'V': the product of the Jacobi rotations is accumulated
                     78: *>                 by postmulyiplying the N-by-N array V.
                     79: *>                (See the description of V.)
                     80: *>          = 'A': the product of the Jacobi rotations is accumulated
                     81: *>                 by postmulyiplying the MV-by-N array V.
                     82: *>                (See the descriptions of MV and V.)
                     83: *>          = 'N': the Jacobi rotations are not accumulated.
                     84: *> \endverbatim
                     85: *>
                     86: *> \param[in] M
                     87: *> \verbatim
                     88: *>          M is INTEGER
                     89: *>          The number of rows of the input matrix A.  M >= 0.
                     90: *> \endverbatim
                     91: *>
                     92: *> \param[in] N
                     93: *> \verbatim
                     94: *>          N is INTEGER
                     95: *>          The number of columns of the input matrix A.
                     96: *>          M >= N >= 0.
                     97: *> \endverbatim
                     98: *>
                     99: *> \param[in] N1
                    100: *> \verbatim
                    101: *>          N1 is INTEGER
                    102: *>          N1 specifies the 2 x 2 block partition, the first N1 columns are
                    103: *>          rotated 'against' the remaining N-N1 columns of A.
                    104: *> \endverbatim
                    105: *>
                    106: *> \param[in,out] A
                    107: *> \verbatim
                    108: *>          A is DOUBLE PRECISION array, dimension (LDA,N)
                    109: *>          On entry, M-by-N matrix A, such that A*diag(D) represents
                    110: *>          the input matrix.
                    111: *>          On exit,
                    112: *>          A_onexit * D_onexit represents the input matrix A*diag(D)
                    113: *>          post-multiplied by a sequence of Jacobi rotations, where the
                    114: *>          rotation threshold and the total number of sweeps are given in
                    115: *>          TOL and NSWEEP, respectively.
                    116: *>          (See the descriptions of N1, D, TOL and NSWEEP.)
                    117: *> \endverbatim
                    118: *>
                    119: *> \param[in] LDA
                    120: *> \verbatim
                    121: *>          LDA is INTEGER
                    122: *>          The leading dimension of the array A.  LDA >= max(1,M).
                    123: *> \endverbatim
                    124: *>
                    125: *> \param[in,out] D
                    126: *> \verbatim
                    127: *>          D is DOUBLE PRECISION array, dimension (N)
                    128: *>          The array D accumulates the scaling factors from the fast scaled
                    129: *>          Jacobi rotations.
                    130: *>          On entry, A*diag(D) represents the input matrix.
                    131: *>          On exit, A_onexit*diag(D_onexit) represents the input matrix
                    132: *>          post-multiplied by a sequence of Jacobi rotations, where the
                    133: *>          rotation threshold and the total number of sweeps are given in
                    134: *>          TOL and NSWEEP, respectively.
                    135: *>          (See the descriptions of N1, A, TOL and NSWEEP.)
                    136: *> \endverbatim
                    137: *>
                    138: *> \param[in,out] SVA
                    139: *> \verbatim
                    140: *>          SVA is DOUBLE PRECISION array, dimension (N)
                    141: *>          On entry, SVA contains the Euclidean norms of the columns of
                    142: *>          the matrix A*diag(D).
                    143: *>          On exit, SVA contains the Euclidean norms of the columns of
                    144: *>          the matrix onexit*diag(D_onexit).
                    145: *> \endverbatim
                    146: *>
                    147: *> \param[in] MV
                    148: *> \verbatim
                    149: *>          MV is INTEGER
1.21      bertrand  150: *>          If JOBV = 'A', then MV rows of V are post-multipled by a
                    151: *>                         sequence of Jacobi rotations.
                    152: *>          If JOBV = 'N', then MV is not referenced.
1.7       bertrand  153: *> \endverbatim
                    154: *>
                    155: *> \param[in,out] V
                    156: *> \verbatim
                    157: *>          V is DOUBLE PRECISION array, dimension (LDV,N)
1.21      bertrand  158: *>          If JOBV = 'V', then N rows of V are post-multipled by a
                    159: *>                         sequence of Jacobi rotations.
                    160: *>          If JOBV = 'A', then MV rows of V are post-multipled by a
                    161: *>                         sequence of Jacobi rotations.
                    162: *>          If JOBV = 'N', then V is not referenced.
1.7       bertrand  163: *> \endverbatim
                    164: *>
                    165: *> \param[in] LDV
                    166: *> \verbatim
                    167: *>          LDV is INTEGER
                    168: *>          The leading dimension of the array V,  LDV >= 1.
1.21      bertrand  169: *>          If JOBV = 'V', LDV >= N.
                    170: *>          If JOBV = 'A', LDV >= MV.
1.7       bertrand  171: *> \endverbatim
                    172: *>
                    173: *> \param[in] EPS
                    174: *> \verbatim
                    175: *>          EPS is DOUBLE PRECISION
                    176: *>          EPS = DLAMCH('Epsilon')
                    177: *> \endverbatim
                    178: *>
                    179: *> \param[in] SFMIN
                    180: *> \verbatim
                    181: *>          SFMIN is DOUBLE PRECISION
                    182: *>          SFMIN = DLAMCH('Safe Minimum')
                    183: *> \endverbatim
                    184: *>
                    185: *> \param[in] TOL
                    186: *> \verbatim
                    187: *>          TOL is DOUBLE PRECISION
                    188: *>          TOL is the threshold for Jacobi rotations. For a pair
                    189: *>          A(:,p), A(:,q) of pivot columns, the Jacobi rotation is
1.21      bertrand  190: *>          applied only if DABS(COS(angle(A(:,p),A(:,q)))) > TOL.
1.7       bertrand  191: *> \endverbatim
                    192: *>
                    193: *> \param[in] NSWEEP
                    194: *> \verbatim
                    195: *>          NSWEEP is INTEGER
                    196: *>          NSWEEP is the number of sweeps of Jacobi rotations to be
                    197: *>          performed.
                    198: *> \endverbatim
                    199: *>
                    200: *> \param[out] WORK
                    201: *> \verbatim
                    202: *>          WORK is DOUBLE PRECISION array, dimension (LWORK)
                    203: *> \endverbatim
                    204: *>
                    205: *> \param[in] LWORK
                    206: *> \verbatim
                    207: *>          LWORK is INTEGER
1.21      bertrand  208: *>          LWORK is the dimension of WORK. LWORK >= M.
1.7       bertrand  209: *> \endverbatim
                    210: *>
                    211: *> \param[out] INFO
                    212: *> \verbatim
                    213: *>          INFO is INTEGER
1.21      bertrand  214: *>          = 0:  successful exit.
                    215: *>          < 0:  if INFO = -i, then the i-th argument had an illegal value
1.7       bertrand  216: *> \endverbatim
                    217: *
                    218: *  Authors:
                    219: *  ========
                    220: *
1.17      bertrand  221: *> \author Univ. of Tennessee
                    222: *> \author Univ. of California Berkeley
                    223: *> \author Univ. of Colorado Denver
                    224: *> \author NAG Ltd.
1.7       bertrand  225: *
                    226: *> \ingroup doubleOTHERcomputational
                    227: *
                    228: *> \par Contributors:
                    229: *  ==================
                    230: *>
                    231: *> Zlatko Drmac (Zagreb, Croatia) and Kresimir Veselic (Hagen, Germany)
                    232: *
                    233: *  =====================================================================
1.1       bertrand  234:       SUBROUTINE DGSVJ1( JOBV, M, N, N1, A, LDA, D, SVA, MV, V, LDV,
1.6       bertrand  235:      $                   EPS, SFMIN, TOL, NSWEEP, WORK, LWORK, INFO )
1.1       bertrand  236: *
1.22    ! bertrand  237: *  -- LAPACK computational routine --
1.1       bertrand  238: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
                    239: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
                    240: *
                    241: *     .. Scalar Arguments ..
                    242:       DOUBLE PRECISION   EPS, SFMIN, TOL
                    243:       INTEGER            INFO, LDA, LDV, LWORK, M, MV, N, N1, NSWEEP
                    244:       CHARACTER*1        JOBV
                    245: *     ..
                    246: *     .. Array Arguments ..
                    247:       DOUBLE PRECISION   A( LDA, * ), D( N ), SVA( N ), V( LDV, * ),
1.6       bertrand  248:      $                   WORK( LWORK )
1.1       bertrand  249: *     ..
                    250: *
                    251: *  =====================================================================
                    252: *
                    253: *     .. Local Parameters ..
1.9       bertrand  254:       DOUBLE PRECISION   ZERO, HALF, ONE
                    255:       PARAMETER          ( ZERO = 0.0D0, HALF = 0.5D0, ONE = 1.0D0 )
1.1       bertrand  256: *     ..
                    257: *     .. Local Scalars ..
                    258:       DOUBLE PRECISION   AAPP, AAPP0, AAPQ, AAQQ, APOAQ, AQOAP, BIG,
1.6       bertrand  259:      $                   BIGTHETA, CS, LARGE, MXAAPQ, MXSINJ, ROOTBIG,
                    260:      $                   ROOTEPS, ROOTSFMIN, ROOTTOL, SMALL, SN, T,
                    261:      $                   TEMP1, THETA, THSIGN
1.1       bertrand  262:       INTEGER            BLSKIP, EMPTSW, i, ibr, igl, IERR, IJBLSK,
1.6       bertrand  263:      $                   ISWROT, jbc, jgl, KBL, MVL, NOTROT, nblc, nblr,
                    264:      $                   p, PSKIPPED, q, ROWSKIP, SWBAND
1.1       bertrand  265:       LOGICAL            APPLV, ROTOK, RSVEC
                    266: *     ..
                    267: *     .. Local Arrays ..
                    268:       DOUBLE PRECISION   FASTR( 5 )
                    269: *     ..
                    270: *     .. Intrinsic Functions ..
1.14      bertrand  271:       INTRINSIC          DABS, MAX, DBLE, MIN, DSIGN, DSQRT
1.1       bertrand  272: *     ..
                    273: *     .. External Functions ..
                    274:       DOUBLE PRECISION   DDOT, DNRM2
                    275:       INTEGER            IDAMAX
                    276:       LOGICAL            LSAME
                    277:       EXTERNAL           IDAMAX, LSAME, DDOT, DNRM2
                    278: *     ..
                    279: *     .. External Subroutines ..
1.19      bertrand  280:       EXTERNAL           DAXPY, DCOPY, DLASCL, DLASSQ, DROTM, DSWAP,
                    281:      $                   XERBLA
1.1       bertrand  282: *     ..
                    283: *     .. Executable Statements ..
                    284: *
                    285: *     Test the input parameters.
                    286: *
                    287:       APPLV = LSAME( JOBV, 'A' )
                    288:       RSVEC = LSAME( JOBV, 'V' )
                    289:       IF( .NOT.( RSVEC .OR. APPLV .OR. LSAME( JOBV, 'N' ) ) ) THEN
                    290:          INFO = -1
                    291:       ELSE IF( M.LT.0 ) THEN
                    292:          INFO = -2
                    293:       ELSE IF( ( N.LT.0 ) .OR. ( N.GT.M ) ) THEN
                    294:          INFO = -3
                    295:       ELSE IF( N1.LT.0 ) THEN
                    296:          INFO = -4
                    297:       ELSE IF( LDA.LT.M ) THEN
                    298:          INFO = -6
1.4       bertrand  299:       ELSE IF( ( RSVEC.OR.APPLV ) .AND. ( MV.LT.0 ) ) THEN
1.1       bertrand  300:          INFO = -9
1.17      bertrand  301:       ELSE IF( ( RSVEC.AND.( LDV.LT.N ) ).OR.
1.6       bertrand  302:      $         ( APPLV.AND.( LDV.LT.MV ) )  ) THEN
1.1       bertrand  303:          INFO = -11
                    304:       ELSE IF( TOL.LE.EPS ) THEN
                    305:          INFO = -14
                    306:       ELSE IF( NSWEEP.LT.0 ) THEN
                    307:          INFO = -15
                    308:       ELSE IF( LWORK.LT.M ) THEN
                    309:          INFO = -17
                    310:       ELSE
                    311:          INFO = 0
                    312:       END IF
                    313: *
                    314: *     #:(
                    315:       IF( INFO.NE.0 ) THEN
                    316:          CALL XERBLA( 'DGSVJ1', -INFO )
                    317:          RETURN
                    318:       END IF
                    319: *
                    320:       IF( RSVEC ) THEN
                    321:          MVL = N
                    322:       ELSE IF( APPLV ) THEN
                    323:          MVL = MV
                    324:       END IF
                    325:       RSVEC = RSVEC .OR. APPLV
                    326: 
                    327:       ROOTEPS = DSQRT( EPS )
                    328:       ROOTSFMIN = DSQRT( SFMIN )
                    329:       SMALL = SFMIN / EPS
                    330:       BIG = ONE / SFMIN
                    331:       ROOTBIG = ONE / ROOTSFMIN
                    332:       LARGE = BIG / DSQRT( DBLE( M*N ) )
                    333:       BIGTHETA = ONE / ROOTEPS
                    334:       ROOTTOL = DSQRT( TOL )
                    335: *
                    336: *     .. Initialize the right singular vector matrix ..
                    337: *
                    338: *     RSVEC = LSAME( JOBV, 'Y' )
                    339: *
                    340:       EMPTSW = N1*( N-N1 )
                    341:       NOTROT = 0
                    342:       FASTR( 1 ) = ZERO
                    343: *
                    344: *     .. Row-cyclic pivot strategy with de Rijk's pivoting ..
                    345: *
1.14      bertrand  346:       KBL = MIN( 8, N )
1.1       bertrand  347:       NBLR = N1 / KBL
                    348:       IF( ( NBLR*KBL ).NE.N1 )NBLR = NBLR + 1
                    349: 
                    350: *     .. the tiling is nblr-by-nblc [tiles]
                    351: 
                    352:       NBLC = ( N-N1 ) / KBL
                    353:       IF( ( NBLC*KBL ).NE.( N-N1 ) )NBLC = NBLC + 1
                    354:       BLSKIP = ( KBL**2 ) + 1
                    355: *[TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL.
                    356: 
1.14      bertrand  357:       ROWSKIP = MIN( 5, KBL )
1.1       bertrand  358: *[TP] ROWSKIP is a tuning parameter.
                    359:       SWBAND = 0
                    360: *[TP] SWBAND is a tuning parameter. It is meaningful and effective
                    361: *     if SGESVJ is used as a computational routine in the preconditioned
                    362: *     Jacobi SVD algorithm SGESVJ.
                    363: *
                    364: *
                    365: *     | *   *   * [x] [x] [x]|
                    366: *     | *   *   * [x] [x] [x]|    Row-cycling in the nblr-by-nblc [x] blocks.
                    367: *     | *   *   * [x] [x] [x]|    Row-cyclic pivoting inside each [x] block.
                    368: *     |[x] [x] [x] *   *   * |
                    369: *     |[x] [x] [x] *   *   * |
                    370: *     |[x] [x] [x] *   *   * |
                    371: *
                    372: *
                    373:       DO 1993 i = 1, NSWEEP
                    374: *     .. go go go ...
                    375: *
                    376:          MXAAPQ = ZERO
                    377:          MXSINJ = ZERO
                    378:          ISWROT = 0
                    379: *
                    380:          NOTROT = 0
                    381:          PSKIPPED = 0
                    382: *
                    383:          DO 2000 ibr = 1, NBLR
                    384: 
                    385:             igl = ( ibr-1 )*KBL + 1
                    386: *
                    387: *
                    388: *........................................................
                    389: * ... go to the off diagonal blocks
                    390: 
                    391:             igl = ( ibr-1 )*KBL + 1
                    392: 
                    393:             DO 2010 jbc = 1, NBLC
                    394: 
                    395:                jgl = N1 + ( jbc-1 )*KBL + 1
                    396: 
                    397: *        doing the block at ( ibr, jbc )
                    398: 
                    399:                IJBLSK = 0
1.14      bertrand  400:                DO 2100 p = igl, MIN( igl+KBL-1, N1 )
1.1       bertrand  401: 
                    402:                   AAPP = SVA( p )
                    403: 
                    404:                   IF( AAPP.GT.ZERO ) THEN
                    405: 
                    406:                      PSKIPPED = 0
                    407: 
1.14      bertrand  408:                      DO 2200 q = jgl, MIN( jgl+KBL-1, N )
1.1       bertrand  409: *
                    410:                         AAQQ = SVA( q )
                    411: 
                    412:                         IF( AAQQ.GT.ZERO ) THEN
                    413:                            AAPP0 = AAPP
                    414: *
                    415: *     .. M x 2 Jacobi SVD ..
                    416: *
                    417: *        .. Safe Gram matrix computation ..
                    418: *
                    419:                            IF( AAQQ.GE.ONE ) THEN
                    420:                               IF( AAPP.GE.AAQQ ) THEN
                    421:                                  ROTOK = ( SMALL*AAPP ).LE.AAQQ
                    422:                               ELSE
                    423:                                  ROTOK = ( SMALL*AAQQ ).LE.AAPP
                    424:                               END IF
                    425:                               IF( AAPP.LT.( BIG / AAQQ ) ) THEN
                    426:                                  AAPQ = ( DDOT( M, A( 1, p ), 1, A( 1,
1.6       bertrand  427:      $                                  q ), 1 )*D( p )*D( q ) / AAQQ )
                    428:      $                                  / AAPP
1.1       bertrand  429:                               ELSE
                    430:                                  CALL DCOPY( M, A( 1, p ), 1, WORK, 1 )
                    431:                                  CALL DLASCL( 'G', 0, 0, AAPP, D( p ),
1.6       bertrand  432:      $                                        M, 1, WORK, LDA, IERR )
1.1       bertrand  433:                                  AAPQ = DDOT( M, WORK, 1, A( 1, q ),
1.6       bertrand  434:      $                                  1 )*D( q ) / AAQQ
1.1       bertrand  435:                               END IF
                    436:                            ELSE
                    437:                               IF( AAPP.GE.AAQQ ) THEN
                    438:                                  ROTOK = AAPP.LE.( AAQQ / SMALL )
                    439:                               ELSE
                    440:                                  ROTOK = AAQQ.LE.( AAPP / SMALL )
                    441:                               END IF
                    442:                               IF( AAPP.GT.( SMALL / AAQQ ) ) THEN
                    443:                                  AAPQ = ( DDOT( M, A( 1, p ), 1, A( 1,
1.6       bertrand  444:      $                                  q ), 1 )*D( p )*D( q ) / AAQQ )
                    445:      $                                  / AAPP
1.1       bertrand  446:                               ELSE
                    447:                                  CALL DCOPY( M, A( 1, q ), 1, WORK, 1 )
                    448:                                  CALL DLASCL( 'G', 0, 0, AAQQ, D( q ),
1.6       bertrand  449:      $                                        M, 1, WORK, LDA, IERR )
1.1       bertrand  450:                                  AAPQ = DDOT( M, WORK, 1, A( 1, p ),
1.6       bertrand  451:      $                                  1 )*D( p ) / AAPP
1.1       bertrand  452:                               END IF
                    453:                            END IF
                    454: 
1.14      bertrand  455:                            MXAAPQ = MAX( MXAAPQ, DABS( AAPQ ) )
1.1       bertrand  456: 
                    457: *        TO rotate or NOT to rotate, THAT is the question ...
                    458: *
                    459:                            IF( DABS( AAPQ ).GT.TOL ) THEN
                    460:                               NOTROT = 0
                    461: *           ROTATED  = ROTATED + 1
                    462:                               PSKIPPED = 0
                    463:                               ISWROT = ISWROT + 1
                    464: *
                    465:                               IF( ROTOK ) THEN
                    466: *
                    467:                                  AQOAP = AAQQ / AAPP
                    468:                                  APOAQ = AAPP / AAQQ
1.6       bertrand  469:                                  THETA = -HALF*DABS(AQOAP-APOAQ) / AAPQ
1.1       bertrand  470:                                  IF( AAQQ.GT.AAPP0 )THETA = -THETA
                    471: 
                    472:                                  IF( DABS( THETA ).GT.BIGTHETA ) THEN
                    473:                                     T = HALF / THETA
                    474:                                     FASTR( 3 ) = T*D( p ) / D( q )
                    475:                                     FASTR( 4 ) = -T*D( q ) / D( p )
                    476:                                     CALL DROTM( M, A( 1, p ), 1,
1.6       bertrand  477:      $                                          A( 1, q ), 1, FASTR )
1.1       bertrand  478:                                     IF( RSVEC )CALL DROTM( MVL,
1.6       bertrand  479:      $                                              V( 1, p ), 1,
                    480:      $                                              V( 1, q ), 1,
                    481:      $                                              FASTR )
1.14      bertrand  482:                                     SVA( q ) = AAQQ*DSQRT( MAX( ZERO,
1.6       bertrand  483:      $                                         ONE+T*APOAQ*AAPQ ) )
1.14      bertrand  484:                                     AAPP = AAPP*DSQRT( MAX( ZERO,
1.6       bertrand  485:      $                                     ONE-T*AQOAP*AAPQ ) )
1.14      bertrand  486:                                     MXSINJ = MAX( MXSINJ, DABS( T ) )
1.1       bertrand  487:                                  ELSE
                    488: *
                    489: *                 .. choose correct signum for THETA and rotate
                    490: *
                    491:                                     THSIGN = -DSIGN( ONE, AAPQ )
                    492:                                     IF( AAQQ.GT.AAPP0 )THSIGN = -THSIGN
                    493:                                     T = ONE / ( THETA+THSIGN*
1.6       bertrand  494:      $                                  DSQRT( ONE+THETA*THETA ) )
1.1       bertrand  495:                                     CS = DSQRT( ONE / ( ONE+T*T ) )
                    496:                                     SN = T*CS
1.14      bertrand  497:                                     MXSINJ = MAX( MXSINJ, DABS( SN ) )
                    498:                                     SVA( q ) = AAQQ*DSQRT( MAX( ZERO,
1.6       bertrand  499:      $                                         ONE+T*APOAQ*AAPQ ) )
1.17      bertrand  500:                                     AAPP = AAPP*DSQRT( MAX( ZERO,
1.6       bertrand  501:      $                                    ONE-T*AQOAP*AAPQ ) )
1.1       bertrand  502: 
                    503:                                     APOAQ = D( p ) / D( q )
                    504:                                     AQOAP = D( q ) / D( p )
                    505:                                     IF( D( p ).GE.ONE ) THEN
                    506: *
                    507:                                        IF( D( q ).GE.ONE ) THEN
                    508:                                           FASTR( 3 ) = T*APOAQ
                    509:                                           FASTR( 4 ) = -T*AQOAP
                    510:                                           D( p ) = D( p )*CS
                    511:                                           D( q ) = D( q )*CS
                    512:                                           CALL DROTM( M, A( 1, p ), 1,
1.6       bertrand  513:      $                                                A( 1, q ), 1,
                    514:      $                                                FASTR )
1.1       bertrand  515:                                           IF( RSVEC )CALL DROTM( MVL,
1.6       bertrand  516:      $                                        V( 1, p ), 1, V( 1, q ),
                    517:      $                                        1, FASTR )
1.1       bertrand  518:                                        ELSE
                    519:                                           CALL DAXPY( M, -T*AQOAP,
1.6       bertrand  520:      $                                                A( 1, q ), 1,
                    521:      $                                                A( 1, p ), 1 )
1.1       bertrand  522:                                           CALL DAXPY( M, CS*SN*APOAQ,
1.6       bertrand  523:      $                                                A( 1, p ), 1,
                    524:      $                                                A( 1, q ), 1 )
1.1       bertrand  525:                                           IF( RSVEC ) THEN
                    526:                                              CALL DAXPY( MVL, -T*AQOAP,
1.6       bertrand  527:      $                                                   V( 1, q ), 1,
                    528:      $                                                   V( 1, p ), 1 )
1.1       bertrand  529:                                              CALL DAXPY( MVL,
1.6       bertrand  530:      $                                                   CS*SN*APOAQ,
                    531:      $                                                   V( 1, p ), 1,
                    532:      $                                                   V( 1, q ), 1 )
1.1       bertrand  533:                                           END IF
                    534:                                           D( p ) = D( p )*CS
                    535:                                           D( q ) = D( q ) / CS
                    536:                                        END IF
                    537:                                     ELSE
                    538:                                        IF( D( q ).GE.ONE ) THEN
                    539:                                           CALL DAXPY( M, T*APOAQ,
1.6       bertrand  540:      $                                                A( 1, p ), 1,
                    541:      $                                                A( 1, q ), 1 )
1.1       bertrand  542:                                           CALL DAXPY( M, -CS*SN*AQOAP,
1.6       bertrand  543:      $                                                A( 1, q ), 1,
                    544:      $                                                A( 1, p ), 1 )
1.1       bertrand  545:                                           IF( RSVEC ) THEN
                    546:                                              CALL DAXPY( MVL, T*APOAQ,
1.6       bertrand  547:      $                                                   V( 1, p ), 1,
                    548:      $                                                   V( 1, q ), 1 )
1.1       bertrand  549:                                              CALL DAXPY( MVL,
1.6       bertrand  550:      $                                                   -CS*SN*AQOAP,
                    551:      $                                                   V( 1, q ), 1,
                    552:      $                                                   V( 1, p ), 1 )
1.1       bertrand  553:                                           END IF
                    554:                                           D( p ) = D( p ) / CS
                    555:                                           D( q ) = D( q )*CS
                    556:                                        ELSE
                    557:                                           IF( D( p ).GE.D( q ) ) THEN
                    558:                                              CALL DAXPY( M, -T*AQOAP,
1.6       bertrand  559:      $                                                   A( 1, q ), 1,
                    560:      $                                                   A( 1, p ), 1 )
1.1       bertrand  561:                                              CALL DAXPY( M, CS*SN*APOAQ,
1.6       bertrand  562:      $                                                   A( 1, p ), 1,
                    563:      $                                                   A( 1, q ), 1 )
1.1       bertrand  564:                                              D( p ) = D( p )*CS
                    565:                                              D( q ) = D( q ) / CS
                    566:                                              IF( RSVEC ) THEN
                    567:                                                 CALL DAXPY( MVL,
1.6       bertrand  568:      $                                               -T*AQOAP,
                    569:      $                                               V( 1, q ), 1,
                    570:      $                                               V( 1, p ), 1 )
1.1       bertrand  571:                                                 CALL DAXPY( MVL,
1.6       bertrand  572:      $                                               CS*SN*APOAQ,
                    573:      $                                               V( 1, p ), 1,
                    574:      $                                               V( 1, q ), 1 )
1.1       bertrand  575:                                              END IF
                    576:                                           ELSE
                    577:                                              CALL DAXPY( M, T*APOAQ,
1.6       bertrand  578:      $                                                   A( 1, p ), 1,
                    579:      $                                                   A( 1, q ), 1 )
1.1       bertrand  580:                                              CALL DAXPY( M,
1.6       bertrand  581:      $                                                   -CS*SN*AQOAP,
                    582:      $                                                   A( 1, q ), 1,
                    583:      $                                                   A( 1, p ), 1 )
1.1       bertrand  584:                                              D( p ) = D( p ) / CS
                    585:                                              D( q ) = D( q )*CS
                    586:                                              IF( RSVEC ) THEN
                    587:                                                 CALL DAXPY( MVL,
1.6       bertrand  588:      $                                               T*APOAQ, V( 1, p ),
                    589:      $                                               1, V( 1, q ), 1 )
1.1       bertrand  590:                                                 CALL DAXPY( MVL,
1.6       bertrand  591:      $                                               -CS*SN*AQOAP,
                    592:      $                                               V( 1, q ), 1,
                    593:      $                                               V( 1, p ), 1 )
1.1       bertrand  594:                                              END IF
                    595:                                           END IF
                    596:                                        END IF
                    597:                                     END IF
                    598:                                  END IF
                    599: 
                    600:                               ELSE
                    601:                                  IF( AAPP.GT.AAQQ ) THEN
                    602:                                     CALL DCOPY( M, A( 1, p ), 1, WORK,
1.6       bertrand  603:      $                                          1 )
1.1       bertrand  604:                                     CALL DLASCL( 'G', 0, 0, AAPP, ONE,
1.6       bertrand  605:      $                                           M, 1, WORK, LDA, IERR )
1.1       bertrand  606:                                     CALL DLASCL( 'G', 0, 0, AAQQ, ONE,
1.6       bertrand  607:      $                                           M, 1, A( 1, q ), LDA,
                    608:      $                                           IERR )
1.1       bertrand  609:                                     TEMP1 = -AAPQ*D( p ) / D( q )
                    610:                                     CALL DAXPY( M, TEMP1, WORK, 1,
1.6       bertrand  611:      $                                          A( 1, q ), 1 )
1.1       bertrand  612:                                     CALL DLASCL( 'G', 0, 0, ONE, AAQQ,
1.6       bertrand  613:      $                                           M, 1, A( 1, q ), LDA,
                    614:      $                                           IERR )
1.14      bertrand  615:                                     SVA( q ) = AAQQ*DSQRT( MAX( ZERO,
1.6       bertrand  616:      $                                         ONE-AAPQ*AAPQ ) )
1.14      bertrand  617:                                     MXSINJ = MAX( MXSINJ, SFMIN )
1.1       bertrand  618:                                  ELSE
                    619:                                     CALL DCOPY( M, A( 1, q ), 1, WORK,
1.6       bertrand  620:      $                                          1 )
1.1       bertrand  621:                                     CALL DLASCL( 'G', 0, 0, AAQQ, ONE,
1.6       bertrand  622:      $                                           M, 1, WORK, LDA, IERR )
1.1       bertrand  623:                                     CALL DLASCL( 'G', 0, 0, AAPP, ONE,
1.6       bertrand  624:      $                                           M, 1, A( 1, p ), LDA,
                    625:      $                                           IERR )
1.1       bertrand  626:                                     TEMP1 = -AAPQ*D( q ) / D( p )
                    627:                                     CALL DAXPY( M, TEMP1, WORK, 1,
1.6       bertrand  628:      $                                          A( 1, p ), 1 )
1.1       bertrand  629:                                     CALL DLASCL( 'G', 0, 0, ONE, AAPP,
1.6       bertrand  630:      $                                           M, 1, A( 1, p ), LDA,
                    631:      $                                           IERR )
1.14      bertrand  632:                                     SVA( p ) = AAPP*DSQRT( MAX( ZERO,
1.6       bertrand  633:      $                                         ONE-AAPQ*AAPQ ) )
1.14      bertrand  634:                                     MXSINJ = MAX( MXSINJ, SFMIN )
1.1       bertrand  635:                                  END IF
                    636:                               END IF
                    637: *           END IF ROTOK THEN ... ELSE
                    638: *
                    639: *           In the case of cancellation in updating SVA(q)
                    640: *           .. recompute SVA(q)
                    641:                               IF( ( SVA( q ) / AAQQ )**2.LE.ROOTEPS )
1.6       bertrand  642:      $                            THEN
1.1       bertrand  643:                                  IF( ( AAQQ.LT.ROOTBIG ) .AND.
1.6       bertrand  644:      $                               ( AAQQ.GT.ROOTSFMIN ) ) THEN
1.1       bertrand  645:                                     SVA( q ) = DNRM2( M, A( 1, q ), 1 )*
1.6       bertrand  646:      $                                         D( q )
1.1       bertrand  647:                                  ELSE
                    648:                                     T = ZERO
1.4       bertrand  649:                                     AAQQ = ONE
1.1       bertrand  650:                                     CALL DLASSQ( M, A( 1, q ), 1, T,
1.6       bertrand  651:      $                                           AAQQ )
1.1       bertrand  652:                                     SVA( q ) = T*DSQRT( AAQQ )*D( q )
                    653:                                  END IF
                    654:                               END IF
                    655:                               IF( ( AAPP / AAPP0 )**2.LE.ROOTEPS ) THEN
                    656:                                  IF( ( AAPP.LT.ROOTBIG ) .AND.
1.6       bertrand  657:      $                               ( AAPP.GT.ROOTSFMIN ) ) THEN
1.1       bertrand  658:                                     AAPP = DNRM2( M, A( 1, p ), 1 )*
1.6       bertrand  659:      $                                     D( p )
1.1       bertrand  660:                                  ELSE
                    661:                                     T = ZERO
1.4       bertrand  662:                                     AAPP = ONE
1.1       bertrand  663:                                     CALL DLASSQ( M, A( 1, p ), 1, T,
1.6       bertrand  664:      $                                           AAPP )
1.1       bertrand  665:                                     AAPP = T*DSQRT( AAPP )*D( p )
                    666:                                  END IF
                    667:                                  SVA( p ) = AAPP
                    668:                               END IF
                    669: *              end of OK rotation
                    670:                            ELSE
                    671:                               NOTROT = NOTROT + 1
                    672: *           SKIPPED  = SKIPPED  + 1
                    673:                               PSKIPPED = PSKIPPED + 1
                    674:                               IJBLSK = IJBLSK + 1
                    675:                            END IF
                    676:                         ELSE
                    677:                            NOTROT = NOTROT + 1
                    678:                            PSKIPPED = PSKIPPED + 1
                    679:                            IJBLSK = IJBLSK + 1
                    680:                         END IF
                    681: 
                    682: *      IF ( NOTROT .GE. EMPTSW )  GO TO 2011
                    683:                         IF( ( i.LE.SWBAND ) .AND. ( IJBLSK.GE.BLSKIP ) )
1.6       bertrand  684:      $                      THEN
1.1       bertrand  685:                            SVA( p ) = AAPP
                    686:                            NOTROT = 0
                    687:                            GO TO 2011
                    688:                         END IF
                    689:                         IF( ( i.LE.SWBAND ) .AND.
1.6       bertrand  690:      $                      ( PSKIPPED.GT.ROWSKIP ) ) THEN
1.1       bertrand  691:                            AAPP = -AAPP
                    692:                            NOTROT = 0
                    693:                            GO TO 2203
                    694:                         END IF
                    695: 
                    696: *
                    697:  2200                CONTINUE
                    698: *        end of the q-loop
                    699:  2203                CONTINUE
                    700: 
                    701:                      SVA( p ) = AAPP
                    702: *
                    703:                   ELSE
                    704:                      IF( AAPP.EQ.ZERO )NOTROT = NOTROT +
1.14      bertrand  705:      $                   MIN( jgl+KBL-1, N ) - jgl + 1
1.1       bertrand  706:                      IF( AAPP.LT.ZERO )NOTROT = 0
                    707: ***      IF ( NOTROT .GE. EMPTSW )  GO TO 2011
                    708:                   END IF
                    709: 
                    710:  2100          CONTINUE
                    711: *     end of the p-loop
                    712:  2010       CONTINUE
                    713: *     end of the jbc-loop
                    714:  2011       CONTINUE
                    715: *2011 bailed out of the jbc-loop
1.14      bertrand  716:             DO 2012 p = igl, MIN( igl+KBL-1, N )
1.1       bertrand  717:                SVA( p ) = DABS( SVA( p ) )
                    718:  2012       CONTINUE
                    719: ***   IF ( NOTROT .GE. EMPTSW ) GO TO 1994
                    720:  2000    CONTINUE
                    721: *2000 :: end of the ibr-loop
                    722: *
                    723: *     .. update SVA(N)
                    724:          IF( ( SVA( N ).LT.ROOTBIG ) .AND. ( SVA( N ).GT.ROOTSFMIN ) )
1.6       bertrand  725:      $       THEN
1.1       bertrand  726:             SVA( N ) = DNRM2( M, A( 1, N ), 1 )*D( N )
                    727:          ELSE
                    728:             T = ZERO
1.4       bertrand  729:             AAPP = ONE
1.1       bertrand  730:             CALL DLASSQ( M, A( 1, N ), 1, T, AAPP )
                    731:             SVA( N ) = T*DSQRT( AAPP )*D( N )
                    732:          END IF
                    733: *
                    734: *     Additional steering devices
                    735: *
                    736:          IF( ( i.LT.SWBAND ) .AND. ( ( MXAAPQ.LE.ROOTTOL ) .OR.
1.6       bertrand  737:      $       ( ISWROT.LE.N ) ) )SWBAND = i
1.1       bertrand  738: 
                    739:          IF( ( i.GT.SWBAND+1 ) .AND. ( MXAAPQ.LT.DBLE( N )*TOL ) .AND.
1.6       bertrand  740:      $       ( DBLE( N )*MXAAPQ*MXSINJ.LT.TOL ) ) THEN
1.1       bertrand  741:             GO TO 1994
                    742:          END IF
                    743: 
                    744: *
                    745:          IF( NOTROT.GE.EMPTSW )GO TO 1994
                    746: 
                    747:  1993 CONTINUE
                    748: *     end i=1:NSWEEP loop
                    749: * #:) Reaching this point means that the procedure has completed the given
                    750: *     number of sweeps.
                    751:       INFO = NSWEEP - 1
                    752:       GO TO 1995
                    753:  1994 CONTINUE
                    754: * #:) Reaching this point means that during the i-th sweep all pivots were
                    755: *     below the given threshold, causing early exit.
                    756: 
                    757:       INFO = 0
                    758: * #:) INFO = 0 confirms successful iterations.
                    759:  1995 CONTINUE
                    760: *
                    761: *     Sort the vector D
                    762: *
                    763:       DO 5991 p = 1, N - 1
                    764:          q = IDAMAX( N-p+1, SVA( p ), 1 ) + p - 1
                    765:          IF( p.NE.q ) THEN
                    766:             TEMP1 = SVA( p )
                    767:             SVA( p ) = SVA( q )
                    768:             SVA( q ) = TEMP1
                    769:             TEMP1 = D( p )
                    770:             D( p ) = D( q )
                    771:             D( q ) = TEMP1
                    772:             CALL DSWAP( M, A( 1, p ), 1, A( 1, q ), 1 )
                    773:             IF( RSVEC )CALL DSWAP( MVL, V( 1, p ), 1, V( 1, q ), 1 )
                    774:          END IF
                    775:  5991 CONTINUE
                    776: *
                    777:       RETURN
                    778: *     ..
                    779: *     .. END OF DGSVJ1
                    780: *     ..
                    781:       END

CVSweb interface <joel.bertrand@systella.fr>