You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

stgsen.c 42 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353
  1. /* f2c.h -- Standard Fortran to C header file */
  2. /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
  3. - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
  4. #ifndef F2C_INCLUDE
  5. #define F2C_INCLUDE
  6. #include <math.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <complex.h>
  11. #ifdef complex
  12. #undef complex
  13. #endif
  14. #ifdef I
  15. #undef I
  16. #endif
  17. #if defined(_WIN64)
  18. typedef long long BLASLONG;
  19. typedef unsigned long long BLASULONG;
  20. #else
  21. typedef long BLASLONG;
  22. typedef unsigned long BLASULONG;
  23. #endif
  24. #ifdef LAPACK_ILP64
  25. typedef BLASLONG blasint;
  26. #if defined(_WIN64)
  27. #define blasabs(x) llabs(x)
  28. #else
  29. #define blasabs(x) labs(x)
  30. #endif
  31. #else
  32. typedef int blasint;
  33. #define blasabs(x) abs(x)
  34. #endif
  35. typedef blasint integer;
  36. typedef unsigned int uinteger;
  37. typedef char *address;
  38. typedef short int shortint;
  39. typedef float real;
  40. typedef double doublereal;
  41. typedef struct { real r, i; } complex;
  42. typedef struct { doublereal r, i; } doublecomplex;
  43. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  44. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  46. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  47. #define pCf(z) (*_pCf(z))
  48. #define pCd(z) (*_pCd(z))
  49. typedef int logical;
  50. typedef short int shortlogical;
  51. typedef char logical1;
  52. typedef char integer1;
  53. #define TRUE_ (1)
  54. #define FALSE_ (0)
  55. /* Extern is for use with -E */
  56. #ifndef Extern
  57. #define Extern extern
  58. #endif
  59. /* I/O stuff */
  60. typedef int flag;
  61. typedef int ftnlen;
  62. typedef int ftnint;
  63. /*external read, write*/
  64. typedef struct
  65. { flag cierr;
  66. ftnint ciunit;
  67. flag ciend;
  68. char *cifmt;
  69. ftnint cirec;
  70. } cilist;
  71. /*internal read, write*/
  72. typedef struct
  73. { flag icierr;
  74. char *iciunit;
  75. flag iciend;
  76. char *icifmt;
  77. ftnint icirlen;
  78. ftnint icirnum;
  79. } icilist;
  80. /*open*/
  81. typedef struct
  82. { flag oerr;
  83. ftnint ounit;
  84. char *ofnm;
  85. ftnlen ofnmlen;
  86. char *osta;
  87. char *oacc;
  88. char *ofm;
  89. ftnint orl;
  90. char *oblnk;
  91. } olist;
  92. /*close*/
  93. typedef struct
  94. { flag cerr;
  95. ftnint cunit;
  96. char *csta;
  97. } cllist;
  98. /*rewind, backspace, endfile*/
  99. typedef struct
  100. { flag aerr;
  101. ftnint aunit;
  102. } alist;
  103. /* inquire */
  104. typedef struct
  105. { flag inerr;
  106. ftnint inunit;
  107. char *infile;
  108. ftnlen infilen;
  109. ftnint *inex; /*parameters in standard's order*/
  110. ftnint *inopen;
  111. ftnint *innum;
  112. ftnint *innamed;
  113. char *inname;
  114. ftnlen innamlen;
  115. char *inacc;
  116. ftnlen inacclen;
  117. char *inseq;
  118. ftnlen inseqlen;
  119. char *indir;
  120. ftnlen indirlen;
  121. char *infmt;
  122. ftnlen infmtlen;
  123. char *inform;
  124. ftnint informlen;
  125. char *inunf;
  126. ftnlen inunflen;
  127. ftnint *inrecl;
  128. ftnint *innrec;
  129. char *inblank;
  130. ftnlen inblanklen;
  131. } inlist;
  132. #define VOID void
  133. union Multitype { /* for multiple entry points */
  134. integer1 g;
  135. shortint h;
  136. integer i;
  137. /* longint j; */
  138. real r;
  139. doublereal d;
  140. complex c;
  141. doublecomplex z;
  142. };
  143. typedef union Multitype Multitype;
  144. struct Vardesc { /* for Namelist */
  145. char *name;
  146. char *addr;
  147. ftnlen *dims;
  148. int type;
  149. };
  150. typedef struct Vardesc Vardesc;
  151. struct Namelist {
  152. char *name;
  153. Vardesc **vars;
  154. int nvars;
  155. };
  156. typedef struct Namelist Namelist;
  157. #define abs(x) ((x) >= 0 ? (x) : -(x))
  158. #define dabs(x) (fabs(x))
  159. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  160. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  161. #define dmin(a,b) (f2cmin(a,b))
  162. #define dmax(a,b) (f2cmax(a,b))
  163. #define bit_test(a,b) ((a) >> (b) & 1)
  164. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  165. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  166. #define abort_() { sig_die("Fortran abort routine called", 1); }
  167. #define c_abs(z) (cabsf(Cf(z)))
  168. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  169. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  170. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  171. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  172. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  173. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  174. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  175. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  176. #define d_abs(x) (fabs(*(x)))
  177. #define d_acos(x) (acos(*(x)))
  178. #define d_asin(x) (asin(*(x)))
  179. #define d_atan(x) (atan(*(x)))
  180. #define d_atn2(x, y) (atan2(*(x),*(y)))
  181. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  182. #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
  183. #define d_cos(x) (cos(*(x)))
  184. #define d_cosh(x) (cosh(*(x)))
  185. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  186. #define d_exp(x) (exp(*(x)))
  187. #define d_imag(z) (cimag(Cd(z)))
  188. #define r_imag(z) (cimag(Cf(z)))
  189. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  190. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  191. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  192. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  193. #define d_log(x) (log(*(x)))
  194. #define d_mod(x, y) (fmod(*(x), *(y)))
  195. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  196. #define d_nint(x) u_nint(*(x))
  197. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  198. #define d_sign(a,b) u_sign(*(a),*(b))
  199. #define r_sign(a,b) u_sign(*(a),*(b))
  200. #define d_sin(x) (sin(*(x)))
  201. #define d_sinh(x) (sinh(*(x)))
  202. #define d_sqrt(x) (sqrt(*(x)))
  203. #define d_tan(x) (tan(*(x)))
  204. #define d_tanh(x) (tanh(*(x)))
  205. #define i_abs(x) abs(*(x))
  206. #define i_dnnt(x) ((integer)u_nint(*(x)))
  207. #define i_len(s, n) (n)
  208. #define i_nint(x) ((integer)u_nint(*(x)))
  209. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  210. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  211. #define pow_si(B,E) spow_ui(*(B),*(E))
  212. #define pow_ri(B,E) spow_ui(*(B),*(E))
  213. #define pow_di(B,E) dpow_ui(*(B),*(E))
  214. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  215. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  216. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  217. #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
  218. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  219. #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
  220. #define sig_die(s, kill) { exit(1); }
  221. #define s_stop(s, n) {exit(0);}
  222. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  223. #define z_abs(z) (cabs(Cd(z)))
  224. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  225. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  226. #define myexit_() break;
  227. #define mycycle() continue;
  228. #define myceiling(w) {ceil(w)}
  229. #define myhuge(w) {HUGE_VAL}
  230. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  231. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  232. /* procedure parameter types for -A and -C++ */
  233. #define F2C_proc_par_types 1
  234. #ifdef __cplusplus
  235. typedef logical (*L_fp)(...);
  236. #else
  237. typedef logical (*L_fp)();
  238. #endif
  239. static float spow_ui(float x, integer n) {
  240. float pow=1.0; unsigned long int u;
  241. if(n != 0) {
  242. if(n < 0) n = -n, x = 1/x;
  243. for(u = n; ; ) {
  244. if(u & 01) pow *= x;
  245. if(u >>= 1) x *= x;
  246. else break;
  247. }
  248. }
  249. return pow;
  250. }
  251. static double dpow_ui(double x, integer n) {
  252. double pow=1.0; unsigned long int u;
  253. if(n != 0) {
  254. if(n < 0) n = -n, x = 1/x;
  255. for(u = n; ; ) {
  256. if(u & 01) pow *= x;
  257. if(u >>= 1) x *= x;
  258. else break;
  259. }
  260. }
  261. return pow;
  262. }
  263. static _Complex float cpow_ui(_Complex float x, integer n) {
  264. _Complex float pow=1.0; unsigned long int u;
  265. if(n != 0) {
  266. if(n < 0) n = -n, x = 1/x;
  267. for(u = n; ; ) {
  268. if(u & 01) pow *= x;
  269. if(u >>= 1) x *= x;
  270. else break;
  271. }
  272. }
  273. return pow;
  274. }
  275. static _Complex double zpow_ui(_Complex double x, integer n) {
  276. _Complex double pow=1.0; unsigned long int u;
  277. if(n != 0) {
  278. if(n < 0) n = -n, x = 1/x;
  279. for(u = n; ; ) {
  280. if(u & 01) pow *= x;
  281. if(u >>= 1) x *= x;
  282. else break;
  283. }
  284. }
  285. return pow;
  286. }
  287. static integer pow_ii(integer x, integer n) {
  288. integer pow; unsigned long int u;
  289. if (n <= 0) {
  290. if (n == 0 || x == 1) pow = 1;
  291. else if (x != -1) pow = x == 0 ? 1/x : 0;
  292. else n = -n;
  293. }
  294. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  295. u = n;
  296. for(pow = 1; ; ) {
  297. if(u & 01) pow *= x;
  298. if(u >>= 1) x *= x;
  299. else break;
  300. }
  301. }
  302. return pow;
  303. }
  304. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  305. {
  306. double m; integer i, mi;
  307. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  308. if (w[i-1]>m) mi=i ,m=w[i-1];
  309. return mi-s+1;
  310. }
  311. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  312. {
  313. float m; integer i, mi;
  314. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  315. if (w[i-1]>m) mi=i ,m=w[i-1];
  316. return mi-s+1;
  317. }
  318. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  319. integer n = *n_, incx = *incx_, incy = *incy_, i;
  320. _Complex float zdotc = 0.0;
  321. if (incx == 1 && incy == 1) {
  322. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  323. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  324. }
  325. } else {
  326. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  327. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  328. }
  329. }
  330. pCf(z) = zdotc;
  331. }
  332. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  333. integer n = *n_, incx = *incx_, incy = *incy_, i;
  334. _Complex double zdotc = 0.0;
  335. if (incx == 1 && incy == 1) {
  336. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  337. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  338. }
  339. } else {
  340. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  341. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  342. }
  343. }
  344. pCd(z) = zdotc;
  345. }
  346. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  347. integer n = *n_, incx = *incx_, incy = *incy_, i;
  348. _Complex float zdotc = 0.0;
  349. if (incx == 1 && incy == 1) {
  350. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  351. zdotc += Cf(&x[i]) * Cf(&y[i]);
  352. }
  353. } else {
  354. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  355. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  356. }
  357. }
  358. pCf(z) = zdotc;
  359. }
  360. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  361. integer n = *n_, incx = *incx_, incy = *incy_, i;
  362. _Complex double zdotc = 0.0;
  363. if (incx == 1 && incy == 1) {
  364. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  365. zdotc += Cd(&x[i]) * Cd(&y[i]);
  366. }
  367. } else {
  368. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  369. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  370. }
  371. }
  372. pCd(z) = zdotc;
  373. }
  374. #endif
  375. /* -- translated by f2c (version 20000121).
  376. You must link the resulting object file with the libraries:
  377. -lf2c -lm (in that order)
  378. */
  379. /* Table of constant values */
  380. static integer c__1 = 1;
  381. static integer c__2 = 2;
  382. static real c_b28 = 1.f;
  383. /* > \brief \b STGSEN */
  384. /* =========== DOCUMENTATION =========== */
  385. /* Online html documentation available at */
  386. /* http://www.netlib.org/lapack/explore-html/ */
  387. /* > \htmlonly */
  388. /* > Download STGSEN + dependencies */
  389. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/stgsen.
  390. f"> */
  391. /* > [TGZ]</a> */
  392. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/stgsen.
  393. f"> */
  394. /* > [ZIP]</a> */
  395. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/stgsen.
  396. f"> */
  397. /* > [TXT]</a> */
  398. /* > \endhtmlonly */
  399. /* Definition: */
  400. /* =========== */
  401. /* SUBROUTINE STGSEN( IJOB, WANTQ, WANTZ, SELECT, N, A, LDA, B, LDB, */
  402. /* ALPHAR, ALPHAI, BETA, Q, LDQ, Z, LDZ, M, PL, */
  403. /* PR, DIF, WORK, LWORK, IWORK, LIWORK, INFO ) */
  404. /* LOGICAL WANTQ, WANTZ */
  405. /* INTEGER IJOB, INFO, LDA, LDB, LDQ, LDZ, LIWORK, LWORK, */
  406. /* $ M, N */
  407. /* REAL PL, PR */
  408. /* LOGICAL SELECT( * ) */
  409. /* INTEGER IWORK( * ) */
  410. /* REAL A( LDA, * ), ALPHAI( * ), ALPHAR( * ), */
  411. /* $ B( LDB, * ), BETA( * ), DIF( * ), Q( LDQ, * ), */
  412. /* $ WORK( * ), Z( LDZ, * ) */
  413. /* > \par Purpose: */
  414. /* ============= */
  415. /* > */
  416. /* > \verbatim */
  417. /* > */
  418. /* > STGSEN reorders the generalized real Schur decomposition of a real */
  419. /* > matrix pair (A, B) (in terms of an orthonormal equivalence trans- */
  420. /* > formation Q**T * (A, B) * Z), so that a selected cluster of eigenvalues */
  421. /* > appears in the leading diagonal blocks of the upper quasi-triangular */
  422. /* > matrix A and the upper triangular B. The leading columns of Q and */
  423. /* > Z form orthonormal bases of the corresponding left and right eigen- */
  424. /* > spaces (deflating subspaces). (A, B) must be in generalized real */
  425. /* > Schur canonical form (as returned by SGGES), i.e. A is block upper */
  426. /* > triangular with 1-by-1 and 2-by-2 diagonal blocks. B is upper */
  427. /* > triangular. */
  428. /* > */
  429. /* > STGSEN also computes the generalized eigenvalues */
  430. /* > */
  431. /* > w(j) = (ALPHAR(j) + i*ALPHAI(j))/BETA(j) */
  432. /* > */
  433. /* > of the reordered matrix pair (A, B). */
  434. /* > */
  435. /* > Optionally, STGSEN computes the estimates of reciprocal condition */
  436. /* > numbers for eigenvalues and eigenspaces. These are Difu[(A11,B11), */
  437. /* > (A22,B22)] and Difl[(A11,B11), (A22,B22)], i.e. the separation(s) */
  438. /* > between the matrix pairs (A11, B11) and (A22,B22) that correspond to */
  439. /* > the selected cluster and the eigenvalues outside the cluster, resp., */
  440. /* > and norms of "projections" onto left and right eigenspaces w.r.t. */
  441. /* > the selected cluster in the (1,1)-block. */
  442. /* > \endverbatim */
  443. /* Arguments: */
  444. /* ========== */
  445. /* > \param[in] IJOB */
  446. /* > \verbatim */
  447. /* > IJOB is INTEGER */
  448. /* > Specifies whether condition numbers are required for the */
  449. /* > cluster of eigenvalues (PL and PR) or the deflating subspaces */
  450. /* > (Difu and Difl): */
  451. /* > =0: Only reorder w.r.t. SELECT. No extras. */
  452. /* > =1: Reciprocal of norms of "projections" onto left and right */
  453. /* > eigenspaces w.r.t. the selected cluster (PL and PR). */
  454. /* > =2: Upper bounds on Difu and Difl. F-norm-based estimate */
  455. /* > (DIF(1:2)). */
  456. /* > =3: Estimate of Difu and Difl. 1-norm-based estimate */
  457. /* > (DIF(1:2)). */
  458. /* > About 5 times as expensive as IJOB = 2. */
  459. /* > =4: Compute PL, PR and DIF (i.e. 0, 1 and 2 above): Economic */
  460. /* > version to get it all. */
  461. /* > =5: Compute PL, PR and DIF (i.e. 0, 1 and 3 above) */
  462. /* > \endverbatim */
  463. /* > */
  464. /* > \param[in] WANTQ */
  465. /* > \verbatim */
  466. /* > WANTQ is LOGICAL */
  467. /* > .TRUE. : update the left transformation matrix Q; */
  468. /* > .FALSE.: do not update Q. */
  469. /* > \endverbatim */
  470. /* > */
  471. /* > \param[in] WANTZ */
  472. /* > \verbatim */
  473. /* > WANTZ is LOGICAL */
  474. /* > .TRUE. : update the right transformation matrix Z; */
  475. /* > .FALSE.: do not update Z. */
  476. /* > \endverbatim */
  477. /* > */
  478. /* > \param[in] SELECT */
  479. /* > \verbatim */
  480. /* > SELECT is LOGICAL array, dimension (N) */
  481. /* > SELECT specifies the eigenvalues in the selected cluster. */
  482. /* > To select a real eigenvalue w(j), SELECT(j) must be set to */
  483. /* > .TRUE.. To select a complex conjugate pair of eigenvalues */
  484. /* > w(j) and w(j+1), corresponding to a 2-by-2 diagonal block, */
  485. /* > either SELECT(j) or SELECT(j+1) or both must be set to */
  486. /* > .TRUE.; a complex conjugate pair of eigenvalues must be */
  487. /* > either both included in the cluster or both excluded. */
  488. /* > \endverbatim */
  489. /* > */
  490. /* > \param[in] N */
  491. /* > \verbatim */
  492. /* > N is INTEGER */
  493. /* > The order of the matrices A and B. N >= 0. */
  494. /* > \endverbatim */
  495. /* > */
  496. /* > \param[in,out] A */
  497. /* > \verbatim */
  498. /* > A is REAL array, dimension(LDA,N) */
  499. /* > On entry, the upper quasi-triangular matrix A, with (A, B) in */
  500. /* > generalized real Schur canonical form. */
  501. /* > On exit, A is overwritten by the reordered matrix A. */
  502. /* > \endverbatim */
  503. /* > */
  504. /* > \param[in] LDA */
  505. /* > \verbatim */
  506. /* > LDA is INTEGER */
  507. /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
  508. /* > \endverbatim */
  509. /* > */
  510. /* > \param[in,out] B */
  511. /* > \verbatim */
  512. /* > B is REAL array, dimension(LDB,N) */
  513. /* > On entry, the upper triangular matrix B, with (A, B) in */
  514. /* > generalized real Schur canonical form. */
  515. /* > On exit, B is overwritten by the reordered matrix B. */
  516. /* > \endverbatim */
  517. /* > */
  518. /* > \param[in] LDB */
  519. /* > \verbatim */
  520. /* > LDB is INTEGER */
  521. /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */
  522. /* > \endverbatim */
  523. /* > */
  524. /* > \param[out] ALPHAR */
  525. /* > \verbatim */
  526. /* > ALPHAR is REAL array, dimension (N) */
  527. /* > \endverbatim */
  528. /* > */
  529. /* > \param[out] ALPHAI */
  530. /* > \verbatim */
  531. /* > ALPHAI is REAL array, dimension (N) */
  532. /* > \endverbatim */
  533. /* > */
  534. /* > \param[out] BETA */
  535. /* > \verbatim */
  536. /* > BETA is REAL array, dimension (N) */
  537. /* > */
  538. /* > On exit, (ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N, will */
  539. /* > be the generalized eigenvalues. ALPHAR(j) + ALPHAI(j)*i */
  540. /* > and BETA(j),j=1,...,N are the diagonals of the complex Schur */
  541. /* > form (S,T) that would result if the 2-by-2 diagonal blocks of */
  542. /* > the real generalized Schur form of (A,B) were further reduced */
  543. /* > to triangular form using complex unitary transformations. */
  544. /* > If ALPHAI(j) is zero, then the j-th eigenvalue is real; if */
  545. /* > positive, then the j-th and (j+1)-st eigenvalues are a */
  546. /* > complex conjugate pair, with ALPHAI(j+1) negative. */
  547. /* > \endverbatim */
  548. /* > */
  549. /* > \param[in,out] Q */
  550. /* > \verbatim */
  551. /* > Q is REAL array, dimension (LDQ,N) */
  552. /* > On entry, if WANTQ = .TRUE., Q is an N-by-N matrix. */
  553. /* > On exit, Q has been postmultiplied by the left orthogonal */
  554. /* > transformation matrix which reorder (A, B); The leading M */
  555. /* > columns of Q form orthonormal bases for the specified pair of */
  556. /* > left eigenspaces (deflating subspaces). */
  557. /* > If WANTQ = .FALSE., Q is not referenced. */
  558. /* > \endverbatim */
  559. /* > */
  560. /* > \param[in] LDQ */
  561. /* > \verbatim */
  562. /* > LDQ is INTEGER */
  563. /* > The leading dimension of the array Q. LDQ >= 1; */
  564. /* > and if WANTQ = .TRUE., LDQ >= N. */
  565. /* > \endverbatim */
  566. /* > */
  567. /* > \param[in,out] Z */
  568. /* > \verbatim */
  569. /* > Z is REAL array, dimension (LDZ,N) */
  570. /* > On entry, if WANTZ = .TRUE., Z is an N-by-N matrix. */
  571. /* > On exit, Z has been postmultiplied by the left orthogonal */
  572. /* > transformation matrix which reorder (A, B); The leading M */
  573. /* > columns of Z form orthonormal bases for the specified pair of */
  574. /* > left eigenspaces (deflating subspaces). */
  575. /* > If WANTZ = .FALSE., Z is not referenced. */
  576. /* > \endverbatim */
  577. /* > */
  578. /* > \param[in] LDZ */
  579. /* > \verbatim */
  580. /* > LDZ is INTEGER */
  581. /* > The leading dimension of the array Z. LDZ >= 1; */
  582. /* > If WANTZ = .TRUE., LDZ >= N. */
  583. /* > \endverbatim */
  584. /* > */
  585. /* > \param[out] M */
  586. /* > \verbatim */
  587. /* > M is INTEGER */
  588. /* > The dimension of the specified pair of left and right eigen- */
  589. /* > spaces (deflating subspaces). 0 <= M <= N. */
  590. /* > \endverbatim */
  591. /* > */
  592. /* > \param[out] PL */
  593. /* > \verbatim */
  594. /* > PL is REAL */
  595. /* > \endverbatim */
  596. /* > */
  597. /* > \param[out] PR */
  598. /* > \verbatim */
  599. /* > PR is REAL */
  600. /* > */
  601. /* > If IJOB = 1, 4 or 5, PL, PR are lower bounds on the */
  602. /* > reciprocal of the norm of "projections" onto left and right */
  603. /* > eigenspaces with respect to the selected cluster. */
  604. /* > 0 < PL, PR <= 1. */
  605. /* > If M = 0 or M = N, PL = PR = 1. */
  606. /* > If IJOB = 0, 2 or 3, PL and PR are not referenced. */
  607. /* > \endverbatim */
  608. /* > */
  609. /* > \param[out] DIF */
  610. /* > \verbatim */
  611. /* > DIF is REAL array, dimension (2). */
  612. /* > If IJOB >= 2, DIF(1:2) store the estimates of Difu and Difl. */
  613. /* > If IJOB = 2 or 4, DIF(1:2) are F-norm-based upper bounds on */
  614. /* > Difu and Difl. If IJOB = 3 or 5, DIF(1:2) are 1-norm-based */
  615. /* > estimates of Difu and Difl. */
  616. /* > If M = 0 or N, DIF(1:2) = F-norm([A, B]). */
  617. /* > If IJOB = 0 or 1, DIF is not referenced. */
  618. /* > \endverbatim */
  619. /* > */
  620. /* > \param[out] WORK */
  621. /* > \verbatim */
  622. /* > WORK is REAL array, dimension (MAX(1,LWORK)) */
  623. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  624. /* > \endverbatim */
  625. /* > */
  626. /* > \param[in] LWORK */
  627. /* > \verbatim */
  628. /* > LWORK is INTEGER */
  629. /* > The dimension of the array WORK. LWORK >= 4*N+16. */
  630. /* > If IJOB = 1, 2 or 4, LWORK >= MAX(4*N+16, 2*M*(N-M)). */
  631. /* > If IJOB = 3 or 5, LWORK >= MAX(4*N+16, 4*M*(N-M)). */
  632. /* > */
  633. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  634. /* > only calculates the optimal size of the WORK array, returns */
  635. /* > this value as the first entry of the WORK array, and no error */
  636. /* > message related to LWORK is issued by XERBLA. */
  637. /* > \endverbatim */
  638. /* > */
  639. /* > \param[out] IWORK */
  640. /* > \verbatim */
  641. /* > IWORK is INTEGER array, dimension (MAX(1,LIWORK)) */
  642. /* > On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
  643. /* > \endverbatim */
  644. /* > */
  645. /* > \param[in] LIWORK */
  646. /* > \verbatim */
  647. /* > LIWORK is INTEGER */
  648. /* > The dimension of the array IWORK. LIWORK >= 1. */
  649. /* > If IJOB = 1, 2 or 4, LIWORK >= N+6. */
  650. /* > If IJOB = 3 or 5, LIWORK >= MAX(2*M*(N-M), N+6). */
  651. /* > */
  652. /* > If LIWORK = -1, then a workspace query is assumed; the */
  653. /* > routine only calculates the optimal size of the IWORK array, */
  654. /* > returns this value as the first entry of the IWORK array, and */
  655. /* > no error message related to LIWORK is issued by XERBLA. */
  656. /* > \endverbatim */
  657. /* > */
  658. /* > \param[out] INFO */
  659. /* > \verbatim */
  660. /* > INFO is INTEGER */
  661. /* > =0: Successful exit. */
  662. /* > <0: If INFO = -i, the i-th argument had an illegal value. */
  663. /* > =1: Reordering of (A, B) failed because the transformed */
  664. /* > matrix pair (A, B) would be too far from generalized */
  665. /* > Schur form; the problem is very ill-conditioned. */
  666. /* > (A, B) may have been partially reordered. */
  667. /* > If requested, 0 is returned in DIF(*), PL and PR. */
  668. /* > \endverbatim */
  669. /* Authors: */
  670. /* ======== */
  671. /* > \author Univ. of Tennessee */
  672. /* > \author Univ. of California Berkeley */
  673. /* > \author Univ. of Colorado Denver */
  674. /* > \author NAG Ltd. */
  675. /* > \date June 2016 */
  676. /* > \ingroup realOTHERcomputational */
  677. /* > \par Further Details: */
  678. /* ===================== */
  679. /* > */
  680. /* > \verbatim */
  681. /* > */
  682. /* > STGSEN first collects the selected eigenvalues by computing */
  683. /* > orthogonal U and W that move them to the top left corner of (A, B). */
  684. /* > In other words, the selected eigenvalues are the eigenvalues of */
  685. /* > (A11, B11) in: */
  686. /* > */
  687. /* > U**T*(A, B)*W = (A11 A12) (B11 B12) n1 */
  688. /* > ( 0 A22),( 0 B22) n2 */
  689. /* > n1 n2 n1 n2 */
  690. /* > */
  691. /* > where N = n1+n2 and U**T means the transpose of U. The first n1 columns */
  692. /* > of U and W span the specified pair of left and right eigenspaces */
  693. /* > (deflating subspaces) of (A, B). */
  694. /* > */
  695. /* > If (A, B) has been obtained from the generalized real Schur */
  696. /* > decomposition of a matrix pair (C, D) = Q*(A, B)*Z**T, then the */
  697. /* > reordered generalized real Schur form of (C, D) is given by */
  698. /* > */
  699. /* > (C, D) = (Q*U)*(U**T*(A, B)*W)*(Z*W)**T, */
  700. /* > */
  701. /* > and the first n1 columns of Q*U and Z*W span the corresponding */
  702. /* > deflating subspaces of (C, D) (Q and Z store Q*U and Z*W, resp.). */
  703. /* > */
  704. /* > Note that if the selected eigenvalue is sufficiently ill-conditioned, */
  705. /* > then its value may differ significantly from its value before */
  706. /* > reordering. */
  707. /* > */
  708. /* > The reciprocal condition numbers of the left and right eigenspaces */
  709. /* > spanned by the first n1 columns of U and W (or Q*U and Z*W) may */
  710. /* > be returned in DIF(1:2), corresponding to Difu and Difl, resp. */
  711. /* > */
  712. /* > The Difu and Difl are defined as: */
  713. /* > */
  714. /* > Difu[(A11, B11), (A22, B22)] = sigma-f2cmin( Zu ) */
  715. /* > and */
  716. /* > Difl[(A11, B11), (A22, B22)] = Difu[(A22, B22), (A11, B11)], */
  717. /* > */
  718. /* > where sigma-f2cmin(Zu) is the smallest singular value of the */
  719. /* > (2*n1*n2)-by-(2*n1*n2) matrix */
  720. /* > */
  721. /* > Zu = [ kron(In2, A11) -kron(A22**T, In1) ] */
  722. /* > [ kron(In2, B11) -kron(B22**T, In1) ]. */
  723. /* > */
  724. /* > Here, Inx is the identity matrix of size nx and A22**T is the */
  725. /* > transpose of A22. kron(X, Y) is the Kronecker product between */
  726. /* > the matrices X and Y. */
  727. /* > */
  728. /* > When DIF(2) is small, small changes in (A, B) can cause large changes */
  729. /* > in the deflating subspace. An approximate (asymptotic) bound on the */
  730. /* > maximum angular error in the computed deflating subspaces is */
  731. /* > */
  732. /* > EPS * norm((A, B)) / DIF(2), */
  733. /* > */
  734. /* > where EPS is the machine precision. */
  735. /* > */
  736. /* > The reciprocal norm of the projectors on the left and right */
  737. /* > eigenspaces associated with (A11, B11) may be returned in PL and PR. */
  738. /* > They are computed as follows. First we compute L and R so that */
  739. /* > P*(A, B)*Q is block diagonal, where */
  740. /* > */
  741. /* > P = ( I -L ) n1 Q = ( I R ) n1 */
  742. /* > ( 0 I ) n2 and ( 0 I ) n2 */
  743. /* > n1 n2 n1 n2 */
  744. /* > */
  745. /* > and (L, R) is the solution to the generalized Sylvester equation */
  746. /* > */
  747. /* > A11*R - L*A22 = -A12 */
  748. /* > B11*R - L*B22 = -B12 */
  749. /* > */
  750. /* > Then PL = (F-norm(L)**2+1)**(-1/2) and PR = (F-norm(R)**2+1)**(-1/2). */
  751. /* > An approximate (asymptotic) bound on the average absolute error of */
  752. /* > the selected eigenvalues is */
  753. /* > */
  754. /* > EPS * norm((A, B)) / PL. */
  755. /* > */
  756. /* > There are also global error bounds which valid for perturbations up */
  757. /* > to a certain restriction: A lower bound (x) on the smallest */
  758. /* > F-norm(E,F) for which an eigenvalue of (A11, B11) may move and */
  759. /* > coalesce with an eigenvalue of (A22, B22) under perturbation (E,F), */
  760. /* > (i.e. (A + E, B + F), is */
  761. /* > */
  762. /* > x = f2cmin(Difu,Difl)/((1/(PL*PL)+1/(PR*PR))**(1/2)+2*f2cmax(1/PL,1/PR)). */
  763. /* > */
  764. /* > An approximate bound on x can be computed from DIF(1:2), PL and PR. */
  765. /* > */
  766. /* > If y = ( F-norm(E,F) / x) <= 1, the angles between the perturbed */
  767. /* > (L', R') and unperturbed (L, R) left and right deflating subspaces */
  768. /* > associated with the selected cluster in the (1,1)-blocks can be */
  769. /* > bounded as */
  770. /* > */
  771. /* > f2cmax-angle(L, L') <= arctan( y * PL / (1 - y * (1 - PL * PL)**(1/2)) */
  772. /* > f2cmax-angle(R, R') <= arctan( y * PR / (1 - y * (1 - PR * PR)**(1/2)) */
  773. /* > */
  774. /* > See LAPACK User's Guide section 4.11 or the following references */
  775. /* > for more information. */
  776. /* > */
  777. /* > Note that if the default method for computing the Frobenius-norm- */
  778. /* > based estimate DIF is not wanted (see SLATDF), then the parameter */
  779. /* > IDIFJB (see below) should be changed from 3 to 4 (routine SLATDF */
  780. /* > (IJOB = 2 will be used)). See STGSYL for more details. */
  781. /* > \endverbatim */
  782. /* > \par Contributors: */
  783. /* ================== */
  784. /* > */
  785. /* > Bo Kagstrom and Peter Poromaa, Department of Computing Science, */
  786. /* > Umea University, S-901 87 Umea, Sweden. */
  787. /* > \par References: */
  788. /* ================ */
  789. /* > */
  790. /* > \verbatim */
  791. /* > */
  792. /* > [1] B. Kagstrom; A Direct Method for Reordering Eigenvalues in the */
  793. /* > Generalized Real Schur Form of a Regular Matrix Pair (A, B), in */
  794. /* > M.S. Moonen et al (eds), Linear Algebra for Large Scale and */
  795. /* > Real-Time Applications, Kluwer Academic Publ. 1993, pp 195-218. */
  796. /* > */
  797. /* > [2] B. Kagstrom and P. Poromaa; Computing Eigenspaces with Specified */
  798. /* > Eigenvalues of a Regular Matrix Pair (A, B) and Condition */
  799. /* > Estimation: Theory, Algorithms and Software, */
  800. /* > Report UMINF - 94.04, Department of Computing Science, Umea */
  801. /* > University, S-901 87 Umea, Sweden, 1994. Also as LAPACK Working */
  802. /* > Note 87. To appear in Numerical Algorithms, 1996. */
  803. /* > */
  804. /* > [3] B. Kagstrom and P. Poromaa, LAPACK-Style Algorithms and Software */
  805. /* > for Solving the Generalized Sylvester Equation and Estimating the */
  806. /* > Separation between Regular Matrix Pairs, Report UMINF - 93.23, */
  807. /* > Department of Computing Science, Umea University, S-901 87 Umea, */
  808. /* > Sweden, December 1993, Revised April 1994, Also as LAPACK Working */
  809. /* > Note 75. To appear in ACM Trans. on Math. Software, Vol 22, No 1, */
  810. /* > 1996. */
  811. /* > \endverbatim */
  812. /* > */
  813. /* ===================================================================== */
  814. /* Subroutine */ int stgsen_(integer *ijob, logical *wantq, logical *wantz,
  815. logical *select, integer *n, real *a, integer *lda, real *b, integer *
  816. ldb, real *alphar, real *alphai, real *beta, real *q, integer *ldq,
  817. real *z__, integer *ldz, integer *m, real *pl, real *pr, real *dif,
  818. real *work, integer *lwork, integer *iwork, integer *liwork, integer *
  819. info)
  820. {
  821. /* System generated locals */
  822. integer a_dim1, a_offset, b_dim1, b_offset, q_dim1, q_offset, z_dim1,
  823. z_offset, i__1, i__2;
  824. real r__1;
  825. /* Local variables */
  826. integer kase;
  827. logical pair;
  828. integer ierr;
  829. real dsum;
  830. logical swap;
  831. extern /* Subroutine */ int slag2_(real *, integer *, real *, integer *,
  832. real *, real *, real *, real *, real *, real *);
  833. integer i__, k, isave[3];
  834. logical wantd;
  835. integer lwmin;
  836. logical wantp;
  837. integer n1, n2;
  838. extern /* Subroutine */ int slacn2_(integer *, real *, real *, integer *,
  839. real *, integer *, integer *);
  840. logical wantd1, wantd2;
  841. integer kk;
  842. real dscale;
  843. integer ks;
  844. real rdscal;
  845. extern real slamch_(char *);
  846. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen), slacpy_(
  847. char *, integer *, integer *, real *, integer *, real *, integer *
  848. ), stgexc_(logical *, logical *, integer *, real *,
  849. integer *, real *, integer *, real *, integer *, real *, integer *
  850. , integer *, integer *, real *, integer *, integer *);
  851. integer liwmin;
  852. extern /* Subroutine */ int slassq_(integer *, real *, integer *, real *,
  853. real *);
  854. real smlnum;
  855. integer mn2;
  856. logical lquery;
  857. extern /* Subroutine */ int stgsyl_(char *, integer *, integer *, integer
  858. *, real *, integer *, real *, integer *, real *, integer *, real *
  859. , integer *, real *, integer *, real *, integer *, real *, real *,
  860. real *, integer *, integer *, integer *);
  861. integer ijb;
  862. real eps;
  863. /* -- LAPACK computational routine (version 3.7.0) -- */
  864. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  865. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  866. /* June 2016 */
  867. /* ===================================================================== */
  868. /* Decode and test the input parameters */
  869. /* Parameter adjustments */
  870. --select;
  871. a_dim1 = *lda;
  872. a_offset = 1 + a_dim1 * 1;
  873. a -= a_offset;
  874. b_dim1 = *ldb;
  875. b_offset = 1 + b_dim1 * 1;
  876. b -= b_offset;
  877. --alphar;
  878. --alphai;
  879. --beta;
  880. q_dim1 = *ldq;
  881. q_offset = 1 + q_dim1 * 1;
  882. q -= q_offset;
  883. z_dim1 = *ldz;
  884. z_offset = 1 + z_dim1 * 1;
  885. z__ -= z_offset;
  886. --dif;
  887. --work;
  888. --iwork;
  889. /* Function Body */
  890. *info = 0;
  891. lquery = *lwork == -1 || *liwork == -1;
  892. if (*ijob < 0 || *ijob > 5) {
  893. *info = -1;
  894. } else if (*n < 0) {
  895. *info = -5;
  896. } else if (*lda < f2cmax(1,*n)) {
  897. *info = -7;
  898. } else if (*ldb < f2cmax(1,*n)) {
  899. *info = -9;
  900. } else if (*ldq < 1 || *wantq && *ldq < *n) {
  901. *info = -14;
  902. } else if (*ldz < 1 || *wantz && *ldz < *n) {
  903. *info = -16;
  904. }
  905. if (*info != 0) {
  906. i__1 = -(*info);
  907. xerbla_("STGSEN", &i__1, (ftnlen)6);
  908. return 0;
  909. }
  910. /* Get machine constants */
  911. eps = slamch_("P");
  912. smlnum = slamch_("S") / eps;
  913. ierr = 0;
  914. wantp = *ijob == 1 || *ijob >= 4;
  915. wantd1 = *ijob == 2 || *ijob == 4;
  916. wantd2 = *ijob == 3 || *ijob == 5;
  917. wantd = wantd1 || wantd2;
  918. /* Set M to the dimension of the specified pair of deflating */
  919. /* subspaces. */
  920. *m = 0;
  921. pair = FALSE_;
  922. if (! lquery || *ijob != 0) {
  923. i__1 = *n;
  924. for (k = 1; k <= i__1; ++k) {
  925. if (pair) {
  926. pair = FALSE_;
  927. } else {
  928. if (k < *n) {
  929. if (a[k + 1 + k * a_dim1] == 0.f) {
  930. if (select[k]) {
  931. ++(*m);
  932. }
  933. } else {
  934. pair = TRUE_;
  935. if (select[k] || select[k + 1]) {
  936. *m += 2;
  937. }
  938. }
  939. } else {
  940. if (select[*n]) {
  941. ++(*m);
  942. }
  943. }
  944. }
  945. /* L10: */
  946. }
  947. }
  948. if (*ijob == 1 || *ijob == 2 || *ijob == 4) {
  949. /* Computing MAX */
  950. i__1 = 1, i__2 = (*n << 2) + 16, i__1 = f2cmax(i__1,i__2), i__2 = (*m <<
  951. 1) * (*n - *m);
  952. lwmin = f2cmax(i__1,i__2);
  953. /* Computing MAX */
  954. i__1 = 1, i__2 = *n + 6;
  955. liwmin = f2cmax(i__1,i__2);
  956. } else if (*ijob == 3 || *ijob == 5) {
  957. /* Computing MAX */
  958. i__1 = 1, i__2 = (*n << 2) + 16, i__1 = f2cmax(i__1,i__2), i__2 = (*m <<
  959. 2) * (*n - *m);
  960. lwmin = f2cmax(i__1,i__2);
  961. /* Computing MAX */
  962. i__1 = 1, i__2 = (*m << 1) * (*n - *m), i__1 = f2cmax(i__1,i__2), i__2 =
  963. *n + 6;
  964. liwmin = f2cmax(i__1,i__2);
  965. } else {
  966. /* Computing MAX */
  967. i__1 = 1, i__2 = (*n << 2) + 16;
  968. lwmin = f2cmax(i__1,i__2);
  969. liwmin = 1;
  970. }
  971. work[1] = (real) lwmin;
  972. iwork[1] = liwmin;
  973. if (*lwork < lwmin && ! lquery) {
  974. *info = -22;
  975. } else if (*liwork < liwmin && ! lquery) {
  976. *info = -24;
  977. }
  978. if (*info != 0) {
  979. i__1 = -(*info);
  980. xerbla_("STGSEN", &i__1, (ftnlen)6);
  981. return 0;
  982. } else if (lquery) {
  983. return 0;
  984. }
  985. /* Quick return if possible. */
  986. if (*m == *n || *m == 0) {
  987. if (wantp) {
  988. *pl = 1.f;
  989. *pr = 1.f;
  990. }
  991. if (wantd) {
  992. dscale = 0.f;
  993. dsum = 1.f;
  994. i__1 = *n;
  995. for (i__ = 1; i__ <= i__1; ++i__) {
  996. slassq_(n, &a[i__ * a_dim1 + 1], &c__1, &dscale, &dsum);
  997. slassq_(n, &b[i__ * b_dim1 + 1], &c__1, &dscale, &dsum);
  998. /* L20: */
  999. }
  1000. dif[1] = dscale * sqrt(dsum);
  1001. dif[2] = dif[1];
  1002. }
  1003. goto L60;
  1004. }
  1005. /* Collect the selected blocks at the top-left corner of (A, B). */
  1006. ks = 0;
  1007. pair = FALSE_;
  1008. i__1 = *n;
  1009. for (k = 1; k <= i__1; ++k) {
  1010. if (pair) {
  1011. pair = FALSE_;
  1012. } else {
  1013. swap = select[k];
  1014. if (k < *n) {
  1015. if (a[k + 1 + k * a_dim1] != 0.f) {
  1016. pair = TRUE_;
  1017. swap = swap || select[k + 1];
  1018. }
  1019. }
  1020. if (swap) {
  1021. ++ks;
  1022. /* Swap the K-th block to position KS. */
  1023. /* Perform the reordering of diagonal blocks in (A, B) */
  1024. /* by orthogonal transformation matrices and update */
  1025. /* Q and Z accordingly (if requested): */
  1026. kk = k;
  1027. if (k != ks) {
  1028. stgexc_(wantq, wantz, n, &a[a_offset], lda, &b[b_offset],
  1029. ldb, &q[q_offset], ldq, &z__[z_offset], ldz, &kk,
  1030. &ks, &work[1], lwork, &ierr);
  1031. }
  1032. if (ierr > 0) {
  1033. /* Swap is rejected: exit. */
  1034. *info = 1;
  1035. if (wantp) {
  1036. *pl = 0.f;
  1037. *pr = 0.f;
  1038. }
  1039. if (wantd) {
  1040. dif[1] = 0.f;
  1041. dif[2] = 0.f;
  1042. }
  1043. goto L60;
  1044. }
  1045. if (pair) {
  1046. ++ks;
  1047. }
  1048. }
  1049. }
  1050. /* L30: */
  1051. }
  1052. if (wantp) {
  1053. /* Solve generalized Sylvester equation for R and L */
  1054. /* and compute PL and PR. */
  1055. n1 = *m;
  1056. n2 = *n - *m;
  1057. i__ = n1 + 1;
  1058. ijb = 0;
  1059. slacpy_("Full", &n1, &n2, &a[i__ * a_dim1 + 1], lda, &work[1], &n1);
  1060. slacpy_("Full", &n1, &n2, &b[i__ * b_dim1 + 1], ldb, &work[n1 * n2 +
  1061. 1], &n1);
  1062. i__1 = *lwork - (n1 << 1) * n2;
  1063. stgsyl_("N", &ijb, &n1, &n2, &a[a_offset], lda, &a[i__ + i__ * a_dim1]
  1064. , lda, &work[1], &n1, &b[b_offset], ldb, &b[i__ + i__ *
  1065. b_dim1], ldb, &work[n1 * n2 + 1], &n1, &dscale, &dif[1], &
  1066. work[(n1 * n2 << 1) + 1], &i__1, &iwork[1], &ierr);
  1067. /* Estimate the reciprocal of norms of "projections" onto left */
  1068. /* and right eigenspaces. */
  1069. rdscal = 0.f;
  1070. dsum = 1.f;
  1071. i__1 = n1 * n2;
  1072. slassq_(&i__1, &work[1], &c__1, &rdscal, &dsum);
  1073. *pl = rdscal * sqrt(dsum);
  1074. if (*pl == 0.f) {
  1075. *pl = 1.f;
  1076. } else {
  1077. *pl = dscale / (sqrt(dscale * dscale / *pl + *pl) * sqrt(*pl));
  1078. }
  1079. rdscal = 0.f;
  1080. dsum = 1.f;
  1081. i__1 = n1 * n2;
  1082. slassq_(&i__1, &work[n1 * n2 + 1], &c__1, &rdscal, &dsum);
  1083. *pr = rdscal * sqrt(dsum);
  1084. if (*pr == 0.f) {
  1085. *pr = 1.f;
  1086. } else {
  1087. *pr = dscale / (sqrt(dscale * dscale / *pr + *pr) * sqrt(*pr));
  1088. }
  1089. }
  1090. if (wantd) {
  1091. /* Compute estimates of Difu and Difl. */
  1092. if (wantd1) {
  1093. n1 = *m;
  1094. n2 = *n - *m;
  1095. i__ = n1 + 1;
  1096. ijb = 3;
  1097. /* Frobenius norm-based Difu-estimate. */
  1098. i__1 = *lwork - (n1 << 1) * n2;
  1099. stgsyl_("N", &ijb, &n1, &n2, &a[a_offset], lda, &a[i__ + i__ *
  1100. a_dim1], lda, &work[1], &n1, &b[b_offset], ldb, &b[i__ +
  1101. i__ * b_dim1], ldb, &work[n1 * n2 + 1], &n1, &dscale, &
  1102. dif[1], &work[(n1 << 1) * n2 + 1], &i__1, &iwork[1], &
  1103. ierr);
  1104. /* Frobenius norm-based Difl-estimate. */
  1105. i__1 = *lwork - (n1 << 1) * n2;
  1106. stgsyl_("N", &ijb, &n2, &n1, &a[i__ + i__ * a_dim1], lda, &a[
  1107. a_offset], lda, &work[1], &n2, &b[i__ + i__ * b_dim1],
  1108. ldb, &b[b_offset], ldb, &work[n1 * n2 + 1], &n2, &dscale,
  1109. &dif[2], &work[(n1 << 1) * n2 + 1], &i__1, &iwork[1], &
  1110. ierr);
  1111. } else {
  1112. /* Compute 1-norm-based estimates of Difu and Difl using */
  1113. /* reversed communication with SLACN2. In each step a */
  1114. /* generalized Sylvester equation or a transposed variant */
  1115. /* is solved. */
  1116. kase = 0;
  1117. n1 = *m;
  1118. n2 = *n - *m;
  1119. i__ = n1 + 1;
  1120. ijb = 0;
  1121. mn2 = (n1 << 1) * n2;
  1122. /* 1-norm-based estimate of Difu. */
  1123. L40:
  1124. slacn2_(&mn2, &work[mn2 + 1], &work[1], &iwork[1], &dif[1], &kase,
  1125. isave);
  1126. if (kase != 0) {
  1127. if (kase == 1) {
  1128. /* Solve generalized Sylvester equation. */
  1129. i__1 = *lwork - (n1 << 1) * n2;
  1130. stgsyl_("N", &ijb, &n1, &n2, &a[a_offset], lda, &a[i__ +
  1131. i__ * a_dim1], lda, &work[1], &n1, &b[b_offset],
  1132. ldb, &b[i__ + i__ * b_dim1], ldb, &work[n1 * n2 +
  1133. 1], &n1, &dscale, &dif[1], &work[(n1 << 1) * n2 +
  1134. 1], &i__1, &iwork[1], &ierr);
  1135. } else {
  1136. /* Solve the transposed variant. */
  1137. i__1 = *lwork - (n1 << 1) * n2;
  1138. stgsyl_("T", &ijb, &n1, &n2, &a[a_offset], lda, &a[i__ +
  1139. i__ * a_dim1], lda, &work[1], &n1, &b[b_offset],
  1140. ldb, &b[i__ + i__ * b_dim1], ldb, &work[n1 * n2 +
  1141. 1], &n1, &dscale, &dif[1], &work[(n1 << 1) * n2 +
  1142. 1], &i__1, &iwork[1], &ierr);
  1143. }
  1144. goto L40;
  1145. }
  1146. dif[1] = dscale / dif[1];
  1147. /* 1-norm-based estimate of Difl. */
  1148. L50:
  1149. slacn2_(&mn2, &work[mn2 + 1], &work[1], &iwork[1], &dif[2], &kase,
  1150. isave);
  1151. if (kase != 0) {
  1152. if (kase == 1) {
  1153. /* Solve generalized Sylvester equation. */
  1154. i__1 = *lwork - (n1 << 1) * n2;
  1155. stgsyl_("N", &ijb, &n2, &n1, &a[i__ + i__ * a_dim1], lda,
  1156. &a[a_offset], lda, &work[1], &n2, &b[i__ + i__ *
  1157. b_dim1], ldb, &b[b_offset], ldb, &work[n1 * n2 +
  1158. 1], &n2, &dscale, &dif[2], &work[(n1 << 1) * n2 +
  1159. 1], &i__1, &iwork[1], &ierr);
  1160. } else {
  1161. /* Solve the transposed variant. */
  1162. i__1 = *lwork - (n1 << 1) * n2;
  1163. stgsyl_("T", &ijb, &n2, &n1, &a[i__ + i__ * a_dim1], lda,
  1164. &a[a_offset], lda, &work[1], &n2, &b[i__ + i__ *
  1165. b_dim1], ldb, &b[b_offset], ldb, &work[n1 * n2 +
  1166. 1], &n2, &dscale, &dif[2], &work[(n1 << 1) * n2 +
  1167. 1], &i__1, &iwork[1], &ierr);
  1168. }
  1169. goto L50;
  1170. }
  1171. dif[2] = dscale / dif[2];
  1172. }
  1173. }
  1174. L60:
  1175. /* Compute generalized eigenvalues of reordered pair (A, B) and */
  1176. /* normalize the generalized Schur form. */
  1177. pair = FALSE_;
  1178. i__1 = *n;
  1179. for (k = 1; k <= i__1; ++k) {
  1180. if (pair) {
  1181. pair = FALSE_;
  1182. } else {
  1183. if (k < *n) {
  1184. if (a[k + 1 + k * a_dim1] != 0.f) {
  1185. pair = TRUE_;
  1186. }
  1187. }
  1188. if (pair) {
  1189. /* Compute the eigenvalue(s) at position K. */
  1190. work[1] = a[k + k * a_dim1];
  1191. work[2] = a[k + 1 + k * a_dim1];
  1192. work[3] = a[k + (k + 1) * a_dim1];
  1193. work[4] = a[k + 1 + (k + 1) * a_dim1];
  1194. work[5] = b[k + k * b_dim1];
  1195. work[6] = b[k + 1 + k * b_dim1];
  1196. work[7] = b[k + (k + 1) * b_dim1];
  1197. work[8] = b[k + 1 + (k + 1) * b_dim1];
  1198. r__1 = smlnum * eps;
  1199. slag2_(&work[1], &c__2, &work[5], &c__2, &r__1, &beta[k], &
  1200. beta[k + 1], &alphar[k], &alphar[k + 1], &alphai[k]);
  1201. alphai[k + 1] = -alphai[k];
  1202. } else {
  1203. if (r_sign(&c_b28, &b[k + k * b_dim1]) < 0.f) {
  1204. /* If B(K,K) is negative, make it positive */
  1205. i__2 = *n;
  1206. for (i__ = 1; i__ <= i__2; ++i__) {
  1207. a[k + i__ * a_dim1] = -a[k + i__ * a_dim1];
  1208. b[k + i__ * b_dim1] = -b[k + i__ * b_dim1];
  1209. if (*wantq) {
  1210. q[i__ + k * q_dim1] = -q[i__ + k * q_dim1];
  1211. }
  1212. /* L80: */
  1213. }
  1214. }
  1215. alphar[k] = a[k + k * a_dim1];
  1216. alphai[k] = 0.f;
  1217. beta[k] = b[k + k * b_dim1];
  1218. }
  1219. }
  1220. /* L70: */
  1221. }
  1222. work[1] = (real) lwmin;
  1223. iwork[1] = liwmin;
  1224. return 0;
  1225. /* End of STGSEN */
  1226. } /* stgsen_ */