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