3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CHETRI2X + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chetri2x.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetri2x.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetri2x.f">
21 * SUBROUTINE CHETRI2X( UPLO, N, A, LDA, IPIV, WORK, NB, INFO )
23 * .. Scalar Arguments ..
25 * INTEGER INFO, LDA, N, NB
27 * .. Array Arguments ..
29 * COMPLEX A( LDA, * ), WORK( N+NB+1,* )
38 *> CHETRI2X computes the inverse of a complex Hermitian indefinite matrix
39 *> A using the factorization A = U*D*U**H or A = L*D*L**H 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**H;
52 *> = 'L': Lower triangular, form is A = L*D*L**H.
58 *> The order of the matrix A. N >= 0.
63 *> A is COMPLEX 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 CHETRF.
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 CHETRF.
90 *> WORK is COMPLEX array, dimension (N+NB+1,NB+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 2015
118 *> \ingroup complexHEcomputational
120 * =====================================================================
121 SUBROUTINE CHETRI2X( UPLO, N, A, LDA, IPIV, WORK, NB, INFO )
123 * -- LAPACK computational routine (version 3.6.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 COMPLEX A( LDA, * ), WORK( N+NB+1,* )
137 * =====================================================================
142 PARAMETER ( ONE = 1.0E+0,
143 $ CONE = ( 1.0E+0, 0.0E+0 ),
144 $ ZERO = ( 0.0E+0, 0.0E+0 ) )
146 * .. Local Scalars ..
148 INTEGER I, IINFO, IP, K, CUT, NNB
152 COMPLEX AK, AKKP1, AKP1, D, T
153 COMPLEX U01_I_J, U01_IP1_J
154 COMPLEX U11_I_J, U11_IP1_J
156 * .. External Functions ..
160 * .. External Subroutines ..
161 EXTERNAL CSYCONV, XERBLA, CTRTRI
162 EXTERNAL CGEMM, CTRMM, CHESWAPR
164 * .. Intrinsic Functions ..
167 * .. Executable Statements ..
169 * Test the input parameters.
172 UPPER = LSAME( UPLO, 'U' )
173 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
175 ELSE IF( N.LT.0 ) THEN
177 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
181 * Quick return if possible
185 CALL XERBLA( 'CHETRI2X', -INFO )
192 * Workspace got Non-diag elements of D
194 CALL CSYCONV( UPLO, 'C', N, A, LDA, IPIV, WORK, IINFO )
196 * Check that the diagonal matrix D is nonsingular.
200 * Upper triangular storage: examine D from bottom to top
203 IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.ZERO )
208 * Lower triangular storage: examine D from top to bottom.
211 IF( IPIV( INFO ).GT.0 .AND. A( INFO, INFO ).EQ.ZERO )
217 * Splitting Workspace
218 * U01 is a block (N,NB+1)
219 * The first element of U01 is in WORK(1,1)
220 * U11 is a block (NB+1,NB+1)
221 * The first element of U11 is in WORK(N+1,1)
223 * INVD is a block (N,2)
224 * The first element of INVD is in WORK(1,INVD)
229 * invA = P * inv(U**H)*inv(D)*inv(U)*P**H.
231 CALL CTRTRI( UPLO, 'U', N, A, LDA, INFO )
233 * inv(D) and inv(D)*inv(U)
236 DO WHILE ( K .LE. N )
237 IF( IPIV( K ).GT.0 ) THEN
239 WORK(K,INVD) = ONE / REAL ( A( K, K ) )
244 T = ABS ( WORK(K+1,1) )
245 AK = REAL ( A( K, K ) ) / T
246 AKP1 = REAL ( A( K+1, K+1 ) ) / T
247 AKKP1 = WORK(K+1,1) / T
248 D = T*( AK*AKP1-ONE )
249 WORK(K,INVD) = AKP1 / D
250 WORK(K+1,INVD+1) = AK / D
251 WORK(K,INVD+1) = -AKKP1 / D
252 WORK(K+1,INVD) = CONJG (WORK(K,INVD+1) )
257 * inv(U**H) = (inv(U))**H
259 * inv(U**H)*inv(D)*inv(U)
262 DO WHILE (CUT .GT. 0)
264 IF (CUT .LE. NNB) THEN
268 * count negative elements,
270 IF (IPIV(I) .LT. 0) COUNT=COUNT+1
272 * need a even number for a clear cut
273 IF (MOD(COUNT,2) .EQ. 1) NNB=NNB+1
294 WORK(U11+I,J)=A(CUT+I,CUT+J)
301 DO WHILE (I .LE. CUT)
302 IF (IPIV(I) > 0) THEN
304 WORK(I,J)=WORK(I,INVD)*WORK(I,J)
310 U01_IP1_J = WORK(I+1,J)
311 WORK(I,J)=WORK(I,INVD)*U01_I_J+
312 $ WORK(I,INVD+1)*U01_IP1_J
313 WORK(I+1,J)=WORK(I+1,INVD)*U01_I_J+
314 $ WORK(I+1,INVD+1)*U01_IP1_J
323 DO WHILE (I .LE. NNB)
324 IF (IPIV(CUT+I) > 0) THEN
326 WORK(U11+I,J)=WORK(CUT+I,INVD)*WORK(U11+I,J)
331 U11_I_J = WORK(U11+I,J)
332 U11_IP1_J = WORK(U11+I+1,J)
333 WORK(U11+I,J)=WORK(CUT+I,INVD)*WORK(U11+I,J) +
334 $ WORK(CUT+I,INVD+1)*WORK(U11+I+1,J)
335 WORK(U11+I+1,J)=WORK(CUT+I+1,INVD)*U11_I_J+
336 $ WORK(CUT+I+1,INVD+1)*U11_IP1_J
342 * U11**H*invD1*U11->U11
344 CALL CTRMM('L','U','C','U',NNB, NNB,
345 $ CONE,A(CUT+1,CUT+1),LDA,WORK(U11+1,1),N+NB+1)
349 A(CUT+I,CUT+J)=WORK(U11+I,J)
353 * U01**H*invD*U01->A(CUT+I,CUT+J)
355 CALL CGEMM('C','N',NNB,NNB,CUT,CONE,A(1,CUT+1),LDA,
356 $ WORK,N+NB+1, ZERO, WORK(U11+1,1), N+NB+1)
358 * U11 = U11**H*invD1*U11 + U01**H*invD*U01
362 A(CUT+I,CUT+J)=A(CUT+I,CUT+J)+WORK(U11+I,J)
366 * U01 = U00**H*invD0*U01
368 CALL CTRMM('L',UPLO,'C','U',CUT, NNB,
369 $ CONE,A,LDA,WORK,N+NB+1)
384 * Apply PERMUTATIONS P and P**H: P * inv(U**H)*inv(D)*inv(U) *P**H
387 DO WHILE ( I .LE. N )
388 IF( IPIV(I) .GT. 0 ) THEN
390 IF (I .LT. IP) CALL CHESWAPR( UPLO, N, A, LDA, I ,IP )
391 IF (I .GT. IP) CALL CHESWAPR( UPLO, N, A, LDA, IP ,I )
396 $ CALL CHESWAPR( UPLO, N, A, LDA, I-1 ,IP )
398 $ CALL CHESWAPR( UPLO, N, A, LDA, IP ,I-1 )
406 * invA = P * inv(U**H)*inv(D)*inv(U)*P**H.
408 CALL CTRTRI( UPLO, 'U', N, A, LDA, INFO )
410 * inv(D) and inv(D)*inv(U)
413 DO WHILE ( K .GE. 1 )
414 IF( IPIV( K ).GT.0 ) THEN
416 WORK(K,INVD) = ONE / REAL ( A( K, K ) )
421 T = ABS ( WORK(K-1,1) )
422 AK = REAL ( A( K-1, K-1 ) ) / T
423 AKP1 = REAL ( A( K, K ) ) / T
424 AKKP1 = WORK(K-1,1) / T
425 D = T*( AK*AKP1-ONE )
426 WORK(K-1,INVD) = AKP1 / D
427 WORK(K,INVD) = AK / D
428 WORK(K,INVD+1) = -AKKP1 / D
429 WORK(K-1,INVD+1) = CONJG (WORK(K,INVD+1) )
434 * inv(U**H) = (inv(U))**H
436 * inv(U**H)*inv(D)*inv(U)
439 DO WHILE (CUT .LT. N)
441 IF (CUT + NNB .GE. N) THEN
445 * count negative elements,
447 IF (IPIV(I) .LT. 0) COUNT=COUNT+1
449 * need a even number for a clear cut
450 IF (MOD(COUNT,2) .EQ. 1) NNB=NNB+1
455 WORK(I,J)=A(CUT+NNB+I,CUT+J)
465 WORK(U11+I,J)=A(CUT+I,CUT+J)
473 IF (IPIV(CUT+NNB+I) > 0) THEN
475 WORK(I,J)=WORK(CUT+NNB+I,INVD)*WORK(I,J)
481 U01_IP1_J = WORK(I-1,J)
482 WORK(I,J)=WORK(CUT+NNB+I,INVD)*U01_I_J+
483 $ WORK(CUT+NNB+I,INVD+1)*U01_IP1_J
484 WORK(I-1,J)=WORK(CUT+NNB+I-1,INVD+1)*U01_I_J+
485 $ WORK(CUT+NNB+I-1,INVD)*U01_IP1_J
495 IF (IPIV(CUT+I) > 0) THEN
497 WORK(U11+I,J)=WORK(CUT+I,INVD)*WORK(U11+I,J)
502 U11_I_J = WORK(U11+I,J)
503 U11_IP1_J = WORK(U11+I-1,J)
504 WORK(U11+I,J)=WORK(CUT+I,INVD)*WORK(U11+I,J) +
505 $ WORK(CUT+I,INVD+1)*U11_IP1_J
506 WORK(U11+I-1,J)=WORK(CUT+I-1,INVD+1)*U11_I_J+
507 $ WORK(CUT+I-1,INVD)*U11_IP1_J
513 * L11**H*invD1*L11->L11
515 CALL CTRMM('L',UPLO,'C','U',NNB, NNB,
516 $ CONE,A(CUT+1,CUT+1),LDA,WORK(U11+1,1),N+NB+1)
520 A(CUT+I,CUT+J)=WORK(U11+I,J)
524 IF ( (CUT+NNB) .LT. N ) THEN
526 * L21**H*invD2*L21->A(CUT+I,CUT+J)
528 CALL CGEMM('C','N',NNB,NNB,N-NNB-CUT,CONE,A(CUT+NNB+1,CUT+1)
529 $ ,LDA,WORK,N+NB+1, ZERO, WORK(U11+1,1), N+NB+1)
532 * L11 = L11**H*invD1*L11 + U01**H*invD*U01
536 A(CUT+I,CUT+J)=A(CUT+I,CUT+J)+WORK(U11+I,J)
540 * L01 = L22**H*invD2*L21
542 CALL CTRMM('L',UPLO,'C','U', N-NNB-CUT, NNB,
543 $ CONE,A(CUT+NNB+1,CUT+NNB+1),LDA,WORK,N+NB+1)
548 A(CUT+NNB+I,CUT+J)=WORK(I,J)
553 * L11 = L11**H*invD1*L11
557 A(CUT+I,CUT+J)=WORK(U11+I,J)
567 * Apply PERMUTATIONS P and P**H: P * inv(U**H)*inv(D)*inv(U) *P**H
570 DO WHILE ( I .GE. 1 )
571 IF( IPIV(I) .GT. 0 ) THEN
573 IF (I .LT. IP) CALL CHESWAPR( UPLO, N, A, LDA, I ,IP )
574 IF (I .GT. IP) CALL CHESWAPR( UPLO, N, A, LDA, IP ,I )
577 IF ( I .LT. IP) CALL CHESWAPR( UPLO, N, A, LDA, I ,IP )
578 IF ( I .GT. IP) CALL CHESWAPR( UPLO, N, A, LDA, IP ,I )