3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CSPTRI + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/csptri.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/csptri.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/csptri.f">
21 * SUBROUTINE CSPTRI( UPLO, N, AP, IPIV, WORK, INFO )
23 * .. Scalar Arguments ..
27 * .. Array Arguments ..
29 * COMPLEX AP( * ), WORK( * )
38 *> CSPTRI computes the inverse of a complex symmetric indefinite matrix
39 *> A in packed storage using the factorization A = U*D*U**T or
40 *> A = L*D*L**T computed by CSPTRF.
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**T;
52 *> = 'L': Lower triangular, form is A = L*D*L**T.
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 CSPTRF,
66 *> stored as a packed triangular matrix.
68 *> On exit, if INFO = 0, the (symmetric) 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 CSPTRF.
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 CSPTRI( 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 * =====================================================================
130 PARAMETER ( ONE = ( 1.0E+0, 0.0E+0 ),
131 $ ZERO = ( 0.0E+0, 0.0E+0 ) )
133 * .. Local Scalars ..
135 INTEGER J, K, KC, KCNEXT, KP, KPC, KSTEP, KX, NPP
136 COMPLEX AK, AKKP1, AKP1, D, T, TEMP
138 * .. External Functions ..
141 EXTERNAL LSAME, CDOTU
143 * .. External Subroutines ..
144 EXTERNAL CCOPY, CSPMV, CSWAP, XERBLA
146 * .. Intrinsic Functions ..
149 * .. Executable Statements ..
151 * Test the input parameters.
154 UPPER = LSAME( UPLO, 'U' )
155 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
157 ELSE IF( N.LT.0 ) THEN
161 CALL XERBLA( 'CSPTRI', -INFO )
165 * Quick return if possible
170 * Check that the diagonal matrix D is nonsingular.
174 * Upper triangular storage: examine D from bottom to top
177 DO 10 INFO = N, 1, -1
178 IF( IPIV( INFO ).GT.0 .AND. AP( KP ).EQ.ZERO )
184 * Lower triangular storage: examine D from top to bottom.
188 IF( IPIV( INFO ).GT.0 .AND. AP( KP ).EQ.ZERO )
190 KP = KP + N - INFO + 1
197 * Compute inv(A) from the factorization A = U*D*U**T.
199 * K is the main loop index, increasing from 1 to N in steps of
200 * 1 or 2, depending on the size of the diagonal blocks.
206 * If K > N, exit from loop.
212 IF( IPIV( K ).GT.0 ) THEN
214 * 1 x 1 diagonal block
216 * Invert the diagonal block.
218 AP( KC+K-1 ) = ONE / AP( KC+K-1 )
220 * Compute column K of the inverse.
223 CALL CCOPY( K-1, AP( KC ), 1, WORK, 1 )
224 CALL CSPMV( UPLO, K-1, -ONE, AP, WORK, 1, ZERO, AP( KC ),
226 AP( KC+K-1 ) = AP( KC+K-1 ) -
227 $ CDOTU( K-1, WORK, 1, AP( KC ), 1 )
232 * 2 x 2 diagonal block
234 * Invert the diagonal block.
237 AK = AP( KC+K-1 ) / T
238 AKP1 = AP( KCNEXT+K ) / T
239 AKKP1 = AP( KCNEXT+K-1 ) / T
240 D = T*( AK*AKP1-ONE )
241 AP( KC+K-1 ) = AKP1 / D
242 AP( KCNEXT+K ) = AK / D
243 AP( KCNEXT+K-1 ) = -AKKP1 / D
245 * Compute columns K and K+1 of the inverse.
248 CALL CCOPY( K-1, AP( KC ), 1, WORK, 1 )
249 CALL CSPMV( UPLO, K-1, -ONE, AP, WORK, 1, ZERO, AP( KC ),
251 AP( KC+K-1 ) = AP( KC+K-1 ) -
252 $ CDOTU( K-1, WORK, 1, AP( KC ), 1 )
253 AP( KCNEXT+K-1 ) = AP( KCNEXT+K-1 ) -
254 $ CDOTU( K-1, AP( KC ), 1, AP( KCNEXT ),
256 CALL CCOPY( K-1, AP( KCNEXT ), 1, WORK, 1 )
257 CALL CSPMV( UPLO, K-1, -ONE, AP, WORK, 1, ZERO,
259 AP( KCNEXT+K ) = AP( KCNEXT+K ) -
260 $ CDOTU( K-1, WORK, 1, AP( KCNEXT ), 1 )
263 KCNEXT = KCNEXT + K + 1
266 KP = ABS( IPIV( K ) )
269 * Interchange rows and columns K and KP in the leading
270 * submatrix A(1:k+1,1:k+1)
272 KPC = ( KP-1 )*KP / 2 + 1
273 CALL CSWAP( KP-1, AP( KC ), 1, AP( KPC ), 1 )
275 DO 40 J = KP + 1, K - 1
278 AP( KC+J-1 ) = AP( KX )
282 AP( KC+K-1 ) = AP( KPC+KP-1 )
283 AP( KPC+KP-1 ) = TEMP
284 IF( KSTEP.EQ.2 ) THEN
285 TEMP = AP( KC+K+K-1 )
286 AP( KC+K+K-1 ) = AP( KC+K+KP-1 )
287 AP( KC+K+KP-1 ) = TEMP
298 * Compute inv(A) from the factorization A = L*D*L**T.
300 * K is the main loop index, increasing from 1 to N in steps of
301 * 1 or 2, depending on the size of the diagonal blocks.
308 * If K < 1, exit from loop.
313 KCNEXT = KC - ( N-K+2 )
314 IF( IPIV( K ).GT.0 ) THEN
316 * 1 x 1 diagonal block
318 * Invert the diagonal block.
320 AP( KC ) = ONE / AP( KC )
322 * Compute column K of the inverse.
325 CALL CCOPY( N-K, AP( KC+1 ), 1, WORK, 1 )
326 CALL CSPMV( UPLO, N-K, -ONE, AP( KC+N-K+1 ), WORK, 1,
327 $ ZERO, AP( KC+1 ), 1 )
328 AP( KC ) = AP( KC ) - CDOTU( N-K, WORK, 1, AP( KC+1 ),
334 * 2 x 2 diagonal block
336 * Invert the diagonal block.
339 AK = AP( KCNEXT ) / T
341 AKKP1 = AP( KCNEXT+1 ) / T
342 D = T*( AK*AKP1-ONE )
343 AP( KCNEXT ) = AKP1 / D
345 AP( KCNEXT+1 ) = -AKKP1 / D
347 * Compute columns K-1 and K of the inverse.
350 CALL CCOPY( N-K, AP( KC+1 ), 1, WORK, 1 )
351 CALL CSPMV( UPLO, N-K, -ONE, AP( KC+( N-K+1 ) ), WORK, 1,
352 $ ZERO, AP( KC+1 ), 1 )
353 AP( KC ) = AP( KC ) - CDOTU( N-K, WORK, 1, AP( KC+1 ),
355 AP( KCNEXT+1 ) = AP( KCNEXT+1 ) -
356 $ CDOTU( N-K, AP( KC+1 ), 1,
357 $ AP( KCNEXT+2 ), 1 )
358 CALL CCOPY( N-K, AP( KCNEXT+2 ), 1, WORK, 1 )
359 CALL CSPMV( UPLO, N-K, -ONE, AP( KC+( N-K+1 ) ), WORK, 1,
360 $ ZERO, AP( KCNEXT+2 ), 1 )
361 AP( KCNEXT ) = AP( KCNEXT ) -
362 $ CDOTU( N-K, WORK, 1, AP( KCNEXT+2 ), 1 )
365 KCNEXT = KCNEXT - ( N-K+3 )
368 KP = ABS( IPIV( K ) )
371 * Interchange rows and columns K and KP in the trailing
372 * submatrix A(k-1:n,k-1:n)
374 KPC = NPP - ( N-KP+1 )*( N-KP+2 ) / 2 + 1
376 $ CALL CSWAP( N-KP, AP( KC+KP-K+1 ), 1, AP( KPC+1 ), 1 )
378 DO 70 J = K + 1, KP - 1
381 AP( KC+J-K ) = AP( KX )
387 IF( KSTEP.EQ.2 ) THEN
388 TEMP = AP( KC-N+K-1 )
389 AP( KC-N+K-1 ) = AP( KC-N+KP-1 )
390 AP( KC-N+KP-1 ) = TEMP