Annotation of rpl/lapack/lapack/zlasyf.f, revision 1.15

1.14      bertrand    1: *> \brief \b ZLASYF computes a partial factorization of a complex symmetric matrix using the Bunch-Kaufman diagonal pivoting method.
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 ZLASYF + dependencies
                     10: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlasyf.f">
                     11: *> [TGZ]</a>
                     12: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlasyf.f">
                     13: *> [ZIP]</a>
                     14: *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlasyf.f">
1.9       bertrand   15: *> [TXT]</a>
1.14      bertrand   16: *> \endhtmlonly
1.9       bertrand   17: *
                     18: *  Definition:
                     19: *  ===========
                     20: *
                     21: *       SUBROUTINE ZLASYF( UPLO, N, NB, KB, A, LDA, IPIV, W, LDW, INFO )
1.14      bertrand   22: *
1.9       bertrand   23: *       .. Scalar Arguments ..
                     24: *       CHARACTER          UPLO
                     25: *       INTEGER            INFO, KB, LDA, LDW, N, NB
                     26: *       ..
                     27: *       .. Array Arguments ..
                     28: *       INTEGER            IPIV( * )
                     29: *       COMPLEX*16         A( LDA, * ), W( LDW, * )
                     30: *       ..
1.14      bertrand   31: *
1.9       bertrand   32: *
                     33: *> \par Purpose:
                     34: *  =============
                     35: *>
                     36: *> \verbatim
                     37: *>
                     38: *> ZLASYF computes a partial factorization of a complex symmetric matrix
                     39: *> A using the Bunch-Kaufman diagonal pivoting method. The partial
                     40: *> factorization has the form:
                     41: *>
                     42: *> A  =  ( I  U12 ) ( A11  0  ) (  I       0    )  if UPLO = 'U', or:
                     43: *>       ( 0  U22 ) (  0   D  ) ( U12**T U22**T )
                     44: *>
                     45: *> A  =  ( L11  0 ) ( D    0  ) ( L11**T L21**T )  if UPLO = 'L'
                     46: *>       ( L21  I ) ( 0   A22 ) (  0       I    )
                     47: *>
                     48: *> where the order of D is at most NB. The actual order is returned in
                     49: *> the argument KB, and is either NB or NB-1, or N if N <= NB.
                     50: *> Note that U**T denotes the transpose of U.
                     51: *>
                     52: *> ZLASYF is an auxiliary routine called by ZSYTRF. It uses blocked code
                     53: *> (calling Level 3 BLAS) to update the submatrix A11 (if UPLO = 'U') or
                     54: *> A22 (if UPLO = 'L').
                     55: *> \endverbatim
                     56: *
                     57: *  Arguments:
                     58: *  ==========
                     59: *
                     60: *> \param[in] UPLO
                     61: *> \verbatim
                     62: *>          UPLO is CHARACTER*1
                     63: *>          Specifies whether the upper or lower triangular part of the
                     64: *>          symmetric matrix A is stored:
                     65: *>          = 'U':  Upper triangular
                     66: *>          = 'L':  Lower triangular
                     67: *> \endverbatim
                     68: *>
                     69: *> \param[in] N
                     70: *> \verbatim
                     71: *>          N is INTEGER
                     72: *>          The order of the matrix A.  N >= 0.
                     73: *> \endverbatim
                     74: *>
                     75: *> \param[in] NB
                     76: *> \verbatim
                     77: *>          NB is INTEGER
                     78: *>          The maximum number of columns of the matrix A that should be
                     79: *>          factored.  NB should be at least 2 to allow for 2-by-2 pivot
                     80: *>          blocks.
                     81: *> \endverbatim
                     82: *>
                     83: *> \param[out] KB
                     84: *> \verbatim
                     85: *>          KB is INTEGER
                     86: *>          The number of columns of A that were actually factored.
                     87: *>          KB is either NB-1 or NB, or N if N <= NB.
                     88: *> \endverbatim
                     89: *>
                     90: *> \param[in,out] A
                     91: *> \verbatim
                     92: *>          A is COMPLEX*16 array, dimension (LDA,N)
                     93: *>          On entry, the symmetric matrix A.  If UPLO = 'U', the leading
                     94: *>          n-by-n upper triangular part of A contains the upper
                     95: *>          triangular part of the matrix A, and the strictly lower
                     96: *>          triangular part of A is not referenced.  If UPLO = 'L', the
                     97: *>          leading n-by-n lower triangular part of A contains the lower
                     98: *>          triangular part of the matrix A, and the strictly upper
                     99: *>          triangular part of A is not referenced.
                    100: *>          On exit, A contains details of the partial factorization.
                    101: *> \endverbatim
                    102: *>
                    103: *> \param[in] LDA
                    104: *> \verbatim
                    105: *>          LDA is INTEGER
                    106: *>          The leading dimension of the array A.  LDA >= max(1,N).
                    107: *> \endverbatim
                    108: *>
                    109: *> \param[out] IPIV
                    110: *> \verbatim
                    111: *>          IPIV is INTEGER array, dimension (N)
                    112: *>          Details of the interchanges and the block structure of D.
                    113: *>
1.14      bertrand  114: *>          If UPLO = 'U':
                    115: *>             Only the last KB elements of IPIV are set.
                    116: *>
                    117: *>             If IPIV(k) > 0, then rows and columns k and IPIV(k) were
                    118: *>             interchanged and D(k,k) is a 1-by-1 diagonal block.
                    119: *>
                    120: *>             If IPIV(k) = IPIV(k-1) < 0, then rows and columns
                    121: *>             k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k)
                    122: *>             is a 2-by-2 diagonal block.
                    123: *>
                    124: *>          If UPLO = 'L':
                    125: *>             Only the first KB elements of IPIV are set.
                    126: *>
                    127: *>             If IPIV(k) > 0, then rows and columns k and IPIV(k) were
                    128: *>             interchanged and D(k,k) is a 1-by-1 diagonal block.
                    129: *>
                    130: *>             If IPIV(k) = IPIV(k+1) < 0, then rows and columns
                    131: *>             k+1 and -IPIV(k) were interchanged and D(k:k+1,k:k+1)
                    132: *>             is a 2-by-2 diagonal block.
1.9       bertrand  133: *> \endverbatim
                    134: *>
                    135: *> \param[out] W
                    136: *> \verbatim
                    137: *>          W is COMPLEX*16 array, dimension (LDW,NB)
                    138: *> \endverbatim
                    139: *>
                    140: *> \param[in] LDW
                    141: *> \verbatim
                    142: *>          LDW is INTEGER
                    143: *>          The leading dimension of the array W.  LDW >= max(1,N).
                    144: *> \endverbatim
                    145: *>
                    146: *> \param[out] INFO
                    147: *> \verbatim
                    148: *>          INFO is INTEGER
                    149: *>          = 0: successful exit
                    150: *>          > 0: if INFO = k, D(k,k) is exactly zero.  The factorization
                    151: *>               has been completed, but the block diagonal matrix D is
                    152: *>               exactly singular.
                    153: *> \endverbatim
                    154: *
                    155: *  Authors:
                    156: *  ========
                    157: *
1.14      bertrand  158: *> \author Univ. of Tennessee
                    159: *> \author Univ. of California Berkeley
                    160: *> \author Univ. of Colorado Denver
                    161: *> \author NAG Ltd.
1.9       bertrand  162: *
1.14      bertrand  163: *> \date November 2013
1.9       bertrand  164: *
                    165: *> \ingroup complex16SYcomputational
                    166: *
1.14      bertrand  167: *> \par Contributors:
                    168: *  ==================
                    169: *>
                    170: *> \verbatim
                    171: *>
                    172: *>  November 2013,  Igor Kozachenko,
                    173: *>                  Computer Science Division,
                    174: *>                  University of California, Berkeley
                    175: *> \endverbatim
                    176: *
1.9       bertrand  177: *  =====================================================================
1.1       bertrand  178:       SUBROUTINE ZLASYF( UPLO, N, NB, KB, A, LDA, IPIV, W, LDW, INFO )
                    179: *
1.14      bertrand  180: *  -- LAPACK computational routine (version 3.5.0) --
1.1       bertrand  181: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
                    182: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
1.14      bertrand  183: *     November 2013
1.1       bertrand  184: *
                    185: *     .. Scalar Arguments ..
                    186:       CHARACTER          UPLO
                    187:       INTEGER            INFO, KB, LDA, LDW, N, NB
                    188: *     ..
                    189: *     .. Array Arguments ..
                    190:       INTEGER            IPIV( * )
                    191:       COMPLEX*16         A( LDA, * ), W( LDW, * )
                    192: *     ..
                    193: *
                    194: *  =====================================================================
                    195: *
                    196: *     .. Parameters ..
                    197:       DOUBLE PRECISION   ZERO, ONE
                    198:       PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0 )
                    199:       DOUBLE PRECISION   EIGHT, SEVTEN
                    200:       PARAMETER          ( EIGHT = 8.0D+0, SEVTEN = 17.0D+0 )
                    201:       COMPLEX*16         CONE
                    202:       PARAMETER          ( CONE = ( 1.0D+0, 0.0D+0 ) )
                    203: *     ..
                    204: *     .. Local Scalars ..
                    205:       INTEGER            IMAX, J, JB, JJ, JMAX, JP, K, KK, KKW, KP,
                    206:      $                   KSTEP, KW
                    207:       DOUBLE PRECISION   ABSAKK, ALPHA, COLMAX, ROWMAX
                    208:       COMPLEX*16         D11, D21, D22, R1, T, Z
                    209: *     ..
                    210: *     .. External Functions ..
                    211:       LOGICAL            LSAME
                    212:       INTEGER            IZAMAX
                    213:       EXTERNAL           LSAME, IZAMAX
                    214: *     ..
                    215: *     .. External Subroutines ..
                    216:       EXTERNAL           ZCOPY, ZGEMM, ZGEMV, ZSCAL, ZSWAP
                    217: *     ..
                    218: *     .. Intrinsic Functions ..
                    219:       INTRINSIC          ABS, DBLE, DIMAG, MAX, MIN, SQRT
                    220: *     ..
                    221: *     .. Statement Functions ..
                    222:       DOUBLE PRECISION   CABS1
                    223: *     ..
                    224: *     .. Statement Function definitions ..
                    225:       CABS1( Z ) = ABS( DBLE( Z ) ) + ABS( DIMAG( Z ) )
                    226: *     ..
                    227: *     .. Executable Statements ..
                    228: *
                    229:       INFO = 0
                    230: *
                    231: *     Initialize ALPHA for use in choosing pivot block size.
                    232: *
                    233:       ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT
                    234: *
                    235:       IF( LSAME( UPLO, 'U' ) ) THEN
                    236: *
                    237: *        Factorize the trailing columns of A using the upper triangle
                    238: *        of A and working backwards, and compute the matrix W = U12*D
                    239: *        for use in updating A11
                    240: *
                    241: *        K is the main loop index, decreasing from N in steps of 1 or 2
                    242: *
                    243: *        KW is the column of W which corresponds to column K of A
                    244: *
                    245:          K = N
                    246:    10    CONTINUE
                    247:          KW = NB + K - N
                    248: *
                    249: *        Exit from loop
                    250: *
                    251:          IF( ( K.LE.N-NB+1 .AND. NB.LT.N ) .OR. K.LT.1 )
                    252:      $      GO TO 30
                    253: *
                    254: *        Copy column K of A to column KW of W and update it
                    255: *
                    256:          CALL ZCOPY( K, A( 1, K ), 1, W( 1, KW ), 1 )
                    257:          IF( K.LT.N )
                    258:      $      CALL ZGEMV( 'No transpose', K, N-K, -CONE, A( 1, K+1 ), LDA,
                    259:      $                  W( K, KW+1 ), LDW, CONE, W( 1, KW ), 1 )
                    260: *
                    261:          KSTEP = 1
                    262: *
                    263: *        Determine rows and columns to be interchanged and whether
                    264: *        a 1-by-1 or 2-by-2 pivot block will be used
                    265: *
                    266:          ABSAKK = CABS1( W( K, KW ) )
                    267: *
                    268: *        IMAX is the row-index of the largest off-diagonal element in
1.14      bertrand  269: 
1.1       bertrand  270: *
                    271:          IF( K.GT.1 ) THEN
                    272:             IMAX = IZAMAX( K-1, W( 1, KW ), 1 )
                    273:             COLMAX = CABS1( W( IMAX, KW ) )
                    274:          ELSE
                    275:             COLMAX = ZERO
                    276:          END IF
                    277: *
                    278:          IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
                    279: *
1.14      bertrand  280: *           Column K is zero or underflow: set INFO and continue
1.1       bertrand  281: *
                    282:             IF( INFO.EQ.0 )
                    283:      $         INFO = K
                    284:             KP = K
                    285:          ELSE
                    286:             IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
                    287: *
                    288: *              no interchange, use 1-by-1 pivot block
                    289: *
                    290:                KP = K
                    291:             ELSE
                    292: *
                    293: *              Copy column IMAX to column KW-1 of W and update it
                    294: *
                    295:                CALL ZCOPY( IMAX, A( 1, IMAX ), 1, W( 1, KW-1 ), 1 )
                    296:                CALL ZCOPY( K-IMAX, A( IMAX, IMAX+1 ), LDA,
                    297:      $                     W( IMAX+1, KW-1 ), 1 )
                    298:                IF( K.LT.N )
                    299:      $            CALL ZGEMV( 'No transpose', K, N-K, -CONE,
                    300:      $                        A( 1, K+1 ), LDA, W( IMAX, KW+1 ), LDW,
                    301:      $                        CONE, W( 1, KW-1 ), 1 )
                    302: *
                    303: *              JMAX is the column-index of the largest off-diagonal
                    304: *              element in row IMAX, and ROWMAX is its absolute value
                    305: *
                    306:                JMAX = IMAX + IZAMAX( K-IMAX, W( IMAX+1, KW-1 ), 1 )
                    307:                ROWMAX = CABS1( W( JMAX, KW-1 ) )
                    308:                IF( IMAX.GT.1 ) THEN
                    309:                   JMAX = IZAMAX( IMAX-1, W( 1, KW-1 ), 1 )
                    310:                   ROWMAX = MAX( ROWMAX, CABS1( W( JMAX, KW-1 ) ) )
                    311:                END IF
                    312: *
                    313:                IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
                    314: *
                    315: *                 no interchange, use 1-by-1 pivot block
                    316: *
                    317:                   KP = K
                    318:                ELSE IF( CABS1( W( IMAX, KW-1 ) ).GE.ALPHA*ROWMAX ) THEN
                    319: *
                    320: *                 interchange rows and columns K and IMAX, use 1-by-1
                    321: *                 pivot block
                    322: *
                    323:                   KP = IMAX
                    324: *
1.14      bertrand  325: *                 copy column KW-1 of W to column KW of W
1.1       bertrand  326: *
                    327:                   CALL ZCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 )
                    328:                ELSE
                    329: *
                    330: *                 interchange rows and columns K-1 and IMAX, use 2-by-2
                    331: *                 pivot block
                    332: *
                    333:                   KP = IMAX
                    334:                   KSTEP = 2
                    335:                END IF
                    336:             END IF
                    337: *
1.14      bertrand  338: *           ============================================================
                    339: *
                    340: *           KK is the column of A where pivoting step stopped
                    341: *
1.1       bertrand  342:             KK = K - KSTEP + 1
1.14      bertrand  343: *
                    344: *           KKW is the column of W which corresponds to column KK of A
                    345: *
1.1       bertrand  346:             KKW = NB + KK - N
                    347: *
1.14      bertrand  348: *           Interchange rows and columns KP and KK.
                    349: *           Updated column KP is already stored in column KKW of W.
1.1       bertrand  350: *
                    351:             IF( KP.NE.KK ) THEN
                    352: *
1.14      bertrand  353: *              Copy non-updated column KK to column KP of submatrix A
                    354: *              at step K. No need to copy element into column K
                    355: *              (or K and K-1 for 2-by-2 pivot) of A, since these columns
                    356: *              will be later overwritten.
1.1       bertrand  357: *
1.14      bertrand  358:                A( KP, KP ) = A( KK, KK )
                    359:                CALL ZCOPY( KK-1-KP, A( KP+1, KK ), 1, A( KP, KP+1 ),
1.1       bertrand  360:      $                     LDA )
1.14      bertrand  361:                IF( KP.GT.1 )
                    362:      $            CALL ZCOPY( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 )
1.1       bertrand  363: *
1.14      bertrand  364: *              Interchange rows KK and KP in last K+1 to N columns of A
                    365: *              (columns K (or K and K-1 for 2-by-2 pivot) of A will be
                    366: *              later overwritten). Interchange rows KK and KP
                    367: *              in last KKW to NB columns of W.
1.1       bertrand  368: *
1.14      bertrand  369:                IF( K.LT.N )
                    370:      $            CALL ZSWAP( N-K, A( KK, K+1 ), LDA, A( KP, K+1 ),
                    371:      $                        LDA )
1.1       bertrand  372:                CALL ZSWAP( N-KK+1, W( KK, KKW ), LDW, W( KP, KKW ),
                    373:      $                     LDW )
                    374:             END IF
                    375: *
                    376:             IF( KSTEP.EQ.1 ) THEN
                    377: *
1.14      bertrand  378: *              1-by-1 pivot block D(k): column kw of W now holds
1.1       bertrand  379: *
1.14      bertrand  380: *              W(kw) = U(k)*D(k),
1.1       bertrand  381: *
                    382: *              where U(k) is the k-th column of U
                    383: *
1.14      bertrand  384: *              Store subdiag. elements of column U(k)
                    385: *              and 1-by-1 block D(k) in column k of A.
                    386: *              NOTE: Diagonal element U(k,k) is a UNIT element
                    387: *              and not stored.
                    388: *                 A(k,k) := D(k,k) = W(k,kw)
                    389: *                 A(1:k-1,k) := U(1:k-1,k) = W(1:k-1,kw)/D(k,k)
1.1       bertrand  390: *
                    391:                CALL ZCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 )
                    392:                R1 = CONE / A( K, K )
                    393:                CALL ZSCAL( K-1, R1, A( 1, K ), 1 )
1.14      bertrand  394: *
1.1       bertrand  395:             ELSE
                    396: *
1.14      bertrand  397: *              2-by-2 pivot block D(k): columns kw and kw-1 of W now hold
1.1       bertrand  398: *
1.14      bertrand  399: *              ( W(kw-1) W(kw) ) = ( U(k-1) U(k) )*D(k)
1.1       bertrand  400: *
                    401: *              where U(k) and U(k-1) are the k-th and (k-1)-th columns
                    402: *              of U
                    403: *
1.14      bertrand  404: *              Store U(1:k-2,k-1) and U(1:k-2,k) and 2-by-2
                    405: *              block D(k-1:k,k-1:k) in columns k-1 and k of A.
                    406: *              NOTE: 2-by-2 diagonal block U(k-1:k,k-1:k) is a UNIT
                    407: *              block and not stored.
                    408: *                 A(k-1:k,k-1:k) := D(k-1:k,k-1:k) = W(k-1:k,kw-1:kw)
                    409: *                 A(1:k-2,k-1:k) := U(1:k-2,k:k-1:k) =
                    410: *                 = W(1:k-2,kw-1:kw) * ( D(k-1:k,k-1:k)**(-1) )
                    411: *
1.1       bertrand  412:                IF( K.GT.2 ) THEN
                    413: *
1.14      bertrand  414: *                 Compose the columns of the inverse of 2-by-2 pivot
                    415: *                 block D in the following way to reduce the number
                    416: *                 of FLOPS when we myltiply panel ( W(kw-1) W(kw) ) by
                    417: *                 this inverse
                    418: *
                    419: *                 D**(-1) = ( d11 d21 )**(-1) =
                    420: *                           ( d21 d22 )
                    421: *
                    422: *                 = 1/(d11*d22-d21**2) * ( ( d22 ) (-d21 ) ) =
                    423: *                                        ( (-d21 ) ( d11 ) )
                    424: *
                    425: *                 = 1/d21 * 1/((d11/d21)*(d22/d21)-1) *
                    426: *
                    427: *                   * ( ( d22/d21 ) (      -1 ) ) =
                    428: *                     ( (      -1 ) ( d11/d21 ) )
                    429: *
                    430: *                 = 1/d21 * 1/(D22*D11-1) * ( ( D11 ) (  -1 ) ) =
                    431: *                                           ( ( -1  ) ( D22 ) )
                    432: *
                    433: *                 = 1/d21 * T * ( ( D11 ) (  -1 ) )
                    434: *                               ( (  -1 ) ( D22 ) )
                    435: *
                    436: *                 = D21 * ( ( D11 ) (  -1 ) )
                    437: *                         ( (  -1 ) ( D22 ) )
1.1       bertrand  438: *
                    439:                   D21 = W( K-1, KW )
                    440:                   D11 = W( K, KW ) / D21
                    441:                   D22 = W( K-1, KW-1 ) / D21
                    442:                   T = CONE / ( D11*D22-CONE )
                    443:                   D21 = T / D21
1.14      bertrand  444: *
                    445: *                 Update elements in columns A(k-1) and A(k) as
                    446: *                 dot products of rows of ( W(kw-1) W(kw) ) and columns
                    447: *                 of D**(-1)
                    448: *
1.1       bertrand  449:                   DO 20 J = 1, K - 2
                    450:                      A( J, K-1 ) = D21*( D11*W( J, KW-1 )-W( J, KW ) )
                    451:                      A( J, K ) = D21*( D22*W( J, KW )-W( J, KW-1 ) )
                    452:    20             CONTINUE
                    453:                END IF
                    454: *
                    455: *              Copy D(k) to A
                    456: *
                    457:                A( K-1, K-1 ) = W( K-1, KW-1 )
                    458:                A( K-1, K ) = W( K-1, KW )
                    459:                A( K, K ) = W( K, KW )
1.14      bertrand  460: *
1.1       bertrand  461:             END IF
1.14      bertrand  462: *
1.1       bertrand  463:          END IF
                    464: *
                    465: *        Store details of the interchanges in IPIV
                    466: *
                    467:          IF( KSTEP.EQ.1 ) THEN
                    468:             IPIV( K ) = KP
                    469:          ELSE
                    470:             IPIV( K ) = -KP
                    471:             IPIV( K-1 ) = -KP
                    472:          END IF
                    473: *
                    474: *        Decrease K and return to the start of the main loop
                    475: *
                    476:          K = K - KSTEP
                    477:          GO TO 10
                    478: *
                    479:    30    CONTINUE
                    480: *
                    481: *        Update the upper triangle of A11 (= A(1:k,1:k)) as
                    482: *
1.8       bertrand  483: *        A11 := A11 - U12*D*U12**T = A11 - U12*W**T
1.1       bertrand  484: *
                    485: *        computing blocks of NB columns at a time
                    486: *
                    487:          DO 50 J = ( ( K-1 ) / NB )*NB + 1, 1, -NB
                    488:             JB = MIN( NB, K-J+1 )
                    489: *
                    490: *           Update the upper triangle of the diagonal block
                    491: *
                    492:             DO 40 JJ = J, J + JB - 1
                    493:                CALL ZGEMV( 'No transpose', JJ-J+1, N-K, -CONE,
                    494:      $                     A( J, K+1 ), LDA, W( JJ, KW+1 ), LDW, CONE,
                    495:      $                     A( J, JJ ), 1 )
                    496:    40       CONTINUE
                    497: *
                    498: *           Update the rectangular superdiagonal block
                    499: *
                    500:             CALL ZGEMM( 'No transpose', 'Transpose', J-1, JB, N-K,
                    501:      $                  -CONE, A( 1, K+1 ), LDA, W( J, KW+1 ), LDW,
                    502:      $                  CONE, A( 1, J ), LDA )
                    503:    50    CONTINUE
                    504: *
                    505: *        Put U12 in standard form by partially undoing the interchanges
1.14      bertrand  506: *        in columns k+1:n looping backwards from k+1 to n
1.1       bertrand  507: *
                    508:          J = K + 1
                    509:    60    CONTINUE
1.14      bertrand  510: *
                    511: *           Undo the interchanges (if any) of rows JJ and JP at each
                    512: *           step J
                    513: *
                    514: *           (Here, J is a diagonal index)
                    515:             JJ = J
                    516:             JP = IPIV( J )
                    517:             IF( JP.LT.0 ) THEN
                    518:                JP = -JP
                    519: *              (Here, J is a diagonal index)
                    520:                J = J + 1
                    521:             END IF
                    522: *           (NOTE: Here, J is used to determine row length. Length N-J+1
                    523: *           of the rows to swap back doesn't include diagonal element)
1.1       bertrand  524:             J = J + 1
1.14      bertrand  525:             IF( JP.NE.JJ .AND. J.LE.N )
                    526:      $         CALL ZSWAP( N-J+1, A( JP, J ), LDA, A( JJ, J ), LDA )
                    527:          IF( J.LT.N )
1.1       bertrand  528:      $      GO TO 60
                    529: *
                    530: *        Set KB to the number of columns factorized
                    531: *
                    532:          KB = N - K
                    533: *
                    534:       ELSE
                    535: *
                    536: *        Factorize the leading columns of A using the lower triangle
                    537: *        of A and working forwards, and compute the matrix W = L21*D
                    538: *        for use in updating A22
                    539: *
                    540: *        K is the main loop index, increasing from 1 in steps of 1 or 2
                    541: *
                    542:          K = 1
                    543:    70    CONTINUE
                    544: *
                    545: *        Exit from loop
                    546: *
                    547:          IF( ( K.GE.NB .AND. NB.LT.N ) .OR. K.GT.N )
                    548:      $      GO TO 90
                    549: *
                    550: *        Copy column K of A to column K of W and update it
                    551: *
                    552:          CALL ZCOPY( N-K+1, A( K, K ), 1, W( K, K ), 1 )
                    553:          CALL ZGEMV( 'No transpose', N-K+1, K-1, -CONE, A( K, 1 ), LDA,
                    554:      $               W( K, 1 ), LDW, CONE, W( K, K ), 1 )
                    555: *
                    556:          KSTEP = 1
                    557: *
                    558: *        Determine rows and columns to be interchanged and whether
                    559: *        a 1-by-1 or 2-by-2 pivot block will be used
                    560: *
                    561:          ABSAKK = CABS1( W( K, K ) )
                    562: *
                    563: *        IMAX is the row-index of the largest off-diagonal element in
1.14      bertrand  564: 
1.1       bertrand  565: *
                    566:          IF( K.LT.N ) THEN
                    567:             IMAX = K + IZAMAX( N-K, W( K+1, K ), 1 )
                    568:             COLMAX = CABS1( W( IMAX, K ) )
                    569:          ELSE
                    570:             COLMAX = ZERO
                    571:          END IF
                    572: *
                    573:          IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
                    574: *
1.14      bertrand  575: *           Column K is zero or underflow: set INFO and continue
1.1       bertrand  576: *
                    577:             IF( INFO.EQ.0 )
                    578:      $         INFO = K
                    579:             KP = K
                    580:          ELSE
                    581:             IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
                    582: *
                    583: *              no interchange, use 1-by-1 pivot block
                    584: *
                    585:                KP = K
                    586:             ELSE
                    587: *
                    588: *              Copy column IMAX to column K+1 of W and update it
                    589: *
                    590:                CALL ZCOPY( IMAX-K, A( IMAX, K ), LDA, W( K, K+1 ), 1 )
                    591:                CALL ZCOPY( N-IMAX+1, A( IMAX, IMAX ), 1, W( IMAX, K+1 ),
                    592:      $                     1 )
                    593:                CALL ZGEMV( 'No transpose', N-K+1, K-1, -CONE, A( K, 1 ),
                    594:      $                     LDA, W( IMAX, 1 ), LDW, CONE, W( K, K+1 ),
                    595:      $                     1 )
                    596: *
                    597: *              JMAX is the column-index of the largest off-diagonal
                    598: *              element in row IMAX, and ROWMAX is its absolute value
                    599: *
                    600:                JMAX = K - 1 + IZAMAX( IMAX-K, W( K, K+1 ), 1 )
                    601:                ROWMAX = CABS1( W( JMAX, K+1 ) )
                    602:                IF( IMAX.LT.N ) THEN
                    603:                   JMAX = IMAX + IZAMAX( N-IMAX, W( IMAX+1, K+1 ), 1 )
                    604:                   ROWMAX = MAX( ROWMAX, CABS1( W( JMAX, K+1 ) ) )
                    605:                END IF
                    606: *
                    607:                IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
                    608: *
                    609: *                 no interchange, use 1-by-1 pivot block
                    610: *
                    611:                   KP = K
                    612:                ELSE IF( CABS1( W( IMAX, K+1 ) ).GE.ALPHA*ROWMAX ) THEN
                    613: *
                    614: *                 interchange rows and columns K and IMAX, use 1-by-1
                    615: *                 pivot block
                    616: *
                    617:                   KP = IMAX
                    618: *
1.14      bertrand  619: *                 copy column K+1 of W to column K of W
1.1       bertrand  620: *
                    621:                   CALL ZCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), 1 )
                    622:                ELSE
                    623: *
                    624: *                 interchange rows and columns K+1 and IMAX, use 2-by-2
                    625: *                 pivot block
                    626: *
                    627:                   KP = IMAX
                    628:                   KSTEP = 2
                    629:                END IF
                    630:             END IF
                    631: *
1.14      bertrand  632: *           ============================================================
                    633: *
                    634: *           KK is the column of A where pivoting step stopped
                    635: *
1.1       bertrand  636:             KK = K + KSTEP - 1
                    637: *
1.14      bertrand  638: *           Interchange rows and columns KP and KK.
                    639: *           Updated column KP is already stored in column KK of W.
1.1       bertrand  640: *
                    641:             IF( KP.NE.KK ) THEN
                    642: *
1.14      bertrand  643: *              Copy non-updated column KK to column KP of submatrix A
                    644: *              at step K. No need to copy element into column K
                    645: *              (or K and K+1 for 2-by-2 pivot) of A, since these columns
                    646: *              will be later overwritten.
1.1       bertrand  647: *
1.14      bertrand  648:                A( KP, KP ) = A( KK, KK )
                    649:                CALL ZCOPY( KP-KK-1, A( KK+1, KK ), 1, A( KP, KK+1 ),
                    650:      $                     LDA )
                    651:                IF( KP.LT.N )
                    652:      $            CALL ZCOPY( N-KP, A( KP+1, KK ), 1, A( KP+1, KP ), 1 )
1.1       bertrand  653: *
1.14      bertrand  654: *              Interchange rows KK and KP in first K-1 columns of A
                    655: *              (columns K (or K and K+1 for 2-by-2 pivot) of A will be
                    656: *              later overwritten). Interchange rows KK and KP
                    657: *              in first KK columns of W.
1.1       bertrand  658: *
1.14      bertrand  659:                IF( K.GT.1 )
                    660:      $            CALL ZSWAP( K-1, A( KK, 1 ), LDA, A( KP, 1 ), LDA )
1.1       bertrand  661:                CALL ZSWAP( KK, W( KK, 1 ), LDW, W( KP, 1 ), LDW )
                    662:             END IF
                    663: *
                    664:             IF( KSTEP.EQ.1 ) THEN
                    665: *
                    666: *              1-by-1 pivot block D(k): column k of W now holds
                    667: *
1.14      bertrand  668: *              W(k) = L(k)*D(k),
1.1       bertrand  669: *
                    670: *              where L(k) is the k-th column of L
                    671: *
1.14      bertrand  672: *              Store subdiag. elements of column L(k)
                    673: *              and 1-by-1 block D(k) in column k of A.
                    674: *              (NOTE: Diagonal element L(k,k) is a UNIT element
                    675: *              and not stored)
                    676: *                 A(k,k) := D(k,k) = W(k,k)
                    677: *                 A(k+1:N,k) := L(k+1:N,k) = W(k+1:N,k)/D(k,k)
1.1       bertrand  678: *
                    679:                CALL ZCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 )
                    680:                IF( K.LT.N ) THEN
                    681:                   R1 = CONE / A( K, K )
                    682:                   CALL ZSCAL( N-K, R1, A( K+1, K ), 1 )
                    683:                END IF
1.14      bertrand  684: *
1.1       bertrand  685:             ELSE
                    686: *
                    687: *              2-by-2 pivot block D(k): columns k and k+1 of W now hold
                    688: *
                    689: *              ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k)
                    690: *
                    691: *              where L(k) and L(k+1) are the k-th and (k+1)-th columns
                    692: *              of L
                    693: *
1.14      bertrand  694: *              Store L(k+2:N,k) and L(k+2:N,k+1) and 2-by-2
                    695: *              block D(k:k+1,k:k+1) in columns k and k+1 of A.
                    696: *              (NOTE: 2-by-2 diagonal block L(k:k+1,k:k+1) is a UNIT
                    697: *              block and not stored)
                    698: *                 A(k:k+1,k:k+1) := D(k:k+1,k:k+1) = W(k:k+1,k:k+1)
                    699: *                 A(k+2:N,k:k+1) := L(k+2:N,k:k+1) =
                    700: *                 = W(k+2:N,k:k+1) * ( D(k:k+1,k:k+1)**(-1) )
                    701: *
1.1       bertrand  702:                IF( K.LT.N-1 ) THEN
                    703: *
1.14      bertrand  704: *                 Compose the columns of the inverse of 2-by-2 pivot
                    705: *                 block D in the following way to reduce the number
                    706: *                 of FLOPS when we myltiply panel ( W(k) W(k+1) ) by
                    707: *                 this inverse
                    708: *
                    709: *                 D**(-1) = ( d11 d21 )**(-1) =
                    710: *                           ( d21 d22 )
                    711: *
                    712: *                 = 1/(d11*d22-d21**2) * ( ( d22 ) (-d21 ) ) =
                    713: *                                        ( (-d21 ) ( d11 ) )
                    714: *
                    715: *                 = 1/d21 * 1/((d11/d21)*(d22/d21)-1) *
                    716: *
                    717: *                   * ( ( d22/d21 ) (      -1 ) ) =
                    718: *                     ( (      -1 ) ( d11/d21 ) )
                    719: *
                    720: *                 = 1/d21 * 1/(D22*D11-1) * ( ( D11 ) (  -1 ) ) =
                    721: *                                           ( ( -1  ) ( D22 ) )
                    722: *
                    723: *                 = 1/d21 * T * ( ( D11 ) (  -1 ) )
                    724: *                               ( (  -1 ) ( D22 ) )
                    725: *
                    726: *                 = D21 * ( ( D11 ) (  -1 ) )
                    727: *                         ( (  -1 ) ( D22 ) )
1.1       bertrand  728: *
                    729:                   D21 = W( K+1, K )
                    730:                   D11 = W( K+1, K+1 ) / D21
                    731:                   D22 = W( K, K ) / D21
                    732:                   T = CONE / ( D11*D22-CONE )
                    733:                   D21 = T / D21
1.14      bertrand  734: *
                    735: *                 Update elements in columns A(k) and A(k+1) as
                    736: *                 dot products of rows of ( W(k) W(k+1) ) and columns
                    737: *                 of D**(-1)
                    738: *
1.1       bertrand  739:                   DO 80 J = K + 2, N
                    740:                      A( J, K ) = D21*( D11*W( J, K )-W( J, K+1 ) )
                    741:                      A( J, K+1 ) = D21*( D22*W( J, K+1 )-W( J, K ) )
                    742:    80             CONTINUE
                    743:                END IF
                    744: *
                    745: *              Copy D(k) to A
                    746: *
                    747:                A( K, K ) = W( K, K )
                    748:                A( K+1, K ) = W( K+1, K )
                    749:                A( K+1, K+1 ) = W( K+1, K+1 )
1.14      bertrand  750: *
1.1       bertrand  751:             END IF
1.14      bertrand  752: *
1.1       bertrand  753:          END IF
                    754: *
                    755: *        Store details of the interchanges in IPIV
                    756: *
                    757:          IF( KSTEP.EQ.1 ) THEN
                    758:             IPIV( K ) = KP
                    759:          ELSE
                    760:             IPIV( K ) = -KP
                    761:             IPIV( K+1 ) = -KP
                    762:          END IF
                    763: *
                    764: *        Increase K and return to the start of the main loop
                    765: *
                    766:          K = K + KSTEP
                    767:          GO TO 70
                    768: *
                    769:    90    CONTINUE
                    770: *
                    771: *        Update the lower triangle of A22 (= A(k:n,k:n)) as
                    772: *
1.8       bertrand  773: *        A22 := A22 - L21*D*L21**T = A22 - L21*W**T
1.1       bertrand  774: *
                    775: *        computing blocks of NB columns at a time
                    776: *
                    777:          DO 110 J = K, N, NB
                    778:             JB = MIN( NB, N-J+1 )
                    779: *
                    780: *           Update the lower triangle of the diagonal block
                    781: *
                    782:             DO 100 JJ = J, J + JB - 1
                    783:                CALL ZGEMV( 'No transpose', J+JB-JJ, K-1, -CONE,
                    784:      $                     A( JJ, 1 ), LDA, W( JJ, 1 ), LDW, CONE,
                    785:      $                     A( JJ, JJ ), 1 )
                    786:   100       CONTINUE
                    787: *
                    788: *           Update the rectangular subdiagonal block
                    789: *
                    790:             IF( J+JB.LE.N )
                    791:      $         CALL ZGEMM( 'No transpose', 'Transpose', N-J-JB+1, JB,
                    792:      $                     K-1, -CONE, A( J+JB, 1 ), LDA, W( J, 1 ),
                    793:      $                     LDW, CONE, A( J+JB, J ), LDA )
                    794:   110    CONTINUE
                    795: *
                    796: *        Put L21 in standard form by partially undoing the interchanges
1.14      bertrand  797: *        of rows in columns 1:k-1 looping backwards from k-1 to 1
1.1       bertrand  798: *
                    799:          J = K - 1
                    800:   120    CONTINUE
1.14      bertrand  801: *
                    802: *           Undo the interchanges (if any) of rows JJ and JP at each
                    803: *           step J
                    804: *
                    805: *           (Here, J is a diagonal index)
                    806:             JJ = J
                    807:             JP = IPIV( J )
                    808:             IF( JP.LT.0 ) THEN
                    809:                JP = -JP
                    810: *              (Here, J is a diagonal index)
                    811:                J = J - 1
                    812:             END IF
                    813: *           (NOTE: Here, J is used to determine row length. Length J
                    814: *           of the rows to swap back doesn't include diagonal element)
1.1       bertrand  815:             J = J - 1
1.14      bertrand  816:             IF( JP.NE.JJ .AND. J.GE.1 )
                    817:      $         CALL ZSWAP( J, A( JP, 1 ), LDA, A( JJ, 1 ), LDA )
                    818:          IF( J.GT.1 )
1.1       bertrand  819:      $      GO TO 120
                    820: *
                    821: *        Set KB to the number of columns factorized
                    822: *
                    823:          KB = K - 1
                    824: *
                    825:       END IF
                    826:       RETURN
                    827: *
                    828: *     End of ZLASYF
                    829: *
                    830:       END

CVSweb interface <joel.bertrand@systella.fr>