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 doublereal c_b18 = 1.;
00020
00021 int dpst01_(char *uplo, integer *n, doublereal *a, integer *
00022 lda, doublereal *afac, integer *ldafac, doublereal *perm, integer *
00023 ldperm, integer *piv, doublereal *rwork, doublereal *resid, integer *
00024 rank)
00025 {
00026
00027 integer a_dim1, a_offset, afac_dim1, afac_offset, perm_dim1, perm_offset,
00028 i__1, i__2;
00029
00030
00031 integer i__, j, k;
00032 doublereal t, eps;
00033 extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
00034 integer *);
00035 extern int dsyr_(char *, integer *, doublereal *,
00036 doublereal *, integer *, doublereal *, integer *), dscal_(
00037 integer *, doublereal *, doublereal *, integer *);
00038 extern logical lsame_(char *, char *);
00039 doublereal anorm;
00040 extern int dtrmv_(char *, char *, char *, integer *,
00041 doublereal *, integer *, doublereal *, integer *);
00042 extern doublereal dlamch_(char *), dlansy_(char *, char *,
00043 integer *, doublereal *, integer *, doublereal *);
00044
00045
00046
00047
00048
00049
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 a_dim1 = *lda;
00126 a_offset = 1 + a_dim1;
00127 a -= a_offset;
00128 afac_dim1 = *ldafac;
00129 afac_offset = 1 + afac_dim1;
00130 afac -= afac_offset;
00131 perm_dim1 = *ldperm;
00132 perm_offset = 1 + perm_dim1;
00133 perm -= perm_offset;
00134 --piv;
00135 --rwork;
00136
00137
00138 if (*n <= 0) {
00139 *resid = 0.;
00140 return 0;
00141 }
00142
00143
00144
00145 eps = dlamch_("Epsilon");
00146 anorm = dlansy_("1", uplo, n, &a[a_offset], lda, &rwork[1]);
00147 if (anorm <= 0.) {
00148 *resid = 1. / eps;
00149 return 0;
00150 }
00151
00152
00153
00154 if (lsame_(uplo, "U")) {
00155
00156 if (*rank < *n) {
00157 i__1 = *n;
00158 for (j = *rank + 1; j <= i__1; ++j) {
00159 i__2 = j;
00160 for (i__ = *rank + 1; i__ <= i__2; ++i__) {
00161 afac[i__ + j * afac_dim1] = 0.;
00162
00163 }
00164
00165 }
00166 }
00167
00168 for (k = *n; k >= 1; --k) {
00169
00170
00171
00172 t = ddot_(&k, &afac[k * afac_dim1 + 1], &c__1, &afac[k *
00173 afac_dim1 + 1], &c__1);
00174 afac[k + k * afac_dim1] = t;
00175
00176
00177
00178 i__1 = k - 1;
00179 dtrmv_("Upper", "Transpose", "Non-unit", &i__1, &afac[afac_offset]
00180 , ldafac, &afac[k * afac_dim1 + 1], &c__1);
00181
00182
00183 }
00184
00185
00186
00187 } else {
00188
00189 if (*rank < *n) {
00190 i__1 = *n;
00191 for (j = *rank + 1; j <= i__1; ++j) {
00192 i__2 = *n;
00193 for (i__ = j; i__ <= i__2; ++i__) {
00194 afac[i__ + j * afac_dim1] = 0.;
00195
00196 }
00197
00198 }
00199 }
00200
00201 for (k = *n; k >= 1; --k) {
00202
00203
00204
00205 if (k + 1 <= *n) {
00206 i__1 = *n - k;
00207 dsyr_("Lower", &i__1, &c_b18, &afac[k + 1 + k * afac_dim1], &
00208 c__1, &afac[k + 1 + (k + 1) * afac_dim1], ldafac);
00209 }
00210
00211
00212
00213 t = afac[k + k * afac_dim1];
00214 i__1 = *n - k + 1;
00215 dscal_(&i__1, &t, &afac[k + k * afac_dim1], &c__1);
00216
00217 }
00218
00219 }
00220
00221
00222
00223 if (lsame_(uplo, "U")) {
00224
00225 i__1 = *n;
00226 for (j = 1; j <= i__1; ++j) {
00227 i__2 = *n;
00228 for (i__ = 1; i__ <= i__2; ++i__) {
00229 if (piv[i__] <= piv[j]) {
00230 if (i__ <= j) {
00231 perm[piv[i__] + piv[j] * perm_dim1] = afac[i__ + j *
00232 afac_dim1];
00233 } else {
00234 perm[piv[i__] + piv[j] * perm_dim1] = afac[j + i__ *
00235 afac_dim1];
00236 }
00237 }
00238
00239 }
00240
00241 }
00242
00243
00244 } else {
00245
00246 i__1 = *n;
00247 for (j = 1; j <= i__1; ++j) {
00248 i__2 = *n;
00249 for (i__ = 1; i__ <= i__2; ++i__) {
00250 if (piv[i__] >= piv[j]) {
00251 if (i__ >= j) {
00252 perm[piv[i__] + piv[j] * perm_dim1] = afac[i__ + j *
00253 afac_dim1];
00254 } else {
00255 perm[piv[i__] + piv[j] * perm_dim1] = afac[j + i__ *
00256 afac_dim1];
00257 }
00258 }
00259
00260 }
00261
00262 }
00263
00264 }
00265
00266
00267
00268 if (lsame_(uplo, "U")) {
00269 i__1 = *n;
00270 for (j = 1; j <= i__1; ++j) {
00271 i__2 = j;
00272 for (i__ = 1; i__ <= i__2; ++i__) {
00273 perm[i__ + j * perm_dim1] -= a[i__ + j * a_dim1];
00274
00275 }
00276
00277 }
00278 } else {
00279 i__1 = *n;
00280 for (j = 1; j <= i__1; ++j) {
00281 i__2 = *n;
00282 for (i__ = j; i__ <= i__2; ++i__) {
00283 perm[i__ + j * perm_dim1] -= a[i__ + j * a_dim1];
00284
00285 }
00286
00287 }
00288 }
00289
00290
00291
00292
00293 *resid = dlansy_("1", uplo, n, &perm[perm_offset], ldafac, &rwork[1]);
00294
00295 *resid = *resid / (doublereal) (*n) / anorm / eps;
00296
00297 return 0;
00298
00299
00300
00301 }