LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
dsytri2x.f
Go to the documentation of this file.
1*> \brief \b DSYTRI2X
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download DSYTRI2X + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsytri2x.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsytri2x.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsytri2x.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE DSYTRI2X( UPLO, N, A, LDA, IPIV, WORK, NB, INFO )
20*
21* .. Scalar Arguments ..
22* CHARACTER UPLO
23* INTEGER INFO, LDA, N, NB
24* ..
25* .. Array Arguments ..
26* INTEGER IPIV( * )
27* DOUBLE PRECISION A( LDA, * ), WORK( N+NB+1,* )
28* ..
29*
30*
31*> \par Purpose:
32* =============
33*>
34*> \verbatim
35*>
36*> DSYTRI2X computes the inverse of a real symmetric indefinite matrix
37*> A using the factorization A = U*D*U**T or A = L*D*L**T computed by
38*> DSYTRF.
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**T;
50*> = 'L': Lower triangular, form is A = L*D*L**T.
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 DOUBLE PRECISION array, dimension (LDA,N)
62*> On entry, the NNB diagonal matrix D and the multipliers
63*> used to obtain the factor U or L as computed by DSYTRF.
64*>
65*> On exit, if INFO = 0, the (symmetric) 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 NNB structure of D
83*> as determined by DSYTRF.
84*> \endverbatim
85*>
86*> \param[out] WORK
87*> \verbatim
88*> WORK is DOUBLE PRECISION array, dimension (N+NB+1,NB+3)
89*> \endverbatim
90*>
91*> \param[in] NB
92*> \verbatim
93*> NB is INTEGER
94*> Block size
95*> \endverbatim
96*>
97*> \param[out] INFO
98*> \verbatim
99*> INFO is INTEGER
100*> = 0: successful exit
101*> < 0: if INFO = -i, the i-th argument had an illegal value
102*> > 0: if INFO = i, D(i,i) = 0; the matrix is singular and its
103*> inverse could not be computed.
104*> \endverbatim
105*
106* Authors:
107* ========
108*
109*> \author Univ. of Tennessee
110*> \author Univ. of California Berkeley
111*> \author Univ. of Colorado Denver
112*> \author NAG Ltd.
113*
114*> \ingroup hetri2x
115*
116* =====================================================================
117 SUBROUTINE dsytri2x( UPLO, N, A, LDA, IPIV, WORK, NB, INFO )
118*
119* -- LAPACK computational routine --
120* -- LAPACK is a software package provided by Univ. of Tennessee, --
121* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
122*
123* .. Scalar Arguments ..
124 CHARACTER UPLO
125 INTEGER INFO, LDA, N, NB
126* ..
127* .. Array Arguments ..
128 INTEGER IPIV( * )
129 DOUBLE PRECISION A( LDA, * ), WORK( N+NB+1,* )
130* ..
131*
132* =====================================================================
133*
134* .. Parameters ..
135 DOUBLE PRECISION ONE, ZERO
136 parameter( one = 1.0d+0, zero = 0.0d+0 )
137* ..
138* .. Local Scalars ..
139 LOGICAL UPPER
140 INTEGER I, IINFO, IP, K, CUT, NNB
141 INTEGER COUNT
142 INTEGER J, U11, INVD
143
144 DOUBLE PRECISION AK, AKKP1, AKP1, D, T
145 DOUBLE PRECISION U01_I_J, U01_IP1_J
146 DOUBLE PRECISION U11_I_J, U11_IP1_J
147* ..
148* .. External Functions ..
149 LOGICAL LSAME
150 EXTERNAL lsame
151* ..
152* .. External Subroutines ..
153 EXTERNAL dsyconv, xerbla, dtrtri
154 EXTERNAL dgemm, dtrmm, dsyswapr
155* ..
156* .. Intrinsic Functions ..
157 INTRINSIC max
158* ..
159* .. Executable Statements ..
160*
161* Test the input parameters.
162*
163 info = 0
164 upper = lsame( uplo, 'U' )
165 IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
166 info = -1
167 ELSE IF( n.LT.0 ) THEN
168 info = -2
169 ELSE IF( lda.LT.max( 1, n ) ) THEN
170 info = -4
171 END IF
172*
173* Quick return if possible
174*
175*
176 IF( info.NE.0 ) THEN
177 CALL xerbla( 'DSYTRI2X', -info )
178 RETURN
179 END IF
180 IF( n.EQ.0 )
181 $ RETURN
182*
183* Convert A
184* Workspace got Non-diag elements of D
185*
186 CALL dsyconv( uplo, 'C', n, a, lda, ipiv, work, iinfo )
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 info = n, 1, -1
195 IF( ipiv( info ).GT.0 .AND. a( info, info ).EQ.zero )
196 $ RETURN
197 END DO
198 ELSE
199*
200* Lower triangular storage: examine D from top to bottom.
201*
202 DO info = 1, n
203 IF( ipiv( info ).GT.0 .AND. a( info, info ).EQ.zero )
204 $ RETURN
205 END DO
206 END IF
207 info = 0
208*
209* Splitting Workspace
210* U01 is a block (N,NB+1)
211* The first element of U01 is in WORK(1,1)
212* U11 is a block (NB+1,NB+1)
213* The first element of U11 is in WORK(N+1,1)
214 u11 = n
215* INVD is a block (N,2)
216* The first element of INVD is in WORK(1,INVD)
217 invd = nb+2
218
219 IF( upper ) THEN
220*
221* invA = P * inv(U**T)*inv(D)*inv(U)*P**T.
222*
223 CALL dtrtri( uplo, 'U', n, a, lda, info )
224*
225* inv(D) and inv(D)*inv(U)
226*
227 k=1
228 DO WHILE ( k .LE. n )
229 IF( ipiv( k ).GT.0 ) THEN
230* 1 x 1 diagonal NNB
231 work(k,invd) = one / a( k, k )
232 work(k,invd+1) = 0
233 k=k+1
234 ELSE
235* 2 x 2 diagonal NNB
236 t = work(k+1,1)
237 ak = a( k, k ) / t
238 akp1 = a( k+1, k+1 ) / t
239 akkp1 = work(k+1,1) / t
240 d = t*( ak*akp1-one )
241 work(k,invd) = akp1 / d
242 work(k+1,invd+1) = ak / d
243 work(k,invd+1) = -akkp1 / d
244 work(k+1,invd) = -akkp1 / d
245 k=k+2
246 END IF
247 END DO
248*
249* inv(U**T) = (inv(U))**T
250*
251* inv(U**T)*inv(D)*inv(U)
252*
253 cut=n
254 DO WHILE (cut .GT. 0)
255 nnb=nb
256 IF (cut .LE. nnb) THEN
257 nnb=cut
258 ELSE
259 count = 0
260* count negative elements,
261 DO i=cut+1-nnb,cut
262 IF (ipiv(i) .LT. 0) count=count+1
263 END DO
264* need a even number for a clear cut
265 IF (mod(count,2) .EQ. 1) nnb=nnb+1
266 END IF
267
268 cut=cut-nnb
269*
270* U01 Block
271*
272 DO i=1,cut
273 DO j=1,nnb
274 work(i,j)=a(i,cut+j)
275 END DO
276 END DO
277*
278* U11 Block
279*
280 DO i=1,nnb
281 work(u11+i,i)=one
282 DO j=1,i-1
283 work(u11+i,j)=zero
284 END DO
285 DO j=i+1,nnb
286 work(u11+i,j)=a(cut+i,cut+j)
287 END DO
288 END DO
289*
290* invD*U01
291*
292 i=1
293 DO WHILE (i .LE. cut)
294 IF (ipiv(i) > 0) THEN
295 DO j=1,nnb
296 work(i,j)=work(i,invd)*work(i,j)
297 END DO
298 i=i+1
299 ELSE
300 DO j=1,nnb
301 u01_i_j = work(i,j)
302 u01_ip1_j = work(i+1,j)
303 work(i,j)=work(i,invd)*u01_i_j+
304 $ work(i,invd+1)*u01_ip1_j
305 work(i+1,j)=work(i+1,invd)*u01_i_j+
306 $ work(i+1,invd+1)*u01_ip1_j
307 END DO
308 i=i+2
309 END IF
310 END DO
311*
312* invD1*U11
313*
314 i=1
315 DO WHILE (i .LE. nnb)
316 IF (ipiv(cut+i) > 0) THEN
317 DO j=i,nnb
318 work(u11+i,j)=work(cut+i,invd)*work(u11+i,j)
319 END DO
320 i=i+1
321 ELSE
322 DO j=i,nnb
323 u11_i_j = work(u11+i,j)
324 u11_ip1_j = work(u11+i+1,j)
325 work(u11+i,j)=work(cut+i,invd)*work(u11+i,j) +
326 $ work(cut+i,invd+1)*work(u11+i+1,j)
327 work(u11+i+1,j)=work(cut+i+1,invd)*u11_i_j+
328 $ work(cut+i+1,invd+1)*u11_ip1_j
329 END DO
330 i=i+2
331 END IF
332 END DO
333*
334* U11**T*invD1*U11->U11
335*
336 CALL dtrmm('L','U','T','U',nnb, nnb,
337 $ one,a(cut+1,cut+1),lda,work(u11+1,1),n+nb+1)
338*
339 DO i=1,nnb
340 DO j=i,nnb
341 a(cut+i,cut+j)=work(u11+i,j)
342 END DO
343 END DO
344*
345* U01**T*invD*U01->A(CUT+I,CUT+J)
346*
347 CALL dgemm('T','N',nnb,nnb,cut,one,a(1,cut+1),lda,
348 $ work,n+nb+1, zero, work(u11+1,1), n+nb+1)
349
350*
351* U11 = U11**T*invD1*U11 + U01**T*invD*U01
352*
353 DO i=1,nnb
354 DO j=i,nnb
355 a(cut+i,cut+j)=a(cut+i,cut+j)+work(u11+i,j)
356 END DO
357 END DO
358*
359* U01 = U00**T*invD0*U01
360*
361 CALL dtrmm('L',uplo,'T','U',cut, nnb,
362 $ one,a,lda,work,n+nb+1)
363
364*
365* Update U01
366*
367 DO i=1,cut
368 DO j=1,nnb
369 a(i,cut+j)=work(i,j)
370 END DO
371 END DO
372*
373* Next Block
374*
375 END DO
376*
377* Apply PERMUTATIONS P and P**T: P * inv(U**T)*inv(D)*inv(U) *P**T
378*
379 i=1
380 DO WHILE ( i .LE. n )
381 IF( ipiv(i) .GT. 0 ) THEN
382 ip=ipiv(i)
383 IF (i .LT. ip) CALL dsyswapr( uplo, n, a, lda, i ,
384 $ ip )
385 IF (i .GT. ip) CALL dsyswapr( uplo, n, a, lda, ip ,
386 $ i )
387 ELSE
388 ip=-ipiv(i)
389 i=i+1
390 IF ( (i-1) .LT. ip)
391 $ CALL dsyswapr( uplo, n, a, lda, i-1 ,ip )
392 IF ( (i-1) .GT. ip)
393 $ CALL dsyswapr( uplo, n, a, lda, ip ,i-1 )
394 ENDIF
395 i=i+1
396 END DO
397 ELSE
398*
399* LOWER...
400*
401* invA = P * inv(U**T)*inv(D)*inv(U)*P**T.
402*
403 CALL dtrtri( uplo, 'U', n, a, lda, info )
404*
405* inv(D) and inv(D)*inv(U)
406*
407 k=n
408 DO WHILE ( k .GE. 1 )
409 IF( ipiv( k ).GT.0 ) THEN
410* 1 x 1 diagonal NNB
411 work(k,invd) = one / a( k, k )
412 work(k,invd+1) = 0
413 k=k-1
414 ELSE
415* 2 x 2 diagonal NNB
416 t = work(k-1,1)
417 ak = a( k-1, k-1 ) / t
418 akp1 = a( k, k ) / t
419 akkp1 = work(k-1,1) / t
420 d = t*( ak*akp1-one )
421 work(k-1,invd) = akp1 / d
422 work(k,invd) = ak / d
423 work(k,invd+1) = -akkp1 / d
424 work(k-1,invd+1) = -akkp1 / d
425 k=k-2
426 END IF
427 END DO
428*
429* inv(U**T) = (inv(U))**T
430*
431* inv(U**T)*inv(D)*inv(U)
432*
433 cut=0
434 DO WHILE (cut .LT. n)
435 nnb=nb
436 IF (cut + nnb .GT. n) THEN
437 nnb=n-cut
438 ELSE
439 count = 0
440* count negative elements,
441 DO i=cut+1,cut+nnb
442 IF (ipiv(i) .LT. 0) count=count+1
443 END DO
444* need a even number for a clear cut
445 IF (mod(count,2) .EQ. 1) nnb=nnb+1
446 END IF
447* L21 Block
448 DO i=1,n-cut-nnb
449 DO j=1,nnb
450 work(i,j)=a(cut+nnb+i,cut+j)
451 END DO
452 END DO
453* L11 Block
454 DO i=1,nnb
455 work(u11+i,i)=one
456 DO j=i+1,nnb
457 work(u11+i,j)=zero
458 END DO
459 DO j=1,i-1
460 work(u11+i,j)=a(cut+i,cut+j)
461 END DO
462 END DO
463*
464* invD*L21
465*
466 i=n-cut-nnb
467 DO WHILE (i .GE. 1)
468 IF (ipiv(cut+nnb+i) > 0) THEN
469 DO j=1,nnb
470 work(i,j)=work(cut+nnb+i,invd)*work(i,j)
471 END DO
472 i=i-1
473 ELSE
474 DO j=1,nnb
475 u01_i_j = work(i,j)
476 u01_ip1_j = work(i-1,j)
477 work(i,j)=work(cut+nnb+i,invd)*u01_i_j+
478 $ work(cut+nnb+i,invd+1)*u01_ip1_j
479 work(i-1,j)=work(cut+nnb+i-1,invd+1)*u01_i_j+
480 $ work(cut+nnb+i-1,invd)*u01_ip1_j
481 END DO
482 i=i-2
483 END IF
484 END DO
485*
486* invD1*L11
487*
488 i=nnb
489 DO WHILE (i .GE. 1)
490 IF (ipiv(cut+i) > 0) THEN
491 DO j=1,nnb
492 work(u11+i,j)=work(cut+i,invd)*work(u11+i,j)
493 END DO
494 i=i-1
495 ELSE
496 DO j=1,nnb
497 u11_i_j = work(u11+i,j)
498 u11_ip1_j = work(u11+i-1,j)
499 work(u11+i,j)=work(cut+i,invd)*work(u11+i,j) +
500 $ work(cut+i,invd+1)*u11_ip1_j
501 work(u11+i-1,j)=work(cut+i-1,invd+1)*u11_i_j+
502 $ work(cut+i-1,invd)*u11_ip1_j
503 END DO
504 i=i-2
505 END IF
506 END DO
507*
508* L11**T*invD1*L11->L11
509*
510 CALL dtrmm('L',uplo,'T','U',nnb, nnb,
511 $ one,a(cut+1,cut+1),lda,work(u11+1,1),n+nb+1)
512
513*
514 DO i=1,nnb
515 DO j=1,i
516 a(cut+i,cut+j)=work(u11+i,j)
517 END DO
518 END DO
519*
520 IF ( (cut+nnb) .LT. n ) THEN
521*
522* L21**T*invD2*L21->A(CUT+I,CUT+J)
523*
524 CALL dgemm('T','N',nnb,nnb,n-nnb-cut,one,a(cut+nnb+1,cut+1)
525 $ ,lda,work,n+nb+1, zero, work(u11+1,1), n+nb+1)
526
527*
528* L11 = L11**T*invD1*L11 + U01**T*invD*U01
529*
530 DO i=1,nnb
531 DO j=1,i
532 a(cut+i,cut+j)=a(cut+i,cut+j)+work(u11+i,j)
533 END DO
534 END DO
535*
536* L01 = L22**T*invD2*L21
537*
538 CALL dtrmm('L',uplo,'T','U', n-nnb-cut, nnb,
539 $ one,a(cut+nnb+1,cut+nnb+1),lda,work,n+nb+1)
540*
541* Update L21
542*
543 DO i=1,n-cut-nnb
544 DO j=1,nnb
545 a(cut+nnb+i,cut+j)=work(i,j)
546 END DO
547 END DO
548
549 ELSE
550*
551* L11 = L11**T*invD1*L11
552*
553 DO i=1,nnb
554 DO j=1,i
555 a(cut+i,cut+j)=work(u11+i,j)
556 END DO
557 END DO
558 END IF
559*
560* Next Block
561*
562 cut=cut+nnb
563 END DO
564*
565* Apply PERMUTATIONS P and P**T: P * inv(U**T)*inv(D)*inv(U) *P**T
566*
567 i=n
568 DO WHILE ( i .GE. 1 )
569 IF( ipiv(i) .GT. 0 ) THEN
570 ip=ipiv(i)
571 IF (i .LT. ip) CALL dsyswapr( uplo, n, a, lda, i ,
572 $ ip )
573 IF (i .GT. ip) CALL dsyswapr( uplo, n, a, lda, ip ,
574 $ i )
575 ELSE
576 ip=-ipiv(i)
577 IF ( i .LT. ip) CALL dsyswapr( uplo, n, a, lda, i ,
578 $ ip )
579 IF ( i .GT. ip) CALL dsyswapr( uplo, n, a, lda, ip,
580 $ i )
581 i=i-1
582 ENDIF
583 i=i-1
584 END DO
585 END IF
586*
587 RETURN
588*
589* End of DSYTRI2X
590*
591 END
592
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine dgemm(transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc)
DGEMM
Definition dgemm.f:188
subroutine dsyswapr(uplo, n, a, lda, i1, i2)
DSYSWAPR applies an elementary permutation on the rows and columns of a symmetric matrix.
Definition dsyswapr.f:98
subroutine dsytri2x(uplo, n, a, lda, ipiv, work, nb, info)
DSYTRI2X
Definition dsytri2x.f:118
subroutine dsyconv(uplo, way, n, a, lda, ipiv, e, info)
DSYCONV
Definition dsyconv.f:112
subroutine dtrmm(side, uplo, transa, diag, m, n, alpha, a, lda, b, ldb)
DTRMM
Definition dtrmm.f:177
subroutine dtrtri(uplo, diag, n, a, lda, info)
DTRTRI
Definition dtrtri.f:107