LAPACK  3.4.2
LAPACK: Linear Algebra PACKage
 All Files Functions Groups
dpstf2.f
Go to the documentation of this file.
1 *> \brief \b DPSTF2 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 DPSTF2 + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dpstf2.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dpstf2.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dpstf2.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 * Definition:
19 * ===========
20 *
21 * SUBROUTINE DPSTF2( UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO )
22 *
23 * .. Scalar Arguments ..
24 * DOUBLE PRECISION TOL
25 * INTEGER INFO, LDA, N, RANK
26 * CHARACTER UPLO
27 * ..
28 * .. Array Arguments ..
29 * DOUBLE PRECISION A( LDA, * ), WORK( 2*N )
30 * INTEGER PIV( N )
31 * ..
32 *
33 *
34 *> \par Purpose:
35 * =============
36 *>
37 *> \verbatim
38 *>
39 *> DPSTF2 computes the Cholesky factorization with complete
40 *> pivoting of a real symmetric positive semidefinite matrix A.
41 *>
42 *> The factorization has the form
43 *> P**T * A * P = U**T * U , if UPLO = 'U',
44 *> P**T * A * P = L * L**T, if UPLO = 'L',
45 *> where U is an upper triangular matrix and L is lower triangular, and
46 *> P is stored as vector PIV.
47 *>
48 *> This algorithm does not attempt to check that A is positive
49 *> semidefinite. This version of the algorithm calls level 2 BLAS.
50 *> \endverbatim
51 *
52 * Arguments:
53 * ==========
54 *
55 *> \param[in] UPLO
56 *> \verbatim
57 *> UPLO is CHARACTER*1
58 *> Specifies whether the upper or lower triangular part of the
59 *> symmetric matrix A is stored.
60 *> = 'U': Upper triangular
61 *> = 'L': Lower triangular
62 *> \endverbatim
63 *>
64 *> \param[in] N
65 *> \verbatim
66 *> N is INTEGER
67 *> The order of the matrix A. N >= 0.
68 *> \endverbatim
69 *>
70 *> \param[in,out] A
71 *> \verbatim
72 *> A is DOUBLE PRECISION array, dimension (LDA,N)
73 *> On entry, the symmetric matrix A. If UPLO = 'U', the leading
74 *> n by n upper triangular part of A contains the upper
75 *> triangular part of the matrix A, and the strictly lower
76 *> triangular part of A is not referenced. If UPLO = 'L', the
77 *> leading n by n lower triangular part of A contains the lower
78 *> triangular part of the matrix A, and the strictly upper
79 *> triangular part of A is not referenced.
80 *>
81 *> On exit, if INFO = 0, the factor U or L from the Cholesky
82 *> factorization as above.
83 *> \endverbatim
84 *>
85 *> \param[out] PIV
86 *> \verbatim
87 *> PIV is INTEGER array, dimension (N)
88 *> PIV is such that the nonzero entries are P( PIV(K), K ) = 1.
89 *> \endverbatim
90 *>
91 *> \param[out] RANK
92 *> \verbatim
93 *> RANK is INTEGER
94 *> The rank of A given by the number of steps the algorithm
95 *> completed.
96 *> \endverbatim
97 *>
98 *> \param[in] TOL
99 *> \verbatim
100 *> TOL is DOUBLE PRECISION
101 *> User defined tolerance. If TOL < 0, then N*U*MAX( A( K,K ) )
102 *> will be used. The algorithm terminates at the (K-1)st step
103 *> if the pivot <= TOL.
104 *> \endverbatim
105 *>
106 *> \param[in] LDA
107 *> \verbatim
108 *> LDA is INTEGER
109 *> The leading dimension of the array A. LDA >= max(1,N).
110 *> \endverbatim
111 *>
112 *> \param[out] WORK
113 *> \verbatim
114 *> WORK is DOUBLE PRECISION array, dimension (2*N)
115 *> Work space.
116 *> \endverbatim
117 *>
118 *> \param[out] INFO
119 *> \verbatim
120 *> INFO is INTEGER
121 *> < 0: If INFO = -K, the K-th argument had an illegal value,
122 *> = 0: algorithm completed successfully, and
123 *> > 0: the matrix A is either rank deficient with computed rank
124 *> as returned in RANK, or is indefinite. See Section 7 of
125 *> LAPACK Working Note #161 for further information.
126 *> \endverbatim
127 *
128 * Authors:
129 * ========
130 *
131 *> \author Univ. of Tennessee
132 *> \author Univ. of California Berkeley
133 *> \author Univ. of Colorado Denver
134 *> \author NAG Ltd.
135 *
136 *> \date September 2012
137 *
138 *> \ingroup doubleOTHERcomputational
139 *
140 * =====================================================================
141  SUBROUTINE dpstf2( UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO )
142 *
143 * -- LAPACK computational routine (version 3.4.2) --
144 * -- LAPACK is a software package provided by Univ. of Tennessee, --
145 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
146 * September 2012
147 *
148 * .. Scalar Arguments ..
149  DOUBLE PRECISION tol
150  INTEGER info, lda, n, rank
151  CHARACTER uplo
152 * ..
153 * .. Array Arguments ..
154  DOUBLE PRECISION a( lda, * ), work( 2*n )
155  INTEGER piv( n )
156 * ..
157 *
158 * =====================================================================
159 *
160 * .. Parameters ..
161  DOUBLE PRECISION one, zero
162  parameter( one = 1.0d+0, zero = 0.0d+0 )
163 * ..
164 * .. Local Scalars ..
165  DOUBLE PRECISION ajj, dstop, dtemp
166  INTEGER i, itemp, j, pvt
167  LOGICAL upper
168 * ..
169 * .. External Functions ..
170  DOUBLE PRECISION dlamch
171  LOGICAL lsame, disnan
172  EXTERNAL dlamch, lsame, disnan
173 * ..
174 * .. External Subroutines ..
175  EXTERNAL dgemv, dscal, dswap, xerbla
176 * ..
177 * .. Intrinsic Functions ..
178  INTRINSIC max, sqrt, maxloc
179 * ..
180 * .. Executable Statements ..
181 *
182 * Test the input parameters
183 *
184  info = 0
185  upper = lsame( uplo, 'U' )
186  IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
187  info = -1
188  ELSE IF( n.LT.0 ) THEN
189  info = -2
190  ELSE IF( lda.LT.max( 1, n ) ) THEN
191  info = -4
192  END IF
193  IF( info.NE.0 ) THEN
194  CALL xerbla( 'DPSTF2', -info )
195  return
196  END IF
197 *
198 * Quick return if possible
199 *
200  IF( n.EQ.0 )
201  $ return
202 *
203 * Initialize PIV
204 *
205  DO 100 i = 1, n
206  piv( i ) = i
207  100 continue
208 *
209 * Compute stopping value
210 *
211  pvt = 1
212  ajj = a( pvt, pvt )
213  DO i = 2, n
214  IF( a( i, i ).GT.ajj ) THEN
215  pvt = i
216  ajj = a( pvt, pvt )
217  END IF
218  END DO
219  IF( ajj.EQ.zero.OR.disnan( ajj ) ) THEN
220  rank = 0
221  info = 1
222  go to 170
223  END IF
224 *
225 * Compute stopping value if not supplied
226 *
227  IF( tol.LT.zero ) THEN
228  dstop = n * dlamch( 'Epsilon' ) * ajj
229  ELSE
230  dstop = tol
231  END IF
232 *
233 * Set first half of WORK to zero, holds dot products
234 *
235  DO 110 i = 1, n
236  work( i ) = 0
237  110 continue
238 *
239  IF( upper ) THEN
240 *
241 * Compute the Cholesky factorization P**T * A * P = U**T * U
242 *
243  DO 130 j = 1, n
244 *
245 * Find pivot, test for exit, else swap rows and columns
246 * Update dot products, compute possible pivots which are
247 * stored in the second half of WORK
248 *
249  DO 120 i = j, n
250 *
251  IF( j.GT.1 ) THEN
252  work( i ) = work( i ) + a( j-1, i )**2
253  END IF
254  work( n+i ) = a( i, i ) - work( i )
255 *
256  120 continue
257 *
258  IF( j.GT.1 ) THEN
259  itemp = maxloc( work( (n+j):(2*n) ), 1 )
260  pvt = itemp + j - 1
261  ajj = work( n+pvt )
262  IF( ajj.LE.dstop.OR.disnan( ajj ) ) THEN
263  a( j, j ) = ajj
264  go to 160
265  END IF
266  END IF
267 *
268  IF( j.NE.pvt ) THEN
269 *
270 * Pivot OK, so can now swap pivot rows and columns
271 *
272  a( pvt, pvt ) = a( j, j )
273  CALL dswap( j-1, a( 1, j ), 1, a( 1, pvt ), 1 )
274  IF( pvt.LT.n )
275  $ CALL dswap( n-pvt, a( j, pvt+1 ), lda,
276  $ a( pvt, pvt+1 ), lda )
277  CALL dswap( pvt-j-1, a( j, j+1 ), lda, a( j+1, pvt ), 1 )
278 *
279 * Swap dot products and PIV
280 *
281  dtemp = work( j )
282  work( j ) = work( pvt )
283  work( pvt ) = dtemp
284  itemp = piv( pvt )
285  piv( pvt ) = piv( j )
286  piv( j ) = itemp
287  END IF
288 *
289  ajj = sqrt( ajj )
290  a( j, j ) = ajj
291 *
292 * Compute elements J+1:N of row J
293 *
294  IF( j.LT.n ) THEN
295  CALL dgemv( 'Trans', j-1, n-j, -one, a( 1, j+1 ), lda,
296  $ a( 1, j ), 1, one, a( j, j+1 ), lda )
297  CALL dscal( n-j, one / ajj, a( j, j+1 ), lda )
298  END IF
299 *
300  130 continue
301 *
302  ELSE
303 *
304 * Compute the Cholesky factorization P**T * A * P = L * L**T
305 *
306  DO 150 j = 1, n
307 *
308 * Find pivot, test for exit, else swap rows and columns
309 * Update dot products, compute possible pivots which are
310 * stored in the second half of WORK
311 *
312  DO 140 i = j, n
313 *
314  IF( j.GT.1 ) THEN
315  work( i ) = work( i ) + a( i, j-1 )**2
316  END IF
317  work( n+i ) = a( i, i ) - work( i )
318 *
319  140 continue
320 *
321  IF( j.GT.1 ) THEN
322  itemp = maxloc( work( (n+j):(2*n) ), 1 )
323  pvt = itemp + j - 1
324  ajj = work( n+pvt )
325  IF( ajj.LE.dstop.OR.disnan( ajj ) ) THEN
326  a( j, j ) = ajj
327  go to 160
328  END IF
329  END IF
330 *
331  IF( j.NE.pvt ) THEN
332 *
333 * Pivot OK, so can now swap pivot rows and columns
334 *
335  a( pvt, pvt ) = a( j, j )
336  CALL dswap( j-1, a( j, 1 ), lda, a( pvt, 1 ), lda )
337  IF( pvt.LT.n )
338  $ CALL dswap( n-pvt, a( pvt+1, j ), 1, a( pvt+1, pvt ),
339  $ 1 )
340  CALL dswap( pvt-j-1, a( j+1, j ), 1, a( pvt, j+1 ), lda )
341 *
342 * Swap dot products and PIV
343 *
344  dtemp = work( j )
345  work( j ) = work( pvt )
346  work( pvt ) = dtemp
347  itemp = piv( pvt )
348  piv( pvt ) = piv( j )
349  piv( j ) = itemp
350  END IF
351 *
352  ajj = sqrt( ajj )
353  a( j, j ) = ajj
354 *
355 * Compute elements J+1:N of column J
356 *
357  IF( j.LT.n ) THEN
358  CALL dgemv( 'No Trans', n-j, j-1, -one, a( j+1, 1 ), lda,
359  $ a( j, 1 ), lda, one, a( j+1, j ), 1 )
360  CALL dscal( n-j, one / ajj, a( j+1, j ), 1 )
361  END IF
362 *
363  150 continue
364 *
365  END IF
366 *
367 * Ran to completion, A has full rank
368 *
369  rank = n
370 *
371  go to 170
372  160 continue
373 *
374 * Rank is number of steps completed. Set INFO = 1 to signal
375 * that the factorization cannot be used to solve a system.
376 *
377  rank = j - 1
378  info = 1
379 *
380  170 continue
381  return
382 *
383 * End of DPSTF2
384 *
385  END