1 *> \brief \b DSYTF2_ROOK computes the factorization of a real symmetric indefinite matrix using the bounded Bunch-Kaufman ("rook") diagonal pivoting method (unblocked algorithm).
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DSYTF2_ROOK + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsytf2_rook.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsytf2_rook.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsytf2_rook.f">
21 * SUBROUTINE DSYTF2_ROOK( UPLO, N, A, LDA, IPIV, INFO )
23 * .. Scalar Arguments ..
25 * INTEGER INFO, LDA, N
27 * .. Array Arguments ..
29 * DOUBLE PRECISION A( LDA, * )
38 *> DSYTF2_ROOK computes the factorization of a real symmetric matrix A
39 *> using the bounded Bunch-Kaufman ("rook") 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)
96 *> were interchanged and D(k,k) is a 1-by-1 diagonal block.
98 *> If IPIV(k) < 0 and IPIV(k-1) < 0, then rows and
99 *> columns k and -IPIV(k) were interchanged and rows and
100 *> columns k-1 and -IPIV(k-1) were inerchaged,
101 *> D(k-1:k,k-1:k) is a 2-by-2 diagonal block.
104 *> If IPIV(k) > 0, then rows and columns k and IPIV(k)
105 *> were interchanged and D(k,k) is a 1-by-1 diagonal block.
107 *> If IPIV(k) < 0 and IPIV(k+1) < 0, then rows and
108 *> columns k and -IPIV(k) were interchanged and rows and
109 *> columns k+1 and -IPIV(k+1) were inerchaged,
110 *> D(k:k+1,k:k+1) is a 2-by-2 diagonal block.
116 *> = 0: successful exit
117 *> < 0: if INFO = -k, the k-th argument had an illegal value
118 *> > 0: if INFO = k, D(k,k) is exactly zero. The factorization
119 *> has been completed, but the block diagonal matrix D is
120 *> exactly singular, and division by zero will occur if it
121 *> is used to solve a system of equations.
127 *> \author Univ. of Tennessee
128 *> \author Univ. of California Berkeley
129 *> \author Univ. of Colorado Denver
132 *> \date November 2013
134 *> \ingroup doubleSYcomputational
136 *> \par Further Details:
137 * =====================
141 *> If UPLO = 'U', then A = U*D*U**T, where
142 *> U = P(n)*U(n)* ... *P(k)U(k)* ...,
143 *> i.e., U is a product of terms P(k)*U(k), where k decreases from n to
144 *> 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
145 *> and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as
146 *> defined by IPIV(k), and U(k) is a unit upper triangular matrix, such
147 *> that if the diagonal block D(k) is of order s (s = 1 or 2), then
150 *> U(k) = ( 0 I 0 ) s
154 *> If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k).
155 *> If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k),
156 *> and A(k,k), and v overwrites A(1:k-2,k-1:k).
158 *> If UPLO = 'L', then A = L*D*L**T, where
159 *> L = P(1)*L(1)* ... *P(k)*L(k)* ...,
160 *> i.e., L is a product of terms P(k)*L(k), where k increases from 1 to
161 *> n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
162 *> and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as
163 *> defined by IPIV(k), and L(k) is a unit lower triangular matrix, such
164 *> that if the diagonal block D(k) is of order s (s = 1 or 2), then
167 *> L(k) = ( 0 I 0 ) s
171 *> If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k).
172 *> If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k),
173 *> and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1).
176 *> \par Contributors:
181 *> November 2013, Igor Kozachenko,
182 *> Computer Science Division,
183 *> University of California, Berkeley
185 *> September 2007, Sven Hammarling, Nicholas J. Higham, Craig Lucas,
186 *> School of Mathematics,
187 *> University of Manchester
189 *> 01-01-96 - Based on modifications by
190 *> J. Lewis, Boeing Computer Services Company
191 *> A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville abd , USA
194 * =====================================================================
195 SUBROUTINE DSYTF2_ROOK( 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, ITEMP, K, KK, KP, KSTEP,
223 DOUBLE PRECISION ABSAKK, ALPHA, COLMAX, D11, D12, D21, D22,
224 $ ROWMAX, DTEMP, T, WK, WKM1, WKP1, SFMIN
226 * .. External Functions ..
229 DOUBLE PRECISION DLAMCH
230 EXTERNAL LSAME, IDAMAX, DLAMCH
232 * .. External Subroutines ..
233 EXTERNAL DSCAL, DSWAP, DSYR, XERBLA
235 * .. Intrinsic Functions ..
236 INTRINSIC ABS, MAX, SQRT
238 * .. Executable Statements ..
240 * Test the input parameters.
243 UPPER = LSAME( UPLO, 'U' )
244 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
246 ELSE IF( N.LT.0 ) THEN
248 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
252 CALL XERBLA( 'DSYTF2_ROOK', -INFO )
256 * Initialize ALPHA for use in choosing pivot block size.
258 ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT
260 * Compute machine safe minimum
262 SFMIN = DLAMCH( 'S' )
266 * Factorize A as U*D*U**T using the upper triangle of A
268 * K is the main loop index, decreasing from N to 1 in steps of
274 * If K < 1, exit from loop
281 * Determine rows and columns to be interchanged and whether
282 * a 1-by-1 or 2-by-2 pivot block will be used
284 ABSAKK = ABS( A( K, K ) )
286 * IMAX is the row-index of the largest off-diagonal element in
287 * column K, and COLMAX is its absolute value.
288 * Determine both COLMAX and IMAX.
291 IMAX = IDAMAX( K-1, A( 1, K ), 1 )
292 COLMAX = ABS( A( IMAX, K ) )
297 IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) ) THEN
299 * Column K is zero or underflow: set INFO and continue
306 * Test for interchange
308 * Equivalent to testing for (used to handle NaN and Inf)
309 * ABSAKK.GE.ALPHA*COLMAX
311 IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN
314 * use 1-by-1 pivot block
321 * Loop until pivot found
325 * Begin pivot search loop body
327 * JMAX is the column-index of the largest off-diagonal
328 * element in row IMAX, and ROWMAX is its absolute value.
329 * Determine both ROWMAX and JMAX.
332 JMAX = IMAX + IDAMAX( K-IMAX, A( IMAX, IMAX+1 ),
334 ROWMAX = ABS( A( IMAX, JMAX ) )
340 ITEMP = IDAMAX( IMAX-1, A( 1, IMAX ), 1 )
341 DTEMP = ABS( A( ITEMP, IMAX ) )
342 IF( DTEMP.GT.ROWMAX ) THEN
348 * Equivalent to testing for (used to handle NaN and Inf)
349 * ABS( A( IMAX, IMAX ) ).GE.ALPHA*ROWMAX
351 IF( .NOT.( ABS( A( IMAX, IMAX ) ).LT.ALPHA*ROWMAX ) )
354 * interchange rows and columns K and IMAX,
355 * use 1-by-1 pivot block
360 * Equivalent to testing for ROWMAX .EQ. COLMAX,
361 * used to handle NaN and Inf
363 ELSE IF( ( P.EQ.JMAX ).OR.( ROWMAX.LE.COLMAX ) ) THEN
365 * interchange rows and columns K+1 and IMAX,
366 * use 2-by-2 pivot block
373 * Pivot NOT found, set variables and repeat
380 * End pivot search loop body
382 IF( .NOT. DONE ) GOTO 12
386 * Swap TWO rows and TWO columns
390 IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN
392 * Interchange rows and column K and P in the leading
393 * submatrix A(1:k,1:k) if we have a 2-by-2 pivot
396 $ CALL DSWAP( P-1, A( 1, K ), 1, A( 1, P ), 1 )
398 $ CALL DSWAP( K-P-1, A( P+1, K ), 1, A( P, P+1 ),
401 A( K, K ) = A( P, P )
410 * Interchange rows and columns KK and KP in the leading
411 * submatrix A(1:k,1:k)
414 $ CALL DSWAP( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 )
415 IF( ( KK.GT.1 ) .AND. ( KP.LT.(KK-1) ) )
416 $ CALL DSWAP( KK-KP-1, A( KP+1, KK ), 1, A( KP, KP+1 ),
419 A( KK, KK ) = A( KP, KP )
421 IF( KSTEP.EQ.2 ) THEN
423 A( K-1, K ) = A( KP, K )
428 * Update the leading submatrix
430 IF( KSTEP.EQ.1 ) THEN
432 * 1-by-1 pivot block D(k): column k now holds
436 * where U(k) is the k-th column of U
440 * Perform a rank-1 update of A(1:k-1,1:k-1) and
441 * store U(k) in column k
443 IF( ABS( A( K, K ) ).GE.SFMIN ) THEN
445 * Perform a rank-1 update of A(1:k-1,1:k-1) as
446 * A := A - U(k)*D(k)*U(k)**T
447 * = A - W(k)*1/D(k)*W(k)**T
449 D11 = ONE / A( K, K )
450 CALL DSYR( UPLO, K-1, -D11, A( 1, K ), 1, A, LDA )
452 * Store U(k) in column k
454 CALL DSCAL( K-1, D11, A( 1, K ), 1 )
457 * Store L(k) in column K
461 A( II, K ) = A( II, K ) / D11
464 * Perform a rank-1 update of A(k+1:n,k+1:n) as
465 * A := A - U(k)*D(k)*U(k)**T
466 * = A - W(k)*(1/D(k))*W(k)**T
467 * = A - (W(k)/D(k))*(D(k))*(W(k)/D(K))**T
469 CALL DSYR( UPLO, K-1, -D11, A( 1, K ), 1, A, LDA )
475 * 2-by-2 pivot block D(k): columns k and k-1 now hold
477 * ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k)
479 * where U(k) and U(k-1) are the k-th and (k-1)-th columns
482 * Perform a rank-2 update of A(1:k-2,1:k-2) as
484 * A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**T
485 * = A - ( ( A(k-1)A(k) )*inv(D(k)) ) * ( A(k-1)A(k) )**T
487 * and store L(k) and L(k+1) in columns k and k+1
492 D22 = A( K-1, K-1 ) / D12
493 D11 = A( K, K ) / D12
494 T = ONE / ( D11*D22-ONE )
496 DO 30 J = K - 2, 1, -1
498 WKM1 = T*( D11*A( J, K-1 )-A( J, K ) )
499 WK = T*( D22*A( J, K )-A( J, K-1 ) )
502 A( I, J ) = A( I, J ) - (A( I, K ) / D12 )*WK -
503 $ ( A( I, K-1 ) / D12 )*WKM1
506 * Store U(k) and U(k-1) in cols k and k-1 for row J
509 A( J, K-1 ) = WKM1 / D12
518 * Store details of the interchanges in IPIV
520 IF( KSTEP.EQ.1 ) THEN
527 * Decrease K and return to the start of the main loop
534 * Factorize A as L*D*L**T using the lower triangle of A
536 * K is the main loop index, increasing from 1 to N in steps of
542 * If K > N, exit from loop
549 * Determine rows and columns to be interchanged and whether
550 * a 1-by-1 or 2-by-2 pivot block will be used
552 ABSAKK = ABS( A( K, K ) )
554 * IMAX is the row-index of the largest off-diagonal element in
555 * column K, and COLMAX is its absolute value.
556 * Determine both COLMAX and IMAX.
559 IMAX = K + IDAMAX( N-K, A( K+1, K ), 1 )
560 COLMAX = ABS( A( IMAX, K ) )
565 IF( ( MAX( ABSAKK, COLMAX ).EQ.ZERO ) ) THEN
567 * Column K is zero or underflow: set INFO and continue
574 * Test for interchange
576 * Equivalent to testing for (used to handle NaN and Inf)
577 * ABSAKK.GE.ALPHA*COLMAX
579 IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN
581 * no interchange, use 1-by-1 pivot block
588 * Loop until pivot found
592 * Begin pivot search loop body
594 * JMAX is the column-index of the largest off-diagonal
595 * element in row IMAX, and ROWMAX is its absolute value.
596 * Determine both ROWMAX and JMAX.
599 JMAX = K - 1 + IDAMAX( IMAX-K, A( IMAX, K ), LDA )
600 ROWMAX = ABS( A( IMAX, JMAX ) )
606 ITEMP = IMAX + IDAMAX( N-IMAX, A( IMAX+1, IMAX ),
608 DTEMP = ABS( A( ITEMP, IMAX ) )
609 IF( DTEMP.GT.ROWMAX ) THEN
615 * Equivalent to testing for (used to handle NaN and Inf)
616 * ABS( A( IMAX, IMAX ) ).GE.ALPHA*ROWMAX
618 IF( .NOT.( ABS( A( IMAX, IMAX ) ).LT.ALPHA*ROWMAX ) )
621 * interchange rows and columns K and IMAX,
622 * use 1-by-1 pivot block
627 * Equivalent to testing for ROWMAX .EQ. COLMAX,
628 * used to handle NaN and Inf
630 ELSE IF( ( P.EQ.JMAX ).OR.( ROWMAX.LE.COLMAX ) ) THEN
632 * interchange rows and columns K+1 and IMAX,
633 * use 2-by-2 pivot block
640 * Pivot NOT found, set variables and repeat
647 * End pivot search loop body
649 IF( .NOT. DONE ) GOTO 42
653 * Swap TWO rows and TWO columns
657 IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN
659 * Interchange rows and column K and P in the trailing
660 * submatrix A(k:n,k:n) if we have a 2-by-2 pivot
663 $ CALL DSWAP( N-P, A( P+1, K ), 1, A( P+1, P ), 1 )
665 $ CALL DSWAP( P-K-1, A( K+1, K ), 1, A( P, K+1 ), LDA )
667 A( K, K ) = A( P, P )
676 * Interchange rows and columns KK and KP in the trailing
677 * submatrix A(k:n,k:n)
680 $ CALL DSWAP( N-KP, A( KP+1, KK ), 1, A( KP+1, KP ), 1 )
681 IF( ( KK.LT.N ) .AND. ( KP.GT.(KK+1) ) )
682 $ CALL DSWAP( KP-KK-1, A( KK+1, KK ), 1, A( KP, KK+1 ),
685 A( KK, KK ) = A( KP, KP )
687 IF( KSTEP.EQ.2 ) THEN
689 A( K+1, K ) = A( KP, K )
694 * Update the trailing submatrix
696 IF( KSTEP.EQ.1 ) THEN
698 * 1-by-1 pivot block D(k): column k now holds
702 * where L(k) is the k-th column of L
706 * Perform a rank-1 update of A(k+1:n,k+1:n) and
707 * store L(k) in column k
709 IF( ABS( A( K, K ) ).GE.SFMIN ) THEN
711 * Perform a rank-1 update of A(k+1:n,k+1:n) as
712 * A := A - L(k)*D(k)*L(k)**T
713 * = A - W(k)*(1/D(k))*W(k)**T
715 D11 = ONE / A( K, K )
716 CALL DSYR( UPLO, N-K, -D11, A( K+1, K ), 1,
717 $ A( K+1, K+1 ), LDA )
719 * Store L(k) in column k
721 CALL DSCAL( N-K, D11, A( K+1, K ), 1 )
724 * Store L(k) in column k
728 A( II, K ) = A( II, K ) / D11
731 * Perform a rank-1 update of A(k+1:n,k+1:n) as
732 * A := A - L(k)*D(k)*L(k)**T
733 * = A - W(k)*(1/D(k))*W(k)**T
734 * = A - (W(k)/D(k))*(D(k))*(W(k)/D(K))**T
736 CALL DSYR( UPLO, N-K, -D11, A( K+1, K ), 1,
737 $ A( K+1, K+1 ), LDA )
743 * 2-by-2 pivot block D(k): columns k and k+1 now hold
745 * ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k)
747 * where L(k) and L(k+1) are the k-th and (k+1)-th columns
751 * Perform a rank-2 update of A(k+2:n,k+2:n) as
753 * A := A - ( L(k) L(k+1) ) * D(k) * ( L(k) L(k+1) )**T
754 * = A - ( ( A(k)A(k+1) )*inv(D(k) ) * ( A(k)A(k+1) )**T
756 * and store L(k) and L(k+1) in columns k and k+1
761 D11 = A( K+1, K+1 ) / D21
762 D22 = A( K, K ) / D21
763 T = ONE / ( D11*D22-ONE )
767 * Compute D21 * ( W(k)W(k+1) ) * inv(D(k)) for row J
769 WK = T*( D11*A( J, K )-A( J, K+1 ) )
770 WKP1 = T*( D22*A( J, K+1 )-A( J, K ) )
772 * Perform a rank-2 update of A(k+2:n,k+2:n)
775 A( I, J ) = A( I, J ) - ( A( I, K ) / D21 )*WK -
776 $ ( A( I, K+1 ) / D21 )*WKP1
779 * Store L(k) and L(k+1) in cols k and k+1 for row J
782 A( J, K+1 ) = WKP1 / D21
791 * Store details of the interchanges in IPIV
793 IF( KSTEP.EQ.1 ) THEN
800 * Increase K and return to the start of the main loop