LAPACK  3.4.1
LAPACK: Linear Algebra PACKage
chetri.f
Go to the documentation of this file.
00001 *> \brief \b CHETRI
00002 *
00003 *  =========== DOCUMENTATION ===========
00004 *
00005 * Online html documentation available at 
00006 *            http://www.netlib.org/lapack/explore-html/ 
00007 *
00008 *> \htmlonly
00009 *> Download CHETRI + dependencies 
00010 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chetri.f"> 
00011 *> [TGZ]</a> 
00012 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetri.f"> 
00013 *> [ZIP]</a> 
00014 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetri.f"> 
00015 *> [TXT]</a>
00016 *> \endhtmlonly 
00017 *
00018 *  Definition:
00019 *  ===========
00020 *
00021 *       SUBROUTINE CHETRI( UPLO, N, A, LDA, IPIV, WORK, INFO )
00022 * 
00023 *       .. Scalar Arguments ..
00024 *       CHARACTER          UPLO
00025 *       INTEGER            INFO, LDA, N
00026 *       ..
00027 *       .. Array Arguments ..
00028 *       INTEGER            IPIV( * )
00029 *       COMPLEX            A( LDA, * ), WORK( * )
00030 *       ..
00031 *  
00032 *
00033 *> \par Purpose:
00034 *  =============
00035 *>
00036 *> \verbatim
00037 *>
00038 *> CHETRI computes the inverse of a complex Hermitian indefinite matrix
00039 *> A using the factorization A = U*D*U**H or A = L*D*L**H computed by
00040 *> CHETRF.
00041 *> \endverbatim
00042 *
00043 *  Arguments:
00044 *  ==========
00045 *
00046 *> \param[in] UPLO
00047 *> \verbatim
00048 *>          UPLO is CHARACTER*1
00049 *>          Specifies whether the details of the factorization are stored
00050 *>          as an upper or lower triangular matrix.
00051 *>          = 'U':  Upper triangular, form is A = U*D*U**H;
00052 *>          = 'L':  Lower triangular, form is A = L*D*L**H.
00053 *> \endverbatim
00054 *>
00055 *> \param[in] N
00056 *> \verbatim
00057 *>          N is INTEGER
00058 *>          The order of the matrix A.  N >= 0.
00059 *> \endverbatim
00060 *>
00061 *> \param[in,out] A
00062 *> \verbatim
00063 *>          A is COMPLEX array, dimension (LDA,N)
00064 *>          On entry, the block diagonal matrix D and the multipliers
00065 *>          used to obtain the factor U or L as computed by CHETRF.
00066 *>
00067 *>          On exit, if INFO = 0, the (Hermitian) inverse of the original
00068 *>          matrix.  If UPLO = 'U', the upper triangular part of the
00069 *>          inverse is formed and the part of A below the diagonal is not
00070 *>          referenced; if UPLO = 'L' the lower triangular part of the
00071 *>          inverse is formed and the part of A above the diagonal is
00072 *>          not referenced.
00073 *> \endverbatim
00074 *>
00075 *> \param[in] LDA
00076 *> \verbatim
00077 *>          LDA is INTEGER
00078 *>          The leading dimension of the array A.  LDA >= max(1,N).
00079 *> \endverbatim
00080 *>
00081 *> \param[in] IPIV
00082 *> \verbatim
00083 *>          IPIV is INTEGER array, dimension (N)
00084 *>          Details of the interchanges and the block structure of D
00085 *>          as determined by CHETRF.
00086 *> \endverbatim
00087 *>
00088 *> \param[out] WORK
00089 *> \verbatim
00090 *>          WORK is COMPLEX array, dimension (N)
00091 *> \endverbatim
00092 *>
00093 *> \param[out] INFO
00094 *> \verbatim
00095 *>          INFO is INTEGER
00096 *>          = 0: successful exit
00097 *>          < 0: if INFO = -i, the i-th argument had an illegal value
00098 *>          > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its
00099 *>               inverse could not be computed.
00100 *> \endverbatim
00101 *
00102 *  Authors:
00103 *  ========
00104 *
00105 *> \author Univ. of Tennessee 
00106 *> \author Univ. of California Berkeley 
00107 *> \author Univ. of Colorado Denver 
00108 *> \author NAG Ltd. 
00109 *
00110 *> \date November 2011
00111 *
00112 *> \ingroup complexHEcomputational
00113 *
00114 *  =====================================================================
00115       SUBROUTINE CHETRI( UPLO, N, A, LDA, IPIV, WORK, INFO )
00116 *
00117 *  -- LAPACK computational routine (version 3.4.0) --
00118 *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
00119 *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
00120 *     November 2011
00121 *
00122 *     .. Scalar Arguments ..
00123       CHARACTER          UPLO
00124       INTEGER            INFO, LDA, N
00125 *     ..
00126 *     .. Array Arguments ..
00127       INTEGER            IPIV( * )
00128       COMPLEX            A( LDA, * ), WORK( * )
00129 *     ..
00130 *
00131 *  =====================================================================
00132 *
00133 *     .. Parameters ..
00134       REAL               ONE
00135       COMPLEX            CONE, ZERO
00136       PARAMETER          ( ONE = 1.0E+0, CONE = ( 1.0E+0, 0.0E+0 ),
00137      $                   ZERO = ( 0.0E+0, 0.0E+0 ) )
00138 *     ..
00139 *     .. Local Scalars ..
00140       LOGICAL            UPPER
00141       INTEGER            J, K, KP, KSTEP
00142       REAL               AK, AKP1, D, T
00143       COMPLEX            AKKP1, TEMP
00144 *     ..
00145 *     .. External Functions ..
00146       LOGICAL            LSAME
00147       COMPLEX            CDOTC
00148       EXTERNAL           LSAME, CDOTC
00149 *     ..
00150 *     .. External Subroutines ..
00151       EXTERNAL           CCOPY, CHEMV, CSWAP, XERBLA
00152 *     ..
00153 *     .. Intrinsic Functions ..
00154       INTRINSIC          ABS, CONJG, MAX, REAL
00155 *     ..
00156 *     .. Executable Statements ..
00157 *
00158 *     Test the input parameters.
00159 *
00160       INFO = 0
00161       UPPER = LSAME( UPLO, 'U' )
00162       IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
00163          INFO = -1
00164       ELSE IF( N.LT.0 ) THEN
00165          INFO = -2
00166       ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
00167          INFO = -4
00168       END IF
00169       IF( INFO.NE.0 ) THEN
00170          CALL XERBLA( 'CHETRI', -INFO )
00171          RETURN
00172       END IF
00173 *
00174 *     Quick return if possible
00175 *
00176       IF( N.EQ.0 )
00177      $   RETURN
00178 *
00179 *     Check that the diagonal matrix D is nonsingular.
00180 *
00181       IF( UPPER ) THEN
00182 *
00183 *        Upper triangular storage: examine D from bottom to top
00184 *
00185          DO 10 INFO = N, 1, -1
00186             IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.ZERO )
00187      $         RETURN
00188    10    CONTINUE
00189       ELSE
00190 *
00191 *        Lower triangular storage: examine D from top to bottom.
00192 *
00193          DO 20 INFO = 1, N
00194             IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.ZERO )
00195      $         RETURN
00196    20    CONTINUE
00197       END IF
00198       INFO = 0
00199 *
00200       IF( UPPER ) THEN
00201 *
00202 *        Compute inv(A) from the factorization A = U*D*U**H.
00203 *
00204 *        K is the main loop index, increasing from 1 to N in steps of
00205 *        1 or 2, depending on the size of the diagonal blocks.
00206 *
00207          K = 1
00208    30    CONTINUE
00209 *
00210 *        If K > N, exit from loop.
00211 *
00212          IF( K.GT.N )
00213      $      GO TO 50
00214 *
00215          IF( IPIV( K ).GT.0 ) THEN
00216 *
00217 *           1 x 1 diagonal block
00218 *
00219 *           Invert the diagonal block.
00220 *
00221             A( K, K ) = ONE / REAL( A( K, K ) )
00222 *
00223 *           Compute column K of the inverse.
00224 *
00225             IF( K.GT.1 ) THEN
00226                CALL CCOPY( K-1, A( 1, K ), 1, WORK, 1 )
00227                CALL CHEMV( UPLO, K-1, -CONE, A, LDA, WORK, 1, ZERO,
00228      $                     A( 1, K ), 1 )
00229                A( K, K ) = A( K, K ) - REAL( CDOTC( K-1, WORK, 1, A( 1,
     $                     K ), 1 ) )
00230             END IF
00231             KSTEP = 1
00232          ELSE
00233 *
00234 *           2 x 2 diagonal block
00235 *
00236 *           Invert the diagonal block.
00237 *
00238             T = ABS( A( K, K+1 ) )
00239             AK = REAL( A( K, K ) ) / T
00240             AKP1 = REAL( A( K+1, K+1 ) ) / T
00241             AKKP1 = A( K, K+1 ) / T
00242             D = T*( AK*AKP1-ONE )
00243             A( K, K ) = AKP1 / D
00244             A( K+1, K+1 ) = AK / D
00245             A( K, K+1 ) = -AKKP1 / D
00246 *
00247 *           Compute columns K and K+1 of the inverse.
00248 *
00249             IF( K.GT.1 ) THEN
00250                CALL CCOPY( K-1, A( 1, K ), 1, WORK, 1 )
00251                CALL CHEMV( UPLO, K-1, -CONE, A, LDA, WORK, 1, ZERO,
00252      $                     A( 1, K ), 1 )
00253                A( K, K ) = A( K, K ) - REAL( CDOTC( K-1, WORK, 1, A( 1,
     $                     K ), 1 ) )
00254                A( K, K+1 ) = A( K, K+1 ) -
00255      $                       CDOTC( K-1, A( 1, K ), 1, A( 1, K+1 ), 1 )
00256                CALL CCOPY( K-1, A( 1, K+1 ), 1, WORK, 1 )
00257                CALL CHEMV( UPLO, K-1, -CONE, A, LDA, WORK, 1, ZERO,
00258      $                     A( 1, K+1 ), 1 )
00259                A( K+1, K+1 ) = A( K+1, K+1 ) -
00260      $                         REAL( CDOTC( K-1, WORK, 1, A( 1, K+1 ),
     $                         1 ) )
00261             END IF
00262             KSTEP = 2
00263          END IF
00264 *
00265          KP = ABS( IPIV( K ) )
00266          IF( KP.NE.K ) THEN
00267 *
00268 *           Interchange rows and columns K and KP in the leading
00269 *           submatrix A(1:k+1,1:k+1)
00270 *
00271             CALL CSWAP( KP-1, A( 1, K ), 1, A( 1, KP ), 1 )
00272             DO 40 J = KP + 1, K - 1
00273                TEMP = CONJG( A( J, K ) )
00274                A( J, K ) = CONJG( A( KP, J ) )
00275                A( KP, J ) = TEMP
00276    40       CONTINUE
00277             A( KP, K ) = CONJG( A( KP, K ) )
00278             TEMP = A( K, K )
00279             A( K, K ) = A( KP, KP )
00280             A( KP, KP ) = TEMP
00281             IF( KSTEP.EQ.2 ) THEN
00282                TEMP = A( K, K+1 )
00283                A( K, K+1 ) = A( KP, K+1 )
00284                A( KP, K+1 ) = TEMP
00285             END IF
00286          END IF
00287 *
00288          K = K + KSTEP
00289          GO TO 30
00290    50    CONTINUE
00291 *
00292       ELSE
00293 *
00294 *        Compute inv(A) from the factorization A = L*D*L**H.
00295 *
00296 *        K is the main loop index, increasing from 1 to N in steps of
00297 *        1 or 2, depending on the size of the diagonal blocks.
00298 *
00299          K = N
00300    60    CONTINUE
00301 *
00302 *        If K < 1, exit from loop.
00303 *
00304          IF( K.LT.1 )
00305      $      GO TO 80
00306 *
00307          IF( IPIV( K ).GT.0 ) THEN
00308 *
00309 *           1 x 1 diagonal block
00310 *
00311 *           Invert the diagonal block.
00312 *
00313             A( K, K ) = ONE / REAL( A( K, K ) )
00314 *
00315 *           Compute column K of the inverse.
00316 *
00317             IF( K.LT.N ) THEN
00318                CALL CCOPY( N-K, A( K+1, K ), 1, WORK, 1 )
00319                CALL CHEMV( UPLO, N-K, -CONE, A( K+1, K+1 ), LDA, WORK,
00320      $                     1, ZERO, A( K+1, K ), 1 )
00321                A( K, K ) = A( K, K ) - REAL( CDOTC( N-K, WORK, 1,
     $                     A( K+1, K ), 1 ) )
00322             END IF
00323             KSTEP = 1
00324          ELSE
00325 *
00326 *           2 x 2 diagonal block
00327 *
00328 *           Invert the diagonal block.
00329 *
00330             T = ABS( A( K, K-1 ) )
00331             AK = REAL( A( K-1, K-1 ) ) / T
00332             AKP1 = REAL( A( K, K ) ) / T
00333             AKKP1 = A( K, K-1 ) / T
00334             D = T*( AK*AKP1-ONE )
00335             A( K-1, K-1 ) = AKP1 / D
00336             A( K, K ) = AK / D
00337             A( K, K-1 ) = -AKKP1 / D
00338 *
00339 *           Compute columns K-1 and K of the inverse.
00340 *
00341             IF( K.LT.N ) THEN
00342                CALL CCOPY( N-K, A( K+1, K ), 1, WORK, 1 )
00343                CALL CHEMV( UPLO, N-K, -CONE, A( K+1, K+1 ), LDA, WORK,
00344      $                     1, ZERO, A( K+1, K ), 1 )
00345                A( K, K ) = A( K, K ) - REAL( CDOTC( N-K, WORK, 1,
     $                     A( K+1, K ), 1 ) )
00346                A( K, K-1 ) = A( K, K-1 ) -
00347      $                       CDOTC( N-K, A( K+1, K ), 1, A( K+1, K-1 ),
00348      $                       1 )
00349                CALL CCOPY( N-K, A( K+1, K-1 ), 1, WORK, 1 )
00350                CALL CHEMV( UPLO, N-K, -CONE, A( K+1, K+1 ), LDA, WORK,
00351      $                     1, ZERO, A( K+1, K-1 ), 1 )
00352                A( K-1, K-1 ) = A( K-1, K-1 ) -
00353      $                         REAL( CDOTC( N-K, WORK, 1, A( K+1, K-1 ),
     $                         1 ) )
00354             END IF
00355             KSTEP = 2
00356          END IF
00357 *
00358          KP = ABS( IPIV( K ) )
00359          IF( KP.NE.K ) THEN
00360 *
00361 *           Interchange rows and columns K and KP in the trailing
00362 *           submatrix A(k-1:n,k-1:n)
00363 *
00364             IF( KP.LT.N )
00365      $         CALL CSWAP( N-KP, A( KP+1, K ), 1, A( KP+1, KP ), 1 )
00366             DO 70 J = K + 1, KP - 1
00367                TEMP = CONJG( A( J, K ) )
00368                A( J, K ) = CONJG( A( KP, J ) )
00369                A( KP, J ) = TEMP
00370    70       CONTINUE
00371             A( KP, K ) = CONJG( A( KP, K ) )
00372             TEMP = A( K, K )
00373             A( K, K ) = A( KP, KP )
00374             A( KP, KP ) = TEMP
00375             IF( KSTEP.EQ.2 ) THEN
00376                TEMP = A( K, K-1 )
00377                A( K, K-1 ) = A( KP, K-1 )
00378                A( KP, K-1 ) = TEMP
00379             END IF
00380          END IF
00381 *
00382          K = K - KSTEP
00383          GO TO 60
00384    80    CONTINUE
00385       END IF
00386 *
00387       RETURN
00388 *
00389 *     End of CHETRI
00390 *
00391       END
00392 
 All Files Functions