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


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:43