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 ctrsyl_(char *trana, char *tranb, integer *isgn, integer
00021 *m, integer *n, complex *a, integer *lda, complex *b, integer *ldb,
00022 complex *c__, integer *ldc, real *scale, integer *info)
00023 {
00024
00025 integer a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset, i__1, i__2,
00026 i__3, i__4;
00027 real r__1, r__2;
00028 complex q__1, q__2, q__3, q__4;
00029
00030
00031 double r_imag(complex *);
00032 void r_cnjg(complex *, complex *);
00033
00034
00035 integer j, k, l;
00036 complex a11;
00037 real db;
00038 complex x11;
00039 real da11;
00040 complex vec;
00041 real dum[1], eps, sgn, smin;
00042 complex suml, sumr;
00043 extern VOID cdotc_(complex *, integer *, complex *, integer
00044 *, complex *, integer *);
00045 extern logical lsame_(char *, char *);
00046 extern VOID cdotu_(complex *, integer *, complex *, integer
00047 *, complex *, integer *);
00048 extern int slabad_(real *, real *);
00049 extern doublereal clange_(char *, integer *, integer *, complex *,
00050 integer *, real *);
00051 extern VOID cladiv_(complex *, complex *, complex *);
00052 real scaloc;
00053 extern doublereal slamch_(char *);
00054 extern int csscal_(integer *, real *, complex *, integer
00055 *), xerbla_(char *, integer *);
00056 real bignum;
00057 logical notrna, notrnb;
00058 real smlnum;
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 a_dim1 = *lda;
00159 a_offset = 1 + a_dim1;
00160 a -= a_offset;
00161 b_dim1 = *ldb;
00162 b_offset = 1 + b_dim1;
00163 b -= b_offset;
00164 c_dim1 = *ldc;
00165 c_offset = 1 + c_dim1;
00166 c__ -= c_offset;
00167
00168
00169 notrna = lsame_(trana, "N");
00170 notrnb = lsame_(tranb, "N");
00171
00172 *info = 0;
00173 if (! notrna && ! lsame_(trana, "C")) {
00174 *info = -1;
00175 } else if (! notrnb && ! lsame_(tranb, "C")) {
00176 *info = -2;
00177 } else if (*isgn != 1 && *isgn != -1) {
00178 *info = -3;
00179 } else if (*m < 0) {
00180 *info = -4;
00181 } else if (*n < 0) {
00182 *info = -5;
00183 } else if (*lda < max(1,*m)) {
00184 *info = -7;
00185 } else if (*ldb < max(1,*n)) {
00186 *info = -9;
00187 } else if (*ldc < max(1,*m)) {
00188 *info = -11;
00189 }
00190 if (*info != 0) {
00191 i__1 = -(*info);
00192 xerbla_("CTRSYL", &i__1);
00193 return 0;
00194 }
00195
00196
00197
00198 *scale = 1.f;
00199 if (*m == 0 || *n == 0) {
00200 return 0;
00201 }
00202
00203
00204
00205 eps = slamch_("P");
00206 smlnum = slamch_("S");
00207 bignum = 1.f / smlnum;
00208 slabad_(&smlnum, &bignum);
00209 smlnum = smlnum * (real) (*m * *n) / eps;
00210 bignum = 1.f / smlnum;
00211
00212 r__1 = smlnum, r__2 = eps * clange_("M", m, m, &a[a_offset], lda, dum), r__1 = max(r__1,r__2), r__2 = eps * clange_("M", n, n,
00213 &b[b_offset], ldb, dum);
00214 smin = dmax(r__1,r__2);
00215 sgn = (real) (*isgn);
00216
00217 if (notrna && notrnb) {
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231 i__1 = *n;
00232 for (l = 1; l <= i__1; ++l) {
00233 for (k = *m; k >= 1; --k) {
00234
00235 i__2 = *m - k;
00236
00237 i__3 = k + 1;
00238
00239 i__4 = k + 1;
00240 cdotu_(&q__1, &i__2, &a[k + min(i__3, *m)* a_dim1], lda, &c__[
00241 min(i__4, *m)+ l * c_dim1], &c__1);
00242 suml.r = q__1.r, suml.i = q__1.i;
00243 i__2 = l - 1;
00244 cdotu_(&q__1, &i__2, &c__[k + c_dim1], ldc, &b[l * b_dim1 + 1]
00245 , &c__1);
00246 sumr.r = q__1.r, sumr.i = q__1.i;
00247 i__2 = k + l * c_dim1;
00248 q__3.r = sgn * sumr.r, q__3.i = sgn * sumr.i;
00249 q__2.r = suml.r + q__3.r, q__2.i = suml.i + q__3.i;
00250 q__1.r = c__[i__2].r - q__2.r, q__1.i = c__[i__2].i - q__2.i;
00251 vec.r = q__1.r, vec.i = q__1.i;
00252
00253 scaloc = 1.f;
00254 i__2 = k + k * a_dim1;
00255 i__3 = l + l * b_dim1;
00256 q__2.r = sgn * b[i__3].r, q__2.i = sgn * b[i__3].i;
00257 q__1.r = a[i__2].r + q__2.r, q__1.i = a[i__2].i + q__2.i;
00258 a11.r = q__1.r, a11.i = q__1.i;
00259 da11 = (r__1 = a11.r, dabs(r__1)) + (r__2 = r_imag(&a11),
00260 dabs(r__2));
00261 if (da11 <= smin) {
00262 a11.r = smin, a11.i = 0.f;
00263 da11 = smin;
00264 *info = 1;
00265 }
00266 db = (r__1 = vec.r, dabs(r__1)) + (r__2 = r_imag(&vec), dabs(
00267 r__2));
00268 if (da11 < 1.f && db > 1.f) {
00269 if (db > bignum * da11) {
00270 scaloc = 1.f / db;
00271 }
00272 }
00273 q__3.r = scaloc, q__3.i = 0.f;
00274 q__2.r = vec.r * q__3.r - vec.i * q__3.i, q__2.i = vec.r *
00275 q__3.i + vec.i * q__3.r;
00276 cladiv_(&q__1, &q__2, &a11);
00277 x11.r = q__1.r, x11.i = q__1.i;
00278
00279 if (scaloc != 1.f) {
00280 i__2 = *n;
00281 for (j = 1; j <= i__2; ++j) {
00282 csscal_(m, &scaloc, &c__[j * c_dim1 + 1], &c__1);
00283
00284 }
00285 *scale *= scaloc;
00286 }
00287 i__2 = k + l * c_dim1;
00288 c__[i__2].r = x11.r, c__[i__2].i = x11.i;
00289
00290
00291 }
00292
00293 }
00294
00295 } else if (! notrna && notrnb) {
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309 i__1 = *n;
00310 for (l = 1; l <= i__1; ++l) {
00311 i__2 = *m;
00312 for (k = 1; k <= i__2; ++k) {
00313
00314 i__3 = k - 1;
00315 cdotc_(&q__1, &i__3, &a[k * a_dim1 + 1], &c__1, &c__[l *
00316 c_dim1 + 1], &c__1);
00317 suml.r = q__1.r, suml.i = q__1.i;
00318 i__3 = l - 1;
00319 cdotu_(&q__1, &i__3, &c__[k + c_dim1], ldc, &b[l * b_dim1 + 1]
00320 , &c__1);
00321 sumr.r = q__1.r, sumr.i = q__1.i;
00322 i__3 = k + l * c_dim1;
00323 q__3.r = sgn * sumr.r, q__3.i = sgn * sumr.i;
00324 q__2.r = suml.r + q__3.r, q__2.i = suml.i + q__3.i;
00325 q__1.r = c__[i__3].r - q__2.r, q__1.i = c__[i__3].i - q__2.i;
00326 vec.r = q__1.r, vec.i = q__1.i;
00327
00328 scaloc = 1.f;
00329 r_cnjg(&q__2, &a[k + k * a_dim1]);
00330 i__3 = l + l * b_dim1;
00331 q__3.r = sgn * b[i__3].r, q__3.i = sgn * b[i__3].i;
00332 q__1.r = q__2.r + q__3.r, q__1.i = q__2.i + q__3.i;
00333 a11.r = q__1.r, a11.i = q__1.i;
00334 da11 = (r__1 = a11.r, dabs(r__1)) + (r__2 = r_imag(&a11),
00335 dabs(r__2));
00336 if (da11 <= smin) {
00337 a11.r = smin, a11.i = 0.f;
00338 da11 = smin;
00339 *info = 1;
00340 }
00341 db = (r__1 = vec.r, dabs(r__1)) + (r__2 = r_imag(&vec), dabs(
00342 r__2));
00343 if (da11 < 1.f && db > 1.f) {
00344 if (db > bignum * da11) {
00345 scaloc = 1.f / db;
00346 }
00347 }
00348
00349 q__3.r = scaloc, q__3.i = 0.f;
00350 q__2.r = vec.r * q__3.r - vec.i * q__3.i, q__2.i = vec.r *
00351 q__3.i + vec.i * q__3.r;
00352 cladiv_(&q__1, &q__2, &a11);
00353 x11.r = q__1.r, x11.i = q__1.i;
00354
00355 if (scaloc != 1.f) {
00356 i__3 = *n;
00357 for (j = 1; j <= i__3; ++j) {
00358 csscal_(m, &scaloc, &c__[j * c_dim1 + 1], &c__1);
00359
00360 }
00361 *scale *= scaloc;
00362 }
00363 i__3 = k + l * c_dim1;
00364 c__[i__3].r = x11.r, c__[i__3].i = x11.i;
00365
00366
00367 }
00368
00369 }
00370
00371 } else if (! notrna && ! notrnb) {
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388 for (l = *n; l >= 1; --l) {
00389 i__1 = *m;
00390 for (k = 1; k <= i__1; ++k) {
00391
00392 i__2 = k - 1;
00393 cdotc_(&q__1, &i__2, &a[k * a_dim1 + 1], &c__1, &c__[l *
00394 c_dim1 + 1], &c__1);
00395 suml.r = q__1.r, suml.i = q__1.i;
00396 i__2 = *n - l;
00397
00398 i__3 = l + 1;
00399
00400 i__4 = l + 1;
00401 cdotc_(&q__1, &i__2, &c__[k + min(i__3, *n)* c_dim1], ldc, &b[
00402 l + min(i__4, *n)* b_dim1], ldb);
00403 sumr.r = q__1.r, sumr.i = q__1.i;
00404 i__2 = k + l * c_dim1;
00405 r_cnjg(&q__4, &sumr);
00406 q__3.r = sgn * q__4.r, q__3.i = sgn * q__4.i;
00407 q__2.r = suml.r + q__3.r, q__2.i = suml.i + q__3.i;
00408 q__1.r = c__[i__2].r - q__2.r, q__1.i = c__[i__2].i - q__2.i;
00409 vec.r = q__1.r, vec.i = q__1.i;
00410
00411 scaloc = 1.f;
00412 i__2 = k + k * a_dim1;
00413 i__3 = l + l * b_dim1;
00414 q__3.r = sgn * b[i__3].r, q__3.i = sgn * b[i__3].i;
00415 q__2.r = a[i__2].r + q__3.r, q__2.i = a[i__2].i + q__3.i;
00416 r_cnjg(&q__1, &q__2);
00417 a11.r = q__1.r, a11.i = q__1.i;
00418 da11 = (r__1 = a11.r, dabs(r__1)) + (r__2 = r_imag(&a11),
00419 dabs(r__2));
00420 if (da11 <= smin) {
00421 a11.r = smin, a11.i = 0.f;
00422 da11 = smin;
00423 *info = 1;
00424 }
00425 db = (r__1 = vec.r, dabs(r__1)) + (r__2 = r_imag(&vec), dabs(
00426 r__2));
00427 if (da11 < 1.f && db > 1.f) {
00428 if (db > bignum * da11) {
00429 scaloc = 1.f / db;
00430 }
00431 }
00432
00433 q__3.r = scaloc, q__3.i = 0.f;
00434 q__2.r = vec.r * q__3.r - vec.i * q__3.i, q__2.i = vec.r *
00435 q__3.i + vec.i * q__3.r;
00436 cladiv_(&q__1, &q__2, &a11);
00437 x11.r = q__1.r, x11.i = q__1.i;
00438
00439 if (scaloc != 1.f) {
00440 i__2 = *n;
00441 for (j = 1; j <= i__2; ++j) {
00442 csscal_(m, &scaloc, &c__[j * c_dim1 + 1], &c__1);
00443
00444 }
00445 *scale *= scaloc;
00446 }
00447 i__2 = k + l * c_dim1;
00448 c__[i__2].r = x11.r, c__[i__2].i = x11.i;
00449
00450
00451 }
00452
00453 }
00454
00455 } else if (notrna && ! notrnb) {
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469 for (l = *n; l >= 1; --l) {
00470 for (k = *m; k >= 1; --k) {
00471
00472 i__1 = *m - k;
00473
00474 i__2 = k + 1;
00475
00476 i__3 = k + 1;
00477 cdotu_(&q__1, &i__1, &a[k + min(i__2, *m)* a_dim1], lda, &c__[
00478 min(i__3, *m)+ l * c_dim1], &c__1);
00479 suml.r = q__1.r, suml.i = q__1.i;
00480 i__1 = *n - l;
00481
00482 i__2 = l + 1;
00483
00484 i__3 = l + 1;
00485 cdotc_(&q__1, &i__1, &c__[k + min(i__2, *n)* c_dim1], ldc, &b[
00486 l + min(i__3, *n)* b_dim1], ldb);
00487 sumr.r = q__1.r, sumr.i = q__1.i;
00488 i__1 = k + l * c_dim1;
00489 r_cnjg(&q__4, &sumr);
00490 q__3.r = sgn * q__4.r, q__3.i = sgn * q__4.i;
00491 q__2.r = suml.r + q__3.r, q__2.i = suml.i + q__3.i;
00492 q__1.r = c__[i__1].r - q__2.r, q__1.i = c__[i__1].i - q__2.i;
00493 vec.r = q__1.r, vec.i = q__1.i;
00494
00495 scaloc = 1.f;
00496 i__1 = k + k * a_dim1;
00497 r_cnjg(&q__3, &b[l + l * b_dim1]);
00498 q__2.r = sgn * q__3.r, q__2.i = sgn * q__3.i;
00499 q__1.r = a[i__1].r + q__2.r, q__1.i = a[i__1].i + q__2.i;
00500 a11.r = q__1.r, a11.i = q__1.i;
00501 da11 = (r__1 = a11.r, dabs(r__1)) + (r__2 = r_imag(&a11),
00502 dabs(r__2));
00503 if (da11 <= smin) {
00504 a11.r = smin, a11.i = 0.f;
00505 da11 = smin;
00506 *info = 1;
00507 }
00508 db = (r__1 = vec.r, dabs(r__1)) + (r__2 = r_imag(&vec), dabs(
00509 r__2));
00510 if (da11 < 1.f && db > 1.f) {
00511 if (db > bignum * da11) {
00512 scaloc = 1.f / db;
00513 }
00514 }
00515
00516 q__3.r = scaloc, q__3.i = 0.f;
00517 q__2.r = vec.r * q__3.r - vec.i * q__3.i, q__2.i = vec.r *
00518 q__3.i + vec.i * q__3.r;
00519 cladiv_(&q__1, &q__2, &a11);
00520 x11.r = q__1.r, x11.i = q__1.i;
00521
00522 if (scaloc != 1.f) {
00523 i__1 = *n;
00524 for (j = 1; j <= i__1; ++j) {
00525 csscal_(m, &scaloc, &c__[j * c_dim1 + 1], &c__1);
00526
00527 }
00528 *scale *= scaloc;
00529 }
00530 i__1 = k + l * c_dim1;
00531 c__[i__1].r = x11.r, c__[i__1].i = x11.i;
00532
00533
00534 }
00535
00536 }
00537
00538 }
00539
00540 return 0;
00541
00542
00543
00544 }