3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CHPTRI + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chptri.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chptri.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chptri.f">
21 * SUBROUTINE CHPTRI( UPLO, N, AP, IPIV, WORK, INFO )
23 * .. Scalar Arguments ..
27 * .. Array Arguments ..
29 * COMPLEX AP( * ), WORK( * )
38 *> CHPTRI computes the inverse of a complex Hermitian indefinite matrix
39 *> A in packed storage using the factorization A = U*D*U**H or
40 *> A = L*D*L**H computed by CHPTRF.
48 *> UPLO is CHARACTER*1
49 *> Specifies whether the details of the factorization are stored
50 *> as an upper or lower triangular matrix.
51 *> = 'U': Upper triangular, form is A = U*D*U**H;
52 *> = 'L': Lower triangular, form is A = L*D*L**H.
58 *> The order of the matrix A. N >= 0.
63 *> AP is COMPLEX array, dimension (N*(N+1)/2)
64 *> On entry, the block diagonal matrix D and the multipliers
65 *> used to obtain the factor U or L as computed by CHPTRF,
66 *> stored as a packed triangular matrix.
68 *> On exit, if INFO = 0, the (Hermitian) inverse of the original
69 *> matrix, stored as a packed triangular matrix. The j-th column
70 *> of inv(A) is stored in the array AP as follows:
71 *> if UPLO = 'U', AP(i + (j-1)*j/2) = inv(A)(i,j) for 1<=i<=j;
73 *> AP(i + (j-1)*(2n-j)/2) = inv(A)(i,j) for j<=i<=n.
78 *> IPIV is INTEGER array, dimension (N)
79 *> Details of the interchanges and the block structure of D
80 *> as determined by CHPTRF.
85 *> WORK is COMPLEX array, dimension (N)
91 *> = 0: successful exit
92 *> < 0: if INFO = -i, the i-th argument had an illegal value
93 *> > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its
94 *> inverse could not be computed.
100 *> \author Univ. of Tennessee
101 *> \author Univ. of California Berkeley
102 *> \author Univ. of Colorado Denver
105 *> \date November 2011
107 *> \ingroup complexOTHERcomputational
109 * =====================================================================
110 SUBROUTINE CHPTRI( UPLO, N, AP, IPIV, WORK, INFO )
112 * -- LAPACK computational routine (version 3.4.0) --
113 * -- LAPACK is a software package provided by Univ. of Tennessee, --
114 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
117 * .. Scalar Arguments ..
121 * .. Array Arguments ..
123 COMPLEX AP( * ), WORK( * )
126 * =====================================================================
131 PARAMETER ( ONE = 1.0E+0, CONE = ( 1.0E+0, 0.0E+0 ),
132 $ ZERO = ( 0.0E+0, 0.0E+0 ) )
134 * .. Local Scalars ..
136 INTEGER J, K, KC, KCNEXT, KP, KPC, KSTEP, KX, NPP
140 * .. External Functions ..
143 EXTERNAL LSAME, CDOTC
145 * .. External Subroutines ..
146 EXTERNAL CCOPY, CHPMV, CSWAP, XERBLA
148 * .. Intrinsic Functions ..
149 INTRINSIC ABS, CONJG, REAL
151 * .. Executable Statements ..
153 * Test the input parameters.
156 UPPER = LSAME( UPLO, 'U' )
157 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
159 ELSE IF( N.LT.0 ) THEN
163 CALL XERBLA( 'CHPTRI', -INFO )
167 * Quick return if possible
172 * Check that the diagonal matrix D is nonsingular.
176 * Upper triangular storage: examine D from bottom to top
179 DO 10 INFO = N, 1, -1
180 IF( IPIV( INFO ).GT.0 .AND. AP( KP ).EQ.ZERO )
186 * Lower triangular storage: examine D from top to bottom.
190 IF( IPIV( INFO ).GT.0 .AND. AP( KP ).EQ.ZERO )
192 KP = KP + N - INFO + 1
199 * Compute inv(A) from the factorization A = U*D*U**H.
201 * K is the main loop index, increasing from 1 to N in steps of
202 * 1 or 2, depending on the size of the diagonal blocks.
208 * If K > N, exit from loop.
214 IF( IPIV( K ).GT.0 ) THEN
216 * 1 x 1 diagonal block
218 * Invert the diagonal block.
220 AP( KC+K-1 ) = ONE / REAL( AP( KC+K-1 ) )
222 * Compute column K of the inverse.
225 CALL CCOPY( K-1, AP( KC ), 1, WORK, 1 )
226 CALL CHPMV( UPLO, K-1, -CONE, AP, WORK, 1, ZERO,
228 AP( KC+K-1 ) = AP( KC+K-1 ) -
229 $ REAL( CDOTC( K-1, WORK, 1, AP( KC ), 1 ) )
234 * 2 x 2 diagonal block
236 * Invert the diagonal block.
238 T = ABS( AP( KCNEXT+K-1 ) )
239 AK = REAL( AP( KC+K-1 ) ) / T
240 AKP1 = REAL( AP( KCNEXT+K ) ) / T
241 AKKP1 = AP( KCNEXT+K-1 ) / T
242 D = T*( AK*AKP1-ONE )
243 AP( KC+K-1 ) = AKP1 / D
244 AP( KCNEXT+K ) = AK / D
245 AP( KCNEXT+K-1 ) = -AKKP1 / D
247 * Compute columns K and K+1 of the inverse.
250 CALL CCOPY( K-1, AP( KC ), 1, WORK, 1 )
251 CALL CHPMV( UPLO, K-1, -CONE, AP, WORK, 1, ZERO,
253 AP( KC+K-1 ) = AP( KC+K-1 ) -
254 $ REAL( CDOTC( K-1, WORK, 1, AP( KC ), 1 ) )
255 AP( KCNEXT+K-1 ) = AP( KCNEXT+K-1 ) -
256 $ CDOTC( K-1, AP( KC ), 1, AP( KCNEXT ),
258 CALL CCOPY( K-1, AP( KCNEXT ), 1, WORK, 1 )
259 CALL CHPMV( UPLO, K-1, -CONE, AP, WORK, 1, ZERO,
261 AP( KCNEXT+K ) = AP( KCNEXT+K ) -
262 $ REAL( CDOTC( K-1, WORK, 1, AP( KCNEXT ),
266 KCNEXT = KCNEXT + K + 1
269 KP = ABS( IPIV( K ) )
272 * Interchange rows and columns K and KP in the leading
273 * submatrix A(1:k+1,1:k+1)
275 KPC = ( KP-1 )*KP / 2 + 1
276 CALL CSWAP( KP-1, AP( KC ), 1, AP( KPC ), 1 )
278 DO 40 J = KP + 1, K - 1
280 TEMP = CONJG( AP( KC+J-1 ) )
281 AP( KC+J-1 ) = CONJG( AP( KX ) )
284 AP( KC+KP-1 ) = CONJG( AP( KC+KP-1 ) )
286 AP( KC+K-1 ) = AP( KPC+KP-1 )
287 AP( KPC+KP-1 ) = TEMP
288 IF( KSTEP.EQ.2 ) THEN
289 TEMP = AP( KC+K+K-1 )
290 AP( KC+K+K-1 ) = AP( KC+K+KP-1 )
291 AP( KC+K+KP-1 ) = TEMP
302 * Compute inv(A) from the factorization A = L*D*L**H.
304 * K is the main loop index, increasing from 1 to N in steps of
305 * 1 or 2, depending on the size of the diagonal blocks.
312 * If K < 1, exit from loop.
317 KCNEXT = KC - ( N-K+2 )
318 IF( IPIV( K ).GT.0 ) THEN
320 * 1 x 1 diagonal block
322 * Invert the diagonal block.
324 AP( KC ) = ONE / REAL( AP( KC ) )
326 * Compute column K of the inverse.
329 CALL CCOPY( N-K, AP( KC+1 ), 1, WORK, 1 )
330 CALL CHPMV( UPLO, N-K, -CONE, AP( KC+N-K+1 ), WORK, 1,
331 $ ZERO, AP( KC+1 ), 1 )
332 AP( KC ) = AP( KC ) - REAL( CDOTC( N-K, WORK, 1,
338 * 2 x 2 diagonal block
340 * Invert the diagonal block.
342 T = ABS( AP( KCNEXT+1 ) )
343 AK = REAL( AP( KCNEXT ) ) / T
344 AKP1 = REAL( AP( KC ) ) / T
345 AKKP1 = AP( KCNEXT+1 ) / T
346 D = T*( AK*AKP1-ONE )
347 AP( KCNEXT ) = AKP1 / D
349 AP( KCNEXT+1 ) = -AKKP1 / D
351 * Compute columns K-1 and K of the inverse.
354 CALL CCOPY( N-K, AP( KC+1 ), 1, WORK, 1 )
355 CALL CHPMV( UPLO, N-K, -CONE, AP( KC+( N-K+1 ) ), WORK,
356 $ 1, ZERO, AP( KC+1 ), 1 )
357 AP( KC ) = AP( KC ) - REAL( CDOTC( N-K, WORK, 1,
359 AP( KCNEXT+1 ) = AP( KCNEXT+1 ) -
360 $ CDOTC( N-K, AP( KC+1 ), 1,
361 $ AP( KCNEXT+2 ), 1 )
362 CALL CCOPY( N-K, AP( KCNEXT+2 ), 1, WORK, 1 )
363 CALL CHPMV( UPLO, N-K, -CONE, AP( KC+( N-K+1 ) ), WORK,
364 $ 1, ZERO, AP( KCNEXT+2 ), 1 )
365 AP( KCNEXT ) = AP( KCNEXT ) -
366 $ REAL( CDOTC( N-K, WORK, 1, AP( KCNEXT+2 ),
370 KCNEXT = KCNEXT - ( N-K+3 )
373 KP = ABS( IPIV( K ) )
376 * Interchange rows and columns K and KP in the trailing
377 * submatrix A(k-1:n,k-1:n)
379 KPC = NPP - ( N-KP+1 )*( N-KP+2 ) / 2 + 1
381 $ CALL CSWAP( N-KP, AP( KC+KP-K+1 ), 1, AP( KPC+1 ), 1 )
383 DO 70 J = K + 1, KP - 1
385 TEMP = CONJG( AP( KC+J-K ) )
386 AP( KC+J-K ) = CONJG( AP( KX ) )
389 AP( KC+KP-K ) = CONJG( AP( KC+KP-K ) )
393 IF( KSTEP.EQ.2 ) THEN
394 TEMP = AP( KC-N+K-1 )
395 AP( KC-N+K-1 ) = AP( KC-N+KP-1 )
396 AP( KC-N+KP-1 ) = TEMP