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_b12 = -1.f;
00020 static real c_b14 = 1.f;
00021
00022 int ssprfs_(char *uplo, integer *n, integer *nrhs, real *ap,
00023 real *afp, integer *ipiv, real *b, integer *ldb, real *x, integer *
00024 ldx, real *ferr, real *berr, real *work, integer *iwork, integer *
00025 info)
00026 {
00027
00028 integer b_dim1, b_offset, x_dim1, x_offset, i__1, i__2, i__3;
00029 real r__1, r__2, r__3;
00030
00031
00032 integer i__, j, k;
00033 real s;
00034 integer ik, kk;
00035 real xk;
00036 integer nz;
00037 real eps;
00038 integer kase;
00039 real safe1, safe2;
00040 extern logical lsame_(char *, char *);
00041 integer isave[3], count;
00042 logical upper;
00043 extern int scopy_(integer *, real *, integer *, real *,
00044 integer *), saxpy_(integer *, real *, real *, integer *, real *,
00045 integer *), sspmv_(char *, integer *, real *, real *, real *,
00046 integer *, real *, real *, integer *), slacn2_(integer *,
00047 real *, real *, integer *, real *, integer *, integer *);
00048 extern doublereal slamch_(char *);
00049 real safmin;
00050 extern int xerbla_(char *, integer *);
00051 real lstres;
00052 extern int ssptrs_(char *, integer *, integer *, real *,
00053 integer *, real *, integer *, integer *);
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
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 --ap;
00168 --afp;
00169 --ipiv;
00170 b_dim1 = *ldb;
00171 b_offset = 1 + b_dim1;
00172 b -= b_offset;
00173 x_dim1 = *ldx;
00174 x_offset = 1 + x_dim1;
00175 x -= x_offset;
00176 --ferr;
00177 --berr;
00178 --work;
00179 --iwork;
00180
00181
00182 *info = 0;
00183 upper = lsame_(uplo, "U");
00184 if (! upper && ! lsame_(uplo, "L")) {
00185 *info = -1;
00186 } else if (*n < 0) {
00187 *info = -2;
00188 } else if (*nrhs < 0) {
00189 *info = -3;
00190 } else if (*ldb < max(1,*n)) {
00191 *info = -8;
00192 } else if (*ldx < max(1,*n)) {
00193 *info = -10;
00194 }
00195 if (*info != 0) {
00196 i__1 = -(*info);
00197 xerbla_("SSPRFS", &i__1);
00198 return 0;
00199 }
00200
00201
00202
00203 if (*n == 0 || *nrhs == 0) {
00204 i__1 = *nrhs;
00205 for (j = 1; j <= i__1; ++j) {
00206 ferr[j] = 0.f;
00207 berr[j] = 0.f;
00208
00209 }
00210 return 0;
00211 }
00212
00213
00214
00215 nz = *n + 1;
00216 eps = slamch_("Epsilon");
00217 safmin = slamch_("Safe minimum");
00218 safe1 = nz * safmin;
00219 safe2 = safe1 / eps;
00220
00221
00222
00223 i__1 = *nrhs;
00224 for (j = 1; j <= i__1; ++j) {
00225
00226 count = 1;
00227 lstres = 3.f;
00228 L20:
00229
00230
00231
00232
00233
00234 scopy_(n, &b[j * b_dim1 + 1], &c__1, &work[*n + 1], &c__1);
00235 sspmv_(uplo, n, &c_b12, &ap[1], &x[j * x_dim1 + 1], &c__1, &c_b14, &
00236 work[*n + 1], &c__1);
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 i__2 = *n;
00248 for (i__ = 1; i__ <= i__2; ++i__) {
00249 work[i__] = (r__1 = b[i__ + j * b_dim1], dabs(r__1));
00250
00251 }
00252
00253
00254
00255 kk = 1;
00256 if (upper) {
00257 i__2 = *n;
00258 for (k = 1; k <= i__2; ++k) {
00259 s = 0.f;
00260 xk = (r__1 = x[k + j * x_dim1], dabs(r__1));
00261 ik = kk;
00262 i__3 = k - 1;
00263 for (i__ = 1; i__ <= i__3; ++i__) {
00264 work[i__] += (r__1 = ap[ik], dabs(r__1)) * xk;
00265 s += (r__1 = ap[ik], dabs(r__1)) * (r__2 = x[i__ + j *
00266 x_dim1], dabs(r__2));
00267 ++ik;
00268
00269 }
00270 work[k] = work[k] + (r__1 = ap[kk + k - 1], dabs(r__1)) * xk
00271 + s;
00272 kk += k;
00273
00274 }
00275 } else {
00276 i__2 = *n;
00277 for (k = 1; k <= i__2; ++k) {
00278 s = 0.f;
00279 xk = (r__1 = x[k + j * x_dim1], dabs(r__1));
00280 work[k] += (r__1 = ap[kk], dabs(r__1)) * xk;
00281 ik = kk + 1;
00282 i__3 = *n;
00283 for (i__ = k + 1; i__ <= i__3; ++i__) {
00284 work[i__] += (r__1 = ap[ik], dabs(r__1)) * xk;
00285 s += (r__1 = ap[ik], dabs(r__1)) * (r__2 = x[i__ + j *
00286 x_dim1], dabs(r__2));
00287 ++ik;
00288
00289 }
00290 work[k] += s;
00291 kk += *n - k + 1;
00292
00293 }
00294 }
00295 s = 0.f;
00296 i__2 = *n;
00297 for (i__ = 1; i__ <= i__2; ++i__) {
00298 if (work[i__] > safe2) {
00299
00300 r__2 = s, r__3 = (r__1 = work[*n + i__], dabs(r__1)) / work[
00301 i__];
00302 s = dmax(r__2,r__3);
00303 } else {
00304
00305 r__2 = s, r__3 = ((r__1 = work[*n + i__], dabs(r__1)) + safe1)
00306 / (work[i__] + safe1);
00307 s = dmax(r__2,r__3);
00308 }
00309
00310 }
00311 berr[j] = s;
00312
00313
00314
00315
00316
00317
00318
00319 if (berr[j] > eps && berr[j] * 2.f <= lstres && count <= 5) {
00320
00321
00322
00323 ssptrs_(uplo, n, &c__1, &afp[1], &ipiv[1], &work[*n + 1], n, info);
00324 saxpy_(n, &c_b14, &work[*n + 1], &c__1, &x[j * x_dim1 + 1], &c__1)
00325 ;
00326 lstres = berr[j];
00327 ++count;
00328 goto L20;
00329 }
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353 i__2 = *n;
00354 for (i__ = 1; i__ <= i__2; ++i__) {
00355 if (work[i__] > safe2) {
00356 work[i__] = (r__1 = work[*n + i__], dabs(r__1)) + nz * eps *
00357 work[i__];
00358 } else {
00359 work[i__] = (r__1 = work[*n + i__], dabs(r__1)) + nz * eps *
00360 work[i__] + safe1;
00361 }
00362
00363 }
00364
00365 kase = 0;
00366 L100:
00367 slacn2_(n, &work[(*n << 1) + 1], &work[*n + 1], &iwork[1], &ferr[j], &
00368 kase, isave);
00369 if (kase != 0) {
00370 if (kase == 1) {
00371
00372
00373
00374 ssptrs_(uplo, n, &c__1, &afp[1], &ipiv[1], &work[*n + 1], n,
00375 info);
00376 i__2 = *n;
00377 for (i__ = 1; i__ <= i__2; ++i__) {
00378 work[*n + i__] = work[i__] * work[*n + i__];
00379
00380 }
00381 } else if (kase == 2) {
00382
00383
00384
00385 i__2 = *n;
00386 for (i__ = 1; i__ <= i__2; ++i__) {
00387 work[*n + i__] = work[i__] * work[*n + i__];
00388
00389 }
00390 ssptrs_(uplo, n, &c__1, &afp[1], &ipiv[1], &work[*n + 1], n,
00391 info);
00392 }
00393 goto L100;
00394 }
00395
00396
00397
00398 lstres = 0.f;
00399 i__2 = *n;
00400 for (i__ = 1; i__ <= i__2; ++i__) {
00401
00402 r__2 = lstres, r__3 = (r__1 = x[i__ + j * x_dim1], dabs(r__1));
00403 lstres = dmax(r__2,r__3);
00404
00405 }
00406 if (lstres != 0.f) {
00407 ferr[j] /= lstres;
00408 }
00409
00410
00411 }
00412
00413 return 0;
00414
00415
00416
00417 }