dtgsen.c
Go to the documentation of this file.
00001 /* dtgsen.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__1 = 1;
00019 static integer c__2 = 2;
00020 static doublereal c_b28 = 1.;
00021 
00022 /* Subroutine */ int dtgsen_(integer *ijob, logical *wantq, logical *wantz, 
00023         logical *select, integer *n, doublereal *a, integer *lda, doublereal *
00024         b, integer *ldb, doublereal *alphar, doublereal *alphai, doublereal *
00025         beta, doublereal *q, integer *ldq, doublereal *z__, integer *ldz, 
00026         integer *m, doublereal *pl, doublereal *pr, doublereal *dif, 
00027         doublereal *work, integer *lwork, integer *iwork, integer *liwork, 
00028         integer *info)
00029 {
00030     /* System generated locals */
00031     integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, z_dim1, 
00032             z_offset, i__1, i__2;
00033     doublereal d__1;
00034 
00035     /* Builtin functions */
00036     double sqrt(doublereal), d_sign(doublereal *, doublereal *);
00037 
00038     /* Local variables */
00039     integer i__, k, n1, n2, kk, ks, mn2, ijb;
00040     doublereal eps;
00041     integer kase;
00042     logical pair;
00043     integer ierr;
00044     doublereal dsum;
00045     logical swap;
00046     extern /* Subroutine */ int dlag2_(doublereal *, integer *, doublereal *, 
00047             integer *, doublereal *, doublereal *, doublereal *, doublereal *, 
00048              doublereal *, doublereal *);
00049     integer isave[3];
00050     logical wantd;
00051     integer lwmin;
00052     logical wantp;
00053     extern /* Subroutine */ int dlacn2_(integer *, doublereal *, doublereal *, 
00054              integer *, doublereal *, integer *, integer *);
00055     logical wantd1, wantd2;
00056     extern doublereal dlamch_(char *);
00057     doublereal dscale, rdscal;
00058     extern /* Subroutine */ int dlacpy_(char *, integer *, integer *, 
00059             doublereal *, integer *, doublereal *, integer *), 
00060             xerbla_(char *, integer *), dtgexc_(logical *, logical *, 
00061             integer *, doublereal *, integer *, doublereal *, integer *, 
00062             doublereal *, integer *, doublereal *, integer *, integer *, 
00063             integer *, doublereal *, integer *, integer *), dlassq_(integer *, 
00064              doublereal *, integer *, doublereal *, doublereal *);
00065     integer liwmin;
00066     extern /* Subroutine */ int dtgsyl_(char *, integer *, integer *, integer 
00067             *, doublereal *, integer *, doublereal *, integer *, doublereal *, 
00068              integer *, doublereal *, integer *, doublereal *, integer *, 
00069             doublereal *, integer *, doublereal *, doublereal *, doublereal *, 
00070              integer *, integer *, integer *);
00071     doublereal smlnum;
00072     logical lquery;
00073 
00074 
00075 /*  -- LAPACK routine (version 3.2) -- */
00076 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
00077 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
00078 /*     January 2007 */
00079 
00080 /*     Modified to call DLACN2 in place of DLACON, 5 Feb 03, SJH. */
00081 
00082 /*     .. Scalar Arguments .. */
00083 /*     .. */
00084 /*     .. Array Arguments .. */
00085 /*     .. */
00086 
00087 /*  Purpose */
00088 /*  ======= */
00089 
00090 /*  DTGSEN reorders the generalized real Schur decomposition of a real */
00091 /*  matrix pair (A, B) (in terms of an orthonormal equivalence trans- */
00092 /*  formation Q' * (A, B) * Z), so that a selected cluster of eigenvalues */
00093 /*  appears in the leading diagonal blocks of the upper quasi-triangular */
00094 /*  matrix A and the upper triangular B. The leading columns of Q and */
00095 /*  Z form orthonormal bases of the corresponding left and right eigen- */
00096 /*  spaces (deflating subspaces). (A, B) must be in generalized real */
00097 /*  Schur canonical form (as returned by DGGES), i.e. A is block upper */
00098 /*  triangular with 1-by-1 and 2-by-2 diagonal blocks. B is upper */
00099 /*  triangular. */
00100 
00101 /*  DTGSEN also computes the generalized eigenvalues */
00102 
00103 /*              w(j) = (ALPHAR(j) + i*ALPHAI(j))/BETA(j) */
00104 
00105 /*  of the reordered matrix pair (A, B). */
00106 
00107 /*  Optionally, DTGSEN computes the estimates of reciprocal condition */
00108 /*  numbers for eigenvalues and eigenspaces. These are Difu[(A11,B11), */
00109 /*  (A22,B22)] and Difl[(A11,B11), (A22,B22)], i.e. the separation(s) */
00110 /*  between the matrix pairs (A11, B11) and (A22,B22) that correspond to */
00111 /*  the selected cluster and the eigenvalues outside the cluster, resp., */
00112 /*  and norms of "projections" onto left and right eigenspaces w.r.t. */
00113 /*  the selected cluster in the (1,1)-block. */
00114 
00115 /*  Arguments */
00116 /*  ========= */
00117 
00118 /*  IJOB    (input) INTEGER */
00119 /*          Specifies whether condition numbers are required for the */
00120 /*          cluster of eigenvalues (PL and PR) or the deflating subspaces */
00121 /*          (Difu and Difl): */
00122 /*           =0: Only reorder w.r.t. SELECT. No extras. */
00123 /*           =1: Reciprocal of norms of "projections" onto left and right */
00124 /*               eigenspaces w.r.t. the selected cluster (PL and PR). */
00125 /*           =2: Upper bounds on Difu and Difl. F-norm-based estimate */
00126 /*               (DIF(1:2)). */
00127 /*           =3: Estimate of Difu and Difl. 1-norm-based estimate */
00128 /*               (DIF(1:2)). */
00129 /*               About 5 times as expensive as IJOB = 2. */
00130 /*           =4: Compute PL, PR and DIF (i.e. 0, 1 and 2 above): Economic */
00131 /*               version to get it all. */
00132 /*           =5: Compute PL, PR and DIF (i.e. 0, 1 and 3 above) */
00133 
00134 /*  WANTQ   (input) LOGICAL */
00135 /*          .TRUE. : update the left transformation matrix Q; */
00136 /*          .FALSE.: do not update Q. */
00137 
00138 /*  WANTZ   (input) LOGICAL */
00139 /*          .TRUE. : update the right transformation matrix Z; */
00140 /*          .FALSE.: do not update Z. */
00141 
00142 /*  SELECT  (input) LOGICAL array, dimension (N) */
00143 /*          SELECT specifies the eigenvalues in the selected cluster. */
00144 /*          To select a real eigenvalue w(j), SELECT(j) must be set to */
00145 /*          .TRUE.. To select a complex conjugate pair of eigenvalues */
00146 /*          w(j) and w(j+1), corresponding to a 2-by-2 diagonal block, */
00147 /*          either SELECT(j) or SELECT(j+1) or both must be set to */
00148 /*          .TRUE.; a complex conjugate pair of eigenvalues must be */
00149 /*          either both included in the cluster or both excluded. */
00150 
00151 /*  N       (input) INTEGER */
00152 /*          The order of the matrices A and B. N >= 0. */
00153 
00154 /*  A       (input/output) DOUBLE PRECISION array, dimension(LDA,N) */
00155 /*          On entry, the upper quasi-triangular matrix A, with (A, B) in */
00156 /*          generalized real Schur canonical form. */
00157 /*          On exit, A is overwritten by the reordered matrix A. */
00158 
00159 /*  LDA     (input) INTEGER */
00160 /*          The leading dimension of the array A. LDA >= max(1,N). */
00161 
00162 /*  B       (input/output) DOUBLE PRECISION array, dimension(LDB,N) */
00163 /*          On entry, the upper triangular matrix B, with (A, B) in */
00164 /*          generalized real Schur canonical form. */
00165 /*          On exit, B is overwritten by the reordered matrix B. */
00166 
00167 /*  LDB     (input) INTEGER */
00168 /*          The leading dimension of the array B. LDB >= max(1,N). */
00169 
00170 /*  ALPHAR  (output) DOUBLE PRECISION array, dimension (N) */
00171 /*  ALPHAI  (output) DOUBLE PRECISION array, dimension (N) */
00172 /*  BETA    (output) DOUBLE PRECISION array, dimension (N) */
00173 /*          On exit, (ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N, will */
00174 /*          be the generalized eigenvalues.  ALPHAR(j) + ALPHAI(j)*i */
00175 /*          and BETA(j),j=1,...,N  are the diagonals of the complex Schur */
00176 /*          form (S,T) that would result if the 2-by-2 diagonal blocks of */
00177 /*          the real generalized Schur form of (A,B) were further reduced */
00178 /*          to triangular form using complex unitary transformations. */
00179 /*          If ALPHAI(j) is zero, then the j-th eigenvalue is real; if */
00180 /*          positive, then the j-th and (j+1)-st eigenvalues are a */
00181 /*          complex conjugate pair, with ALPHAI(j+1) negative. */
00182 
00183 /*  Q       (input/output) DOUBLE PRECISION array, dimension (LDQ,N) */
00184 /*          On entry, if WANTQ = .TRUE., Q is an N-by-N matrix. */
00185 /*          On exit, Q has been postmultiplied by the left orthogonal */
00186 /*          transformation matrix which reorder (A, B); The leading M */
00187 /*          columns of Q form orthonormal bases for the specified pair of */
00188 /*          left eigenspaces (deflating subspaces). */
00189 /*          If WANTQ = .FALSE., Q is not referenced. */
00190 
00191 /*  LDQ     (input) INTEGER */
00192 /*          The leading dimension of the array Q.  LDQ >= 1; */
00193 /*          and if WANTQ = .TRUE., LDQ >= N. */
00194 
00195 /*  Z       (input/output) DOUBLE PRECISION array, dimension (LDZ,N) */
00196 /*          On entry, if WANTZ = .TRUE., Z is an N-by-N matrix. */
00197 /*          On exit, Z has been postmultiplied by the left orthogonal */
00198 /*          transformation matrix which reorder (A, B); The leading M */
00199 /*          columns of Z form orthonormal bases for the specified pair of */
00200 /*          left eigenspaces (deflating subspaces). */
00201 /*          If WANTZ = .FALSE., Z is not referenced. */
00202 
00203 /*  LDZ     (input) INTEGER */
00204 /*          The leading dimension of the array Z. LDZ >= 1; */
00205 /*          If WANTZ = .TRUE., LDZ >= N. */
00206 
00207 /*  M       (output) INTEGER */
00208 /*          The dimension of the specified pair of left and right eigen- */
00209 /*          spaces (deflating subspaces). 0 <= M <= N. */
00210 
00211 /*  PL      (output) DOUBLE PRECISION */
00212 /*  PR      (output) DOUBLE PRECISION */
00213 /*          If IJOB = 1, 4 or 5, PL, PR are lower bounds on the */
00214 /*          reciprocal of the norm of "projections" onto left and right */
00215 /*          eigenspaces with respect to the selected cluster. */
00216 /*          0 < PL, PR <= 1. */
00217 /*          If M = 0 or M = N, PL = PR  = 1. */
00218 /*          If IJOB = 0, 2 or 3, PL and PR are not referenced. */
00219 
00220 /*  DIF     (output) DOUBLE PRECISION array, dimension (2). */
00221 /*          If IJOB >= 2, DIF(1:2) store the estimates of Difu and Difl. */
00222 /*          If IJOB = 2 or 4, DIF(1:2) are F-norm-based upper bounds on */
00223 /*          Difu and Difl. If IJOB = 3 or 5, DIF(1:2) are 1-norm-based */
00224 /*          estimates of Difu and Difl. */
00225 /*          If M = 0 or N, DIF(1:2) = F-norm([A, B]). */
00226 /*          If IJOB = 0 or 1, DIF is not referenced. */
00227 
00228 /*  WORK    (workspace/output) DOUBLE PRECISION array, */
00229 /*          dimension (MAX(1,LWORK)) */
00230 /*          On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
00231 
00232 /*  LWORK   (input) INTEGER */
00233 /*          The dimension of the array WORK. LWORK >=  4*N+16. */
00234 /*          If IJOB = 1, 2 or 4, LWORK >= MAX(4*N+16, 2*M*(N-M)). */
00235 /*          If IJOB = 3 or 5, LWORK >= MAX(4*N+16, 4*M*(N-M)). */
00236 
00237 /*          If LWORK = -1, then a workspace query is assumed; the routine */
00238 /*          only calculates the optimal size of the WORK array, returns */
00239 /*          this value as the first entry of the WORK array, and no error */
00240 /*          message related to LWORK is issued by XERBLA. */
00241 
00242 /*  IWORK   (workspace/output) INTEGER array, dimension (MAX(1,LIWORK)) */
00243 /*          IF IJOB = 0, IWORK is not referenced.  Otherwise, */
00244 /*          on exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
00245 
00246 /*  LIWORK  (input) INTEGER */
00247 /*          The dimension of the array IWORK. LIWORK >= 1. */
00248 /*          If IJOB = 1, 2 or 4, LIWORK >=  N+6. */
00249 /*          If IJOB = 3 or 5, LIWORK >= MAX(2*M*(N-M), N+6). */
00250 
00251 /*          If LIWORK = -1, then a workspace query is assumed; the */
00252 /*          routine only calculates the optimal size of the IWORK array, */
00253 /*          returns this value as the first entry of the IWORK array, and */
00254 /*          no error message related to LIWORK is issued by XERBLA. */
00255 
00256 /*  INFO    (output) INTEGER */
00257 /*            =0: Successful exit. */
00258 /*            <0: If INFO = -i, the i-th argument had an illegal value. */
00259 /*            =1: Reordering of (A, B) failed because the transformed */
00260 /*                matrix pair (A, B) would be too far from generalized */
00261 /*                Schur form; the problem is very ill-conditioned. */
00262 /*                (A, B) may have been partially reordered. */
00263 /*                If requested, 0 is returned in DIF(*), PL and PR. */
00264 
00265 /*  Further Details */
00266 /*  =============== */
00267 
00268 /*  DTGSEN first collects the selected eigenvalues by computing */
00269 /*  orthogonal U and W that move them to the top left corner of (A, B). */
00270 /*  In other words, the selected eigenvalues are the eigenvalues of */
00271 /*  (A11, B11) in: */
00272 
00273 /*                U'*(A, B)*W = (A11 A12) (B11 B12) n1 */
00274 /*                              ( 0  A22),( 0  B22) n2 */
00275 /*                                n1  n2    n1  n2 */
00276 
00277 /*  where N = n1+n2 and U' means the transpose of U. The first n1 columns */
00278 /*  of U and W span the specified pair of left and right eigenspaces */
00279 /*  (deflating subspaces) of (A, B). */
00280 
00281 /*  If (A, B) has been obtained from the generalized real Schur */
00282 /*  decomposition of a matrix pair (C, D) = Q*(A, B)*Z', then the */
00283 /*  reordered generalized real Schur form of (C, D) is given by */
00284 
00285 /*           (C, D) = (Q*U)*(U'*(A, B)*W)*(Z*W)', */
00286 
00287 /*  and the first n1 columns of Q*U and Z*W span the corresponding */
00288 /*  deflating subspaces of (C, D) (Q and Z store Q*U and Z*W, resp.). */
00289 
00290 /*  Note that if the selected eigenvalue is sufficiently ill-conditioned, */
00291 /*  then its value may differ significantly from its value before */
00292 /*  reordering. */
00293 
00294 /*  The reciprocal condition numbers of the left and right eigenspaces */
00295 /*  spanned by the first n1 columns of U and W (or Q*U and Z*W) may */
00296 /*  be returned in DIF(1:2), corresponding to Difu and Difl, resp. */
00297 
00298 /*  The Difu and Difl are defined as: */
00299 
00300 /*       Difu[(A11, B11), (A22, B22)] = sigma-min( Zu ) */
00301 /*  and */
00302 /*       Difl[(A11, B11), (A22, B22)] = Difu[(A22, B22), (A11, B11)], */
00303 
00304 /*  where sigma-min(Zu) is the smallest singular value of the */
00305 /*  (2*n1*n2)-by-(2*n1*n2) matrix */
00306 
00307 /*       Zu = [ kron(In2, A11)  -kron(A22', In1) ] */
00308 /*            [ kron(In2, B11)  -kron(B22', In1) ]. */
00309 
00310 /*  Here, Inx is the identity matrix of size nx and A22' is the */
00311 /*  transpose of A22. kron(X, Y) is the Kronecker product between */
00312 /*  the matrices X and Y. */
00313 
00314 /*  When DIF(2) is small, small changes in (A, B) can cause large changes */
00315 /*  in the deflating subspace. An approximate (asymptotic) bound on the */
00316 /*  maximum angular error in the computed deflating subspaces is */
00317 
00318 /*       EPS * norm((A, B)) / DIF(2), */
00319 
00320 /*  where EPS is the machine precision. */
00321 
00322 /*  The reciprocal norm of the projectors on the left and right */
00323 /*  eigenspaces associated with (A11, B11) may be returned in PL and PR. */
00324 /*  They are computed as follows. First we compute L and R so that */
00325 /*  P*(A, B)*Q is block diagonal, where */
00326 
00327 /*       P = ( I -L ) n1           Q = ( I R ) n1 */
00328 /*           ( 0  I ) n2    and        ( 0 I ) n2 */
00329 /*             n1 n2                    n1 n2 */
00330 
00331 /*  and (L, R) is the solution to the generalized Sylvester equation */
00332 
00333 /*       A11*R - L*A22 = -A12 */
00334 /*       B11*R - L*B22 = -B12 */
00335 
00336 /*  Then PL = (F-norm(L)**2+1)**(-1/2) and PR = (F-norm(R)**2+1)**(-1/2). */
00337 /*  An approximate (asymptotic) bound on the average absolute error of */
00338 /*  the selected eigenvalues is */
00339 
00340 /*       EPS * norm((A, B)) / PL. */
00341 
00342 /*  There are also global error bounds which valid for perturbations up */
00343 /*  to a certain restriction:  A lower bound (x) on the smallest */
00344 /*  F-norm(E,F) for which an eigenvalue of (A11, B11) may move and */
00345 /*  coalesce with an eigenvalue of (A22, B22) under perturbation (E,F), */
00346 /*  (i.e. (A + E, B + F), is */
00347 
00348 /*   x = min(Difu,Difl)/((1/(PL*PL)+1/(PR*PR))**(1/2)+2*max(1/PL,1/PR)). */
00349 
00350 /*  An approximate bound on x can be computed from DIF(1:2), PL and PR. */
00351 
00352 /*  If y = ( F-norm(E,F) / x) <= 1, the angles between the perturbed */
00353 /*  (L', R') and unperturbed (L, R) left and right deflating subspaces */
00354 /*  associated with the selected cluster in the (1,1)-blocks can be */
00355 /*  bounded as */
00356 
00357 /*   max-angle(L, L') <= arctan( y * PL / (1 - y * (1 - PL * PL)**(1/2)) */
00358 /*   max-angle(R, R') <= arctan( y * PR / (1 - y * (1 - PR * PR)**(1/2)) */
00359 
00360 /*  See LAPACK User's Guide section 4.11 or the following references */
00361 /*  for more information. */
00362 
00363 /*  Note that if the default method for computing the Frobenius-norm- */
00364 /*  based estimate DIF is not wanted (see DLATDF), then the parameter */
00365 /*  IDIFJB (see below) should be changed from 3 to 4 (routine DLATDF */
00366 /*  (IJOB = 2 will be used)). See DTGSYL for more details. */
00367 
00368 /*  Based on contributions by */
00369 /*     Bo Kagstrom and Peter Poromaa, Department of Computing Science, */
00370 /*     Umea University, S-901 87 Umea, Sweden. */
00371 
00372 /*  References */
00373 /*  ========== */
00374 
00375 /*  [1] B. Kagstrom; A Direct Method for Reordering Eigenvalues in the */
00376 /*      Generalized Real Schur Form of a Regular Matrix Pair (A, B), in */
00377 /*      M.S. Moonen et al (eds), Linear Algebra for Large Scale and */
00378 /*      Real-Time Applications, Kluwer Academic Publ. 1993, pp 195-218. */
00379 
00380 /*  [2] B. Kagstrom and P. Poromaa; Computing Eigenspaces with Specified */
00381 /*      Eigenvalues of a Regular Matrix Pair (A, B) and Condition */
00382 /*      Estimation: Theory, Algorithms and Software, */
00383 /*      Report UMINF - 94.04, Department of Computing Science, Umea */
00384 /*      University, S-901 87 Umea, Sweden, 1994. Also as LAPACK Working */
00385 /*      Note 87. To appear in Numerical Algorithms, 1996. */
00386 
00387 /*  [3] B. Kagstrom and P. Poromaa, LAPACK-Style Algorithms and Software */
00388 /*      for Solving the Generalized Sylvester Equation and Estimating the */
00389 /*      Separation between Regular Matrix Pairs, Report UMINF - 93.23, */
00390 /*      Department of Computing Science, Umea University, S-901 87 Umea, */
00391 /*      Sweden, December 1993, Revised April 1994, Also as LAPACK Working */
00392 /*      Note 75. To appear in ACM Trans. on Math. Software, Vol 22, No 1, */
00393 /*      1996. */
00394 
00395 /*  ===================================================================== */
00396 
00397 /*     .. Parameters .. */
00398 /*     .. */
00399 /*     .. Local Scalars .. */
00400 /*     .. */
00401 /*     .. Local Arrays .. */
00402 /*     .. */
00403 /*     .. External Subroutines .. */
00404 /*     .. */
00405 /*     .. External Functions .. */
00406 /*     .. */
00407 /*     .. Intrinsic Functions .. */
00408 /*     .. */
00409 /*     .. Executable Statements .. */
00410 
00411 /*     Decode and test the input parameters */
00412 
00413     /* Parameter adjustments */
00414     --select;
00415     a_dim1 = *lda;
00416     a_offset = 1 + a_dim1;
00417     a -= a_offset;
00418     b_dim1 = *ldb;
00419     b_offset = 1 + b_dim1;
00420     b -= b_offset;
00421     --alphar;
00422     --alphai;
00423     --beta;
00424     q_dim1 = *ldq;
00425     q_offset = 1 + q_dim1;
00426     q -= q_offset;
00427     z_dim1 = *ldz;
00428     z_offset = 1 + z_dim1;
00429     z__ -= z_offset;
00430     --dif;
00431     --work;
00432     --iwork;
00433 
00434     /* Function Body */
00435     *info = 0;
00436     lquery = *lwork == -1 || *liwork == -1;
00437 
00438     if (*ijob < 0 || *ijob > 5) {
00439         *info = -1;
00440     } else if (*n < 0) {
00441         *info = -5;
00442     } else if (*lda < max(1,*n)) {
00443         *info = -7;
00444     } else if (*ldb < max(1,*n)) {
00445         *info = -9;
00446     } else if (*ldq < 1 || *wantq && *ldq < *n) {
00447         *info = -14;
00448     } else if (*ldz < 1 || *wantz && *ldz < *n) {
00449         *info = -16;
00450     }
00451 
00452     if (*info != 0) {
00453         i__1 = -(*info);
00454         xerbla_("DTGSEN", &i__1);
00455         return 0;
00456     }
00457 
00458 /*     Get machine constants */
00459 
00460     eps = dlamch_("P");
00461     smlnum = dlamch_("S") / eps;
00462     ierr = 0;
00463 
00464     wantp = *ijob == 1 || *ijob >= 4;
00465     wantd1 = *ijob == 2 || *ijob == 4;
00466     wantd2 = *ijob == 3 || *ijob == 5;
00467     wantd = wantd1 || wantd2;
00468 
00469 /*     Set M to the dimension of the specified pair of deflating */
00470 /*     subspaces. */
00471 
00472     *m = 0;
00473     pair = FALSE_;
00474     i__1 = *n;
00475     for (k = 1; k <= i__1; ++k) {
00476         if (pair) {
00477             pair = FALSE_;
00478         } else {
00479             if (k < *n) {
00480                 if (a[k + 1 + k * a_dim1] == 0.) {
00481                     if (select[k]) {
00482                         ++(*m);
00483                     }
00484                 } else {
00485                     pair = TRUE_;
00486                     if (select[k] || select[k + 1]) {
00487                         *m += 2;
00488                     }
00489                 }
00490             } else {
00491                 if (select[*n]) {
00492                     ++(*m);
00493                 }
00494             }
00495         }
00496 /* L10: */
00497     }
00498 
00499     if (*ijob == 1 || *ijob == 2 || *ijob == 4) {
00500 /* Computing MAX */
00501         i__1 = 1, i__2 = (*n << 2) + 16, i__1 = max(i__1,i__2), i__2 = (*m << 
00502                 1) * (*n - *m);
00503         lwmin = max(i__1,i__2);
00504 /* Computing MAX */
00505         i__1 = 1, i__2 = *n + 6;
00506         liwmin = max(i__1,i__2);
00507     } else if (*ijob == 3 || *ijob == 5) {
00508 /* Computing MAX */
00509         i__1 = 1, i__2 = (*n << 2) + 16, i__1 = max(i__1,i__2), i__2 = (*m << 
00510                 2) * (*n - *m);
00511         lwmin = max(i__1,i__2);
00512 /* Computing MAX */
00513         i__1 = 1, i__2 = (*m << 1) * (*n - *m), i__1 = max(i__1,i__2), i__2 = 
00514                 *n + 6;
00515         liwmin = max(i__1,i__2);
00516     } else {
00517 /* Computing MAX */
00518         i__1 = 1, i__2 = (*n << 2) + 16;
00519         lwmin = max(i__1,i__2);
00520         liwmin = 1;
00521     }
00522 
00523     work[1] = (doublereal) lwmin;
00524     iwork[1] = liwmin;
00525 
00526     if (*lwork < lwmin && ! lquery) {
00527         *info = -22;
00528     } else if (*liwork < liwmin && ! lquery) {
00529         *info = -24;
00530     }
00531 
00532     if (*info != 0) {
00533         i__1 = -(*info);
00534         xerbla_("DTGSEN", &i__1);
00535         return 0;
00536     } else if (lquery) {
00537         return 0;
00538     }
00539 
00540 /*     Quick return if possible. */
00541 
00542     if (*m == *n || *m == 0) {
00543         if (wantp) {
00544             *pl = 1.;
00545             *pr = 1.;
00546         }
00547         if (wantd) {
00548             dscale = 0.;
00549             dsum = 1.;
00550             i__1 = *n;
00551             for (i__ = 1; i__ <= i__1; ++i__) {
00552                 dlassq_(n, &a[i__ * a_dim1 + 1], &c__1, &dscale, &dsum);
00553                 dlassq_(n, &b[i__ * b_dim1 + 1], &c__1, &dscale, &dsum);
00554 /* L20: */
00555             }
00556             dif[1] = dscale * sqrt(dsum);
00557             dif[2] = dif[1];
00558         }
00559         goto L60;
00560     }
00561 
00562 /*     Collect the selected blocks at the top-left corner of (A, B). */
00563 
00564     ks = 0;
00565     pair = FALSE_;
00566     i__1 = *n;
00567     for (k = 1; k <= i__1; ++k) {
00568         if (pair) {
00569             pair = FALSE_;
00570         } else {
00571 
00572             swap = select[k];
00573             if (k < *n) {
00574                 if (a[k + 1 + k * a_dim1] != 0.) {
00575                     pair = TRUE_;
00576                     swap = swap || select[k + 1];
00577                 }
00578             }
00579 
00580             if (swap) {
00581                 ++ks;
00582 
00583 /*              Swap the K-th block to position KS. */
00584 /*              Perform the reordering of diagonal blocks in (A, B) */
00585 /*              by orthogonal transformation matrices and update */
00586 /*              Q and Z accordingly (if requested): */
00587 
00588                 kk = k;
00589                 if (k != ks) {
00590                     dtgexc_(wantq, wantz, n, &a[a_offset], lda, &b[b_offset], 
00591                             ldb, &q[q_offset], ldq, &z__[z_offset], ldz, &kk, 
00592                             &ks, &work[1], lwork, &ierr);
00593                 }
00594 
00595                 if (ierr > 0) {
00596 
00597 /*                 Swap is rejected: exit. */
00598 
00599                     *info = 1;
00600                     if (wantp) {
00601                         *pl = 0.;
00602                         *pr = 0.;
00603                     }
00604                     if (wantd) {
00605                         dif[1] = 0.;
00606                         dif[2] = 0.;
00607                     }
00608                     goto L60;
00609                 }
00610 
00611                 if (pair) {
00612                     ++ks;
00613                 }
00614             }
00615         }
00616 /* L30: */
00617     }
00618     if (wantp) {
00619 
00620 /*        Solve generalized Sylvester equation for R and L */
00621 /*        and compute PL and PR. */
00622 
00623         n1 = *m;
00624         n2 = *n - *m;
00625         i__ = n1 + 1;
00626         ijb = 0;
00627         dlacpy_("Full", &n1, &n2, &a[i__ * a_dim1 + 1], lda, &work[1], &n1);
00628         dlacpy_("Full", &n1, &n2, &b[i__ * b_dim1 + 1], ldb, &work[n1 * n2 + 
00629                 1], &n1);
00630         i__1 = *lwork - (n1 << 1) * n2;
00631         dtgsyl_("N", &ijb, &n1, &n2, &a[a_offset], lda, &a[i__ + i__ * a_dim1]
00632 , lda, &work[1], &n1, &b[b_offset], ldb, &b[i__ + i__ * 
00633                 b_dim1], ldb, &work[n1 * n2 + 1], &n1, &dscale, &dif[1], &
00634                 work[(n1 * n2 << 1) + 1], &i__1, &iwork[1], &ierr);
00635 
00636 /*        Estimate the reciprocal of norms of "projections" onto left */
00637 /*        and right eigenspaces. */
00638 
00639         rdscal = 0.;
00640         dsum = 1.;
00641         i__1 = n1 * n2;
00642         dlassq_(&i__1, &work[1], &c__1, &rdscal, &dsum);
00643         *pl = rdscal * sqrt(dsum);
00644         if (*pl == 0.) {
00645             *pl = 1.;
00646         } else {
00647             *pl = dscale / (sqrt(dscale * dscale / *pl + *pl) * sqrt(*pl));
00648         }
00649         rdscal = 0.;
00650         dsum = 1.;
00651         i__1 = n1 * n2;
00652         dlassq_(&i__1, &work[n1 * n2 + 1], &c__1, &rdscal, &dsum);
00653         *pr = rdscal * sqrt(dsum);
00654         if (*pr == 0.) {
00655             *pr = 1.;
00656         } else {
00657             *pr = dscale / (sqrt(dscale * dscale / *pr + *pr) * sqrt(*pr));
00658         }
00659     }
00660 
00661     if (wantd) {
00662 
00663 /*        Compute estimates of Difu and Difl. */
00664 
00665         if (wantd1) {
00666             n1 = *m;
00667             n2 = *n - *m;
00668             i__ = n1 + 1;
00669             ijb = 3;
00670 
00671 /*           Frobenius norm-based Difu-estimate. */
00672 
00673             i__1 = *lwork - (n1 << 1) * n2;
00674             dtgsyl_("N", &ijb, &n1, &n2, &a[a_offset], lda, &a[i__ + i__ * 
00675                     a_dim1], lda, &work[1], &n1, &b[b_offset], ldb, &b[i__ + 
00676                     i__ * b_dim1], ldb, &work[n1 * n2 + 1], &n1, &dscale, &
00677                     dif[1], &work[(n1 << 1) * n2 + 1], &i__1, &iwork[1], &
00678                     ierr);
00679 
00680 /*           Frobenius norm-based Difl-estimate. */
00681 
00682             i__1 = *lwork - (n1 << 1) * n2;
00683             dtgsyl_("N", &ijb, &n2, &n1, &a[i__ + i__ * a_dim1], lda, &a[
00684                     a_offset], lda, &work[1], &n2, &b[i__ + i__ * b_dim1], 
00685                     ldb, &b[b_offset], ldb, &work[n1 * n2 + 1], &n2, &dscale, 
00686                     &dif[2], &work[(n1 << 1) * n2 + 1], &i__1, &iwork[1], &
00687                     ierr);
00688         } else {
00689 
00690 
00691 /*           Compute 1-norm-based estimates of Difu and Difl using */
00692 /*           reversed communication with DLACN2. In each step a */
00693 /*           generalized Sylvester equation or a transposed variant */
00694 /*           is solved. */
00695 
00696             kase = 0;
00697             n1 = *m;
00698             n2 = *n - *m;
00699             i__ = n1 + 1;
00700             ijb = 0;
00701             mn2 = (n1 << 1) * n2;
00702 
00703 /*           1-norm-based estimate of Difu. */
00704 
00705 L40:
00706             dlacn2_(&mn2, &work[mn2 + 1], &work[1], &iwork[1], &dif[1], &kase, 
00707                      isave);
00708             if (kase != 0) {
00709                 if (kase == 1) {
00710 
00711 /*                 Solve generalized Sylvester equation. */
00712 
00713                     i__1 = *lwork - (n1 << 1) * n2;
00714                     dtgsyl_("N", &ijb, &n1, &n2, &a[a_offset], lda, &a[i__ + 
00715                             i__ * a_dim1], lda, &work[1], &n1, &b[b_offset], 
00716                             ldb, &b[i__ + i__ * b_dim1], ldb, &work[n1 * n2 + 
00717                             1], &n1, &dscale, &dif[1], &work[(n1 << 1) * n2 + 
00718                             1], &i__1, &iwork[1], &ierr);
00719                 } else {
00720 
00721 /*                 Solve the transposed variant. */
00722 
00723                     i__1 = *lwork - (n1 << 1) * n2;
00724                     dtgsyl_("T", &ijb, &n1, &n2, &a[a_offset], lda, &a[i__ + 
00725                             i__ * a_dim1], lda, &work[1], &n1, &b[b_offset], 
00726                             ldb, &b[i__ + i__ * b_dim1], ldb, &work[n1 * n2 + 
00727                             1], &n1, &dscale, &dif[1], &work[(n1 << 1) * n2 + 
00728                             1], &i__1, &iwork[1], &ierr);
00729                 }
00730                 goto L40;
00731             }
00732             dif[1] = dscale / dif[1];
00733 
00734 /*           1-norm-based estimate of Difl. */
00735 
00736 L50:
00737             dlacn2_(&mn2, &work[mn2 + 1], &work[1], &iwork[1], &dif[2], &kase, 
00738                      isave);
00739             if (kase != 0) {
00740                 if (kase == 1) {
00741 
00742 /*                 Solve generalized Sylvester equation. */
00743 
00744                     i__1 = *lwork - (n1 << 1) * n2;
00745                     dtgsyl_("N", &ijb, &n2, &n1, &a[i__ + i__ * a_dim1], lda, 
00746                             &a[a_offset], lda, &work[1], &n2, &b[i__ + i__ * 
00747                             b_dim1], ldb, &b[b_offset], ldb, &work[n1 * n2 + 
00748                             1], &n2, &dscale, &dif[2], &work[(n1 << 1) * n2 + 
00749                             1], &i__1, &iwork[1], &ierr);
00750                 } else {
00751 
00752 /*                 Solve the transposed variant. */
00753 
00754                     i__1 = *lwork - (n1 << 1) * n2;
00755                     dtgsyl_("T", &ijb, &n2, &n1, &a[i__ + i__ * a_dim1], lda, 
00756                             &a[a_offset], lda, &work[1], &n2, &b[i__ + i__ * 
00757                             b_dim1], ldb, &b[b_offset], ldb, &work[n1 * n2 + 
00758                             1], &n2, &dscale, &dif[2], &work[(n1 << 1) * n2 + 
00759                             1], &i__1, &iwork[1], &ierr);
00760                 }
00761                 goto L50;
00762             }
00763             dif[2] = dscale / dif[2];
00764 
00765         }
00766     }
00767 
00768 L60:
00769 
00770 /*     Compute generalized eigenvalues of reordered pair (A, B) and */
00771 /*     normalize the generalized Schur form. */
00772 
00773     pair = FALSE_;
00774     i__1 = *n;
00775     for (k = 1; k <= i__1; ++k) {
00776         if (pair) {
00777             pair = FALSE_;
00778         } else {
00779 
00780             if (k < *n) {
00781                 if (a[k + 1 + k * a_dim1] != 0.) {
00782                     pair = TRUE_;
00783                 }
00784             }
00785 
00786             if (pair) {
00787 
00788 /*             Compute the eigenvalue(s) at position K. */
00789 
00790                 work[1] = a[k + k * a_dim1];
00791                 work[2] = a[k + 1 + k * a_dim1];
00792                 work[3] = a[k + (k + 1) * a_dim1];
00793                 work[4] = a[k + 1 + (k + 1) * a_dim1];
00794                 work[5] = b[k + k * b_dim1];
00795                 work[6] = b[k + 1 + k * b_dim1];
00796                 work[7] = b[k + (k + 1) * b_dim1];
00797                 work[8] = b[k + 1 + (k + 1) * b_dim1];
00798                 d__1 = smlnum * eps;
00799                 dlag2_(&work[1], &c__2, &work[5], &c__2, &d__1, &beta[k], &
00800                         beta[k + 1], &alphar[k], &alphar[k + 1], &alphai[k]);
00801                 alphai[k + 1] = -alphai[k];
00802 
00803             } else {
00804 
00805                 if (d_sign(&c_b28, &b[k + k * b_dim1]) < 0.) {
00806 
00807 /*                 If B(K,K) is negative, make it positive */
00808 
00809                     i__2 = *n;
00810                     for (i__ = 1; i__ <= i__2; ++i__) {
00811                         a[k + i__ * a_dim1] = -a[k + i__ * a_dim1];
00812                         b[k + i__ * b_dim1] = -b[k + i__ * b_dim1];
00813                         if (*wantq) {
00814                             q[i__ + k * q_dim1] = -q[i__ + k * q_dim1];
00815                         }
00816 /* L70: */
00817                     }
00818                 }
00819 
00820                 alphar[k] = a[k + k * a_dim1];
00821                 alphai[k] = 0.;
00822                 beta[k] = b[k + k * b_dim1];
00823 
00824             }
00825         }
00826 /* L80: */
00827     }
00828 
00829     work[1] = (doublereal) lwmin;
00830     iwork[1] = liwmin;
00831 
00832     return 0;
00833 
00834 /*     End of DTGSEN */
00835 
00836 } /* dtgsen_ */


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