LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
ssytf2.f
Go to the documentation of this file.
1*> \brief \b SSYTF2 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 SSYTF2 + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssytf2.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssytf2.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssytf2.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE SSYTF2( 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* REAL A( LDA, * )
28* ..
29*
30*
31*> \par Purpose:
32* =============
33*>
34*> \verbatim
35*>
36*> SSYTF2 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 REAL 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. SISNAN(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*>
189*> \endverbatim
190*
191* =====================================================================
192 SUBROUTINE ssytf2( UPLO, N, A, LDA, IPIV, INFO )
193*
194* -- LAPACK computational routine --
195* -- LAPACK is a software package provided by Univ. of Tennessee, --
196* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
197*
198* .. Scalar Arguments ..
199 CHARACTER UPLO
200 INTEGER INFO, LDA, N
201* ..
202* .. Array Arguments ..
203 INTEGER IPIV( * )
204 REAL A( LDA, * )
205* ..
206*
207* =====================================================================
208*
209* .. Parameters ..
210 REAL ZERO, ONE
211 parameter( zero = 0.0e+0, one = 1.0e+0 )
212 REAL EIGHT, SEVTEN
213 parameter( eight = 8.0e+0, sevten = 17.0e+0 )
214* ..
215* .. Local Scalars ..
216 LOGICAL UPPER
217 INTEGER I, IMAX, J, JMAX, K, KK, KP, KSTEP
218 REAL ABSAKK, ALPHA, COLMAX, D11, D12, D21, D22, R1,
219 $ ROWMAX, T, WK, WKM1, WKP1
220* ..
221* .. External Functions ..
222 LOGICAL LSAME, SISNAN
223 INTEGER ISAMAX
224 EXTERNAL lsame, isamax, sisnan
225* ..
226* .. External Subroutines ..
227 EXTERNAL sscal, sswap, ssyr, xerbla
228* ..
229* .. Intrinsic Functions ..
230 INTRINSIC abs, max, sqrt
231* ..
232* .. Executable Statements ..
233*
234* Test the input parameters.
235*
236 info = 0
237 upper = lsame( uplo, 'U' )
238 IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
239 info = -1
240 ELSE IF( n.LT.0 ) THEN
241 info = -2
242 ELSE IF( lda.LT.max( 1, n ) ) THEN
243 info = -4
244 END IF
245 IF( info.NE.0 ) THEN
246 CALL xerbla( 'SSYTF2', -info )
247 RETURN
248 END IF
249*
250* Initialize ALPHA for use in choosing pivot block size.
251*
252 alpha = ( one+sqrt( sevten ) ) / eight
253*
254 IF( upper ) THEN
255*
256* Factorize A as U*D*U**T using the upper triangle of A
257*
258* K is the main loop index, decreasing from N to 1 in steps of
259* 1 or 2
260*
261 k = n
262 10 CONTINUE
263*
264* If K < 1, exit from loop
265*
266 IF( k.LT.1 )
267 $ GO TO 70
268 kstep = 1
269*
270* Determine rows and columns to be interchanged and whether
271* a 1-by-1 or 2-by-2 pivot block will be used
272*
273 absakk = abs( a( k, k ) )
274*
275* IMAX is the row-index of the largest off-diagonal element in
276* column K, and COLMAX is its absolute value.
277* Determine both COLMAX and IMAX.
278*
279 IF( k.GT.1 ) THEN
280 imax = isamax( k-1, a( 1, k ), 1 )
281 colmax = abs( a( imax, k ) )
282 ELSE
283 colmax = zero
284 END IF
285*
286 IF( (max( absakk, colmax ).EQ.zero) .OR.
287 $ sisnan(absakk) ) THEN
288*
289* Column K is zero or underflow, or contains a NaN:
290* set INFO and continue
291*
292 IF( info.EQ.0 )
293 $ info = k
294 kp = k
295 ELSE
296 IF( absakk.GE.alpha*colmax ) THEN
297*
298* no interchange, use 1-by-1 pivot block
299*
300 kp = k
301 ELSE
302*
303* JMAX is the column-index of the largest off-diagonal
304* element in row IMAX, and ROWMAX is its absolute value
305*
306 jmax = imax + isamax( k-imax, a( imax, imax+1 ), lda )
307 rowmax = abs( a( imax, jmax ) )
308 IF( imax.GT.1 ) THEN
309 jmax = isamax( imax-1, a( 1, imax ), 1 )
310 rowmax = max( rowmax, abs( a( jmax, imax ) ) )
311 END IF
312*
313 IF( absakk.GE.alpha*colmax*( colmax / rowmax ) ) THEN
314*
315* no interchange, use 1-by-1 pivot block
316*
317 kp = k
318 ELSE IF( abs( a( imax, imax ) ).GE.alpha*rowmax ) THEN
319*
320* interchange rows and columns K and IMAX, use 1-by-1
321* pivot block
322*
323 kp = imax
324 ELSE
325*
326* interchange rows and columns K-1 and IMAX, use 2-by-2
327* pivot block
328*
329 kp = imax
330 kstep = 2
331 END IF
332 END IF
333*
334 kk = k - kstep + 1
335 IF( kp.NE.kk ) THEN
336*
337* Interchange rows and columns KK and KP in the leading
338* submatrix A(1:k,1:k)
339*
340 CALL sswap( kp-1, a( 1, kk ), 1, a( 1, kp ), 1 )
341 CALL sswap( kk-kp-1, a( kp+1, kk ), 1, a( kp, kp+1 ),
342 $ lda )
343 t = a( kk, kk )
344 a( kk, kk ) = a( kp, kp )
345 a( kp, kp ) = t
346 IF( kstep.EQ.2 ) THEN
347 t = a( k-1, k )
348 a( k-1, k ) = a( kp, k )
349 a( kp, k ) = t
350 END IF
351 END IF
352*
353* Update the leading submatrix
354*
355 IF( kstep.EQ.1 ) THEN
356*
357* 1-by-1 pivot block D(k): column k now holds
358*
359* W(k) = U(k)*D(k)
360*
361* where U(k) is the k-th column of U
362*
363* Perform a rank-1 update of A(1:k-1,1:k-1) as
364*
365* A := A - U(k)*D(k)*U(k)**T = A - W(k)*1/D(k)*W(k)**T
366*
367 r1 = one / a( k, k )
368 CALL ssyr( uplo, k-1, -r1, a( 1, k ), 1, a, lda )
369*
370* Store U(k) in column k
371*
372 CALL sscal( k-1, r1, a( 1, k ), 1 )
373 ELSE
374*
375* 2-by-2 pivot block D(k): columns k and k-1 now hold
376*
377* ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k)
378*
379* where U(k) and U(k-1) are the k-th and (k-1)-th columns
380* of U
381*
382* Perform a rank-2 update of A(1:k-2,1:k-2) as
383*
384* A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**T
385* = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )**T
386*
387 IF( k.GT.2 ) THEN
388*
389 d12 = a( k-1, k )
390 d22 = a( k-1, k-1 ) / d12
391 d11 = a( k, k ) / d12
392 t = one / ( d11*d22-one )
393 d12 = t / d12
394*
395 DO 30 j = k - 2, 1, -1
396 wkm1 = d12*( d11*a( j, k-1 )-a( j, k ) )
397 wk = d12*( d22*a( j, k )-a( j, k-1 ) )
398 DO 20 i = j, 1, -1
399 a( i, j ) = a( i, j ) - a( i, k )*wk -
400 $ a( i, k-1 )*wkm1
401 20 CONTINUE
402 a( j, k ) = wk
403 a( j, k-1 ) = wkm1
404 30 CONTINUE
405*
406 END IF
407*
408 END IF
409 END IF
410*
411* Store details of the interchanges in IPIV
412*
413 IF( kstep.EQ.1 ) THEN
414 ipiv( k ) = kp
415 ELSE
416 ipiv( k ) = -kp
417 ipiv( k-1 ) = -kp
418 END IF
419*
420* Decrease K and return to the start of the main loop
421*
422 k = k - kstep
423 GO TO 10
424*
425 ELSE
426*
427* Factorize A as L*D*L**T using the lower triangle of A
428*
429* K is the main loop index, increasing from 1 to N in steps of
430* 1 or 2
431*
432 k = 1
433 40 CONTINUE
434*
435* If K > N, exit from loop
436*
437 IF( k.GT.n )
438 $ GO TO 70
439 kstep = 1
440*
441* Determine rows and columns to be interchanged and whether
442* a 1-by-1 or 2-by-2 pivot block will be used
443*
444 absakk = abs( a( k, k ) )
445*
446* IMAX is the row-index of the largest off-diagonal element in
447* column K, and COLMAX is its absolute value.
448* Determine both COLMAX and IMAX.
449*
450 IF( k.LT.n ) THEN
451 imax = k + isamax( n-k, a( k+1, k ), 1 )
452 colmax = abs( a( imax, k ) )
453 ELSE
454 colmax = zero
455 END IF
456*
457 IF( (max( absakk, colmax ).EQ.zero) .OR.
458 $ sisnan(absakk) ) THEN
459*
460* Column K is zero or underflow, or contains a NaN:
461* set INFO and continue
462*
463 IF( info.EQ.0 )
464 $ info = k
465 kp = k
466 ELSE
467 IF( absakk.GE.alpha*colmax ) THEN
468*
469* no interchange, use 1-by-1 pivot block
470*
471 kp = k
472 ELSE
473*
474* JMAX is the column-index of the largest off-diagonal
475* element in row IMAX, and ROWMAX is its absolute value
476*
477 jmax = k - 1 + isamax( imax-k, a( imax, k ), lda )
478 rowmax = abs( a( imax, jmax ) )
479 IF( imax.LT.n ) THEN
480 jmax = imax + isamax( n-imax, a( imax+1, imax ),
481 $ 1 )
482 rowmax = max( rowmax, abs( a( jmax, imax ) ) )
483 END IF
484*
485 IF( absakk.GE.alpha*colmax*( colmax / rowmax ) ) THEN
486*
487* no interchange, use 1-by-1 pivot block
488*
489 kp = k
490 ELSE IF( abs( a( imax, imax ) ).GE.alpha*rowmax ) THEN
491*
492* interchange rows and columns K and IMAX, use 1-by-1
493* pivot block
494*
495 kp = imax
496 ELSE
497*
498* interchange rows and columns K+1 and IMAX, use 2-by-2
499* pivot block
500*
501 kp = imax
502 kstep = 2
503 END IF
504 END IF
505*
506 kk = k + kstep - 1
507 IF( kp.NE.kk ) THEN
508*
509* Interchange rows and columns KK and KP in the trailing
510* submatrix A(k:n,k:n)
511*
512 IF( kp.LT.n )
513 $ CALL sswap( n-kp, a( kp+1, kk ), 1, a( kp+1, kp ),
514 $ 1 )
515 CALL sswap( kp-kk-1, a( kk+1, kk ), 1, a( kp, kk+1 ),
516 $ lda )
517 t = a( kk, kk )
518 a( kk, kk ) = a( kp, kp )
519 a( kp, kp ) = t
520 IF( kstep.EQ.2 ) THEN
521 t = a( k+1, k )
522 a( k+1, k ) = a( kp, k )
523 a( kp, k ) = t
524 END IF
525 END IF
526*
527* Update the trailing submatrix
528*
529 IF( kstep.EQ.1 ) THEN
530*
531* 1-by-1 pivot block D(k): column k now holds
532*
533* W(k) = L(k)*D(k)
534*
535* where L(k) is the k-th column of L
536*
537 IF( k.LT.n ) THEN
538*
539* Perform a rank-1 update of A(k+1:n,k+1:n) as
540*
541* A := A - L(k)*D(k)*L(k)**T = A - W(k)*(1/D(k))*W(k)**T
542*
543 d11 = one / a( k, k )
544 CALL ssyr( uplo, n-k, -d11, a( k+1, k ), 1,
545 $ a( k+1, k+1 ), lda )
546*
547* Store L(k) in column K
548*
549 CALL sscal( n-k, d11, a( k+1, k ), 1 )
550 END IF
551 ELSE
552*
553* 2-by-2 pivot block D(k)
554*
555 IF( k.LT.n-1 ) THEN
556*
557* Perform a rank-2 update of A(k+2:n,k+2:n) as
558*
559* A := A - ( (A(k) A(k+1))*D(k)**(-1) ) * (A(k) A(k+1))**T
560*
561* where L(k) and L(k+1) are the k-th and (k+1)-th
562* columns of L
563*
564 d21 = a( k+1, k )
565 d11 = a( k+1, k+1 ) / d21
566 d22 = a( k, k ) / d21
567 t = one / ( d11*d22-one )
568 d21 = t / d21
569*
570 DO 60 j = k + 2, n
571*
572 wk = d21*( d11*a( j, k )-a( j, k+1 ) )
573 wkp1 = d21*( d22*a( j, k+1 )-a( j, k ) )
574*
575 DO 50 i = j, n
576 a( i, j ) = a( i, j ) - a( i, k )*wk -
577 $ a( i, k+1 )*wkp1
578 50 CONTINUE
579*
580 a( j, k ) = wk
581 a( j, k+1 ) = wkp1
582*
583 60 CONTINUE
584 END IF
585 END IF
586 END IF
587*
588* Store details of the interchanges in IPIV
589*
590 IF( kstep.EQ.1 ) THEN
591 ipiv( k ) = kp
592 ELSE
593 ipiv( k ) = -kp
594 ipiv( k+1 ) = -kp
595 END IF
596*
597* Increase K and return to the start of the main loop
598*
599 k = k + kstep
600 GO TO 40
601*
602 END IF
603*
604 70 CONTINUE
605*
606 RETURN
607*
608* End of SSYTF2
609*
610 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine ssyr(uplo, n, alpha, x, incx, a, lda)
SSYR
Definition ssyr.f:132
subroutine ssytf2(uplo, n, a, lda, ipiv, info)
SSYTF2 computes the factorization of a real symmetric indefinite matrix, using the diagonal pivoting ...
Definition ssytf2.f:193
subroutine sscal(n, sa, sx, incx)
SSCAL
Definition sscal.f:79
subroutine sswap(n, sx, incx, sy, incy)
SSWAP
Definition sswap.f:82