1 /* ./src_f77/ctbrfs.f -- translated by f2c (version 20030320).
2 You must link the resulting object file with the libraries:
3 -lf2c -lm (in that order)
4 */
5
6 #include <punc/vf2c.h>
7
8 /* Table of constant values */
9
10 static integer c__1 = 1;
11
ctbrfs_(char * uplo,char * trans,char * diag,integer * n,integer * kd,integer * nrhs,complex * ab,integer * ldab,complex * b,integer * ldb,complex * x,integer * ldx,real * ferr,real * berr,complex * work,real * rwork,integer * info,ftnlen uplo_len,ftnlen trans_len,ftnlen diag_len)12 /* Subroutine */ int ctbrfs_(char *uplo, char *trans, char *diag, integer *n,
13 integer *kd, integer *nrhs, complex *ab, integer *ldab, complex *b,
14 integer *ldb, complex *x, integer *ldx, real *ferr, real *berr,
15 complex *work, real *rwork, integer *info, ftnlen uplo_len, ftnlen
16 trans_len, ftnlen diag_len)
17 {
18 /* System generated locals */
19 integer ab_dim1, ab_offset, b_dim1, b_offset, x_dim1, x_offset, i__1,
20 i__2, i__3, i__4, i__5;
21 real r__1, r__2, r__3, r__4;
22 complex q__1;
23
24 /* Builtin functions */
25 double r_imag(complex *);
26
27 /* Local variables */
28 static integer i__, j, k;
29 static real s, xk;
30 static integer nz;
31 static real eps;
32 static integer kase;
33 static real safe1, safe2;
34 extern logical lsame_(char *, char *, ftnlen, ftnlen);
35 extern /* Subroutine */ int ctbmv_(char *, char *, char *, integer *,
36 integer *, complex *, integer *, complex *, integer *, ftnlen,
37 ftnlen, ftnlen), ccopy_(integer *, complex *, integer *, complex *
38 , integer *), ctbsv_(char *, char *, char *, integer *, integer *,
39 complex *, integer *, complex *, integer *, ftnlen, ftnlen,
40 ftnlen), caxpy_(integer *, complex *, complex *, integer *,
41 complex *, integer *);
42 static logical upper;
43 extern /* Subroutine */ int clacon_(integer *, complex *, complex *, real
44 *, integer *);
45 extern doublereal slamch_(char *, ftnlen);
46 static real safmin;
47 extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
48 static logical notran;
49 static char transn[1], transt[1];
50 static logical nounit;
51 static real lstres;
52
53
54 /* -- LAPACK routine (version 3.0) -- */
55 /* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., */
56 /* Courant Institute, Argonne National Lab, and Rice University */
57 /* September 30, 1994 */
58
59 /* .. Scalar Arguments .. */
60 /* .. */
61 /* .. Array Arguments .. */
62 /* .. */
63
64 /* Purpose */
65 /* ======= */
66
67 /* CTBRFS provides error bounds and backward error estimates for the */
68 /* solution to a system of linear equations with a triangular band */
69 /* coefficient matrix. */
70
71 /* The solution matrix X must be computed by CTBTRS or some other */
72 /* means before entering this routine. CTBRFS does not do iterative */
73 /* refinement because doing so cannot improve the backward error. */
74
75 /* Arguments */
76 /* ========= */
77
78 /* UPLO (input) CHARACTER*1 */
79 /* = 'U': A is upper triangular; */
80 /* = 'L': A is lower triangular. */
81
82 /* TRANS (input) CHARACTER*1 */
83 /* Specifies the form of the system of equations: */
84 /* = 'N': A * X = B (No transpose) */
85 /* = 'T': A**T * X = B (Transpose) */
86 /* = 'C': A**H * X = B (Conjugate transpose) */
87
88 /* DIAG (input) CHARACTER*1 */
89 /* = 'N': A is non-unit triangular; */
90 /* = 'U': A is unit triangular. */
91
92 /* N (input) INTEGER */
93 /* The order of the matrix A. N >= 0. */
94
95 /* KD (input) INTEGER */
96 /* The number of superdiagonals or subdiagonals of the */
97 /* triangular band matrix A. KD >= 0. */
98
99 /* NRHS (input) INTEGER */
100 /* The number of right hand sides, i.e., the number of columns */
101 /* of the matrices B and X. NRHS >= 0. */
102
103 /* AB (input) COMPLEX array, dimension (LDAB,N) */
104 /* The upper or lower triangular band matrix A, stored in the */
105 /* first kd+1 rows of the array. The j-th column of A is stored */
106 /* in the j-th column of the array AB as follows: */
107 /* if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; */
108 /* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd). */
109 /* If DIAG = 'U', the diagonal elements of A are not referenced */
110 /* and are assumed to be 1. */
111
112 /* LDAB (input) INTEGER */
113 /* The leading dimension of the array AB. LDAB >= KD+1. */
114
115 /* B (input) COMPLEX array, dimension (LDB,NRHS) */
116 /* The right hand side matrix B. */
117
118 /* LDB (input) INTEGER */
119 /* The leading dimension of the array B. LDB >= max(1,N). */
120
121 /* X (input) COMPLEX array, dimension (LDX,NRHS) */
122 /* The solution matrix X. */
123
124 /* LDX (input) INTEGER */
125 /* The leading dimension of the array X. LDX >= max(1,N). */
126
127 /* FERR (output) REAL array, dimension (NRHS) */
128 /* The estimated forward error bound for each solution vector */
129 /* X(j) (the j-th column of the solution matrix X). */
130 /* If XTRUE is the true solution corresponding to X(j), FERR(j) */
131 /* is an estimated upper bound for the magnitude of the largest */
132 /* element in (X(j) - XTRUE) divided by the magnitude of the */
133 /* largest element in X(j). The estimate is as reliable as */
134 /* the estimate for RCOND, and is almost always a slight */
135 /* overestimate of the true error. */
136
137 /* BERR (output) REAL array, dimension (NRHS) */
138 /* The componentwise relative backward error of each solution */
139 /* vector X(j) (i.e., the smallest relative change in */
140 /* any element of A or B that makes X(j) an exact solution). */
141
142 /* WORK (workspace) COMPLEX array, dimension (2*N) */
143
144 /* RWORK (workspace) REAL array, dimension (N) */
145
146 /* INFO (output) INTEGER */
147 /* = 0: successful exit */
148 /* < 0: if INFO = -i, the i-th argument had an illegal value */
149
150 /* ===================================================================== */
151
152 /* .. Parameters .. */
153 /* .. */
154 /* .. Local Scalars .. */
155 /* .. */
156 /* .. External Subroutines .. */
157 /* .. */
158 /* .. Intrinsic Functions .. */
159 /* .. */
160 /* .. External Functions .. */
161 /* .. */
162 /* .. Statement Functions .. */
163 /* .. */
164 /* .. Statement Function definitions .. */
165 /* .. */
166 /* .. Executable Statements .. */
167
168 /* Test the input parameters. */
169
170 /* Parameter adjustments */
171 ab_dim1 = *ldab;
172 ab_offset = 1 + ab_dim1;
173 ab -= ab_offset;
174 b_dim1 = *ldb;
175 b_offset = 1 + b_dim1;
176 b -= b_offset;
177 x_dim1 = *ldx;
178 x_offset = 1 + x_dim1;
179 x -= x_offset;
180 --ferr;
181 --berr;
182 --work;
183 --rwork;
184
185 /* Function Body */
186 *info = 0;
187 upper = lsame_(uplo, "U", (ftnlen)1, (ftnlen)1);
188 notran = lsame_(trans, "N", (ftnlen)1, (ftnlen)1);
189 nounit = lsame_(diag, "N", (ftnlen)1, (ftnlen)1);
190
191 if (! upper && ! lsame_(uplo, "L", (ftnlen)1, (ftnlen)1)) {
192 *info = -1;
193 } else if (! notran && ! lsame_(trans, "T", (ftnlen)1, (ftnlen)1) && !
194 lsame_(trans, "C", (ftnlen)1, (ftnlen)1)) {
195 *info = -2;
196 } else if (! nounit && ! lsame_(diag, "U", (ftnlen)1, (ftnlen)1)) {
197 *info = -3;
198 } else if (*n < 0) {
199 *info = -4;
200 } else if (*kd < 0) {
201 *info = -5;
202 } else if (*nrhs < 0) {
203 *info = -6;
204 } else if (*ldab < *kd + 1) {
205 *info = -8;
206 } else if (*ldb < max(1,*n)) {
207 *info = -10;
208 } else if (*ldx < max(1,*n)) {
209 *info = -12;
210 }
211 if (*info != 0) {
212 i__1 = -(*info);
213 xerbla_("CTBRFS", &i__1, (ftnlen)6);
214 return 0;
215 }
216
217 /* Quick return if possible */
218
219 if (*n == 0 || *nrhs == 0) {
220 i__1 = *nrhs;
221 for (j = 1; j <= i__1; ++j) {
222 ferr[j] = 0.f;
223 berr[j] = 0.f;
224 /* L10: */
225 }
226 return 0;
227 }
228
229 if (notran) {
230 *(unsigned char *)transn = 'N';
231 *(unsigned char *)transt = 'C';
232 } else {
233 *(unsigned char *)transn = 'C';
234 *(unsigned char *)transt = 'N';
235 }
236
237 /* NZ = maximum number of nonzero elements in each row of A, plus 1 */
238
239 nz = *kd + 2;
240 eps = slamch_("Epsilon", (ftnlen)7);
241 safmin = slamch_("Safe minimum", (ftnlen)12);
242 safe1 = nz * safmin;
243 safe2 = safe1 / eps;
244
245 /* Do for each right hand side */
246
247 i__1 = *nrhs;
248 for (j = 1; j <= i__1; ++j) {
249
250 /* Compute residual R = B - op(A) * X, */
251 /* where op(A) = A, A**T, or A**H, depending on TRANS. */
252
253 ccopy_(n, &x[j * x_dim1 + 1], &c__1, &work[1], &c__1);
254 ctbmv_(uplo, trans, diag, n, kd, &ab[ab_offset], ldab, &work[1], &
255 c__1, (ftnlen)1, (ftnlen)1, (ftnlen)1);
256 q__1.r = -1.f, q__1.i = -0.f;
257 caxpy_(n, &q__1, &b[j * b_dim1 + 1], &c__1, &work[1], &c__1);
258
259 /* Compute componentwise relative backward error from formula */
260
261 /* max(i) ( abs(R(i)) / ( abs(op(A))*abs(X) + abs(B) )(i) ) */
262
263 /* where abs(Z) is the componentwise absolute value of the matrix */
264 /* or vector Z. If the i-th component of the denominator is less */
265 /* than SAFE2, then SAFE1 is added to the i-th components of the */
266 /* numerator and denominator before dividing. */
267
268 i__2 = *n;
269 for (i__ = 1; i__ <= i__2; ++i__) {
270 i__3 = i__ + j * b_dim1;
271 rwork[i__] = (r__1 = b[i__3].r, dabs(r__1)) + (r__2 = r_imag(&b[
272 i__ + j * b_dim1]), dabs(r__2));
273 /* L20: */
274 }
275
276 if (notran) {
277
278 /* Compute abs(A)*abs(X) + abs(B). */
279
280 if (upper) {
281 if (nounit) {
282 i__2 = *n;
283 for (k = 1; k <= i__2; ++k) {
284 i__3 = k + j * x_dim1;
285 xk = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&
286 x[k + j * x_dim1]), dabs(r__2));
287 /* Computing MAX */
288 i__3 = 1, i__4 = k - *kd;
289 i__5 = k;
290 for (i__ = max(i__3,i__4); i__ <= i__5; ++i__) {
291 i__3 = *kd + 1 + i__ - k + k * ab_dim1;
292 rwork[i__] += ((r__1 = ab[i__3].r, dabs(r__1)) + (
293 r__2 = r_imag(&ab[*kd + 1 + i__ - k + k *
294 ab_dim1]), dabs(r__2))) * xk;
295 /* L30: */
296 }
297 /* L40: */
298 }
299 } else {
300 i__2 = *n;
301 for (k = 1; k <= i__2; ++k) {
302 i__5 = k + j * x_dim1;
303 xk = (r__1 = x[i__5].r, dabs(r__1)) + (r__2 = r_imag(&
304 x[k + j * x_dim1]), dabs(r__2));
305 /* Computing MAX */
306 i__5 = 1, i__3 = k - *kd;
307 i__4 = k - 1;
308 for (i__ = max(i__5,i__3); i__ <= i__4; ++i__) {
309 i__5 = *kd + 1 + i__ - k + k * ab_dim1;
310 rwork[i__] += ((r__1 = ab[i__5].r, dabs(r__1)) + (
311 r__2 = r_imag(&ab[*kd + 1 + i__ - k + k *
312 ab_dim1]), dabs(r__2))) * xk;
313 /* L50: */
314 }
315 rwork[k] += xk;
316 /* L60: */
317 }
318 }
319 } else {
320 if (nounit) {
321 i__2 = *n;
322 for (k = 1; k <= i__2; ++k) {
323 i__4 = k + j * x_dim1;
324 xk = (r__1 = x[i__4].r, dabs(r__1)) + (r__2 = r_imag(&
325 x[k + j * x_dim1]), dabs(r__2));
326 /* Computing MIN */
327 i__5 = *n, i__3 = k + *kd;
328 i__4 = min(i__5,i__3);
329 for (i__ = k; i__ <= i__4; ++i__) {
330 i__5 = i__ + 1 - k + k * ab_dim1;
331 rwork[i__] += ((r__1 = ab[i__5].r, dabs(r__1)) + (
332 r__2 = r_imag(&ab[i__ + 1 - k + k *
333 ab_dim1]), dabs(r__2))) * xk;
334 /* L70: */
335 }
336 /* L80: */
337 }
338 } else {
339 i__2 = *n;
340 for (k = 1; k <= i__2; ++k) {
341 i__4 = k + j * x_dim1;
342 xk = (r__1 = x[i__4].r, dabs(r__1)) + (r__2 = r_imag(&
343 x[k + j * x_dim1]), dabs(r__2));
344 /* Computing MIN */
345 i__5 = *n, i__3 = k + *kd;
346 i__4 = min(i__5,i__3);
347 for (i__ = k + 1; i__ <= i__4; ++i__) {
348 i__5 = i__ + 1 - k + k * ab_dim1;
349 rwork[i__] += ((r__1 = ab[i__5].r, dabs(r__1)) + (
350 r__2 = r_imag(&ab[i__ + 1 - k + k *
351 ab_dim1]), dabs(r__2))) * xk;
352 /* L90: */
353 }
354 rwork[k] += xk;
355 /* L100: */
356 }
357 }
358 }
359 } else {
360
361 /* Compute abs(A**H)*abs(X) + abs(B). */
362
363 if (upper) {
364 if (nounit) {
365 i__2 = *n;
366 for (k = 1; k <= i__2; ++k) {
367 s = 0.f;
368 /* Computing MAX */
369 i__4 = 1, i__5 = k - *kd;
370 i__3 = k;
371 for (i__ = max(i__4,i__5); i__ <= i__3; ++i__) {
372 i__4 = *kd + 1 + i__ - k + k * ab_dim1;
373 i__5 = i__ + j * x_dim1;
374 s += ((r__1 = ab[i__4].r, dabs(r__1)) + (r__2 =
375 r_imag(&ab[*kd + 1 + i__ - k + k *
376 ab_dim1]), dabs(r__2))) * ((r__3 = x[i__5]
377 .r, dabs(r__3)) + (r__4 = r_imag(&x[i__ +
378 j * x_dim1]), dabs(r__4)));
379 /* L110: */
380 }
381 rwork[k] += s;
382 /* L120: */
383 }
384 } else {
385 i__2 = *n;
386 for (k = 1; k <= i__2; ++k) {
387 i__3 = k + j * x_dim1;
388 s = (r__1 = x[i__3].r, dabs(r__1)) + (r__2 = r_imag(&
389 x[k + j * x_dim1]), dabs(r__2));
390 /* Computing MAX */
391 i__3 = 1, i__4 = k - *kd;
392 i__5 = k - 1;
393 for (i__ = max(i__3,i__4); i__ <= i__5; ++i__) {
394 i__3 = *kd + 1 + i__ - k + k * ab_dim1;
395 i__4 = i__ + j * x_dim1;
396 s += ((r__1 = ab[i__3].r, dabs(r__1)) + (r__2 =
397 r_imag(&ab[*kd + 1 + i__ - k + k *
398 ab_dim1]), dabs(r__2))) * ((r__3 = x[i__4]
399 .r, dabs(r__3)) + (r__4 = r_imag(&x[i__ +
400 j * x_dim1]), dabs(r__4)));
401 /* L130: */
402 }
403 rwork[k] += s;
404 /* L140: */
405 }
406 }
407 } else {
408 if (nounit) {
409 i__2 = *n;
410 for (k = 1; k <= i__2; ++k) {
411 s = 0.f;
412 /* Computing MIN */
413 i__3 = *n, i__4 = k + *kd;
414 i__5 = min(i__3,i__4);
415 for (i__ = k; i__ <= i__5; ++i__) {
416 i__3 = i__ + 1 - k + k * ab_dim1;
417 i__4 = i__ + j * x_dim1;
418 s += ((r__1 = ab[i__3].r, dabs(r__1)) + (r__2 =
419 r_imag(&ab[i__ + 1 - k + k * ab_dim1]),
420 dabs(r__2))) * ((r__3 = x[i__4].r, dabs(
421 r__3)) + (r__4 = r_imag(&x[i__ + j *
422 x_dim1]), dabs(r__4)));
423 /* L150: */
424 }
425 rwork[k] += s;
426 /* L160: */
427 }
428 } else {
429 i__2 = *n;
430 for (k = 1; k <= i__2; ++k) {
431 i__5 = k + j * x_dim1;
432 s = (r__1 = x[i__5].r, dabs(r__1)) + (r__2 = r_imag(&
433 x[k + j * x_dim1]), dabs(r__2));
434 /* Computing MIN */
435 i__3 = *n, i__4 = k + *kd;
436 i__5 = min(i__3,i__4);
437 for (i__ = k + 1; i__ <= i__5; ++i__) {
438 i__3 = i__ + 1 - k + k * ab_dim1;
439 i__4 = i__ + j * x_dim1;
440 s += ((r__1 = ab[i__3].r, dabs(r__1)) + (r__2 =
441 r_imag(&ab[i__ + 1 - k + k * ab_dim1]),
442 dabs(r__2))) * ((r__3 = x[i__4].r, dabs(
443 r__3)) + (r__4 = r_imag(&x[i__ + j *
444 x_dim1]), dabs(r__4)));
445 /* L170: */
446 }
447 rwork[k] += s;
448 /* L180: */
449 }
450 }
451 }
452 }
453 s = 0.f;
454 i__2 = *n;
455 for (i__ = 1; i__ <= i__2; ++i__) {
456 if (rwork[i__] > safe2) {
457 /* Computing MAX */
458 i__5 = i__;
459 r__3 = s, r__4 = ((r__1 = work[i__5].r, dabs(r__1)) + (r__2 =
460 r_imag(&work[i__]), dabs(r__2))) / rwork[i__];
461 s = dmax(r__3,r__4);
462 } else {
463 /* Computing MAX */
464 i__5 = i__;
465 r__3 = s, r__4 = ((r__1 = work[i__5].r, dabs(r__1)) + (r__2 =
466 r_imag(&work[i__]), dabs(r__2)) + safe1) / (rwork[i__]
467 + safe1);
468 s = dmax(r__3,r__4);
469 }
470 /* L190: */
471 }
472 berr[j] = s;
473
474 /* Bound error from formula */
475
476 /* norm(X - XTRUE) / norm(X) .le. FERR = */
477 /* norm( abs(inv(op(A)))* */
478 /* ( abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) / norm(X) */
479
480 /* where */
481 /* norm(Z) is the magnitude of the largest component of Z */
482 /* inv(op(A)) is the inverse of op(A) */
483 /* abs(Z) is the componentwise absolute value of the matrix or */
484 /* vector Z */
485 /* NZ is the maximum number of nonzeros in any row of A, plus 1 */
486 /* EPS is machine epsilon */
487
488 /* The i-th component of abs(R)+NZ*EPS*(abs(op(A))*abs(X)+abs(B)) */
489 /* is incremented by SAFE1 if the i-th component of */
490 /* abs(op(A))*abs(X) + abs(B) is less than SAFE2. */
491
492 /* Use CLACON to estimate the infinity-norm of the matrix */
493 /* inv(op(A)) * diag(W), */
494 /* where W = abs(R) + NZ*EPS*( abs(op(A))*abs(X)+abs(B) ))) */
495
496 i__2 = *n;
497 for (i__ = 1; i__ <= i__2; ++i__) {
498 if (rwork[i__] > safe2) {
499 i__5 = i__;
500 rwork[i__] = (r__1 = work[i__5].r, dabs(r__1)) + (r__2 =
501 r_imag(&work[i__]), dabs(r__2)) + nz * eps * rwork[
502 i__];
503 } else {
504 i__5 = i__;
505 rwork[i__] = (r__1 = work[i__5].r, dabs(r__1)) + (r__2 =
506 r_imag(&work[i__]), dabs(r__2)) + nz * eps * rwork[
507 i__] + safe1;
508 }
509 /* L200: */
510 }
511
512 kase = 0;
513 L210:
514 clacon_(n, &work[*n + 1], &work[1], &ferr[j], &kase);
515 if (kase != 0) {
516 if (kase == 1) {
517
518 /* Multiply by diag(W)*inv(op(A)**H). */
519
520 ctbsv_(uplo, transt, diag, n, kd, &ab[ab_offset], ldab, &work[
521 1], &c__1, (ftnlen)1, (ftnlen)1, (ftnlen)1);
522 i__2 = *n;
523 for (i__ = 1; i__ <= i__2; ++i__) {
524 i__5 = i__;
525 i__3 = i__;
526 i__4 = i__;
527 q__1.r = rwork[i__3] * work[i__4].r, q__1.i = rwork[i__3]
528 * work[i__4].i;
529 work[i__5].r = q__1.r, work[i__5].i = q__1.i;
530 /* L220: */
531 }
532 } else {
533
534 /* Multiply by inv(op(A))*diag(W). */
535
536 i__2 = *n;
537 for (i__ = 1; i__ <= i__2; ++i__) {
538 i__5 = i__;
539 i__3 = i__;
540 i__4 = i__;
541 q__1.r = rwork[i__3] * work[i__4].r, q__1.i = rwork[i__3]
542 * work[i__4].i;
543 work[i__5].r = q__1.r, work[i__5].i = q__1.i;
544 /* L230: */
545 }
546 ctbsv_(uplo, transn, diag, n, kd, &ab[ab_offset], ldab, &work[
547 1], &c__1, (ftnlen)1, (ftnlen)1, (ftnlen)1);
548 }
549 goto L210;
550 }
551
552 /* Normalize error. */
553
554 lstres = 0.f;
555 i__2 = *n;
556 for (i__ = 1; i__ <= i__2; ++i__) {
557 /* Computing MAX */
558 i__5 = i__ + j * x_dim1;
559 r__3 = lstres, r__4 = (r__1 = x[i__5].r, dabs(r__1)) + (r__2 =
560 r_imag(&x[i__ + j * x_dim1]), dabs(r__2));
561 lstres = dmax(r__3,r__4);
562 /* L240: */
563 }
564 if (lstres != 0.f) {
565 ferr[j] /= lstres;
566 }
567
568 /* L250: */
569 }
570
571 return 0;
572
573 /* End of CTBRFS */
574
575 } /* ctbrfs_ */
576
577