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 complex c_b16 = {1.f,0.f};
00020
00021 int cptrfs_(char *uplo, integer *n, integer *nrhs, real *d__,
00022 complex *e, real *df, complex *ef, complex *b, integer *ldb, complex
00023 *x, integer *ldx, real *ferr, real *berr, complex *work, real *rwork,
00024 integer *info)
00025 {
00026
00027 integer b_dim1, b_offset, x_dim1, x_offset, i__1, i__2, i__3, i__4, i__5,
00028 i__6;
00029 real r__1, r__2, r__3, r__4, r__5, r__6, r__7, r__8, r__9, r__10, r__11,
00030 r__12;
00031 complex q__1, q__2, q__3;
00032
00033
00034 double r_imag(complex *);
00035 void r_cnjg(complex *, complex *);
00036 double c_abs(complex *);
00037
00038
00039 integer i__, j;
00040 real s;
00041 complex bi, cx, dx, ex;
00042 integer ix, nz;
00043 real eps, safe1, safe2;
00044 extern logical lsame_(char *, char *);
00045 extern int caxpy_(integer *, complex *, complex *,
00046 integer *, complex *, integer *);
00047 integer count;
00048 logical upper;
00049 extern doublereal slamch_(char *);
00050 real safmin;
00051 extern int xerbla_(char *, integer *);
00052 extern integer isamax_(integer *, real *, integer *);
00053 real lstres;
00054 extern int cpttrs_(char *, integer *, integer *, real *,
00055 complex *, complex *, integer *, integer *);
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
00168
00169 --d__;
00170 --e;
00171 --df;
00172 --ef;
00173 b_dim1 = *ldb;
00174 b_offset = 1 + b_dim1;
00175 b -= b_offset;
00176 x_dim1 = *ldx;
00177 x_offset = 1 + x_dim1;
00178 x -= x_offset;
00179 --ferr;
00180 --berr;
00181 --work;
00182 --rwork;
00183
00184
00185 *info = 0;
00186 upper = lsame_(uplo, "U");
00187 if (! upper && ! lsame_(uplo, "L")) {
00188 *info = -1;
00189 } else if (*n < 0) {
00190 *info = -2;
00191 } else if (*nrhs < 0) {
00192 *info = -3;
00193 } else if (*ldb < max(1,*n)) {
00194 *info = -9;
00195 } else if (*ldx < max(1,*n)) {
00196 *info = -11;
00197 }
00198 if (*info != 0) {
00199 i__1 = -(*info);
00200 xerbla_("CPTRFS", &i__1);
00201 return 0;
00202 }
00203
00204
00205
00206 if (*n == 0 || *nrhs == 0) {
00207 i__1 = *nrhs;
00208 for (j = 1; j <= i__1; ++j) {
00209 ferr[j] = 0.f;
00210 berr[j] = 0.f;
00211
00212 }
00213 return 0;
00214 }
00215
00216
00217
00218 nz = 4;
00219 eps = slamch_("Epsilon");
00220 safmin = slamch_("Safe minimum");
00221 safe1 = nz * safmin;
00222 safe2 = safe1 / eps;
00223
00224
00225
00226 i__1 = *nrhs;
00227 for (j = 1; j <= i__1; ++j) {
00228
00229 count = 1;
00230 lstres = 3.f;
00231 L20:
00232
00233
00234
00235
00236
00237
00238 if (upper) {
00239 if (*n == 1) {
00240 i__2 = j * b_dim1 + 1;
00241 bi.r = b[i__2].r, bi.i = b[i__2].i;
00242 i__2 = j * x_dim1 + 1;
00243 q__1.r = d__[1] * x[i__2].r, q__1.i = d__[1] * x[i__2].i;
00244 dx.r = q__1.r, dx.i = q__1.i;
00245 q__1.r = bi.r - dx.r, q__1.i = bi.i - dx.i;
00246 work[1].r = q__1.r, work[1].i = q__1.i;
00247 rwork[1] = (r__1 = bi.r, dabs(r__1)) + (r__2 = r_imag(&bi),
00248 dabs(r__2)) + ((r__3 = dx.r, dabs(r__3)) + (r__4 =
00249 r_imag(&dx), dabs(r__4)));
00250 } else {
00251 i__2 = j * b_dim1 + 1;
00252 bi.r = b[i__2].r, bi.i = b[i__2].i;
00253 i__2 = j * x_dim1 + 1;
00254 q__1.r = d__[1] * x[i__2].r, q__1.i = d__[1] * x[i__2].i;
00255 dx.r = q__1.r, dx.i = q__1.i;
00256 i__2 = j * x_dim1 + 2;
00257 q__1.r = e[1].r * x[i__2].r - e[1].i * x[i__2].i, q__1.i = e[
00258 1].r * x[i__2].i + e[1].i * x[i__2].r;
00259 ex.r = q__1.r, ex.i = q__1.i;
00260 q__2.r = bi.r - dx.r, q__2.i = bi.i - dx.i;
00261 q__1.r = q__2.r - ex.r, q__1.i = q__2.i - ex.i;
00262 work[1].r = q__1.r, work[1].i = q__1.i;
00263 i__2 = j * x_dim1 + 2;
00264 rwork[1] = (r__1 = bi.r, dabs(r__1)) + (r__2 = r_imag(&bi),
00265 dabs(r__2)) + ((r__3 = dx.r, dabs(r__3)) + (r__4 =
00266 r_imag(&dx), dabs(r__4))) + ((r__5 = e[1].r, dabs(
00267 r__5)) + (r__6 = r_imag(&e[1]), dabs(r__6))) * ((r__7
00268 = x[i__2].r, dabs(r__7)) + (r__8 = r_imag(&x[j *
00269 x_dim1 + 2]), dabs(r__8)));
00270 i__2 = *n - 1;
00271 for (i__ = 2; i__ <= i__2; ++i__) {
00272 i__3 = i__ + j * b_dim1;
00273 bi.r = b[i__3].r, bi.i = b[i__3].i;
00274 r_cnjg(&q__2, &e[i__ - 1]);
00275 i__3 = i__ - 1 + j * x_dim1;
00276 q__1.r = q__2.r * x[i__3].r - q__2.i * x[i__3].i, q__1.i =
00277 q__2.r * x[i__3].i + q__2.i * x[i__3].r;
00278 cx.r = q__1.r, cx.i = q__1.i;
00279 i__3 = i__;
00280 i__4 = i__ + j * x_dim1;
00281 q__1.r = d__[i__3] * x[i__4].r, q__1.i = d__[i__3] * x[
00282 i__4].i;
00283 dx.r = q__1.r, dx.i = q__1.i;
00284 i__3 = i__;
00285 i__4 = i__ + 1 + j * x_dim1;
00286 q__1.r = e[i__3].r * x[i__4].r - e[i__3].i * x[i__4].i,
00287 q__1.i = e[i__3].r * x[i__4].i + e[i__3].i * x[
00288 i__4].r;
00289 ex.r = q__1.r, ex.i = q__1.i;
00290 i__3 = i__;
00291 q__3.r = bi.r - cx.r, q__3.i = bi.i - cx.i;
00292 q__2.r = q__3.r - dx.r, q__2.i = q__3.i - dx.i;
00293 q__1.r = q__2.r - ex.r, q__1.i = q__2.i - ex.i;
00294 work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00295 i__3 = i__ - 1;
00296 i__4 = i__ - 1 + j * x_dim1;
00297 i__5 = i__;
00298 i__6 = i__ + 1 + j * x_dim1;
00299 rwork[i__] = (r__1 = bi.r, dabs(r__1)) + (r__2 = r_imag(&
00300 bi), dabs(r__2)) + ((r__3 = e[i__3].r, dabs(r__3))
00301 + (r__4 = r_imag(&e[i__ - 1]), dabs(r__4))) * ((
00302 r__5 = x[i__4].r, dabs(r__5)) + (r__6 = r_imag(&x[
00303 i__ - 1 + j * x_dim1]), dabs(r__6))) + ((r__7 =
00304 dx.r, dabs(r__7)) + (r__8 = r_imag(&dx), dabs(
00305 r__8))) + ((r__9 = e[i__5].r, dabs(r__9)) + (
00306 r__10 = r_imag(&e[i__]), dabs(r__10))) * ((r__11 =
00307 x[i__6].r, dabs(r__11)) + (r__12 = r_imag(&x[i__
00308 + 1 + j * x_dim1]), dabs(r__12)));
00309
00310 }
00311 i__2 = *n + j * b_dim1;
00312 bi.r = b[i__2].r, bi.i = b[i__2].i;
00313 r_cnjg(&q__2, &e[*n - 1]);
00314 i__2 = *n - 1 + j * x_dim1;
00315 q__1.r = q__2.r * x[i__2].r - q__2.i * x[i__2].i, q__1.i =
00316 q__2.r * x[i__2].i + q__2.i * x[i__2].r;
00317 cx.r = q__1.r, cx.i = q__1.i;
00318 i__2 = *n;
00319 i__3 = *n + j * x_dim1;
00320 q__1.r = d__[i__2] * x[i__3].r, q__1.i = d__[i__2] * x[i__3]
00321 .i;
00322 dx.r = q__1.r, dx.i = q__1.i;
00323 i__2 = *n;
00324 q__2.r = bi.r - cx.r, q__2.i = bi.i - cx.i;
00325 q__1.r = q__2.r - dx.r, q__1.i = q__2.i - dx.i;
00326 work[i__2].r = q__1.r, work[i__2].i = q__1.i;
00327 i__2 = *n - 1;
00328 i__3 = *n - 1 + j * x_dim1;
00329 rwork[*n] = (r__1 = bi.r, dabs(r__1)) + (r__2 = r_imag(&bi),
00330 dabs(r__2)) + ((r__3 = e[i__2].r, dabs(r__3)) + (r__4
00331 = r_imag(&e[*n - 1]), dabs(r__4))) * ((r__5 = x[i__3]
00332 .r, dabs(r__5)) + (r__6 = r_imag(&x[*n - 1 + j *
00333 x_dim1]), dabs(r__6))) + ((r__7 = dx.r, dabs(r__7)) +
00334 (r__8 = r_imag(&dx), dabs(r__8)));
00335 }
00336 } else {
00337 if (*n == 1) {
00338 i__2 = j * b_dim1 + 1;
00339 bi.r = b[i__2].r, bi.i = b[i__2].i;
00340 i__2 = j * x_dim1 + 1;
00341 q__1.r = d__[1] * x[i__2].r, q__1.i = d__[1] * x[i__2].i;
00342 dx.r = q__1.r, dx.i = q__1.i;
00343 q__1.r = bi.r - dx.r, q__1.i = bi.i - dx.i;
00344 work[1].r = q__1.r, work[1].i = q__1.i;
00345 rwork[1] = (r__1 = bi.r, dabs(r__1)) + (r__2 = r_imag(&bi),
00346 dabs(r__2)) + ((r__3 = dx.r, dabs(r__3)) + (r__4 =
00347 r_imag(&dx), dabs(r__4)));
00348 } else {
00349 i__2 = j * b_dim1 + 1;
00350 bi.r = b[i__2].r, bi.i = b[i__2].i;
00351 i__2 = j * x_dim1 + 1;
00352 q__1.r = d__[1] * x[i__2].r, q__1.i = d__[1] * x[i__2].i;
00353 dx.r = q__1.r, dx.i = q__1.i;
00354 r_cnjg(&q__2, &e[1]);
00355 i__2 = j * x_dim1 + 2;
00356 q__1.r = q__2.r * x[i__2].r - q__2.i * x[i__2].i, q__1.i =
00357 q__2.r * x[i__2].i + q__2.i * x[i__2].r;
00358 ex.r = q__1.r, ex.i = q__1.i;
00359 q__2.r = bi.r - dx.r, q__2.i = bi.i - dx.i;
00360 q__1.r = q__2.r - ex.r, q__1.i = q__2.i - ex.i;
00361 work[1].r = q__1.r, work[1].i = q__1.i;
00362 i__2 = j * x_dim1 + 2;
00363 rwork[1] = (r__1 = bi.r, dabs(r__1)) + (r__2 = r_imag(&bi),
00364 dabs(r__2)) + ((r__3 = dx.r, dabs(r__3)) + (r__4 =
00365 r_imag(&dx), dabs(r__4))) + ((r__5 = e[1].r, dabs(
00366 r__5)) + (r__6 = r_imag(&e[1]), dabs(r__6))) * ((r__7
00367 = x[i__2].r, dabs(r__7)) + (r__8 = r_imag(&x[j *
00368 x_dim1 + 2]), dabs(r__8)));
00369 i__2 = *n - 1;
00370 for (i__ = 2; i__ <= i__2; ++i__) {
00371 i__3 = i__ + j * b_dim1;
00372 bi.r = b[i__3].r, bi.i = b[i__3].i;
00373 i__3 = i__ - 1;
00374 i__4 = i__ - 1 + j * x_dim1;
00375 q__1.r = e[i__3].r * x[i__4].r - e[i__3].i * x[i__4].i,
00376 q__1.i = e[i__3].r * x[i__4].i + e[i__3].i * x[
00377 i__4].r;
00378 cx.r = q__1.r, cx.i = q__1.i;
00379 i__3 = i__;
00380 i__4 = i__ + j * x_dim1;
00381 q__1.r = d__[i__3] * x[i__4].r, q__1.i = d__[i__3] * x[
00382 i__4].i;
00383 dx.r = q__1.r, dx.i = q__1.i;
00384 r_cnjg(&q__2, &e[i__]);
00385 i__3 = i__ + 1 + j * x_dim1;
00386 q__1.r = q__2.r * x[i__3].r - q__2.i * x[i__3].i, q__1.i =
00387 q__2.r * x[i__3].i + q__2.i * x[i__3].r;
00388 ex.r = q__1.r, ex.i = q__1.i;
00389 i__3 = i__;
00390 q__3.r = bi.r - cx.r, q__3.i = bi.i - cx.i;
00391 q__2.r = q__3.r - dx.r, q__2.i = q__3.i - dx.i;
00392 q__1.r = q__2.r - ex.r, q__1.i = q__2.i - ex.i;
00393 work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00394 i__3 = i__ - 1;
00395 i__4 = i__ - 1 + j * x_dim1;
00396 i__5 = i__;
00397 i__6 = i__ + 1 + j * x_dim1;
00398 rwork[i__] = (r__1 = bi.r, dabs(r__1)) + (r__2 = r_imag(&
00399 bi), dabs(r__2)) + ((r__3 = e[i__3].r, dabs(r__3))
00400 + (r__4 = r_imag(&e[i__ - 1]), dabs(r__4))) * ((
00401 r__5 = x[i__4].r, dabs(r__5)) + (r__6 = r_imag(&x[
00402 i__ - 1 + j * x_dim1]), dabs(r__6))) + ((r__7 =
00403 dx.r, dabs(r__7)) + (r__8 = r_imag(&dx), dabs(
00404 r__8))) + ((r__9 = e[i__5].r, dabs(r__9)) + (
00405 r__10 = r_imag(&e[i__]), dabs(r__10))) * ((r__11 =
00406 x[i__6].r, dabs(r__11)) + (r__12 = r_imag(&x[i__
00407 + 1 + j * x_dim1]), dabs(r__12)));
00408
00409 }
00410 i__2 = *n + j * b_dim1;
00411 bi.r = b[i__2].r, bi.i = b[i__2].i;
00412 i__2 = *n - 1;
00413 i__3 = *n - 1 + j * x_dim1;
00414 q__1.r = e[i__2].r * x[i__3].r - e[i__2].i * x[i__3].i,
00415 q__1.i = e[i__2].r * x[i__3].i + e[i__2].i * x[i__3]
00416 .r;
00417 cx.r = q__1.r, cx.i = q__1.i;
00418 i__2 = *n;
00419 i__3 = *n + j * x_dim1;
00420 q__1.r = d__[i__2] * x[i__3].r, q__1.i = d__[i__2] * x[i__3]
00421 .i;
00422 dx.r = q__1.r, dx.i = q__1.i;
00423 i__2 = *n;
00424 q__2.r = bi.r - cx.r, q__2.i = bi.i - cx.i;
00425 q__1.r = q__2.r - dx.r, q__1.i = q__2.i - dx.i;
00426 work[i__2].r = q__1.r, work[i__2].i = q__1.i;
00427 i__2 = *n - 1;
00428 i__3 = *n - 1 + j * x_dim1;
00429 rwork[*n] = (r__1 = bi.r, dabs(r__1)) + (r__2 = r_imag(&bi),
00430 dabs(r__2)) + ((r__3 = e[i__2].r, dabs(r__3)) + (r__4
00431 = r_imag(&e[*n - 1]), dabs(r__4))) * ((r__5 = x[i__3]
00432 .r, dabs(r__5)) + (r__6 = r_imag(&x[*n - 1 + j *
00433 x_dim1]), dabs(r__6))) + ((r__7 = dx.r, dabs(r__7)) +
00434 (r__8 = r_imag(&dx), dabs(r__8)));
00435 }
00436 }
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447 s = 0.f;
00448 i__2 = *n;
00449 for (i__ = 1; i__ <= i__2; ++i__) {
00450 if (rwork[i__] > safe2) {
00451
00452 i__3 = i__;
00453 r__3 = s, r__4 = ((r__1 = work[i__3].r, dabs(r__1)) + (r__2 =
00454 r_imag(&work[i__]), dabs(r__2))) / rwork[i__];
00455 s = dmax(r__3,r__4);
00456 } else {
00457
00458 i__3 = i__;
00459 r__3 = s, r__4 = ((r__1 = work[i__3].r, dabs(r__1)) + (r__2 =
00460 r_imag(&work[i__]), dabs(r__2)) + safe1) / (rwork[i__]
00461 + safe1);
00462 s = dmax(r__3,r__4);
00463 }
00464
00465 }
00466 berr[j] = s;
00467
00468
00469
00470
00471
00472
00473
00474 if (berr[j] > eps && berr[j] * 2.f <= lstres && count <= 5) {
00475
00476
00477
00478 cpttrs_(uplo, n, &c__1, &df[1], &ef[1], &work[1], n, info);
00479 caxpy_(n, &c_b16, &work[1], &c__1, &x[j * x_dim1 + 1], &c__1);
00480 lstres = berr[j];
00481 ++count;
00482 goto L20;
00483 }
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503 i__2 = *n;
00504 for (i__ = 1; i__ <= i__2; ++i__) {
00505 if (rwork[i__] > safe2) {
00506 i__3 = i__;
00507 rwork[i__] = (r__1 = work[i__3].r, dabs(r__1)) + (r__2 =
00508 r_imag(&work[i__]), dabs(r__2)) + nz * eps * rwork[
00509 i__];
00510 } else {
00511 i__3 = i__;
00512 rwork[i__] = (r__1 = work[i__3].r, dabs(r__1)) + (r__2 =
00513 r_imag(&work[i__]), dabs(r__2)) + nz * eps * rwork[
00514 i__] + safe1;
00515 }
00516
00517 }
00518 ix = isamax_(n, &rwork[1], &c__1);
00519 ferr[j] = rwork[ix];
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532 rwork[1] = 1.f;
00533 i__2 = *n;
00534 for (i__ = 2; i__ <= i__2; ++i__) {
00535 rwork[i__] = rwork[i__ - 1] * c_abs(&ef[i__ - 1]) + 1.f;
00536
00537 }
00538
00539
00540
00541 rwork[*n] /= df[*n];
00542 for (i__ = *n - 1; i__ >= 1; --i__) {
00543 rwork[i__] = rwork[i__] / df[i__] + rwork[i__ + 1] * c_abs(&ef[
00544 i__]);
00545
00546 }
00547
00548
00549
00550 ix = isamax_(n, &rwork[1], &c__1);
00551 ferr[j] *= (r__1 = rwork[ix], dabs(r__1));
00552
00553
00554
00555 lstres = 0.f;
00556 i__2 = *n;
00557 for (i__ = 1; i__ <= i__2; ++i__) {
00558
00559 r__1 = lstres, r__2 = c_abs(&x[i__ + j * x_dim1]);
00560 lstres = dmax(r__1,r__2);
00561
00562 }
00563 if (lstres != 0.f) {
00564 ferr[j] /= lstres;
00565 }
00566
00567
00568 }
00569
00570 return 0;
00571
00572
00573
00574 }