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

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
                     43: *> (stopping criterion). Few tunning parameters (marked by [TP]) are
                     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
                     64: *> tiled using quadratic tiles of side KBL. Here, KBL is a tunning parmeter.
                     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
                    150: *>          If JOBV .EQ. '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.
                    153: *> \endverbatim
                    154: *>
                    155: *> \param[in,out] V
                    156: *> \verbatim
                    157: *>          V is DOUBLE PRECISION array, dimension (LDV,N)
                    158: *>          If JOBV .EQ. 'V' then N rows of V are post-multipled by a
                    159: *>                           sequence of Jacobi rotations.
                    160: *>          If JOBV .EQ. '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.
                    163: *> \endverbatim
                    164: *>
                    165: *> \param[in] LDV
                    166: *> \verbatim
                    167: *>          LDV is INTEGER
                    168: *>          The leading dimension of the array V,  LDV >= 1.
                    169: *>          If JOBV = 'V', LDV .GE. N.
                    170: *>          If JOBV = 'A', LDV .GE. MV.
                    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
                    190: *>          applied only if DABS(COS(angle(A(:,p),A(:,q)))) .GT. TOL.
                    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
                    208: *>          LWORK is the dimension of WORK. LWORK .GE. M.
                    209: *> \endverbatim
                    210: *>
                    211: *> \param[out] INFO
                    212: *> \verbatim
                    213: *>          INFO is INTEGER
                    214: *>          = 0 : successful exit.
                    215: *>          < 0 : if INFO = -i, then the i-th argument had an illegal value
                    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: *
1.15      bertrand  226: *> \date June 2016
1.7       bertrand  227: *
                    228: *> \ingroup doubleOTHERcomputational
                    229: *
                    230: *> \par Contributors:
                    231: *  ==================
                    232: *>
                    233: *> Zlatko Drmac (Zagreb, Croatia) and Kresimir Veselic (Hagen, Germany)
                    234: *
                    235: *  =====================================================================
1.1       bertrand  236:       SUBROUTINE DGSVJ1( JOBV, M, N, N1, A, LDA, D, SVA, MV, V, LDV,
1.6       bertrand  237:      $                   EPS, SFMIN, TOL, NSWEEP, WORK, LWORK, INFO )
1.1       bertrand  238: *
1.19      bertrand  239: *  -- LAPACK computational routine (version 3.8.0) --
1.1       bertrand  240: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
                    241: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
1.15      bertrand  242: *     June 2016
1.1       bertrand  243: *
                    244: *     .. Scalar Arguments ..
                    245:       DOUBLE PRECISION   EPS, SFMIN, TOL
                    246:       INTEGER            INFO, LDA, LDV, LWORK, M, MV, N, N1, NSWEEP
                    247:       CHARACTER*1        JOBV
                    248: *     ..
                    249: *     .. Array Arguments ..
                    250:       DOUBLE PRECISION   A( LDA, * ), D( N ), SVA( N ), V( LDV, * ),
1.6       bertrand  251:      $                   WORK( LWORK )
1.1       bertrand  252: *     ..
                    253: *
                    254: *  =====================================================================
                    255: *
                    256: *     .. Local Parameters ..
1.9       bertrand  257:       DOUBLE PRECISION   ZERO, HALF, ONE
                    258:       PARAMETER          ( ZERO = 0.0D0, HALF = 0.5D0, ONE = 1.0D0 )
1.1       bertrand  259: *     ..
                    260: *     .. Local Scalars ..
                    261:       DOUBLE PRECISION   AAPP, AAPP0, AAPQ, AAQQ, APOAQ, AQOAP, BIG,
1.6       bertrand  262:      $                   BIGTHETA, CS, LARGE, MXAAPQ, MXSINJ, ROOTBIG,
                    263:      $                   ROOTEPS, ROOTSFMIN, ROOTTOL, SMALL, SN, T,
                    264:      $                   TEMP1, THETA, THSIGN
1.1       bertrand  265:       INTEGER            BLSKIP, EMPTSW, i, ibr, igl, IERR, IJBLSK,
1.6       bertrand  266:      $                   ISWROT, jbc, jgl, KBL, MVL, NOTROT, nblc, nblr,
                    267:      $                   p, PSKIPPED, q, ROWSKIP, SWBAND
1.1       bertrand  268:       LOGICAL            APPLV, ROTOK, RSVEC
                    269: *     ..
                    270: *     .. Local Arrays ..
                    271:       DOUBLE PRECISION   FASTR( 5 )
                    272: *     ..
                    273: *     .. Intrinsic Functions ..
1.14      bertrand  274:       INTRINSIC          DABS, MAX, DBLE, MIN, DSIGN, DSQRT
1.1       bertrand  275: *     ..
                    276: *     .. External Functions ..
                    277:       DOUBLE PRECISION   DDOT, DNRM2
                    278:       INTEGER            IDAMAX
                    279:       LOGICAL            LSAME
                    280:       EXTERNAL           IDAMAX, LSAME, DDOT, DNRM2
                    281: *     ..
                    282: *     .. External Subroutines ..
1.19      bertrand  283:       EXTERNAL           DAXPY, DCOPY, DLASCL, DLASSQ, DROTM, DSWAP,
                    284:      $                   XERBLA
1.1       bertrand  285: *     ..
                    286: *     .. Executable Statements ..
                    287: *
                    288: *     Test the input parameters.
                    289: *
                    290:       APPLV = LSAME( JOBV, 'A' )
                    291:       RSVEC = LSAME( JOBV, 'V' )
                    292:       IF( .NOT.( RSVEC .OR. APPLV .OR. LSAME( JOBV, 'N' ) ) ) THEN
                    293:          INFO = -1
                    294:       ELSE IF( M.LT.0 ) THEN
                    295:          INFO = -2
                    296:       ELSE IF( ( N.LT.0 ) .OR. ( N.GT.M ) ) THEN
                    297:          INFO = -3
                    298:       ELSE IF( N1.LT.0 ) THEN
                    299:          INFO = -4
                    300:       ELSE IF( LDA.LT.M ) THEN
                    301:          INFO = -6
1.4       bertrand  302:       ELSE IF( ( RSVEC.OR.APPLV ) .AND. ( MV.LT.0 ) ) THEN
1.1       bertrand  303:          INFO = -9
1.17      bertrand  304:       ELSE IF( ( RSVEC.AND.( LDV.LT.N ) ).OR.
1.6       bertrand  305:      $         ( APPLV.AND.( LDV.LT.MV ) )  ) THEN
1.1       bertrand  306:          INFO = -11
                    307:       ELSE IF( TOL.LE.EPS ) THEN
                    308:          INFO = -14
                    309:       ELSE IF( NSWEEP.LT.0 ) THEN
                    310:          INFO = -15
                    311:       ELSE IF( LWORK.LT.M ) THEN
                    312:          INFO = -17
                    313:       ELSE
                    314:          INFO = 0
                    315:       END IF
                    316: *
                    317: *     #:(
                    318:       IF( INFO.NE.0 ) THEN
                    319:          CALL XERBLA( 'DGSVJ1', -INFO )
                    320:          RETURN
                    321:       END IF
                    322: *
                    323:       IF( RSVEC ) THEN
                    324:          MVL = N
                    325:       ELSE IF( APPLV ) THEN
                    326:          MVL = MV
                    327:       END IF
                    328:       RSVEC = RSVEC .OR. APPLV
                    329: 
                    330:       ROOTEPS = DSQRT( EPS )
                    331:       ROOTSFMIN = DSQRT( SFMIN )
                    332:       SMALL = SFMIN / EPS
                    333:       BIG = ONE / SFMIN
                    334:       ROOTBIG = ONE / ROOTSFMIN
                    335:       LARGE = BIG / DSQRT( DBLE( M*N ) )
                    336:       BIGTHETA = ONE / ROOTEPS
                    337:       ROOTTOL = DSQRT( TOL )
                    338: *
                    339: *     .. Initialize the right singular vector matrix ..
                    340: *
                    341: *     RSVEC = LSAME( JOBV, 'Y' )
                    342: *
                    343:       EMPTSW = N1*( N-N1 )
                    344:       NOTROT = 0
                    345:       FASTR( 1 ) = ZERO
                    346: *
                    347: *     .. Row-cyclic pivot strategy with de Rijk's pivoting ..
                    348: *
1.14      bertrand  349:       KBL = MIN( 8, N )
1.1       bertrand  350:       NBLR = N1 / KBL
                    351:       IF( ( NBLR*KBL ).NE.N1 )NBLR = NBLR + 1
                    352: 
                    353: *     .. the tiling is nblr-by-nblc [tiles]
                    354: 
                    355:       NBLC = ( N-N1 ) / KBL
                    356:       IF( ( NBLC*KBL ).NE.( N-N1 ) )NBLC = NBLC + 1
                    357:       BLSKIP = ( KBL**2 ) + 1
                    358: *[TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL.
                    359: 
1.14      bertrand  360:       ROWSKIP = MIN( 5, KBL )
1.1       bertrand  361: *[TP] ROWSKIP is a tuning parameter.
                    362:       SWBAND = 0
                    363: *[TP] SWBAND is a tuning parameter. It is meaningful and effective
                    364: *     if SGESVJ is used as a computational routine in the preconditioned
                    365: *     Jacobi SVD algorithm SGESVJ.
                    366: *
                    367: *
                    368: *     | *   *   * [x] [x] [x]|
                    369: *     | *   *   * [x] [x] [x]|    Row-cycling in the nblr-by-nblc [x] blocks.
                    370: *     | *   *   * [x] [x] [x]|    Row-cyclic pivoting inside each [x] block.
                    371: *     |[x] [x] [x] *   *   * |
                    372: *     |[x] [x] [x] *   *   * |
                    373: *     |[x] [x] [x] *   *   * |
                    374: *
                    375: *
                    376:       DO 1993 i = 1, NSWEEP
                    377: *     .. go go go ...
                    378: *
                    379:          MXAAPQ = ZERO
                    380:          MXSINJ = ZERO
                    381:          ISWROT = 0
                    382: *
                    383:          NOTROT = 0
                    384:          PSKIPPED = 0
                    385: *
                    386:          DO 2000 ibr = 1, NBLR
                    387: 
                    388:             igl = ( ibr-1 )*KBL + 1
                    389: *
                    390: *
                    391: *........................................................
                    392: * ... go to the off diagonal blocks
                    393: 
                    394:             igl = ( ibr-1 )*KBL + 1
                    395: 
                    396:             DO 2010 jbc = 1, NBLC
                    397: 
                    398:                jgl = N1 + ( jbc-1 )*KBL + 1
                    399: 
                    400: *        doing the block at ( ibr, jbc )
                    401: 
                    402:                IJBLSK = 0
1.14      bertrand  403:                DO 2100 p = igl, MIN( igl+KBL-1, N1 )
1.1       bertrand  404: 
                    405:                   AAPP = SVA( p )
                    406: 
                    407:                   IF( AAPP.GT.ZERO ) THEN
                    408: 
                    409:                      PSKIPPED = 0
                    410: 
1.14      bertrand  411:                      DO 2200 q = jgl, MIN( jgl+KBL-1, N )
1.1       bertrand  412: *
                    413:                         AAQQ = SVA( q )
                    414: 
                    415:                         IF( AAQQ.GT.ZERO ) THEN
                    416:                            AAPP0 = AAPP
                    417: *
                    418: *     .. M x 2 Jacobi SVD ..
                    419: *
                    420: *        .. Safe Gram matrix computation ..
                    421: *
                    422:                            IF( AAQQ.GE.ONE ) THEN
                    423:                               IF( AAPP.GE.AAQQ ) THEN
                    424:                                  ROTOK = ( SMALL*AAPP ).LE.AAQQ
                    425:                               ELSE
                    426:                                  ROTOK = ( SMALL*AAQQ ).LE.AAPP
                    427:                               END IF
                    428:                               IF( AAPP.LT.( BIG / AAQQ ) ) THEN
                    429:                                  AAPQ = ( DDOT( M, A( 1, p ), 1, A( 1,
1.6       bertrand  430:      $                                  q ), 1 )*D( p )*D( q ) / AAQQ )
                    431:      $                                  / AAPP
1.1       bertrand  432:                               ELSE
                    433:                                  CALL DCOPY( M, A( 1, p ), 1, WORK, 1 )
                    434:                                  CALL DLASCL( 'G', 0, 0, AAPP, D( p ),
1.6       bertrand  435:      $                                        M, 1, WORK, LDA, IERR )
1.1       bertrand  436:                                  AAPQ = DDOT( M, WORK, 1, A( 1, q ),
1.6       bertrand  437:      $                                  1 )*D( q ) / AAQQ
1.1       bertrand  438:                               END IF
                    439:                            ELSE
                    440:                               IF( AAPP.GE.AAQQ ) THEN
                    441:                                  ROTOK = AAPP.LE.( AAQQ / SMALL )
                    442:                               ELSE
                    443:                                  ROTOK = AAQQ.LE.( AAPP / SMALL )
                    444:                               END IF
                    445:                               IF( AAPP.GT.( SMALL / AAQQ ) ) THEN
                    446:                                  AAPQ = ( DDOT( M, A( 1, p ), 1, A( 1,
1.6       bertrand  447:      $                                  q ), 1 )*D( p )*D( q ) / AAQQ )
                    448:      $                                  / AAPP
1.1       bertrand  449:                               ELSE
                    450:                                  CALL DCOPY( M, A( 1, q ), 1, WORK, 1 )
                    451:                                  CALL DLASCL( 'G', 0, 0, AAQQ, D( q ),
1.6       bertrand  452:      $                                        M, 1, WORK, LDA, IERR )
1.1       bertrand  453:                                  AAPQ = DDOT( M, WORK, 1, A( 1, p ),
1.6       bertrand  454:      $                                  1 )*D( p ) / AAPP
1.1       bertrand  455:                               END IF
                    456:                            END IF
                    457: 
1.14      bertrand  458:                            MXAAPQ = MAX( MXAAPQ, DABS( AAPQ ) )
1.1       bertrand  459: 
                    460: *        TO rotate or NOT to rotate, THAT is the question ...
                    461: *
                    462:                            IF( DABS( AAPQ ).GT.TOL ) THEN
                    463:                               NOTROT = 0
                    464: *           ROTATED  = ROTATED + 1
                    465:                               PSKIPPED = 0
                    466:                               ISWROT = ISWROT + 1
                    467: *
                    468:                               IF( ROTOK ) THEN
                    469: *
                    470:                                  AQOAP = AAQQ / AAPP
                    471:                                  APOAQ = AAPP / AAQQ
1.6       bertrand  472:                                  THETA = -HALF*DABS(AQOAP-APOAQ) / AAPQ
1.1       bertrand  473:                                  IF( AAQQ.GT.AAPP0 )THETA = -THETA
                    474: 
                    475:                                  IF( DABS( THETA ).GT.BIGTHETA ) THEN
                    476:                                     T = HALF / THETA
                    477:                                     FASTR( 3 ) = T*D( p ) / D( q )
                    478:                                     FASTR( 4 ) = -T*D( q ) / D( p )
                    479:                                     CALL DROTM( M, A( 1, p ), 1,
1.6       bertrand  480:      $                                          A( 1, q ), 1, FASTR )
1.1       bertrand  481:                                     IF( RSVEC )CALL DROTM( MVL,
1.6       bertrand  482:      $                                              V( 1, p ), 1,
                    483:      $                                              V( 1, q ), 1,
                    484:      $                                              FASTR )
1.14      bertrand  485:                                     SVA( q ) = AAQQ*DSQRT( MAX( ZERO,
1.6       bertrand  486:      $                                         ONE+T*APOAQ*AAPQ ) )
1.14      bertrand  487:                                     AAPP = AAPP*DSQRT( MAX( ZERO,
1.6       bertrand  488:      $                                     ONE-T*AQOAP*AAPQ ) )
1.14      bertrand  489:                                     MXSINJ = MAX( MXSINJ, DABS( T ) )
1.1       bertrand  490:                                  ELSE
                    491: *
                    492: *                 .. choose correct signum for THETA and rotate
                    493: *
                    494:                                     THSIGN = -DSIGN( ONE, AAPQ )
                    495:                                     IF( AAQQ.GT.AAPP0 )THSIGN = -THSIGN
                    496:                                     T = ONE / ( THETA+THSIGN*
1.6       bertrand  497:      $                                  DSQRT( ONE+THETA*THETA ) )
1.1       bertrand  498:                                     CS = DSQRT( ONE / ( ONE+T*T ) )
                    499:                                     SN = T*CS
1.14      bertrand  500:                                     MXSINJ = MAX( MXSINJ, DABS( SN ) )
                    501:                                     SVA( q ) = AAQQ*DSQRT( MAX( ZERO,
1.6       bertrand  502:      $                                         ONE+T*APOAQ*AAPQ ) )
1.17      bertrand  503:                                     AAPP = AAPP*DSQRT( MAX( ZERO,
1.6       bertrand  504:      $                                    ONE-T*AQOAP*AAPQ ) )
1.1       bertrand  505: 
                    506:                                     APOAQ = D( p ) / D( q )
                    507:                                     AQOAP = D( q ) / D( p )
                    508:                                     IF( D( p ).GE.ONE ) THEN
                    509: *
                    510:                                        IF( D( q ).GE.ONE ) THEN
                    511:                                           FASTR( 3 ) = T*APOAQ
                    512:                                           FASTR( 4 ) = -T*AQOAP
                    513:                                           D( p ) = D( p )*CS
                    514:                                           D( q ) = D( q )*CS
                    515:                                           CALL DROTM( M, A( 1, p ), 1,
1.6       bertrand  516:      $                                                A( 1, q ), 1,
                    517:      $                                                FASTR )
1.1       bertrand  518:                                           IF( RSVEC )CALL DROTM( MVL,
1.6       bertrand  519:      $                                        V( 1, p ), 1, V( 1, q ),
                    520:      $                                        1, FASTR )
1.1       bertrand  521:                                        ELSE
                    522:                                           CALL DAXPY( M, -T*AQOAP,
1.6       bertrand  523:      $                                                A( 1, q ), 1,
                    524:      $                                                A( 1, p ), 1 )
1.1       bertrand  525:                                           CALL DAXPY( M, CS*SN*APOAQ,
1.6       bertrand  526:      $                                                A( 1, p ), 1,
                    527:      $                                                A( 1, q ), 1 )
1.1       bertrand  528:                                           IF( RSVEC ) THEN
                    529:                                              CALL DAXPY( MVL, -T*AQOAP,
1.6       bertrand  530:      $                                                   V( 1, q ), 1,
                    531:      $                                                   V( 1, p ), 1 )
1.1       bertrand  532:                                              CALL DAXPY( MVL,
1.6       bertrand  533:      $                                                   CS*SN*APOAQ,
                    534:      $                                                   V( 1, p ), 1,
                    535:      $                                                   V( 1, q ), 1 )
1.1       bertrand  536:                                           END IF
                    537:                                           D( p ) = D( p )*CS
                    538:                                           D( q ) = D( q ) / CS
                    539:                                        END IF
                    540:                                     ELSE
                    541:                                        IF( D( q ).GE.ONE ) THEN
                    542:                                           CALL DAXPY( M, T*APOAQ,
1.6       bertrand  543:      $                                                A( 1, p ), 1,
                    544:      $                                                A( 1, q ), 1 )
1.1       bertrand  545:                                           CALL DAXPY( M, -CS*SN*AQOAP,
1.6       bertrand  546:      $                                                A( 1, q ), 1,
                    547:      $                                                A( 1, p ), 1 )
1.1       bertrand  548:                                           IF( RSVEC ) THEN
                    549:                                              CALL DAXPY( MVL, T*APOAQ,
1.6       bertrand  550:      $                                                   V( 1, p ), 1,
                    551:      $                                                   V( 1, q ), 1 )
1.1       bertrand  552:                                              CALL DAXPY( MVL,
1.6       bertrand  553:      $                                                   -CS*SN*AQOAP,
                    554:      $                                                   V( 1, q ), 1,
                    555:      $                                                   V( 1, p ), 1 )
1.1       bertrand  556:                                           END IF
                    557:                                           D( p ) = D( p ) / CS
                    558:                                           D( q ) = D( q )*CS
                    559:                                        ELSE
                    560:                                           IF( D( p ).GE.D( q ) ) THEN
                    561:                                              CALL DAXPY( M, -T*AQOAP,
1.6       bertrand  562:      $                                                   A( 1, q ), 1,
                    563:      $                                                   A( 1, p ), 1 )
1.1       bertrand  564:                                              CALL DAXPY( M, CS*SN*APOAQ,
1.6       bertrand  565:      $                                                   A( 1, p ), 1,
                    566:      $                                                   A( 1, q ), 1 )
1.1       bertrand  567:                                              D( p ) = D( p )*CS
                    568:                                              D( q ) = D( q ) / CS
                    569:                                              IF( RSVEC ) THEN
                    570:                                                 CALL DAXPY( MVL,
1.6       bertrand  571:      $                                               -T*AQOAP,
                    572:      $                                               V( 1, q ), 1,
                    573:      $                                               V( 1, p ), 1 )
1.1       bertrand  574:                                                 CALL DAXPY( MVL,
1.6       bertrand  575:      $                                               CS*SN*APOAQ,
                    576:      $                                               V( 1, p ), 1,
                    577:      $                                               V( 1, q ), 1 )
1.1       bertrand  578:                                              END IF
                    579:                                           ELSE
                    580:                                              CALL DAXPY( M, T*APOAQ,
1.6       bertrand  581:      $                                                   A( 1, p ), 1,
                    582:      $                                                   A( 1, q ), 1 )
1.1       bertrand  583:                                              CALL DAXPY( M,
1.6       bertrand  584:      $                                                   -CS*SN*AQOAP,
                    585:      $                                                   A( 1, q ), 1,
                    586:      $                                                   A( 1, p ), 1 )
1.1       bertrand  587:                                              D( p ) = D( p ) / CS
                    588:                                              D( q ) = D( q )*CS
                    589:                                              IF( RSVEC ) THEN
                    590:                                                 CALL DAXPY( MVL,
1.6       bertrand  591:      $                                               T*APOAQ, V( 1, p ),
                    592:      $                                               1, V( 1, q ), 1 )
1.1       bertrand  593:                                                 CALL DAXPY( MVL,
1.6       bertrand  594:      $                                               -CS*SN*AQOAP,
                    595:      $                                               V( 1, q ), 1,
                    596:      $                                               V( 1, p ), 1 )
1.1       bertrand  597:                                              END IF
                    598:                                           END IF
                    599:                                        END IF
                    600:                                     END IF
                    601:                                  END IF
                    602: 
                    603:                               ELSE
                    604:                                  IF( AAPP.GT.AAQQ ) THEN
                    605:                                     CALL DCOPY( M, A( 1, p ), 1, WORK,
1.6       bertrand  606:      $                                          1 )
1.1       bertrand  607:                                     CALL DLASCL( 'G', 0, 0, AAPP, ONE,
1.6       bertrand  608:      $                                           M, 1, WORK, LDA, IERR )
1.1       bertrand  609:                                     CALL DLASCL( 'G', 0, 0, AAQQ, ONE,
1.6       bertrand  610:      $                                           M, 1, A( 1, q ), LDA,
                    611:      $                                           IERR )
1.1       bertrand  612:                                     TEMP1 = -AAPQ*D( p ) / D( q )
                    613:                                     CALL DAXPY( M, TEMP1, WORK, 1,
1.6       bertrand  614:      $                                          A( 1, q ), 1 )
1.1       bertrand  615:                                     CALL DLASCL( 'G', 0, 0, ONE, AAQQ,
1.6       bertrand  616:      $                                           M, 1, A( 1, q ), LDA,
                    617:      $                                           IERR )
1.14      bertrand  618:                                     SVA( q ) = AAQQ*DSQRT( MAX( ZERO,
1.6       bertrand  619:      $                                         ONE-AAPQ*AAPQ ) )
1.14      bertrand  620:                                     MXSINJ = MAX( MXSINJ, SFMIN )
1.1       bertrand  621:                                  ELSE
                    622:                                     CALL DCOPY( M, A( 1, q ), 1, WORK,
1.6       bertrand  623:      $                                          1 )
1.1       bertrand  624:                                     CALL DLASCL( 'G', 0, 0, AAQQ, ONE,
1.6       bertrand  625:      $                                           M, 1, WORK, LDA, IERR )
1.1       bertrand  626:                                     CALL DLASCL( 'G', 0, 0, AAPP, ONE,
1.6       bertrand  627:      $                                           M, 1, A( 1, p ), LDA,
                    628:      $                                           IERR )
1.1       bertrand  629:                                     TEMP1 = -AAPQ*D( q ) / D( p )
                    630:                                     CALL DAXPY( M, TEMP1, WORK, 1,
1.6       bertrand  631:      $                                          A( 1, p ), 1 )
1.1       bertrand  632:                                     CALL DLASCL( 'G', 0, 0, ONE, AAPP,
1.6       bertrand  633:      $                                           M, 1, A( 1, p ), LDA,
                    634:      $                                           IERR )
1.14      bertrand  635:                                     SVA( p ) = AAPP*DSQRT( MAX( ZERO,
1.6       bertrand  636:      $                                         ONE-AAPQ*AAPQ ) )
1.14      bertrand  637:                                     MXSINJ = MAX( MXSINJ, SFMIN )
1.1       bertrand  638:                                  END IF
                    639:                               END IF
                    640: *           END IF ROTOK THEN ... ELSE
                    641: *
                    642: *           In the case of cancellation in updating SVA(q)
                    643: *           .. recompute SVA(q)
                    644:                               IF( ( SVA( q ) / AAQQ )**2.LE.ROOTEPS )
1.6       bertrand  645:      $                            THEN
1.1       bertrand  646:                                  IF( ( AAQQ.LT.ROOTBIG ) .AND.
1.6       bertrand  647:      $                               ( AAQQ.GT.ROOTSFMIN ) ) THEN
1.1       bertrand  648:                                     SVA( q ) = DNRM2( M, A( 1, q ), 1 )*
1.6       bertrand  649:      $                                         D( q )
1.1       bertrand  650:                                  ELSE
                    651:                                     T = ZERO
1.4       bertrand  652:                                     AAQQ = ONE
1.1       bertrand  653:                                     CALL DLASSQ( M, A( 1, q ), 1, T,
1.6       bertrand  654:      $                                           AAQQ )
1.1       bertrand  655:                                     SVA( q ) = T*DSQRT( AAQQ )*D( q )
                    656:                                  END IF
                    657:                               END IF
                    658:                               IF( ( AAPP / AAPP0 )**2.LE.ROOTEPS ) THEN
                    659:                                  IF( ( AAPP.LT.ROOTBIG ) .AND.
1.6       bertrand  660:      $                               ( AAPP.GT.ROOTSFMIN ) ) THEN
1.1       bertrand  661:                                     AAPP = DNRM2( M, A( 1, p ), 1 )*
1.6       bertrand  662:      $                                     D( p )
1.1       bertrand  663:                                  ELSE
                    664:                                     T = ZERO
1.4       bertrand  665:                                     AAPP = ONE
1.1       bertrand  666:                                     CALL DLASSQ( M, A( 1, p ), 1, T,
1.6       bertrand  667:      $                                           AAPP )
1.1       bertrand  668:                                     AAPP = T*DSQRT( AAPP )*D( p )
                    669:                                  END IF
                    670:                                  SVA( p ) = AAPP
                    671:                               END IF
                    672: *              end of OK rotation
                    673:                            ELSE
                    674:                               NOTROT = NOTROT + 1
                    675: *           SKIPPED  = SKIPPED  + 1
                    676:                               PSKIPPED = PSKIPPED + 1
                    677:                               IJBLSK = IJBLSK + 1
                    678:                            END IF
                    679:                         ELSE
                    680:                            NOTROT = NOTROT + 1
                    681:                            PSKIPPED = PSKIPPED + 1
                    682:                            IJBLSK = IJBLSK + 1
                    683:                         END IF
                    684: 
                    685: *      IF ( NOTROT .GE. EMPTSW )  GO TO 2011
                    686:                         IF( ( i.LE.SWBAND ) .AND. ( IJBLSK.GE.BLSKIP ) )
1.6       bertrand  687:      $                      THEN
1.1       bertrand  688:                            SVA( p ) = AAPP
                    689:                            NOTROT = 0
                    690:                            GO TO 2011
                    691:                         END IF
                    692:                         IF( ( i.LE.SWBAND ) .AND.
1.6       bertrand  693:      $                      ( PSKIPPED.GT.ROWSKIP ) ) THEN
1.1       bertrand  694:                            AAPP = -AAPP
                    695:                            NOTROT = 0
                    696:                            GO TO 2203
                    697:                         END IF
                    698: 
                    699: *
                    700:  2200                CONTINUE
                    701: *        end of the q-loop
                    702:  2203                CONTINUE
                    703: 
                    704:                      SVA( p ) = AAPP
                    705: *
                    706:                   ELSE
                    707:                      IF( AAPP.EQ.ZERO )NOTROT = NOTROT +
1.14      bertrand  708:      $                   MIN( jgl+KBL-1, N ) - jgl + 1
1.1       bertrand  709:                      IF( AAPP.LT.ZERO )NOTROT = 0
                    710: ***      IF ( NOTROT .GE. EMPTSW )  GO TO 2011
                    711:                   END IF
                    712: 
                    713:  2100          CONTINUE
                    714: *     end of the p-loop
                    715:  2010       CONTINUE
                    716: *     end of the jbc-loop
                    717:  2011       CONTINUE
                    718: *2011 bailed out of the jbc-loop
1.14      bertrand  719:             DO 2012 p = igl, MIN( igl+KBL-1, N )
1.1       bertrand  720:                SVA( p ) = DABS( SVA( p ) )
                    721:  2012       CONTINUE
                    722: ***   IF ( NOTROT .GE. EMPTSW ) GO TO 1994
                    723:  2000    CONTINUE
                    724: *2000 :: end of the ibr-loop
                    725: *
                    726: *     .. update SVA(N)
                    727:          IF( ( SVA( N ).LT.ROOTBIG ) .AND. ( SVA( N ).GT.ROOTSFMIN ) )
1.6       bertrand  728:      $       THEN
1.1       bertrand  729:             SVA( N ) = DNRM2( M, A( 1, N ), 1 )*D( N )
                    730:          ELSE
                    731:             T = ZERO
1.4       bertrand  732:             AAPP = ONE
1.1       bertrand  733:             CALL DLASSQ( M, A( 1, N ), 1, T, AAPP )
                    734:             SVA( N ) = T*DSQRT( AAPP )*D( N )
                    735:          END IF
                    736: *
                    737: *     Additional steering devices
                    738: *
                    739:          IF( ( i.LT.SWBAND ) .AND. ( ( MXAAPQ.LE.ROOTTOL ) .OR.
1.6       bertrand  740:      $       ( ISWROT.LE.N ) ) )SWBAND = i
1.1       bertrand  741: 
                    742:          IF( ( i.GT.SWBAND+1 ) .AND. ( MXAAPQ.LT.DBLE( N )*TOL ) .AND.
1.6       bertrand  743:      $       ( DBLE( N )*MXAAPQ*MXSINJ.LT.TOL ) ) THEN
1.1       bertrand  744:             GO TO 1994
                    745:          END IF
                    746: 
                    747: *
                    748:          IF( NOTROT.GE.EMPTSW )GO TO 1994
                    749: 
                    750:  1993 CONTINUE
                    751: *     end i=1:NSWEEP loop
                    752: * #:) Reaching this point means that the procedure has completed the given
                    753: *     number of sweeps.
                    754:       INFO = NSWEEP - 1
                    755:       GO TO 1995
                    756:  1994 CONTINUE
                    757: * #:) Reaching this point means that during the i-th sweep all pivots were
                    758: *     below the given threshold, causing early exit.
                    759: 
                    760:       INFO = 0
                    761: * #:) INFO = 0 confirms successful iterations.
                    762:  1995 CONTINUE
                    763: *
                    764: *     Sort the vector D
                    765: *
                    766:       DO 5991 p = 1, N - 1
                    767:          q = IDAMAX( N-p+1, SVA( p ), 1 ) + p - 1
                    768:          IF( p.NE.q ) THEN
                    769:             TEMP1 = SVA( p )
                    770:             SVA( p ) = SVA( q )
                    771:             SVA( q ) = TEMP1
                    772:             TEMP1 = D( p )
                    773:             D( p ) = D( q )
                    774:             D( q ) = TEMP1
                    775:             CALL DSWAP( M, A( 1, p ), 1, A( 1, q ), 1 )
                    776:             IF( RSVEC )CALL DSWAP( MVL, V( 1, p ), 1, V( 1, q ), 1 )
                    777:          END IF
                    778:  5991 CONTINUE
                    779: *
                    780:       RETURN
                    781: *     ..
                    782: *     .. END OF DGSVJ1
                    783: *     ..
                    784:       END

CVSweb interface <joel.bertrand@systella.fr>