3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DSYTRI + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsytri.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsytri.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsytri.f">
21 * SUBROUTINE DSYTRI( UPLO, N, A, LDA, IPIV, WORK, INFO )
23 * .. Scalar Arguments ..
25 * INTEGER INFO, LDA, N
27 * .. Array Arguments ..
29 * DOUBLE PRECISION A( LDA, * ), WORK( * )
38 *> DSYTRI computes the inverse of a real symmetric indefinite matrix
39 *> A using the factorization A = U*D*U**T or A = L*D*L**T computed by
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 *> A is DOUBLE PRECISION array, dimension (LDA,N)
64 *> On entry, the block diagonal matrix D and the multipliers
65 *> used to obtain the factor U or L as computed by DSYTRF.
67 *> On exit, if INFO = 0, the (symmetric) inverse of the original
68 *> matrix. If UPLO = 'U', the upper triangular part of the
69 *> inverse is formed and the part of A below the diagonal is not
70 *> referenced; if UPLO = 'L' the lower triangular part of the
71 *> inverse is formed and the part of A above the diagonal is
78 *> The leading dimension of the array A. LDA >= max(1,N).
83 *> IPIV is INTEGER array, dimension (N)
84 *> Details of the interchanges and the block structure of D
85 *> as determined by DSYTRF.
90 *> WORK is DOUBLE PRECISION array, dimension (N)
96 *> = 0: successful exit
97 *> < 0: if INFO = -i, the i-th argument had an illegal value
98 *> > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its
99 *> inverse could not be computed.
105 *> \author Univ. of Tennessee
106 *> \author Univ. of California Berkeley
107 *> \author Univ. of Colorado Denver
110 *> \date November 2011
112 *> \ingroup doubleSYcomputational
114 * =====================================================================
115 SUBROUTINE DSYTRI( UPLO, N, A, LDA, IPIV, WORK, INFO )
117 * -- LAPACK computational routine (version 3.4.0) --
118 * -- LAPACK is a software package provided by Univ. of Tennessee, --
119 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
122 * .. Scalar Arguments ..
126 * .. Array Arguments ..
128 DOUBLE PRECISION A( LDA, * ), WORK( * )
131 * =====================================================================
134 DOUBLE PRECISION ONE, ZERO
135 PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )
137 * .. Local Scalars ..
140 DOUBLE PRECISION AK, AKKP1, AKP1, D, T, TEMP
142 * .. External Functions ..
144 DOUBLE PRECISION DDOT
147 * .. External Subroutines ..
148 EXTERNAL DCOPY, DSWAP, DSYMV, XERBLA
150 * .. Intrinsic Functions ..
153 * .. Executable Statements ..
155 * Test the input parameters.
158 UPPER = LSAME( UPLO, 'U' )
159 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
161 ELSE IF( N.LT.0 ) THEN
163 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
167 CALL XERBLA( 'DSYTRI', -INFO )
171 * Quick return if possible
176 * Check that the diagonal matrix D is nonsingular.
180 * Upper triangular storage: examine D from bottom to top
182 DO 10 INFO = N, 1, -1
183 IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.ZERO )
188 * Lower triangular storage: examine D from top to bottom.
191 IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.ZERO )
199 * Compute inv(A) from the factorization A = U*D*U**T.
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.
207 * 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 A( K, K ) = ONE / A( K, K )
220 * Compute column K of the inverse.
223 CALL DCOPY( K-1, A( 1, K ), 1, WORK, 1 )
224 CALL DSYMV( UPLO, K-1, -ONE, A, LDA, WORK, 1, ZERO,
226 A( K, K ) = A( K, K ) - DDOT( K-1, WORK, 1, A( 1, K ),
232 * 2 x 2 diagonal block
234 * Invert the diagonal block.
236 T = ABS( A( K, K+1 ) )
238 AKP1 = A( K+1, K+1 ) / T
239 AKKP1 = A( K, K+1 ) / T
240 D = T*( AK*AKP1-ONE )
242 A( K+1, K+1 ) = AK / D
243 A( K, K+1 ) = -AKKP1 / D
245 * Compute columns K and K+1 of the inverse.
248 CALL DCOPY( K-1, A( 1, K ), 1, WORK, 1 )
249 CALL DSYMV( UPLO, K-1, -ONE, A, LDA, WORK, 1, ZERO,
251 A( K, K ) = A( K, K ) - DDOT( K-1, WORK, 1, A( 1, K ),
253 A( K, K+1 ) = A( K, K+1 ) -
254 $ DDOT( K-1, A( 1, K ), 1, A( 1, K+1 ), 1 )
255 CALL DCOPY( K-1, A( 1, K+1 ), 1, WORK, 1 )
256 CALL DSYMV( UPLO, K-1, -ONE, A, LDA, WORK, 1, ZERO,
258 A( K+1, K+1 ) = A( K+1, K+1 ) -
259 $ DDOT( K-1, WORK, 1, A( 1, K+1 ), 1 )
264 KP = ABS( IPIV( K ) )
267 * Interchange rows and columns K and KP in the leading
268 * submatrix A(1:k+1,1:k+1)
270 CALL DSWAP( KP-1, A( 1, K ), 1, A( 1, KP ), 1 )
271 CALL DSWAP( K-KP-1, A( KP+1, K ), 1, A( KP, KP+1 ), LDA )
273 A( K, K ) = A( KP, KP )
275 IF( KSTEP.EQ.2 ) THEN
277 A( K, K+1 ) = A( KP, K+1 )
288 * Compute inv(A) from the factorization A = L*D*L**T.
290 * K is the main loop index, increasing from 1 to N in steps of
291 * 1 or 2, depending on the size of the diagonal blocks.
296 * If K < 1, exit from loop.
301 IF( IPIV( K ).GT.0 ) THEN
303 * 1 x 1 diagonal block
305 * Invert the diagonal block.
307 A( K, K ) = ONE / A( K, K )
309 * Compute column K of the inverse.
312 CALL DCOPY( N-K, A( K+1, K ), 1, WORK, 1 )
313 CALL DSYMV( UPLO, N-K, -ONE, A( K+1, K+1 ), LDA, WORK, 1,
314 $ ZERO, A( K+1, K ), 1 )
315 A( K, K ) = A( K, K ) - DDOT( N-K, WORK, 1, A( K+1, K ),
321 * 2 x 2 diagonal block
323 * Invert the diagonal block.
325 T = ABS( A( K, K-1 ) )
326 AK = A( K-1, K-1 ) / T
328 AKKP1 = A( K, K-1 ) / T
329 D = T*( AK*AKP1-ONE )
330 A( K-1, K-1 ) = AKP1 / D
332 A( K, K-1 ) = -AKKP1 / D
334 * Compute columns K-1 and K of the inverse.
337 CALL DCOPY( N-K, A( K+1, K ), 1, WORK, 1 )
338 CALL DSYMV( UPLO, N-K, -ONE, A( K+1, K+1 ), LDA, WORK, 1,
339 $ ZERO, A( K+1, K ), 1 )
340 A( K, K ) = A( K, K ) - DDOT( N-K, WORK, 1, A( K+1, K ),
342 A( K, K-1 ) = A( K, K-1 ) -
343 $ DDOT( N-K, A( K+1, K ), 1, A( K+1, K-1 ),
345 CALL DCOPY( N-K, A( K+1, K-1 ), 1, WORK, 1 )
346 CALL DSYMV( UPLO, N-K, -ONE, A( K+1, K+1 ), LDA, WORK, 1,
347 $ ZERO, A( K+1, K-1 ), 1 )
348 A( K-1, K-1 ) = A( K-1, K-1 ) -
349 $ DDOT( N-K, WORK, 1, A( K+1, K-1 ), 1 )
354 KP = ABS( IPIV( K ) )
357 * Interchange rows and columns K and KP in the trailing
358 * submatrix A(k-1:n,k-1:n)
361 $ CALL DSWAP( N-KP, A( KP+1, K ), 1, A( KP+1, KP ), 1 )
362 CALL DSWAP( KP-K-1, A( K+1, K ), 1, A( KP, K+1 ), LDA )
364 A( K, K ) = A( KP, KP )
366 IF( KSTEP.EQ.2 ) THEN
368 A( K, K-1 ) = A( KP, K-1 )