ctgex2.c
Go to the documentation of this file.
00001 /* ctgex2.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 ctgex2_(logical *wantq, logical *wantz, integer *n, 
00022         complex *a, integer *lda, complex *b, integer *ldb, complex *q, 
00023         integer *ldq, complex *z__, integer *ldz, integer *j1, integer *info)
00024 {
00025     /* System generated locals */
00026     integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, z_dim1, 
00027             z_offset, i__1, i__2, i__3;
00028     real r__1;
00029     complex q__1, q__2, q__3;
00030 
00031     /* Builtin functions */
00032     double sqrt(doublereal), c_abs(complex *);
00033     void r_cnjg(complex *, complex *);
00034 
00035     /* Local variables */
00036     complex f, g;
00037     integer i__, m;
00038     complex s[4]        /* was [2][2] */, t[4]  /* was [2][2] */;
00039     real cq, sa, sb, cz;
00040     complex sq;
00041     real ss, ws;
00042     complex sz;
00043     real eps, sum;
00044     logical weak;
00045     complex cdum;
00046     extern /* Subroutine */ int crot_(integer *, complex *, integer *, 
00047             complex *, integer *, real *, complex *);
00048     complex work[8];
00049     real scale;
00050     extern doublereal slamch_(char *);
00051     extern /* Subroutine */ int clacpy_(char *, integer *, integer *, complex 
00052             *, integer *, complex *, integer *), clartg_(complex *, 
00053             complex *, real *, complex *, complex *), classq_(integer *, 
00054             complex *, integer *, real *, real *);
00055     real thresh, smlnum;
00056     logical strong;
00057 
00058 
00059 /*  -- LAPACK auxiliary routine (version 3.2) -- */
00060 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00061 /*     November 2006 */
00062 
00063 /*     .. Scalar Arguments .. */
00064 /*     .. */
00065 /*     .. Array Arguments .. */
00066 /*     .. */
00067 
00068 /*  Purpose */
00069 /*  ======= */
00070 
00071 /*  CTGEX2 swaps adjacent diagonal 1 by 1 blocks (A11,B11) and (A22,B22) */
00072 /*  in an upper triangular matrix pair (A, B) by an unitary equivalence */
00073 /*  transformation. */
00074 
00075 /*  (A, B) must be in generalized Schur canonical form, that is, A and */
00076 /*  B are both upper triangular. */
00077 
00078 /*  Optionally, the matrices Q and Z of generalized Schur vectors are */
00079 /*  updated. */
00080 
00081 /*         Q(in) * A(in) * Z(in)' = Q(out) * A(out) * Z(out)' */
00082 /*         Q(in) * B(in) * Z(in)' = Q(out) * B(out) * Z(out)' */
00083 
00084 
00085 /*  Arguments */
00086 /*  ========= */
00087 
00088 /*  WANTQ   (input) LOGICAL */
00089 /*          .TRUE. : update the left transformation matrix Q; */
00090 /*          .FALSE.: do not update Q. */
00091 
00092 /*  WANTZ   (input) LOGICAL */
00093 /*          .TRUE. : update the right transformation matrix Z; */
00094 /*          .FALSE.: do not update Z. */
00095 
00096 /*  N       (input) INTEGER */
00097 /*          The order of the matrices A and B. N >= 0. */
00098 
00099 /*  A       (input/output) COMPLEX arrays, dimensions (LDA,N) */
00100 /*          On entry, the matrix A in the pair (A, B). */
00101 /*          On exit, the updated matrix A. */
00102 
00103 /*  LDA     (input)  INTEGER */
00104 /*          The leading dimension of the array A. LDA >= max(1,N). */
00105 
00106 /*  B       (input/output) COMPLEX arrays, dimensions (LDB,N) */
00107 /*          On entry, the matrix B in the pair (A, B). */
00108 /*          On exit, the updated matrix B. */
00109 
00110 /*  LDB     (input)  INTEGER */
00111 /*          The leading dimension of the array B. LDB >= max(1,N). */
00112 
00113 /*  Q       (input/output) COMPLEX array, dimension (LDZ,N) */
00114 /*          If WANTQ = .TRUE, on entry, the unitary matrix Q. On exit, */
00115 /*          the updated matrix Q. */
00116 /*          Not referenced if WANTQ = .FALSE.. */
00117 
00118 /*  LDQ     (input) INTEGER */
00119 /*          The leading dimension of the array Q. LDQ >= 1; */
00120 /*          If WANTQ = .TRUE., LDQ >= N. */
00121 
00122 /*  Z       (input/output) COMPLEX array, dimension (LDZ,N) */
00123 /*          If WANTZ = .TRUE, on entry, the unitary matrix Z. On exit, */
00124 /*          the updated matrix Z. */
00125 /*          Not referenced if WANTZ = .FALSE.. */
00126 
00127 /*  LDZ     (input) INTEGER */
00128 /*          The leading dimension of the array Z. LDZ >= 1; */
00129 /*          If WANTZ = .TRUE., LDZ >= N. */
00130 
00131 /*  J1      (input) INTEGER */
00132 /*          The index to the first block (A11, B11). */
00133 
00134 /*  INFO    (output) INTEGER */
00135 /*           =0:  Successful exit. */
00136 /*           =1:  The transformed matrix pair (A, B) would be too far */
00137 /*                from generalized Schur form; the problem is ill- */
00138 /*                conditioned. */
00139 
00140 
00141 /*  Further Details */
00142 /*  =============== */
00143 
00144 /*  Based on contributions by */
00145 /*     Bo Kagstrom and Peter Poromaa, Department of Computing Science, */
00146 /*     Umea University, S-901 87 Umea, Sweden. */
00147 
00148 /*  In the current code both weak and strong stability tests are */
00149 /*  performed. The user can omit the strong stability test by changing */
00150 /*  the internal logical parameter WANDS to .FALSE.. See ref. [2] for */
00151 /*  details. */
00152 
00153 /*  [1] B. Kagstrom; A Direct Method for Reordering Eigenvalues in the */
00154 /*      Generalized Real Schur Form of a Regular Matrix Pair (A, B), in */
00155 /*      M.S. Moonen et al (eds), Linear Algebra for Large Scale and */
00156 /*      Real-Time Applications, Kluwer Academic Publ. 1993, pp 195-218. */
00157 
00158 /*  [2] B. Kagstrom and P. Poromaa; Computing Eigenspaces with Specified */
00159 /*      Eigenvalues of a Regular Matrix Pair (A, B) and Condition */
00160 /*      Estimation: Theory, Algorithms and Software, Report UMINF-94.04, */
00161 /*      Department of Computing Science, Umea University, S-901 87 Umea, */
00162 /*      Sweden, 1994. Also as LAPACK Working Note 87. To appear in */
00163 /*      Numerical Algorithms, 1996. */
00164 
00165 /*  ===================================================================== */
00166 
00167 /*     .. Parameters .. */
00168 /*     .. */
00169 /*     .. Local Scalars .. */
00170 /*     .. */
00171 /*     .. Local Arrays .. */
00172 /*     .. */
00173 /*     .. External Functions .. */
00174 /*     .. */
00175 /*     .. External Subroutines .. */
00176 /*     .. */
00177 /*     .. Intrinsic Functions .. */
00178 /*     .. */
00179 /*     .. Executable Statements .. */
00180 
00181     /* Parameter adjustments */
00182     a_dim1 = *lda;
00183     a_offset = 1 + a_dim1;
00184     a -= a_offset;
00185     b_dim1 = *ldb;
00186     b_offset = 1 + b_dim1;
00187     b -= b_offset;
00188     q_dim1 = *ldq;
00189     q_offset = 1 + q_dim1;
00190     q -= q_offset;
00191     z_dim1 = *ldz;
00192     z_offset = 1 + z_dim1;
00193     z__ -= z_offset;
00194 
00195     /* Function Body */
00196     *info = 0;
00197 
00198 /*     Quick return if possible */
00199 
00200     if (*n <= 1) {
00201         return 0;
00202     }
00203 
00204     m = 2;
00205     weak = FALSE_;
00206     strong = FALSE_;
00207 
00208 /*     Make a local copy of selected block in (A, B) */
00209 
00210     clacpy_("Full", &m, &m, &a[*j1 + *j1 * a_dim1], lda, s, &c__2);
00211     clacpy_("Full", &m, &m, &b[*j1 + *j1 * b_dim1], ldb, t, &c__2);
00212 
00213 /*     Compute the threshold for testing the acceptance of swapping. */
00214 
00215     eps = slamch_("P");
00216     smlnum = slamch_("S") / eps;
00217     scale = 0.f;
00218     sum = 1.f;
00219     clacpy_("Full", &m, &m, s, &c__2, work, &m);
00220     clacpy_("Full", &m, &m, t, &c__2, &work[m * m], &m);
00221     i__1 = (m << 1) * m;
00222     classq_(&i__1, work, &c__1, &scale, &sum);
00223     sa = scale * sqrt(sum);
00224 /* Computing MAX */
00225     r__1 = eps * 10.f * sa;
00226     thresh = dmax(r__1,smlnum);
00227 
00228 /*     Compute unitary QL and RQ that swap 1-by-1 and 1-by-1 blocks */
00229 /*     using Givens rotations and perform the swap tentatively. */
00230 
00231     q__2.r = s[3].r * t[0].r - s[3].i * t[0].i, q__2.i = s[3].r * t[0].i + s[
00232             3].i * t[0].r;
00233     q__3.r = t[3].r * s[0].r - t[3].i * s[0].i, q__3.i = t[3].r * s[0].i + t[
00234             3].i * s[0].r;
00235     q__1.r = q__2.r - q__3.r, q__1.i = q__2.i - q__3.i;
00236     f.r = q__1.r, f.i = q__1.i;
00237     q__2.r = s[3].r * t[2].r - s[3].i * t[2].i, q__2.i = s[3].r * t[2].i + s[
00238             3].i * t[2].r;
00239     q__3.r = t[3].r * s[2].r - t[3].i * s[2].i, q__3.i = t[3].r * s[2].i + t[
00240             3].i * s[2].r;
00241     q__1.r = q__2.r - q__3.r, q__1.i = q__2.i - q__3.i;
00242     g.r = q__1.r, g.i = q__1.i;
00243     sa = c_abs(&s[3]);
00244     sb = c_abs(&t[3]);
00245     clartg_(&g, &f, &cz, &sz, &cdum);
00246     q__1.r = -sz.r, q__1.i = -sz.i;
00247     sz.r = q__1.r, sz.i = q__1.i;
00248     r_cnjg(&q__1, &sz);
00249     crot_(&c__2, s, &c__1, &s[2], &c__1, &cz, &q__1);
00250     r_cnjg(&q__1, &sz);
00251     crot_(&c__2, t, &c__1, &t[2], &c__1, &cz, &q__1);
00252     if (sa >= sb) {
00253         clartg_(s, &s[1], &cq, &sq, &cdum);
00254     } else {
00255         clartg_(t, &t[1], &cq, &sq, &cdum);
00256     }
00257     crot_(&c__2, s, &c__2, &s[1], &c__2, &cq, &sq);
00258     crot_(&c__2, t, &c__2, &t[1], &c__2, &cq, &sq);
00259 
00260 /*     Weak stability test: |S21| + |T21| <= O(EPS F-norm((S, T))) */
00261 
00262     ws = c_abs(&s[1]) + c_abs(&t[1]);
00263     weak = ws <= thresh;
00264     if (! weak) {
00265         goto L20;
00266     }
00267 
00268     if (TRUE_) {
00269 
00270 /*        Strong stability test: */
00271 /*           F-norm((A-QL'*S*QR, B-QL'*T*QR)) <= O(EPS*F-norm((A, B))) */
00272 
00273         clacpy_("Full", &m, &m, s, &c__2, work, &m);
00274         clacpy_("Full", &m, &m, t, &c__2, &work[m * m], &m);
00275         r_cnjg(&q__2, &sz);
00276         q__1.r = -q__2.r, q__1.i = -q__2.i;
00277         crot_(&c__2, work, &c__1, &work[2], &c__1, &cz, &q__1);
00278         r_cnjg(&q__2, &sz);
00279         q__1.r = -q__2.r, q__1.i = -q__2.i;
00280         crot_(&c__2, &work[4], &c__1, &work[6], &c__1, &cz, &q__1);
00281         q__1.r = -sq.r, q__1.i = -sq.i;
00282         crot_(&c__2, work, &c__2, &work[1], &c__2, &cq, &q__1);
00283         q__1.r = -sq.r, q__1.i = -sq.i;
00284         crot_(&c__2, &work[4], &c__2, &work[5], &c__2, &cq, &q__1);
00285         for (i__ = 1; i__ <= 2; ++i__) {
00286             i__1 = i__ - 1;
00287             i__2 = i__ - 1;
00288             i__3 = *j1 + i__ - 1 + *j1 * a_dim1;
00289             q__1.r = work[i__2].r - a[i__3].r, q__1.i = work[i__2].i - a[i__3]
00290                     .i;
00291             work[i__1].r = q__1.r, work[i__1].i = q__1.i;
00292             i__1 = i__ + 1;
00293             i__2 = i__ + 1;
00294             i__3 = *j1 + i__ - 1 + (*j1 + 1) * a_dim1;
00295             q__1.r = work[i__2].r - a[i__3].r, q__1.i = work[i__2].i - a[i__3]
00296                     .i;
00297             work[i__1].r = q__1.r, work[i__1].i = q__1.i;
00298             i__1 = i__ + 3;
00299             i__2 = i__ + 3;
00300             i__3 = *j1 + i__ - 1 + *j1 * b_dim1;
00301             q__1.r = work[i__2].r - b[i__3].r, q__1.i = work[i__2].i - b[i__3]
00302                     .i;
00303             work[i__1].r = q__1.r, work[i__1].i = q__1.i;
00304             i__1 = i__ + 5;
00305             i__2 = i__ + 5;
00306             i__3 = *j1 + i__ - 1 + (*j1 + 1) * b_dim1;
00307             q__1.r = work[i__2].r - b[i__3].r, q__1.i = work[i__2].i - b[i__3]
00308                     .i;
00309             work[i__1].r = q__1.r, work[i__1].i = q__1.i;
00310 /* L10: */
00311         }
00312         scale = 0.f;
00313         sum = 1.f;
00314         i__1 = (m << 1) * m;
00315         classq_(&i__1, work, &c__1, &scale, &sum);
00316         ss = scale * sqrt(sum);
00317         strong = ss <= thresh;
00318         if (! strong) {
00319             goto L20;
00320         }
00321     }
00322 
00323 /*     If the swap is accepted ("weakly" and "strongly"), apply the */
00324 /*     equivalence transformations to the original matrix pair (A,B) */
00325 
00326     i__1 = *j1 + 1;
00327     r_cnjg(&q__1, &sz);
00328     crot_(&i__1, &a[*j1 * a_dim1 + 1], &c__1, &a[(*j1 + 1) * a_dim1 + 1], &
00329             c__1, &cz, &q__1);
00330     i__1 = *j1 + 1;
00331     r_cnjg(&q__1, &sz);
00332     crot_(&i__1, &b[*j1 * b_dim1 + 1], &c__1, &b[(*j1 + 1) * b_dim1 + 1], &
00333             c__1, &cz, &q__1);
00334     i__1 = *n - *j1 + 1;
00335     crot_(&i__1, &a[*j1 + *j1 * a_dim1], lda, &a[*j1 + 1 + *j1 * a_dim1], lda, 
00336              &cq, &sq);
00337     i__1 = *n - *j1 + 1;
00338     crot_(&i__1, &b[*j1 + *j1 * b_dim1], ldb, &b[*j1 + 1 + *j1 * b_dim1], ldb, 
00339              &cq, &sq);
00340 
00341 /*     Set  N1 by N2 (2,1) blocks to 0 */
00342 
00343     i__1 = *j1 + 1 + *j1 * a_dim1;
00344     a[i__1].r = 0.f, a[i__1].i = 0.f;
00345     i__1 = *j1 + 1 + *j1 * b_dim1;
00346     b[i__1].r = 0.f, b[i__1].i = 0.f;
00347 
00348 /*     Accumulate transformations into Q and Z if requested. */
00349 
00350     if (*wantz) {
00351         r_cnjg(&q__1, &sz);
00352         crot_(n, &z__[*j1 * z_dim1 + 1], &c__1, &z__[(*j1 + 1) * z_dim1 + 1], 
00353                 &c__1, &cz, &q__1);
00354     }
00355     if (*wantq) {
00356         r_cnjg(&q__1, &sq);
00357         crot_(n, &q[*j1 * q_dim1 + 1], &c__1, &q[(*j1 + 1) * q_dim1 + 1], &
00358                 c__1, &cq, &q__1);
00359     }
00360 
00361 /*     Exit with INFO = 0 if swap was successfully performed. */
00362 
00363     return 0;
00364 
00365 /*     Exit with INFO = 1 if swap was rejected. */
00366 
00367 L20:
00368     *info = 1;
00369     return 0;
00370 
00371 /*     End of CTGEX2 */
00372 
00373 } /* ctgex2_ */


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