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 complex c_b1 = {1.f,0.f};
00019 static integer c__1 = 1;
00020
00021 int csyrfs_(char *uplo, integer *n, integer *nrhs, complex *
00022 a, integer *lda, complex *af, integer *ldaf, integer *ipiv, complex *
00023 b, integer *ldb, complex *x, integer *ldx, real *ferr, real *berr,
00024 complex *work, real *rwork, integer *info)
00025 {
00026
00027 integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, x_dim1,
00028 x_offset, i__1, i__2, i__3, i__4, i__5;
00029 real r__1, r__2, r__3, r__4;
00030 complex q__1;
00031
00032
00033 double r_imag(complex *);
00034
00035
00036 integer i__, j, k;
00037 real s, xk;
00038 integer nz;
00039 real eps;
00040 integer kase;
00041 real safe1, safe2;
00042 extern logical lsame_(char *, char *);
00043 integer isave[3];
00044 extern int ccopy_(integer *, complex *, integer *,
00045 complex *, integer *), caxpy_(integer *, complex *, complex *,
00046 integer *, complex *, integer *);
00047 integer count;
00048 logical upper;
00049 extern int csymv_(char *, integer *, complex *, complex *
00050 , integer *, complex *, integer *, complex *, complex *, integer *
00051 ), clacn2_(integer *, complex *, complex *, real *,
00052 integer *, integer *);
00053 extern doublereal slamch_(char *);
00054 real safmin;
00055 extern int xerbla_(char *, integer *);
00056 real lstres;
00057 extern int csytrs_(char *, integer *, integer *, complex
00058 *, integer *, integer *, complex *, integer *, integer *);
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
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 a_dim1 = *lda;
00183 a_offset = 1 + a_dim1;
00184 a -= a_offset;
00185 af_dim1 = *ldaf;
00186 af_offset = 1 + af_dim1;
00187 af -= af_offset;
00188 --ipiv;
00189 b_dim1 = *ldb;
00190 b_offset = 1 + b_dim1;
00191 b -= b_offset;
00192 x_dim1 = *ldx;
00193 x_offset = 1 + x_dim1;
00194 x -= x_offset;
00195 --ferr;
00196 --berr;
00197 --work;
00198 --rwork;
00199
00200
00201 *info = 0;
00202 upper = lsame_(uplo, "U");
00203 if (! upper && ! lsame_(uplo, "L")) {
00204 *info = -1;
00205 } else if (*n < 0) {
00206 *info = -2;
00207 } else if (*nrhs < 0) {
00208 *info = -3;
00209 } else if (*lda < max(1,*n)) {
00210 *info = -5;
00211 } else if (*ldaf < max(1,*n)) {
00212 *info = -7;
00213 } else if (*ldb < max(1,*n)) {
00214 *info = -10;
00215 } else if (*ldx < max(1,*n)) {
00216 *info = -12;
00217 }
00218 if (*info != 0) {
00219 i__1 = -(*info);
00220 xerbla_("CSYRFS", &i__1);
00221 return 0;
00222 }
00223
00224
00225
00226 if (*n == 0 || *nrhs == 0) {
00227 i__1 = *nrhs;
00228 for (j = 1; j <= i__1; ++j) {
00229 ferr[j] = 0.f;
00230 berr[j] = 0.f;
00231
00232 }
00233 return 0;
00234 }
00235
00236
00237
00238 nz = *n + 1;
00239 eps = slamch_("Epsilon");
00240 safmin = slamch_("Safe minimum");
00241 safe1 = nz * safmin;
00242 safe2 = safe1 / eps;
00243
00244
00245
00246 i__1 = *nrhs;
00247 for (j = 1; j <= i__1; ++j) {
00248
00249 count = 1;
00250 lstres = 3.f;
00251 L20:
00252
00253
00254
00255
00256
00257 ccopy_(n, &b[j * b_dim1 + 1], &c__1, &work[1], &c__1);
00258 q__1.r = -1.f, q__1.i = -0.f;
00259 csymv_(uplo, n, &q__1, &a[a_offset], lda, &x[j * x_dim1 + 1], &c__1, &
00260 c_b1, &work[1], &c__1);
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271 i__2 = *n;
00272 for (i__ = 1; i__ <= i__2; ++i__) {
00273 i__3 = i__ + j * b_dim1;
00274 rwork[i__] = (r__1 = b[i__3].r, dabs(r__1)) + (r__2 = r_imag(&b[
00275 i__ + j * b_dim1]), dabs(r__2));
00276
00277 }
00278
00279
00280
00281 if (upper) {
00282 i__2 = *n;
00283 for (k = 1; k <= i__2; ++k) {
00284 s = 0.f;
00285 i__3 = k + j * x_dim1;
00286 xk = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&x[k + j
00287 * x_dim1]), dabs(r__2));
00288 i__3 = k - 1;
00289 for (i__ = 1; i__ <= i__3; ++i__) {
00290 i__4 = i__ + k * a_dim1;
00291 rwork[i__] += ((r__1 = a[i__4].r, dabs(r__1)) + (r__2 =
00292 r_imag(&a[i__ + k * a_dim1]), dabs(r__2))) * xk;
00293 i__4 = i__ + k * a_dim1;
00294 i__5 = i__ + j * x_dim1;
00295 s += ((r__1 = a[i__4].r, dabs(r__1)) + (r__2 = r_imag(&a[
00296 i__ + k * a_dim1]), dabs(r__2))) * ((r__3 = x[
00297 i__5].r, dabs(r__3)) + (r__4 = r_imag(&x[i__ + j *
00298 x_dim1]), dabs(r__4)));
00299
00300 }
00301 i__3 = k + k * a_dim1;
00302 rwork[k] = rwork[k] + ((r__1 = a[i__3].r, dabs(r__1)) + (r__2
00303 = r_imag(&a[k + k * a_dim1]), dabs(r__2))) * xk + s;
00304
00305 }
00306 } else {
00307 i__2 = *n;
00308 for (k = 1; k <= i__2; ++k) {
00309 s = 0.f;
00310 i__3 = k + j * x_dim1;
00311 xk = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&x[k + j
00312 * x_dim1]), dabs(r__2));
00313 i__3 = k + k * a_dim1;
00314 rwork[k] += ((r__1 = a[i__3].r, dabs(r__1)) + (r__2 = r_imag(&
00315 a[k + k * a_dim1]), dabs(r__2))) * xk;
00316 i__3 = *n;
00317 for (i__ = k + 1; i__ <= i__3; ++i__) {
00318 i__4 = i__ + k * a_dim1;
00319 rwork[i__] += ((r__1 = a[i__4].r, dabs(r__1)) + (r__2 =
00320 r_imag(&a[i__ + k * a_dim1]), dabs(r__2))) * xk;
00321 i__4 = i__ + k * a_dim1;
00322 i__5 = i__ + j * x_dim1;
00323 s += ((r__1 = a[i__4].r, dabs(r__1)) + (r__2 = r_imag(&a[
00324 i__ + k * a_dim1]), dabs(r__2))) * ((r__3 = x[
00325 i__5].r, dabs(r__3)) + (r__4 = r_imag(&x[i__ + j *
00326 x_dim1]), dabs(r__4)));
00327
00328 }
00329 rwork[k] += s;
00330
00331 }
00332 }
00333 s = 0.f;
00334 i__2 = *n;
00335 for (i__ = 1; i__ <= i__2; ++i__) {
00336 if (rwork[i__] > safe2) {
00337
00338 i__3 = i__;
00339 r__3 = s, r__4 = ((r__1 = work[i__3].r, dabs(r__1)) + (r__2 =
00340 r_imag(&work[i__]), dabs(r__2))) / rwork[i__];
00341 s = dmax(r__3,r__4);
00342 } else {
00343
00344 i__3 = i__;
00345 r__3 = s, r__4 = ((r__1 = work[i__3].r, dabs(r__1)) + (r__2 =
00346 r_imag(&work[i__]), dabs(r__2)) + safe1) / (rwork[i__]
00347 + safe1);
00348 s = dmax(r__3,r__4);
00349 }
00350
00351 }
00352 berr[j] = s;
00353
00354
00355
00356
00357
00358
00359
00360 if (berr[j] > eps && berr[j] * 2.f <= lstres && count <= 5) {
00361
00362
00363
00364 csytrs_(uplo, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[1],
00365 n, info);
00366 caxpy_(n, &c_b1, &work[1], &c__1, &x[j * x_dim1 + 1], &c__1);
00367 lstres = berr[j];
00368 ++count;
00369 goto L20;
00370 }
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394 i__2 = *n;
00395 for (i__ = 1; i__ <= i__2; ++i__) {
00396 if (rwork[i__] > safe2) {
00397 i__3 = i__;
00398 rwork[i__] = (r__1 = work[i__3].r, dabs(r__1)) + (r__2 =
00399 r_imag(&work[i__]), dabs(r__2)) + nz * eps * rwork[
00400 i__];
00401 } else {
00402 i__3 = i__;
00403 rwork[i__] = (r__1 = work[i__3].r, dabs(r__1)) + (r__2 =
00404 r_imag(&work[i__]), dabs(r__2)) + nz * eps * rwork[
00405 i__] + safe1;
00406 }
00407
00408 }
00409
00410 kase = 0;
00411 L100:
00412 clacn2_(n, &work[*n + 1], &work[1], &ferr[j], &kase, isave);
00413 if (kase != 0) {
00414 if (kase == 1) {
00415
00416
00417
00418 csytrs_(uplo, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[
00419 1], n, info);
00420 i__2 = *n;
00421 for (i__ = 1; i__ <= i__2; ++i__) {
00422 i__3 = i__;
00423 i__4 = i__;
00424 i__5 = i__;
00425 q__1.r = rwork[i__4] * work[i__5].r, q__1.i = rwork[i__4]
00426 * work[i__5].i;
00427 work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00428
00429 }
00430 } else if (kase == 2) {
00431
00432
00433
00434 i__2 = *n;
00435 for (i__ = 1; i__ <= i__2; ++i__) {
00436 i__3 = i__;
00437 i__4 = i__;
00438 i__5 = i__;
00439 q__1.r = rwork[i__4] * work[i__5].r, q__1.i = rwork[i__4]
00440 * work[i__5].i;
00441 work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00442
00443 }
00444 csytrs_(uplo, n, &c__1, &af[af_offset], ldaf, &ipiv[1], &work[
00445 1], n, info);
00446 }
00447 goto L100;
00448 }
00449
00450
00451
00452 lstres = 0.f;
00453 i__2 = *n;
00454 for (i__ = 1; i__ <= i__2; ++i__) {
00455
00456 i__3 = i__ + j * x_dim1;
00457 r__3 = lstres, r__4 = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 =
00458 r_imag(&x[i__ + j * x_dim1]), dabs(r__2));
00459 lstres = dmax(r__3,r__4);
00460
00461 }
00462 if (lstres != 0.f) {
00463 ferr[j] /= lstres;
00464 }
00465
00466
00467 }
00468
00469 return 0;
00470
00471
00472
00473 }