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