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 ctprfs_(char *uplo, char *trans, char *diag, integer *n,
00021 integer *nrhs, complex *ap, complex *b, integer *ldb, complex *x,
00022 integer *ldx, real *ferr, real *berr, complex *work, real *rwork,
00023 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 real r__1, r__2, r__3, r__4;
00028 complex q__1;
00029
00030
00031 double r_imag(complex *);
00032
00033
00034 integer i__, j, k;
00035 real s;
00036 integer kc;
00037 real 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 *), ctpmv_(char *, char *, char *,
00047 integer *, complex *, complex *, integer *);
00048 logical upper;
00049 extern int ctpsv_(char *, char *, char *, integer *,
00050 complex *, complex *, integer *), clacn2_(
00051 integer *, complex *, complex *, real *, integer *, integer *);
00052 extern doublereal slamch_(char *);
00053 real safmin;
00054 extern int xerbla_(char *, integer *);
00055 logical notran;
00056 char transn[1], transt[1];
00057 logical nounit;
00058 real 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_("CTPRFS", &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.f;
00220 berr[j] = 0.f;
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 = slamch_("Epsilon");
00238 safmin = slamch_("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 ccopy_(n, &x[j * x_dim1 + 1], &c__1, &work[1], &c__1);
00251 ctpmv_(uplo, trans, diag, n, &ap[1], &work[1], &c__1);
00252 q__1.r = -1.f, q__1.i = -0.f;
00253 caxpy_(n, &q__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__] = (r__1 = b[i__3].r, dabs(r__1)) + (r__2 = r_imag(&b[
00268 i__ + j * b_dim1]), dabs(r__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 = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&
00283 x[k + j * x_dim1]), dabs(r__2));
00284 i__3 = k;
00285 for (i__ = 1; i__ <= i__3; ++i__) {
00286 i__4 = kc + i__ - 1;
00287 rwork[i__] += ((r__1 = ap[i__4].r, dabs(r__1)) + (
00288 r__2 = r_imag(&ap[kc + i__ - 1]), dabs(
00289 r__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 = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&
00300 x[k + j * x_dim1]), dabs(r__2));
00301 i__3 = k - 1;
00302 for (i__ = 1; i__ <= i__3; ++i__) {
00303 i__4 = kc + i__ - 1;
00304 rwork[i__] += ((r__1 = ap[i__4].r, dabs(r__1)) + (
00305 r__2 = r_imag(&ap[kc + i__ - 1]), dabs(
00306 r__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 = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&
00321 x[k + j * x_dim1]), dabs(r__2));
00322 i__3 = *n;
00323 for (i__ = k; i__ <= i__3; ++i__) {
00324 i__4 = kc + i__ - k;
00325 rwork[i__] += ((r__1 = ap[i__4].r, dabs(r__1)) + (
00326 r__2 = r_imag(&ap[kc + i__ - k]), dabs(
00327 r__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 = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&
00338 x[k + j * x_dim1]), dabs(r__2));
00339 i__3 = *n;
00340 for (i__ = k + 1; i__ <= i__3; ++i__) {
00341 i__4 = kc + i__ - k;
00342 rwork[i__] += ((r__1 = ap[i__4].r, dabs(r__1)) + (
00343 r__2 = r_imag(&ap[kc + i__ - k]), dabs(
00344 r__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.f;
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 += ((r__1 = ap[i__4].r, dabs(r__1)) + (r__2 =
00368 r_imag(&ap[kc + i__ - 1]), dabs(r__2))) *
00369 ((r__3 = x[i__5].r, dabs(r__3)) + (r__4 =
00370 r_imag(&x[i__ + j * x_dim1]), dabs(r__4)))
00371 ;
00372
00373 }
00374 rwork[k] += s;
00375 kc += k;
00376
00377 }
00378 } else {
00379 i__2 = *n;
00380 for (k = 1; k <= i__2; ++k) {
00381 i__3 = k + j * x_dim1;
00382 s = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&
00383 x[k + j * x_dim1]), dabs(r__2));
00384 i__3 = k - 1;
00385 for (i__ = 1; i__ <= i__3; ++i__) {
00386 i__4 = kc + i__ - 1;
00387 i__5 = i__ + j * x_dim1;
00388 s += ((r__1 = ap[i__4].r, dabs(r__1)) + (r__2 =
00389 r_imag(&ap[kc + i__ - 1]), dabs(r__2))) *
00390 ((r__3 = x[i__5].r, dabs(r__3)) + (r__4 =
00391 r_imag(&x[i__ + j * x_dim1]), dabs(r__4)))
00392 ;
00393
00394 }
00395 rwork[k] += s;
00396 kc += k;
00397
00398 }
00399 }
00400 } else {
00401 kc = 1;
00402 if (nounit) {
00403 i__2 = *n;
00404 for (k = 1; k <= i__2; ++k) {
00405 s = 0.f;
00406 i__3 = *n;
00407 for (i__ = k; i__ <= i__3; ++i__) {
00408 i__4 = kc + i__ - k;
00409 i__5 = i__ + j * x_dim1;
00410 s += ((r__1 = ap[i__4].r, dabs(r__1)) + (r__2 =
00411 r_imag(&ap[kc + i__ - k]), dabs(r__2))) *
00412 ((r__3 = x[i__5].r, dabs(r__3)) + (r__4 =
00413 r_imag(&x[i__ + j * x_dim1]), dabs(r__4)))
00414 ;
00415
00416 }
00417 rwork[k] += s;
00418 kc = kc + *n - k + 1;
00419
00420 }
00421 } else {
00422 i__2 = *n;
00423 for (k = 1; k <= i__2; ++k) {
00424 i__3 = k + j * x_dim1;
00425 s = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&
00426 x[k + j * x_dim1]), dabs(r__2));
00427 i__3 = *n;
00428 for (i__ = k + 1; i__ <= i__3; ++i__) {
00429 i__4 = kc + i__ - k;
00430 i__5 = i__ + j * x_dim1;
00431 s += ((r__1 = ap[i__4].r, dabs(r__1)) + (r__2 =
00432 r_imag(&ap[kc + i__ - k]), dabs(r__2))) *
00433 ((r__3 = x[i__5].r, dabs(r__3)) + (r__4 =
00434 r_imag(&x[i__ + j * x_dim1]), dabs(r__4)))
00435 ;
00436
00437 }
00438 rwork[k] += s;
00439 kc = kc + *n - k + 1;
00440
00441 }
00442 }
00443 }
00444 }
00445 s = 0.f;
00446 i__2 = *n;
00447 for (i__ = 1; i__ <= i__2; ++i__) {
00448 if (rwork[i__] > safe2) {
00449
00450 i__3 = i__;
00451 r__3 = s, r__4 = ((r__1 = work[i__3].r, dabs(r__1)) + (r__2 =
00452 r_imag(&work[i__]), dabs(r__2))) / rwork[i__];
00453 s = dmax(r__3,r__4);
00454 } else {
00455
00456 i__3 = i__;
00457 r__3 = s, r__4 = ((r__1 = work[i__3].r, dabs(r__1)) + (r__2 =
00458 r_imag(&work[i__]), dabs(r__2)) + safe1) / (rwork[i__]
00459 + safe1);
00460 s = dmax(r__3,r__4);
00461 }
00462
00463 }
00464 berr[j] = s;
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488 i__2 = *n;
00489 for (i__ = 1; i__ <= i__2; ++i__) {
00490 if (rwork[i__] > safe2) {
00491 i__3 = i__;
00492 rwork[i__] = (r__1 = work[i__3].r, dabs(r__1)) + (r__2 =
00493 r_imag(&work[i__]), dabs(r__2)) + nz * eps * rwork[
00494 i__];
00495 } else {
00496 i__3 = i__;
00497 rwork[i__] = (r__1 = work[i__3].r, dabs(r__1)) + (r__2 =
00498 r_imag(&work[i__]), dabs(r__2)) + nz * eps * rwork[
00499 i__] + safe1;
00500 }
00501
00502 }
00503
00504 kase = 0;
00505 L210:
00506 clacn2_(n, &work[*n + 1], &work[1], &ferr[j], &kase, isave);
00507 if (kase != 0) {
00508 if (kase == 1) {
00509
00510
00511
00512 ctpsv_(uplo, transt, diag, n, &ap[1], &work[1], &c__1);
00513 i__2 = *n;
00514 for (i__ = 1; i__ <= i__2; ++i__) {
00515 i__3 = i__;
00516 i__4 = i__;
00517 i__5 = i__;
00518 q__1.r = rwork[i__4] * work[i__5].r, q__1.i = rwork[i__4]
00519 * work[i__5].i;
00520 work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00521
00522 }
00523 } else {
00524
00525
00526
00527 i__2 = *n;
00528 for (i__ = 1; i__ <= i__2; ++i__) {
00529 i__3 = i__;
00530 i__4 = i__;
00531 i__5 = i__;
00532 q__1.r = rwork[i__4] * work[i__5].r, q__1.i = rwork[i__4]
00533 * work[i__5].i;
00534 work[i__3].r = q__1.r, work[i__3].i = q__1.i;
00535
00536 }
00537 ctpsv_(uplo, transn, diag, n, &ap[1], &work[1], &c__1);
00538 }
00539 goto L210;
00540 }
00541
00542
00543
00544 lstres = 0.f;
00545 i__2 = *n;
00546 for (i__ = 1; i__ <= i__2; ++i__) {
00547
00548 i__3 = i__ + j * x_dim1;
00549 r__3 = lstres, r__4 = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 =
00550 r_imag(&x[i__ + j * x_dim1]), dabs(r__2));
00551 lstres = dmax(r__3,r__4);
00552
00553 }
00554 if (lstres != 0.f) {
00555 ferr[j] /= lstres;
00556 }
00557
00558
00559 }
00560
00561 return 0;
00562
00563
00564
00565 }