Blame thirdparty/openblas/xianyi-OpenBLAS-e6e87a2/lapack/getri/dgetri.f

kusano 2b45e8
      SUBROUTINE DGETRI( N, A, LDA, IPIV, WORK, LWORK, INFO )
kusano 2b45e8
*
kusano 2b45e8
*  -- LAPACK routine (version 3.0) --
kusano 2b45e8
*     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
kusano 2b45e8
*     Courant Institute, Argonne National Lab, and Rice University
kusano 2b45e8
*     June 30, 1999
kusano 2b45e8
*
kusano 2b45e8
*     .. Scalar Arguments ..
kusano 2b45e8
      INTEGER            INFO, LDA, LWORK, N
kusano 2b45e8
*     ..
kusano 2b45e8
*     .. Array Arguments ..
kusano 2b45e8
      INTEGER            IPIV( * )
kusano 2b45e8
      DOUBLE PRECISION   A( LDA, * ), WORK( * )
kusano 2b45e8
*     ..
kusano 2b45e8
*
kusano 2b45e8
*  Purpose
kusano 2b45e8
*  =======
kusano 2b45e8
*
kusano 2b45e8
*  DGETRI computes the inverse of a matrix using the LU factorization
kusano 2b45e8
*  computed by DGETRF.
kusano 2b45e8
*
kusano 2b45e8
*  This method inverts U and then computes inv(A) by solving the system
kusano 2b45e8
*  inv(A)*L = inv(U) for inv(A).
kusano 2b45e8
*
kusano 2b45e8
*  Arguments
kusano 2b45e8
*  =========
kusano 2b45e8
*
kusano 2b45e8
*  N       (input) INTEGER
kusano 2b45e8
*          The order of the matrix A.  N >= 0.
kusano 2b45e8
*
kusano 2b45e8
*  A       (input/output) DOUBLE PRECISION array, dimension (LDA,N)
kusano 2b45e8
*          On entry, the factors L and U from the factorization
kusano 2b45e8
*          A = P*L*U as computed by DGETRF.
kusano 2b45e8
*          On exit, if INFO = 0, the inverse of the original matrix A.
kusano 2b45e8
*
kusano 2b45e8
*  LDA     (input) INTEGER
kusano 2b45e8
*          The leading dimension of the array A.  LDA >= max(1,N).
kusano 2b45e8
*
kusano 2b45e8
*  IPIV    (input) INTEGER array, dimension (N)
kusano 2b45e8
*          The pivot indices from DGETRF; for 1<=i<=N, row i of the
kusano 2b45e8
*          matrix was interchanged with row IPIV(i).
kusano 2b45e8
*
kusano 2b45e8
*  WORK    (workspace/output) DOUBLE PRECISION array, dimension (LWORK)
kusano 2b45e8
*          On exit, if INFO=0, then WORK(1) returns the optimal LWORK.
kusano 2b45e8
*
kusano 2b45e8
*  LWORK   (input) INTEGER
kusano 2b45e8
*          The dimension of the array WORK.  LWORK >= max(1,N).
kusano 2b45e8
*          For optimal performance LWORK >= N*NB, where NB is
kusano 2b45e8
*          the optimal blocksize returned by ILAENV.
kusano 2b45e8
*
kusano 2b45e8
*          If LWORK = -1, then a workspace query is assumed; the routine
kusano 2b45e8
*          only calculates the optimal size of the WORK array, returns
kusano 2b45e8
*          this value as the first entry of the WORK array, and no error
kusano 2b45e8
*          message related to LWORK is issued by XERBLA.
kusano 2b45e8
*
kusano 2b45e8
*  INFO    (output) INTEGER
kusano 2b45e8
*          = 0:  successful exit
kusano 2b45e8
*          < 0:  if INFO = -i, the i-th argument had an illegal value
kusano 2b45e8
*          > 0:  if INFO = i, U(i,i) is exactly zero; the matrix is
kusano 2b45e8
*                singular and its inverse could not be computed.
kusano 2b45e8
*
kusano 2b45e8
*  =====================================================================
kusano 2b45e8
*
kusano 2b45e8
*     .. Parameters ..
kusano 2b45e8
      DOUBLE PRECISION   ZERO, ONE
kusano 2b45e8
      PARAMETER          ( ZERO = 0.0D+0, ONE = 1.0D+0 )
kusano 2b45e8
*     ..
kusano 2b45e8
*     .. Local Scalars ..
kusano 2b45e8
      LOGICAL            LQUERY
kusano 2b45e8
      INTEGER            I, IWS, J, JB, JJ, JP, LDWORK, LWKOPT, NB,
kusano 2b45e8
     $                   NBMIN, NN
kusano 2b45e8
*     ..
kusano 2b45e8
*     .. External Functions ..
kusano 2b45e8
      INTEGER            ILAENV
kusano 2b45e8
      EXTERNAL           ILAENV
kusano 2b45e8
*     ..
kusano 2b45e8
*     .. External Subroutines ..
kusano 2b45e8
      EXTERNAL           DGEMM, DGEMV, DSWAP, DTRSM, DTRTRI, XERBLA
kusano 2b45e8
*     ..
kusano 2b45e8
*     .. Intrinsic Functions ..
kusano 2b45e8
      INTRINSIC          MAX, MIN
kusano 2b45e8
*     ..
kusano 2b45e8
*     .. Executable Statements ..
kusano 2b45e8
*
kusano 2b45e8
*     Test the input parameters.
kusano 2b45e8
*
kusano 2b45e8
      INFO = 0
kusano 2b45e8
      NB = ILAENV( 1, 'DGETRI', ' ', N, -1, -1, -1 )
kusano 2b45e8
      LWKOPT = N*NB
kusano 2b45e8
      WORK( 1 ) = LWKOPT
kusano 2b45e8
      LQUERY = ( LWORK.EQ.-1 )
kusano 2b45e8
      IF( N.LT.0 ) THEN
kusano 2b45e8
         INFO = -1
kusano 2b45e8
      ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
kusano 2b45e8
         INFO = -3
kusano 2b45e8
      ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
kusano 2b45e8
         INFO = -6
kusano 2b45e8
      END IF
kusano 2b45e8
      IF( INFO.NE.0 ) THEN
kusano 2b45e8
         CALL XERBLA( 'DGETRI', -INFO )
kusano 2b45e8
         RETURN
kusano 2b45e8
      ELSE IF( LQUERY ) THEN
kusano 2b45e8
         RETURN
kusano 2b45e8
      END IF
kusano 2b45e8
*
kusano 2b45e8
*     Quick return if possible
kusano 2b45e8
*
kusano 2b45e8
      IF( N.EQ.0 )
kusano 2b45e8
     $   RETURN
kusano 2b45e8
*
kusano 2b45e8
*     Form inv(U).  If INFO > 0 from DTRTRI, then U is singular,
kusano 2b45e8
*     and the inverse is not computed.
kusano 2b45e8
*
kusano 2b45e8
      CALL DTRTRI( 'Upper', 'Non-unit', N, A, LDA, INFO )
kusano 2b45e8
      IF( INFO.GT.0 )
kusano 2b45e8
     $   RETURN
kusano 2b45e8
*
kusano 2b45e8
      NBMIN = 2
kusano 2b45e8
      LDWORK = N
kusano 2b45e8
      IF( NB.GT.1 .AND. NB.LT.N ) THEN
kusano 2b45e8
         IWS = MAX( LDWORK*NB, 1 )
kusano 2b45e8
         IF( LWORK.LT.IWS ) THEN
kusano 2b45e8
            NB = LWORK / LDWORK
kusano 2b45e8
            NBMIN = MAX( 2, ILAENV( 2, 'DGETRI', ' ', N, -1, -1, -1 ) )
kusano 2b45e8
         END IF
kusano 2b45e8
      ELSE
kusano 2b45e8
         IWS = N
kusano 2b45e8
      END IF
kusano 2b45e8
*
kusano 2b45e8
*     Solve the equation inv(A)*L = inv(U) for inv(A).
kusano 2b45e8
*
kusano 2b45e8
      IF( NB.LT.NBMIN .OR. NB.GE.N ) THEN
kusano 2b45e8
*
kusano 2b45e8
*        Use unblocked code.
kusano 2b45e8
*
kusano 2b45e8
         DO 20 J = N, 1, -1
kusano 2b45e8
*
kusano 2b45e8
*           Copy current column of L to WORK and replace with zeros.
kusano 2b45e8
*
kusano 2b45e8
            DO 10 I = J + 1, N
kusano 2b45e8
               WORK( I ) = A( I, J )
kusano 2b45e8
               A( I, J ) = ZERO
kusano 2b45e8
   10       CONTINUE
kusano 2b45e8
*
kusano 2b45e8
*           Compute current column of inv(A).
kusano 2b45e8
*
kusano 2b45e8
            IF( J.LT.N )
kusano 2b45e8
     $         CALL DGEMV( 'No transpose', N, N-J, -ONE, A( 1, J+1 ),
kusano 2b45e8
     $                     LDA, WORK( J+1 ), 1, ONE, A( 1, J ), 1 )
kusano 2b45e8
   20    CONTINUE
kusano 2b45e8
      ELSE
kusano 2b45e8
*
kusano 2b45e8
*        Use blocked code.
kusano 2b45e8
*
kusano 2b45e8
         NN = ( ( N-1 ) / NB )*NB + 1
kusano 2b45e8
         DO 50 J = NN, 1, -NB
kusano 2b45e8
            JB = MIN( NB, N-J+1 )
kusano 2b45e8
*
kusano 2b45e8
*           Copy current block column of L to WORK and replace with
kusano 2b45e8
*           zeros.
kusano 2b45e8
*
kusano 2b45e8
            DO 40 JJ = J, J + JB - 1
kusano 2b45e8
               DO 30 I = JJ + 1, N
kusano 2b45e8
                  WORK( I+( JJ-J )*LDWORK ) = A( I, JJ )
kusano 2b45e8
                  A( I, JJ ) = ZERO
kusano 2b45e8
   30          CONTINUE
kusano 2b45e8
   40       CONTINUE
kusano 2b45e8
*
kusano 2b45e8
*           Compute current block column of inv(A).
kusano 2b45e8
*
kusano 2b45e8
            IF( J+JB.LE.N )
kusano 2b45e8
     $         CALL DGEMM( 'No transpose', 'No transpose', N, JB,
kusano 2b45e8
     $                     N-J-JB+1, -ONE, A( 1, J+JB ), LDA,
kusano 2b45e8
     $                     WORK( J+JB ), LDWORK, ONE, A( 1, J ), LDA )
kusano 2b45e8
            CALL DTRSM( 'Right', 'Lower', 'No transpose', 'Unit', N, JB,
kusano 2b45e8
     $                  ONE, WORK( J ), LDWORK, A( 1, J ), LDA )
kusano 2b45e8
   50    CONTINUE
kusano 2b45e8
      END IF
kusano 2b45e8
*
kusano 2b45e8
*     Apply column interchanges.
kusano 2b45e8
*
kusano 2b45e8
      DO 60 J = N - 1, 1, -1
kusano 2b45e8
         JP = IPIV( J )
kusano 2b45e8
         IF( JP.NE.J )
kusano 2b45e8
     $      CALL DSWAP( N, A( 1, J ), 1, A( 1, JP ), 1 )
kusano 2b45e8
   60 CONTINUE
kusano 2b45e8
*
kusano 2b45e8
      WORK( 1 ) = IWS
kusano 2b45e8
      RETURN
kusano 2b45e8
*
kusano 2b45e8
*     End of DGETRI
kusano 2b45e8
*
kusano 2b45e8
      END