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


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