LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
chetri_rook.f
Go to the documentation of this file.
1*> \brief \b CHETRI_ROOK computes the inverse of HE matrix using the factorization obtained with the bounded Bunch-Kaufman ("rook") diagonal pivoting method.
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download CHETRI_ROOK + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chetri_rook.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetri_rook.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetri_rook.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE CHETRI_ROOK( UPLO, N, A, LDA, IPIV, WORK, INFO )
20*
21* .. Scalar Arguments ..
22* CHARACTER UPLO
23* INTEGER INFO, LDA, N
24* ..
25* .. Array Arguments ..
26* INTEGER IPIV( * )
27* COMPLEX A( LDA, * ), WORK( * )
28* ..
29*
30*
31*> \par Purpose:
32* =============
33*>
34*> \verbatim
35*>
36*> CHETRI_ROOK computes the inverse of a complex Hermitian indefinite matrix
37*> A using the factorization A = U*D*U**H or A = L*D*L**H computed by
38*> CHETRF_ROOK.
39*> \endverbatim
40*
41* Arguments:
42* ==========
43*
44*> \param[in] UPLO
45*> \verbatim
46*> UPLO is CHARACTER*1
47*> Specifies whether the details of the factorization are stored
48*> as an upper or lower triangular matrix.
49*> = 'U': Upper triangular, form is A = U*D*U**H;
50*> = 'L': Lower triangular, form is A = L*D*L**H.
51*> \endverbatim
52*>
53*> \param[in] N
54*> \verbatim
55*> N is INTEGER
56*> The order of the matrix A. N >= 0.
57*> \endverbatim
58*>
59*> \param[in,out] A
60*> \verbatim
61*> A is COMPLEX array, dimension (LDA,N)
62*> On entry, the block diagonal matrix D and the multipliers
63*> used to obtain the factor U or L as computed by CHETRF_ROOK.
64*>
65*> On exit, if INFO = 0, the (Hermitian) inverse of the original
66*> matrix. If UPLO = 'U', the upper triangular part of the
67*> inverse is formed and the part of A below the diagonal is not
68*> referenced; if UPLO = 'L' the lower triangular part of the
69*> inverse is formed and the part of A above the diagonal is
70*> not referenced.
71*> \endverbatim
72*>
73*> \param[in] LDA
74*> \verbatim
75*> LDA is INTEGER
76*> The leading dimension of the array A. LDA >= max(1,N).
77*> \endverbatim
78*>
79*> \param[in] IPIV
80*> \verbatim
81*> IPIV is INTEGER array, dimension (N)
82*> Details of the interchanges and the block structure of D
83*> as determined by CHETRF_ROOK.
84*> \endverbatim
85*>
86*> \param[out] WORK
87*> \verbatim
88*> WORK is COMPLEX array, dimension (N)
89*> \endverbatim
90*>
91*> \param[out] INFO
92*> \verbatim
93*> INFO is INTEGER
94*> = 0: successful exit
95*> < 0: if INFO = -i, the i-th argument had an illegal value
96*> > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its
97*> inverse could not be computed.
98*> \endverbatim
99*
100* Authors:
101* ========
102*
103*> \author Univ. of Tennessee
104*> \author Univ. of California Berkeley
105*> \author Univ. of Colorado Denver
106*> \author NAG Ltd.
107*
108*> \ingroup hetri_rook
109*
110*> \par Contributors:
111* ==================
112*>
113*> \verbatim
114*>
115*> November 2013, Igor Kozachenko,
116*> Computer Science Division,
117*> University of California, Berkeley
118*>
119*> September 2007, Sven Hammarling, Nicholas J. Higham, Craig Lucas,
120*> School of Mathematics,
121*> University of Manchester
122*> \endverbatim
123*
124* =====================================================================
125 SUBROUTINE chetri_rook( UPLO, N, A, LDA, IPIV, WORK, INFO )
126*
127* -- LAPACK computational routine --
128* -- LAPACK is a software package provided by Univ. of Tennessee, --
129* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
130*
131* .. Scalar Arguments ..
132 CHARACTER UPLO
133 INTEGER INFO, LDA, N
134* ..
135* .. Array Arguments ..
136 INTEGER IPIV( * )
137 COMPLEX A( LDA, * ), WORK( * )
138* ..
139*
140* =====================================================================
141*
142* .. Parameters ..
143 REAL ONE
144 COMPLEX CONE, CZERO
145 parameter( one = 1.0e+0, cone = ( 1.0e+0, 0.0e+0 ),
146 $ czero = ( 0.0e+0, 0.0e+0 ) )
147* ..
148* .. Local Scalars ..
149 LOGICAL UPPER
150 INTEGER J, K, KP, KSTEP
151 REAL AK, AKP1, D, T
152 COMPLEX AKKP1, TEMP
153* ..
154* .. External Functions ..
155 LOGICAL LSAME
156 COMPLEX CDOTC
157 EXTERNAL lsame, cdotc
158* ..
159* .. External Subroutines ..
160 EXTERNAL ccopy, chemv, cswap, xerbla
161* ..
162* .. Intrinsic Functions ..
163 INTRINSIC abs, conjg, max, real
164* ..
165* .. Executable Statements ..
166*
167* Test the input parameters.
168*
169 info = 0
170 upper = lsame( uplo, 'U' )
171 IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
172 info = -1
173 ELSE IF( n.LT.0 ) THEN
174 info = -2
175 ELSE IF( lda.LT.max( 1, n ) ) THEN
176 info = -4
177 END IF
178 IF( info.NE.0 ) THEN
179 CALL xerbla( 'CHETRI_ROOK', -info )
180 RETURN
181 END IF
182*
183* Quick return if possible
184*
185 IF( n.EQ.0 )
186 $ RETURN
187*
188* Check that the diagonal matrix D is nonsingular.
189*
190 IF( upper ) THEN
191*
192* Upper triangular storage: examine D from bottom to top
193*
194 DO 10 info = n, 1, -1
195 IF( ipiv( info ).GT.0 .AND. a( info, info ).EQ.czero )
196 $ RETURN
197 10 CONTINUE
198 ELSE
199*
200* Lower triangular storage: examine D from top to bottom.
201*
202 DO 20 info = 1, n
203 IF( ipiv( info ).GT.0 .AND. a( info, info ).EQ.czero )
204 $ RETURN
205 20 CONTINUE
206 END IF
207 info = 0
208*
209 IF( upper ) THEN
210*
211* Compute inv(A) from the factorization A = U*D*U**H.
212*
213* K is the main loop index, increasing from 1 to N in steps of
214* 1 or 2, depending on the size of the diagonal blocks.
215*
216 k = 1
217 30 CONTINUE
218*
219* If K > N, exit from loop.
220*
221 IF( k.GT.n )
222 $ GO TO 70
223*
224 IF( ipiv( k ).GT.0 ) THEN
225*
226* 1 x 1 diagonal block
227*
228* Invert the diagonal block.
229*
230 a( k, k ) = one / real( a( k, k ) )
231*
232* Compute column K of the inverse.
233*
234 IF( k.GT.1 ) THEN
235 CALL ccopy( k-1, a( 1, k ), 1, work, 1 )
236 CALL chemv( uplo, k-1, -cone, a, lda, work, 1, czero,
237 $ a( 1, k ), 1 )
238 a( k, k ) = a( k, k ) - real( cdotc( k-1, work, 1,
239 $ a( 1,
240 $ k ), 1 ) )
241 END IF
242 kstep = 1
243 ELSE
244*
245* 2 x 2 diagonal block
246*
247* Invert the diagonal block.
248*
249 t = abs( a( k, k+1 ) )
250 ak = real( a( k, k ) ) / t
251 akp1 = real( a( k+1, k+1 ) ) / t
252 akkp1 = a( k, k+1 ) / t
253 d = t*( ak*akp1-one )
254 a( k, k ) = akp1 / d
255 a( k+1, k+1 ) = ak / d
256 a( k, k+1 ) = -akkp1 / d
257*
258* Compute columns K and K+1 of the inverse.
259*
260 IF( k.GT.1 ) THEN
261 CALL ccopy( k-1, a( 1, k ), 1, work, 1 )
262 CALL chemv( uplo, k-1, -cone, a, lda, work, 1, czero,
263 $ a( 1, k ), 1 )
264 a( k, k ) = a( k, k ) - real( cdotc( k-1, work, 1,
265 $ a( 1,
266 $ k ), 1 ) )
267 a( k, k+1 ) = a( k, k+1 ) -
268 $ cdotc( k-1, a( 1, k ), 1, a( 1, k+1 ),
269 $ 1 )
270 CALL ccopy( k-1, a( 1, k+1 ), 1, work, 1 )
271 CALL chemv( uplo, k-1, -cone, a, lda, work, 1, czero,
272 $ a( 1, k+1 ), 1 )
273 a( k+1, k+1 ) = a( k+1, k+1 ) -
274 $ real( cdotc( k-1, work, 1, a( 1,
275 $ k+1 ),
276 $ 1 ) )
277 END IF
278 kstep = 2
279 END IF
280*
281 IF( kstep.EQ.1 ) THEN
282*
283* Interchange rows and columns K and IPIV(K) in the leading
284* submatrix A(1:k,1:k)
285*
286 kp = ipiv( k )
287 IF( kp.NE.k ) THEN
288*
289 IF( kp.GT.1 )
290 $ CALL cswap( kp-1, a( 1, k ), 1, a( 1, kp ), 1 )
291*
292 DO 40 j = kp + 1, k - 1
293 temp = conjg( a( j, k ) )
294 a( j, k ) = conjg( a( kp, j ) )
295 a( kp, j ) = temp
296 40 CONTINUE
297*
298 a( kp, k ) = conjg( a( kp, k ) )
299*
300 temp = a( k, k )
301 a( k, k ) = a( kp, kp )
302 a( kp, kp ) = temp
303 END IF
304 ELSE
305*
306* Interchange rows and columns K and K+1 with -IPIV(K) and
307* -IPIV(K+1) in the leading submatrix A(k+1:n,k+1:n)
308*
309* (1) Interchange rows and columns K and -IPIV(K)
310*
311 kp = -ipiv( k )
312 IF( kp.NE.k ) THEN
313*
314 IF( kp.GT.1 )
315 $ CALL cswap( kp-1, a( 1, k ), 1, a( 1, kp ), 1 )
316*
317 DO 50 j = kp + 1, k - 1
318 temp = conjg( a( j, k ) )
319 a( j, k ) = conjg( a( kp, j ) )
320 a( kp, j ) = temp
321 50 CONTINUE
322*
323 a( kp, k ) = conjg( a( kp, k ) )
324*
325 temp = a( k, k )
326 a( k, k ) = a( kp, kp )
327 a( kp, kp ) = temp
328*
329 temp = a( k, k+1 )
330 a( k, k+1 ) = a( kp, k+1 )
331 a( kp, k+1 ) = temp
332 END IF
333*
334* (2) Interchange rows and columns K+1 and -IPIV(K+1)
335*
336 k = k + 1
337 kp = -ipiv( k )
338 IF( kp.NE.k ) THEN
339*
340 IF( kp.GT.1 )
341 $ CALL cswap( kp-1, a( 1, k ), 1, a( 1, kp ), 1 )
342*
343 DO 60 j = kp + 1, k - 1
344 temp = conjg( a( j, k ) )
345 a( j, k ) = conjg( a( kp, j ) )
346 a( kp, j ) = temp
347 60 CONTINUE
348*
349 a( kp, k ) = conjg( a( kp, k ) )
350*
351 temp = a( k, k )
352 a( k, k ) = a( kp, kp )
353 a( kp, kp ) = temp
354 END IF
355 END IF
356*
357 k = k + 1
358 GO TO 30
359 70 CONTINUE
360*
361 ELSE
362*
363* Compute inv(A) from the factorization A = L*D*L**H.
364*
365* K is the main loop index, decreasing from N to 1 in steps of
366* 1 or 2, depending on the size of the diagonal blocks.
367*
368 k = n
369 80 CONTINUE
370*
371* If K < 1, exit from loop.
372*
373 IF( k.LT.1 )
374 $ GO TO 120
375*
376 IF( ipiv( k ).GT.0 ) THEN
377*
378* 1 x 1 diagonal block
379*
380* Invert the diagonal block.
381*
382 a( k, k ) = one / real( a( k, k ) )
383*
384* Compute column K of the inverse.
385*
386 IF( k.LT.n ) THEN
387 CALL ccopy( n-k, a( k+1, k ), 1, work, 1 )
388 CALL chemv( uplo, n-k, -cone, a( k+1, k+1 ), lda,
389 $ work,
390 $ 1, czero, a( k+1, k ), 1 )
391 a( k, k ) = a( k, k ) - real( cdotc( n-k, work, 1,
392 $ a( k+1, k ), 1 ) )
393 END IF
394 kstep = 1
395 ELSE
396*
397* 2 x 2 diagonal block
398*
399* Invert the diagonal block.
400*
401 t = abs( a( k, k-1 ) )
402 ak = real( a( k-1, k-1 ) ) / t
403 akp1 = real( a( k, k ) ) / t
404 akkp1 = a( k, k-1 ) / t
405 d = t*( ak*akp1-one )
406 a( k-1, k-1 ) = akp1 / d
407 a( k, k ) = ak / d
408 a( k, k-1 ) = -akkp1 / d
409*
410* Compute columns K-1 and K of the inverse.
411*
412 IF( k.LT.n ) THEN
413 CALL ccopy( n-k, a( k+1, k ), 1, work, 1 )
414 CALL chemv( uplo, n-k, -cone, a( k+1, k+1 ), lda,
415 $ work,
416 $ 1, czero, a( k+1, k ), 1 )
417 a( k, k ) = a( k, k ) - real( cdotc( n-k, work, 1,
418 $ a( k+1, k ), 1 ) )
419 a( k, k-1 ) = a( k, k-1 ) -
420 $ cdotc( n-k, a( k+1, k ), 1, a( k+1,
421 $ k-1 ),
422 $ 1 )
423 CALL ccopy( n-k, a( k+1, k-1 ), 1, work, 1 )
424 CALL chemv( uplo, n-k, -cone, a( k+1, k+1 ), lda,
425 $ work,
426 $ 1, czero, a( k+1, k-1 ), 1 )
427 a( k-1, k-1 ) = a( k-1, k-1 ) -
428 $ real( cdotc( n-k, work, 1, a( k+1,
429 $ k-1 ),
430 $ 1 ) )
431 END IF
432 kstep = 2
433 END IF
434*
435 IF( kstep.EQ.1 ) THEN
436*
437* Interchange rows and columns K and IPIV(K) in the trailing
438* submatrix A(k:n,k:n)
439*
440 kp = ipiv( k )
441 IF( kp.NE.k ) THEN
442*
443 IF( kp.LT.n )
444 $ CALL cswap( n-kp, a( kp+1, k ), 1, a( kp+1, kp ),
445 $ 1 )
446*
447 DO 90 j = k + 1, kp - 1
448 temp = conjg( a( j, k ) )
449 a( j, k ) = conjg( a( kp, j ) )
450 a( kp, j ) = temp
451 90 CONTINUE
452*
453 a( kp, k ) = conjg( a( kp, k ) )
454*
455 temp = a( k, k )
456 a( k, k ) = a( kp, kp )
457 a( kp, kp ) = temp
458 END IF
459 ELSE
460*
461* Interchange rows and columns K and K-1 with -IPIV(K) and
462* -IPIV(K-1) in the trailing submatrix A(k-1:n,k-1:n)
463*
464* (1) Interchange rows and columns K and -IPIV(K)
465*
466 kp = -ipiv( k )
467 IF( kp.NE.k ) THEN
468*
469 IF( kp.LT.n )
470 $ CALL cswap( n-kp, a( kp+1, k ), 1, a( kp+1, kp ),
471 $ 1 )
472*
473 DO 100 j = k + 1, kp - 1
474 temp = conjg( a( j, k ) )
475 a( j, k ) = conjg( a( kp, j ) )
476 a( kp, j ) = temp
477 100 CONTINUE
478*
479 a( kp, k ) = conjg( a( kp, k ) )
480*
481 temp = a( k, k )
482 a( k, k ) = a( kp, kp )
483 a( kp, kp ) = temp
484*
485 temp = a( k, k-1 )
486 a( k, k-1 ) = a( kp, k-1 )
487 a( kp, k-1 ) = temp
488 END IF
489*
490* (2) Interchange rows and columns K-1 and -IPIV(K-1)
491*
492 k = k - 1
493 kp = -ipiv( k )
494 IF( kp.NE.k ) THEN
495*
496 IF( kp.LT.n )
497 $ CALL cswap( n-kp, a( kp+1, k ), 1, a( kp+1, kp ),
498 $ 1 )
499*
500 DO 110 j = k + 1, kp - 1
501 temp = conjg( a( j, k ) )
502 a( j, k ) = conjg( a( kp, j ) )
503 a( kp, j ) = temp
504 110 CONTINUE
505*
506 a( kp, k ) = conjg( a( kp, k ) )
507*
508 temp = a( k, k )
509 a( k, k ) = a( kp, kp )
510 a( kp, kp ) = temp
511 END IF
512 END IF
513*
514 k = k - 1
515 GO TO 80
516 120 CONTINUE
517 END IF
518*
519 RETURN
520*
521* End of CHETRI_ROOK
522*
523 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine ccopy(n, cx, incx, cy, incy)
CCOPY
Definition ccopy.f:81
subroutine chemv(uplo, n, alpha, a, lda, x, incx, beta, y, incy)
CHEMV
Definition chemv.f:154
subroutine chetri_rook(uplo, n, a, lda, ipiv, work, info)
CHETRI_ROOK computes the inverse of HE matrix using the factorization obtained with the bounded Bunch...
subroutine cswap(n, cx, incx, cy, incy)
CSWAP
Definition cswap.f:81