LAPACK  3.6.1 LAPACK: Linear Algebra PACKage
chetri.f
Go to the documentation of this file.
1 *> \brief \b CHETRI
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 *> \htmlonly
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chetri.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetri.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetri.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 * Definition:
19 * ===========
20 *
21 * SUBROUTINE CHETRI( UPLO, N, A, LDA, IPIV, WORK, INFO )
22 *
23 * .. Scalar Arguments ..
24 * CHARACTER UPLO
25 * INTEGER INFO, LDA, N
26 * ..
27 * .. Array Arguments ..
28 * INTEGER IPIV( * )
29 * COMPLEX A( LDA, * ), WORK( * )
30 * ..
31 *
32 *
33 *> \par Purpose:
34 * =============
35 *>
36 *> \verbatim
37 *>
38 *> CHETRI 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
40 *> CHETRF.
41 *> \endverbatim
42 *
43 * Arguments:
44 * ==========
45 *
46 *> \param[in] UPLO
47 *> \verbatim
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.
53 *> \endverbatim
54 *>
55 *> \param[in] N
56 *> \verbatim
57 *> N is INTEGER
58 *> The order of the matrix A. N >= 0.
59 *> \endverbatim
60 *>
61 *> \param[in,out] A
62 *> \verbatim
63 *> A is COMPLEX 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 CHETRF.
66 *>
67 *> On exit, if INFO = 0, the (Hermitian) 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
72 *> not referenced.
73 *> \endverbatim
74 *>
75 *> \param[in] LDA
76 *> \verbatim
77 *> LDA is INTEGER
78 *> The leading dimension of the array A. LDA >= max(1,N).
79 *> \endverbatim
80 *>
81 *> \param[in] IPIV
82 *> \verbatim
83 *> IPIV is INTEGER array, dimension (N)
84 *> Details of the interchanges and the block structure of D
85 *> as determined by CHETRF.
86 *> \endverbatim
87 *>
88 *> \param[out] WORK
89 *> \verbatim
90 *> WORK is COMPLEX array, dimension (N)
91 *> \endverbatim
92 *>
93 *> \param[out] INFO
94 *> \verbatim
95 *> INFO is INTEGER
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.
100 *> \endverbatim
101 *
102 * Authors:
103 * ========
104 *
105 *> \author Univ. of Tennessee
106 *> \author Univ. of California Berkeley
107 *> \author Univ. of Colorado Denver
108 *> \author NAG Ltd.
109 *
110 *> \date November 2011
111 *
112 *> \ingroup complexHEcomputational
113 *
114 * =====================================================================
115  SUBROUTINE chetri( UPLO, N, A, LDA, IPIV, WORK, INFO )
116 *
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..--
120 * November 2011
121 *
122 * .. Scalar Arguments ..
123  CHARACTER UPLO
124  INTEGER INFO, LDA, N
125 * ..
126 * .. Array Arguments ..
127  INTEGER IPIV( * )
128  COMPLEX A( lda, * ), WORK( * )
129 * ..
130 *
131 * =====================================================================
132 *
133 * .. Parameters ..
134  REAL ONE
135  COMPLEX CONE, ZERO
136  parameter ( one = 1.0e+0, cone = ( 1.0e+0, 0.0e+0 ),
137  \$ zero = ( 0.0e+0, 0.0e+0 ) )
138 * ..
139 * .. Local Scalars ..
140  LOGICAL UPPER
141  INTEGER J, K, KP, KSTEP
142  REAL AK, AKP1, D, T
143  COMPLEX AKKP1, TEMP
144 * ..
145 * .. External Functions ..
146  LOGICAL LSAME
147  COMPLEX CDOTC
148  EXTERNAL lsame, cdotc
149 * ..
150 * .. External Subroutines ..
151  EXTERNAL ccopy, chemv, cswap, xerbla
152 * ..
153 * .. Intrinsic Functions ..
154  INTRINSIC abs, conjg, max, real
155 * ..
156 * .. Executable Statements ..
157 *
158 * Test the input parameters.
159 *
160  info = 0
161  upper = lsame( uplo, 'U' )
162  IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
163  info = -1
164  ELSE IF( n.LT.0 ) THEN
165  info = -2
166  ELSE IF( lda.LT.max( 1, n ) ) THEN
167  info = -4
168  END IF
169  IF( info.NE.0 ) THEN
170  CALL xerbla( 'CHETRI', -info )
171  RETURN
172  END IF
173 *
174 * Quick return if possible
175 *
176  IF( n.EQ.0 )
177  \$ RETURN
178 *
179 * Check that the diagonal matrix D is nonsingular.
180 *
181  IF( upper ) THEN
182 *
183 * Upper triangular storage: examine D from bottom to top
184 *
185  DO 10 info = n, 1, -1
186  IF( ipiv( info ).GT.0 .AND. a( info, info ).EQ.zero )
187  \$ RETURN
188  10 CONTINUE
189  ELSE
190 *
191 * Lower triangular storage: examine D from top to bottom.
192 *
193  DO 20 info = 1, n
194  IF( ipiv( info ).GT.0 .AND. a( info, info ).EQ.zero )
195  \$ RETURN
196  20 CONTINUE
197  END IF
198  info = 0
199 *
200  IF( upper ) THEN
201 *
202 * Compute inv(A) from the factorization A = U*D*U**H.
203 *
204 * K is the main loop index, increasing from 1 to N in steps of
205 * 1 or 2, depending on the size of the diagonal blocks.
206 *
207  k = 1
208  30 CONTINUE
209 *
210 * If K > N, exit from loop.
211 *
212  IF( k.GT.n )
213  \$ GO TO 50
214 *
215  IF( ipiv( k ).GT.0 ) THEN
216 *
217 * 1 x 1 diagonal block
218 *
219 * Invert the diagonal block.
220 *
221  a( k, k ) = one / REAL( A( K, K ) )
222 *
223 * Compute column K of the inverse.
224 *
225  IF( k.GT.1 ) THEN
226  CALL ccopy( k-1, a( 1, k ), 1, work, 1 )
227  CALL chemv( uplo, k-1, -cone, a, lda, work, 1, zero,
228  \$ a( 1, k ), 1 )
229  a( k, k ) = a( k, k ) - REAL( CDOTC( K-1, WORK, 1, A( 1, \$ K ), 1 ) )
230  END IF
231  kstep = 1
232  ELSE
233 *
234 * 2 x 2 diagonal block
235 *
236 * Invert the diagonal block.
237 *
238  t = abs( a( k, k+1 ) )
239  ak = REAL( A( K, K ) ) / T
240  akp1 = REAL( A( K+1, K+1 ) ) / T
241  akkp1 = a( k, k+1 ) / t
242  d = t*( ak*akp1-one )
243  a( k, k ) = akp1 / d
244  a( k+1, k+1 ) = ak / d
245  a( k, k+1 ) = -akkp1 / d
246 *
247 * Compute columns K and K+1 of the inverse.
248 *
249  IF( k.GT.1 ) THEN
250  CALL ccopy( k-1, a( 1, k ), 1, work, 1 )
251  CALL chemv( uplo, k-1, -cone, a, lda, work, 1, zero,
252  \$ a( 1, k ), 1 )
253  a( k, k ) = a( k, k ) - REAL( CDOTC( K-1, WORK, 1, A( 1, \$ K ), 1 ) )
254  a( k, k+1 ) = a( k, k+1 ) -
255  \$ cdotc( k-1, a( 1, k ), 1, a( 1, k+1 ), 1 )
256  CALL ccopy( k-1, a( 1, k+1 ), 1, work, 1 )
257  CALL chemv( uplo, k-1, -cone, a, lda, work, 1, zero,
258  \$ a( 1, k+1 ), 1 )
259  a( k+1, k+1 ) = a( k+1, k+1 ) -
260  \$ REAL( CDOTC( K-1, WORK, 1, A( 1, K+1 ), \$ 1 ) )
261  END IF
262  kstep = 2
263  END IF
264 *
265  kp = abs( ipiv( k ) )
266  IF( kp.NE.k ) THEN
267 *
268 * Interchange rows and columns K and KP in the leading
269 * submatrix A(1:k+1,1:k+1)
270 *
271  CALL cswap( kp-1, a( 1, k ), 1, a( 1, kp ), 1 )
272  DO 40 j = kp + 1, k - 1
273  temp = conjg( a( j, k ) )
274  a( j, k ) = conjg( a( kp, j ) )
275  a( kp, j ) = temp
276  40 CONTINUE
277  a( kp, k ) = conjg( a( kp, k ) )
278  temp = a( k, k )
279  a( k, k ) = a( kp, kp )
280  a( kp, kp ) = temp
281  IF( kstep.EQ.2 ) THEN
282  temp = a( k, k+1 )
283  a( k, k+1 ) = a( kp, k+1 )
284  a( kp, k+1 ) = temp
285  END IF
286  END IF
287 *
288  k = k + kstep
289  GO TO 30
290  50 CONTINUE
291 *
292  ELSE
293 *
294 * Compute inv(A) from the factorization A = L*D*L**H.
295 *
296 * K is the main loop index, increasing from 1 to N in steps of
297 * 1 or 2, depending on the size of the diagonal blocks.
298 *
299  k = n
300  60 CONTINUE
301 *
302 * If K < 1, exit from loop.
303 *
304  IF( k.LT.1 )
305  \$ GO TO 80
306 *
307  IF( ipiv( k ).GT.0 ) THEN
308 *
309 * 1 x 1 diagonal block
310 *
311 * Invert the diagonal block.
312 *
313  a( k, k ) = one / REAL( A( K, K ) )
314 *
315 * Compute column K of the inverse.
316 *
317  IF( k.LT.n ) THEN
318  CALL ccopy( n-k, a( k+1, k ), 1, work, 1 )
319  CALL chemv( uplo, n-k, -cone, a( k+1, k+1 ), lda, work,
320  \$ 1, zero, a( k+1, k ), 1 )
321  a( k, k ) = a( k, k ) - REAL( CDOTC( N-K, WORK, 1, \$ A( K+1, K ), 1 ) )
322  END IF
323  kstep = 1
324  ELSE
325 *
326 * 2 x 2 diagonal block
327 *
328 * Invert the diagonal block.
329 *
330  t = abs( a( k, k-1 ) )
331  ak = REAL( A( K-1, K-1 ) ) / T
332  akp1 = REAL( A( K, K ) ) / T
333  akkp1 = a( k, k-1 ) / t
334  d = t*( ak*akp1-one )
335  a( k-1, k-1 ) = akp1 / d
336  a( k, k ) = ak / d
337  a( k, k-1 ) = -akkp1 / d
338 *
339 * Compute columns K-1 and K of the inverse.
340 *
341  IF( k.LT.n ) THEN
342  CALL ccopy( n-k, a( k+1, k ), 1, work, 1 )
343  CALL chemv( uplo, n-k, -cone, a( k+1, k+1 ), lda, work,
344  \$ 1, zero, a( k+1, k ), 1 )
345  a( k, k ) = a( k, k ) - REAL( CDOTC( N-K, WORK, 1, \$ A( K+1, K ), 1 ) )
346  a( k, k-1 ) = a( k, k-1 ) -
347  \$ cdotc( n-k, a( k+1, k ), 1, a( k+1, k-1 ),
348  \$ 1 )
349  CALL ccopy( n-k, a( k+1, k-1 ), 1, work, 1 )
350  CALL chemv( uplo, n-k, -cone, a( k+1, k+1 ), lda, work,
351  \$ 1, zero, a( k+1, k-1 ), 1 )
352  a( k-1, k-1 ) = a( k-1, k-1 ) -
353  \$ REAL( CDOTC( N-K, WORK, 1, A( K+1, K-1 ), \$ 1 ) )
354  END IF
355  kstep = 2
356  END IF
357 *
358  kp = abs( ipiv( k ) )
359  IF( kp.NE.k ) THEN
360 *
361 * Interchange rows and columns K and KP in the trailing
362 * submatrix A(k-1:n,k-1:n)
363 *
364  IF( kp.LT.n )
365  \$ CALL cswap( n-kp, a( kp+1, k ), 1, a( kp+1, kp ), 1 )
366  DO 70 j = k + 1, kp - 1
367  temp = conjg( a( j, k ) )
368  a( j, k ) = conjg( a( kp, j ) )
369  a( kp, j ) = temp
370  70 CONTINUE
371  a( kp, k ) = conjg( a( kp, k ) )
372  temp = a( k, k )
373  a( k, k ) = a( kp, kp )
374  a( kp, kp ) = temp
375  IF( kstep.EQ.2 ) THEN
376  temp = a( k, k-1 )
377  a( k, k-1 ) = a( kp, k-1 )
378  a( kp, k-1 ) = temp
379  END IF
380  END IF
381 *
382  k = k - kstep
383  GO TO 60
384  80 CONTINUE
385  END IF
386 *
387  RETURN
388 *
389 * End of CHETRI
390 *
391  END
392
subroutine xerbla(SRNAME, INFO)
XERBLA
Definition: xerbla.f:62
subroutine chetri(UPLO, N, A, LDA, IPIV, WORK, INFO)
CHETRI
Definition: chetri.f:116
subroutine chemv(UPLO, N, ALPHA, A, LDA, X, INCX, BETA, Y, INCY)
CHEMV
Definition: chemv.f:156
subroutine ccopy(N, CX, INCX, CY, INCY)
CCOPY
Definition: ccopy.f:52
subroutine cswap(N, CX, INCX, CY, INCY)
CSWAP
Definition: cswap.f:52