You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

chetf2.f 20 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. *> \brief \b CHETF2 computes the factorization of a complex Hermitian matrix, using the diagonal pivoting method (unblocked algorithm).
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download CHETF2 + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chetf2.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetf2.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetf2.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE CHETF2( UPLO, N, A, LDA, IPIV, INFO )
  22. *
  23. * .. Scalar Arguments ..
  24. * CHARACTER UPLO
  25. * INTEGER INFO, LDA, N
  26. * ..
  27. * .. Array Arguments ..
  28. * INTEGER IPIV( * )
  29. * COMPLEX A( LDA, * )
  30. * ..
  31. *
  32. *
  33. *> \par Purpose:
  34. * =============
  35. *>
  36. *> \verbatim
  37. *>
  38. *> CHETF2 computes the factorization of a complex Hermitian matrix A
  39. *> using the Bunch-Kaufman diagonal pivoting method:
  40. *>
  41. *> A = U*D*U**H or A = L*D*L**H
  42. *>
  43. *> where U (or L) is a product of permutation and unit upper (lower)
  44. *> triangular matrices, U**H is the conjugate transpose of U, and D is
  45. *> Hermitian and block diagonal with 1-by-1 and 2-by-2 diagonal blocks.
  46. *>
  47. *> This is the unblocked version of the algorithm, calling Level 2 BLAS.
  48. *> \endverbatim
  49. *
  50. * Arguments:
  51. * ==========
  52. *
  53. *> \param[in] UPLO
  54. *> \verbatim
  55. *> UPLO is CHARACTER*1
  56. *> Specifies whether the upper or lower triangular part of the
  57. *> Hermitian matrix A is stored:
  58. *> = 'U': Upper triangular
  59. *> = 'L': Lower triangular
  60. *> \endverbatim
  61. *>
  62. *> \param[in] N
  63. *> \verbatim
  64. *> N is INTEGER
  65. *> The order of the matrix A. N >= 0.
  66. *> \endverbatim
  67. *>
  68. *> \param[in,out] A
  69. *> \verbatim
  70. *> A is COMPLEX array, dimension (LDA,N)
  71. *> On entry, the Hermitian matrix A. If UPLO = 'U', the leading
  72. *> n-by-n upper triangular part of A contains the upper
  73. *> triangular part of the matrix A, and the strictly lower
  74. *> triangular part of A is not referenced. If UPLO = 'L', the
  75. *> leading n-by-n lower triangular part of A contains the lower
  76. *> triangular part of the matrix A, and the strictly upper
  77. *> triangular part of A is not referenced.
  78. *>
  79. *> On exit, the block diagonal matrix D and the multipliers used
  80. *> to obtain the factor U or L (see below for further details).
  81. *> \endverbatim
  82. *>
  83. *> \param[in] LDA
  84. *> \verbatim
  85. *> LDA is INTEGER
  86. *> The leading dimension of the array A. LDA >= max(1,N).
  87. *> \endverbatim
  88. *>
  89. *> \param[out] IPIV
  90. *> \verbatim
  91. *> IPIV is INTEGER array, dimension (N)
  92. *> Details of the interchanges and the block structure of D.
  93. *> If IPIV(k) > 0, then rows and columns k and IPIV(k) were
  94. *> interchanged and D(k,k) is a 1-by-1 diagonal block.
  95. *> If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and
  96. *> columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k)
  97. *> is a 2-by-2 diagonal block. If UPLO = 'L' and IPIV(k) =
  98. *> IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were
  99. *> interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block.
  100. *> \endverbatim
  101. *>
  102. *> \param[out] INFO
  103. *> \verbatim
  104. *> INFO is INTEGER
  105. *> = 0: successful exit
  106. *> < 0: if INFO = -k, the k-th argument had an illegal value
  107. *> > 0: if INFO = k, D(k,k) is exactly zero. The factorization
  108. *> has been completed, but the block diagonal matrix D is
  109. *> exactly singular, and division by zero will occur if it
  110. *> is used to solve a system of equations.
  111. *> \endverbatim
  112. *
  113. * Authors:
  114. * ========
  115. *
  116. *> \author Univ. of Tennessee
  117. *> \author Univ. of California Berkeley
  118. *> \author Univ. of Colorado Denver
  119. *> \author NAG Ltd.
  120. *
  121. *> \date September 2012
  122. *
  123. *> \ingroup complexHEcomputational
  124. *
  125. *> \par Further Details:
  126. * =====================
  127. *>
  128. *> \verbatim
  129. *>
  130. *> 09-29-06 - patch from
  131. *> Bobby Cheng, MathWorks
  132. *>
  133. *> Replace l.210 and l.392
  134. *> IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
  135. *> by
  136. *> IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. SISNAN(ABSAKK) ) THEN
  137. *>
  138. *> 01-01-96 - Based on modifications by
  139. *> J. Lewis, Boeing Computer Services Company
  140. *> A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA
  141. *>
  142. *> If UPLO = 'U', then A = U*D*U**H, where
  143. *> U = P(n)*U(n)* ... *P(k)U(k)* ...,
  144. *> i.e., U is a product of terms P(k)*U(k), where k decreases from n to
  145. *> 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
  146. *> and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as
  147. *> defined by IPIV(k), and U(k) is a unit upper triangular matrix, such
  148. *> that if the diagonal block D(k) is of order s (s = 1 or 2), then
  149. *>
  150. *> ( I v 0 ) k-s
  151. *> U(k) = ( 0 I 0 ) s
  152. *> ( 0 0 I ) n-k
  153. *> k-s s n-k
  154. *>
  155. *> If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k).
  156. *> If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k),
  157. *> and A(k,k), and v overwrites A(1:k-2,k-1:k).
  158. *>
  159. *> If UPLO = 'L', then A = L*D*L**H, where
  160. *> L = P(1)*L(1)* ... *P(k)*L(k)* ...,
  161. *> i.e., L is a product of terms P(k)*L(k), where k increases from 1 to
  162. *> n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1
  163. *> and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as
  164. *> defined by IPIV(k), and L(k) is a unit lower triangular matrix, such
  165. *> that if the diagonal block D(k) is of order s (s = 1 or 2), then
  166. *>
  167. *> ( I 0 0 ) k-1
  168. *> L(k) = ( 0 I 0 ) s
  169. *> ( 0 v I ) n-k-s+1
  170. *> k-1 s n-k-s+1
  171. *>
  172. *> If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k).
  173. *> If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k),
  174. *> and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1).
  175. *> \endverbatim
  176. *>
  177. * =====================================================================
  178. SUBROUTINE CHETF2( UPLO, N, A, LDA, IPIV, INFO )
  179. *
  180. * -- LAPACK computational routine (version 3.4.2) --
  181. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  182. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  183. * September 2012
  184. *
  185. * .. Scalar Arguments ..
  186. CHARACTER UPLO
  187. INTEGER INFO, LDA, N
  188. * ..
  189. * .. Array Arguments ..
  190. INTEGER IPIV( * )
  191. COMPLEX A( LDA, * )
  192. * ..
  193. *
  194. * =====================================================================
  195. *
  196. * .. Parameters ..
  197. REAL ZERO, ONE
  198. PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0 )
  199. REAL EIGHT, SEVTEN
  200. PARAMETER ( EIGHT = 8.0E+0, SEVTEN = 17.0E+0 )
  201. * ..
  202. * .. Local Scalars ..
  203. LOGICAL UPPER
  204. INTEGER I, IMAX, J, JMAX, K, KK, KP, KSTEP
  205. REAL ABSAKK, ALPHA, COLMAX, D, D11, D22, R1, ROWMAX,
  206. $ TT
  207. COMPLEX D12, D21, T, WK, WKM1, WKP1, ZDUM
  208. * ..
  209. * .. External Functions ..
  210. LOGICAL LSAME, SISNAN
  211. INTEGER ICAMAX
  212. REAL SLAPY2
  213. EXTERNAL LSAME, ICAMAX, SLAPY2, SISNAN
  214. * ..
  215. * .. External Subroutines ..
  216. EXTERNAL CHER, CSSCAL, CSWAP, XERBLA
  217. * ..
  218. * .. Intrinsic Functions ..
  219. INTRINSIC ABS, AIMAG, CMPLX, CONJG, MAX, REAL, SQRT
  220. * ..
  221. * .. Statement Functions ..
  222. REAL CABS1
  223. * ..
  224. * .. Statement Function definitions ..
  225. CABS1( ZDUM ) = ABS( REAL( ZDUM ) ) + ABS( AIMAG( ZDUM ) )
  226. * ..
  227. * .. Executable Statements ..
  228. *
  229. * Test the input parameters.
  230. *
  231. INFO = 0
  232. UPPER = LSAME( UPLO, 'U' )
  233. IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
  234. INFO = -1
  235. ELSE IF( N.LT.0 ) THEN
  236. INFO = -2
  237. ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
  238. INFO = -4
  239. END IF
  240. IF( INFO.NE.0 ) THEN
  241. CALL XERBLA( 'CHETF2', -INFO )
  242. RETURN
  243. END IF
  244. *
  245. * Initialize ALPHA for use in choosing pivot block size.
  246. *
  247. ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT
  248. *
  249. IF( UPPER ) THEN
  250. *
  251. * Factorize A as U*D*U**H using the upper triangle of A
  252. *
  253. * K is the main loop index, decreasing from N to 1 in steps of
  254. * 1 or 2
  255. *
  256. K = N
  257. 10 CONTINUE
  258. *
  259. * If K < 1, exit from loop
  260. *
  261. IF( K.LT.1 )
  262. $ GO TO 90
  263. KSTEP = 1
  264. *
  265. * Determine rows and columns to be interchanged and whether
  266. * a 1-by-1 or 2-by-2 pivot block will be used
  267. *
  268. ABSAKK = ABS( REAL( A( K, K ) ) )
  269. *
  270. * IMAX is the row-index of the largest off-diagonal element in
  271. * column K, and COLMAX is its absolute value
  272. *
  273. IF( K.GT.1 ) THEN
  274. IMAX = ICAMAX( K-1, A( 1, K ), 1 )
  275. COLMAX = CABS1( A( IMAX, K ) )
  276. ELSE
  277. COLMAX = ZERO
  278. END IF
  279. *
  280. IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. SISNAN(ABSAKK) ) THEN
  281. *
  282. * Column K is zero or contains a NaN: set INFO and continue
  283. *
  284. IF( INFO.EQ.0 )
  285. $ INFO = K
  286. KP = K
  287. A( K, K ) = REAL( A( K, K ) )
  288. ELSE
  289. IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
  290. *
  291. * no interchange, use 1-by-1 pivot block
  292. *
  293. KP = K
  294. ELSE
  295. *
  296. * JMAX is the column-index of the largest off-diagonal
  297. * element in row IMAX, and ROWMAX is its absolute value
  298. *
  299. JMAX = IMAX + ICAMAX( K-IMAX, A( IMAX, IMAX+1 ), LDA )
  300. ROWMAX = CABS1( A( IMAX, JMAX ) )
  301. IF( IMAX.GT.1 ) THEN
  302. JMAX = ICAMAX( IMAX-1, A( 1, IMAX ), 1 )
  303. ROWMAX = MAX( ROWMAX, CABS1( A( JMAX, IMAX ) ) )
  304. END IF
  305. *
  306. IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
  307. *
  308. * no interchange, use 1-by-1 pivot block
  309. *
  310. KP = K
  311. ELSE IF( ABS( REAL( A( IMAX, IMAX ) ) ).GE.ALPHA*ROWMAX )
  312. $ THEN
  313. *
  314. * interchange rows and columns K and IMAX, use 1-by-1
  315. * pivot block
  316. *
  317. KP = IMAX
  318. ELSE
  319. *
  320. * interchange rows and columns K-1 and IMAX, use 2-by-2
  321. * pivot block
  322. *
  323. KP = IMAX
  324. KSTEP = 2
  325. END IF
  326. END IF
  327. *
  328. KK = K - KSTEP + 1
  329. IF( KP.NE.KK ) THEN
  330. *
  331. * Interchange rows and columns KK and KP in the leading
  332. * submatrix A(1:k,1:k)
  333. *
  334. CALL CSWAP( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 )
  335. DO 20 J = KP + 1, KK - 1
  336. T = CONJG( A( J, KK ) )
  337. A( J, KK ) = CONJG( A( KP, J ) )
  338. A( KP, J ) = T
  339. 20 CONTINUE
  340. A( KP, KK ) = CONJG( A( KP, KK ) )
  341. R1 = REAL( A( KK, KK ) )
  342. A( KK, KK ) = REAL( A( KP, KP ) )
  343. A( KP, KP ) = R1
  344. IF( KSTEP.EQ.2 ) THEN
  345. A( K, K ) = REAL( A( K, K ) )
  346. T = A( K-1, K )
  347. A( K-1, K ) = A( KP, K )
  348. A( KP, K ) = T
  349. END IF
  350. ELSE
  351. A( K, K ) = REAL( A( K, K ) )
  352. IF( KSTEP.EQ.2 )
  353. $ A( K-1, K-1 ) = REAL( A( K-1, K-1 ) )
  354. END IF
  355. *
  356. * Update the leading submatrix
  357. *
  358. IF( KSTEP.EQ.1 ) THEN
  359. *
  360. * 1-by-1 pivot block D(k): column k now holds
  361. *
  362. * W(k) = U(k)*D(k)
  363. *
  364. * where U(k) is the k-th column of U
  365. *
  366. * Perform a rank-1 update of A(1:k-1,1:k-1) as
  367. *
  368. * A := A - U(k)*D(k)*U(k)**H = A - W(k)*1/D(k)*W(k)**H
  369. *
  370. R1 = ONE / REAL( A( K, K ) )
  371. CALL CHER( UPLO, K-1, -R1, A( 1, K ), 1, A, LDA )
  372. *
  373. * Store U(k) in column k
  374. *
  375. CALL CSSCAL( K-1, R1, A( 1, K ), 1 )
  376. ELSE
  377. *
  378. * 2-by-2 pivot block D(k): columns k and k-1 now hold
  379. *
  380. * ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k)
  381. *
  382. * where U(k) and U(k-1) are the k-th and (k-1)-th columns
  383. * of U
  384. *
  385. * Perform a rank-2 update of A(1:k-2,1:k-2) as
  386. *
  387. * A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**H
  388. * = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )**H
  389. *
  390. IF( K.GT.2 ) THEN
  391. *
  392. D = SLAPY2( REAL( A( K-1, K ) ),
  393. $ AIMAG( A( K-1, K ) ) )
  394. D22 = REAL( A( K-1, K-1 ) ) / D
  395. D11 = REAL( A( K, K ) ) / D
  396. TT = ONE / ( D11*D22-ONE )
  397. D12 = A( K-1, K ) / D
  398. D = TT / D
  399. *
  400. DO 40 J = K - 2, 1, -1
  401. WKM1 = D*( D11*A( J, K-1 )-CONJG( D12 )*A( J, K ) )
  402. WK = D*( D22*A( J, K )-D12*A( J, K-1 ) )
  403. DO 30 I = J, 1, -1
  404. A( I, J ) = A( I, J ) - A( I, K )*CONJG( WK ) -
  405. $ A( I, K-1 )*CONJG( WKM1 )
  406. 30 CONTINUE
  407. A( J, K ) = WK
  408. A( J, K-1 ) = WKM1
  409. A( J, J ) = CMPLX( REAL( A( J, J ) ), 0.0E+0 )
  410. 40 CONTINUE
  411. *
  412. END IF
  413. *
  414. END IF
  415. END IF
  416. *
  417. * Store details of the interchanges in IPIV
  418. *
  419. IF( KSTEP.EQ.1 ) THEN
  420. IPIV( K ) = KP
  421. ELSE
  422. IPIV( K ) = -KP
  423. IPIV( K-1 ) = -KP
  424. END IF
  425. *
  426. * Decrease K and return to the start of the main loop
  427. *
  428. K = K - KSTEP
  429. GO TO 10
  430. *
  431. ELSE
  432. *
  433. * Factorize A as L*D*L**H using the lower triangle of A
  434. *
  435. * K is the main loop index, increasing from 1 to N in steps of
  436. * 1 or 2
  437. *
  438. K = 1
  439. 50 CONTINUE
  440. *
  441. * If K > N, exit from loop
  442. *
  443. IF( K.GT.N )
  444. $ GO TO 90
  445. KSTEP = 1
  446. *
  447. * Determine rows and columns to be interchanged and whether
  448. * a 1-by-1 or 2-by-2 pivot block will be used
  449. *
  450. ABSAKK = ABS( REAL( A( K, K ) ) )
  451. *
  452. * IMAX is the row-index of the largest off-diagonal element in
  453. * column K, and COLMAX is its absolute value
  454. *
  455. IF( K.LT.N ) THEN
  456. IMAX = K + ICAMAX( N-K, A( K+1, K ), 1 )
  457. COLMAX = CABS1( A( IMAX, K ) )
  458. ELSE
  459. COLMAX = ZERO
  460. END IF
  461. *
  462. IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. SISNAN(ABSAKK) ) THEN
  463. *
  464. * Column K is zero or contains a NaN: set INFO and continue
  465. *
  466. IF( INFO.EQ.0 )
  467. $ INFO = K
  468. KP = K
  469. A( K, K ) = REAL( A( K, K ) )
  470. ELSE
  471. IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
  472. *
  473. * no interchange, use 1-by-1 pivot block
  474. *
  475. KP = K
  476. ELSE
  477. *
  478. * JMAX is the column-index of the largest off-diagonal
  479. * element in row IMAX, and ROWMAX is its absolute value
  480. *
  481. JMAX = K - 1 + ICAMAX( IMAX-K, A( IMAX, K ), LDA )
  482. ROWMAX = CABS1( A( IMAX, JMAX ) )
  483. IF( IMAX.LT.N ) THEN
  484. JMAX = IMAX + ICAMAX( N-IMAX, A( IMAX+1, IMAX ), 1 )
  485. ROWMAX = MAX( ROWMAX, CABS1( A( JMAX, IMAX ) ) )
  486. END IF
  487. *
  488. IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
  489. *
  490. * no interchange, use 1-by-1 pivot block
  491. *
  492. KP = K
  493. ELSE IF( ABS( REAL( A( IMAX, IMAX ) ) ).GE.ALPHA*ROWMAX )
  494. $ THEN
  495. *
  496. * interchange rows and columns K and IMAX, use 1-by-1
  497. * pivot block
  498. *
  499. KP = IMAX
  500. ELSE
  501. *
  502. * interchange rows and columns K+1 and IMAX, use 2-by-2
  503. * pivot block
  504. *
  505. KP = IMAX
  506. KSTEP = 2
  507. END IF
  508. END IF
  509. *
  510. KK = K + KSTEP - 1
  511. IF( KP.NE.KK ) THEN
  512. *
  513. * Interchange rows and columns KK and KP in the trailing
  514. * submatrix A(k:n,k:n)
  515. *
  516. IF( KP.LT.N )
  517. $ CALL CSWAP( N-KP, A( KP+1, KK ), 1, A( KP+1, KP ), 1 )
  518. DO 60 J = KK + 1, KP - 1
  519. T = CONJG( A( J, KK ) )
  520. A( J, KK ) = CONJG( A( KP, J ) )
  521. A( KP, J ) = T
  522. 60 CONTINUE
  523. A( KP, KK ) = CONJG( A( KP, KK ) )
  524. R1 = REAL( A( KK, KK ) )
  525. A( KK, KK ) = REAL( A( KP, KP ) )
  526. A( KP, KP ) = R1
  527. IF( KSTEP.EQ.2 ) THEN
  528. A( K, K ) = REAL( A( K, K ) )
  529. T = A( K+1, K )
  530. A( K+1, K ) = A( KP, K )
  531. A( KP, K ) = T
  532. END IF
  533. ELSE
  534. A( K, K ) = REAL( A( K, K ) )
  535. IF( KSTEP.EQ.2 )
  536. $ A( K+1, K+1 ) = REAL( A( K+1, K+1 ) )
  537. END IF
  538. *
  539. * Update the trailing submatrix
  540. *
  541. IF( KSTEP.EQ.1 ) THEN
  542. *
  543. * 1-by-1 pivot block D(k): column k now holds
  544. *
  545. * W(k) = L(k)*D(k)
  546. *
  547. * where L(k) is the k-th column of L
  548. *
  549. IF( K.LT.N ) THEN
  550. *
  551. * Perform a rank-1 update of A(k+1:n,k+1:n) as
  552. *
  553. * A := A - L(k)*D(k)*L(k)**H = A - W(k)*(1/D(k))*W(k)**H
  554. *
  555. R1 = ONE / REAL( A( K, K ) )
  556. CALL CHER( UPLO, N-K, -R1, A( K+1, K ), 1,
  557. $ A( K+1, K+1 ), LDA )
  558. *
  559. * Store L(k) in column K
  560. *
  561. CALL CSSCAL( N-K, R1, A( K+1, K ), 1 )
  562. END IF
  563. ELSE
  564. *
  565. * 2-by-2 pivot block D(k)
  566. *
  567. IF( K.LT.N-1 ) THEN
  568. *
  569. * Perform a rank-2 update of A(k+2:n,k+2:n) as
  570. *
  571. * A := A - ( L(k) L(k+1) )*D(k)*( L(k) L(k+1) )**H
  572. * = A - ( W(k) W(k+1) )*inv(D(k))*( W(k) W(k+1) )**H
  573. *
  574. * where L(k) and L(k+1) are the k-th and (k+1)-th
  575. * columns of L
  576. *
  577. D = SLAPY2( REAL( A( K+1, K ) ),
  578. $ AIMAG( A( K+1, K ) ) )
  579. D11 = REAL( A( K+1, K+1 ) ) / D
  580. D22 = REAL( A( K, K ) ) / D
  581. TT = ONE / ( D11*D22-ONE )
  582. D21 = A( K+1, K ) / D
  583. D = TT / D
  584. *
  585. DO 80 J = K + 2, N
  586. WK = D*( D11*A( J, K )-D21*A( J, K+1 ) )
  587. WKP1 = D*( D22*A( J, K+1 )-CONJG( D21 )*A( J, K ) )
  588. DO 70 I = J, N
  589. A( I, J ) = A( I, J ) - A( I, K )*CONJG( WK ) -
  590. $ A( I, K+1 )*CONJG( WKP1 )
  591. 70 CONTINUE
  592. A( J, K ) = WK
  593. A( J, K+1 ) = WKP1
  594. A( J, J ) = CMPLX( REAL( A( J, J ) ), 0.0E+0 )
  595. 80 CONTINUE
  596. END IF
  597. END IF
  598. END IF
  599. *
  600. * Store details of the interchanges in IPIV
  601. *
  602. IF( KSTEP.EQ.1 ) THEN
  603. IPIV( K ) = KP
  604. ELSE
  605. IPIV( K ) = -KP
  606. IPIV( K+1 ) = -KP
  607. END IF
  608. *
  609. * Increase K and return to the start of the main loop
  610. *
  611. K = K + KSTEP
  612. GO TO 50
  613. *
  614. END IF
  615. *
  616. 90 CONTINUE
  617. RETURN
  618. *
  619. * End of CHETF2
  620. *
  621. END