exciting-0.9.218
[exciting.git] / src / LAPACK / zpptrf.f
blob738eec4956c47959711fa6786101f4c0061f921e
1 SUBROUTINE ZPPTRF( UPLO, N, AP, INFO )
3 * -- LAPACK routine (version 3.1) --
4 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
5 * November 2006
7 * .. Scalar Arguments ..
8 CHARACTER UPLO
9 INTEGER INFO, N
10 * ..
11 * .. Array Arguments ..
12 COMPLEX*16 AP( * )
13 * ..
15 * Purpose
16 * =======
18 * ZPPTRF computes the Cholesky factorization of a complex Hermitian
19 * positive definite matrix A stored in packed format.
21 * The factorization has the form
22 * A = U**H * U, if UPLO = 'U', or
23 * A = L * L**H, if UPLO = 'L',
24 * where U is an upper triangular matrix and L is lower triangular.
26 * Arguments
27 * =========
29 * UPLO (input) CHARACTER*1
30 * = 'U': Upper triangle of A is stored;
31 * = 'L': Lower triangle of A is stored.
33 * N (input) INTEGER
34 * The order of the matrix A. N >= 0.
36 * AP (input/output) COMPLEX*16 array, dimension (N*(N+1)/2)
37 * On entry, the upper or lower triangle of the Hermitian matrix
38 * A, packed columnwise in a linear array. The j-th column of A
39 * is stored in the array AP as follows:
40 * if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
41 * if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.
42 * See below for further details.
44 * On exit, if INFO = 0, the triangular factor U or L from the
45 * Cholesky factorization A = U**H*U or A = L*L**H, in the same
46 * storage format as A.
48 * INFO (output) INTEGER
49 * = 0: successful exit
50 * < 0: if INFO = -i, the i-th argument had an illegal value
51 * > 0: if INFO = i, the leading minor of order i is not
52 * positive definite, and the factorization could not be
53 * completed.
55 * Further Details
56 * ===============
58 * The packed storage scheme is illustrated by the following example
59 * when N = 4, UPLO = 'U':
61 * Two-dimensional storage of the Hermitian matrix A:
63 * a11 a12 a13 a14
64 * a22 a23 a24
65 * a33 a34 (aij = conjg(aji))
66 * a44
68 * Packed storage of the upper triangle of A:
70 * AP = [ a11, a12, a22, a13, a23, a33, a14, a24, a34, a44 ]
72 * =====================================================================
74 * .. Parameters ..
75 DOUBLE PRECISION ZERO, ONE
76 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
77 * ..
78 * .. Local Scalars ..
79 LOGICAL UPPER
80 INTEGER J, JC, JJ
81 DOUBLE PRECISION AJJ
82 * ..
83 * .. External Functions ..
84 LOGICAL LSAME
85 COMPLEX*16 ZDOTC
86 EXTERNAL LSAME, ZDOTC
87 * ..
88 * .. External Subroutines ..
89 EXTERNAL XERBLA, ZDSCAL, ZHPR, ZTPSV
90 * ..
91 * .. Intrinsic Functions ..
92 INTRINSIC DBLE, SQRT
93 * ..
94 * .. Executable Statements ..
96 * Test the input parameters.
98 INFO = 0
99 UPPER = LSAME( UPLO, 'U' )
100 IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
101 INFO = -1
102 ELSE IF( N.LT.0 ) THEN
103 INFO = -2
104 END IF
105 IF( INFO.NE.0 ) THEN
106 CALL XERBLA( 'ZPPTRF', -INFO )
107 RETURN
108 END IF
110 * Quick return if possible
112 IF( N.EQ.0 )
113 $ RETURN
115 IF( UPPER ) THEN
117 * Compute the Cholesky factorization A = U'*U.
119 JJ = 0
120 DO 10 J = 1, N
121 JC = JJ + 1
122 JJ = JJ + J
124 * Compute elements 1:J-1 of column J.
126 IF( J.GT.1 )
127 $ CALL ZTPSV( 'Upper', 'Conjugate transpose', 'Non-unit',
128 $ J-1, AP, AP( JC ), 1 )
130 * Compute U(J,J) and test for non-positive-definiteness.
132 AJJ = DBLE( AP( JJ ) ) - ZDOTC( J-1, AP( JC ), 1, AP( JC ),
133 $ 1 )
134 IF( AJJ.LE.ZERO ) THEN
135 AP( JJ ) = AJJ
136 GO TO 30
137 END IF
138 AP( JJ ) = SQRT( AJJ )
139 10 CONTINUE
140 ELSE
142 * Compute the Cholesky factorization A = L*L'.
144 JJ = 1
145 DO 20 J = 1, N
147 * Compute L(J,J) and test for non-positive-definiteness.
149 AJJ = DBLE( AP( JJ ) )
150 IF( AJJ.LE.ZERO ) THEN
151 AP( JJ ) = AJJ
152 GO TO 30
153 END IF
154 AJJ = SQRT( AJJ )
155 AP( JJ ) = AJJ
157 * Compute elements J+1:N of column J and update the trailing
158 * submatrix.
160 IF( J.LT.N ) THEN
161 CALL ZDSCAL( N-J, ONE / AJJ, AP( JJ+1 ), 1 )
162 CALL ZHPR( 'Lower', N-J, -ONE, AP( JJ+1 ), 1,
163 $ AP( JJ+N-J+1 ) )
164 JJ = JJ + N - J + 1
165 END IF
166 20 CONTINUE
167 END IF
168 GO TO 40
170 30 CONTINUE
171 INFO = J
173 40 CONTINUE
174 RETURN
176 * End of ZPPTRF