Annotation of rpl/lapack/lapack/dpstf2.f, revision 1.7

1.6       bertrand    1: *> \brief \b DPSTF2
                      2: *
                      3: *  =========== DOCUMENTATION ===========
                      4: *
                      5: * Online html documentation available at 
                      6: *            http://www.netlib.org/lapack/explore-html/ 
                      7: *
                      8: *> \htmlonly
                      9: *> Download DPSTF2 + dependencies 
                     10: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dpstf2.f"> 
                     11: *> [TGZ]</a> 
                     12: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dpstf2.f"> 
                     13: *> [ZIP]</a> 
                     14: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dpstf2.f"> 
                     15: *> [TXT]</a>
                     16: *> \endhtmlonly 
                     17: *
                     18: *  Definition:
                     19: *  ===========
                     20: *
                     21: *       SUBROUTINE DPSTF2( UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO )
                     22: * 
                     23: *       .. Scalar Arguments ..
                     24: *       DOUBLE PRECISION   TOL
                     25: *       INTEGER            INFO, LDA, N, RANK
                     26: *       CHARACTER          UPLO
                     27: *       ..
                     28: *       .. Array Arguments ..
                     29: *       DOUBLE PRECISION   A( LDA, * ), WORK( 2*N )
                     30: *       INTEGER            PIV( N )
                     31: *       ..
                     32: *  
                     33: *
                     34: *> \par Purpose:
                     35: *  =============
                     36: *>
                     37: *> \verbatim
                     38: *>
                     39: *> DPSTF2 computes the Cholesky factorization with complete
                     40: *> pivoting of a real symmetric positive semidefinite matrix A.
                     41: *>
                     42: *> The factorization has the form
                     43: *>    P**T * A * P = U**T * U ,  if UPLO = 'U',
                     44: *>    P**T * A * P = L  * L**T,  if UPLO = 'L',
                     45: *> where U is an upper triangular matrix and L is lower triangular, and
                     46: *> P is stored as vector PIV.
                     47: *>
                     48: *> This algorithm does not attempt to check that A is positive
                     49: *> semidefinite. This version of the algorithm calls level 2 BLAS.
                     50: *> \endverbatim
                     51: *
                     52: *  Arguments:
                     53: *  ==========
                     54: *
                     55: *> \param[in] UPLO
                     56: *> \verbatim
                     57: *>          UPLO is CHARACTER*1
                     58: *>          Specifies whether the upper or lower triangular part of the
                     59: *>          symmetric matrix A is stored.
                     60: *>          = 'U':  Upper triangular
                     61: *>          = 'L':  Lower triangular
                     62: *> \endverbatim
                     63: *>
                     64: *> \param[in] N
                     65: *> \verbatim
                     66: *>          N is INTEGER
                     67: *>          The order of the matrix A.  N >= 0.
                     68: *> \endverbatim
                     69: *>
                     70: *> \param[in,out] A
                     71: *> \verbatim
                     72: *>          A is DOUBLE PRECISION array, dimension (LDA,N)
                     73: *>          On entry, the symmetric matrix A.  If UPLO = 'U', the leading
                     74: *>          n by n upper triangular part of A contains the upper
                     75: *>          triangular part of the matrix A, and the strictly lower
                     76: *>          triangular part of A is not referenced.  If UPLO = 'L', the
                     77: *>          leading n by n lower triangular part of A contains the lower
                     78: *>          triangular part of the matrix A, and the strictly upper
                     79: *>          triangular part of A is not referenced.
                     80: *>
                     81: *>          On exit, if INFO = 0, the factor U or L from the Cholesky
                     82: *>          factorization as above.
                     83: *> \endverbatim
                     84: *>
                     85: *> \param[out] PIV
                     86: *> \verbatim
                     87: *>          PIV is INTEGER array, dimension (N)
                     88: *>          PIV is such that the nonzero entries are P( PIV(K), K ) = 1.
                     89: *> \endverbatim
                     90: *>
                     91: *> \param[out] RANK
                     92: *> \verbatim
                     93: *>          RANK is INTEGER
                     94: *>          The rank of A given by the number of steps the algorithm
                     95: *>          completed.
                     96: *> \endverbatim
                     97: *>
                     98: *> \param[in] TOL
                     99: *> \verbatim
                    100: *>          TOL is DOUBLE PRECISION
                    101: *>          User defined tolerance. If TOL < 0, then N*U*MAX( A( K,K ) )
                    102: *>          will be used. The algorithm terminates at the (K-1)st step
                    103: *>          if the pivot <= TOL.
                    104: *> \endverbatim
                    105: *>
                    106: *> \param[in] LDA
                    107: *> \verbatim
                    108: *>          LDA is INTEGER
                    109: *>          The leading dimension of the array A.  LDA >= max(1,N).
                    110: *> \endverbatim
                    111: *>
                    112: *> \param[out] WORK
                    113: *> \verbatim
                    114: *>          WORK is DOUBLE PRECISION array, dimension (2*N)
                    115: *>          Work space.
                    116: *> \endverbatim
                    117: *>
                    118: *> \param[out] INFO
                    119: *> \verbatim
                    120: *>          INFO is INTEGER
                    121: *>          < 0: If INFO = -K, the K-th argument had an illegal value,
                    122: *>          = 0: algorithm completed successfully, and
                    123: *>          > 0: the matrix A is either rank deficient with computed rank
                    124: *>               as returned in RANK, or is indefinite.  See Section 7 of
                    125: *>               LAPACK Working Note #161 for further information.
                    126: *> \endverbatim
                    127: *
                    128: *  Authors:
                    129: *  ========
                    130: *
                    131: *> \author Univ. of Tennessee 
                    132: *> \author Univ. of California Berkeley 
                    133: *> \author Univ. of Colorado Denver 
                    134: *> \author NAG Ltd. 
                    135: *
                    136: *> \date November 2011
                    137: *
                    138: *> \ingroup doubleOTHERcomputational
                    139: *
                    140: *  =====================================================================
1.1       bertrand  141:       SUBROUTINE DPSTF2( UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO )
                    142: *
1.6       bertrand  143: *  -- LAPACK computational routine (version 3.4.0) --
                    144: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
                    145: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
                    146: *     November 2011
1.1       bertrand  147: *
                    148: *     .. Scalar Arguments ..
                    149:       DOUBLE PRECISION   TOL
                    150:       INTEGER            INFO, LDA, N, RANK
                    151:       CHARACTER          UPLO
                    152: *     ..
                    153: *     .. Array Arguments ..
                    154:       DOUBLE PRECISION   A( LDA, * ), WORK( 2*N )
                    155:       INTEGER            PIV( N )
                    156: *     ..
                    157: *
                    158: *  =====================================================================
                    159: *
                    160: *     .. Parameters ..
                    161:       DOUBLE PRECISION   ONE, ZERO
                    162:       PARAMETER          ( ONE = 1.0D+0, ZERO = 0.0D+0 )
                    163: *     ..
                    164: *     .. Local Scalars ..
                    165:       DOUBLE PRECISION   AJJ, DSTOP, DTEMP
                    166:       INTEGER            I, ITEMP, J, PVT
                    167:       LOGICAL            UPPER
                    168: *     ..
                    169: *     .. External Functions ..
                    170:       DOUBLE PRECISION   DLAMCH
                    171:       LOGICAL            LSAME, DISNAN
                    172:       EXTERNAL           DLAMCH, LSAME, DISNAN
                    173: *     ..
                    174: *     .. External Subroutines ..
                    175:       EXTERNAL           DGEMV, DSCAL, DSWAP, XERBLA
                    176: *     ..
                    177: *     .. Intrinsic Functions ..
                    178:       INTRINSIC          MAX, SQRT, MAXLOC
                    179: *     ..
                    180: *     .. Executable Statements ..
                    181: *
                    182: *     Test the input parameters
                    183: *
                    184:       INFO = 0
                    185:       UPPER = LSAME( UPLO, 'U' )
                    186:       IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
                    187:          INFO = -1
                    188:       ELSE IF( N.LT.0 ) THEN
                    189:          INFO = -2
                    190:       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
                    191:          INFO = -4
                    192:       END IF
                    193:       IF( INFO.NE.0 ) THEN
                    194:          CALL XERBLA( 'DPSTF2', -INFO )
                    195:          RETURN
                    196:       END IF
                    197: *
                    198: *     Quick return if possible
                    199: *
                    200:       IF( N.EQ.0 )
                    201:      $   RETURN
                    202: *
                    203: *     Initialize PIV
                    204: *
                    205:       DO 100 I = 1, N
                    206:          PIV( I ) = I
                    207:   100 CONTINUE
                    208: *
                    209: *     Compute stopping value
                    210: *
                    211:       PVT = 1
                    212:       AJJ = A( PVT, PVT )
                    213:       DO I = 2, N
                    214:          IF( A( I, I ).GT.AJJ ) THEN
                    215:             PVT = I
                    216:             AJJ = A( PVT, PVT )
                    217:          END IF
                    218:       END DO
                    219:       IF( AJJ.EQ.ZERO.OR.DISNAN( AJJ ) ) THEN
                    220:          RANK = 0
                    221:          INFO = 1
                    222:          GO TO 170
                    223:       END IF
                    224: *
                    225: *     Compute stopping value if not supplied
                    226: *
                    227:       IF( TOL.LT.ZERO ) THEN
                    228:          DSTOP = N * DLAMCH( 'Epsilon' ) * AJJ
                    229:       ELSE
                    230:          DSTOP = TOL
                    231:       END IF
                    232: *
                    233: *     Set first half of WORK to zero, holds dot products
                    234: *
                    235:       DO 110 I = 1, N
                    236:          WORK( I ) = 0
                    237:   110 CONTINUE
                    238: *
                    239:       IF( UPPER ) THEN
                    240: *
1.5       bertrand  241: *        Compute the Cholesky factorization P**T * A * P = U**T * U
1.1       bertrand  242: *
                    243:          DO 130 J = 1, N
                    244: *
                    245: *        Find pivot, test for exit, else swap rows and columns
                    246: *        Update dot products, compute possible pivots which are
                    247: *        stored in the second half of WORK
                    248: *
                    249:             DO 120 I = J, N
                    250: *
                    251:                IF( J.GT.1 ) THEN
                    252:                   WORK( I ) = WORK( I ) + A( J-1, I )**2
                    253:                END IF
                    254:                WORK( N+I ) = A( I, I ) - WORK( I )
                    255: *
                    256:   120       CONTINUE
                    257: *
                    258:             IF( J.GT.1 ) THEN
                    259:                ITEMP = MAXLOC( WORK( (N+J):(2*N) ), 1 )
                    260:                PVT = ITEMP + J - 1
                    261:                AJJ = WORK( N+PVT )
                    262:                IF( AJJ.LE.DSTOP.OR.DISNAN( AJJ ) ) THEN
                    263:                   A( J, J ) = AJJ
                    264:                   GO TO 160
                    265:                END IF
                    266:             END IF
                    267: *
                    268:             IF( J.NE.PVT ) THEN
                    269: *
                    270: *              Pivot OK, so can now swap pivot rows and columns
                    271: *
                    272:                A( PVT, PVT ) = A( J, J )
                    273:                CALL DSWAP( J-1, A( 1, J ), 1, A( 1, PVT ), 1 )
                    274:                IF( PVT.LT.N )
                    275:      $            CALL DSWAP( N-PVT, A( J, PVT+1 ), LDA,
                    276:      $                        A( PVT, PVT+1 ), LDA )
                    277:                CALL DSWAP( PVT-J-1, A( J, J+1 ), LDA, A( J+1, PVT ), 1 )
                    278: *
                    279: *              Swap dot products and PIV
                    280: *
                    281:                DTEMP = WORK( J )
                    282:                WORK( J ) = WORK( PVT )
                    283:                WORK( PVT ) = DTEMP
                    284:                ITEMP = PIV( PVT )
                    285:                PIV( PVT ) = PIV( J )
                    286:                PIV( J ) = ITEMP
                    287:             END IF
                    288: *
                    289:             AJJ = SQRT( AJJ )
                    290:             A( J, J ) = AJJ
                    291: *
                    292: *           Compute elements J+1:N of row J
                    293: *
                    294:             IF( J.LT.N ) THEN
                    295:                CALL DGEMV( 'Trans', J-1, N-J, -ONE, A( 1, J+1 ), LDA,
                    296:      $                     A( 1, J ), 1, ONE, A( J, J+1 ), LDA )
                    297:                CALL DSCAL( N-J, ONE / AJJ, A( J, J+1 ), LDA )
                    298:             END IF
                    299: *
                    300:   130    CONTINUE
                    301: *
                    302:       ELSE
                    303: *
1.5       bertrand  304: *        Compute the Cholesky factorization P**T * A * P = L * L**T
1.1       bertrand  305: *
                    306:          DO 150 J = 1, N
                    307: *
                    308: *        Find pivot, test for exit, else swap rows and columns
                    309: *        Update dot products, compute possible pivots which are
                    310: *        stored in the second half of WORK
                    311: *
                    312:             DO 140 I = J, N
                    313: *
                    314:                IF( J.GT.1 ) THEN
                    315:                   WORK( I ) = WORK( I ) + A( I, J-1 )**2
                    316:                END IF
                    317:                WORK( N+I ) = A( I, I ) - WORK( I )
                    318: *
                    319:   140       CONTINUE
                    320: *
                    321:             IF( J.GT.1 ) THEN
                    322:                ITEMP = MAXLOC( WORK( (N+J):(2*N) ), 1 )
                    323:                PVT = ITEMP + J - 1
                    324:                AJJ = WORK( N+PVT )
                    325:                IF( AJJ.LE.DSTOP.OR.DISNAN( AJJ ) ) THEN
                    326:                   A( J, J ) = AJJ
                    327:                   GO TO 160
                    328:                END IF
                    329:             END IF
                    330: *
                    331:             IF( J.NE.PVT ) THEN
                    332: *
                    333: *              Pivot OK, so can now swap pivot rows and columns
                    334: *
                    335:                A( PVT, PVT ) = A( J, J )
                    336:                CALL DSWAP( J-1, A( J, 1 ), LDA, A( PVT, 1 ), LDA )
                    337:                IF( PVT.LT.N )
                    338:      $            CALL DSWAP( N-PVT, A( PVT+1, J ), 1, A( PVT+1, PVT ),
                    339:      $                        1 )
                    340:                CALL DSWAP( PVT-J-1, A( J+1, J ), 1, A( PVT, J+1 ), LDA )
                    341: *
                    342: *              Swap dot products and PIV
                    343: *
                    344:                DTEMP = WORK( J )
                    345:                WORK( J ) = WORK( PVT )
                    346:                WORK( PVT ) = DTEMP
                    347:                ITEMP = PIV( PVT )
                    348:                PIV( PVT ) = PIV( J )
                    349:                PIV( J ) = ITEMP
                    350:             END IF
                    351: *
                    352:             AJJ = SQRT( AJJ )
                    353:             A( J, J ) = AJJ
                    354: *
                    355: *           Compute elements J+1:N of column J
                    356: *
                    357:             IF( J.LT.N ) THEN
                    358:                CALL DGEMV( 'No Trans', N-J, J-1, -ONE, A( J+1, 1 ), LDA,
                    359:      $                     A( J, 1 ), LDA, ONE, A( J+1, J ), 1 )
                    360:                CALL DSCAL( N-J, ONE / AJJ, A( J+1, J ), 1 )
                    361:             END IF
                    362: *
                    363:   150    CONTINUE
                    364: *
                    365:       END IF
                    366: *
                    367: *     Ran to completion, A has full rank
                    368: *
                    369:       RANK = N
                    370: *
                    371:       GO TO 170
                    372:   160 CONTINUE
                    373: *
                    374: *     Rank is number of steps completed.  Set INFO = 1 to signal
                    375: *     that the factorization cannot be used to solve a system.
                    376: *
                    377:       RANK = J - 1
                    378:       INFO = 1
                    379: *
                    380:   170 CONTINUE
                    381:       RETURN
                    382: *
                    383: *     End of DPSTF2
                    384: *
                    385:       END

CVSweb interface <joel.bertrand@systella.fr>