Annotation of rpl/lapack/lapack/zhptrs.f, revision 1.18

1.9       bertrand    1: *> \brief \b ZHPTRS
                      2: *
                      3: *  =========== DOCUMENTATION ===========
                      4: *
1.15      bertrand    5: * Online html documentation available at
                      6: *            http://www.netlib.org/lapack/explore-html/
1.9       bertrand    7: *
                      8: *> \htmlonly
1.15      bertrand    9: *> Download ZHPTRS + dependencies
                     10: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhptrs.f">
                     11: *> [TGZ]</a>
                     12: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhptrs.f">
                     13: *> [ZIP]</a>
                     14: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhptrs.f">
1.9       bertrand   15: *> [TXT]</a>
1.15      bertrand   16: *> \endhtmlonly
1.9       bertrand   17: *
                     18: *  Definition:
                     19: *  ===========
                     20: *
                     21: *       SUBROUTINE ZHPTRS( UPLO, N, NRHS, AP, IPIV, B, LDB, INFO )
1.15      bertrand   22: *
1.9       bertrand   23: *       .. Scalar Arguments ..
                     24: *       CHARACTER          UPLO
                     25: *       INTEGER            INFO, LDB, N, NRHS
                     26: *       ..
                     27: *       .. Array Arguments ..
                     28: *       INTEGER            IPIV( * )
                     29: *       COMPLEX*16         AP( * ), B( LDB, * )
                     30: *       ..
1.15      bertrand   31: *
1.9       bertrand   32: *
                     33: *> \par Purpose:
                     34: *  =============
                     35: *>
                     36: *> \verbatim
                     37: *>
                     38: *> ZHPTRS solves a system of linear equations A*X = B with a complex
                     39: *> Hermitian matrix A stored in packed format using the factorization
                     40: *> A = U*D*U**H or A = L*D*L**H computed by ZHPTRF.
                     41: *> \endverbatim
                     42: *
                     43: *  Arguments:
                     44: *  ==========
                     45: *
                     46: *> \param[in] UPLO
                     47: *> \verbatim
                     48: *>          UPLO is CHARACTER*1
                     49: *>          Specifies whether the details of the factorization are stored
                     50: *>          as an upper or lower triangular matrix.
                     51: *>          = 'U':  Upper triangular, form is A = U*D*U**H;
                     52: *>          = 'L':  Lower triangular, form is A = L*D*L**H.
                     53: *> \endverbatim
                     54: *>
                     55: *> \param[in] N
                     56: *> \verbatim
                     57: *>          N is INTEGER
                     58: *>          The order of the matrix A.  N >= 0.
                     59: *> \endverbatim
                     60: *>
                     61: *> \param[in] NRHS
                     62: *> \verbatim
                     63: *>          NRHS is INTEGER
                     64: *>          The number of right hand sides, i.e., the number of columns
                     65: *>          of the matrix B.  NRHS >= 0.
                     66: *> \endverbatim
                     67: *>
                     68: *> \param[in] AP
                     69: *> \verbatim
                     70: *>          AP is COMPLEX*16 array, dimension (N*(N+1)/2)
                     71: *>          The block diagonal matrix D and the multipliers used to
                     72: *>          obtain the factor U or L as computed by ZHPTRF, stored as a
                     73: *>          packed triangular matrix.
                     74: *> \endverbatim
                     75: *>
                     76: *> \param[in] IPIV
                     77: *> \verbatim
                     78: *>          IPIV is INTEGER array, dimension (N)
                     79: *>          Details of the interchanges and the block structure of D
                     80: *>          as determined by ZHPTRF.
                     81: *> \endverbatim
                     82: *>
                     83: *> \param[in,out] B
                     84: *> \verbatim
                     85: *>          B is COMPLEX*16 array, dimension (LDB,NRHS)
                     86: *>          On entry, the right hand side matrix B.
                     87: *>          On exit, the solution matrix X.
                     88: *> \endverbatim
                     89: *>
                     90: *> \param[in] LDB
                     91: *> \verbatim
                     92: *>          LDB is INTEGER
                     93: *>          The leading dimension of the array B.  LDB >= max(1,N).
                     94: *> \endverbatim
                     95: *>
                     96: *> \param[out] INFO
                     97: *> \verbatim
                     98: *>          INFO is INTEGER
                     99: *>          = 0:  successful exit
                    100: *>          < 0: if INFO = -i, the i-th argument had an illegal value
                    101: *> \endverbatim
                    102: *
                    103: *  Authors:
                    104: *  ========
                    105: *
1.15      bertrand  106: *> \author Univ. of Tennessee
                    107: *> \author Univ. of California Berkeley
                    108: *> \author Univ. of Colorado Denver
                    109: *> \author NAG Ltd.
1.9       bertrand  110: *
                    111: *> \ingroup complex16OTHERcomputational
                    112: *
                    113: *  =====================================================================
1.1       bertrand  114:       SUBROUTINE ZHPTRS( UPLO, N, NRHS, AP, IPIV, B, LDB, INFO )
                    115: *
1.18    ! bertrand  116: *  -- LAPACK computational routine --
1.1       bertrand  117: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
                    118: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
                    119: *
                    120: *     .. Scalar Arguments ..
                    121:       CHARACTER          UPLO
                    122:       INTEGER            INFO, LDB, N, NRHS
                    123: *     ..
                    124: *     .. Array Arguments ..
                    125:       INTEGER            IPIV( * )
                    126:       COMPLEX*16         AP( * ), B( LDB, * )
                    127: *     ..
                    128: *
                    129: *  =====================================================================
                    130: *
                    131: *     .. Parameters ..
                    132:       COMPLEX*16         ONE
                    133:       PARAMETER          ( ONE = ( 1.0D+0, 0.0D+0 ) )
                    134: *     ..
                    135: *     .. Local Scalars ..
                    136:       LOGICAL            UPPER
                    137:       INTEGER            J, K, KC, KP
                    138:       DOUBLE PRECISION   S
                    139:       COMPLEX*16         AK, AKM1, AKM1K, BK, BKM1, DENOM
                    140: *     ..
                    141: *     .. External Functions ..
                    142:       LOGICAL            LSAME
                    143:       EXTERNAL           LSAME
                    144: *     ..
                    145: *     .. External Subroutines ..
                    146:       EXTERNAL           XERBLA, ZDSCAL, ZGEMV, ZGERU, ZLACGV, ZSWAP
                    147: *     ..
                    148: *     .. Intrinsic Functions ..
                    149:       INTRINSIC          DBLE, DCONJG, MAX
                    150: *     ..
                    151: *     .. Executable Statements ..
                    152: *
                    153:       INFO = 0
                    154:       UPPER = LSAME( UPLO, 'U' )
                    155:       IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
                    156:          INFO = -1
                    157:       ELSE IF( N.LT.0 ) THEN
                    158:          INFO = -2
                    159:       ELSE IF( NRHS.LT.0 ) THEN
                    160:          INFO = -3
                    161:       ELSE IF( LDB.LT.MAX( 1, N ) ) THEN
                    162:          INFO = -7
                    163:       END IF
                    164:       IF( INFO.NE.0 ) THEN
                    165:          CALL XERBLA( 'ZHPTRS', -INFO )
                    166:          RETURN
                    167:       END IF
                    168: *
                    169: *     Quick return if possible
                    170: *
                    171:       IF( N.EQ.0 .OR. NRHS.EQ.0 )
                    172:      $   RETURN
                    173: *
                    174:       IF( UPPER ) THEN
                    175: *
1.8       bertrand  176: *        Solve A*X = B, where A = U*D*U**H.
1.1       bertrand  177: *
                    178: *        First solve U*D*X = B, overwriting B with X.
                    179: *
                    180: *        K is the main loop index, decreasing from N to 1 in steps of
                    181: *        1 or 2, depending on the size of the diagonal blocks.
                    182: *
                    183:          K = N
                    184:          KC = N*( N+1 ) / 2 + 1
                    185:    10    CONTINUE
                    186: *
                    187: *        If K < 1, exit from loop.
                    188: *
                    189:          IF( K.LT.1 )
                    190:      $      GO TO 30
                    191: *
                    192:          KC = KC - K
                    193:          IF( IPIV( K ).GT.0 ) THEN
                    194: *
                    195: *           1 x 1 diagonal block
                    196: *
                    197: *           Interchange rows K and IPIV(K).
                    198: *
                    199:             KP = IPIV( K )
                    200:             IF( KP.NE.K )
                    201:      $         CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
                    202: *
                    203: *           Multiply by inv(U(K)), where U(K) is the transformation
                    204: *           stored in column K of A.
                    205: *
                    206:             CALL ZGERU( K-1, NRHS, -ONE, AP( KC ), 1, B( K, 1 ), LDB,
                    207:      $                  B( 1, 1 ), LDB )
                    208: *
                    209: *           Multiply by the inverse of the diagonal block.
                    210: *
                    211:             S = DBLE( ONE ) / DBLE( AP( KC+K-1 ) )
                    212:             CALL ZDSCAL( NRHS, S, B( K, 1 ), LDB )
                    213:             K = K - 1
                    214:          ELSE
                    215: *
                    216: *           2 x 2 diagonal block
                    217: *
                    218: *           Interchange rows K-1 and -IPIV(K).
                    219: *
                    220:             KP = -IPIV( K )
                    221:             IF( KP.NE.K-1 )
                    222:      $         CALL ZSWAP( NRHS, B( K-1, 1 ), LDB, B( KP, 1 ), LDB )
                    223: *
                    224: *           Multiply by inv(U(K)), where U(K) is the transformation
                    225: *           stored in columns K-1 and K of A.
                    226: *
                    227:             CALL ZGERU( K-2, NRHS, -ONE, AP( KC ), 1, B( K, 1 ), LDB,
                    228:      $                  B( 1, 1 ), LDB )
                    229:             CALL ZGERU( K-2, NRHS, -ONE, AP( KC-( K-1 ) ), 1,
                    230:      $                  B( K-1, 1 ), LDB, B( 1, 1 ), LDB )
                    231: *
                    232: *           Multiply by the inverse of the diagonal block.
                    233: *
                    234:             AKM1K = AP( KC+K-2 )
                    235:             AKM1 = AP( KC-1 ) / AKM1K
                    236:             AK = AP( KC+K-1 ) / DCONJG( AKM1K )
                    237:             DENOM = AKM1*AK - ONE
                    238:             DO 20 J = 1, NRHS
                    239:                BKM1 = B( K-1, J ) / AKM1K
                    240:                BK = B( K, J ) / DCONJG( AKM1K )
                    241:                B( K-1, J ) = ( AK*BKM1-BK ) / DENOM
                    242:                B( K, J ) = ( AKM1*BK-BKM1 ) / DENOM
                    243:    20       CONTINUE
                    244:             KC = KC - K + 1
                    245:             K = K - 2
                    246:          END IF
                    247: *
                    248:          GO TO 10
                    249:    30    CONTINUE
                    250: *
1.8       bertrand  251: *        Next solve U**H *X = B, overwriting B with X.
1.1       bertrand  252: *
                    253: *        K is the main loop index, increasing from 1 to N in steps of
                    254: *        1 or 2, depending on the size of the diagonal blocks.
                    255: *
                    256:          K = 1
                    257:          KC = 1
                    258:    40    CONTINUE
                    259: *
                    260: *        If K > N, exit from loop.
                    261: *
                    262:          IF( K.GT.N )
                    263:      $      GO TO 50
                    264: *
                    265:          IF( IPIV( K ).GT.0 ) THEN
                    266: *
                    267: *           1 x 1 diagonal block
                    268: *
1.8       bertrand  269: *           Multiply by inv(U**H(K)), where U(K) is the transformation
1.1       bertrand  270: *           stored in column K of A.
                    271: *
                    272:             IF( K.GT.1 ) THEN
                    273:                CALL ZLACGV( NRHS, B( K, 1 ), LDB )
                    274:                CALL ZGEMV( 'Conjugate transpose', K-1, NRHS, -ONE, B,
                    275:      $                     LDB, AP( KC ), 1, ONE, B( K, 1 ), LDB )
                    276:                CALL ZLACGV( NRHS, B( K, 1 ), LDB )
                    277:             END IF
                    278: *
                    279: *           Interchange rows K and IPIV(K).
                    280: *
                    281:             KP = IPIV( K )
                    282:             IF( KP.NE.K )
                    283:      $         CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
                    284:             KC = KC + K
                    285:             K = K + 1
                    286:          ELSE
                    287: *
                    288: *           2 x 2 diagonal block
                    289: *
1.8       bertrand  290: *           Multiply by inv(U**H(K+1)), where U(K+1) is the transformation
1.1       bertrand  291: *           stored in columns K and K+1 of A.
                    292: *
                    293:             IF( K.GT.1 ) THEN
                    294:                CALL ZLACGV( NRHS, B( K, 1 ), LDB )
                    295:                CALL ZGEMV( 'Conjugate transpose', K-1, NRHS, -ONE, B,
                    296:      $                     LDB, AP( KC ), 1, ONE, B( K, 1 ), LDB )
                    297:                CALL ZLACGV( NRHS, B( K, 1 ), LDB )
                    298: *
                    299:                CALL ZLACGV( NRHS, B( K+1, 1 ), LDB )
                    300:                CALL ZGEMV( 'Conjugate transpose', K-1, NRHS, -ONE, B,
                    301:      $                     LDB, AP( KC+K ), 1, ONE, B( K+1, 1 ), LDB )
                    302:                CALL ZLACGV( NRHS, B( K+1, 1 ), LDB )
                    303:             END IF
                    304: *
                    305: *           Interchange rows K and -IPIV(K).
                    306: *
                    307:             KP = -IPIV( K )
                    308:             IF( KP.NE.K )
                    309:      $         CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
                    310:             KC = KC + 2*K + 1
                    311:             K = K + 2
                    312:          END IF
                    313: *
                    314:          GO TO 40
                    315:    50    CONTINUE
                    316: *
                    317:       ELSE
                    318: *
1.8       bertrand  319: *        Solve A*X = B, where A = L*D*L**H.
1.1       bertrand  320: *
                    321: *        First solve L*D*X = B, overwriting B with X.
                    322: *
                    323: *        K is the main loop index, increasing from 1 to N in steps of
                    324: *        1 or 2, depending on the size of the diagonal blocks.
                    325: *
                    326:          K = 1
                    327:          KC = 1
                    328:    60    CONTINUE
                    329: *
                    330: *        If K > N, exit from loop.
                    331: *
                    332:          IF( K.GT.N )
                    333:      $      GO TO 80
                    334: *
                    335:          IF( IPIV( K ).GT.0 ) THEN
                    336: *
                    337: *           1 x 1 diagonal block
                    338: *
                    339: *           Interchange rows K and IPIV(K).
                    340: *
                    341:             KP = IPIV( K )
                    342:             IF( KP.NE.K )
                    343:      $         CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
                    344: *
                    345: *           Multiply by inv(L(K)), where L(K) is the transformation
                    346: *           stored in column K of A.
                    347: *
                    348:             IF( K.LT.N )
                    349:      $         CALL ZGERU( N-K, NRHS, -ONE, AP( KC+1 ), 1, B( K, 1 ),
                    350:      $                     LDB, B( K+1, 1 ), LDB )
                    351: *
                    352: *           Multiply by the inverse of the diagonal block.
                    353: *
                    354:             S = DBLE( ONE ) / DBLE( AP( KC ) )
                    355:             CALL ZDSCAL( NRHS, S, B( K, 1 ), LDB )
                    356:             KC = KC + N - K + 1
                    357:             K = K + 1
                    358:          ELSE
                    359: *
                    360: *           2 x 2 diagonal block
                    361: *
                    362: *           Interchange rows K+1 and -IPIV(K).
                    363: *
                    364:             KP = -IPIV( K )
                    365:             IF( KP.NE.K+1 )
                    366:      $         CALL ZSWAP( NRHS, B( K+1, 1 ), LDB, B( KP, 1 ), LDB )
                    367: *
                    368: *           Multiply by inv(L(K)), where L(K) is the transformation
                    369: *           stored in columns K and K+1 of A.
                    370: *
                    371:             IF( K.LT.N-1 ) THEN
                    372:                CALL ZGERU( N-K-1, NRHS, -ONE, AP( KC+2 ), 1, B( K, 1 ),
                    373:      $                     LDB, B( K+2, 1 ), LDB )
                    374:                CALL ZGERU( N-K-1, NRHS, -ONE, AP( KC+N-K+2 ), 1,
                    375:      $                     B( K+1, 1 ), LDB, B( K+2, 1 ), LDB )
                    376:             END IF
                    377: *
                    378: *           Multiply by the inverse of the diagonal block.
                    379: *
                    380:             AKM1K = AP( KC+1 )
                    381:             AKM1 = AP( KC ) / DCONJG( AKM1K )
                    382:             AK = AP( KC+N-K+1 ) / AKM1K
                    383:             DENOM = AKM1*AK - ONE
                    384:             DO 70 J = 1, NRHS
                    385:                BKM1 = B( K, J ) / DCONJG( AKM1K )
                    386:                BK = B( K+1, J ) / AKM1K
                    387:                B( K, J ) = ( AK*BKM1-BK ) / DENOM
                    388:                B( K+1, J ) = ( AKM1*BK-BKM1 ) / DENOM
                    389:    70       CONTINUE
                    390:             KC = KC + 2*( N-K ) + 1
                    391:             K = K + 2
                    392:          END IF
                    393: *
                    394:          GO TO 60
                    395:    80    CONTINUE
                    396: *
1.8       bertrand  397: *        Next solve L**H *X = B, overwriting B with X.
1.1       bertrand  398: *
                    399: *        K is the main loop index, decreasing from N to 1 in steps of
                    400: *        1 or 2, depending on the size of the diagonal blocks.
                    401: *
                    402:          K = N
                    403:          KC = N*( N+1 ) / 2 + 1
                    404:    90    CONTINUE
                    405: *
                    406: *        If K < 1, exit from loop.
                    407: *
                    408:          IF( K.LT.1 )
                    409:      $      GO TO 100
                    410: *
                    411:          KC = KC - ( N-K+1 )
                    412:          IF( IPIV( K ).GT.0 ) THEN
                    413: *
                    414: *           1 x 1 diagonal block
                    415: *
1.8       bertrand  416: *           Multiply by inv(L**H(K)), where L(K) is the transformation
1.1       bertrand  417: *           stored in column K of A.
                    418: *
                    419:             IF( K.LT.N ) THEN
                    420:                CALL ZLACGV( NRHS, B( K, 1 ), LDB )
                    421:                CALL ZGEMV( 'Conjugate transpose', N-K, NRHS, -ONE,
                    422:      $                     B( K+1, 1 ), LDB, AP( KC+1 ), 1, ONE,
                    423:      $                     B( K, 1 ), LDB )
                    424:                CALL ZLACGV( NRHS, B( K, 1 ), LDB )
                    425:             END IF
                    426: *
                    427: *           Interchange rows K and IPIV(K).
                    428: *
                    429:             KP = IPIV( K )
                    430:             IF( KP.NE.K )
                    431:      $         CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
                    432:             K = K - 1
                    433:          ELSE
                    434: *
                    435: *           2 x 2 diagonal block
                    436: *
1.8       bertrand  437: *           Multiply by inv(L**H(K-1)), where L(K-1) is the transformation
1.1       bertrand  438: *           stored in columns K-1 and K of A.
                    439: *
                    440:             IF( K.LT.N ) THEN
                    441:                CALL ZLACGV( NRHS, B( K, 1 ), LDB )
                    442:                CALL ZGEMV( 'Conjugate transpose', N-K, NRHS, -ONE,
                    443:      $                     B( K+1, 1 ), LDB, AP( KC+1 ), 1, ONE,
                    444:      $                     B( K, 1 ), LDB )
                    445:                CALL ZLACGV( NRHS, B( K, 1 ), LDB )
                    446: *
                    447:                CALL ZLACGV( NRHS, B( K-1, 1 ), LDB )
                    448:                CALL ZGEMV( 'Conjugate transpose', N-K, NRHS, -ONE,
                    449:      $                     B( K+1, 1 ), LDB, AP( KC-( N-K ) ), 1, ONE,
                    450:      $                     B( K-1, 1 ), LDB )
                    451:                CALL ZLACGV( NRHS, B( K-1, 1 ), LDB )
                    452:             END IF
                    453: *
                    454: *           Interchange rows K and -IPIV(K).
                    455: *
                    456:             KP = -IPIV( K )
                    457:             IF( KP.NE.K )
                    458:      $         CALL ZSWAP( NRHS, B( K, 1 ), LDB, B( KP, 1 ), LDB )
                    459:             KC = KC - ( N-K+2 )
                    460:             K = K - 2
                    461:          END IF
                    462: *
                    463:          GO TO 90
                    464:   100    CONTINUE
                    465:       END IF
                    466: *
                    467:       RETURN
                    468: *
                    469: *     End of ZHPTRS
                    470: *
                    471:       END

CVSweb interface <joel.bertrand@systella.fr>