00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015
00016
00017
00018 static integer c__1 = 1;
00019 static real c_b20 = 1.f;
00020
00021 int cpst01_(char *uplo, integer *n, complex *a, integer *lda,
00022 complex *afac, integer *ldafac, complex *perm, integer *ldperm,
00023 integer *piv, real *rwork, real *resid, integer *rank)
00024 {
00025
00026 integer a_dim1, a_offset, afac_dim1, afac_offset, perm_dim1, perm_offset,
00027 i__1, i__2, i__3, i__4, i__5;
00028 real r__1;
00029 complex q__1;
00030
00031
00032 double r_imag(complex *);
00033 void r_cnjg(complex *, complex *);
00034
00035
00036 integer i__, j, k;
00037 complex tc;
00038 real tr, eps;
00039 extern int cher_(char *, integer *, real *, complex *,
00040 integer *, complex *, integer *), cscal_(integer *,
00041 complex *, complex *, integer *);
00042 extern VOID cdotc_(complex *, integer *, complex *, integer
00043 *, complex *, integer *);
00044 extern logical lsame_(char *, char *);
00045 real anorm;
00046 extern int ctrmv_(char *, char *, char *, integer *,
00047 complex *, integer *, complex *, integer *);
00048 extern doublereal clanhe_(char *, char *, integer *, complex *, integer *,
00049 real *), slamch_(char *);
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 a_dim1 = *lda;
00133 a_offset = 1 + a_dim1;
00134 a -= a_offset;
00135 afac_dim1 = *ldafac;
00136 afac_offset = 1 + afac_dim1;
00137 afac -= afac_offset;
00138 perm_dim1 = *ldperm;
00139 perm_offset = 1 + perm_dim1;
00140 perm -= perm_offset;
00141 --piv;
00142 --rwork;
00143
00144
00145 if (*n <= 0) {
00146 *resid = 0.f;
00147 return 0;
00148 }
00149
00150
00151
00152 eps = slamch_("Epsilon");
00153 anorm = clanhe_("1", uplo, n, &a[a_offset], lda, &rwork[1]);
00154 if (anorm <= 0.f) {
00155 *resid = 1.f / eps;
00156 return 0;
00157 }
00158
00159
00160
00161
00162 i__1 = *n;
00163 for (j = 1; j <= i__1; ++j) {
00164 if (r_imag(&afac[j + j * afac_dim1]) != 0.f) {
00165 *resid = 1.f / eps;
00166 return 0;
00167 }
00168
00169 }
00170
00171
00172
00173 if (lsame_(uplo, "U")) {
00174
00175 if (*rank < *n) {
00176 i__1 = *n;
00177 for (j = *rank + 1; j <= i__1; ++j) {
00178 i__2 = j;
00179 for (i__ = *rank + 1; i__ <= i__2; ++i__) {
00180 i__3 = i__ + j * afac_dim1;
00181 afac[i__3].r = 0.f, afac[i__3].i = 0.f;
00182
00183 }
00184
00185 }
00186 }
00187
00188 for (k = *n; k >= 1; --k) {
00189
00190
00191
00192 cdotc_(&q__1, &k, &afac[k * afac_dim1 + 1], &c__1, &afac[k *
00193 afac_dim1 + 1], &c__1);
00194 tr = q__1.r;
00195 i__1 = k + k * afac_dim1;
00196 afac[i__1].r = tr, afac[i__1].i = 0.f;
00197
00198
00199
00200 i__1 = k - 1;
00201 ctrmv_("Upper", "Conjugate", "Non-unit", &i__1, &afac[afac_offset]
00202 , ldafac, &afac[k * afac_dim1 + 1], &c__1);
00203
00204
00205 }
00206
00207
00208
00209 } else {
00210
00211 if (*rank < *n) {
00212 i__1 = *n;
00213 for (j = *rank + 1; j <= i__1; ++j) {
00214 i__2 = *n;
00215 for (i__ = j; i__ <= i__2; ++i__) {
00216 i__3 = i__ + j * afac_dim1;
00217 afac[i__3].r = 0.f, afac[i__3].i = 0.f;
00218
00219 }
00220
00221 }
00222 }
00223
00224 for (k = *n; k >= 1; --k) {
00225
00226
00227
00228 if (k + 1 <= *n) {
00229 i__1 = *n - k;
00230 cher_("Lower", &i__1, &c_b20, &afac[k + 1 + k * afac_dim1], &
00231 c__1, &afac[k + 1 + (k + 1) * afac_dim1], ldafac);
00232 }
00233
00234
00235
00236 i__1 = k + k * afac_dim1;
00237 tc.r = afac[i__1].r, tc.i = afac[i__1].i;
00238 i__1 = *n - k + 1;
00239 cscal_(&i__1, &tc, &afac[k + k * afac_dim1], &c__1);
00240
00241 }
00242
00243 }
00244
00245
00246
00247 if (lsame_(uplo, "U")) {
00248
00249 i__1 = *n;
00250 for (j = 1; j <= i__1; ++j) {
00251 i__2 = *n;
00252 for (i__ = 1; i__ <= i__2; ++i__) {
00253 if (piv[i__] <= piv[j]) {
00254 if (i__ <= j) {
00255 i__3 = piv[i__] + piv[j] * perm_dim1;
00256 i__4 = i__ + j * afac_dim1;
00257 perm[i__3].r = afac[i__4].r, perm[i__3].i = afac[i__4]
00258 .i;
00259 } else {
00260 i__3 = piv[i__] + piv[j] * perm_dim1;
00261 r_cnjg(&q__1, &afac[j + i__ * afac_dim1]);
00262 perm[i__3].r = q__1.r, perm[i__3].i = q__1.i;
00263 }
00264 }
00265
00266 }
00267
00268 }
00269
00270
00271 } else {
00272
00273 i__1 = *n;
00274 for (j = 1; j <= i__1; ++j) {
00275 i__2 = *n;
00276 for (i__ = 1; i__ <= i__2; ++i__) {
00277 if (piv[i__] >= piv[j]) {
00278 if (i__ >= j) {
00279 i__3 = piv[i__] + piv[j] * perm_dim1;
00280 i__4 = i__ + j * afac_dim1;
00281 perm[i__3].r = afac[i__4].r, perm[i__3].i = afac[i__4]
00282 .i;
00283 } else {
00284 i__3 = piv[i__] + piv[j] * perm_dim1;
00285 r_cnjg(&q__1, &afac[j + i__ * afac_dim1]);
00286 perm[i__3].r = q__1.r, perm[i__3].i = q__1.i;
00287 }
00288 }
00289
00290 }
00291
00292 }
00293
00294 }
00295
00296
00297
00298 if (lsame_(uplo, "U")) {
00299 i__1 = *n;
00300 for (j = 1; j <= i__1; ++j) {
00301 i__2 = j - 1;
00302 for (i__ = 1; i__ <= i__2; ++i__) {
00303 i__3 = i__ + j * perm_dim1;
00304 i__4 = i__ + j * perm_dim1;
00305 i__5 = i__ + j * a_dim1;
00306 q__1.r = perm[i__4].r - a[i__5].r, q__1.i = perm[i__4].i - a[
00307 i__5].i;
00308 perm[i__3].r = q__1.r, perm[i__3].i = q__1.i;
00309
00310 }
00311 i__2 = j + j * perm_dim1;
00312 i__3 = j + j * perm_dim1;
00313 i__4 = j + j * a_dim1;
00314 r__1 = a[i__4].r;
00315 q__1.r = perm[i__3].r - r__1, q__1.i = perm[i__3].i;
00316 perm[i__2].r = q__1.r, perm[i__2].i = q__1.i;
00317
00318 }
00319 } else {
00320 i__1 = *n;
00321 for (j = 1; j <= i__1; ++j) {
00322 i__2 = j + j * perm_dim1;
00323 i__3 = j + j * perm_dim1;
00324 i__4 = j + j * a_dim1;
00325 r__1 = a[i__4].r;
00326 q__1.r = perm[i__3].r - r__1, q__1.i = perm[i__3].i;
00327 perm[i__2].r = q__1.r, perm[i__2].i = q__1.i;
00328 i__2 = *n;
00329 for (i__ = j + 1; i__ <= i__2; ++i__) {
00330 i__3 = i__ + j * perm_dim1;
00331 i__4 = i__ + j * perm_dim1;
00332 i__5 = i__ + j * a_dim1;
00333 q__1.r = perm[i__4].r - a[i__5].r, q__1.i = perm[i__4].i - a[
00334 i__5].i;
00335 perm[i__3].r = q__1.r, perm[i__3].i = q__1.i;
00336
00337 }
00338
00339 }
00340 }
00341
00342
00343
00344
00345 *resid = clanhe_("1", uplo, n, &perm[perm_offset], ldafac, &rwork[1]);
00346
00347 *resid = *resid / (real) (*n) / anorm / eps;
00348
00349 return 0;
00350
00351
00352
00353 }