![]() |
LAPACK
3.4.1
LAPACK: Linear Algebra PACKage
|
00001 *> \brief \b DSYTF2 00002 * 00003 * =========== DOCUMENTATION =========== 00004 * 00005 * Online html documentation available at 00006 * http://www.netlib.org/lapack/explore-html/ 00007 * 00008 *> \htmlonly 00009 *> Download DSYTF2 + dependencies 00010 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsytf2.f"> 00011 *> [TGZ]</a> 00012 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsytf2.f"> 00013 *> [ZIP]</a> 00014 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsytf2.f"> 00015 *> [TXT]</a> 00016 *> \endhtmlonly 00017 * 00018 * Definition: 00019 * =========== 00020 * 00021 * SUBROUTINE DSYTF2( 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 * DOUBLE PRECISION A( LDA, * ) 00030 * .. 00031 * 00032 * 00033 *> \par Purpose: 00034 * ============= 00035 *> 00036 *> \verbatim 00037 *> 00038 *> DSYTF2 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 DOUBLE PRECISION 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 doubleSYcomputational 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. DISNAN(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 *> \endverbatim 00184 * 00185 * ===================================================================== 00186 SUBROUTINE DSYTF2( UPLO, N, A, LDA, IPIV, INFO ) 00187 * 00188 * -- LAPACK computational routine (version 3.4.0) -- 00189 * -- LAPACK is a software package provided by Univ. of Tennessee, -- 00190 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- 00191 * November 2011 00192 * 00193 * .. Scalar Arguments .. 00194 CHARACTER UPLO 00195 INTEGER INFO, LDA, N 00196 * .. 00197 * .. Array Arguments .. 00198 INTEGER IPIV( * ) 00199 DOUBLE PRECISION A( LDA, * ) 00200 * .. 00201 * 00202 * ===================================================================== 00203 * 00204 * .. Parameters .. 00205 DOUBLE PRECISION ZERO, ONE 00206 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 ) 00207 DOUBLE PRECISION EIGHT, SEVTEN 00208 PARAMETER ( EIGHT = 8.0D+0, SEVTEN = 17.0D+0 ) 00209 * .. 00210 * .. Local Scalars .. 00211 LOGICAL UPPER 00212 INTEGER I, IMAX, J, JMAX, K, KK, KP, KSTEP 00213 DOUBLE PRECISION ABSAKK, ALPHA, COLMAX, D11, D12, D21, D22, R1, 00214 $ ROWMAX, T, WK, WKM1, WKP1 00215 * .. 00216 * .. External Functions .. 00217 LOGICAL LSAME, DISNAN 00218 INTEGER IDAMAX 00219 EXTERNAL LSAME, IDAMAX, DISNAN 00220 * .. 00221 * .. External Subroutines .. 00222 EXTERNAL DSCAL, DSWAP, DSYR, XERBLA 00223 * .. 00224 * .. Intrinsic Functions .. 00225 INTRINSIC ABS, MAX, SQRT 00226 * .. 00227 * .. Executable Statements .. 00228 * 00229 * Test the input parameters. 00230 * 00231 INFO = 0 00232 UPPER = LSAME( UPLO, 'U' ) 00233 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN 00234 INFO = -1 00235 ELSE IF( N.LT.0 ) THEN 00236 INFO = -2 00237 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN 00238 INFO = -4 00239 END IF 00240 IF( INFO.NE.0 ) THEN 00241 CALL XERBLA( 'DSYTF2', -INFO ) 00242 RETURN 00243 END IF 00244 * 00245 * Initialize ALPHA for use in choosing pivot block size. 00246 * 00247 ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT 00248 * 00249 IF( UPPER ) THEN 00250 * 00251 * Factorize A as U*D*U**T using the upper triangle of A 00252 * 00253 * K is the main loop index, decreasing from N to 1 in steps of 00254 * 1 or 2 00255 * 00256 K = N 00257 10 CONTINUE 00258 * 00259 * If K < 1, exit from loop 00260 * 00261 IF( K.LT.1 ) 00262 $ GO TO 70 00263 KSTEP = 1 00264 * 00265 * Determine rows and columns to be interchanged and whether 00266 * a 1-by-1 or 2-by-2 pivot block will be used 00267 * 00268 ABSAKK = ABS( A( K, K ) ) 00269 * 00270 * IMAX is the row-index of the largest off-diagonal element in 00271 * column K, and COLMAX is its absolute value 00272 * 00273 IF( K.GT.1 ) THEN 00274 IMAX = IDAMAX( K-1, A( 1, K ), 1 ) 00275 COLMAX = ABS( A( IMAX, K ) ) 00276 ELSE 00277 COLMAX = ZERO 00278 END IF 00279 * 00280 IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. DISNAN(ABSAKK) ) THEN 00281 * 00282 * Column K is zero or contains a NaN: set INFO and continue 00283 * 00284 IF( INFO.EQ.0 ) 00285 $ INFO = K 00286 KP = K 00287 ELSE 00288 IF( ABSAKK.GE.ALPHA*COLMAX ) THEN 00289 * 00290 * no interchange, use 1-by-1 pivot block 00291 * 00292 KP = K 00293 ELSE 00294 * 00295 * JMAX is the column-index of the largest off-diagonal 00296 * element in row IMAX, and ROWMAX is its absolute value 00297 * 00298 JMAX = IMAX + IDAMAX( K-IMAX, A( IMAX, IMAX+1 ), LDA ) 00299 ROWMAX = ABS( A( IMAX, JMAX ) ) 00300 IF( IMAX.GT.1 ) THEN 00301 JMAX = IDAMAX( IMAX-1, A( 1, IMAX ), 1 ) 00302 ROWMAX = MAX( ROWMAX, ABS( A( JMAX, IMAX ) ) ) 00303 END IF 00304 * 00305 IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN 00306 * 00307 * no interchange, use 1-by-1 pivot block 00308 * 00309 KP = K 00310 ELSE IF( ABS( A( IMAX, IMAX ) ).GE.ALPHA*ROWMAX ) THEN 00311 * 00312 * interchange rows and columns K and IMAX, use 1-by-1 00313 * pivot block 00314 * 00315 KP = IMAX 00316 ELSE 00317 * 00318 * interchange rows and columns K-1 and IMAX, use 2-by-2 00319 * pivot block 00320 * 00321 KP = IMAX 00322 KSTEP = 2 00323 END IF 00324 END IF 00325 * 00326 KK = K - KSTEP + 1 00327 IF( KP.NE.KK ) THEN 00328 * 00329 * Interchange rows and columns KK and KP in the leading 00330 * submatrix A(1:k,1:k) 00331 * 00332 CALL DSWAP( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 ) 00333 CALL DSWAP( KK-KP-1, A( KP+1, KK ), 1, A( KP, KP+1 ), 00334 $ LDA ) 00335 T = A( KK, KK ) 00336 A( KK, KK ) = A( KP, KP ) 00337 A( KP, KP ) = T 00338 IF( KSTEP.EQ.2 ) THEN 00339 T = A( K-1, K ) 00340 A( K-1, K ) = A( KP, K ) 00341 A( KP, K ) = T 00342 END IF 00343 END IF 00344 * 00345 * Update the leading submatrix 00346 * 00347 IF( KSTEP.EQ.1 ) THEN 00348 * 00349 * 1-by-1 pivot block D(k): column k now holds 00350 * 00351 * W(k) = U(k)*D(k) 00352 * 00353 * where U(k) is the k-th column of U 00354 * 00355 * Perform a rank-1 update of A(1:k-1,1:k-1) as 00356 * 00357 * A := A - U(k)*D(k)*U(k)**T = A - W(k)*1/D(k)*W(k)**T 00358 * 00359 R1 = ONE / A( K, K ) 00360 CALL DSYR( UPLO, K-1, -R1, A( 1, K ), 1, A, LDA ) 00361 * 00362 * Store U(k) in column k 00363 * 00364 CALL DSCAL( K-1, R1, A( 1, K ), 1 ) 00365 ELSE 00366 * 00367 * 2-by-2 pivot block D(k): columns k and k-1 now hold 00368 * 00369 * ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k) 00370 * 00371 * where U(k) and U(k-1) are the k-th and (k-1)-th columns 00372 * of U 00373 * 00374 * Perform a rank-2 update of A(1:k-2,1:k-2) as 00375 * 00376 * A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**T 00377 * = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )**T 00378 * 00379 IF( K.GT.2 ) THEN 00380 * 00381 D12 = A( K-1, K ) 00382 D22 = A( K-1, K-1 ) / D12 00383 D11 = A( K, K ) / D12 00384 T = ONE / ( D11*D22-ONE ) 00385 D12 = T / D12 00386 * 00387 DO 30 J = K - 2, 1, -1 00388 WKM1 = D12*( D11*A( J, K-1 )-A( J, K ) ) 00389 WK = D12*( D22*A( J, K )-A( J, K-1 ) ) 00390 DO 20 I = J, 1, -1 00391 A( I, J ) = A( I, J ) - A( I, K )*WK - 00392 $ A( I, K-1 )*WKM1 00393 20 CONTINUE 00394 A( J, K ) = WK 00395 A( J, K-1 ) = WKM1 00396 30 CONTINUE 00397 * 00398 END IF 00399 * 00400 END IF 00401 END IF 00402 * 00403 * Store details of the interchanges in IPIV 00404 * 00405 IF( KSTEP.EQ.1 ) THEN 00406 IPIV( K ) = KP 00407 ELSE 00408 IPIV( K ) = -KP 00409 IPIV( K-1 ) = -KP 00410 END IF 00411 * 00412 * Decrease K and return to the start of the main loop 00413 * 00414 K = K - KSTEP 00415 GO TO 10 00416 * 00417 ELSE 00418 * 00419 * Factorize A as L*D*L**T using the lower triangle of A 00420 * 00421 * K is the main loop index, increasing from 1 to N in steps of 00422 * 1 or 2 00423 * 00424 K = 1 00425 40 CONTINUE 00426 * 00427 * If K > N, exit from loop 00428 * 00429 IF( K.GT.N ) 00430 $ GO TO 70 00431 KSTEP = 1 00432 * 00433 * Determine rows and columns to be interchanged and whether 00434 * a 1-by-1 or 2-by-2 pivot block will be used 00435 * 00436 ABSAKK = ABS( A( K, K ) ) 00437 * 00438 * IMAX is the row-index of the largest off-diagonal element in 00439 * column K, and COLMAX is its absolute value 00440 * 00441 IF( K.LT.N ) THEN 00442 IMAX = K + IDAMAX( N-K, A( K+1, K ), 1 ) 00443 COLMAX = ABS( A( IMAX, K ) ) 00444 ELSE 00445 COLMAX = ZERO 00446 END IF 00447 * 00448 IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. DISNAN(ABSAKK) ) THEN 00449 * 00450 * Column K is zero or contains a NaN: set INFO and continue 00451 * 00452 IF( INFO.EQ.0 ) 00453 $ INFO = K 00454 KP = K 00455 ELSE 00456 IF( ABSAKK.GE.ALPHA*COLMAX ) THEN 00457 * 00458 * no interchange, use 1-by-1 pivot block 00459 * 00460 KP = K 00461 ELSE 00462 * 00463 * JMAX is the column-index of the largest off-diagonal 00464 * element in row IMAX, and ROWMAX is its absolute value 00465 * 00466 JMAX = K - 1 + IDAMAX( IMAX-K, A( IMAX, K ), LDA ) 00467 ROWMAX = ABS( A( IMAX, JMAX ) ) 00468 IF( IMAX.LT.N ) THEN 00469 JMAX = IMAX + IDAMAX( N-IMAX, A( IMAX+1, IMAX ), 1 ) 00470 ROWMAX = MAX( ROWMAX, ABS( A( JMAX, IMAX ) ) ) 00471 END IF 00472 * 00473 IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN 00474 * 00475 * no interchange, use 1-by-1 pivot block 00476 * 00477 KP = K 00478 ELSE IF( ABS( A( IMAX, IMAX ) ).GE.ALPHA*ROWMAX ) THEN 00479 * 00480 * interchange rows and columns K and IMAX, use 1-by-1 00481 * pivot block 00482 * 00483 KP = IMAX 00484 ELSE 00485 * 00486 * interchange rows and columns K+1 and IMAX, use 2-by-2 00487 * pivot block 00488 * 00489 KP = IMAX 00490 KSTEP = 2 00491 END IF 00492 END IF 00493 * 00494 KK = K + KSTEP - 1 00495 IF( KP.NE.KK ) THEN 00496 * 00497 * Interchange rows and columns KK and KP in the trailing 00498 * submatrix A(k:n,k:n) 00499 * 00500 IF( KP.LT.N ) 00501 $ CALL DSWAP( N-KP, A( KP+1, KK ), 1, A( KP+1, KP ), 1 ) 00502 CALL DSWAP( KP-KK-1, A( KK+1, KK ), 1, A( KP, KK+1 ), 00503 $ LDA ) 00504 T = A( KK, KK ) 00505 A( KK, KK ) = A( KP, KP ) 00506 A( KP, KP ) = T 00507 IF( KSTEP.EQ.2 ) THEN 00508 T = A( K+1, K ) 00509 A( K+1, K ) = A( KP, K ) 00510 A( KP, K ) = T 00511 END IF 00512 END IF 00513 * 00514 * Update the trailing submatrix 00515 * 00516 IF( KSTEP.EQ.1 ) THEN 00517 * 00518 * 1-by-1 pivot block D(k): column k now holds 00519 * 00520 * W(k) = L(k)*D(k) 00521 * 00522 * where L(k) is the k-th column of L 00523 * 00524 IF( K.LT.N ) THEN 00525 * 00526 * Perform a rank-1 update of A(k+1:n,k+1:n) as 00527 * 00528 * A := A - L(k)*D(k)*L(k)**T = A - W(k)*(1/D(k))*W(k)**T 00529 * 00530 D11 = ONE / A( K, K ) 00531 CALL DSYR( UPLO, N-K, -D11, A( K+1, K ), 1, 00532 $ A( K+1, K+1 ), LDA ) 00533 * 00534 * Store L(k) in column K 00535 * 00536 CALL DSCAL( N-K, D11, A( K+1, K ), 1 ) 00537 END IF 00538 ELSE 00539 * 00540 * 2-by-2 pivot block D(k) 00541 * 00542 IF( K.LT.N-1 ) THEN 00543 * 00544 * Perform a rank-2 update of A(k+2:n,k+2:n) as 00545 * 00546 * A := A - ( (A(k) A(k+1))*D(k)**(-1) ) * (A(k) A(k+1))**T 00547 * 00548 * where L(k) and L(k+1) are the k-th and (k+1)-th 00549 * columns of L 00550 * 00551 D21 = A( K+1, K ) 00552 D11 = A( K+1, K+1 ) / D21 00553 D22 = A( K, K ) / D21 00554 T = ONE / ( D11*D22-ONE ) 00555 D21 = T / D21 00556 * 00557 DO 60 J = K + 2, N 00558 * 00559 WK = D21*( D11*A( J, K )-A( J, K+1 ) ) 00560 WKP1 = D21*( D22*A( J, K+1 )-A( J, K ) ) 00561 * 00562 DO 50 I = J, N 00563 A( I, J ) = A( I, J ) - A( I, K )*WK - 00564 $ A( I, K+1 )*WKP1 00565 50 CONTINUE 00566 * 00567 A( J, K ) = WK 00568 A( J, K+1 ) = WKP1 00569 * 00570 60 CONTINUE 00571 END IF 00572 END IF 00573 END IF 00574 * 00575 * Store details of the interchanges in IPIV 00576 * 00577 IF( KSTEP.EQ.1 ) THEN 00578 IPIV( K ) = KP 00579 ELSE 00580 IPIV( K ) = -KP 00581 IPIV( K+1 ) = -KP 00582 END IF 00583 * 00584 * Increase K and return to the start of the main loop 00585 * 00586 K = K + KSTEP 00587 GO TO 40 00588 * 00589 END IF 00590 * 00591 70 CONTINUE 00592 * 00593 RETURN 00594 * 00595 * End of DSYTF2 00596 * 00597 END