1 *> \brief \b CPSTF2 computes the Cholesky factorization with complete pivoting of complex Hermitian positive semidefinite matrix.
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download CPSTF2 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cpstf2.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cpstf2.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cpstf2.f">
21 * SUBROUTINE CPSTF2( UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO )
23 * .. Scalar Arguments ..
25 * INTEGER INFO, LDA, N, RANK
28 * .. Array Arguments ..
40 *> CPSTF2 computes the Cholesky factorization with complete
41 *> pivoting of a complex Hermitian positive semidefinite matrix A.
43 *> The factorization has the form
44 *> P**T * A * P = U**H * U , if UPLO = 'U',
45 *> P**T * A * P = L * L**H, if UPLO = 'L',
46 *> where U is an upper triangular matrix and L is lower triangular, and
47 *> P is stored as vector PIV.
49 *> This algorithm does not attempt to check that A is positive
50 *> semidefinite. This version of the algorithm calls level 2 BLAS.
58 *> UPLO is CHARACTER*1
59 *> Specifies whether the upper or lower triangular part of the
60 *> symmetric matrix A is stored.
61 *> = 'U': Upper triangular
62 *> = 'L': Lower triangular
68 *> The order of the matrix A. N >= 0.
73 *> A is COMPLEX array, dimension (LDA,N)
74 *> On entry, the symmetric matrix A. If UPLO = 'U', the leading
75 *> n by n upper triangular part of A contains the upper
76 *> triangular part of the matrix A, and the strictly lower
77 *> triangular part of A is not referenced. If UPLO = 'L', the
78 *> leading n by n lower triangular part of A contains the lower
79 *> triangular part of the matrix A, and the strictly upper
80 *> triangular part of A is not referenced.
82 *> On exit, if INFO = 0, the factor U or L from the Cholesky
83 *> factorization as above.
88 *> PIV is INTEGER array, dimension (N)
89 *> PIV is such that the nonzero entries are P( PIV(K), K ) = 1.
95 *> The rank of A given by the number of steps the algorithm
102 *> User defined tolerance. If TOL < 0, then N*U*MAX( A( K,K ) )
103 *> will be used. The algorithm terminates at the (K-1)st step
104 *> if the pivot <= TOL.
110 *> The leading dimension of the array A. LDA >= max(1,N).
115 *> WORK is REAL array, dimension (2*N)
122 *> < 0: If INFO = -K, the K-th argument had an illegal value,
123 *> = 0: algorithm completed successfully, and
124 *> > 0: the matrix A is either rank deficient with computed rank
125 *> as returned in RANK, or is not positive semidefinite. See
126 *> Section 7 of LAPACK Working Note #161 for further
133 *> \author Univ. of Tennessee
134 *> \author Univ. of California Berkeley
135 *> \author Univ. of Colorado Denver
138 *> \date November 2015
140 *> \ingroup complexOTHERcomputational
142 * =====================================================================
143 SUBROUTINE CPSTF2( UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO )
145 * -- LAPACK computational routine (version 3.6.0) --
146 * -- LAPACK is a software package provided by Univ. of Tennessee, --
147 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
150 * .. Scalar Arguments ..
152 INTEGER INFO, LDA, N, RANK
155 * .. Array Arguments ..
161 * =====================================================================
165 PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 )
167 PARAMETER ( CONE = ( 1.0E+0, 0.0E+0 ) )
169 * .. Local Scalars ..
171 REAL AJJ, SSTOP, STEMP
172 INTEGER I, ITEMP, J, PVT
175 * .. External Functions ..
177 LOGICAL LSAME, SISNAN
178 EXTERNAL SLAMCH, LSAME, SISNAN
180 * .. External Subroutines ..
181 EXTERNAL CGEMV, CLACGV, CSSCAL, CSWAP, XERBLA
183 * .. Intrinsic Functions ..
184 INTRINSIC CONJG, MAX, REAL, SQRT
186 * .. Executable Statements ..
188 * Test the input parameters
191 UPPER = LSAME( UPLO, 'U' )
192 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
194 ELSE IF( N.LT.0 ) THEN
196 ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
200 CALL XERBLA( 'CPSTF2', -INFO )
204 * Quick return if possible
215 * Compute stopping value
218 WORK( I ) = REAL( A( I, I ) )
220 PVT = MAXLOC( WORK( 1:N ), 1 )
221 AJJ = REAL ( A( PVT, PVT ) )
222 IF( AJJ.LE.ZERO.OR.SISNAN( AJJ ) ) THEN
228 * Compute stopping value if not supplied
230 IF( TOL.LT.ZERO ) THEN
231 SSTOP = N * SLAMCH( 'Epsilon' ) * AJJ
236 * Set first half of WORK to zero, holds dot products
244 * Compute the Cholesky factorization P**T * A * P = U**H * U
248 * Find pivot, test for exit, else swap rows and columns
249 * Update dot products, compute possible pivots which are
250 * stored in the second half of WORK
255 WORK( I ) = WORK( I ) +
256 $ REAL( CONJG( A( J-1, I ) )*
259 WORK( N+I ) = REAL( A( I, I ) ) - WORK( I )
264 ITEMP = MAXLOC( WORK( (N+J):(2*N) ), 1 )
267 IF( AJJ.LE.SSTOP.OR.SISNAN( AJJ ) ) THEN
275 * Pivot OK, so can now swap pivot rows and columns
277 A( PVT, PVT ) = A( J, J )
278 CALL CSWAP( J-1, A( 1, J ), 1, A( 1, PVT ), 1 )
280 $ CALL CSWAP( N-PVT, A( J, PVT+1 ), LDA,
281 $ A( PVT, PVT+1 ), LDA )
282 DO 140 I = J + 1, PVT - 1
283 CTEMP = CONJG( A( J, I ) )
284 A( J, I ) = CONJG( A( I, PVT ) )
287 A( J, PVT ) = CONJG( A( J, PVT ) )
289 * Swap dot products and PIV
292 WORK( J ) = WORK( PVT )
295 PIV( PVT ) = PIV( J )
302 * Compute elements J+1:N of row J
305 CALL CLACGV( J-1, A( 1, J ), 1 )
306 CALL CGEMV( 'Trans', J-1, N-J, -CONE, A( 1, J+1 ), LDA,
307 $ A( 1, J ), 1, CONE, A( J, J+1 ), LDA )
308 CALL CLACGV( J-1, A( 1, J ), 1 )
309 CALL CSSCAL( N-J, ONE / AJJ, A( J, J+1 ), LDA )
316 * Compute the Cholesky factorization P**T * A * P = L * L**H
320 * Find pivot, test for exit, else swap rows and columns
321 * Update dot products, compute possible pivots which are
322 * stored in the second half of WORK
327 WORK( I ) = WORK( I ) +
328 $ REAL( CONJG( A( I, J-1 ) )*
331 WORK( N+I ) = REAL( A( I, I ) ) - WORK( I )
336 ITEMP = MAXLOC( WORK( (N+J):(2*N) ), 1 )
339 IF( AJJ.LE.SSTOP.OR.SISNAN( AJJ ) ) THEN
347 * Pivot OK, so can now swap pivot rows and columns
349 A( PVT, PVT ) = A( J, J )
350 CALL CSWAP( J-1, A( J, 1 ), LDA, A( PVT, 1 ), LDA )
352 $ CALL CSWAP( N-PVT, A( PVT+1, J ), 1, A( PVT+1, PVT ),
354 DO 170 I = J + 1, PVT - 1
355 CTEMP = CONJG( A( I, J ) )
356 A( I, J ) = CONJG( A( PVT, I ) )
359 A( PVT, J ) = CONJG( A( PVT, J ) )
361 * Swap dot products and PIV
364 WORK( J ) = WORK( PVT )
367 PIV( PVT ) = PIV( J )
374 * Compute elements J+1:N of column J
377 CALL CLACGV( J-1, A( J, 1 ), LDA )
378 CALL CGEMV( 'No Trans', N-J, J-1, -CONE, A( J+1, 1 ),
379 $ LDA, A( J, 1 ), LDA, CONE, A( J+1, J ), 1 )
380 CALL CLACGV( J-1, A( J, 1 ), LDA )
381 CALL CSSCAL( N-J, ONE / AJJ, A( J+1, J ), 1 )
388 * Ran to completion, A has full rank
395 * Rank is number of steps completed. Set INFO = 1 to signal
396 * that the factorization cannot be used to solve a system.