chetf2.f.html

来自「famous linear algebra library (LAPACK) p」· HTML 代码 · 共 576 行 · 第 1/3 页

HTML
576
字号
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Initialize ALPHA for use in choosing pivot block size.
</span><span class="comment">*</span><span class="comment">
</span>      ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT
<span class="comment">*</span><span class="comment">
</span>      IF( UPPER ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Factorize A as U*D*U' using the upper triangle of A
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        K is the main loop index, decreasing from N to 1 in steps of
</span><span class="comment">*</span><span class="comment">        1 or 2
</span><span class="comment">*</span><span class="comment">
</span>         K = N
   10    CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        If K &lt; 1, exit from loop
</span><span class="comment">*</span><span class="comment">
</span>         IF( K.LT.1 )
     $      GO TO 90
         KSTEP = 1
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Determine rows and columns to be interchanged and whether
</span><span class="comment">*</span><span class="comment">        a 1-by-1 or 2-by-2 pivot block will be used
</span><span class="comment">*</span><span class="comment">
</span>         ABSAKK = ABS( REAL( A( K, K ) ) )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        IMAX is the row-index of the largest off-diagonal element in
</span><span class="comment">*</span><span class="comment">        column K, and COLMAX is its absolute value
</span><span class="comment">*</span><span class="comment">
</span>         IF( K.GT.1 ) THEN
            IMAX = ICAMAX( K-1, A( 1, K ), 1 )
            COLMAX = CABS1( A( IMAX, K ) )
         ELSE
            COLMAX = ZERO
         END IF
<span class="comment">*</span><span class="comment">
</span>         IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. <a name="SISNAN.210"></a><a href="sisnan.f.html#SISNAN.1">SISNAN</a>(ABSAKK) ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Column K is zero or contains a NaN: set INFO and continue
</span><span class="comment">*</span><span class="comment">
</span>            IF( INFO.EQ.0 )
     $         INFO = K
            KP = K
            A( K, K ) = REAL( A( K, K ) )
         ELSE
            IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              no interchange, use 1-by-1 pivot block
</span><span class="comment">*</span><span class="comment">
</span>               KP = K
            ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              JMAX is the column-index of the largest off-diagonal
</span><span class="comment">*</span><span class="comment">              element in row IMAX, and ROWMAX is its absolute value
</span><span class="comment">*</span><span class="comment">
</span>               JMAX = IMAX + ICAMAX( K-IMAX, A( IMAX, IMAX+1 ), LDA )
               ROWMAX = CABS1( A( IMAX, JMAX ) )
               IF( IMAX.GT.1 ) THEN
                  JMAX = ICAMAX( IMAX-1, A( 1, IMAX ), 1 )
                  ROWMAX = MAX( ROWMAX, CABS1( A( JMAX, IMAX ) ) )
               END IF
<span class="comment">*</span><span class="comment">
</span>               IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">                 no interchange, use 1-by-1 pivot block
</span><span class="comment">*</span><span class="comment">
</span>                  KP = K
               ELSE IF( ABS( REAL( A( IMAX, IMAX ) ) ).GE.ALPHA*ROWMAX )
     $                   THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">                 interchange rows and columns K and IMAX, use 1-by-1
</span><span class="comment">*</span><span class="comment">                 pivot block
</span><span class="comment">*</span><span class="comment">
</span>                  KP = IMAX
               ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">                 interchange rows and columns K-1 and IMAX, use 2-by-2
</span><span class="comment">*</span><span class="comment">                 pivot block
</span><span class="comment">*</span><span class="comment">
</span>                  KP = IMAX
                  KSTEP = 2
               END IF
            END IF
<span class="comment">*</span><span class="comment">
</span>            KK = K - KSTEP + 1
            IF( KP.NE.KK ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Interchange rows and columns KK and KP in the leading
</span><span class="comment">*</span><span class="comment">              submatrix A(1:k,1:k)
</span><span class="comment">*</span><span class="comment">
</span>               CALL CSWAP( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 )
               DO 20 J = KP + 1, KK - 1
                  T = CONJG( A( J, KK ) )
                  A( J, KK ) = CONJG( A( KP, J ) )
                  A( KP, J ) = T
   20          CONTINUE
               A( KP, KK ) = CONJG( A( KP, KK ) )
               R1 = REAL( A( KK, KK ) )
               A( KK, KK ) = REAL( A( KP, KP ) )
               A( KP, KP ) = R1
               IF( KSTEP.EQ.2 ) THEN
                  A( K, K ) = REAL( A( K, K ) )
                  T = A( K-1, K )
                  A( K-1, K ) = A( KP, K )
                  A( KP, K ) = T
               END IF
            ELSE
               A( K, K ) = REAL( A( K, K ) )
               IF( KSTEP.EQ.2 )
     $            A( K-1, K-1 ) = REAL( A( K-1, K-1 ) )
            END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Update the leading submatrix
</span><span class="comment">*</span><span class="comment">
</span>            IF( KSTEP.EQ.1 ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              1-by-1 pivot block D(k): column k now holds
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              W(k) = U(k)*D(k)
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              where U(k) is the k-th column of U
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Perform a rank-1 update of A(1:k-1,1:k-1) as
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              A := A - U(k)*D(k)*U(k)' = A - W(k)*1/D(k)*W(k)'
</span><span class="comment">*</span><span class="comment">
</span>               R1 = ONE / REAL( A( K, K ) )
               CALL CHER( UPLO, K-1, -R1, A( 1, K ), 1, A, LDA )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Store U(k) in column k
</span><span class="comment">*</span><span class="comment">
</span>               CALL CSSCAL( K-1, R1, A( 1, K ), 1 )
            ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              2-by-2 pivot block D(k): columns k and k-1 now hold
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k)
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              where U(k) and U(k-1) are the k-th and (k-1)-th columns
</span><span class="comment">*</span><span class="comment">              of U
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Perform a rank-2 update of A(1:k-2,1:k-2) as
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )'
</span><span class="comment">*</span><span class="comment">                 = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )'
</span><span class="comment">*</span><span class="comment">
</span>               IF( K.GT.2 ) THEN
<span class="comment">*</span><span class="comment">
</span>                  D = <a name="SLAPY2.322"></a><a href="slapy2.f.html#SLAPY2.1">SLAPY2</a>( REAL( A( K-1, K ) ),
     $                AIMAG( A( K-1, K ) ) )
                  D22 = REAL( A( K-1, K-1 ) ) / D
                  D11 = REAL( A( K, K ) ) / D
                  TT = ONE / ( D11*D22-ONE )
                  D12 = A( K-1, K ) / D
                  D = TT / D
<span class="comment">*</span><span class="comment">
</span>                  DO 40 J = K - 2, 1, -1
                     WKM1 = D*( D11*A( J, K-1 )-CONJG( D12 )*A( J, K ) )
                     WK = D*( D22*A( J, K )-D12*A( J, K-1 ) )
                     DO 30 I = J, 1, -1
                        A( I, J ) = A( I, J ) - A( I, K )*CONJG( WK ) -
     $                              A( I, K-1 )*CONJG( WKM1 )
   30                CONTINUE
                     A( J, K ) = WK
                     A( J, K-1 ) = WKM1
                     A( J, J ) = CMPLX( REAL( A( J, J ) ), 0.0E+0 )
   40             CONTINUE
<span class="comment">*</span><span class="comment">
</span>               END IF
<span class="comment">*</span><span class="comment">
</span>            END IF
         END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Store details of the interchanges in IPIV
</span><span class="comment">*</span><span class="comment">
</span>         IF( KSTEP.EQ.1 ) THEN
            IPIV( K ) = KP
         ELSE
            IPIV( K ) = -KP
            IPIV( K-1 ) = -KP
         END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Decrease K and return to the start of the main loop
</span><span class="comment">*</span><span class="comment">
</span>         K = K - KSTEP
         GO TO 10
<span class="comment">*</span><span class="comment">
</span>      ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Factorize A as L*D*L' using the lower triangle of A
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        K is the main loop index, increasing from 1 to N in steps of

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?