3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download SSYTRI2X + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssytri2x.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssytri2x.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssytri2x.f">
21 * SUBROUTINE SSYTRI2X( UPLO, N, A, LDA, IPIV, WORK, NB, INFO )
23 * .. Scalar Arguments ..
25 * INTEGER INFO, LDA, N, NB
27 * .. Array Arguments ..
29 * REAL A( LDA, * ), WORK( N+NB+1,* )
38 *> SSYTRI2X 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 REAL array, dimension (LDA,N)
64 *> On entry, the NNB diagonal matrix D and the multipliers
65 *> used to obtain the factor U or L as computed by SSYTRF.
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 NNB structure of D
85 *> as determined by SSYTRF.
90 *> WORK is REAL array, dimension (N+NNB+1,NNB+3)
102 *> = 0: successful exit
103 *> < 0: if INFO = -i, the i-th argument had an illegal value
104 *> > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its
105 *> inverse could not be computed.
111 *> \author Univ. of Tennessee
112 *> \author Univ. of California Berkeley
113 *> \author Univ. of Colorado Denver
116 *> \date November 2011
118 *> \ingroup realSYcomputational
120 * =====================================================================
121 SUBROUTINE SSYTRI2X( UPLO, N, A, LDA, IPIV, WORK, NB, INFO )
123 * -- LAPACK computational routine (version 3.4.0) --
124 * -- LAPACK is a software package provided by Univ. of Tennessee, --
125 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
128 * .. Scalar Arguments ..
130 INTEGER INFO, LDA, N, NB
132 * .. Array Arguments ..
134 REAL A( LDA, * ), WORK( N+NB+1,* )
137 * =====================================================================
141 PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 )
143 * .. Local Scalars ..
145 INTEGER I, IINFO, IP, K, CUT, NNB
149 REAL AK, AKKP1, AKP1, D, T
150 REAL U01_I_J, U01_IP1_J
151 REAL U11_I_J, U11_IP1_J
153 * .. External Functions ..
157 * .. External Subroutines ..
158 EXTERNAL SSYCONV, XERBLA, STRTRI
159 EXTERNAL SGEMM, STRMM, SSYSWAPR
161 * .. Intrinsic Functions ..
164 * .. Executable Statements ..
166 * Test the input parameters.
169 UPPER = LSAME( UPLO, 'U' )
170 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
172 ELSE IF( N.LT.0 ) THEN
174 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
178 * Quick return if possible
182 CALL XERBLA( 'SSYTRI2X', -INFO )
189 * Workspace got Non-diag elements of D
191 CALL SSYCONV( UPLO, 'C', N, A, LDA, IPIV, WORK, IINFO )
193 * Check that the diagonal matrix D is nonsingular.
197 * Upper triangular storage: examine D from bottom to top
200 IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.ZERO )
205 * Lower triangular storage: examine D from top to bottom.
208 IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.ZERO )
214 * Splitting Workspace
215 * U01 is a block (N,NB+1)
216 * The first element of U01 is in WORK(1,1)
217 * U11 is a block (NB+1,NB+1)
218 * The first element of U11 is in WORK(N+1,1)
220 * INVD is a block (N,2)
221 * The first element of INVD is in WORK(1,INVD)
226 * invA = P * inv(U**T)*inv(D)*inv(U)*P**T.
228 CALL STRTRI( UPLO, 'U', N, A, LDA, INFO )
230 * inv(D) and inv(D)*inv(U)
233 DO WHILE ( K .LE. N )
234 IF( IPIV( K ).GT.0 ) THEN
236 WORK(K,INVD) = ONE / A( K, K )
243 AKP1 = A( K+1, K+1 ) / T
244 AKKP1 = WORK(K+1,1) / T
245 D = T*( AK*AKP1-ONE )
246 WORK(K,INVD) = AKP1 / D
247 WORK(K+1,INVD+1) = AK / D
248 WORK(K,INVD+1) = -AKKP1 / D
249 WORK(K+1,INVD) = -AKKP1 / D
254 * inv(U**T) = (inv(U))**T
256 * inv(U**T)*inv(D)*inv(U)
259 DO WHILE (CUT .GT. 0)
261 IF (CUT .LE. NNB) THEN
265 * count negative elements,
267 IF (IPIV(I) .LT. 0) COUNT=COUNT+1
269 * need a even number for a clear cut
270 IF (MOD(COUNT,2) .EQ. 1) NNB=NNB+1
291 WORK(U11+I,J)=A(CUT+I,CUT+J)
298 DO WHILE (I .LE. CUT)
299 IF (IPIV(I) > 0) THEN
301 WORK(I,J)=WORK(I,INVD)*WORK(I,J)
307 U01_IP1_J = WORK(I+1,J)
308 WORK(I,J)=WORK(I,INVD)*U01_I_J+
309 $ WORK(I,INVD+1)*U01_IP1_J
310 WORK(I+1,J)=WORK(I+1,INVD)*U01_I_J+
311 $ WORK(I+1,INVD+1)*U01_IP1_J
320 DO WHILE (I .LE. NNB)
321 IF (IPIV(CUT+I) > 0) THEN
323 WORK(U11+I,J)=WORK(CUT+I,INVD)*WORK(U11+I,J)
328 U11_I_J = WORK(U11+I,J)
329 U11_IP1_J = WORK(U11+I+1,J)
330 WORK(U11+I,J)=WORK(CUT+I,INVD)*WORK(U11+I,J) +
331 $ WORK(CUT+I,INVD+1)*WORK(U11+I+1,J)
332 WORK(U11+I+1,J)=WORK(CUT+I+1,INVD)*U11_I_J+
333 $ WORK(CUT+I+1,INVD+1)*U11_IP1_J
339 * U11**T*invD1*U11->U11
341 CALL STRMM('L','U','T','U',NNB, NNB,
342 $ ONE,A(CUT+1,CUT+1),LDA,WORK(U11+1,1),N+NB+1)
346 A(CUT+I,CUT+J)=WORK(U11+I,J)
350 * U01**T*invD*U01->A(CUT+I,CUT+J)
352 CALL SGEMM('T','N',NNB,NNB,CUT,ONE,A(1,CUT+1),LDA,
353 $ WORK,N+NB+1, ZERO, WORK(U11+1,1), N+NB+1)
355 * U11 = U11**T*invD1*U11 + U01**T*invD*U01
359 A(CUT+I,CUT+J)=A(CUT+I,CUT+J)+WORK(U11+I,J)
363 * U01 = U00**T*invD0*U01
365 CALL STRMM('L',UPLO,'T','U',CUT, NNB,
366 $ ONE,A,LDA,WORK,N+NB+1)
381 * Apply PERMUTATIONS P and P**T: P * inv(U**T)*inv(D)*inv(U) *P**T
384 DO WHILE ( I .LE. N )
385 IF( IPIV(I) .GT. 0 ) THEN
387 IF (I .LT. IP) CALL SSYSWAPR( UPLO, N, A, LDA, I ,IP )
388 IF (I .GT. IP) CALL SSYSWAPR( UPLO, N, A, LDA, IP ,I )
393 $ CALL SSYSWAPR( UPLO, N, A, LDA, I-1 ,IP )
395 $ CALL SSYSWAPR( UPLO, N, A, LDA, IP ,I-1 )
403 * invA = P * inv(U**T)*inv(D)*inv(U)*P**T.
405 CALL STRTRI( UPLO, 'U', N, A, LDA, INFO )
407 * inv(D) and inv(D)*inv(U)
410 DO WHILE ( K .GE. 1 )
411 IF( IPIV( K ).GT.0 ) THEN
413 WORK(K,INVD) = ONE / A( K, K )
419 AK = A( K-1, K-1 ) / T
421 AKKP1 = WORK(K-1,1) / T
422 D = T*( AK*AKP1-ONE )
423 WORK(K-1,INVD) = AKP1 / D
424 WORK(K,INVD) = AK / D
425 WORK(K,INVD+1) = -AKKP1 / D
426 WORK(K-1,INVD+1) = -AKKP1 / D
431 * inv(U**T) = (inv(U))**T
433 * inv(U**T)*inv(D)*inv(U)
436 DO WHILE (CUT .LT. N)
438 IF (CUT + NNB .GT. N) THEN
442 * count negative elements,
444 IF (IPIV(I) .LT. 0) COUNT=COUNT+1
446 * need a even number for a clear cut
447 IF (MOD(COUNT,2) .EQ. 1) NNB=NNB+1
452 WORK(I,J)=A(CUT+NNB+I,CUT+J)
462 WORK(U11+I,J)=A(CUT+I,CUT+J)
470 IF (IPIV(CUT+NNB+I) > 0) THEN
472 WORK(I,J)=WORK(CUT+NNB+I,INVD)*WORK(I,J)
478 U01_IP1_J = WORK(I-1,J)
479 WORK(I,J)=WORK(CUT+NNB+I,INVD)*U01_I_J+
480 $ WORK(CUT+NNB+I,INVD+1)*U01_IP1_J
481 WORK(I-1,J)=WORK(CUT+NNB+I-1,INVD+1)*U01_I_J+
482 $ WORK(CUT+NNB+I-1,INVD)*U01_IP1_J
492 IF (IPIV(CUT+I) > 0) THEN
494 WORK(U11+I,J)=WORK(CUT+I,INVD)*WORK(U11+I,J)
499 U11_I_J = WORK(U11+I,J)
500 U11_IP1_J = WORK(U11+I-1,J)
501 WORK(U11+I,J)=WORK(CUT+I,INVD)*WORK(U11+I,J) +
502 $ WORK(CUT+I,INVD+1)*U11_IP1_J
503 WORK(U11+I-1,J)=WORK(CUT+I-1,INVD+1)*U11_I_J+
504 $ WORK(CUT+I-1,INVD)*U11_IP1_J
510 * L11**T*invD1*L11->L11
512 CALL STRMM('L',UPLO,'T','U',NNB, NNB,
513 $ ONE,A(CUT+1,CUT+1),LDA,WORK(U11+1,1),N+NB+1)
518 A(CUT+I,CUT+J)=WORK(U11+I,J)
522 IF ( (CUT+NNB) .LT. N ) THEN
524 * L21**T*invD2*L21->A(CUT+I,CUT+J)
526 CALL SGEMM('T','N',NNB,NNB,N-NNB-CUT,ONE,A(CUT+NNB+1,CUT+1)
527 $ ,LDA,WORK,N+NB+1, ZERO, WORK(U11+1,1), N+NB+1)
530 * L11 = L11**T*invD1*L11 + U01**T*invD*U01
534 A(CUT+I,CUT+J)=A(CUT+I,CUT+J)+WORK(U11+I,J)
538 * L01 = L22**T*invD2*L21
540 CALL STRMM('L',UPLO,'T','U', N-NNB-CUT, NNB,
541 $ ONE,A(CUT+NNB+1,CUT+NNB+1),LDA,WORK,N+NB+1)
547 A(CUT+NNB+I,CUT+J)=WORK(I,J)
553 * L11 = L11**T*invD1*L11
557 A(CUT+I,CUT+J)=WORK(U11+I,J)
567 * Apply PERMUTATIONS P and P**T: P * inv(U**T)*inv(D)*inv(U) *P**T
570 DO WHILE ( I .GE. 1 )
571 IF( IPIV(I) .GT. 0 ) THEN
573 IF (I .LT. IP) CALL SSYSWAPR( UPLO, N, A, LDA, I ,IP )
574 IF (I .GT. IP) CALL SSYSWAPR( UPLO, N, A, LDA, IP ,I )
577 IF ( I .LT. IP) CALL SSYSWAPR( UPLO, N, A, LDA, I ,IP )
578 IF ( I .GT. IP) CALL SSYSWAPR( UPLO, N, A, LDA, IP ,I )