Annotation of rpl/lapack/lapack/dlasd3.f, revision 1.21

1.13      bertrand    1: *> \brief \b DLASD3 finds all square roots of the roots of the secular equation, as defined by the values in D and Z, and then updates the singular vectors by matrix multiplication. Used by sbdsdc.
1.10      bertrand    2: *
                      3: *  =========== DOCUMENTATION ===========
                      4: *
1.18      bertrand    5: * Online html documentation available at
                      6: *            http://www.netlib.org/lapack/explore-html/
1.10      bertrand    7: *
                      8: *> \htmlonly
1.18      bertrand    9: *> Download DLASD3 + dependencies
                     10: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlasd3.f">
                     11: *> [TGZ]</a>
                     12: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlasd3.f">
                     13: *> [ZIP]</a>
                     14: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlasd3.f">
1.10      bertrand   15: *> [TXT]</a>
1.18      bertrand   16: *> \endhtmlonly
1.10      bertrand   17: *
                     18: *  Definition:
                     19: *  ===========
                     20: *
                     21: *       SUBROUTINE DLASD3( NL, NR, SQRE, K, D, Q, LDQ, DSIGMA, U, LDU, U2,
                     22: *                          LDU2, VT, LDVT, VT2, LDVT2, IDXC, CTOT, Z,
                     23: *                          INFO )
1.18      bertrand   24: *
1.10      bertrand   25: *       .. Scalar Arguments ..
                     26: *       INTEGER            INFO, K, LDQ, LDU, LDU2, LDVT, LDVT2, NL, NR,
                     27: *      $                   SQRE
                     28: *       ..
                     29: *       .. Array Arguments ..
                     30: *       INTEGER            CTOT( * ), IDXC( * )
                     31: *       DOUBLE PRECISION   D( * ), DSIGMA( * ), Q( LDQ, * ), U( LDU, * ),
                     32: *      $                   U2( LDU2, * ), VT( LDVT, * ), VT2( LDVT2, * ),
                     33: *      $                   Z( * )
                     34: *       ..
1.18      bertrand   35: *
1.10      bertrand   36: *
                     37: *> \par Purpose:
                     38: *  =============
                     39: *>
                     40: *> \verbatim
                     41: *>
                     42: *> DLASD3 finds all the square roots of the roots of the secular
                     43: *> equation, as defined by the values in D and Z.  It makes the
                     44: *> appropriate calls to DLASD4 and then updates the singular
                     45: *> vectors by matrix multiplication.
                     46: *>
                     47: *> This code makes very mild assumptions about floating point
                     48: *> arithmetic. It will work on machines with a guard digit in
                     49: *> add/subtract, or on those binary machines without guard digits
                     50: *> which subtract like the Cray XMP, Cray YMP, Cray C 90, or Cray 2.
                     51: *> It could conceivably fail on hexadecimal or decimal machines
                     52: *> without guard digits, but we know of none.
                     53: *>
                     54: *> DLASD3 is called from DLASD1.
                     55: *> \endverbatim
                     56: *
                     57: *  Arguments:
                     58: *  ==========
                     59: *
                     60: *> \param[in] NL
                     61: *> \verbatim
                     62: *>          NL is INTEGER
                     63: *>         The row dimension of the upper block.  NL >= 1.
                     64: *> \endverbatim
                     65: *>
                     66: *> \param[in] NR
                     67: *> \verbatim
                     68: *>          NR is INTEGER
                     69: *>         The row dimension of the lower block.  NR >= 1.
                     70: *> \endverbatim
                     71: *>
                     72: *> \param[in] SQRE
                     73: *> \verbatim
                     74: *>          SQRE is INTEGER
                     75: *>         = 0: the lower block is an NR-by-NR square matrix.
                     76: *>         = 1: the lower block is an NR-by-(NR+1) rectangular matrix.
                     77: *>
                     78: *>         The bidiagonal matrix has N = NL + NR + 1 rows and
                     79: *>         M = N + SQRE >= N columns.
                     80: *> \endverbatim
                     81: *>
                     82: *> \param[in] K
                     83: *> \verbatim
                     84: *>          K is INTEGER
                     85: *>         The size of the secular equation, 1 =< K = < N.
                     86: *> \endverbatim
                     87: *>
                     88: *> \param[out] D
                     89: *> \verbatim
                     90: *>          D is DOUBLE PRECISION array, dimension(K)
                     91: *>         On exit the square roots of the roots of the secular equation,
                     92: *>         in ascending order.
                     93: *> \endverbatim
                     94: *>
                     95: *> \param[out] Q
                     96: *> \verbatim
1.20      bertrand   97: *>          Q is DOUBLE PRECISION array, dimension (LDQ,K)
1.10      bertrand   98: *> \endverbatim
                     99: *>
                    100: *> \param[in] LDQ
                    101: *> \verbatim
                    102: *>          LDQ is INTEGER
                    103: *>         The leading dimension of the array Q.  LDQ >= K.
                    104: *> \endverbatim
                    105: *>
1.20      bertrand  106: *> \param[in,out] DSIGMA
1.10      bertrand  107: *> \verbatim
                    108: *>          DSIGMA is DOUBLE PRECISION array, dimension(K)
                    109: *>         The first K elements of this array contain the old roots
                    110: *>         of the deflated updating problem.  These are the poles
                    111: *>         of the secular equation.
                    112: *> \endverbatim
                    113: *>
                    114: *> \param[out] U
                    115: *> \verbatim
                    116: *>          U is DOUBLE PRECISION array, dimension (LDU, N)
                    117: *>         The last N - K columns of this matrix contain the deflated
                    118: *>         left singular vectors.
                    119: *> \endverbatim
                    120: *>
                    121: *> \param[in] LDU
                    122: *> \verbatim
                    123: *>          LDU is INTEGER
                    124: *>         The leading dimension of the array U.  LDU >= N.
                    125: *> \endverbatim
                    126: *>
1.20      bertrand  127: *> \param[in] U2
1.10      bertrand  128: *> \verbatim
                    129: *>          U2 is DOUBLE PRECISION array, dimension (LDU2, N)
                    130: *>         The first K columns of this matrix contain the non-deflated
                    131: *>         left singular vectors for the split problem.
                    132: *> \endverbatim
                    133: *>
                    134: *> \param[in] LDU2
                    135: *> \verbatim
                    136: *>          LDU2 is INTEGER
                    137: *>         The leading dimension of the array U2.  LDU2 >= N.
                    138: *> \endverbatim
                    139: *>
                    140: *> \param[out] VT
                    141: *> \verbatim
                    142: *>          VT is DOUBLE PRECISION array, dimension (LDVT, M)
                    143: *>         The last M - K columns of VT**T contain the deflated
                    144: *>         right singular vectors.
                    145: *> \endverbatim
                    146: *>
                    147: *> \param[in] LDVT
                    148: *> \verbatim
                    149: *>          LDVT is INTEGER
                    150: *>         The leading dimension of the array VT.  LDVT >= N.
                    151: *> \endverbatim
                    152: *>
                    153: *> \param[in,out] VT2
                    154: *> \verbatim
                    155: *>          VT2 is DOUBLE PRECISION array, dimension (LDVT2, N)
                    156: *>         The first K columns of VT2**T contain the non-deflated
                    157: *>         right singular vectors for the split problem.
                    158: *> \endverbatim
                    159: *>
                    160: *> \param[in] LDVT2
                    161: *> \verbatim
                    162: *>          LDVT2 is INTEGER
                    163: *>         The leading dimension of the array VT2.  LDVT2 >= N.
                    164: *> \endverbatim
                    165: *>
                    166: *> \param[in] IDXC
                    167: *> \verbatim
                    168: *>          IDXC is INTEGER array, dimension ( N )
                    169: *>         The permutation used to arrange the columns of U (and rows of
                    170: *>         VT) into three groups:  the first group contains non-zero
                    171: *>         entries only at and above (or before) NL +1; the second
                    172: *>         contains non-zero entries only at and below (or after) NL+2;
                    173: *>         and the third is dense. The first column of U and the row of
                    174: *>         VT are treated separately, however.
                    175: *>
                    176: *>         The rows of the singular vectors found by DLASD4
                    177: *>         must be likewise permuted before the matrix multiplies can
                    178: *>         take place.
                    179: *> \endverbatim
                    180: *>
                    181: *> \param[in] CTOT
                    182: *> \verbatim
                    183: *>          CTOT is INTEGER array, dimension ( 4 )
                    184: *>         A count of the total number of the various types of columns
                    185: *>         in U (or rows in VT), as described in IDXC. The fourth column
                    186: *>         type is any column which has been deflated.
                    187: *> \endverbatim
                    188: *>
1.20      bertrand  189: *> \param[in,out] Z
1.10      bertrand  190: *> \verbatim
                    191: *>          Z is DOUBLE PRECISION array, dimension (K)
                    192: *>         The first K elements of this array contain the components
                    193: *>         of the deflation-adjusted updating row vector.
                    194: *> \endverbatim
                    195: *>
                    196: *> \param[out] INFO
                    197: *> \verbatim
                    198: *>          INFO is INTEGER
                    199: *>         = 0:  successful exit.
                    200: *>         < 0:  if INFO = -i, the i-th argument had an illegal value.
                    201: *>         > 0:  if INFO = 1, a singular value did not converge
                    202: *> \endverbatim
                    203: *
                    204: *  Authors:
                    205: *  ========
                    206: *
1.18      bertrand  207: *> \author Univ. of Tennessee
                    208: *> \author Univ. of California Berkeley
                    209: *> \author Univ. of Colorado Denver
                    210: *> \author NAG Ltd.
1.10      bertrand  211: *
1.20      bertrand  212: *> \date June 2017
1.10      bertrand  213: *
1.18      bertrand  214: *> \ingroup OTHERauxiliary
1.10      bertrand  215: *
                    216: *> \par Contributors:
                    217: *  ==================
                    218: *>
                    219: *>     Ming Gu and Huan Ren, Computer Science Division, University of
                    220: *>     California at Berkeley, USA
                    221: *>
                    222: *  =====================================================================
1.1       bertrand  223:       SUBROUTINE DLASD3( NL, NR, SQRE, K, D, Q, LDQ, DSIGMA, U, LDU, U2,
                    224:      $                   LDU2, VT, LDVT, VT2, LDVT2, IDXC, CTOT, Z,
                    225:      $                   INFO )
                    226: *
1.20      bertrand  227: *  -- LAPACK auxiliary routine (version 3.7.1) --
1.1       bertrand  228: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
                    229: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
1.20      bertrand  230: *     June 2017
1.1       bertrand  231: *
                    232: *     .. Scalar Arguments ..
                    233:       INTEGER            INFO, K, LDQ, LDU, LDU2, LDVT, LDVT2, NL, NR,
                    234:      $                   SQRE
                    235: *     ..
                    236: *     .. Array Arguments ..
                    237:       INTEGER            CTOT( * ), IDXC( * )
                    238:       DOUBLE PRECISION   D( * ), DSIGMA( * ), Q( LDQ, * ), U( LDU, * ),
                    239:      $                   U2( LDU2, * ), VT( LDVT, * ), VT2( LDVT2, * ),
                    240:      $                   Z( * )
                    241: *     ..
                    242: *
                    243: *  =====================================================================
                    244: *
                    245: *     .. Parameters ..
                    246:       DOUBLE PRECISION   ONE, ZERO, NEGONE
                    247:       PARAMETER          ( ONE = 1.0D+0, ZERO = 0.0D+0,
                    248:      $                   NEGONE = -1.0D+0 )
                    249: *     ..
                    250: *     .. Local Scalars ..
                    251:       INTEGER            CTEMP, I, J, JC, KTEMP, M, N, NLP1, NLP2, NRP1
                    252:       DOUBLE PRECISION   RHO, TEMP
                    253: *     ..
                    254: *     .. External Functions ..
                    255:       DOUBLE PRECISION   DLAMC3, DNRM2
                    256:       EXTERNAL           DLAMC3, DNRM2
                    257: *     ..
                    258: *     .. External Subroutines ..
                    259:       EXTERNAL           DCOPY, DGEMM, DLACPY, DLASCL, DLASD4, XERBLA
                    260: *     ..
                    261: *     .. Intrinsic Functions ..
                    262:       INTRINSIC          ABS, SIGN, SQRT
                    263: *     ..
                    264: *     .. Executable Statements ..
                    265: *
                    266: *     Test the input parameters.
                    267: *
                    268:       INFO = 0
                    269: *
                    270:       IF( NL.LT.1 ) THEN
                    271:          INFO = -1
                    272:       ELSE IF( NR.LT.1 ) THEN
                    273:          INFO = -2
                    274:       ELSE IF( ( SQRE.NE.1 ) .AND. ( SQRE.NE.0 ) ) THEN
                    275:          INFO = -3
                    276:       END IF
                    277: *
                    278:       N = NL + NR + 1
                    279:       M = N + SQRE
                    280:       NLP1 = NL + 1
                    281:       NLP2 = NL + 2
                    282: *
                    283:       IF( ( K.LT.1 ) .OR. ( K.GT.N ) ) THEN
                    284:          INFO = -4
                    285:       ELSE IF( LDQ.LT.K ) THEN
                    286:          INFO = -7
                    287:       ELSE IF( LDU.LT.N ) THEN
                    288:          INFO = -10
                    289:       ELSE IF( LDU2.LT.N ) THEN
                    290:          INFO = -12
                    291:       ELSE IF( LDVT.LT.M ) THEN
                    292:          INFO = -14
                    293:       ELSE IF( LDVT2.LT.M ) THEN
                    294:          INFO = -16
                    295:       END IF
                    296:       IF( INFO.NE.0 ) THEN
                    297:          CALL XERBLA( 'DLASD3', -INFO )
                    298:          RETURN
                    299:       END IF
                    300: *
                    301: *     Quick return if possible
                    302: *
                    303:       IF( K.EQ.1 ) THEN
                    304:          D( 1 ) = ABS( Z( 1 ) )
                    305:          CALL DCOPY( M, VT2( 1, 1 ), LDVT2, VT( 1, 1 ), LDVT )
                    306:          IF( Z( 1 ).GT.ZERO ) THEN
                    307:             CALL DCOPY( N, U2( 1, 1 ), 1, U( 1, 1 ), 1 )
                    308:          ELSE
                    309:             DO 10 I = 1, N
                    310:                U( I, 1 ) = -U2( I, 1 )
                    311:    10       CONTINUE
                    312:          END IF
                    313:          RETURN
                    314:       END IF
                    315: *
                    316: *     Modify values DSIGMA(i) to make sure all DSIGMA(i)-DSIGMA(j) can
                    317: *     be computed with high relative accuracy (barring over/underflow).
                    318: *     This is a problem on machines without a guard digit in
                    319: *     add/subtract (Cray XMP, Cray YMP, Cray C 90 and Cray 2).
                    320: *     The following code replaces DSIGMA(I) by 2*DSIGMA(I)-DSIGMA(I),
                    321: *     which on any of these machines zeros out the bottommost
                    322: *     bit of DSIGMA(I) if it is 1; this makes the subsequent
                    323: *     subtractions DSIGMA(I)-DSIGMA(J) unproblematic when cancellation
                    324: *     occurs. On binary machines with a guard digit (almost all
                    325: *     machines) it does not change DSIGMA(I) at all. On hexadecimal
                    326: *     and decimal machines with a guard digit, it slightly
                    327: *     changes the bottommost bits of DSIGMA(I). It does not account
                    328: *     for hexadecimal or decimal machines without guard digits
                    329: *     (we know of none). We use a subroutine call to compute
                    330: *     2*DSIGMA(I) to prevent optimizing compilers from eliminating
                    331: *     this code.
                    332: *
                    333:       DO 20 I = 1, K
                    334:          DSIGMA( I ) = DLAMC3( DSIGMA( I ), DSIGMA( I ) ) - DSIGMA( I )
                    335:    20 CONTINUE
                    336: *
                    337: *     Keep a copy of Z.
                    338: *
                    339:       CALL DCOPY( K, Z, 1, Q, 1 )
                    340: *
                    341: *     Normalize Z.
                    342: *
                    343:       RHO = DNRM2( K, Z, 1 )
                    344:       CALL DLASCL( 'G', 0, 0, RHO, ONE, K, 1, Z, K, INFO )
                    345:       RHO = RHO*RHO
                    346: *
                    347: *     Find the new singular values.
                    348: *
                    349:       DO 30 J = 1, K
                    350:          CALL DLASD4( K, J, DSIGMA, Z, U( 1, J ), RHO, D( J ),
                    351:      $                VT( 1, J ), INFO )
                    352: *
1.16      bertrand  353: *        If the zero finder fails, report the convergence failure.
1.1       bertrand  354: *
                    355:          IF( INFO.NE.0 ) THEN
                    356:             RETURN
                    357:          END IF
                    358:    30 CONTINUE
                    359: *
                    360: *     Compute updated Z.
                    361: *
                    362:       DO 60 I = 1, K
                    363:          Z( I ) = U( I, K )*VT( I, K )
                    364:          DO 40 J = 1, I - 1
                    365:             Z( I ) = Z( I )*( U( I, J )*VT( I, J ) /
                    366:      $               ( DSIGMA( I )-DSIGMA( J ) ) /
                    367:      $               ( DSIGMA( I )+DSIGMA( J ) ) )
                    368:    40    CONTINUE
                    369:          DO 50 J = I, K - 1
                    370:             Z( I ) = Z( I )*( U( I, J )*VT( I, J ) /
                    371:      $               ( DSIGMA( I )-DSIGMA( J+1 ) ) /
                    372:      $               ( DSIGMA( I )+DSIGMA( J+1 ) ) )
                    373:    50    CONTINUE
                    374:          Z( I ) = SIGN( SQRT( ABS( Z( I ) ) ), Q( I, 1 ) )
                    375:    60 CONTINUE
                    376: *
                    377: *     Compute left singular vectors of the modified diagonal matrix,
                    378: *     and store related information for the right singular vectors.
                    379: *
                    380:       DO 90 I = 1, K
                    381:          VT( 1, I ) = Z( 1 ) / U( 1, I ) / VT( 1, I )
                    382:          U( 1, I ) = NEGONE
                    383:          DO 70 J = 2, K
                    384:             VT( J, I ) = Z( J ) / U( J, I ) / VT( J, I )
                    385:             U( J, I ) = DSIGMA( J )*VT( J, I )
                    386:    70    CONTINUE
                    387:          TEMP = DNRM2( K, U( 1, I ), 1 )
                    388:          Q( 1, I ) = U( 1, I ) / TEMP
                    389:          DO 80 J = 2, K
                    390:             JC = IDXC( J )
                    391:             Q( J, I ) = U( JC, I ) / TEMP
                    392:    80    CONTINUE
                    393:    90 CONTINUE
                    394: *
                    395: *     Update the left singular vector matrix.
                    396: *
                    397:       IF( K.EQ.2 ) THEN
                    398:          CALL DGEMM( 'N', 'N', N, K, K, ONE, U2, LDU2, Q, LDQ, ZERO, U,
                    399:      $               LDU )
                    400:          GO TO 100
                    401:       END IF
                    402:       IF( CTOT( 1 ).GT.0 ) THEN
                    403:          CALL DGEMM( 'N', 'N', NL, K, CTOT( 1 ), ONE, U2( 1, 2 ), LDU2,
                    404:      $               Q( 2, 1 ), LDQ, ZERO, U( 1, 1 ), LDU )
                    405:          IF( CTOT( 3 ).GT.0 ) THEN
                    406:             KTEMP = 2 + CTOT( 1 ) + CTOT( 2 )
                    407:             CALL DGEMM( 'N', 'N', NL, K, CTOT( 3 ), ONE, U2( 1, KTEMP ),
                    408:      $                  LDU2, Q( KTEMP, 1 ), LDQ, ONE, U( 1, 1 ), LDU )
                    409:          END IF
                    410:       ELSE IF( CTOT( 3 ).GT.0 ) THEN
                    411:          KTEMP = 2 + CTOT( 1 ) + CTOT( 2 )
                    412:          CALL DGEMM( 'N', 'N', NL, K, CTOT( 3 ), ONE, U2( 1, KTEMP ),
                    413:      $               LDU2, Q( KTEMP, 1 ), LDQ, ZERO, U( 1, 1 ), LDU )
                    414:       ELSE
                    415:          CALL DLACPY( 'F', NL, K, U2, LDU2, U, LDU )
                    416:       END IF
                    417:       CALL DCOPY( K, Q( 1, 1 ), LDQ, U( NLP1, 1 ), LDU )
                    418:       KTEMP = 2 + CTOT( 1 )
                    419:       CTEMP = CTOT( 2 ) + CTOT( 3 )
                    420:       CALL DGEMM( 'N', 'N', NR, K, CTEMP, ONE, U2( NLP2, KTEMP ), LDU2,
                    421:      $            Q( KTEMP, 1 ), LDQ, ZERO, U( NLP2, 1 ), LDU )
                    422: *
                    423: *     Generate the right singular vectors.
                    424: *
                    425:   100 CONTINUE
                    426:       DO 120 I = 1, K
                    427:          TEMP = DNRM2( K, VT( 1, I ), 1 )
                    428:          Q( I, 1 ) = VT( 1, I ) / TEMP
                    429:          DO 110 J = 2, K
                    430:             JC = IDXC( J )
                    431:             Q( I, J ) = VT( JC, I ) / TEMP
                    432:   110    CONTINUE
                    433:   120 CONTINUE
                    434: *
                    435: *     Update the right singular vector matrix.
                    436: *
                    437:       IF( K.EQ.2 ) THEN
                    438:          CALL DGEMM( 'N', 'N', K, M, K, ONE, Q, LDQ, VT2, LDVT2, ZERO,
                    439:      $               VT, LDVT )
                    440:          RETURN
                    441:       END IF
                    442:       KTEMP = 1 + CTOT( 1 )
                    443:       CALL DGEMM( 'N', 'N', K, NLP1, KTEMP, ONE, Q( 1, 1 ), LDQ,
                    444:      $            VT2( 1, 1 ), LDVT2, ZERO, VT( 1, 1 ), LDVT )
                    445:       KTEMP = 2 + CTOT( 1 ) + CTOT( 2 )
                    446:       IF( KTEMP.LE.LDVT2 )
                    447:      $   CALL DGEMM( 'N', 'N', K, NLP1, CTOT( 3 ), ONE, Q( 1, KTEMP ),
                    448:      $               LDQ, VT2( KTEMP, 1 ), LDVT2, ONE, VT( 1, 1 ),
                    449:      $               LDVT )
                    450: *
                    451:       KTEMP = CTOT( 1 ) + 1
                    452:       NRP1 = NR + SQRE
                    453:       IF( KTEMP.GT.1 ) THEN
                    454:          DO 130 I = 1, K
                    455:             Q( I, KTEMP ) = Q( I, 1 )
                    456:   130    CONTINUE
                    457:          DO 140 I = NLP2, M
                    458:             VT2( KTEMP, I ) = VT2( 1, I )
                    459:   140    CONTINUE
                    460:       END IF
                    461:       CTEMP = 1 + CTOT( 2 ) + CTOT( 3 )
                    462:       CALL DGEMM( 'N', 'N', K, NRP1, CTEMP, ONE, Q( 1, KTEMP ), LDQ,
                    463:      $            VT2( KTEMP, NLP2 ), LDVT2, ZERO, VT( 1, NLP2 ), LDVT )
                    464: *
                    465:       RETURN
                    466: *
                    467: *     End of DLASD3
                    468: *
                    469:       END

CVSweb interface <joel.bertrand@systella.fr>