LAPACK 3.3.1
Linear Algebra PACKage
|
00001 SUBROUTINE CSPTRF( UPLO, N, AP, IPIV, INFO ) 00002 * 00003 * -- LAPACK routine (version 3.3.1) -- 00004 * -- LAPACK is a software package provided by Univ. of Tennessee, -- 00005 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- 00006 * -- April 2011 -- 00007 * 00008 * .. Scalar Arguments .. 00009 CHARACTER UPLO 00010 INTEGER INFO, N 00011 * .. 00012 * .. Array Arguments .. 00013 INTEGER IPIV( * ) 00014 COMPLEX AP( * ) 00015 * .. 00016 * 00017 * Purpose 00018 * ======= 00019 * 00020 * CSPTRF computes the factorization of a complex symmetric matrix A 00021 * stored in packed format using the Bunch-Kaufman diagonal pivoting 00022 * method: 00023 * 00024 * A = U*D*U**T or A = L*D*L**T 00025 * 00026 * where U (or L) is a product of permutation and unit upper (lower) 00027 * triangular matrices, and D is symmetric and block diagonal with 00028 * 1-by-1 and 2-by-2 diagonal blocks. 00029 * 00030 * Arguments 00031 * ========= 00032 * 00033 * UPLO (input) CHARACTER*1 00034 * = 'U': Upper triangle of A is stored; 00035 * = 'L': Lower triangle of A is stored. 00036 * 00037 * N (input) INTEGER 00038 * The order of the matrix A. N >= 0. 00039 * 00040 * AP (input/output) COMPLEX array, dimension (N*(N+1)/2) 00041 * On entry, the upper or lower triangle of the symmetric matrix 00042 * A, packed columnwise in a linear array. The j-th column of A 00043 * is stored in the array AP as follows: 00044 * if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; 00045 * if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. 00046 * 00047 * On exit, the block diagonal matrix D and the multipliers used 00048 * to obtain the factor U or L, stored as a packed triangular 00049 * matrix overwriting A (see below for further details). 00050 * 00051 * IPIV (output) INTEGER array, dimension (N) 00052 * Details of the interchanges and the block structure of D. 00053 * If IPIV(k) > 0, then rows and columns k and IPIV(k) were 00054 * interchanged and D(k,k) is a 1-by-1 diagonal block. 00055 * If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and 00056 * columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k) 00057 * is a 2-by-2 diagonal block. If UPLO = 'L' and IPIV(k) = 00058 * IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were 00059 * interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block. 00060 * 00061 * INFO (output) INTEGER 00062 * = 0: successful exit 00063 * < 0: if INFO = -i, the i-th argument had an illegal value 00064 * > 0: if INFO = i, D(i,i) is exactly zero. The factorization 00065 * has been completed, but the block diagonal matrix D is 00066 * exactly singular, and division by zero will occur if it 00067 * is used to solve a system of equations. 00068 * 00069 * Further Details 00070 * =============== 00071 * 00072 * 5-96 - Based on modifications by J. Lewis, Boeing Computer Services 00073 * Company 00074 * 00075 * If UPLO = 'U', then A = U*D*U**T, where 00076 * U = P(n)*U(n)* ... *P(k)U(k)* ..., 00077 * i.e., U is a product of terms P(k)*U(k), where k decreases from n to 00078 * 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 00079 * and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as 00080 * defined by IPIV(k), and U(k) is a unit upper triangular matrix, such 00081 * that if the diagonal block D(k) is of order s (s = 1 or 2), then 00082 * 00083 * ( I v 0 ) k-s 00084 * U(k) = ( 0 I 0 ) s 00085 * ( 0 0 I ) n-k 00086 * k-s s n-k 00087 * 00088 * If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k). 00089 * If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k), 00090 * and A(k,k), and v overwrites A(1:k-2,k-1:k). 00091 * 00092 * If UPLO = 'L', then A = L*D*L**T, where 00093 * L = P(1)*L(1)* ... *P(k)*L(k)* ..., 00094 * i.e., L is a product of terms P(k)*L(k), where k increases from 1 to 00095 * n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 00096 * and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as 00097 * defined by IPIV(k), and L(k) is a unit lower triangular matrix, such 00098 * that if the diagonal block D(k) is of order s (s = 1 or 2), then 00099 * 00100 * ( I 0 0 ) k-1 00101 * L(k) = ( 0 I 0 ) s 00102 * ( 0 v I ) n-k-s+1 00103 * k-1 s n-k-s+1 00104 * 00105 * If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k). 00106 * If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k), 00107 * and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1). 00108 * 00109 * ===================================================================== 00110 * 00111 * .. Parameters .. 00112 REAL ZERO, ONE 00113 PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 ) 00114 REAL EIGHT, SEVTEN 00115 PARAMETER ( EIGHT = 8.0E+0, SEVTEN = 17.0E+0 ) 00116 COMPLEX CONE 00117 PARAMETER ( CONE = ( 1.0E+0, 0.0E+0 ) ) 00118 * .. 00119 * .. Local Scalars .. 00120 LOGICAL UPPER 00121 INTEGER I, IMAX, J, JMAX, K, KC, KK, KNC, KP, KPC, 00122 $ KSTEP, KX, NPP 00123 REAL ABSAKK, ALPHA, COLMAX, ROWMAX 00124 COMPLEX D11, D12, D21, D22, R1, T, WK, WKM1, WKP1, ZDUM 00125 * .. 00126 * .. External Functions .. 00127 LOGICAL LSAME 00128 INTEGER ICAMAX 00129 EXTERNAL LSAME, ICAMAX 00130 * .. 00131 * .. External Subroutines .. 00132 EXTERNAL CSCAL, CSPR, CSWAP, XERBLA 00133 * .. 00134 * .. Intrinsic Functions .. 00135 INTRINSIC ABS, AIMAG, MAX, REAL, SQRT 00136 * .. 00137 * .. Statement Functions .. 00138 REAL CABS1 00139 * .. 00140 * .. Statement Function definitions .. 00141 CABS1( ZDUM ) = ABS( REAL( ZDUM ) ) + ABS( AIMAG( ZDUM ) ) 00142 * .. 00143 * .. Executable Statements .. 00144 * 00145 * Test the input parameters. 00146 * 00147 INFO = 0 00148 UPPER = LSAME( UPLO, 'U' ) 00149 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN 00150 INFO = -1 00151 ELSE IF( N.LT.0 ) THEN 00152 INFO = -2 00153 END IF 00154 IF( INFO.NE.0 ) THEN 00155 CALL XERBLA( 'CSPTRF', -INFO ) 00156 RETURN 00157 END IF 00158 * 00159 * Initialize ALPHA for use in choosing pivot block size. 00160 * 00161 ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT 00162 * 00163 IF( UPPER ) THEN 00164 * 00165 * Factorize A as U*D*U**T using the upper triangle of A 00166 * 00167 * K is the main loop index, decreasing from N to 1 in steps of 00168 * 1 or 2 00169 * 00170 K = N 00171 KC = ( N-1 )*N / 2 + 1 00172 10 CONTINUE 00173 KNC = KC 00174 * 00175 * If K < 1, exit from loop 00176 * 00177 IF( K.LT.1 ) 00178 $ GO TO 110 00179 KSTEP = 1 00180 * 00181 * Determine rows and columns to be interchanged and whether 00182 * a 1-by-1 or 2-by-2 pivot block will be used 00183 * 00184 ABSAKK = CABS1( AP( KC+K-1 ) ) 00185 * 00186 * IMAX is the row-index of the largest off-diagonal element in 00187 * column K, and COLMAX is its absolute value 00188 * 00189 IF( K.GT.1 ) THEN 00190 IMAX = ICAMAX( K-1, AP( KC ), 1 ) 00191 COLMAX = CABS1( AP( KC+IMAX-1 ) ) 00192 ELSE 00193 COLMAX = ZERO 00194 END IF 00195 * 00196 IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN 00197 * 00198 * Column K is zero: set INFO and continue 00199 * 00200 IF( INFO.EQ.0 ) 00201 $ INFO = K 00202 KP = K 00203 ELSE 00204 IF( ABSAKK.GE.ALPHA*COLMAX ) THEN 00205 * 00206 * no interchange, use 1-by-1 pivot block 00207 * 00208 KP = K 00209 ELSE 00210 * 00211 ROWMAX = ZERO 00212 JMAX = IMAX 00213 KX = IMAX*( IMAX+1 ) / 2 + IMAX 00214 DO 20 J = IMAX + 1, K 00215 IF( CABS1( AP( KX ) ).GT.ROWMAX ) THEN 00216 ROWMAX = CABS1( AP( KX ) ) 00217 JMAX = J 00218 END IF 00219 KX = KX + J 00220 20 CONTINUE 00221 KPC = ( IMAX-1 )*IMAX / 2 + 1 00222 IF( IMAX.GT.1 ) THEN 00223 JMAX = ICAMAX( IMAX-1, AP( KPC ), 1 ) 00224 ROWMAX = MAX( ROWMAX, CABS1( AP( KPC+JMAX-1 ) ) ) 00225 END IF 00226 * 00227 IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN 00228 * 00229 * no interchange, use 1-by-1 pivot block 00230 * 00231 KP = K 00232 ELSE IF( CABS1( AP( KPC+IMAX-1 ) ).GE.ALPHA*ROWMAX ) THEN 00233 * 00234 * interchange rows and columns K and IMAX, use 1-by-1 00235 * pivot block 00236 * 00237 KP = IMAX 00238 ELSE 00239 * 00240 * interchange rows and columns K-1 and IMAX, use 2-by-2 00241 * pivot block 00242 * 00243 KP = IMAX 00244 KSTEP = 2 00245 END IF 00246 END IF 00247 * 00248 KK = K - KSTEP + 1 00249 IF( KSTEP.EQ.2 ) 00250 $ KNC = KNC - K + 1 00251 IF( KP.NE.KK ) THEN 00252 * 00253 * Interchange rows and columns KK and KP in the leading 00254 * submatrix A(1:k,1:k) 00255 * 00256 CALL CSWAP( KP-1, AP( KNC ), 1, AP( KPC ), 1 ) 00257 KX = KPC + KP - 1 00258 DO 30 J = KP + 1, KK - 1 00259 KX = KX + J - 1 00260 T = AP( KNC+J-1 ) 00261 AP( KNC+J-1 ) = AP( KX ) 00262 AP( KX ) = T 00263 30 CONTINUE 00264 T = AP( KNC+KK-1 ) 00265 AP( KNC+KK-1 ) = AP( KPC+KP-1 ) 00266 AP( KPC+KP-1 ) = T 00267 IF( KSTEP.EQ.2 ) THEN 00268 T = AP( KC+K-2 ) 00269 AP( KC+K-2 ) = AP( KC+KP-1 ) 00270 AP( KC+KP-1 ) = T 00271 END IF 00272 END IF 00273 * 00274 * Update the leading submatrix 00275 * 00276 IF( KSTEP.EQ.1 ) THEN 00277 * 00278 * 1-by-1 pivot block D(k): column k now holds 00279 * 00280 * W(k) = U(k)*D(k) 00281 * 00282 * where U(k) is the k-th column of U 00283 * 00284 * Perform a rank-1 update of A(1:k-1,1:k-1) as 00285 * 00286 * A := A - U(k)*D(k)*U(k)**T = A - W(k)*1/D(k)*W(k)**T 00287 * 00288 R1 = CONE / AP( KC+K-1 ) 00289 CALL CSPR( UPLO, K-1, -R1, AP( KC ), 1, AP ) 00290 * 00291 * Store U(k) in column k 00292 * 00293 CALL CSCAL( K-1, R1, AP( KC ), 1 ) 00294 ELSE 00295 * 00296 * 2-by-2 pivot block D(k): columns k and k-1 now hold 00297 * 00298 * ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k) 00299 * 00300 * where U(k) and U(k-1) are the k-th and (k-1)-th columns 00301 * of U 00302 * 00303 * Perform a rank-2 update of A(1:k-2,1:k-2) as 00304 * 00305 * A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**T 00306 * = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )**T 00307 * 00308 IF( K.GT.2 ) THEN 00309 * 00310 D12 = AP( K-1+( K-1 )*K / 2 ) 00311 D22 = AP( K-1+( K-2 )*( K-1 ) / 2 ) / D12 00312 D11 = AP( K+( K-1 )*K / 2 ) / D12 00313 T = CONE / ( D11*D22-CONE ) 00314 D12 = T / D12 00315 * 00316 DO 50 J = K - 2, 1, -1 00317 WKM1 = D12*( D11*AP( J+( K-2 )*( K-1 ) / 2 )- 00318 $ AP( J+( K-1 )*K / 2 ) ) 00319 WK = D12*( D22*AP( J+( K-1 )*K / 2 )- 00320 $ AP( J+( K-2 )*( K-1 ) / 2 ) ) 00321 DO 40 I = J, 1, -1 00322 AP( I+( J-1 )*J / 2 ) = AP( I+( J-1 )*J / 2 ) - 00323 $ AP( I+( K-1 )*K / 2 )*WK - 00324 $ AP( I+( K-2 )*( K-1 ) / 2 )*WKM1 00325 40 CONTINUE 00326 AP( J+( K-1 )*K / 2 ) = WK 00327 AP( J+( K-2 )*( K-1 ) / 2 ) = WKM1 00328 50 CONTINUE 00329 * 00330 END IF 00331 END IF 00332 END IF 00333 * 00334 * Store details of the interchanges in IPIV 00335 * 00336 IF( KSTEP.EQ.1 ) THEN 00337 IPIV( K ) = KP 00338 ELSE 00339 IPIV( K ) = -KP 00340 IPIV( K-1 ) = -KP 00341 END IF 00342 * 00343 * Decrease K and return to the start of the main loop 00344 * 00345 K = K - KSTEP 00346 KC = KNC - K 00347 GO TO 10 00348 * 00349 ELSE 00350 * 00351 * Factorize A as L*D*L**T using the lower triangle of A 00352 * 00353 * K is the main loop index, increasing from 1 to N in steps of 00354 * 1 or 2 00355 * 00356 K = 1 00357 KC = 1 00358 NPP = N*( N+1 ) / 2 00359 60 CONTINUE 00360 KNC = KC 00361 * 00362 * If K > N, exit from loop 00363 * 00364 IF( K.GT.N ) 00365 $ GO TO 110 00366 KSTEP = 1 00367 * 00368 * Determine rows and columns to be interchanged and whether 00369 * a 1-by-1 or 2-by-2 pivot block will be used 00370 * 00371 ABSAKK = CABS1( AP( KC ) ) 00372 * 00373 * IMAX is the row-index of the largest off-diagonal element in 00374 * column K, and COLMAX is its absolute value 00375 * 00376 IF( K.LT.N ) THEN 00377 IMAX = K + ICAMAX( N-K, AP( KC+1 ), 1 ) 00378 COLMAX = CABS1( AP( KC+IMAX-K ) ) 00379 ELSE 00380 COLMAX = ZERO 00381 END IF 00382 * 00383 IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN 00384 * 00385 * Column K is zero: set INFO and continue 00386 * 00387 IF( INFO.EQ.0 ) 00388 $ INFO = K 00389 KP = K 00390 ELSE 00391 IF( ABSAKK.GE.ALPHA*COLMAX ) THEN 00392 * 00393 * no interchange, use 1-by-1 pivot block 00394 * 00395 KP = K 00396 ELSE 00397 * 00398 * JMAX is the column-index of the largest off-diagonal 00399 * element in row IMAX, and ROWMAX is its absolute value 00400 * 00401 ROWMAX = ZERO 00402 KX = KC + IMAX - K 00403 DO 70 J = K, IMAX - 1 00404 IF( CABS1( AP( KX ) ).GT.ROWMAX ) THEN 00405 ROWMAX = CABS1( AP( KX ) ) 00406 JMAX = J 00407 END IF 00408 KX = KX + N - J 00409 70 CONTINUE 00410 KPC = NPP - ( N-IMAX+1 )*( N-IMAX+2 ) / 2 + 1 00411 IF( IMAX.LT.N ) THEN 00412 JMAX = IMAX + ICAMAX( N-IMAX, AP( KPC+1 ), 1 ) 00413 ROWMAX = MAX( ROWMAX, CABS1( AP( KPC+JMAX-IMAX ) ) ) 00414 END IF 00415 * 00416 IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN 00417 * 00418 * no interchange, use 1-by-1 pivot block 00419 * 00420 KP = K 00421 ELSE IF( CABS1( AP( KPC ) ).GE.ALPHA*ROWMAX ) THEN 00422 * 00423 * interchange rows and columns K and IMAX, use 1-by-1 00424 * pivot block 00425 * 00426 KP = IMAX 00427 ELSE 00428 * 00429 * interchange rows and columns K+1 and IMAX, use 2-by-2 00430 * pivot block 00431 * 00432 KP = IMAX 00433 KSTEP = 2 00434 END IF 00435 END IF 00436 * 00437 KK = K + KSTEP - 1 00438 IF( KSTEP.EQ.2 ) 00439 $ KNC = KNC + N - K + 1 00440 IF( KP.NE.KK ) THEN 00441 * 00442 * Interchange rows and columns KK and KP in the trailing 00443 * submatrix A(k:n,k:n) 00444 * 00445 IF( KP.LT.N ) 00446 $ CALL CSWAP( N-KP, AP( KNC+KP-KK+1 ), 1, AP( KPC+1 ), 00447 $ 1 ) 00448 KX = KNC + KP - KK 00449 DO 80 J = KK + 1, KP - 1 00450 KX = KX + N - J + 1 00451 T = AP( KNC+J-KK ) 00452 AP( KNC+J-KK ) = AP( KX ) 00453 AP( KX ) = T 00454 80 CONTINUE 00455 T = AP( KNC ) 00456 AP( KNC ) = AP( KPC ) 00457 AP( KPC ) = T 00458 IF( KSTEP.EQ.2 ) THEN 00459 T = AP( KC+1 ) 00460 AP( KC+1 ) = AP( KC+KP-K ) 00461 AP( KC+KP-K ) = T 00462 END IF 00463 END IF 00464 * 00465 * Update the trailing submatrix 00466 * 00467 IF( KSTEP.EQ.1 ) THEN 00468 * 00469 * 1-by-1 pivot block D(k): column k now holds 00470 * 00471 * W(k) = L(k)*D(k) 00472 * 00473 * where L(k) is the k-th column of L 00474 * 00475 IF( K.LT.N ) THEN 00476 * 00477 * Perform a rank-1 update of A(k+1:n,k+1:n) as 00478 * 00479 * A := A - L(k)*D(k)*L(k)**T = A - W(k)*(1/D(k))*W(k)**T 00480 * 00481 R1 = CONE / AP( KC ) 00482 CALL CSPR( UPLO, N-K, -R1, AP( KC+1 ), 1, 00483 $ AP( KC+N-K+1 ) ) 00484 * 00485 * Store L(k) in column K 00486 * 00487 CALL CSCAL( N-K, R1, AP( KC+1 ), 1 ) 00488 END IF 00489 ELSE 00490 * 00491 * 2-by-2 pivot block D(k): columns K and K+1 now hold 00492 * 00493 * ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k) 00494 * 00495 * where L(k) and L(k+1) are the k-th and (k+1)-th columns 00496 * of L 00497 * 00498 IF( K.LT.N-1 ) THEN 00499 * 00500 * Perform a rank-2 update of A(k+2:n,k+2:n) as 00501 * 00502 * A := A - ( L(k) L(k+1) )*D(k)*( L(k) L(k+1) )**T 00503 * = A - ( W(k) W(k+1) )*inv(D(k))*( W(k) W(k+1) )**T 00504 * 00505 * where L(k) and L(k+1) are the k-th and (k+1)-th 00506 * columns of L 00507 * 00508 D21 = AP( K+1+( K-1 )*( 2*N-K ) / 2 ) 00509 D11 = AP( K+1+K*( 2*N-K-1 ) / 2 ) / D21 00510 D22 = AP( K+( K-1 )*( 2*N-K ) / 2 ) / D21 00511 T = CONE / ( D11*D22-CONE ) 00512 D21 = T / D21 00513 * 00514 DO 100 J = K + 2, N 00515 WK = D21*( D11*AP( J+( K-1 )*( 2*N-K ) / 2 )- 00516 $ AP( J+K*( 2*N-K-1 ) / 2 ) ) 00517 WKP1 = D21*( D22*AP( J+K*( 2*N-K-1 ) / 2 )- 00518 $ AP( J+( K-1 )*( 2*N-K ) / 2 ) ) 00519 DO 90 I = J, N 00520 AP( I+( J-1 )*( 2*N-J ) / 2 ) = AP( I+( J-1 )* 00521 $ ( 2*N-J ) / 2 ) - AP( I+( K-1 )*( 2*N-K ) / 00522 $ 2 )*WK - AP( I+K*( 2*N-K-1 ) / 2 )*WKP1 00523 90 CONTINUE 00524 AP( J+( K-1 )*( 2*N-K ) / 2 ) = WK 00525 AP( J+K*( 2*N-K-1 ) / 2 ) = WKP1 00526 100 CONTINUE 00527 END IF 00528 END IF 00529 END IF 00530 * 00531 * Store details of the interchanges in IPIV 00532 * 00533 IF( KSTEP.EQ.1 ) THEN 00534 IPIV( K ) = KP 00535 ELSE 00536 IPIV( K ) = -KP 00537 IPIV( K+1 ) = -KP 00538 END IF 00539 * 00540 * Increase K and return to the start of the main loop 00541 * 00542 K = K + KSTEP 00543 KC = KNC + N - K + 2 00544 GO TO 60 00545 * 00546 END IF 00547 * 00548 110 CONTINUE 00549 RETURN 00550 * 00551 * End of CSPTRF 00552 * 00553 END