3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DSPTRI + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsptri.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsptri.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsptri.f">
21 * SUBROUTINE DSPTRI( UPLO, N, AP, IPIV, WORK, INFO )
23 * .. Scalar Arguments ..
27 * .. Array Arguments ..
29 * DOUBLE PRECISION AP( * ), WORK( * )
38 *> DSPTRI computes the inverse of a real 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 DSPTRF.
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 DOUBLE PRECISION 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 DSPTRF,
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 DSPTRF.
85 *> WORK is DOUBLE PRECISION 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 doubleOTHERcomputational
109 * =====================================================================
110 SUBROUTINE DSPTRI( 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 DOUBLE PRECISION AP( * ), WORK( * )
126 * =====================================================================
129 DOUBLE PRECISION ONE, ZERO
130 PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )
132 * .. Local Scalars ..
134 INTEGER J, K, KC, KCNEXT, KP, KPC, KSTEP, KX, NPP
135 DOUBLE PRECISION AK, AKKP1, AKP1, D, T, TEMP
137 * .. External Functions ..
139 DOUBLE PRECISION DDOT
142 * .. External Subroutines ..
143 EXTERNAL DCOPY, DSPMV, DSWAP, XERBLA
145 * .. Intrinsic Functions ..
148 * .. Executable Statements ..
150 * Test the input parameters.
153 UPPER = LSAME( UPLO, 'U' )
154 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
156 ELSE IF( N.LT.0 ) THEN
160 CALL XERBLA( 'DSPTRI', -INFO )
164 * Quick return if possible
169 * Check that the diagonal matrix D is nonsingular.
173 * Upper triangular storage: examine D from bottom to top
176 DO 10 INFO = N, 1, -1
177 IF( IPIV( INFO ).GT.0 .AND. AP( KP ).EQ.ZERO )
183 * Lower triangular storage: examine D from top to bottom.
187 IF( IPIV( INFO ).GT.0 .AND. AP( KP ).EQ.ZERO )
189 KP = KP + N - INFO + 1
196 * Compute inv(A) from the factorization A = U*D*U**T.
198 * K is the main loop index, increasing from 1 to N in steps of
199 * 1 or 2, depending on the size of the diagonal blocks.
205 * If K > N, exit from loop.
211 IF( IPIV( K ).GT.0 ) THEN
213 * 1 x 1 diagonal block
215 * Invert the diagonal block.
217 AP( KC+K-1 ) = ONE / AP( KC+K-1 )
219 * Compute column K of the inverse.
222 CALL DCOPY( K-1, AP( KC ), 1, WORK, 1 )
223 CALL DSPMV( UPLO, K-1, -ONE, AP, WORK, 1, ZERO, AP( KC ),
225 AP( KC+K-1 ) = AP( KC+K-1 ) -
226 $ DDOT( K-1, WORK, 1, AP( KC ), 1 )
231 * 2 x 2 diagonal block
233 * Invert the diagonal block.
235 T = ABS( AP( KCNEXT+K-1 ) )
236 AK = AP( KC+K-1 ) / T
237 AKP1 = AP( KCNEXT+K ) / T
238 AKKP1 = AP( KCNEXT+K-1 ) / T
239 D = T*( AK*AKP1-ONE )
240 AP( KC+K-1 ) = AKP1 / D
241 AP( KCNEXT+K ) = AK / D
242 AP( KCNEXT+K-1 ) = -AKKP1 / D
244 * Compute columns K and K+1 of the inverse.
247 CALL DCOPY( K-1, AP( KC ), 1, WORK, 1 )
248 CALL DSPMV( UPLO, K-1, -ONE, AP, WORK, 1, ZERO, AP( KC ),
250 AP( KC+K-1 ) = AP( KC+K-1 ) -
251 $ DDOT( K-1, WORK, 1, AP( KC ), 1 )
252 AP( KCNEXT+K-1 ) = AP( KCNEXT+K-1 ) -
253 $ DDOT( K-1, AP( KC ), 1, AP( KCNEXT ),
255 CALL DCOPY( K-1, AP( KCNEXT ), 1, WORK, 1 )
256 CALL DSPMV( UPLO, K-1, -ONE, AP, WORK, 1, ZERO,
258 AP( KCNEXT+K ) = AP( KCNEXT+K ) -
259 $ DDOT( K-1, WORK, 1, AP( KCNEXT ), 1 )
262 KCNEXT = KCNEXT + K + 1
265 KP = ABS( IPIV( K ) )
268 * Interchange rows and columns K and KP in the leading
269 * submatrix A(1:k+1,1:k+1)
271 KPC = ( KP-1 )*KP / 2 + 1
272 CALL DSWAP( KP-1, AP( KC ), 1, AP( KPC ), 1 )
274 DO 40 J = KP + 1, K - 1
277 AP( KC+J-1 ) = AP( KX )
281 AP( KC+K-1 ) = AP( KPC+KP-1 )
282 AP( KPC+KP-1 ) = TEMP
283 IF( KSTEP.EQ.2 ) THEN
284 TEMP = AP( KC+K+K-1 )
285 AP( KC+K+K-1 ) = AP( KC+K+KP-1 )
286 AP( KC+K+KP-1 ) = TEMP
297 * Compute inv(A) from the factorization A = L*D*L**T.
299 * K is the main loop index, increasing from 1 to N in steps of
300 * 1 or 2, depending on the size of the diagonal blocks.
307 * If K < 1, exit from loop.
312 KCNEXT = KC - ( N-K+2 )
313 IF( IPIV( K ).GT.0 ) THEN
315 * 1 x 1 diagonal block
317 * Invert the diagonal block.
319 AP( KC ) = ONE / AP( KC )
321 * Compute column K of the inverse.
324 CALL DCOPY( N-K, AP( KC+1 ), 1, WORK, 1 )
325 CALL DSPMV( UPLO, N-K, -ONE, AP( KC+N-K+1 ), WORK, 1,
326 $ ZERO, AP( KC+1 ), 1 )
327 AP( KC ) = AP( KC ) - DDOT( N-K, WORK, 1, AP( KC+1 ), 1 )
332 * 2 x 2 diagonal block
334 * Invert the diagonal block.
336 T = ABS( AP( KCNEXT+1 ) )
337 AK = AP( KCNEXT ) / T
339 AKKP1 = AP( KCNEXT+1 ) / T
340 D = T*( AK*AKP1-ONE )
341 AP( KCNEXT ) = AKP1 / D
343 AP( KCNEXT+1 ) = -AKKP1 / D
345 * Compute columns K-1 and K of the inverse.
348 CALL DCOPY( N-K, AP( KC+1 ), 1, WORK, 1 )
349 CALL DSPMV( UPLO, N-K, -ONE, AP( KC+( N-K+1 ) ), WORK, 1,
350 $ ZERO, AP( KC+1 ), 1 )
351 AP( KC ) = AP( KC ) - DDOT( N-K, WORK, 1, AP( KC+1 ), 1 )
352 AP( KCNEXT+1 ) = AP( KCNEXT+1 ) -
353 $ DDOT( N-K, AP( KC+1 ), 1,
354 $ AP( KCNEXT+2 ), 1 )
355 CALL DCOPY( N-K, AP( KCNEXT+2 ), 1, WORK, 1 )
356 CALL DSPMV( UPLO, N-K, -ONE, AP( KC+( N-K+1 ) ), WORK, 1,
357 $ ZERO, AP( KCNEXT+2 ), 1 )
358 AP( KCNEXT ) = AP( KCNEXT ) -
359 $ DDOT( N-K, WORK, 1, AP( KCNEXT+2 ), 1 )
362 KCNEXT = KCNEXT - ( N-K+3 )
365 KP = ABS( IPIV( K ) )
368 * Interchange rows and columns K and KP in the trailing
369 * submatrix A(k-1:n,k-1:n)
371 KPC = NPP - ( N-KP+1 )*( N-KP+2 ) / 2 + 1
373 $ CALL DSWAP( N-KP, AP( KC+KP-K+1 ), 1, AP( KPC+1 ), 1 )
375 DO 70 J = K + 1, KP - 1
378 AP( KC+J-K ) = AP( KX )
384 IF( KSTEP.EQ.2 ) THEN
385 TEMP = AP( KC-N+K-1 )
386 AP( KC-N+K-1 ) = AP( KC-N+KP-1 )
387 AP( KC-N+KP-1 ) = TEMP