LAPACK  3.6.1
LAPACK: Linear Algebra PACKage
dpstf2.f
Go to the documentation of this file.
1 *> \brief \b DPSTF2 computes the Cholesky factorization with complete pivoting of a real symmetric positive semidefinite 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 not positive semidefinite. See
125 *> Section 7 of LAPACK Working Note #161 for further
126 *> 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 November 2015
138 *
139 *> \ingroup doubleOTHERcomputational
140 *
141 * =====================================================================
142  SUBROUTINE dpstf2( UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO )
143 *
144 * -- LAPACK computational routine (version 3.6.0) --
145 * -- LAPACK is a software package provided by Univ. of Tennessee, --
146 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
147 * November 2015
148 *
149 * .. Scalar Arguments ..
150  DOUBLE PRECISION TOL
151  INTEGER INFO, LDA, N, RANK
152  CHARACTER UPLO
153 * ..
154 * .. Array Arguments ..
155  DOUBLE PRECISION A( lda, * ), WORK( 2*n )
156  INTEGER PIV( n )
157 * ..
158 *
159 * =====================================================================
160 *
161 * .. Parameters ..
162  DOUBLE PRECISION ONE, ZERO
163  parameter ( one = 1.0d+0, zero = 0.0d+0 )
164 * ..
165 * .. Local Scalars ..
166  DOUBLE PRECISION AJJ, DSTOP, DTEMP
167  INTEGER I, ITEMP, J, PVT
168  LOGICAL UPPER
169 * ..
170 * .. External Functions ..
171  DOUBLE PRECISION DLAMCH
172  LOGICAL LSAME, DISNAN
173  EXTERNAL dlamch, lsame, disnan
174 * ..
175 * .. External Subroutines ..
176  EXTERNAL dgemv, dscal, dswap, xerbla
177 * ..
178 * .. Intrinsic Functions ..
179  INTRINSIC max, sqrt, maxloc
180 * ..
181 * .. Executable Statements ..
182 *
183 * Test the input parameters
184 *
185  info = 0
186  upper = lsame( uplo, 'U' )
187  IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
188  info = -1
189  ELSE IF( n.LT.0 ) THEN
190  info = -2
191  ELSE IF( lda.LT.max( 1, n ) ) THEN
192  info = -4
193  END IF
194  IF( info.NE.0 ) THEN
195  CALL xerbla( 'DPSTF2', -info )
196  RETURN
197  END IF
198 *
199 * Quick return if possible
200 *
201  IF( n.EQ.0 )
202  $ RETURN
203 *
204 * Initialize PIV
205 *
206  DO 100 i = 1, n
207  piv( i ) = i
208  100 CONTINUE
209 *
210 * Compute stopping value
211 *
212  pvt = 1
213  ajj = a( pvt, pvt )
214  DO i = 2, n
215  IF( a( i, i ).GT.ajj ) THEN
216  pvt = i
217  ajj = a( pvt, pvt )
218  END IF
219  END DO
220  IF( ajj.LE.zero.OR.disnan( ajj ) ) THEN
221  rank = 0
222  info = 1
223  GO TO 170
224  END IF
225 *
226 * Compute stopping value if not supplied
227 *
228  IF( tol.LT.zero ) THEN
229  dstop = n * dlamch( 'Epsilon' ) * ajj
230  ELSE
231  dstop = tol
232  END IF
233 *
234 * Set first half of WORK to zero, holds dot products
235 *
236  DO 110 i = 1, n
237  work( i ) = 0
238  110 CONTINUE
239 *
240  IF( upper ) THEN
241 *
242 * Compute the Cholesky factorization P**T * A * P = U**T * U
243 *
244  DO 130 j = 1, n
245 *
246 * Find pivot, test for exit, else swap rows and columns
247 * Update dot products, compute possible pivots which are
248 * stored in the second half of WORK
249 *
250  DO 120 i = j, n
251 *
252  IF( j.GT.1 ) THEN
253  work( i ) = work( i ) + a( j-1, i )**2
254  END IF
255  work( n+i ) = a( i, i ) - work( i )
256 *
257  120 CONTINUE
258 *
259  IF( j.GT.1 ) THEN
260  itemp = maxloc( work( (n+j):(2*n) ), 1 )
261  pvt = itemp + j - 1
262  ajj = work( n+pvt )
263  IF( ajj.LE.dstop.OR.disnan( ajj ) ) THEN
264  a( j, j ) = ajj
265  GO TO 160
266  END IF
267  END IF
268 *
269  IF( j.NE.pvt ) THEN
270 *
271 * Pivot OK, so can now swap pivot rows and columns
272 *
273  a( pvt, pvt ) = a( j, j )
274  CALL dswap( j-1, a( 1, j ), 1, a( 1, pvt ), 1 )
275  IF( pvt.LT.n )
276  $ CALL dswap( n-pvt, a( j, pvt+1 ), lda,
277  $ a( pvt, pvt+1 ), lda )
278  CALL dswap( pvt-j-1, a( j, j+1 ), lda, a( j+1, pvt ), 1 )
279 *
280 * Swap dot products and PIV
281 *
282  dtemp = work( j )
283  work( j ) = work( pvt )
284  work( pvt ) = dtemp
285  itemp = piv( pvt )
286  piv( pvt ) = piv( j )
287  piv( j ) = itemp
288  END IF
289 *
290  ajj = sqrt( ajj )
291  a( j, j ) = ajj
292 *
293 * Compute elements J+1:N of row J
294 *
295  IF( j.LT.n ) THEN
296  CALL dgemv( 'Trans', j-1, n-j, -one, a( 1, j+1 ), lda,
297  $ a( 1, j ), 1, one, a( j, j+1 ), lda )
298  CALL dscal( n-j, one / ajj, a( j, j+1 ), lda )
299  END IF
300 *
301  130 CONTINUE
302 *
303  ELSE
304 *
305 * Compute the Cholesky factorization P**T * A * P = L * L**T
306 *
307  DO 150 j = 1, n
308 *
309 * Find pivot, test for exit, else swap rows and columns
310 * Update dot products, compute possible pivots which are
311 * stored in the second half of WORK
312 *
313  DO 140 i = j, n
314 *
315  IF( j.GT.1 ) THEN
316  work( i ) = work( i ) + a( i, j-1 )**2
317  END IF
318  work( n+i ) = a( i, i ) - work( i )
319 *
320  140 CONTINUE
321 *
322  IF( j.GT.1 ) THEN
323  itemp = maxloc( work( (n+j):(2*n) ), 1 )
324  pvt = itemp + j - 1
325  ajj = work( n+pvt )
326  IF( ajj.LE.dstop.OR.disnan( ajj ) ) THEN
327  a( j, j ) = ajj
328  GO TO 160
329  END IF
330  END IF
331 *
332  IF( j.NE.pvt ) THEN
333 *
334 * Pivot OK, so can now swap pivot rows and columns
335 *
336  a( pvt, pvt ) = a( j, j )
337  CALL dswap( j-1, a( j, 1 ), lda, a( pvt, 1 ), lda )
338  IF( pvt.LT.n )
339  $ CALL dswap( n-pvt, a( pvt+1, j ), 1, a( pvt+1, pvt ),
340  $ 1 )
341  CALL dswap( pvt-j-1, a( j+1, j ), 1, a( pvt, j+1 ), lda )
342 *
343 * Swap dot products and PIV
344 *
345  dtemp = work( j )
346  work( j ) = work( pvt )
347  work( pvt ) = dtemp
348  itemp = piv( pvt )
349  piv( pvt ) = piv( j )
350  piv( j ) = itemp
351  END IF
352 *
353  ajj = sqrt( ajj )
354  a( j, j ) = ajj
355 *
356 * Compute elements J+1:N of column J
357 *
358  IF( j.LT.n ) THEN
359  CALL dgemv( 'No Trans', n-j, j-1, -one, a( j+1, 1 ), lda,
360  $ a( j, 1 ), lda, one, a( j+1, j ), 1 )
361  CALL dscal( n-j, one / ajj, a( j+1, j ), 1 )
362  END IF
363 *
364  150 CONTINUE
365 *
366  END IF
367 *
368 * Ran to completion, A has full rank
369 *
370  rank = n
371 *
372  GO TO 170
373  160 CONTINUE
374 *
375 * Rank is number of steps completed. Set INFO = 1 to signal
376 * that the factorization cannot be used to solve a system.
377 *
378  rank = j - 1
379  info = 1
380 *
381  170 CONTINUE
382  RETURN
383 *
384 * End of DPSTF2
385 *
386  END
subroutine dpstf2(UPLO, N, A, LDA, PIV, RANK, TOL, WORK, INFO)
DPSTF2 computes the Cholesky factorization with complete pivoting of a real symmetric positive semide...
Definition: dpstf2.f:143
subroutine dgemv(TRANS, M, N, ALPHA, A, LDA, X, INCX, BETA, Y, INCY)
DGEMV
Definition: dgemv.f:158
subroutine xerbla(SRNAME, INFO)
XERBLA
Definition: xerbla.f:62
subroutine dswap(N, DX, INCX, DY, INCY)
DSWAP
Definition: dswap.f:53
subroutine dscal(N, DA, DX, INCX)
DSCAL
Definition: dscal.f:55