1 *> \brief \b DSYTF2 computes the factorization of a real symmetric indefinite matrix, using the diagonal pivoting method (unblocked algorithm).
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DSYTF2 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsytf2.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsytf2.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsytf2.f">
21 * SUBROUTINE DSYTF2( UPLO, N, A, LDA, IPIV, INFO )
23 * .. Scalar Arguments ..
25 * INTEGER INFO, LDA, N
27 * .. Array Arguments ..
29 * DOUBLE PRECISION A( LDA, * )
38 *> DSYTF2 computes the factorization of a real symmetric matrix A using
39 *> the Bunch-Kaufman diagonal pivoting method:
41 *> A = U*D*U**T or A = L*D*L**T
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.
47 *> This is the unblocked version of the algorithm, calling Level 2 BLAS.
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
65 *> The order of the matrix A. N >= 0.
70 *> A is DOUBLE PRECISION 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.
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).
86 *> The leading dimension of the array A. LDA >= max(1,N).
91 *> IPIV is INTEGER array, dimension (N)
92 *> Details of the interchanges and the block structure of D.
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.
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.
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.
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.
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.
125 *> \author Univ. of Tennessee
126 *> \author Univ. of California Berkeley
127 *> \author Univ. of Colorado Denver
130 *> \date November 2013
132 *> \ingroup doubleSYcomputational
134 *> \par Further Details:
135 * =====================
139 *> If UPLO = 'U', then A = U*D*U**T, where
140 *> U = P(n)*U(n)* ... *P(k)U(k)* ...,
141 *> i.e., U is a product of terms P(k)*U(k), where k decreases from n to
142 *> 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
143 *> and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as
144 *> defined by IPIV(k), and U(k) is a unit upper triangular matrix, such
145 *> that if the diagonal block D(k) is of order s (s = 1 or 2), then
148 *> U(k) = ( 0 I 0 ) s
152 *> If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k).
153 *> If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k),
154 *> and A(k,k), and v overwrites A(1:k-2,k-1:k).
156 *> If UPLO = 'L', then A = L*D*L**T, where
157 *> L = P(1)*L(1)* ... *P(k)*L(k)* ...,
158 *> i.e., L is a product of terms P(k)*L(k), where k increases from 1 to
159 *> n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
160 *> and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as
161 *> defined by IPIV(k), and L(k) is a unit lower triangular matrix, such
162 *> that if the diagonal block D(k) is of order s (s = 1 or 2), then
165 *> L(k) = ( 0 I 0 ) s
169 *> If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k).
170 *> If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k),
171 *> and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1).
174 *> \par Contributors:
179 *> 09-29-06 - patch from
180 *> Bobby Cheng, MathWorks
182 *> Replace l.204 and l.372
183 *> IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
185 *> IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. DISNAN(ABSAKK) ) THEN
187 *> 01-01-96 - Based on modifications by
188 *> J. Lewis, Boeing Computer Services Company
189 *> A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA
190 *> 1-96 - Based on modifications by J. Lewis, Boeing Computer Services
194 * =====================================================================
195 SUBROUTINE DSYTF2( UPLO, N, A, LDA, IPIV, INFO )
197 * -- LAPACK computational routine (version 3.5.0) --
198 * -- LAPACK is a software package provided by Univ. of Tennessee, --
199 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
202 * .. Scalar Arguments ..
206 * .. Array Arguments ..
208 DOUBLE PRECISION A( LDA, * )
211 * =====================================================================
214 DOUBLE PRECISION ZERO, ONE
215 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
216 DOUBLE PRECISION EIGHT, SEVTEN
217 PARAMETER ( EIGHT = 8.0D+0, SEVTEN = 17.0D+0 )
219 * .. Local Scalars ..
221 INTEGER I, IMAX, J, JMAX, K, KK, KP, KSTEP
222 DOUBLE PRECISION ABSAKK, ALPHA, COLMAX, D11, D12, D21, D22, R1,
223 $ ROWMAX, T, WK, WKM1, WKP1
225 * .. External Functions ..
226 LOGICAL LSAME, DISNAN
228 EXTERNAL LSAME, IDAMAX, DISNAN
230 * .. External Subroutines ..
231 EXTERNAL DSCAL, DSWAP, DSYR, XERBLA
233 * .. Intrinsic Functions ..
234 INTRINSIC ABS, MAX, SQRT
236 * .. Executable Statements ..
238 * Test the input parameters.
241 UPPER = LSAME( UPLO, 'U' )
242 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
244 ELSE IF( N.LT.0 ) THEN
246 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
250 CALL XERBLA( 'DSYTF2', -INFO )
254 * Initialize ALPHA for use in choosing pivot block size.
256 ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT
260 * Factorize A as U*D*U**T using the upper triangle of A
262 * K is the main loop index, decreasing from N to 1 in steps of
268 * If K < 1, exit from loop
274 * Determine rows and columns to be interchanged and whether
275 * a 1-by-1 or 2-by-2 pivot block will be used
277 ABSAKK = ABS( A( K, K ) )
279 * IMAX is the row-index of the largest off-diagonal element in
280 * column K, and COLMAX is its absolute value.
281 * Determine both COLMAX and IMAX.
284 IMAX = IDAMAX( K-1, A( 1, K ), 1 )
285 COLMAX = ABS( A( IMAX, K ) )
290 IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. DISNAN(ABSAKK) ) THEN
292 * Column K is zero or underflow, or contains a NaN:
293 * set INFO and continue
299 IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
301 * no interchange, use 1-by-1 pivot block
306 * JMAX is the column-index of the largest off-diagonal
307 * element in row IMAX, and ROWMAX is its absolute value
309 JMAX = IMAX + IDAMAX( K-IMAX, A( IMAX, IMAX+1 ), LDA )
310 ROWMAX = ABS( A( IMAX, JMAX ) )
312 JMAX = IDAMAX( IMAX-1, A( 1, IMAX ), 1 )
313 ROWMAX = MAX( ROWMAX, ABS( A( JMAX, IMAX ) ) )
316 IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
318 * no interchange, use 1-by-1 pivot block
321 ELSE IF( ABS( A( IMAX, IMAX ) ).GE.ALPHA*ROWMAX ) THEN
323 * interchange rows and columns K and IMAX, use 1-by-1
329 * interchange rows and columns K-1 and IMAX, use 2-by-2
340 * Interchange rows and columns KK and KP in the leading
341 * submatrix A(1:k,1:k)
343 CALL DSWAP( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 )
344 CALL DSWAP( KK-KP-1, A( KP+1, KK ), 1, A( KP, KP+1 ),
347 A( KK, KK ) = A( KP, KP )
349 IF( KSTEP.EQ.2 ) THEN
351 A( K-1, K ) = A( KP, K )
356 * Update the leading submatrix
358 IF( KSTEP.EQ.1 ) THEN
360 * 1-by-1 pivot block D(k): column k now holds
364 * where U(k) is the k-th column of U
366 * Perform a rank-1 update of A(1:k-1,1:k-1) as
368 * A := A - U(k)*D(k)*U(k)**T = A - W(k)*1/D(k)*W(k)**T
371 CALL DSYR( UPLO, K-1, -R1, A( 1, K ), 1, A, LDA )
373 * Store U(k) in column k
375 CALL DSCAL( K-1, R1, A( 1, K ), 1 )
378 * 2-by-2 pivot block D(k): columns k and k-1 now hold
380 * ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k)
382 * where U(k) and U(k-1) are the k-th and (k-1)-th columns
385 * Perform a rank-2 update of A(1:k-2,1:k-2) as
387 * A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**T
388 * = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )**T
393 D22 = A( K-1, K-1 ) / D12
394 D11 = A( K, K ) / D12
395 T = ONE / ( D11*D22-ONE )
398 DO 30 J = K - 2, 1, -1
399 WKM1 = D12*( D11*A( J, K-1 )-A( J, K ) )
400 WK = D12*( D22*A( J, K )-A( J, K-1 ) )
402 A( I, J ) = A( I, J ) - A( I, K )*WK -
414 * Store details of the interchanges in IPIV
416 IF( KSTEP.EQ.1 ) THEN
423 * Decrease K and return to the start of the main loop
430 * Factorize A as L*D*L**T using the lower triangle of A
432 * K is the main loop index, increasing from 1 to N in steps of
438 * If K > N, exit from loop
444 * Determine rows and columns to be interchanged and whether
445 * a 1-by-1 or 2-by-2 pivot block will be used
447 ABSAKK = ABS( A( K, K ) )
449 * IMAX is the row-index of the largest off-diagonal element in
450 * column K, and COLMAX is its absolute value.
451 * Determine both COLMAX and IMAX.
454 IMAX = K + IDAMAX( N-K, A( K+1, K ), 1 )
455 COLMAX = ABS( A( IMAX, K ) )
460 IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. DISNAN(ABSAKK) ) THEN
462 * Column K is zero or underflow, or contains a NaN:
463 * set INFO and continue
469 IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
471 * no interchange, use 1-by-1 pivot block
476 * JMAX is the column-index of the largest off-diagonal
477 * element in row IMAX, and ROWMAX is its absolute value
479 JMAX = K - 1 + IDAMAX( IMAX-K, A( IMAX, K ), LDA )
480 ROWMAX = ABS( A( IMAX, JMAX ) )
482 JMAX = IMAX + IDAMAX( N-IMAX, A( IMAX+1, IMAX ), 1 )
483 ROWMAX = MAX( ROWMAX, ABS( A( JMAX, IMAX ) ) )
486 IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
488 * no interchange, use 1-by-1 pivot block
491 ELSE IF( ABS( A( IMAX, IMAX ) ).GE.ALPHA*ROWMAX ) THEN
493 * interchange rows and columns K and IMAX, use 1-by-1
499 * interchange rows and columns K+1 and IMAX, use 2-by-2
510 * Interchange rows and columns KK and KP in the trailing
511 * submatrix A(k:n,k:n)
514 $ CALL DSWAP( N-KP, A( KP+1, KK ), 1, A( KP+1, KP ), 1 )
515 CALL DSWAP( KP-KK-1, A( KK+1, KK ), 1, A( KP, KK+1 ),
518 A( KK, KK ) = A( KP, KP )
520 IF( KSTEP.EQ.2 ) THEN
522 A( K+1, K ) = A( KP, K )
527 * Update the trailing submatrix
529 IF( KSTEP.EQ.1 ) THEN
531 * 1-by-1 pivot block D(k): column k now holds
535 * where L(k) is the k-th column of L
539 * Perform a rank-1 update of A(k+1:n,k+1:n) as
541 * A := A - L(k)*D(k)*L(k)**T = A - W(k)*(1/D(k))*W(k)**T
543 D11 = ONE / A( K, K )
544 CALL DSYR( UPLO, N-K, -D11, A( K+1, K ), 1,
545 $ A( K+1, K+1 ), LDA )
547 * Store L(k) in column K
549 CALL DSCAL( N-K, D11, A( K+1, K ), 1 )
553 * 2-by-2 pivot block D(k)
557 * Perform a rank-2 update of A(k+2:n,k+2:n) as
559 * A := A - ( (A(k) A(k+1))*D(k)**(-1) ) * (A(k) A(k+1))**T
561 * where L(k) and L(k+1) are the k-th and (k+1)-th
565 D11 = A( K+1, K+1 ) / D21
566 D22 = A( K, K ) / D21
567 T = ONE / ( D11*D22-ONE )
572 WK = D21*( D11*A( J, K )-A( J, K+1 ) )
573 WKP1 = D21*( D22*A( J, K+1 )-A( J, K ) )
576 A( I, J ) = A( I, J ) - A( I, K )*WK -
588 * Store details of the interchanges in IPIV
590 IF( KSTEP.EQ.1 ) THEN
597 * Increase K and return to the start of the main loop