LAPACK  3.5.0
LAPACK: Linear Algebra PACKage
cpstf2.f File Reference

Go to the source code of this file.

Functions/Subroutines

subroutine cpstf2 (UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO)
 CPSTF2 computes the Cholesky factorization with complete pivoting of a real symmetric or complex Hermitian positive semi-definite matrix. More...
 

Function/Subroutine Documentation

subroutine cpstf2 ( character  UPLO,
integer  N,
complex, dimension( lda, * )  A,
integer  LDA,
integer, dimension( n )  PIV,
integer  RANK,
real  TOL,
real, dimension( 2*n )  WORK,
integer  INFO 
)

CPSTF2 computes the Cholesky factorization with complete pivoting of a real symmetric or complex Hermitian positive semi-definite matrix.

Download CPSTF2 + dependencies [TGZ] [ZIP] [TXT]

Purpose:
 CPSTF2 computes the Cholesky factorization with complete
 pivoting of a complex Hermitian positive semidefinite matrix A.

 The factorization has the form
    P**T * A * P = U**H * U ,  if UPLO = 'U',
    P**T * A * P = L  * L**H,  if UPLO = 'L',
 where U is an upper triangular matrix and L is lower triangular, and
 P is stored as vector PIV.

 This algorithm does not attempt to check that A is positive
 semidefinite. This version of the algorithm calls level 2 BLAS.
Parameters
[in]UPLO
          UPLO is CHARACTER*1
          Specifies whether the upper or lower triangular part of the
          symmetric matrix A is stored.
          = 'U':  Upper triangular
          = 'L':  Lower triangular
[in]N
          N is INTEGER
          The order of the matrix A.  N >= 0.
[in,out]A
          A is COMPLEX array, dimension (LDA,N)
          On entry, the symmetric matrix A.  If UPLO = 'U', the leading
          n by n upper triangular part of A contains the upper
          triangular part of the matrix A, and the strictly lower
          triangular part of A is not referenced.  If UPLO = 'L', the
          leading n by n lower triangular part of A contains the lower
          triangular part of the matrix A, and the strictly upper
          triangular part of A is not referenced.

          On exit, if INFO = 0, the factor U or L from the Cholesky
          factorization as above.
[out]PIV
          PIV is INTEGER array, dimension (N)
          PIV is such that the nonzero entries are P( PIV(K), K ) = 1.
[out]RANK
          RANK is INTEGER
          The rank of A given by the number of steps the algorithm
          completed.
[in]TOL
          TOL is REAL
          User defined tolerance. If TOL < 0, then N*U*MAX( A( K,K ) )
          will be used. The algorithm terminates at the (K-1)st step
          if the pivot <= TOL.
[in]LDA
          LDA is INTEGER
          The leading dimension of the array A.  LDA >= max(1,N).
[out]WORK
          WORK is REAL array, dimension (2*N)
          Work space.
[out]INFO
          INFO is INTEGER
          < 0: If INFO = -K, the K-th argument had an illegal value,
          = 0: algorithm completed successfully, and
          > 0: the matrix A is either rank deficient with computed rank
               as returned in RANK, or is indefinite.  See Section 7 of
               LAPACK Working Note #161 for further information.
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.
Date
September 2012

Definition at line 143 of file cpstf2.f.

143 *
144 * -- LAPACK computational routine (version 3.4.2) --
145 * -- LAPACK is a software package provided by Univ. of Tennessee, --
146 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
147 * September 2012
148 *
149 * .. Scalar Arguments ..
150  REAL tol
151  INTEGER info, lda, n, rank
152  CHARACTER uplo
153 * ..
154 * .. Array Arguments ..
155  COMPLEX a( lda, * )
156  REAL work( 2*n )
157  INTEGER piv( n )
158 * ..
159 *
160 * =====================================================================
161 *
162 * .. Parameters ..
163  REAL one, zero
164  parameter( one = 1.0e+0, zero = 0.0e+0 )
165  COMPLEX cone
166  parameter( cone = ( 1.0e+0, 0.0e+0 ) )
167 * ..
168 * .. Local Scalars ..
169  COMPLEX ctemp
170  REAL ajj, sstop, stemp
171  INTEGER i, itemp, j, pvt
172  LOGICAL upper
173 * ..
174 * .. External Functions ..
175  REAL slamch
176  LOGICAL lsame, sisnan
177  EXTERNAL slamch, lsame, sisnan
178 * ..
179 * .. External Subroutines ..
180  EXTERNAL cgemv, clacgv, csscal, cswap, xerbla
181 * ..
182 * .. Intrinsic Functions ..
183  INTRINSIC conjg, max, REAL, sqrt
184 * ..
185 * .. Executable Statements ..
186 *
187 * Test the input parameters
188 *
189  info = 0
190  upper = lsame( uplo, 'U' )
191  IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
192  info = -1
193  ELSE IF( n.LT.0 ) THEN
194  info = -2
195  ELSE IF( lda.LT.max( 1, n ) ) THEN
196  info = -4
197  END IF
198  IF( info.NE.0 ) THEN
199  CALL xerbla( 'CPSTF2', -info )
200  RETURN
201  END IF
202 *
203 * Quick return if possible
204 *
205  IF( n.EQ.0 )
206  $ RETURN
207 *
208 * Initialize PIV
209 *
210  DO 100 i = 1, n
211  piv( i ) = i
212  100 CONTINUE
213 *
214 * Compute stopping value
215 *
216  DO 110 i = 1, n
217  work( i ) = REAL( A( I, I ) )
218  110 CONTINUE
219  pvt = maxloc( work( 1:n ), 1 )
220  ajj = REAL ( A( PVT, PVT ) )
221  IF( ajj.EQ.zero.OR.sisnan( ajj ) ) THEN
222  rank = 0
223  info = 1
224  GO TO 200
225  END IF
226 *
227 * Compute stopping value if not supplied
228 *
229  IF( tol.LT.zero ) THEN
230  sstop = n * slamch( 'Epsilon' ) * ajj
231  ELSE
232  sstop = tol
233  END IF
234 *
235 * Set first half of WORK to zero, holds dot products
236 *
237  DO 120 i = 1, n
238  work( i ) = 0
239  120 CONTINUE
240 *
241  IF( upper ) THEN
242 *
243 * Compute the Cholesky factorization P**T * A * P = U**H * U
244 *
245  DO 150 j = 1, n
246 *
247 * Find pivot, test for exit, else swap rows and columns
248 * Update dot products, compute possible pivots which are
249 * stored in the second half of WORK
250 *
251  DO 130 i = j, n
252 *
253  IF( j.GT.1 ) THEN
254  work( i ) = work( i ) +
255  $ REAL( CONJG( A( J-1, I ) )*
256  $ a( j-1, i ) )
257  END IF
258  work( n+i ) = REAL( A( I, I ) ) - work( i )
259 *
260  130 CONTINUE
261 *
262  IF( j.GT.1 ) THEN
263  itemp = maxloc( work( (n+j):(2*n) ), 1 )
264  pvt = itemp + j - 1
265  ajj = work( n+pvt )
266  IF( ajj.LE.sstop.OR.sisnan( ajj ) ) THEN
267  a( j, j ) = ajj
268  GO TO 190
269  END IF
270  END IF
271 *
272  IF( j.NE.pvt ) THEN
273 *
274 * Pivot OK, so can now swap pivot rows and columns
275 *
276  a( pvt, pvt ) = a( j, j )
277  CALL cswap( j-1, a( 1, j ), 1, a( 1, pvt ), 1 )
278  IF( pvt.LT.n )
279  $ CALL cswap( n-pvt, a( j, pvt+1 ), lda,
280  $ a( pvt, pvt+1 ), lda )
281  DO 140 i = j + 1, pvt - 1
282  ctemp = conjg( a( j, i ) )
283  a( j, i ) = conjg( a( i, pvt ) )
284  a( i, pvt ) = ctemp
285  140 CONTINUE
286  a( j, pvt ) = conjg( a( j, pvt ) )
287 *
288 * Swap dot products and PIV
289 *
290  stemp = work( j )
291  work( j ) = work( pvt )
292  work( pvt ) = stemp
293  itemp = piv( pvt )
294  piv( pvt ) = piv( j )
295  piv( j ) = itemp
296  END IF
297 *
298  ajj = sqrt( ajj )
299  a( j, j ) = ajj
300 *
301 * Compute elements J+1:N of row J
302 *
303  IF( j.LT.n ) THEN
304  CALL clacgv( j-1, a( 1, j ), 1 )
305  CALL cgemv( 'Trans', j-1, n-j, -cone, a( 1, j+1 ), lda,
306  $ a( 1, j ), 1, cone, a( j, j+1 ), lda )
307  CALL clacgv( j-1, a( 1, j ), 1 )
308  CALL csscal( n-j, one / ajj, a( j, j+1 ), lda )
309  END IF
310 *
311  150 CONTINUE
312 *
313  ELSE
314 *
315 * Compute the Cholesky factorization P**T * A * P = L * L**H
316 *
317  DO 180 j = 1, n
318 *
319 * Find pivot, test for exit, else swap rows and columns
320 * Update dot products, compute possible pivots which are
321 * stored in the second half of WORK
322 *
323  DO 160 i = j, n
324 *
325  IF( j.GT.1 ) THEN
326  work( i ) = work( i ) +
327  $ REAL( CONJG( A( I, J-1 ) )*
328  $ a( i, j-1 ) )
329  END IF
330  work( n+i ) = REAL( A( I, I ) ) - work( i )
331 *
332  160 CONTINUE
333 *
334  IF( j.GT.1 ) THEN
335  itemp = maxloc( work( (n+j):(2*n) ), 1 )
336  pvt = itemp + j - 1
337  ajj = work( n+pvt )
338  IF( ajj.LE.sstop.OR.sisnan( ajj ) ) THEN
339  a( j, j ) = ajj
340  GO TO 190
341  END IF
342  END IF
343 *
344  IF( j.NE.pvt ) THEN
345 *
346 * Pivot OK, so can now swap pivot rows and columns
347 *
348  a( pvt, pvt ) = a( j, j )
349  CALL cswap( j-1, a( j, 1 ), lda, a( pvt, 1 ), lda )
350  IF( pvt.LT.n )
351  $ CALL cswap( n-pvt, a( pvt+1, j ), 1, a( pvt+1, pvt ),
352  $ 1 )
353  DO 170 i = j + 1, pvt - 1
354  ctemp = conjg( a( i, j ) )
355  a( i, j ) = conjg( a( pvt, i ) )
356  a( pvt, i ) = ctemp
357  170 CONTINUE
358  a( pvt, j ) = conjg( a( pvt, j ) )
359 *
360 * Swap dot products and PIV
361 *
362  stemp = work( j )
363  work( j ) = work( pvt )
364  work( pvt ) = stemp
365  itemp = piv( pvt )
366  piv( pvt ) = piv( j )
367  piv( j ) = itemp
368  END IF
369 *
370  ajj = sqrt( ajj )
371  a( j, j ) = ajj
372 *
373 * Compute elements J+1:N of column J
374 *
375  IF( j.LT.n ) THEN
376  CALL clacgv( j-1, a( j, 1 ), lda )
377  CALL cgemv( 'No Trans', n-j, j-1, -cone, a( j+1, 1 ),
378  $ lda, a( j, 1 ), lda, cone, a( j+1, j ), 1 )
379  CALL clacgv( j-1, a( j, 1 ), lda )
380  CALL csscal( n-j, one / ajj, a( j+1, j ), 1 )
381  END IF
382 *
383  180 CONTINUE
384 *
385  END IF
386 *
387 * Ran to completion, A has full rank
388 *
389  rank = n
390 *
391  GO TO 200
392  190 CONTINUE
393 *
394 * Rank is number of steps completed. Set INFO = 1 to signal
395 * that the factorization cannot be used to solve a system.
396 *
397  rank = j - 1
398  info = 1
399 *
400  200 CONTINUE
401  RETURN
402 *
403 * End of CPSTF2
404 *
subroutine xerbla(SRNAME, INFO)
XERBLA
Definition: xerbla.f:62
subroutine cswap(N, CX, INCX, CY, INCY)
CSWAP
Definition: cswap.f:52
logical function lsame(CA, CB)
LSAME
Definition: lsame.f:55
subroutine clacgv(N, X, INCX)
CLACGV conjugates a complex vector.
Definition: clacgv.f:76
subroutine cgemv(TRANS, M, N, ALPHA, A, LDA, X, INCX, BETA, Y, INCY)
CGEMV
Definition: cgemv.f:160
real function slamch(CMACH)
SLAMCH
Definition: slamch.f:69
subroutine csscal(N, SA, CX, INCX)
CSSCAL
Definition: csscal.f:54
logical function sisnan(SIN)
SISNAN tests input for NaN.
Definition: sisnan.f:61

Here is the call graph for this function:

Here is the caller graph for this function: