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