File:  [local] / rpl / lapack / lapack / zlasyf.f
Revision 1.19: download - view: text, annotated - select for diffs - revision graph
Mon Aug 7 08:39:32 2023 UTC (8 months, 3 weeks ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_1_35, rpl-4_1_34, HEAD
Première mise à jour de lapack et blas.

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

CVSweb interface <joel.bertrand@systella.fr>