LAPACK  3.4.2
LAPACK: Linear Algebra PACKage
 All Files Functions Groups
cpstf2.f
Go to the documentation of this file.
1 *> \brief \b CPSTF2 computes the Cholesky factorization with complete pivoting of a real symmetric or complex Hermitian positive semi-definite matrix.
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 *> \htmlonly
9 *> Download CPSTF2 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cpstf2.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cpstf2.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cpstf2.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 * Definition:
19 * ===========
20 *
21 * SUBROUTINE CPSTF2( UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO )
22 *
23 * .. Scalar Arguments ..
24 * REAL TOL
25 * INTEGER INFO, LDA, N, RANK
26 * CHARACTER UPLO
27 * ..
28 * .. Array Arguments ..
29 * COMPLEX A( LDA, * )
30 * REAL WORK( 2*N )
31 * INTEGER PIV( N )
32 * ..
33 *
34 *
35 *> \par Purpose:
36 * =============
37 *>
38 *> \verbatim
39 *>
40 *> CPSTF2 computes the Cholesky factorization with complete
41 *> pivoting of a complex Hermitian positive semidefinite matrix A.
42 *>
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.
48 *>
49 *> This algorithm does not attempt to check that A is positive
50 *> semidefinite. This version of the algorithm calls level 2 BLAS.
51 *> \endverbatim
52 *
53 * Arguments:
54 * ==========
55 *
56 *> \param[in] UPLO
57 *> \verbatim
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
63 *> \endverbatim
64 *>
65 *> \param[in] N
66 *> \verbatim
67 *> N is INTEGER
68 *> The order of the matrix A. N >= 0.
69 *> \endverbatim
70 *>
71 *> \param[in,out] A
72 *> \verbatim
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.
81 *>
82 *> On exit, if INFO = 0, the factor U or L from the Cholesky
83 *> factorization as above.
84 *> \endverbatim
85 *>
86 *> \param[out] PIV
87 *> \verbatim
88 *> PIV is INTEGER array, dimension (N)
89 *> PIV is such that the nonzero entries are P( PIV(K), K ) = 1.
90 *> \endverbatim
91 *>
92 *> \param[out] RANK
93 *> \verbatim
94 *> RANK is INTEGER
95 *> The rank of A given by the number of steps the algorithm
96 *> completed.
97 *> \endverbatim
98 *>
99 *> \param[in] TOL
100 *> \verbatim
101 *> TOL is REAL
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.
105 *> \endverbatim
106 *>
107 *> \param[in] LDA
108 *> \verbatim
109 *> LDA is INTEGER
110 *> The leading dimension of the array A. LDA >= max(1,N).
111 *> \endverbatim
112 *>
113 *> \param[out] WORK
114 *> \verbatim
115 *> WORK is REAL array, dimension (2*N)
116 *> Work space.
117 *> \endverbatim
118 *>
119 *> \param[out] INFO
120 *> \verbatim
121 *> INFO is INTEGER
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 indefinite. See Section 7 of
126 *> LAPACK Working Note #161 for further information.
127 *> \endverbatim
128 *
129 * Authors:
130 * ========
131 *
132 *> \author Univ. of Tennessee
133 *> \author Univ. of California Berkeley
134 *> \author Univ. of Colorado Denver
135 *> \author NAG Ltd.
136 *
137 *> \date September 2012
138 *
139 *> \ingroup complexOTHERcomputational
140 *
141 * =====================================================================
142  SUBROUTINE cpstf2( UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO )
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 *
405  END