LAPACK 3.12.0 LAPACK: Linear Algebra PACKage
Searching...
No Matches
chetf2.f
Go to the documentation of this file.
1*> \brief \b CHETF2 computes the factorization of a complex Hermitian matrix, using the diagonal pivoting method (unblocked algorithm calling Level 2 BLAS).
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/chetf2.f">
11*> [TGZ]</a>
12*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetf2.f">
13*> [ZIP]</a>
14*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetf2.f">
15*> [TXT]</a>
16*> \endhtmlonly
17*
18* Definition:
19* ===========
20*
21* SUBROUTINE CHETF2( UPLO, N, A, LDA, IPIV, INFO )
22*
23* .. Scalar Arguments ..
24* CHARACTER UPLO
25* INTEGER INFO, LDA, N
26* ..
27* .. Array Arguments ..
28* INTEGER IPIV( * )
29* COMPLEX A( LDA, * )
30* ..
31*
32*
33*> \par Purpose:
34* =============
35*>
36*> \verbatim
37*>
38*> CHETF2 computes the factorization of a complex Hermitian matrix A
39*> using the Bunch-Kaufman diagonal pivoting method:
40*>
41*> A = U*D*U**H or A = L*D*L**H
42*>
43*> where U (or L) is a product of permutation and unit upper (lower)
44*> triangular matrices, U**H is the conjugate transpose of U, and D is
45*> Hermitian and block diagonal with 1-by-1 and 2-by-2 diagonal blocks.
46*>
47*> This is the unblocked version of the algorithm, calling Level 2 BLAS.
48*> \endverbatim
49*
50* Arguments:
51* ==========
52*
53*> \param[in] UPLO
54*> \verbatim
55*> UPLO is CHARACTER*1
56*> Specifies whether the upper or lower triangular part of the
57*> Hermitian matrix A is stored:
58*> = 'U': Upper triangular
59*> = 'L': Lower triangular
60*> \endverbatim
61*>
62*> \param[in] N
63*> \verbatim
64*> N is INTEGER
65*> The order of the matrix A. N >= 0.
66*> \endverbatim
67*>
68*> \param[in,out] A
69*> \verbatim
70*> A is COMPLEX array, dimension (LDA,N)
71*> On entry, the Hermitian matrix A. If UPLO = 'U', the leading
72*> n-by-n upper triangular part of A contains the upper
73*> triangular part of the matrix A, and the strictly lower
74*> triangular part of A is not referenced. If UPLO = 'L', the
75*> leading n-by-n lower triangular part of A contains the lower
76*> triangular part of the matrix A, and the strictly upper
77*> triangular part of A is not referenced.
78*>
79*> On exit, the block diagonal matrix D and the multipliers used
80*> to obtain the factor U or L (see below for further details).
81*> \endverbatim
82*>
83*> \param[in] LDA
84*> \verbatim
85*> LDA is INTEGER
86*> The leading dimension of the array A. LDA >= max(1,N).
87*> \endverbatim
88*>
89*> \param[out] IPIV
90*> \verbatim
91*> IPIV is INTEGER array, dimension (N)
92*> Details of the interchanges and the block structure of D.
93*>
94*> If UPLO = 'U':
95*> If IPIV(k) > 0, then rows and columns k and IPIV(k) were
96*> interchanged and D(k,k) is a 1-by-1 diagonal block.
97*>
98*> If IPIV(k) = IPIV(k-1) < 0, then rows and columns
99*> k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k)
100*> is a 2-by-2 diagonal block.
101*>
102*> If UPLO = 'L':
103*> If IPIV(k) > 0, then rows and columns k and IPIV(k) were
104*> interchanged and D(k,k) is a 1-by-1 diagonal block.
105*>
106*> If IPIV(k) = IPIV(k+1) < 0, then rows and columns
107*> k+1 and -IPIV(k) were interchanged and D(k:k+1,k:k+1)
108*> is a 2-by-2 diagonal block.
109*> \endverbatim
110*>
111*> \param[out] INFO
112*> \verbatim
113*> INFO is INTEGER
114*> = 0: successful exit
115*> < 0: if INFO = -k, the k-th argument had an illegal value
116*> > 0: if INFO = k, D(k,k) is exactly zero. The factorization
117*> has been completed, but the block diagonal matrix D is
118*> exactly singular, and division by zero will occur if it
119*> is used to solve a system of equations.
120*> \endverbatim
121*
122* Authors:
123* ========
124*
125*> \author Univ. of Tennessee
126*> \author Univ. of California Berkeley
127*> \author Univ. of Colorado Denver
128*> \author NAG Ltd.
129*
130*> \ingroup hetf2
131*
132*> \par Further Details:
133* =====================
134*>
135*> \verbatim
136*>
137*> 09-29-06 - patch from
138*> Bobby Cheng, MathWorks
139*>
140*> Replace l.210 and l.392
141*> IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
142*> by
143*> IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. SISNAN(ABSAKK) ) THEN
144*>
145*> 01-01-96 - Based on modifications by
146*> J. Lewis, Boeing Computer Services Company
147*> A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA
148*>
149*> If UPLO = 'U', then A = U*D*U**H, where
150*> U = P(n)*U(n)* ... *P(k)U(k)* ...,
151*> i.e., U is a product of terms P(k)*U(k), where k decreases from n to
152*> 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
153*> and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as
154*> defined by IPIV(k), and U(k) is a unit upper triangular matrix, such
155*> that if the diagonal block D(k) is of order s (s = 1 or 2), then
156*>
157*> ( I v 0 ) k-s
158*> U(k) = ( 0 I 0 ) s
159*> ( 0 0 I ) n-k
160*> k-s s n-k
161*>
162*> If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k).
163*> If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k),
164*> and A(k,k), and v overwrites A(1:k-2,k-1:k).
165*>
166*> If UPLO = 'L', then A = L*D*L**H, where
167*> L = P(1)*L(1)* ... *P(k)*L(k)* ...,
168*> i.e., L is a product of terms P(k)*L(k), where k increases from 1 to
169*> n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
170*> and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as
171*> defined by IPIV(k), and L(k) is a unit lower triangular matrix, such
172*> that if the diagonal block D(k) is of order s (s = 1 or 2), then
173*>
174*> ( I 0 0 ) k-1
175*> L(k) = ( 0 I 0 ) s
176*> ( 0 v I ) n-k-s+1
177*> k-1 s n-k-s+1
178*>
179*> If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k).
180*> If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k),
181*> and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1).
182*> \endverbatim
183*>
184* =====================================================================
185 SUBROUTINE chetf2( UPLO, N, A, LDA, IPIV, INFO )
186*
187* -- LAPACK computational routine --
188* -- LAPACK is a software package provided by Univ. of Tennessee, --
189* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
190*
191* .. Scalar Arguments ..
192 CHARACTER UPLO
193 INTEGER INFO, LDA, N
194* ..
195* .. Array Arguments ..
196 INTEGER IPIV( * )
197 COMPLEX A( LDA, * )
198* ..
199*
200* =====================================================================
201*
202* .. Parameters ..
203 REAL ZERO, ONE
204 parameter( zero = 0.0e+0, one = 1.0e+0 )
205 REAL EIGHT, SEVTEN
206 parameter( eight = 8.0e+0, sevten = 17.0e+0 )
207* ..
208* .. Local Scalars ..
209 LOGICAL UPPER
210 INTEGER I, IMAX, J, JMAX, K, KK, KP, KSTEP
211 REAL ABSAKK, ALPHA, COLMAX, D, D11, D22, R1, ROWMAX,
212 \$ TT
213 COMPLEX D12, D21, T, WK, WKM1, WKP1, ZDUM
214* ..
215* .. External Functions ..
216 LOGICAL LSAME, SISNAN
217 INTEGER ICAMAX
218 REAL SLAPY2
219 EXTERNAL lsame, icamax, slapy2, sisnan
220* ..
221* .. External Subroutines ..
222 EXTERNAL cher, csscal, cswap, xerbla
223* ..
224* .. Intrinsic Functions ..
225 INTRINSIC abs, aimag, cmplx, conjg, max, real, sqrt
226* ..
227* .. Statement Functions ..
228 REAL CABS1
229* ..
230* .. Statement Function definitions ..
231 cabs1( zdum ) = abs( real( zdum ) ) + abs( aimag( zdum ) )
232* ..
233* .. Executable Statements ..
234*
235* Test the input parameters.
236*
237 info = 0
238 upper = lsame( uplo, 'U' )
239 IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
240 info = -1
241 ELSE IF( n.LT.0 ) THEN
242 info = -2
243 ELSE IF( lda.LT.max( 1, n ) ) THEN
244 info = -4
245 END IF
246 IF( info.NE.0 ) THEN
247 CALL xerbla( 'CHETF2', -info )
248 RETURN
249 END IF
250*
251* Initialize ALPHA for use in choosing pivot block size.
252*
253 alpha = ( one+sqrt( sevten ) ) / eight
254*
255 IF( upper ) THEN
256*
257* Factorize A as U*D*U**H using the upper triangle of A
258*
259* K is the main loop index, decreasing from N to 1 in steps of
260* 1 or 2
261*
262 k = n
263 10 CONTINUE
264*
265* If K < 1, exit from loop
266*
267 IF( k.LT.1 )
268 \$ GO TO 90
269 kstep = 1
270*
271* Determine rows and columns to be interchanged and whether
272* a 1-by-1 or 2-by-2 pivot block will be used
273*
274 absakk = abs( real( a( k, k ) ) )
275*
276* IMAX is the row-index of the largest off-diagonal element in
277* column K, and COLMAX is its absolute value.
278* Determine both COLMAX and IMAX.
279*
280 IF( k.GT.1 ) THEN
281 imax = icamax( k-1, a( 1, k ), 1 )
282 colmax = cabs1( a( imax, k ) )
283 ELSE
284 colmax = zero
285 END IF
286*
287 IF( (max( absakk, colmax ).EQ.zero) .OR. sisnan(absakk) ) THEN
288*
289* Column K is or underflow, or contains a NaN:
290* set INFO and continue
291*
292 IF( info.EQ.0 )
293 \$ info = k
294 kp = k
295 a( k, k ) = real( a( k, k ) )
296 ELSE
297 IF( absakk.GE.alpha*colmax ) THEN
298*
299* no interchange, use 1-by-1 pivot block
300*
301 kp = k
302 ELSE
303*
304* JMAX is the column-index of the largest off-diagonal
305* element in row IMAX, and ROWMAX is its absolute value
306*
307 jmax = imax + icamax( k-imax, a( imax, imax+1 ), lda )
308 rowmax = cabs1( a( imax, jmax ) )
309 IF( imax.GT.1 ) THEN
310 jmax = icamax( imax-1, a( 1, imax ), 1 )
311 rowmax = max( rowmax, cabs1( a( jmax, imax ) ) )
312 END IF
313*
314 IF( absakk.GE.alpha*colmax*( colmax / rowmax ) ) THEN
315*
316* no interchange, use 1-by-1 pivot block
317*
318 kp = k
319 ELSE IF( abs( real( a( imax, imax ) ) ).GE.alpha*rowmax )
320 \$ THEN
321*
322* interchange rows and columns K and IMAX, use 1-by-1
323* pivot block
324*
325 kp = imax
326 ELSE
327*
328* interchange rows and columns K-1 and IMAX, use 2-by-2
329* pivot block
330*
331 kp = imax
332 kstep = 2
333 END IF
334 END IF
335*
336 kk = k - kstep + 1
337 IF( kp.NE.kk ) THEN
338*
339* Interchange rows and columns KK and KP in the leading
340* submatrix A(1:k,1:k)
341*
342 CALL cswap( kp-1, a( 1, kk ), 1, a( 1, kp ), 1 )
343 DO 20 j = kp + 1, kk - 1
344 t = conjg( a( j, kk ) )
345 a( j, kk ) = conjg( a( kp, j ) )
346 a( kp, j ) = t
347 20 CONTINUE
348 a( kp, kk ) = conjg( a( kp, kk ) )
349 r1 = real( a( kk, kk ) )
350 a( kk, kk ) = real( a( kp, kp ) )
351 a( kp, kp ) = r1
352 IF( kstep.EQ.2 ) THEN
353 a( k, k ) = real( a( k, k ) )
354 t = a( k-1, k )
355 a( k-1, k ) = a( kp, k )
356 a( kp, k ) = t
357 END IF
358 ELSE
359 a( k, k ) = real( a( k, k ) )
360 IF( kstep.EQ.2 )
361 \$ a( k-1, k-1 ) = real( a( k-1, k-1 ) )
362 END IF
363*
365*
366 IF( kstep.EQ.1 ) THEN
367*
368* 1-by-1 pivot block D(k): column k now holds
369*
370* W(k) = U(k)*D(k)
371*
372* where U(k) is the k-th column of U
373*
374* Perform a rank-1 update of A(1:k-1,1:k-1) as
375*
376* A := A - U(k)*D(k)*U(k)**H = A - W(k)*1/D(k)*W(k)**H
377*
378 r1 = one / real( a( k, k ) )
379 CALL cher( uplo, k-1, -r1, a( 1, k ), 1, a, lda )
380*
381* Store U(k) in column k
382*
383 CALL csscal( k-1, r1, a( 1, k ), 1 )
384 ELSE
385*
386* 2-by-2 pivot block D(k): columns k and k-1 now hold
387*
388* ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k)
389*
390* where U(k) and U(k-1) are the k-th and (k-1)-th columns
391* of U
392*
393* Perform a rank-2 update of A(1:k-2,1:k-2) as
394*
395* A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**H
396* = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )**H
397*
398 IF( k.GT.2 ) THEN
399*
400 d = slapy2( real( a( k-1, k ) ),
401 \$ aimag( a( k-1, k ) ) )
402 d22 = real( a( k-1, k-1 ) ) / d
403 d11 = real( a( k, k ) ) / d
404 tt = one / ( d11*d22-one )
405 d12 = a( k-1, k ) / d
406 d = tt / d
407*
408 DO 40 j = k - 2, 1, -1
409 wkm1 = d*( d11*a( j, k-1 )-conjg( d12 )*a( j, k ) )
410 wk = d*( d22*a( j, k )-d12*a( j, k-1 ) )
411 DO 30 i = j, 1, -1
412 a( i, j ) = a( i, j ) - a( i, k )*conjg( wk ) -
413 \$ a( i, k-1 )*conjg( wkm1 )
414 30 CONTINUE
415 a( j, k ) = wk
416 a( j, k-1 ) = wkm1
417 a( j, j ) = cmplx( real( a( j, j ) ), 0.0e+0 )
418 40 CONTINUE
419*
420 END IF
421*
422 END IF
423 END IF
424*
425* Store details of the interchanges in IPIV
426*
427 IF( kstep.EQ.1 ) THEN
428 ipiv( k ) = kp
429 ELSE
430 ipiv( k ) = -kp
431 ipiv( k-1 ) = -kp
432 END IF
433*
434* Decrease K and return to the start of the main loop
435*
436 k = k - kstep
437 GO TO 10
438*
439 ELSE
440*
441* Factorize A as L*D*L**H using the lower triangle of A
442*
443* K is the main loop index, increasing from 1 to N in steps of
444* 1 or 2
445*
446 k = 1
447 50 CONTINUE
448*
449* If K > N, exit from loop
450*
451 IF( k.GT.n )
452 \$ GO TO 90
453 kstep = 1
454*
455* Determine rows and columns to be interchanged and whether
456* a 1-by-1 or 2-by-2 pivot block will be used
457*
458 absakk = abs( real( a( k, k ) ) )
459*
460* IMAX is the row-index of the largest off-diagonal element in
461* column K, and COLMAX is its absolute value.
462* Determine both COLMAX and IMAX.
463*
464 IF( k.LT.n ) THEN
465 imax = k + icamax( n-k, a( k+1, k ), 1 )
466 colmax = cabs1( a( imax, k ) )
467 ELSE
468 colmax = zero
469 END IF
470*
471 IF( (max( absakk, colmax ).EQ.zero) .OR. sisnan(absakk) ) THEN
472*
473* Column K is zero or underflow, contains a NaN:
474* set INFO and continue
475*
476 IF( info.EQ.0 )
477 \$ info = k
478 kp = k
479 a( k, k ) = real( a( k, k ) )
480 ELSE
481 IF( absakk.GE.alpha*colmax ) THEN
482*
483* no interchange, use 1-by-1 pivot block
484*
485 kp = k
486 ELSE
487*
488* JMAX is the column-index of the largest off-diagonal
489* element in row IMAX, and ROWMAX is its absolute value
490*
491 jmax = k - 1 + icamax( imax-k, a( imax, k ), lda )
492 rowmax = cabs1( a( imax, jmax ) )
493 IF( imax.LT.n ) THEN
494 jmax = imax + icamax( n-imax, a( imax+1, imax ), 1 )
495 rowmax = max( rowmax, cabs1( a( jmax, imax ) ) )
496 END IF
497*
498 IF( absakk.GE.alpha*colmax*( colmax / rowmax ) ) THEN
499*
500* no interchange, use 1-by-1 pivot block
501*
502 kp = k
503 ELSE IF( abs( real( a( imax, imax ) ) ).GE.alpha*rowmax )
504 \$ THEN
505*
506* interchange rows and columns K and IMAX, use 1-by-1
507* pivot block
508*
509 kp = imax
510 ELSE
511*
512* interchange rows and columns K+1 and IMAX, use 2-by-2
513* pivot block
514*
515 kp = imax
516 kstep = 2
517 END IF
518 END IF
519*
520 kk = k + kstep - 1
521 IF( kp.NE.kk ) THEN
522*
523* Interchange rows and columns KK and KP in the trailing
524* submatrix A(k:n,k:n)
525*
526 IF( kp.LT.n )
527 \$ CALL cswap( n-kp, a( kp+1, kk ), 1, a( kp+1, kp ), 1 )
528 DO 60 j = kk + 1, kp - 1
529 t = conjg( a( j, kk ) )
530 a( j, kk ) = conjg( a( kp, j ) )
531 a( kp, j ) = t
532 60 CONTINUE
533 a( kp, kk ) = conjg( a( kp, kk ) )
534 r1 = real( a( kk, kk ) )
535 a( kk, kk ) = real( a( kp, kp ) )
536 a( kp, kp ) = r1
537 IF( kstep.EQ.2 ) THEN
538 a( k, k ) = real( a( k, k ) )
539 t = a( k+1, k )
540 a( k+1, k ) = a( kp, k )
541 a( kp, k ) = t
542 END IF
543 ELSE
544 a( k, k ) = real( a( k, k ) )
545 IF( kstep.EQ.2 )
546 \$ a( k+1, k+1 ) = real( a( k+1, k+1 ) )
547 END IF
548*
549* Update the trailing submatrix
550*
551 IF( kstep.EQ.1 ) THEN
552*
553* 1-by-1 pivot block D(k): column k now holds
554*
555* W(k) = L(k)*D(k)
556*
557* where L(k) is the k-th column of L
558*
559 IF( k.LT.n ) THEN
560*
561* Perform a rank-1 update of A(k+1:n,k+1:n) as
562*
563* A := A - L(k)*D(k)*L(k)**H = A - W(k)*(1/D(k))*W(k)**H
564*
565 r1 = one / real( a( k, k ) )
566 CALL cher( uplo, n-k, -r1, a( k+1, k ), 1,
567 \$ a( k+1, k+1 ), lda )
568*
569* Store L(k) in column K
570*
571 CALL csscal( n-k, r1, a( k+1, k ), 1 )
572 END IF
573 ELSE
574*
575* 2-by-2 pivot block D(k)
576*
577 IF( k.LT.n-1 ) THEN
578*
579* Perform a rank-2 update of A(k+2:n,k+2:n) as
580*
581* A := A - ( L(k) L(k+1) )*D(k)*( L(k) L(k+1) )**H
582* = A - ( W(k) W(k+1) )*inv(D(k))*( W(k) W(k+1) )**H
583*
584* where L(k) and L(k+1) are the k-th and (k+1)-th
585* columns of L
586*
587 d = slapy2( real( a( k+1, k ) ),
588 \$ aimag( a( k+1, k ) ) )
589 d11 = real( a( k+1, k+1 ) ) / d
590 d22 = real( a( k, k ) ) / d
591 tt = one / ( d11*d22-one )
592 d21 = a( k+1, k ) / d
593 d = tt / d
594*
595 DO 80 j = k + 2, n
596 wk = d*( d11*a( j, k )-d21*a( j, k+1 ) )
597 wkp1 = d*( d22*a( j, k+1 )-conjg( d21 )*a( j, k ) )
598 DO 70 i = j, n
599 a( i, j ) = a( i, j ) - a( i, k )*conjg( wk ) -
600 \$ a( i, k+1 )*conjg( wkp1 )
601 70 CONTINUE
602 a( j, k ) = wk
603 a( j, k+1 ) = wkp1
604 a( j, j ) = cmplx( real( a( j, j ) ), 0.0e+0 )
605 80 CONTINUE
606 END IF
607 END IF
608 END IF
609*
610* Store details of the interchanges in IPIV
611*
612 IF( kstep.EQ.1 ) THEN
613 ipiv( k ) = kp
614 ELSE
615 ipiv( k ) = -kp
616 ipiv( k+1 ) = -kp
617 END IF
618*
619* Increase K and return to the start of the main loop
620*
621 k = k + kstep
622 GO TO 50
623*
624 END IF
625*
626 90 CONTINUE
627 RETURN
628*
629* End of CHETF2
630*
631 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine cher(uplo, n, alpha, x, incx, a, lda)
CHER
Definition cher.f:135
subroutine chetf2(uplo, n, a, lda, ipiv, info)
CHETF2 computes the factorization of a complex Hermitian matrix, using the diagonal pivoting method (...
Definition chetf2.f:186
subroutine csscal(n, sa, cx, incx)
CSSCAL
Definition csscal.f:78
subroutine cswap(n, cx, incx, cy, incy)
CSWAP
Definition cswap.f:81