Annotation of rpl/lapack/lapack/zhetf2.f, revision 1.19

1.14      bertrand    1: *> \brief \b ZHETF2 computes the factorization of a complex Hermitian matrix, using the diagonal pivoting method (unblocked algorithm, calling Level 2 BLAS).
1.9       bertrand    2: *
                      3: *  =========== DOCUMENTATION ===========
                      4: *
1.14      bertrand    5: * Online html documentation available at
                      6: *            http://www.netlib.org/lapack/explore-html/
1.9       bertrand    7: *
                      8: *> \htmlonly
1.14      bertrand    9: *> Download ZHETF2 + dependencies
                     10: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhetf2.f">
                     11: *> [TGZ]</a>
                     12: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhetf2.f">
                     13: *> [ZIP]</a>
                     14: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhetf2.f">
1.9       bertrand   15: *> [TXT]</a>
1.14      bertrand   16: *> \endhtmlonly
1.9       bertrand   17: *
                     18: *  Definition:
                     19: *  ===========
                     20: *
                     21: *       SUBROUTINE ZHETF2( UPLO, N, A, LDA, IPIV, INFO )
1.14      bertrand   22: *
1.9       bertrand   23: *       .. Scalar Arguments ..
                     24: *       CHARACTER          UPLO
                     25: *       INTEGER            INFO, LDA, N
                     26: *       ..
                     27: *       .. Array Arguments ..
                     28: *       INTEGER            IPIV( * )
                     29: *       COMPLEX*16         A( LDA, * )
                     30: *       ..
1.14      bertrand   31: *
1.9       bertrand   32: *
                     33: *> \par Purpose:
                     34: *  =============
                     35: *>
                     36: *> \verbatim
                     37: *>
                     38: *> ZHETF2 computes the factorization of a complex Hermitian matrix A
                     39: *> using the Bunch-Kaufman diagonal pivoting method:
                     40: *>
                     41: *>    A = U*D*U**H  or  A = L*D*L**H
                     42: *>
                     43: *> where U (or L) is a product of permutation and unit upper (lower)
                     44: *> triangular matrices, U**H is the conjugate transpose of U, and D is
                     45: *> Hermitian and block diagonal with 1-by-1 and 2-by-2 diagonal blocks.
                     46: *>
                     47: *> This is the unblocked version of the algorithm, calling Level 2 BLAS.
                     48: *> \endverbatim
                     49: *
                     50: *  Arguments:
                     51: *  ==========
                     52: *
                     53: *> \param[in] UPLO
                     54: *> \verbatim
                     55: *>          UPLO is CHARACTER*1
                     56: *>          Specifies whether the upper or lower triangular part of the
                     57: *>          Hermitian matrix A is stored:
                     58: *>          = 'U':  Upper triangular
                     59: *>          = 'L':  Lower triangular
                     60: *> \endverbatim
                     61: *>
                     62: *> \param[in] N
                     63: *> \verbatim
                     64: *>          N is INTEGER
                     65: *>          The order of the matrix A.  N >= 0.
                     66: *> \endverbatim
                     67: *>
                     68: *> \param[in,out] A
                     69: *> \verbatim
                     70: *>          A is COMPLEX*16 array, dimension (LDA,N)
                     71: *>          On entry, the Hermitian matrix A.  If UPLO = 'U', the leading
                     72: *>          n-by-n upper triangular part of A contains the upper
                     73: *>          triangular part of the matrix A, and the strictly lower
                     74: *>          triangular part of A is not referenced.  If UPLO = 'L', the
                     75: *>          leading n-by-n lower triangular part of A contains the lower
                     76: *>          triangular part of the matrix A, and the strictly upper
                     77: *>          triangular part of A is not referenced.
                     78: *>
                     79: *>          On exit, the block diagonal matrix D and the multipliers used
                     80: *>          to obtain the factor U or L (see below for further details).
                     81: *> \endverbatim
                     82: *>
                     83: *> \param[in] LDA
                     84: *> \verbatim
                     85: *>          LDA is INTEGER
                     86: *>          The leading dimension of the array A.  LDA >= max(1,N).
                     87: *> \endverbatim
                     88: *>
                     89: *> \param[out] IPIV
                     90: *> \verbatim
                     91: *>          IPIV is INTEGER array, dimension (N)
                     92: *>          Details of the interchanges and the block structure of D.
1.14      bertrand   93: *>
                     94: *>          If UPLO = 'U':
                     95: *>             If IPIV(k) > 0, then rows and columns k and IPIV(k) were
                     96: *>             interchanged and D(k,k) is a 1-by-1 diagonal block.
                     97: *>
                     98: *>             If IPIV(k) = IPIV(k-1) < 0, then rows and columns
                     99: *>             k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k)
                    100: *>             is a 2-by-2 diagonal block.
                    101: *>
                    102: *>          If UPLO = 'L':
                    103: *>             If IPIV(k) > 0, then rows and columns k and IPIV(k) were
                    104: *>             interchanged and D(k,k) is a 1-by-1 diagonal block.
                    105: *>
                    106: *>             If IPIV(k) = IPIV(k+1) < 0, then rows and columns
                    107: *>             k+1 and -IPIV(k) were interchanged and D(k:k+1,k:k+1)
                    108: *>             is a 2-by-2 diagonal block.
1.9       bertrand  109: *> \endverbatim
                    110: *>
                    111: *> \param[out] INFO
                    112: *> \verbatim
                    113: *>          INFO is INTEGER
                    114: *>          = 0: successful exit
                    115: *>          < 0: if INFO = -k, the k-th argument had an illegal value
                    116: *>          > 0: if INFO = k, D(k,k) is exactly zero.  The factorization
                    117: *>               has been completed, but the block diagonal matrix D is
                    118: *>               exactly singular, and division by zero will occur if it
                    119: *>               is used to solve a system of equations.
                    120: *> \endverbatim
                    121: *
                    122: *  Authors:
                    123: *  ========
                    124: *
1.14      bertrand  125: *> \author Univ. of Tennessee
                    126: *> \author Univ. of California Berkeley
                    127: *> \author Univ. of Colorado Denver
                    128: *> \author NAG Ltd.
1.9       bertrand  129: *
                    130: *> \ingroup complex16HEcomputational
                    131: *
                    132: *> \par Further Details:
                    133: *  =====================
                    134: *>
                    135: *> \verbatim
                    136: *>
                    137: *>  If UPLO = 'U', then A = U*D*U**H, where
                    138: *>     U = P(n)*U(n)* ... *P(k)U(k)* ...,
                    139: *>  i.e., U is a product of terms P(k)*U(k), where k decreases from n to
                    140: *>  1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
                    141: *>  and 2-by-2 diagonal blocks D(k).  P(k) is a permutation matrix as
                    142: *>  defined by IPIV(k), and U(k) is a unit upper triangular matrix, such
                    143: *>  that if the diagonal block D(k) is of order s (s = 1 or 2), then
                    144: *>
                    145: *>             (   I    v    0   )   k-s
                    146: *>     U(k) =  (   0    I    0   )   s
                    147: *>             (   0    0    I   )   n-k
                    148: *>                k-s   s   n-k
                    149: *>
                    150: *>  If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k).
                    151: *>  If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k),
                    152: *>  and A(k,k), and v overwrites A(1:k-2,k-1:k).
                    153: *>
                    154: *>  If UPLO = 'L', then A = L*D*L**H, where
                    155: *>     L = P(1)*L(1)* ... *P(k)*L(k)* ...,
                    156: *>  i.e., L is a product of terms P(k)*L(k), where k increases from 1 to
                    157: *>  n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
                    158: *>  and 2-by-2 diagonal blocks D(k).  P(k) is a permutation matrix as
                    159: *>  defined by IPIV(k), and L(k) is a unit lower triangular matrix, such
                    160: *>  that if the diagonal block D(k) is of order s (s = 1 or 2), then
                    161: *>
                    162: *>             (   I    0     0   )  k-1
                    163: *>     L(k) =  (   0    I     0   )  s
                    164: *>             (   0    v     I   )  n-k-s+1
                    165: *>                k-1   s  n-k-s+1
                    166: *>
                    167: *>  If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k).
                    168: *>  If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k),
                    169: *>  and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1).
                    170: *> \endverbatim
                    171: *
                    172: *> \par Contributors:
                    173: *  ==================
                    174: *>
                    175: *> \verbatim
                    176: *>  09-29-06 - patch from
                    177: *>    Bobby Cheng, MathWorks
                    178: *>
                    179: *>    Replace l.210 and l.393
                    180: *>         IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
                    181: *>    by
                    182: *>         IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. DISNAN(ABSAKK) ) THEN
                    183: *>
                    184: *>  01-01-96 - Based on modifications by
                    185: *>    J. Lewis, Boeing Computer Services Company
                    186: *>    A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA
                    187: *> \endverbatim
                    188: *
                    189: *  =====================================================================
1.1       bertrand  190:       SUBROUTINE ZHETF2( UPLO, N, A, LDA, IPIV, INFO )
                    191: *
1.19    ! bertrand  192: *  -- LAPACK computational routine --
1.1       bertrand  193: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
                    194: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
                    195: *
                    196: *     .. Scalar Arguments ..
                    197:       CHARACTER          UPLO
                    198:       INTEGER            INFO, LDA, N
                    199: *     ..
                    200: *     .. Array Arguments ..
                    201:       INTEGER            IPIV( * )
                    202:       COMPLEX*16         A( LDA, * )
                    203: *     ..
                    204: *
                    205: *  =====================================================================
                    206: *
                    207: *     .. Parameters ..
                    208:       DOUBLE PRECISION   ZERO, ONE
                    209:       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0 )
                    210:       DOUBLE PRECISION   EIGHT, SEVTEN
                    211:       PARAMETER          ( EIGHT = 8.0D+0, SEVTEN = 17.0D+0 )
                    212: *     ..
                    213: *     .. Local Scalars ..
                    214:       LOGICAL            UPPER
                    215:       INTEGER            I, IMAX, J, JMAX, K, KK, KP, KSTEP
                    216:       DOUBLE PRECISION   ABSAKK, ALPHA, COLMAX, D, D11, D22, R1, ROWMAX,
                    217:      $                   TT
                    218:       COMPLEX*16         D12, D21, T, WK, WKM1, WKP1, ZDUM
                    219: *     ..
                    220: *     .. External Functions ..
                    221:       LOGICAL            LSAME, DISNAN
                    222:       INTEGER            IZAMAX
                    223:       DOUBLE PRECISION   DLAPY2
                    224:       EXTERNAL           LSAME, IZAMAX, DLAPY2, DISNAN
                    225: *     ..
                    226: *     .. External Subroutines ..
                    227:       EXTERNAL           XERBLA, ZDSCAL, ZHER, ZSWAP
                    228: *     ..
                    229: *     .. Intrinsic Functions ..
                    230:       INTRINSIC          ABS, DBLE, DCMPLX, DCONJG, DIMAG, MAX, SQRT
                    231: *     ..
                    232: *     .. Statement Functions ..
                    233:       DOUBLE PRECISION   CABS1
                    234: *     ..
                    235: *     .. Statement Function definitions ..
                    236:       CABS1( ZDUM ) = ABS( DBLE( ZDUM ) ) + ABS( DIMAG( ZDUM ) )
                    237: *     ..
                    238: *     .. Executable Statements ..
                    239: *
                    240: *     Test the input parameters.
                    241: *
                    242:       INFO = 0
                    243:       UPPER = LSAME( UPLO, 'U' )
                    244:       IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
                    245:          INFO = -1
                    246:       ELSE IF( N.LT.0 ) THEN
                    247:          INFO = -2
                    248:       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
                    249:          INFO = -4
                    250:       END IF
                    251:       IF( INFO.NE.0 ) THEN
                    252:          CALL XERBLA( 'ZHETF2', -INFO )
                    253:          RETURN
                    254:       END IF
                    255: *
                    256: *     Initialize ALPHA for use in choosing pivot block size.
                    257: *
                    258:       ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT
                    259: *
                    260:       IF( UPPER ) THEN
                    261: *
1.8       bertrand  262: *        Factorize A as U*D*U**H using the upper triangle of A
1.1       bertrand  263: *
                    264: *        K is the main loop index, decreasing from N to 1 in steps of
                    265: *        1 or 2
                    266: *
                    267:          K = N
                    268:    10    CONTINUE
                    269: *
                    270: *        If K < 1, exit from loop
                    271: *
                    272:          IF( K.LT.1 )
                    273:      $      GO TO 90
                    274:          KSTEP = 1
                    275: *
                    276: *        Determine rows and columns to be interchanged and whether
                    277: *        a 1-by-1 or 2-by-2 pivot block will be used
                    278: *
                    279:          ABSAKK = ABS( DBLE( A( K, K ) ) )
                    280: *
                    281: *        IMAX is the row-index of the largest off-diagonal element in
1.14      bertrand  282: *        column K, and COLMAX is its absolute value.
                    283: *        Determine both COLMAX and IMAX.
1.1       bertrand  284: *
                    285:          IF( K.GT.1 ) THEN
                    286:             IMAX = IZAMAX( K-1, A( 1, K ), 1 )
                    287:             COLMAX = CABS1( A( IMAX, K ) )
                    288:          ELSE
                    289:             COLMAX = ZERO
                    290:          END IF
                    291: *
                    292:          IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. DISNAN(ABSAKK) ) THEN
                    293: *
1.14      bertrand  294: *           Column K is zero or underflow, or contains a NaN:
                    295: *           set INFO and continue
1.1       bertrand  296: *
                    297:             IF( INFO.EQ.0 )
                    298:      $         INFO = K
                    299:             KP = K
                    300:             A( K, K ) = DBLE( A( K, K ) )
                    301:          ELSE
1.14      bertrand  302: *
                    303: *           ============================================================
                    304: *
                    305: *           Test for interchange
                    306: *
1.1       bertrand  307:             IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
                    308: *
                    309: *              no interchange, use 1-by-1 pivot block
                    310: *
                    311:                KP = K
                    312:             ELSE
                    313: *
                    314: *              JMAX is the column-index of the largest off-diagonal
1.14      bertrand  315: *              element in row IMAX, and ROWMAX is its absolute value.
                    316: *              Determine only ROWMAX.
1.1       bertrand  317: *
                    318:                JMAX = IMAX + IZAMAX( K-IMAX, A( IMAX, IMAX+1 ), LDA )
                    319:                ROWMAX = CABS1( A( IMAX, JMAX ) )
                    320:                IF( IMAX.GT.1 ) THEN
                    321:                   JMAX = IZAMAX( IMAX-1, A( 1, IMAX ), 1 )
                    322:                   ROWMAX = MAX( ROWMAX, CABS1( A( JMAX, IMAX ) ) )
                    323:                END IF
                    324: *
                    325:                IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
                    326: *
                    327: *                 no interchange, use 1-by-1 pivot block
                    328: *
                    329:                   KP = K
1.14      bertrand  330: *
1.1       bertrand  331:                ELSE IF( ABS( DBLE( A( IMAX, IMAX ) ) ).GE.ALPHA*ROWMAX )
                    332:      $                   THEN
                    333: *
                    334: *                 interchange rows and columns K and IMAX, use 1-by-1
                    335: *                 pivot block
                    336: *
                    337:                   KP = IMAX
                    338:                ELSE
                    339: *
                    340: *                 interchange rows and columns K-1 and IMAX, use 2-by-2
                    341: *                 pivot block
                    342: *
                    343:                   KP = IMAX
                    344:                   KSTEP = 2
                    345:                END IF
1.14      bertrand  346: *
1.1       bertrand  347:             END IF
                    348: *
1.14      bertrand  349: *           ============================================================
                    350: *
1.1       bertrand  351:             KK = K - KSTEP + 1
                    352:             IF( KP.NE.KK ) THEN
                    353: *
                    354: *              Interchange rows and columns KK and KP in the leading
                    355: *              submatrix A(1:k,1:k)
                    356: *
                    357:                CALL ZSWAP( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 )
                    358:                DO 20 J = KP + 1, KK - 1
                    359:                   T = DCONJG( A( J, KK ) )
                    360:                   A( J, KK ) = DCONJG( A( KP, J ) )
                    361:                   A( KP, J ) = T
                    362:    20          CONTINUE
                    363:                A( KP, KK ) = DCONJG( A( KP, KK ) )
                    364:                R1 = DBLE( A( KK, KK ) )
                    365:                A( KK, KK ) = DBLE( A( KP, KP ) )
                    366:                A( KP, KP ) = R1
                    367:                IF( KSTEP.EQ.2 ) THEN
                    368:                   A( K, K ) = DBLE( A( K, K ) )
                    369:                   T = A( K-1, K )
                    370:                   A( K-1, K ) = A( KP, K )
                    371:                   A( KP, K ) = T
                    372:                END IF
                    373:             ELSE
                    374:                A( K, K ) = DBLE( A( K, K ) )
                    375:                IF( KSTEP.EQ.2 )
                    376:      $            A( K-1, K-1 ) = DBLE( A( K-1, K-1 ) )
                    377:             END IF
                    378: *
                    379: *           Update the leading submatrix
                    380: *
                    381:             IF( KSTEP.EQ.1 ) THEN
                    382: *
                    383: *              1-by-1 pivot block D(k): column k now holds
                    384: *
                    385: *              W(k) = U(k)*D(k)
                    386: *
                    387: *              where U(k) is the k-th column of U
                    388: *
                    389: *              Perform a rank-1 update of A(1:k-1,1:k-1) as
                    390: *
1.8       bertrand  391: *              A := A - U(k)*D(k)*U(k)**H = A - W(k)*1/D(k)*W(k)**H
1.1       bertrand  392: *
                    393:                R1 = ONE / DBLE( A( K, K ) )
                    394:                CALL ZHER( UPLO, K-1, -R1, A( 1, K ), 1, A, LDA )
                    395: *
                    396: *              Store U(k) in column k
                    397: *
                    398:                CALL ZDSCAL( K-1, R1, A( 1, K ), 1 )
                    399:             ELSE
                    400: *
                    401: *              2-by-2 pivot block D(k): columns k and k-1 now hold
                    402: *
                    403: *              ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k)
                    404: *
                    405: *              where U(k) and U(k-1) are the k-th and (k-1)-th columns
                    406: *              of U
                    407: *
                    408: *              Perform a rank-2 update of A(1:k-2,1:k-2) as
                    409: *
1.8       bertrand  410: *              A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**H
                    411: *                 = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )**H
1.1       bertrand  412: *
                    413:                IF( K.GT.2 ) THEN
                    414: *
                    415:                   D = DLAPY2( DBLE( A( K-1, K ) ),
                    416:      $                DIMAG( A( K-1, K ) ) )
                    417:                   D22 = DBLE( A( K-1, K-1 ) ) / D
                    418:                   D11 = DBLE( A( K, K ) ) / D
                    419:                   TT = ONE / ( D11*D22-ONE )
                    420:                   D12 = A( K-1, K ) / D
                    421:                   D = TT / D
                    422: *
                    423:                   DO 40 J = K - 2, 1, -1
                    424:                      WKM1 = D*( D11*A( J, K-1 )-DCONJG( D12 )*
                    425:      $                      A( J, K ) )
                    426:                      WK = D*( D22*A( J, K )-D12*A( J, K-1 ) )
                    427:                      DO 30 I = J, 1, -1
                    428:                         A( I, J ) = A( I, J ) - A( I, K )*DCONJG( WK ) -
                    429:      $                              A( I, K-1 )*DCONJG( WKM1 )
                    430:    30                CONTINUE
                    431:                      A( J, K ) = WK
                    432:                      A( J, K-1 ) = WKM1
                    433:                      A( J, J ) = DCMPLX( DBLE( A( J, J ) ), 0.0D+0 )
                    434:    40             CONTINUE
                    435: *
                    436:                END IF
                    437: *
                    438:             END IF
                    439:          END IF
                    440: *
                    441: *        Store details of the interchanges in IPIV
                    442: *
                    443:          IF( KSTEP.EQ.1 ) THEN
                    444:             IPIV( K ) = KP
                    445:          ELSE
                    446:             IPIV( K ) = -KP
                    447:             IPIV( K-1 ) = -KP
                    448:          END IF
                    449: *
                    450: *        Decrease K and return to the start of the main loop
                    451: *
                    452:          K = K - KSTEP
                    453:          GO TO 10
                    454: *
                    455:       ELSE
                    456: *
1.8       bertrand  457: *        Factorize A as L*D*L**H using the lower triangle of A
1.1       bertrand  458: *
                    459: *        K is the main loop index, increasing from 1 to N in steps of
                    460: *        1 or 2
                    461: *
                    462:          K = 1
                    463:    50    CONTINUE
                    464: *
                    465: *        If K > N, exit from loop
                    466: *
                    467:          IF( K.GT.N )
                    468:      $      GO TO 90
                    469:          KSTEP = 1
                    470: *
                    471: *        Determine rows and columns to be interchanged and whether
                    472: *        a 1-by-1 or 2-by-2 pivot block will be used
                    473: *
                    474:          ABSAKK = ABS( DBLE( A( K, K ) ) )
                    475: *
                    476: *        IMAX is the row-index of the largest off-diagonal element in
1.14      bertrand  477: *        column K, and COLMAX is its absolute value.
                    478: *        Determine both COLMAX and IMAX.
1.1       bertrand  479: *
                    480:          IF( K.LT.N ) THEN
                    481:             IMAX = K + IZAMAX( N-K, A( K+1, K ), 1 )
                    482:             COLMAX = CABS1( A( IMAX, K ) )
                    483:          ELSE
                    484:             COLMAX = ZERO
                    485:          END IF
                    486: *
                    487:          IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. DISNAN(ABSAKK) ) THEN
                    488: *
1.14      bertrand  489: *           Column K is zero or underflow, or contains a NaN:
                    490: *           set INFO and continue
1.1       bertrand  491: *
                    492:             IF( INFO.EQ.0 )
                    493:      $         INFO = K
                    494:             KP = K
                    495:             A( K, K ) = DBLE( A( K, K ) )
                    496:          ELSE
1.14      bertrand  497: *
                    498: *           ============================================================
                    499: *
                    500: *           Test for interchange
                    501: *
1.1       bertrand  502:             IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
                    503: *
                    504: *              no interchange, use 1-by-1 pivot block
                    505: *
                    506:                KP = K
                    507:             ELSE
                    508: *
                    509: *              JMAX is the column-index of the largest off-diagonal
1.14      bertrand  510: *              element in row IMAX, and ROWMAX is its absolute value.
                    511: *              Determine only ROWMAX.
1.1       bertrand  512: *
                    513:                JMAX = K - 1 + IZAMAX( IMAX-K, A( IMAX, K ), LDA )
                    514:                ROWMAX = CABS1( A( IMAX, JMAX ) )
                    515:                IF( IMAX.LT.N ) THEN
                    516:                   JMAX = IMAX + IZAMAX( N-IMAX, A( IMAX+1, IMAX ), 1 )
                    517:                   ROWMAX = MAX( ROWMAX, CABS1( A( JMAX, IMAX ) ) )
                    518:                END IF
                    519: *
                    520:                IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
                    521: *
                    522: *                 no interchange, use 1-by-1 pivot block
                    523: *
                    524:                   KP = K
1.14      bertrand  525: *
1.1       bertrand  526:                ELSE IF( ABS( DBLE( A( IMAX, IMAX ) ) ).GE.ALPHA*ROWMAX )
                    527:      $                   THEN
                    528: *
                    529: *                 interchange rows and columns K and IMAX, use 1-by-1
                    530: *                 pivot block
                    531: *
                    532:                   KP = IMAX
                    533:                ELSE
                    534: *
                    535: *                 interchange rows and columns K+1 and IMAX, use 2-by-2
                    536: *                 pivot block
                    537: *
                    538:                   KP = IMAX
                    539:                   KSTEP = 2
                    540:                END IF
1.14      bertrand  541: *
1.1       bertrand  542:             END IF
                    543: *
1.14      bertrand  544: *           ============================================================
                    545: *
1.1       bertrand  546:             KK = K + KSTEP - 1
                    547:             IF( KP.NE.KK ) THEN
                    548: *
                    549: *              Interchange rows and columns KK and KP in the trailing
                    550: *              submatrix A(k:n,k:n)
                    551: *
                    552:                IF( KP.LT.N )
                    553:      $            CALL ZSWAP( N-KP, A( KP+1, KK ), 1, A( KP+1, KP ), 1 )
                    554:                DO 60 J = KK + 1, KP - 1
                    555:                   T = DCONJG( A( J, KK ) )
                    556:                   A( J, KK ) = DCONJG( A( KP, J ) )
                    557:                   A( KP, J ) = T
                    558:    60          CONTINUE
                    559:                A( KP, KK ) = DCONJG( A( KP, KK ) )
                    560:                R1 = DBLE( A( KK, KK ) )
                    561:                A( KK, KK ) = DBLE( A( KP, KP ) )
                    562:                A( KP, KP ) = R1
                    563:                IF( KSTEP.EQ.2 ) THEN
                    564:                   A( K, K ) = DBLE( A( K, K ) )
                    565:                   T = A( K+1, K )
                    566:                   A( K+1, K ) = A( KP, K )
                    567:                   A( KP, K ) = T
                    568:                END IF
                    569:             ELSE
                    570:                A( K, K ) = DBLE( A( K, K ) )
                    571:                IF( KSTEP.EQ.2 )
                    572:      $            A( K+1, K+1 ) = DBLE( A( K+1, K+1 ) )
                    573:             END IF
                    574: *
                    575: *           Update the trailing submatrix
                    576: *
                    577:             IF( KSTEP.EQ.1 ) THEN
                    578: *
                    579: *              1-by-1 pivot block D(k): column k now holds
                    580: *
                    581: *              W(k) = L(k)*D(k)
                    582: *
                    583: *              where L(k) is the k-th column of L
                    584: *
                    585:                IF( K.LT.N ) THEN
                    586: *
                    587: *                 Perform a rank-1 update of A(k+1:n,k+1:n) as
                    588: *
1.8       bertrand  589: *                 A := A - L(k)*D(k)*L(k)**H = A - W(k)*(1/D(k))*W(k)**H
1.1       bertrand  590: *
                    591:                   R1 = ONE / DBLE( A( K, K ) )
                    592:                   CALL ZHER( UPLO, N-K, -R1, A( K+1, K ), 1,
                    593:      $                       A( K+1, K+1 ), LDA )
                    594: *
                    595: *                 Store L(k) in column K
                    596: *
                    597:                   CALL ZDSCAL( N-K, R1, A( K+1, K ), 1 )
                    598:                END IF
                    599:             ELSE
                    600: *
                    601: *              2-by-2 pivot block D(k)
                    602: *
                    603:                IF( K.LT.N-1 ) THEN
                    604: *
                    605: *                 Perform a rank-2 update of A(k+2:n,k+2:n) as
                    606: *
1.8       bertrand  607: *                 A := A - ( L(k) L(k+1) )*D(k)*( L(k) L(k+1) )**H
                    608: *                    = A - ( W(k) W(k+1) )*inv(D(k))*( W(k) W(k+1) )**H
1.1       bertrand  609: *
                    610: *                 where L(k) and L(k+1) are the k-th and (k+1)-th
                    611: *                 columns of L
                    612: *
                    613:                   D = DLAPY2( DBLE( A( K+1, K ) ),
                    614:      $                DIMAG( A( K+1, K ) ) )
                    615:                   D11 = DBLE( A( K+1, K+1 ) ) / D
                    616:                   D22 = DBLE( A( K, K ) ) / D
                    617:                   TT = ONE / ( D11*D22-ONE )
                    618:                   D21 = A( K+1, K ) / D
                    619:                   D = TT / D
                    620: *
                    621:                   DO 80 J = K + 2, N
                    622:                      WK = D*( D11*A( J, K )-D21*A( J, K+1 ) )
                    623:                      WKP1 = D*( D22*A( J, K+1 )-DCONJG( D21 )*
                    624:      $                      A( J, K ) )
                    625:                      DO 70 I = J, N
                    626:                         A( I, J ) = A( I, J ) - A( I, K )*DCONJG( WK ) -
                    627:      $                              A( I, K+1 )*DCONJG( WKP1 )
                    628:    70                CONTINUE
                    629:                      A( J, K ) = WK
                    630:                      A( J, K+1 ) = WKP1
                    631:                      A( J, J ) = DCMPLX( DBLE( A( J, J ) ), 0.0D+0 )
                    632:    80             CONTINUE
                    633:                END IF
                    634:             END IF
                    635:          END IF
                    636: *
                    637: *        Store details of the interchanges in IPIV
                    638: *
                    639:          IF( KSTEP.EQ.1 ) THEN
                    640:             IPIV( K ) = KP
                    641:          ELSE
                    642:             IPIV( K ) = -KP
                    643:             IPIV( K+1 ) = -KP
                    644:          END IF
                    645: *
                    646: *        Increase K and return to the start of the main loop
                    647: *
                    648:          K = K + KSTEP
                    649:          GO TO 50
                    650: *
                    651:       END IF
                    652: *
                    653:    90 CONTINUE
                    654:       RETURN
                    655: *
                    656: *     End of ZHETF2
                    657: *
                    658:       END

CVSweb interface <joel.bertrand@systella.fr>