LAPACK 3.12.0
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*> \htmlonly
9*> Download SSYTF2 + dependencies
10*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssytf2.f">
11*> [TGZ]</a>
12*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssytf2.f">
13*> [ZIP]</a>
14*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssytf2.f">
15*> [TXT]</a>
16*> \endhtmlonly
17*
18* Definition:
19* ===========
20*
21* SUBROUTINE SSYTF2( 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* REAL A( LDA, * )
30* ..
31*
32*
33*> \par Purpose:
34* =============
35*>
36*> \verbatim
37*>
38*> SSYTF2 computes the factorization of a real symmetric matrix A using
39*> the Bunch-Kaufman diagonal pivoting method:
40*>
41*> A = U*D*U**T or A = L*D*L**T
42*>
43*> where U (or L) is a product of permutation and unit upper (lower)
44*> triangular matrices, U**T is the transpose of U, and D is symmetric and
45*> 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*> symmetric 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 REAL array, dimension (LDA,N)
71*> On entry, the symmetric 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*> If UPLO = 'U', then A = U*D*U**T, where
138*> U = P(n)*U(n)* ... *P(k)U(k)* ...,
139*> i.e., U is a product of terms P(k)*U(k), where k decreases from n to
140*> 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
141*> and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as
142*> defined by IPIV(k), and U(k) is a unit upper triangular matrix, such
143*> that if the diagonal block D(k) is of order s (s = 1 or 2), then
144*>
145*> ( I v 0 ) k-s
146*> U(k) = ( 0 I 0 ) s
147*> ( 0 0 I ) n-k
148*> k-s s n-k
149*>
150*> If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k).
151*> If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k),
152*> and A(k,k), and v overwrites A(1:k-2,k-1:k).
153*>
154*> If UPLO = 'L', then A = L*D*L**T, where
155*> L = P(1)*L(1)* ... *P(k)*L(k)* ...,
156*> i.e., L is a product of terms P(k)*L(k), where k increases from 1 to
157*> n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
158*> and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as
159*> defined by IPIV(k), and L(k) is a unit lower triangular matrix, such
160*> that if the diagonal block D(k) is of order s (s = 1 or 2), then
161*>
162*> ( I 0 0 ) k-1
163*> L(k) = ( 0 I 0 ) s
164*> ( 0 v I ) n-k-s+1
165*> k-1 s n-k-s+1
166*>
167*> If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k).
168*> If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k),
169*> and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1).
170*> \endverbatim
171*
172*> \par Contributors:
173* ==================
174*>
175*> \verbatim
176*>
177*> 09-29-06 - patch from
178*> Bobby Cheng, MathWorks
179*>
180*> Replace l.204 and l.372
181*> IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
182*> by
183*> IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. SISNAN(ABSAKK) ) THEN
184*>
185*> 01-01-96 - Based on modifications by
186*> J. Lewis, Boeing Computer Services Company
187*> A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA
188*> 1-96 - Based on modifications by J. Lewis, Boeing Computer Services
189*> Company
190*>
191*> \endverbatim
192*
193* =====================================================================
194 SUBROUTINE ssytf2( UPLO, N, A, LDA, IPIV, INFO )
195*
196* -- LAPACK computational routine --
197* -- LAPACK is a software package provided by Univ. of Tennessee, --
198* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
199*
200* .. Scalar Arguments ..
201 CHARACTER UPLO
202 INTEGER INFO, LDA, N
203* ..
204* .. Array Arguments ..
205 INTEGER IPIV( * )
206 REAL A( LDA, * )
207* ..
208*
209* =====================================================================
210*
211* .. Parameters ..
212 REAL ZERO, ONE
213 parameter( zero = 0.0e+0, one = 1.0e+0 )
214 REAL EIGHT, SEVTEN
215 parameter( eight = 8.0e+0, sevten = 17.0e+0 )
216* ..
217* .. Local Scalars ..
218 LOGICAL UPPER
219 INTEGER I, IMAX, J, JMAX, K, KK, KP, KSTEP
220 REAL ABSAKK, ALPHA, COLMAX, D11, D12, D21, D22, R1,
221 $ ROWMAX, T, WK, WKM1, WKP1
222* ..
223* .. External Functions ..
224 LOGICAL LSAME, SISNAN
225 INTEGER ISAMAX
226 EXTERNAL lsame, isamax, sisnan
227* ..
228* .. External Subroutines ..
229 EXTERNAL sscal, sswap, ssyr, xerbla
230* ..
231* .. Intrinsic Functions ..
232 INTRINSIC abs, max, sqrt
233* ..
234* .. Executable Statements ..
235*
236* Test the input parameters.
237*
238 info = 0
239 upper = lsame( uplo, 'U' )
240 IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
241 info = -1
242 ELSE IF( n.LT.0 ) THEN
243 info = -2
244 ELSE IF( lda.LT.max( 1, n ) ) THEN
245 info = -4
246 END IF
247 IF( info.NE.0 ) THEN
248 CALL xerbla( 'SSYTF2', -info )
249 RETURN
250 END IF
251*
252* Initialize ALPHA for use in choosing pivot block size.
253*
254 alpha = ( one+sqrt( sevten ) ) / eight
255*
256 IF( upper ) THEN
257*
258* Factorize A as U*D*U**T using the upper triangle of A
259*
260* K is the main loop index, decreasing from N to 1 in steps of
261* 1 or 2
262*
263 k = n
264 10 CONTINUE
265*
266* If K < 1, exit from loop
267*
268 IF( k.LT.1 )
269 $ GO TO 70
270 kstep = 1
271*
272* Determine rows and columns to be interchanged and whether
273* a 1-by-1 or 2-by-2 pivot block will be used
274*
275 absakk = abs( a( k, k ) )
276*
277* IMAX is the row-index of the largest off-diagonal element in
278* column K, and COLMAX is its absolute value.
279* Determine both COLMAX and IMAX.
280*
281 IF( k.GT.1 ) THEN
282 imax = isamax( k-1, a( 1, k ), 1 )
283 colmax = abs( a( imax, k ) )
284 ELSE
285 colmax = zero
286 END IF
287*
288 IF( (max( absakk, colmax ).EQ.zero) .OR. sisnan(absakk) ) THEN
289*
290* Column K is zero or underflow, or contains a NaN:
291* set INFO and continue
292*
293 IF( info.EQ.0 )
294 $ info = k
295 kp = 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 + isamax( k-imax, a( imax, imax+1 ), lda )
308 rowmax = abs( a( imax, jmax ) )
309 IF( imax.GT.1 ) THEN
310 jmax = isamax( imax-1, a( 1, imax ), 1 )
311 rowmax = max( rowmax, abs( 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( a( imax, imax ) ).GE.alpha*rowmax ) THEN
320*
321* interchange rows and columns K and IMAX, use 1-by-1
322* pivot block
323*
324 kp = imax
325 ELSE
326*
327* interchange rows and columns K-1 and IMAX, use 2-by-2
328* pivot block
329*
330 kp = imax
331 kstep = 2
332 END IF
333 END IF
334*
335 kk = k - kstep + 1
336 IF( kp.NE.kk ) THEN
337*
338* Interchange rows and columns KK and KP in the leading
339* submatrix A(1:k,1:k)
340*
341 CALL sswap( kp-1, a( 1, kk ), 1, a( 1, kp ), 1 )
342 CALL sswap( kk-kp-1, a( kp+1, kk ), 1, a( kp, kp+1 ),
343 $ lda )
344 t = a( kk, kk )
345 a( kk, kk ) = a( kp, kp )
346 a( kp, kp ) = t
347 IF( kstep.EQ.2 ) THEN
348 t = a( k-1, k )
349 a( k-1, k ) = a( kp, k )
350 a( kp, k ) = t
351 END IF
352 END IF
353*
354* Update the leading submatrix
355*
356 IF( kstep.EQ.1 ) THEN
357*
358* 1-by-1 pivot block D(k): column k now holds
359*
360* W(k) = U(k)*D(k)
361*
362* where U(k) is the k-th column of U
363*
364* Perform a rank-1 update of A(1:k-1,1:k-1) as
365*
366* A := A - U(k)*D(k)*U(k)**T = A - W(k)*1/D(k)*W(k)**T
367*
368 r1 = one / a( k, k )
369 CALL ssyr( uplo, k-1, -r1, a( 1, k ), 1, a, lda )
370*
371* Store U(k) in column k
372*
373 CALL sscal( k-1, r1, a( 1, k ), 1 )
374 ELSE
375*
376* 2-by-2 pivot block D(k): columns k and k-1 now hold
377*
378* ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k)
379*
380* where U(k) and U(k-1) are the k-th and (k-1)-th columns
381* of U
382*
383* Perform a rank-2 update of A(1:k-2,1:k-2) as
384*
385* A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**T
386* = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )**T
387*
388 IF( k.GT.2 ) THEN
389*
390 d12 = a( k-1, k )
391 d22 = a( k-1, k-1 ) / d12
392 d11 = a( k, k ) / d12
393 t = one / ( d11*d22-one )
394 d12 = t / d12
395*
396 DO 30 j = k - 2, 1, -1
397 wkm1 = d12*( d11*a( j, k-1 )-a( j, k ) )
398 wk = d12*( d22*a( j, k )-a( j, k-1 ) )
399 DO 20 i = j, 1, -1
400 a( i, j ) = a( i, j ) - a( i, k )*wk -
401 $ a( i, k-1 )*wkm1
402 20 CONTINUE
403 a( j, k ) = wk
404 a( j, k-1 ) = wkm1
405 30 CONTINUE
406*
407 END IF
408*
409 END IF
410 END IF
411*
412* Store details of the interchanges in IPIV
413*
414 IF( kstep.EQ.1 ) THEN
415 ipiv( k ) = kp
416 ELSE
417 ipiv( k ) = -kp
418 ipiv( k-1 ) = -kp
419 END IF
420*
421* Decrease K and return to the start of the main loop
422*
423 k = k - kstep
424 GO TO 10
425*
426 ELSE
427*
428* Factorize A as L*D*L**T using the lower triangle of A
429*
430* K is the main loop index, increasing from 1 to N in steps of
431* 1 or 2
432*
433 k = 1
434 40 CONTINUE
435*
436* If K > N, exit from loop
437*
438 IF( k.GT.n )
439 $ GO TO 70
440 kstep = 1
441*
442* Determine rows and columns to be interchanged and whether
443* a 1-by-1 or 2-by-2 pivot block will be used
444*
445 absakk = abs( a( k, k ) )
446*
447* IMAX is the row-index of the largest off-diagonal element in
448* column K, and COLMAX is its absolute value.
449* Determine both COLMAX and IMAX.
450*
451 IF( k.LT.n ) THEN
452 imax = k + isamax( n-k, a( k+1, k ), 1 )
453 colmax = abs( a( imax, k ) )
454 ELSE
455 colmax = zero
456 END IF
457*
458 IF( (max( absakk, colmax ).EQ.zero) .OR. 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 ), 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 sswap( n-kp, a( kp+1, kk ), 1, a( kp+1, kp ), 1 )
513 CALL sswap( kp-kk-1, a( kk+1, kk ), 1, a( kp, kk+1 ),
514 $ lda )
515 t = a( kk, kk )
516 a( kk, kk ) = a( kp, kp )
517 a( kp, kp ) = t
518 IF( kstep.EQ.2 ) THEN
519 t = a( k+1, k )
520 a( k+1, k ) = a( kp, k )
521 a( kp, k ) = t
522 END IF
523 END IF
524*
525* Update the trailing submatrix
526*
527 IF( kstep.EQ.1 ) THEN
528*
529* 1-by-1 pivot block D(k): column k now holds
530*
531* W(k) = L(k)*D(k)
532*
533* where L(k) is the k-th column of L
534*
535 IF( k.LT.n ) THEN
536*
537* Perform a rank-1 update of A(k+1:n,k+1:n) as
538*
539* A := A - L(k)*D(k)*L(k)**T = A - W(k)*(1/D(k))*W(k)**T
540*
541 d11 = one / a( k, k )
542 CALL ssyr( uplo, n-k, -d11, a( k+1, k ), 1,
543 $ a( k+1, k+1 ), lda )
544*
545* Store L(k) in column K
546*
547 CALL sscal( n-k, d11, a( k+1, k ), 1 )
548 END IF
549 ELSE
550*
551* 2-by-2 pivot block D(k)
552*
553 IF( k.LT.n-1 ) THEN
554*
555* Perform a rank-2 update of A(k+2:n,k+2:n) as
556*
557* A := A - ( (A(k) A(k+1))*D(k)**(-1) ) * (A(k) A(k+1))**T
558*
559* where L(k) and L(k+1) are the k-th and (k+1)-th
560* columns of L
561*
562 d21 = a( k+1, k )
563 d11 = a( k+1, k+1 ) / d21
564 d22 = a( k, k ) / d21
565 t = one / ( d11*d22-one )
566 d21 = t / d21
567*
568 DO 60 j = k + 2, n
569*
570 wk = d21*( d11*a( j, k )-a( j, k+1 ) )
571 wkp1 = d21*( d22*a( j, k+1 )-a( j, k ) )
572*
573 DO 50 i = j, n
574 a( i, j ) = a( i, j ) - a( i, k )*wk -
575 $ a( i, k+1 )*wkp1
576 50 CONTINUE
577*
578 a( j, k ) = wk
579 a( j, k+1 ) = wkp1
580*
581 60 CONTINUE
582 END IF
583 END IF
584 END IF
585*
586* Store details of the interchanges in IPIV
587*
588 IF( kstep.EQ.1 ) THEN
589 ipiv( k ) = kp
590 ELSE
591 ipiv( k ) = -kp
592 ipiv( k+1 ) = -kp
593 END IF
594*
595* Increase K and return to the start of the main loop
596*
597 k = k + kstep
598 GO TO 40
599*
600 END IF
601*
602 70 CONTINUE
603*
604 RETURN
605*
606* End of SSYTF2
607*
608 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:195
subroutine sscal(n, sa, sx, incx)
SSCAL
Definition sscal.f:79
subroutine sswap(n, sx, incx, sy, incy)
SSWAP
Definition sswap.f:82