ctgsy2.c
Go to the documentation of this file.
00001 /* ctgsy2.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Table of constant values */
00017 
00018 static integer c__2 = 2;
00019 static integer c__1 = 1;
00020 
00021 /* Subroutine */ int ctgsy2_(char *trans, integer *ijob, integer *m, integer *
00022         n, complex *a, integer *lda, complex *b, integer *ldb, complex *c__, 
00023         integer *ldc, complex *d__, integer *ldd, complex *e, integer *lde, 
00024         complex *f, integer *ldf, real *scale, real *rdsum, real *rdscal, 
00025         integer *info)
00026 {
00027     /* System generated locals */
00028     integer a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset, d_dim1, 
00029             d_offset, e_dim1, e_offset, f_dim1, f_offset, i__1, i__2, i__3, 
00030             i__4;
00031     complex q__1, q__2, q__3, q__4, q__5, q__6;
00032 
00033     /* Builtin functions */
00034     void r_cnjg(complex *, complex *);
00035 
00036     /* Local variables */
00037     integer i__, j, k;
00038     complex z__[4]      /* was [2][2] */, rhs[2];
00039     integer ierr, ipiv[2], jpiv[2];
00040     complex alpha;
00041     extern /* Subroutine */ int cscal_(integer *, complex *, complex *, 
00042             integer *);
00043     extern logical lsame_(char *, char *);
00044     extern /* Subroutine */ int caxpy_(integer *, complex *, complex *, 
00045             integer *, complex *, integer *), cgesc2_(integer *, complex *, 
00046             integer *, complex *, integer *, integer *, real *), cgetc2_(
00047             integer *, complex *, integer *, integer *, integer *, integer *),
00048              clatdf_(integer *, integer *, complex *, integer *, complex *, 
00049             real *, real *, integer *, integer *);
00050     real scaloc;
00051     extern /* Subroutine */ int xerbla_(char *, integer *);
00052     logical notran;
00053 
00054 
00055 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00056 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00057 /*     November 2006 */
00058 
00059 /*     .. Scalar Arguments .. */
00060 /*     .. */
00061 /*     .. Array Arguments .. */
00062 /*     .. */
00063 
00064 /*  Purpose */
00065 /*  ======= */
00066 
00067 /*  CTGSY2 solves the generalized Sylvester equation */
00068 
00069 /*              A * R - L * B = scale *   C               (1) */
00070 /*              D * R - L * E = scale * F */
00071 
00072 /*  using Level 1 and 2 BLAS, where R and L are unknown M-by-N matrices, */
00073 /*  (A, D), (B, E) and (C, F) are given matrix pairs of size M-by-M, */
00074 /*  N-by-N and M-by-N, respectively. A, B, D and E are upper triangular */
00075 /*  (i.e., (A,D) and (B,E) in generalized Schur form). */
00076 
00077 /*  The solution (R, L) overwrites (C, F). 0 <= SCALE <= 1 is an output */
00078 /*  scaling factor chosen to avoid overflow. */
00079 
00080 /*  In matrix notation solving equation (1) corresponds to solve */
00081 /*  Zx = scale * b, where Z is defined as */
00082 
00083 /*         Z = [ kron(In, A)  -kron(B', Im) ]             (2) */
00084 /*             [ kron(In, D)  -kron(E', Im) ], */
00085 
00086 /*  Ik is the identity matrix of size k and X' is the transpose of X. */
00087 /*  kron(X, Y) is the Kronecker product between the matrices X and Y. */
00088 
00089 /*  If TRANS = 'C', y in the conjugate transposed system Z'y = scale*b */
00090 /*  is solved for, which is equivalent to solve for R and L in */
00091 
00092 /*              A' * R  + D' * L   = scale *  C           (3) */
00093 /*              R  * B' + L  * E'  = scale * -F */
00094 
00095 /*  This case is used to compute an estimate of Dif[(A, D), (B, E)] = */
00096 /*  = sigma_min(Z) using reverse communicaton with CLACON. */
00097 
00098 /*  CTGSY2 also (IJOB >= 1) contributes to the computation in CTGSYL */
00099 /*  of an upper bound on the separation between to matrix pairs. Then */
00100 /*  the input (A, D), (B, E) are sub-pencils of two matrix pairs in */
00101 /*  CTGSYL. */
00102 
00103 /*  Arguments */
00104 /*  ========= */
00105 
00106 /*  TRANS   (input) CHARACTER*1 */
00107 /*          = 'N', solve the generalized Sylvester equation (1). */
00108 /*          = 'T': solve the 'transposed' system (3). */
00109 
00110 /*  IJOB    (input) INTEGER */
00111 /*          Specifies what kind of functionality to be performed. */
00112 /*          =0: solve (1) only. */
00113 /*          =1: A contribution from this subsystem to a Frobenius */
00114 /*              norm-based estimate of the separation between two matrix */
00115 /*              pairs is computed. (look ahead strategy is used). */
00116 /*          =2: A contribution from this subsystem to a Frobenius */
00117 /*              norm-based estimate of the separation between two matrix */
00118 /*              pairs is computed. (SGECON on sub-systems is used.) */
00119 /*          Not referenced if TRANS = 'T'. */
00120 
00121 /*  M       (input) INTEGER */
00122 /*          On entry, M specifies the order of A and D, and the row */
00123 /*          dimension of C, F, R and L. */
00124 
00125 /*  N       (input) INTEGER */
00126 /*          On entry, N specifies the order of B and E, and the column */
00127 /*          dimension of C, F, R and L. */
00128 
00129 /*  A       (input) COMPLEX array, dimension (LDA, M) */
00130 /*          On entry, A contains an upper triangular matrix. */
00131 
00132 /*  LDA     (input) INTEGER */
00133 /*          The leading dimension of the matrix A. LDA >= max(1, M). */
00134 
00135 /*  B       (input) COMPLEX array, dimension (LDB, N) */
00136 /*          On entry, B contains an upper triangular matrix. */
00137 
00138 /*  LDB     (input) INTEGER */
00139 /*          The leading dimension of the matrix B. LDB >= max(1, N). */
00140 
00141 /*  C       (input/output) COMPLEX array, dimension (LDC, N) */
00142 /*          On entry, C contains the right-hand-side of the first matrix */
00143 /*          equation in (1). */
00144 /*          On exit, if IJOB = 0, C has been overwritten by the solution */
00145 /*          R. */
00146 
00147 /*  LDC     (input) INTEGER */
00148 /*          The leading dimension of the matrix C. LDC >= max(1, M). */
00149 
00150 /*  D       (input) COMPLEX array, dimension (LDD, M) */
00151 /*          On entry, D contains an upper triangular matrix. */
00152 
00153 /*  LDD     (input) INTEGER */
00154 /*          The leading dimension of the matrix D. LDD >= max(1, M). */
00155 
00156 /*  E       (input) COMPLEX array, dimension (LDE, N) */
00157 /*          On entry, E contains an upper triangular matrix. */
00158 
00159 /*  LDE     (input) INTEGER */
00160 /*          The leading dimension of the matrix E. LDE >= max(1, N). */
00161 
00162 /*  F       (input/output) COMPLEX array, dimension (LDF, N) */
00163 /*          On entry, F contains the right-hand-side of the second matrix */
00164 /*          equation in (1). */
00165 /*          On exit, if IJOB = 0, F has been overwritten by the solution */
00166 /*          L. */
00167 
00168 /*  LDF     (input) INTEGER */
00169 /*          The leading dimension of the matrix F. LDF >= max(1, M). */
00170 
00171 /*  SCALE   (output) REAL */
00172 /*          On exit, 0 <= SCALE <= 1. If 0 < SCALE < 1, the solutions */
00173 /*          R and L (C and F on entry) will hold the solutions to a */
00174 /*          slightly perturbed system but the input matrices A, B, D and */
00175 /*          E have not been changed. If SCALE = 0, R and L will hold the */
00176 /*          solutions to the homogeneous system with C = F = 0. */
00177 /*          Normally, SCALE = 1. */
00178 
00179 /*  RDSUM   (input/output) REAL */
00180 /*          On entry, the sum of squares of computed contributions to */
00181 /*          the Dif-estimate under computation by CTGSYL, where the */
00182 /*          scaling factor RDSCAL (see below) has been factored out. */
00183 /*          On exit, the corresponding sum of squares updated with the */
00184 /*          contributions from the current sub-system. */
00185 /*          If TRANS = 'T' RDSUM is not touched. */
00186 /*          NOTE: RDSUM only makes sense when CTGSY2 is called by */
00187 /*          CTGSYL. */
00188 
00189 /*  RDSCAL  (input/output) REAL */
00190 /*          On entry, scaling factor used to prevent overflow in RDSUM. */
00191 /*          On exit, RDSCAL is updated w.r.t. the current contributions */
00192 /*          in RDSUM. */
00193 /*          If TRANS = 'T', RDSCAL is not touched. */
00194 /*          NOTE: RDSCAL only makes sense when CTGSY2 is called by */
00195 /*          CTGSYL. */
00196 
00197 /*  INFO    (output) INTEGER */
00198 /*          On exit, if INFO is set to */
00199 /*            =0: Successful exit */
00200 /*            <0: If INFO = -i, input argument number i is illegal. */
00201 /*            >0: The matrix pairs (A, D) and (B, E) have common or very */
00202 /*                close eigenvalues. */
00203 
00204 /*  Further Details */
00205 /*  =============== */
00206 
00207 /*  Based on contributions by */
00208 /*     Bo Kagstrom and Peter Poromaa, Department of Computing Science, */
00209 /*     Umea University, S-901 87 Umea, Sweden. */
00210 
00211 /*  ===================================================================== */
00212 
00213 /*     .. Parameters .. */
00214 /*     .. */
00215 /*     .. Local Scalars .. */
00216 /*     .. */
00217 /*     .. Local Arrays .. */
00218 /*     .. */
00219 /*     .. External Functions .. */
00220 /*     .. */
00221 /*     .. External Subroutines .. */
00222 /*     .. */
00223 /*     .. Intrinsic Functions .. */
00224 /*     .. */
00225 /*     .. Executable Statements .. */
00226 
00227 /*     Decode and test input parameters */
00228 
00229     /* Parameter adjustments */
00230     a_dim1 = *lda;
00231     a_offset = 1 + a_dim1;
00232     a -= a_offset;
00233     b_dim1 = *ldb;
00234     b_offset = 1 + b_dim1;
00235     b -= b_offset;
00236     c_dim1 = *ldc;
00237     c_offset = 1 + c_dim1;
00238     c__ -= c_offset;
00239     d_dim1 = *ldd;
00240     d_offset = 1 + d_dim1;
00241     d__ -= d_offset;
00242     e_dim1 = *lde;
00243     e_offset = 1 + e_dim1;
00244     e -= e_offset;
00245     f_dim1 = *ldf;
00246     f_offset = 1 + f_dim1;
00247     f -= f_offset;
00248 
00249     /* Function Body */
00250     *info = 0;
00251     ierr = 0;
00252     notran = lsame_(trans, "N");
00253     if (! notran && ! lsame_(trans, "C")) {
00254         *info = -1;
00255     } else if (notran) {
00256         if (*ijob < 0 || *ijob > 2) {
00257             *info = -2;
00258         }
00259     }
00260     if (*info == 0) {
00261         if (*m <= 0) {
00262             *info = -3;
00263         } else if (*n <= 0) {
00264             *info = -4;
00265         } else if (*lda < max(1,*m)) {
00266             *info = -5;
00267         } else if (*ldb < max(1,*n)) {
00268             *info = -8;
00269         } else if (*ldc < max(1,*m)) {
00270             *info = -10;
00271         } else if (*ldd < max(1,*m)) {
00272             *info = -12;
00273         } else if (*lde < max(1,*n)) {
00274             *info = -14;
00275         } else if (*ldf < max(1,*m)) {
00276             *info = -16;
00277         }
00278     }
00279     if (*info != 0) {
00280         i__1 = -(*info);
00281         xerbla_("CTGSY2", &i__1);
00282         return 0;
00283     }
00284 
00285     if (notran) {
00286 
00287 /*        Solve (I, J) - system */
00288 /*           A(I, I) * R(I, J) - L(I, J) * B(J, J) = C(I, J) */
00289 /*           D(I, I) * R(I, J) - L(I, J) * E(J, J) = F(I, J) */
00290 /*        for I = M, M - 1, ..., 1; J = 1, 2, ..., N */
00291 
00292         *scale = 1.f;
00293         scaloc = 1.f;
00294         i__1 = *n;
00295         for (j = 1; j <= i__1; ++j) {
00296             for (i__ = *m; i__ >= 1; --i__) {
00297 
00298 /*              Build 2 by 2 system */
00299 
00300                 i__2 = i__ + i__ * a_dim1;
00301                 z__[0].r = a[i__2].r, z__[0].i = a[i__2].i;
00302                 i__2 = i__ + i__ * d_dim1;
00303                 z__[1].r = d__[i__2].r, z__[1].i = d__[i__2].i;
00304                 i__2 = j + j * b_dim1;
00305                 q__1.r = -b[i__2].r, q__1.i = -b[i__2].i;
00306                 z__[2].r = q__1.r, z__[2].i = q__1.i;
00307                 i__2 = j + j * e_dim1;
00308                 q__1.r = -e[i__2].r, q__1.i = -e[i__2].i;
00309                 z__[3].r = q__1.r, z__[3].i = q__1.i;
00310 
00311 /*              Set up right hand side(s) */
00312 
00313                 i__2 = i__ + j * c_dim1;
00314                 rhs[0].r = c__[i__2].r, rhs[0].i = c__[i__2].i;
00315                 i__2 = i__ + j * f_dim1;
00316                 rhs[1].r = f[i__2].r, rhs[1].i = f[i__2].i;
00317 
00318 /*              Solve Z * x = RHS */
00319 
00320                 cgetc2_(&c__2, z__, &c__2, ipiv, jpiv, &ierr);
00321                 if (ierr > 0) {
00322                     *info = ierr;
00323                 }
00324                 if (*ijob == 0) {
00325                     cgesc2_(&c__2, z__, &c__2, rhs, ipiv, jpiv, &scaloc);
00326                     if (scaloc != 1.f) {
00327                         i__2 = *n;
00328                         for (k = 1; k <= i__2; ++k) {
00329                             q__1.r = scaloc, q__1.i = 0.f;
00330                             cscal_(m, &q__1, &c__[k * c_dim1 + 1], &c__1);
00331                             q__1.r = scaloc, q__1.i = 0.f;
00332                             cscal_(m, &q__1, &f[k * f_dim1 + 1], &c__1);
00333 /* L10: */
00334                         }
00335                         *scale *= scaloc;
00336                     }
00337                 } else {
00338                     clatdf_(ijob, &c__2, z__, &c__2, rhs, rdsum, rdscal, ipiv, 
00339                              jpiv);
00340                 }
00341 
00342 /*              Unpack solution vector(s) */
00343 
00344                 i__2 = i__ + j * c_dim1;
00345                 c__[i__2].r = rhs[0].r, c__[i__2].i = rhs[0].i;
00346                 i__2 = i__ + j * f_dim1;
00347                 f[i__2].r = rhs[1].r, f[i__2].i = rhs[1].i;
00348 
00349 /*              Substitute R(I, J) and L(I, J) into remaining equation. */
00350 
00351                 if (i__ > 1) {
00352                     q__1.r = -rhs[0].r, q__1.i = -rhs[0].i;
00353                     alpha.r = q__1.r, alpha.i = q__1.i;
00354                     i__2 = i__ - 1;
00355                     caxpy_(&i__2, &alpha, &a[i__ * a_dim1 + 1], &c__1, &c__[j 
00356                             * c_dim1 + 1], &c__1);
00357                     i__2 = i__ - 1;
00358                     caxpy_(&i__2, &alpha, &d__[i__ * d_dim1 + 1], &c__1, &f[j 
00359                             * f_dim1 + 1], &c__1);
00360                 }
00361                 if (j < *n) {
00362                     i__2 = *n - j;
00363                     caxpy_(&i__2, &rhs[1], &b[j + (j + 1) * b_dim1], ldb, &
00364                             c__[i__ + (j + 1) * c_dim1], ldc);
00365                     i__2 = *n - j;
00366                     caxpy_(&i__2, &rhs[1], &e[j + (j + 1) * e_dim1], lde, &f[
00367                             i__ + (j + 1) * f_dim1], ldf);
00368                 }
00369 
00370 /* L20: */
00371             }
00372 /* L30: */
00373         }
00374     } else {
00375 
00376 /*        Solve transposed (I, J) - system: */
00377 /*           A(I, I)' * R(I, J) + D(I, I)' * L(J, J) = C(I, J) */
00378 /*           R(I, I) * B(J, J) + L(I, J) * E(J, J)   = -F(I, J) */
00379 /*        for I = 1, 2, ..., M, J = N, N - 1, ..., 1 */
00380 
00381         *scale = 1.f;
00382         scaloc = 1.f;
00383         i__1 = *m;
00384         for (i__ = 1; i__ <= i__1; ++i__) {
00385             for (j = *n; j >= 1; --j) {
00386 
00387 /*              Build 2 by 2 system Z' */
00388 
00389                 r_cnjg(&q__1, &a[i__ + i__ * a_dim1]);
00390                 z__[0].r = q__1.r, z__[0].i = q__1.i;
00391                 r_cnjg(&q__2, &b[j + j * b_dim1]);
00392                 q__1.r = -q__2.r, q__1.i = -q__2.i;
00393                 z__[1].r = q__1.r, z__[1].i = q__1.i;
00394                 r_cnjg(&q__1, &d__[i__ + i__ * d_dim1]);
00395                 z__[2].r = q__1.r, z__[2].i = q__1.i;
00396                 r_cnjg(&q__2, &e[j + j * e_dim1]);
00397                 q__1.r = -q__2.r, q__1.i = -q__2.i;
00398                 z__[3].r = q__1.r, z__[3].i = q__1.i;
00399 
00400 
00401 /*              Set up right hand side(s) */
00402 
00403                 i__2 = i__ + j * c_dim1;
00404                 rhs[0].r = c__[i__2].r, rhs[0].i = c__[i__2].i;
00405                 i__2 = i__ + j * f_dim1;
00406                 rhs[1].r = f[i__2].r, rhs[1].i = f[i__2].i;
00407 
00408 /*              Solve Z' * x = RHS */
00409 
00410                 cgetc2_(&c__2, z__, &c__2, ipiv, jpiv, &ierr);
00411                 if (ierr > 0) {
00412                     *info = ierr;
00413                 }
00414                 cgesc2_(&c__2, z__, &c__2, rhs, ipiv, jpiv, &scaloc);
00415                 if (scaloc != 1.f) {
00416                     i__2 = *n;
00417                     for (k = 1; k <= i__2; ++k) {
00418                         q__1.r = scaloc, q__1.i = 0.f;
00419                         cscal_(m, &q__1, &c__[k * c_dim1 + 1], &c__1);
00420                         q__1.r = scaloc, q__1.i = 0.f;
00421                         cscal_(m, &q__1, &f[k * f_dim1 + 1], &c__1);
00422 /* L40: */
00423                     }
00424                     *scale *= scaloc;
00425                 }
00426 
00427 /*              Unpack solution vector(s) */
00428 
00429                 i__2 = i__ + j * c_dim1;
00430                 c__[i__2].r = rhs[0].r, c__[i__2].i = rhs[0].i;
00431                 i__2 = i__ + j * f_dim1;
00432                 f[i__2].r = rhs[1].r, f[i__2].i = rhs[1].i;
00433 
00434 /*              Substitute R(I, J) and L(I, J) into remaining equation. */
00435 
00436                 i__2 = j - 1;
00437                 for (k = 1; k <= i__2; ++k) {
00438                     i__3 = i__ + k * f_dim1;
00439                     i__4 = i__ + k * f_dim1;
00440                     r_cnjg(&q__4, &b[k + j * b_dim1]);
00441                     q__3.r = rhs[0].r * q__4.r - rhs[0].i * q__4.i, q__3.i = 
00442                             rhs[0].r * q__4.i + rhs[0].i * q__4.r;
00443                     q__2.r = f[i__4].r + q__3.r, q__2.i = f[i__4].i + q__3.i;
00444                     r_cnjg(&q__6, &e[k + j * e_dim1]);
00445                     q__5.r = rhs[1].r * q__6.r - rhs[1].i * q__6.i, q__5.i = 
00446                             rhs[1].r * q__6.i + rhs[1].i * q__6.r;
00447                     q__1.r = q__2.r + q__5.r, q__1.i = q__2.i + q__5.i;
00448                     f[i__3].r = q__1.r, f[i__3].i = q__1.i;
00449 /* L50: */
00450                 }
00451                 i__2 = *m;
00452                 for (k = i__ + 1; k <= i__2; ++k) {
00453                     i__3 = k + j * c_dim1;
00454                     i__4 = k + j * c_dim1;
00455                     r_cnjg(&q__4, &a[i__ + k * a_dim1]);
00456                     q__3.r = q__4.r * rhs[0].r - q__4.i * rhs[0].i, q__3.i = 
00457                             q__4.r * rhs[0].i + q__4.i * rhs[0].r;
00458                     q__2.r = c__[i__4].r - q__3.r, q__2.i = c__[i__4].i - 
00459                             q__3.i;
00460                     r_cnjg(&q__6, &d__[i__ + k * d_dim1]);
00461                     q__5.r = q__6.r * rhs[1].r - q__6.i * rhs[1].i, q__5.i = 
00462                             q__6.r * rhs[1].i + q__6.i * rhs[1].r;
00463                     q__1.r = q__2.r - q__5.r, q__1.i = q__2.i - q__5.i;
00464                     c__[i__3].r = q__1.r, c__[i__3].i = q__1.i;
00465 /* L60: */
00466                 }
00467 
00468 /* L70: */
00469             }
00470 /* L80: */
00471         }
00472     }
00473     return 0;
00474 
00475 /*     End of CTGSY2 */
00476 
00477 } /* ctgsy2_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:34