clatrs.f.html

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

HTML
904
字号
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           A is unit triangular.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}.
</span><span class="comment">*</span><span class="comment">
</span>            GROW = MIN( ONE, HALF / MAX( XBND, SMLNUM ) )
            DO 80 J = JFIRST, JLAST, JINC
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Exit the loop if the growth factor is too small.
</span><span class="comment">*</span><span class="comment">
</span>               IF( GROW.LE.SMLNUM )
     $            GO TO 90
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              G(j) = ( 1 + CNORM(j) )*G(j-1)
</span><span class="comment">*</span><span class="comment">
</span>               XJ = ONE + CNORM( J )
               GROW = GROW / XJ
   80       CONTINUE
         END IF
   90    CONTINUE
      END IF
<span class="comment">*</span><span class="comment">
</span>      IF( ( GROW*TSCAL ).GT.SMLNUM ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Use the Level 2 BLAS solve if the reciprocal of the bound on
</span><span class="comment">*</span><span class="comment">        elements of X is not too small.
</span><span class="comment">*</span><span class="comment">
</span>         CALL CTRSV( UPLO, TRANS, DIAG, N, A, LDA, X, 1 )
      ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Use a Level 1 BLAS solve, scaling intermediate results.
</span><span class="comment">*</span><span class="comment">
</span>         IF( XMAX.GT.BIGNUM*HALF ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Scale X so that its components are less than or equal to
</span><span class="comment">*</span><span class="comment">           BIGNUM in absolute value.
</span><span class="comment">*</span><span class="comment">
</span>            SCALE = ( BIGNUM*HALF ) / XMAX
            CALL CSSCAL( N, SCALE, X, 1 )
            XMAX = BIGNUM
         ELSE
            XMAX = XMAX*TWO
         END IF
<span class="comment">*</span><span class="comment">
</span>         IF( NOTRAN ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Solve A * x = b
</span><span class="comment">*</span><span class="comment">
</span>            DO 110 J = JFIRST, JLAST, JINC
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Compute x(j) = b(j) / A(j,j), scaling x if necessary.
</span><span class="comment">*</span><span class="comment">
</span>               XJ = CABS1( X( J ) )
               IF( NOUNIT ) THEN
                  TJJS = A( J, J )*TSCAL
               ELSE
                  TJJS = TSCAL
                  IF( TSCAL.EQ.ONE )
     $               GO TO 105
               END IF
                  TJJ = CABS1( TJJS )
                  IF( TJJ.GT.SMLNUM ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">                    abs(A(j,j)) &gt; SMLNUM:
</span><span class="comment">*</span><span class="comment">
</span>                     IF( TJJ.LT.ONE ) THEN
                        IF( XJ.GT.TJJ*BIGNUM ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">                          Scale x by 1/b(j).
</span><span class="comment">*</span><span class="comment">
</span>                           REC = ONE / XJ
                           CALL CSSCAL( N, REC, X, 1 )
                           SCALE = SCALE*REC
                           XMAX = XMAX*REC
                        END IF
                     END IF
                     X( J ) = <a name="CLADIV.510"></a><a href="cladiv.f.html#CLADIV.1">CLADIV</a>( X( J ), TJJS )
                     XJ = CABS1( X( J ) )
                  ELSE IF( TJJ.GT.ZERO ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">                    0 &lt; abs(A(j,j)) &lt;= SMLNUM:
</span><span class="comment">*</span><span class="comment">
</span>                     IF( XJ.GT.TJJ*BIGNUM ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">                       Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM
</span><span class="comment">*</span><span class="comment">                       to avoid overflow when dividing by A(j,j).
</span><span class="comment">*</span><span class="comment">
</span>                        REC = ( TJJ*BIGNUM ) / XJ
                        IF( CNORM( J ).GT.ONE ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">                          Scale by 1/CNORM(j) to avoid overflow when
</span><span class="comment">*</span><span class="comment">                          multiplying x(j) times column j.
</span><span class="comment">*</span><span class="comment">
</span>                           REC = REC / CNORM( J )
                        END IF
                        CALL CSSCAL( N, REC, X, 1 )
                        SCALE = SCALE*REC
                        XMAX = XMAX*REC
                     END IF
                     X( J ) = <a name="CLADIV.533"></a><a href="cladiv.f.html#CLADIV.1">CLADIV</a>( X( J ), TJJS )
                     XJ = CABS1( X( J ) )
                  ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">                    A(j,j) = 0:  Set x(1:n) = 0, x(j) = 1, and
</span><span class="comment">*</span><span class="comment">                    scale = 0, and compute a solution to A*x = 0.
</span><span class="comment">*</span><span class="comment">
</span>                     DO 100 I = 1, N
                        X( I ) = ZERO
  100                CONTINUE
                     X( J ) = ONE
                     XJ = ONE
                     SCALE = ZERO
                     XMAX = ZERO
                  END IF
  105          CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Scale x if necessary to avoid overflow when adding a
</span><span class="comment">*</span><span class="comment">              multiple of column j of A.
</span><span class="comment">*</span><span class="comment">
</span>               IF( XJ.GT.ONE ) THEN
                  REC = ONE / XJ
                  IF( CNORM( J ).GT.( BIGNUM-XMAX )*REC ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">                    Scale x by 1/(2*abs(x(j))).
</span><span class="comment">*</span><span class="comment">
</span>                     REC = REC*HALF
                     CALL CSSCAL( N, REC, X, 1 )
                     SCALE = SCALE*REC
                  END IF
               ELSE IF( XJ*CNORM( J ).GT.( BIGNUM-XMAX ) ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">                 Scale x by 1/2.
</span><span class="comment">*</span><span class="comment">
</span>                  CALL CSSCAL( N, HALF, X, 1 )
                  SCALE = SCALE*HALF
               END IF
<span class="comment">*</span><span class="comment">
</span>               IF( UPPER ) THEN
                  IF( J.GT.1 ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">                    Compute the update
</span><span class="comment">*</span><span class="comment">                       x(1:j-1) := x(1:j-1) - x(j) * A(1:j-1,j)
</span><span class="comment">*</span><span class="comment">
</span>                     CALL CAXPY( J-1, -X( J )*TSCAL, A( 1, J ), 1, X,
     $                           1 )
                     I = ICAMAX( J-1, X, 1 )
                     XMAX = CABS1( X( I ) )
                  END IF
               ELSE
                  IF( J.LT.N ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">                    Compute the update
</span><span class="comment">*</span><span class="comment">                       x(j+1:n) := x(j+1:n) - x(j) * A(j+1:n,j)
</span><span class="comment">*</span><span class="comment">
</span>                     CALL CAXPY( N-J, -X( J )*TSCAL, A( J+1, J ), 1,
     $                           X( J+1 ), 1 )
                     I = J + ICAMAX( N-J, X( J+1 ), 1 )
                     XMAX = CABS1( X( I ) )
                  END IF
               END IF
  110       CONTINUE
<span class="comment">*</span><span class="comment">
</span>         ELSE IF( <a name="LSAME.596"></a><a href="lsame.f.html#LSAME.1">LSAME</a>( TRANS, <span class="string">'T'</span> ) ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Solve A**T * x = b
</span><span class="comment">*</span><span class="comment">
</span>            DO 150 J = JFIRST, JLAST, JINC
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Compute x(j) = b(j) - sum A(k,j)*x(k).
</span><span class="comment">*</span><span class="comment">                                    k&lt;&gt;j
</span><span class="comment">*</span><span class="comment">
</span>               XJ = CABS1( X( J ) )
               USCAL = TSCAL
               REC = ONE / MAX( XMAX, ONE )
               IF( CNORM( J ).GT.( BIGNUM-XJ )*REC ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">                 If x(j) could overflow, scale x by 1/(2*XMAX).
</span><span class="comment">*</span><span class="comment">
</span>                  REC = REC*HALF
                  IF( NOUNIT ) THEN
                     TJJS = A( J, J )*TSCAL
                  ELSE
                     TJJS = TSCAL
                  END IF
                     TJJ = CABS1( TJJS )
                     IF( TJJ.GT.ONE ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">                       Divide by A(j,j) when scaling x if A(j,j) &gt; 1.
</span><span class="comment">*</span><span class="comment">
</span>                        REC = MIN( ONE, REC*TJJ )
                        USCAL = <a name="CLADIV.624"></a><a href="cladiv.f.html#CLADIV.1">CLADIV</a>( USCAL, TJJS )
                     END IF
                  IF( REC.LT.ONE ) THEN
                     CALL CSSCAL( N, REC, X, 1 )
                     SCALE = SCALE*REC
                     XMAX = XMAX*REC
                  END IF
               END IF
<span class="comment">*</span><span class="comment">
</span>               CSUMJ = ZERO
               IF( USCAL.EQ.CMPLX( ONE ) ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">                 If the scaling needed for A in the dot product is 1,
</span><span class="comment">*</span><span class="comment">                 call CDOTU to perform the dot product.
</span><span class="comment">*</span><span class="comment">
</span>                  IF( UPPER ) THEN
                     CSUMJ = CDOTU( J-1, A( 1, J ), 1, X, 1 )
                  ELSE IF( J.LT.N ) THEN
                     CSUMJ = CDOTU( N-J, A( J+1, J ), 1, X( J+1 ), 1 )
                  END IF
               ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">                 Otherwise, use in-line code for the dot product.
</span><span class="comment">*</span><span class="comment">
</span>                  IF( UPPER ) THEN
                     DO 120 I = 1, J - 1
                        CSUMJ = CSUMJ + ( A( I, J )*USCAL )*X( I )
  120                CONTINUE
                  ELSE IF( J.LT.N ) THEN
                     DO 130 I = J + 1, N
                        CSUMJ = CSUMJ + ( A( I, J )*USCAL )*X( I )
  130                CONTINUE
                  END IF
               END IF
<span class="comment">*</span><span class="comment">
</span>               IF( USCAL.EQ.CMPLX( TSCAL ) ) THEN

⌨️ 快捷键说明

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