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