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 real c_b19 = -1.f;
00020
00021 int strrfs_(char *uplo, char *trans, char *diag, integer *n,
00022 integer *nrhs, real *a, integer *lda, real *b, integer *ldb, real *x,
00023 integer *ldx, real *ferr, real *berr, real *work, integer *iwork,
00024 integer *info)
00025 {
00026
00027 integer a_dim1, a_offset, b_dim1, b_offset, x_dim1, x_offset, i__1, i__2,
00028 i__3;
00029 real r__1, r__2, r__3;
00030
00031
00032 integer i__, j, k;
00033 real s, xk;
00034 integer nz;
00035 real eps;
00036 integer kase;
00037 real safe1, safe2;
00038 extern logical lsame_(char *, char *);
00039 integer isave[3];
00040 logical upper;
00041 extern int scopy_(integer *, real *, integer *, real *,
00042 integer *), saxpy_(integer *, real *, real *, integer *, real *,
00043 integer *), strmv_(char *, char *, char *, integer *, real *,
00044 integer *, real *, integer *), strsv_(
00045 char *, char *, char *, integer *, real *, integer *, real *,
00046 integer *), slacn2_(integer *, real *,
00047 real *, integer *, real *, integer *, integer *);
00048 extern doublereal slamch_(char *);
00049 real safmin;
00050 extern int xerbla_(char *, integer *);
00051 logical notran;
00052 char transt[1];
00053 logical nounit;
00054 real lstres;
00055
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
00170 a_dim1 = *lda;
00171 a_offset = 1 + a_dim1;
00172 a -= a_offset;
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 --iwork;
00183
00184
00185 *info = 0;
00186 upper = lsame_(uplo, "U");
00187 notran = lsame_(trans, "N");
00188 nounit = lsame_(diag, "N");
00189
00190 if (! upper && ! lsame_(uplo, "L")) {
00191 *info = -1;
00192 } else if (! notran && ! lsame_(trans, "T") && !
00193 lsame_(trans, "C")) {
00194 *info = -2;
00195 } else if (! nounit && ! lsame_(diag, "U")) {
00196 *info = -3;
00197 } else if (*n < 0) {
00198 *info = -4;
00199 } else if (*nrhs < 0) {
00200 *info = -5;
00201 } else if (*lda < max(1,*n)) {
00202 *info = -7;
00203 } else if (*ldb < max(1,*n)) {
00204 *info = -9;
00205 } else if (*ldx < max(1,*n)) {
00206 *info = -11;
00207 }
00208 if (*info != 0) {
00209 i__1 = -(*info);
00210 xerbla_("STRRFS", &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 *)transt = 'T';
00228 } else {
00229 *(unsigned char *)transt = 'N';
00230 }
00231
00232
00233
00234 nz = *n + 1;
00235 eps = slamch_("Epsilon");
00236 safmin = slamch_("Safe minimum");
00237 safe1 = nz * safmin;
00238 safe2 = safe1 / eps;
00239
00240
00241
00242 i__1 = *nrhs;
00243 for (j = 1; j <= i__1; ++j) {
00244
00245
00246
00247
00248 scopy_(n, &x[j * x_dim1 + 1], &c__1, &work[*n + 1], &c__1);
00249 strmv_(uplo, trans, diag, n, &a[a_offset], lda, &work[*n + 1], &c__1);
00250 saxpy_(n, &c_b19, &b[j * b_dim1 + 1], &c__1, &work[*n + 1], &c__1);
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 i__2 = *n;
00262 for (i__ = 1; i__ <= i__2; ++i__) {
00263 work[i__] = (r__1 = b[i__ + j * b_dim1], dabs(r__1));
00264
00265 }
00266
00267 if (notran) {
00268
00269
00270
00271 if (upper) {
00272 if (nounit) {
00273 i__2 = *n;
00274 for (k = 1; k <= i__2; ++k) {
00275 xk = (r__1 = x[k + j * x_dim1], dabs(r__1));
00276 i__3 = k;
00277 for (i__ = 1; i__ <= i__3; ++i__) {
00278 work[i__] += (r__1 = a[i__ + k * a_dim1], dabs(
00279 r__1)) * xk;
00280
00281 }
00282
00283 }
00284 } else {
00285 i__2 = *n;
00286 for (k = 1; k <= i__2; ++k) {
00287 xk = (r__1 = x[k + j * x_dim1], dabs(r__1));
00288 i__3 = k - 1;
00289 for (i__ = 1; i__ <= i__3; ++i__) {
00290 work[i__] += (r__1 = a[i__ + k * a_dim1], dabs(
00291 r__1)) * xk;
00292
00293 }
00294 work[k] += xk;
00295
00296 }
00297 }
00298 } else {
00299 if (nounit) {
00300 i__2 = *n;
00301 for (k = 1; k <= i__2; ++k) {
00302 xk = (r__1 = x[k + j * x_dim1], dabs(r__1));
00303 i__3 = *n;
00304 for (i__ = k; i__ <= i__3; ++i__) {
00305 work[i__] += (r__1 = a[i__ + k * a_dim1], dabs(
00306 r__1)) * xk;
00307
00308 }
00309
00310 }
00311 } else {
00312 i__2 = *n;
00313 for (k = 1; k <= i__2; ++k) {
00314 xk = (r__1 = x[k + j * x_dim1], dabs(r__1));
00315 i__3 = *n;
00316 for (i__ = k + 1; i__ <= i__3; ++i__) {
00317 work[i__] += (r__1 = a[i__ + k * a_dim1], dabs(
00318 r__1)) * xk;
00319
00320 }
00321 work[k] += xk;
00322
00323 }
00324 }
00325 }
00326 } else {
00327
00328
00329
00330 if (upper) {
00331 if (nounit) {
00332 i__2 = *n;
00333 for (k = 1; k <= i__2; ++k) {
00334 s = 0.f;
00335 i__3 = k;
00336 for (i__ = 1; i__ <= i__3; ++i__) {
00337 s += (r__1 = a[i__ + k * a_dim1], dabs(r__1)) * (
00338 r__2 = x[i__ + j * x_dim1], dabs(r__2));
00339
00340 }
00341 work[k] += s;
00342
00343 }
00344 } else {
00345 i__2 = *n;
00346 for (k = 1; k <= i__2; ++k) {
00347 s = (r__1 = x[k + j * x_dim1], dabs(r__1));
00348 i__3 = k - 1;
00349 for (i__ = 1; i__ <= i__3; ++i__) {
00350 s += (r__1 = a[i__ + k * a_dim1], dabs(r__1)) * (
00351 r__2 = x[i__ + j * x_dim1], dabs(r__2));
00352
00353 }
00354 work[k] += s;
00355
00356 }
00357 }
00358 } else {
00359 if (nounit) {
00360 i__2 = *n;
00361 for (k = 1; k <= i__2; ++k) {
00362 s = 0.f;
00363 i__3 = *n;
00364 for (i__ = k; i__ <= i__3; ++i__) {
00365 s += (r__1 = a[i__ + k * a_dim1], dabs(r__1)) * (
00366 r__2 = x[i__ + j * x_dim1], dabs(r__2));
00367
00368 }
00369 work[k] += s;
00370
00371 }
00372 } else {
00373 i__2 = *n;
00374 for (k = 1; k <= i__2; ++k) {
00375 s = (r__1 = x[k + j * x_dim1], dabs(r__1));
00376 i__3 = *n;
00377 for (i__ = k + 1; i__ <= i__3; ++i__) {
00378 s += (r__1 = a[i__ + k * a_dim1], dabs(r__1)) * (
00379 r__2 = x[i__ + j * x_dim1], dabs(r__2));
00380
00381 }
00382 work[k] += s;
00383
00384 }
00385 }
00386 }
00387 }
00388 s = 0.f;
00389 i__2 = *n;
00390 for (i__ = 1; i__ <= i__2; ++i__) {
00391 if (work[i__] > safe2) {
00392
00393 r__2 = s, r__3 = (r__1 = work[*n + i__], dabs(r__1)) / work[
00394 i__];
00395 s = dmax(r__2,r__3);
00396 } else {
00397
00398 r__2 = s, r__3 = ((r__1 = work[*n + i__], dabs(r__1)) + safe1)
00399 / (work[i__] + safe1);
00400 s = dmax(r__2,r__3);
00401 }
00402
00403 }
00404 berr[j] = s;
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428 i__2 = *n;
00429 for (i__ = 1; i__ <= i__2; ++i__) {
00430 if (work[i__] > safe2) {
00431 work[i__] = (r__1 = work[*n + i__], dabs(r__1)) + nz * eps *
00432 work[i__];
00433 } else {
00434 work[i__] = (r__1 = work[*n + i__], dabs(r__1)) + nz * eps *
00435 work[i__] + safe1;
00436 }
00437
00438 }
00439
00440 kase = 0;
00441 L210:
00442 slacn2_(n, &work[(*n << 1) + 1], &work[*n + 1], &iwork[1], &ferr[j], &
00443 kase, isave);
00444 if (kase != 0) {
00445 if (kase == 1) {
00446
00447
00448
00449 strsv_(uplo, transt, diag, n, &a[a_offset], lda, &work[*n + 1]
00450 , &c__1);
00451 i__2 = *n;
00452 for (i__ = 1; i__ <= i__2; ++i__) {
00453 work[*n + i__] = work[i__] * work[*n + i__];
00454
00455 }
00456 } else {
00457
00458
00459
00460 i__2 = *n;
00461 for (i__ = 1; i__ <= i__2; ++i__) {
00462 work[*n + i__] = work[i__] * work[*n + i__];
00463
00464 }
00465 strsv_(uplo, trans, diag, n, &a[a_offset], lda, &work[*n + 1],
00466 &c__1);
00467 }
00468 goto L210;
00469 }
00470
00471
00472
00473 lstres = 0.f;
00474 i__2 = *n;
00475 for (i__ = 1; i__ <= i__2; ++i__) {
00476
00477 r__2 = lstres, r__3 = (r__1 = x[i__ + j * x_dim1], dabs(r__1));
00478 lstres = dmax(r__2,r__3);
00479
00480 }
00481 if (lstres != 0.f) {
00482 ferr[j] /= lstres;
00483 }
00484
00485
00486 }
00487
00488 return 0;
00489
00490
00491
00492 }