3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download DSPTRF + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsptrf.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsptrf.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsptrf.f">
21 * SUBROUTINE DSPTRF( UPLO, N, AP, IPIV, INFO )
23 * .. Scalar Arguments ..
27 * .. Array Arguments ..
29 * DOUBLE PRECISION AP( * )
38 *> DSPTRF computes the factorization of a real symmetric matrix A stored
39 *> in packed format using 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, and D is symmetric and block diagonal with
45 *> 1-by-1 and 2-by-2 diagonal blocks.
53 *> UPLO is CHARACTER*1
54 *> = 'U': Upper triangle of A is stored;
55 *> = 'L': Lower triangle of A is stored.
61 *> The order of the matrix A. N >= 0.
66 *> AP is DOUBLE PRECISION array, dimension (N*(N+1)/2)
67 *> On entry, the upper or lower triangle of the symmetric matrix
68 *> A, packed columnwise in a linear array. The j-th column of A
69 *> is stored in the array AP as follows:
70 *> if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
71 *> if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.
73 *> On exit, the block diagonal matrix D and the multipliers used
74 *> to obtain the factor U or L, stored as a packed triangular
75 *> matrix overwriting A (see below for further details).
80 *> IPIV is INTEGER array, dimension (N)
81 *> Details of the interchanges and the block structure of D.
82 *> If IPIV(k) > 0, then rows and columns k and IPIV(k) were
83 *> interchanged and D(k,k) is a 1-by-1 diagonal block.
84 *> If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and
85 *> columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k)
86 *> is a 2-by-2 diagonal block. If UPLO = 'L' and IPIV(k) =
87 *> IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were
88 *> interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block.
94 *> = 0: successful exit
95 *> < 0: if INFO = -i, the i-th argument had an illegal value
96 *> > 0: if INFO = i, D(i,i) is exactly zero. The factorization
97 *> has been completed, but the block diagonal matrix D is
98 *> exactly singular, and division by zero will occur if it
99 *> is used to solve a system of equations.
105 *> \author Univ. of Tennessee
106 *> \author Univ. of California Berkeley
107 *> \author Univ. of Colorado Denver
110 *> \date November 2011
112 *> \ingroup doubleOTHERcomputational
114 *> \par Further Details:
115 * =====================
119 *> If UPLO = 'U', then A = U*D*U**T, where
120 *> U = P(n)*U(n)* ... *P(k)U(k)* ...,
121 *> i.e., U is a product of terms P(k)*U(k), where k decreases from n to
122 *> 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
123 *> and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as
124 *> defined by IPIV(k), and U(k) is a unit upper triangular matrix, such
125 *> that if the diagonal block D(k) is of order s (s = 1 or 2), then
128 *> U(k) = ( 0 I 0 ) s
132 *> If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k).
133 *> If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k),
134 *> and A(k,k), and v overwrites A(1:k-2,k-1:k).
136 *> If UPLO = 'L', then A = L*D*L**T, where
137 *> L = P(1)*L(1)* ... *P(k)*L(k)* ...,
138 *> i.e., L is a product of terms P(k)*L(k), where k increases from 1 to
139 *> n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
140 *> and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as
141 *> defined by IPIV(k), and L(k) is a unit lower triangular matrix, such
142 *> that if the diagonal block D(k) is of order s (s = 1 or 2), then
145 *> L(k) = ( 0 I 0 ) s
149 *> If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k).
150 *> If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k),
151 *> and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1).
154 *> \par Contributors:
157 *> J. Lewis, Boeing Computer Services Company
159 * =====================================================================
160 SUBROUTINE DSPTRF( UPLO, N, AP, IPIV, INFO )
162 * -- LAPACK computational routine (version 3.4.0) --
163 * -- LAPACK is a software package provided by Univ. of Tennessee, --
164 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
167 * .. Scalar Arguments ..
171 * .. Array Arguments ..
173 DOUBLE PRECISION AP( * )
176 * =====================================================================
179 DOUBLE PRECISION ZERO, ONE
180 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
181 DOUBLE PRECISION EIGHT, SEVTEN
182 PARAMETER ( EIGHT = 8.0D+0, SEVTEN = 17.0D+0 )
184 * .. Local Scalars ..
186 INTEGER I, IMAX, J, JMAX, K, KC, KK, KNC, KP, KPC,
188 DOUBLE PRECISION ABSAKK, ALPHA, COLMAX, D11, D12, D21, D22, R1,
189 $ ROWMAX, T, WK, WKM1, WKP1
191 * .. External Functions ..
194 EXTERNAL LSAME, IDAMAX
196 * .. External Subroutines ..
197 EXTERNAL DSCAL, DSPR, DSWAP, XERBLA
199 * .. Intrinsic Functions ..
200 INTRINSIC ABS, MAX, SQRT
202 * .. Executable Statements ..
204 * Test the input parameters.
207 UPPER = LSAME( UPLO, 'U' )
208 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
210 ELSE IF( N.LT.0 ) THEN
214 CALL XERBLA( 'DSPTRF', -INFO )
218 * Initialize ALPHA for use in choosing pivot block size.
220 ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT
224 * Factorize A as U*D*U**T using the upper triangle of A
226 * K is the main loop index, decreasing from N to 1 in steps of
230 KC = ( N-1 )*N / 2 + 1
234 * If K < 1, exit from loop
240 * Determine rows and columns to be interchanged and whether
241 * a 1-by-1 or 2-by-2 pivot block will be used
243 ABSAKK = ABS( AP( KC+K-1 ) )
245 * IMAX is the row-index of the largest off-diagonal element in
246 * column K, and COLMAX is its absolute value
249 IMAX = IDAMAX( K-1, AP( KC ), 1 )
250 COLMAX = ABS( AP( KC+IMAX-1 ) )
255 IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
257 * Column K is zero: set INFO and continue
263 IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
265 * no interchange, use 1-by-1 pivot block
272 KX = IMAX*( IMAX+1 ) / 2 + IMAX
273 DO 20 J = IMAX + 1, K
274 IF( ABS( AP( KX ) ).GT.ROWMAX ) THEN
275 ROWMAX = ABS( AP( KX ) )
280 KPC = ( IMAX-1 )*IMAX / 2 + 1
282 JMAX = IDAMAX( IMAX-1, AP( KPC ), 1 )
283 ROWMAX = MAX( ROWMAX, ABS( AP( KPC+JMAX-1 ) ) )
286 IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
288 * no interchange, use 1-by-1 pivot block
291 ELSE IF( ABS( AP( KPC+IMAX-1 ) ).GE.ALPHA*ROWMAX ) THEN
293 * interchange rows and columns K and IMAX, use 1-by-1
299 * interchange rows and columns K-1 and IMAX, use 2-by-2
312 * Interchange rows and columns KK and KP in the leading
313 * submatrix A(1:k,1:k)
315 CALL DSWAP( KP-1, AP( KNC ), 1, AP( KPC ), 1 )
317 DO 30 J = KP + 1, KK - 1
320 AP( KNC+J-1 ) = AP( KX )
324 AP( KNC+KK-1 ) = AP( KPC+KP-1 )
326 IF( KSTEP.EQ.2 ) THEN
328 AP( KC+K-2 ) = AP( KC+KP-1 )
333 * Update the leading submatrix
335 IF( KSTEP.EQ.1 ) THEN
337 * 1-by-1 pivot block D(k): column k now holds
341 * where U(k) is the k-th column of U
343 * Perform a rank-1 update of A(1:k-1,1:k-1) as
345 * A := A - U(k)*D(k)*U(k)**T = A - W(k)*1/D(k)*W(k)**T
347 R1 = ONE / AP( KC+K-1 )
348 CALL DSPR( UPLO, K-1, -R1, AP( KC ), 1, AP )
350 * Store U(k) in column k
352 CALL DSCAL( K-1, R1, AP( KC ), 1 )
355 * 2-by-2 pivot block D(k): columns k and k-1 now hold
357 * ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k)
359 * where U(k) and U(k-1) are the k-th and (k-1)-th columns
362 * Perform a rank-2 update of A(1:k-2,1:k-2) as
364 * A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**T
365 * = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )**T
369 D12 = AP( K-1+( K-1 )*K / 2 )
370 D22 = AP( K-1+( K-2 )*( K-1 ) / 2 ) / D12
371 D11 = AP( K+( K-1 )*K / 2 ) / D12
372 T = ONE / ( D11*D22-ONE )
375 DO 50 J = K - 2, 1, -1
376 WKM1 = D12*( D11*AP( J+( K-2 )*( K-1 ) / 2 )-
377 $ AP( J+( K-1 )*K / 2 ) )
378 WK = D12*( D22*AP( J+( K-1 )*K / 2 )-
379 $ AP( J+( K-2 )*( K-1 ) / 2 ) )
381 AP( I+( J-1 )*J / 2 ) = AP( I+( J-1 )*J / 2 ) -
382 $ AP( I+( K-1 )*K / 2 )*WK -
383 $ AP( I+( K-2 )*( K-1 ) / 2 )*WKM1
385 AP( J+( K-1 )*K / 2 ) = WK
386 AP( J+( K-2 )*( K-1 ) / 2 ) = WKM1
394 * Store details of the interchanges in IPIV
396 IF( KSTEP.EQ.1 ) THEN
403 * Decrease K and return to the start of the main loop
411 * Factorize A as L*D*L**T using the lower triangle of A
413 * K is the main loop index, increasing from 1 to N in steps of
422 * If K > N, exit from loop
428 * Determine rows and columns to be interchanged and whether
429 * a 1-by-1 or 2-by-2 pivot block will be used
431 ABSAKK = ABS( AP( KC ) )
433 * IMAX is the row-index of the largest off-diagonal element in
434 * column K, and COLMAX is its absolute value
437 IMAX = K + IDAMAX( N-K, AP( KC+1 ), 1 )
438 COLMAX = ABS( AP( KC+IMAX-K ) )
443 IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
445 * Column K is zero: set INFO and continue
451 IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
453 * no interchange, use 1-by-1 pivot block
458 * JMAX is the column-index of the largest off-diagonal
459 * element in row IMAX, and ROWMAX is its absolute value
463 DO 70 J = K, IMAX - 1
464 IF( ABS( AP( KX ) ).GT.ROWMAX ) THEN
465 ROWMAX = ABS( AP( KX ) )
470 KPC = NPP - ( N-IMAX+1 )*( N-IMAX+2 ) / 2 + 1
472 JMAX = IMAX + IDAMAX( N-IMAX, AP( KPC+1 ), 1 )
473 ROWMAX = MAX( ROWMAX, ABS( AP( KPC+JMAX-IMAX ) ) )
476 IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
478 * no interchange, use 1-by-1 pivot block
481 ELSE IF( ABS( AP( KPC ) ).GE.ALPHA*ROWMAX ) THEN
483 * interchange rows and columns K and IMAX, use 1-by-1
489 * interchange rows and columns K+1 and IMAX, use 2-by-2
499 $ KNC = KNC + N - K + 1
502 * Interchange rows and columns KK and KP in the trailing
503 * submatrix A(k:n,k:n)
506 $ CALL DSWAP( N-KP, AP( KNC+KP-KK+1 ), 1, AP( KPC+1 ),
509 DO 80 J = KK + 1, KP - 1
512 AP( KNC+J-KK ) = AP( KX )
516 AP( KNC ) = AP( KPC )
518 IF( KSTEP.EQ.2 ) THEN
520 AP( KC+1 ) = AP( KC+KP-K )
525 * Update the trailing submatrix
527 IF( KSTEP.EQ.1 ) THEN
529 * 1-by-1 pivot block D(k): column k now holds
533 * where L(k) is the k-th column of L
537 * Perform a rank-1 update of A(k+1:n,k+1:n) as
539 * A := A - L(k)*D(k)*L(k)**T = A - W(k)*(1/D(k))*W(k)**T
542 CALL DSPR( UPLO, N-K, -R1, AP( KC+1 ), 1,
545 * Store L(k) in column K
547 CALL DSCAL( N-K, R1, AP( KC+1 ), 1 )
551 * 2-by-2 pivot block D(k): columns K and K+1 now hold
553 * ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k)
555 * where L(k) and L(k+1) are the k-th and (k+1)-th columns
560 * Perform a rank-2 update of A(k+2:n,k+2:n) as
562 * A := A - ( L(k) L(k+1) )*D(k)*( L(k) L(k+1) )**T
563 * = A - ( W(k) W(k+1) )*inv(D(k))*( W(k) W(k+1) )**T
565 * where L(k) and L(k+1) are the k-th and (k+1)-th
568 D21 = AP( K+1+( K-1 )*( 2*N-K ) / 2 )
569 D11 = AP( K+1+K*( 2*N-K-1 ) / 2 ) / D21
570 D22 = AP( K+( K-1 )*( 2*N-K ) / 2 ) / D21
571 T = ONE / ( D11*D22-ONE )
575 WK = D21*( D11*AP( J+( K-1 )*( 2*N-K ) / 2 )-
576 $ AP( J+K*( 2*N-K-1 ) / 2 ) )
577 WKP1 = D21*( D22*AP( J+K*( 2*N-K-1 ) / 2 )-
578 $ AP( J+( K-1 )*( 2*N-K ) / 2 ) )
581 AP( I+( J-1 )*( 2*N-J ) / 2 ) = AP( I+( J-1 )*
582 $ ( 2*N-J ) / 2 ) - AP( I+( K-1 )*( 2*N-K ) /
583 $ 2 )*WK - AP( I+K*( 2*N-K-1 ) / 2 )*WKP1
586 AP( J+( K-1 )*( 2*N-K ) / 2 ) = WK
587 AP( J+K*( 2*N-K-1 ) / 2 ) = WKP1
594 * Store details of the interchanges in IPIV
596 IF( KSTEP.EQ.1 ) THEN
603 * Increase K and return to the start of the main loop