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