MAGMA  1.2.0
MatrixAlgebraonGPUandMulticoreArchitectures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
cppt01.f
Go to the documentation of this file.
1  SUBROUTINE cppt01( UPLO, N, A, AFAC, RWORK, RESID )
2 *
3 * -- LAPACK test routine (version 3.1) --
4 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
5 * November 2006
6 *
7 * .. Scalar Arguments ..
8  CHARACTER uplo
9  INTEGER n
10  REAL resid
11 * ..
12 * .. Array Arguments ..
13  REAL rwork( * )
14  COMPLEX a( * ), afac( * )
15 * ..
16 *
17 * Purpose
18 * =======
19 *
20 * CPPT01 reconstructs a Hermitian positive definite packed matrix A
21 * from its L*L' or U'*U factorization and computes the residual
22 * norm( L*L' - A ) / ( N * norm(A) * EPS ) or
23 * norm( U'*U - A ) / ( N * norm(A) * EPS ),
24 * where EPS is the machine epsilon, L' is the conjugate transpose of
25 * L, and U' is the conjugate transpose of U.
26 *
27 * Arguments
28 * ==========
29 *
30 * UPLO (input) CHARACTER*1
31 * Specifies whether the upper or lower triangular part of the
32 * Hermitian matrix A is stored:
33 * = 'U': Upper triangular
34 * = 'L': Lower triangular
35 *
36 * N (input) INTEGER
37 * The number of rows and columns of the matrix A. N >= 0.
38 *
39 * A (input) COMPLEX array, dimension (N*(N+1)/2)
40 * The original Hermitian matrix A, stored as a packed
41 * triangular matrix.
42 *
43 * AFAC (input/output) COMPLEX array, dimension (N*(N+1)/2)
44 * On entry, the factor L or U from the L*L' or U'*U
45 * factorization of A, stored as a packed triangular matrix.
46 * Overwritten with the reconstructed matrix, and then with the
47 * difference L*L' - A (or U'*U - A).
48 *
49 * RWORK (workspace) REAL array, dimension (N)
50 *
51 * RESID (output) REAL
52 * If UPLO = 'L', norm(L*L' - A) / ( N * norm(A) * EPS )
53 * If UPLO = 'U', norm(U'*U - A) / ( N * norm(A) * EPS )
54 *
55 * =====================================================================
56 *
57 * .. Parameters ..
58  REAL zero, one
59  parameter( zero = 0.0e+0, one = 1.0e+0 )
60 * ..
61 * .. Local Scalars ..
62  INTEGER i, k, kc
63  REAL anorm, eps, tr
64  COMPLEX tc
65 * ..
66 * .. External Functions ..
67  LOGICAL lsame
68  REAL clanhp, slamch
69  COMPLEX cdotc
70  EXTERNAL lsame, clanhp, slamch, cdotc
71 * ..
72 * .. External Subroutines ..
73  EXTERNAL chpr, cscal, ctpmv
74 * ..
75 * .. Intrinsic Functions ..
76  INTRINSIC aimag, real
77 * ..
78 * .. Executable Statements ..
79 *
80 * Quick exit if N = 0
81 *
82  IF( n.LE.0 ) THEN
83  resid = zero
84  return
85  END IF
86 *
87 * Exit with RESID = 1/EPS if ANORM = 0.
88 *
89  eps = slamch( 'Epsilon' )
90  anorm = clanhp( '1', uplo, n, a, rwork )
91  IF( anorm.LE.zero ) THEN
92  resid = one / eps
93  return
94  END IF
95 *
96 * Check the imaginary parts of the diagonal elements and return with
97 * an error code if any are nonzero.
98 *
99  kc = 1
100  IF( lsame( uplo, 'U' ) ) THEN
101  DO 10 k = 1, n
102  IF( aimag( afac( kc ) ).NE.zero ) THEN
103  resid = one / eps
104  return
105  END IF
106  kc = kc + k + 1
107  10 continue
108  ELSE
109  DO 20 k = 1, n
110  IF( aimag( afac( kc ) ).NE.zero ) THEN
111  resid = one / eps
112  return
113  END IF
114  kc = kc + n - k + 1
115  20 continue
116  END IF
117 *
118 * Compute the product U'*U, overwriting U.
119 *
120  IF( lsame( uplo, 'U' ) ) THEN
121  kc = ( n*( n-1 ) ) / 2 + 1
122  DO 30 k = n, 1, -1
123 *
124 * Compute the (K,K) element of the result.
125 *
126  tr = cdotc( k, afac( kc ), 1, afac( kc ), 1 )
127  afac( kc+k-1 ) = tr
128 *
129 * Compute the rest of column K.
130 *
131  IF( k.GT.1 ) THEN
132  CALL ctpmv( 'Upper', 'Conjugate', 'Non-unit', k-1, afac,
133  $ afac( kc ), 1 )
134  kc = kc - ( k-1 )
135  END IF
136  30 continue
137 *
138 * Compute the difference L*L' - A
139 *
140  kc = 1
141  DO 50 k = 1, n
142  DO 40 i = 1, k - 1
143  afac( kc+i-1 ) = afac( kc+i-1 ) - a( kc+i-1 )
144  40 continue
145  afac( kc+k-1 ) = afac( kc+k-1 ) - REAL( A( KC+K-1 ) )
146  kc = kc + k
147  50 continue
148 *
149 * Compute the product L*L', overwriting L.
150 *
151  ELSE
152  kc = ( n*( n+1 ) ) / 2
153  DO 60 k = n, 1, -1
154 *
155 * Add a multiple of column K of the factor L to each of
156 * columns K+1 through N.
157 *
158  IF( k.LT.n )
159  $ CALL chpr( 'Lower', n-k, one, afac( kc+1 ), 1,
160  $ afac( kc+n-k+1 ) )
161 *
162 * Scale column K by the diagonal element.
163 *
164  tc = afac( kc )
165  CALL cscal( n-k+1, tc, afac( kc ), 1 )
166 *
167  kc = kc - ( n-k+2 )
168  60 continue
169 *
170 * Compute the difference U'*U - A
171 *
172  kc = 1
173  DO 80 k = 1, n
174  afac( kc ) = afac( kc ) - REAL( A( KC ) )
175  DO 70 i = k + 1, n
176  afac( kc+i-k ) = afac( kc+i-k ) - a( kc+i-k )
177  70 continue
178  kc = kc + n - k + 1
179  80 continue
180  END IF
181 *
182 * Compute norm( L*U - A ) / ( N * norm(A) * EPS )
183 *
184  resid = clanhp( '1', uplo, n, afac, rwork )
185 *
186  resid = ( ( resid / REAL( N ) ) / anorm ) / eps
187 *
188  return
189 *
190 * End of CPPT01
191 *
192  END