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