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.

sggev3.c 29 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <complex.h>
  6. #ifdef complex
  7. #undef complex
  8. #endif
  9. #ifdef I
  10. #undef I
  11. #endif
  12. #if defined(_WIN64)
  13. typedef long long BLASLONG;
  14. typedef unsigned long long BLASULONG;
  15. #else
  16. typedef long BLASLONG;
  17. typedef unsigned long BLASULONG;
  18. #endif
  19. #ifdef LAPACK_ILP64
  20. typedef BLASLONG blasint;
  21. #if defined(_WIN64)
  22. #define blasabs(x) llabs(x)
  23. #else
  24. #define blasabs(x) labs(x)
  25. #endif
  26. #else
  27. typedef int blasint;
  28. #define blasabs(x) abs(x)
  29. #endif
  30. typedef blasint integer;
  31. typedef unsigned int uinteger;
  32. typedef char *address;
  33. typedef short int shortint;
  34. typedef float real;
  35. typedef double doublereal;
  36. typedef struct { real r, i; } complex;
  37. typedef struct { doublereal r, i; } doublecomplex;
  38. #ifdef _MSC_VER
  39. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  40. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  41. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  42. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  43. #else
  44. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  47. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  48. #endif
  49. #define pCf(z) (*_pCf(z))
  50. #define pCd(z) (*_pCd(z))
  51. typedef blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  172. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #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++ = ' '; }
  217. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  218. #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]; }
  219. #define sig_die(s, kill) { exit(1); }
  220. #define s_stop(s, n) {exit(0);}
  221. #define z_abs(z) (cabs(Cd(z)))
  222. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  223. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  224. #define myexit_() break;
  225. #define mycycle() continue;
  226. #define myceiling(w) {ceil(w)}
  227. #define myhuge(w) {HUGE_VAL}
  228. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  229. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  230. /* -- translated by f2c (version 20000121).
  231. You must link the resulting object file with the libraries:
  232. -lf2c -lm (in that order)
  233. */
  234. /* Table of constant values */
  235. static integer c_n1 = -1;
  236. static integer c__1 = 1;
  237. static integer c__0 = 0;
  238. static real c_b34 = 0.f;
  239. static real c_b35 = 1.f;
  240. /* > \brief <b> SGGEV3 computes the eigenvalues and, optionally, the left and/or right eigenvectors for GE mat
  241. rices (blocked algorithm)</b> */
  242. /* =========== DOCUMENTATION =========== */
  243. /* Online html documentation available at */
  244. /* http://www.netlib.org/lapack/explore-html/ */
  245. /* > \htmlonly */
  246. /* > Download SGGEV3 + dependencies */
  247. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sggev3.
  248. f"> */
  249. /* > [TGZ]</a> */
  250. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sggev3.
  251. f"> */
  252. /* > [ZIP]</a> */
  253. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sggev3.
  254. f"> */
  255. /* > [TXT]</a> */
  256. /* > \endhtmlonly */
  257. /* Definition: */
  258. /* =========== */
  259. /* SUBROUTINE SGGEV3( JOBVL, JOBVR, N, A, LDA, B, LDB, ALPHAR, */
  260. /* $ ALPHAI, BETA, VL, LDVL, VR, LDVR, WORK, LWORK, */
  261. /* $ INFO ) */
  262. /* CHARACTER JOBVL, JOBVR */
  263. /* INTEGER INFO, LDA, LDB, LDVL, LDVR, LWORK, N */
  264. /* REAL A( LDA, * ), ALPHAI( * ), ALPHAR( * ), */
  265. /* $ B( LDB, * ), BETA( * ), VL( LDVL, * ), */
  266. /* $ VR( LDVR, * ), WORK( * ) */
  267. /* > \par Purpose: */
  268. /* ============= */
  269. /* > */
  270. /* > \verbatim */
  271. /* > */
  272. /* > SGGEV3 computes for a pair of N-by-N real nonsymmetric matrices (A,B) */
  273. /* > the generalized eigenvalues, and optionally, the left and/or right */
  274. /* > generalized eigenvectors. */
  275. /* > */
  276. /* > A generalized eigenvalue for a pair of matrices (A,B) is a scalar */
  277. /* > lambda or a ratio alpha/beta = lambda, such that A - lambda*B is */
  278. /* > singular. It is usually represented as the pair (alpha,beta), as */
  279. /* > there is a reasonable interpretation for beta=0, and even for both */
  280. /* > being zero. */
  281. /* > */
  282. /* > The right eigenvector v(j) corresponding to the eigenvalue lambda(j) */
  283. /* > of (A,B) satisfies */
  284. /* > */
  285. /* > A * v(j) = lambda(j) * B * v(j). */
  286. /* > */
  287. /* > The left eigenvector u(j) corresponding to the eigenvalue lambda(j) */
  288. /* > of (A,B) satisfies */
  289. /* > */
  290. /* > u(j)**H * A = lambda(j) * u(j)**H * B . */
  291. /* > */
  292. /* > where u(j)**H is the conjugate-transpose of u(j). */
  293. /* > */
  294. /* > \endverbatim */
  295. /* Arguments: */
  296. /* ========== */
  297. /* > \param[in] JOBVL */
  298. /* > \verbatim */
  299. /* > JOBVL is CHARACTER*1 */
  300. /* > = 'N': do not compute the left generalized eigenvectors; */
  301. /* > = 'V': compute the left generalized eigenvectors. */
  302. /* > \endverbatim */
  303. /* > */
  304. /* > \param[in] JOBVR */
  305. /* > \verbatim */
  306. /* > JOBVR is CHARACTER*1 */
  307. /* > = 'N': do not compute the right generalized eigenvectors; */
  308. /* > = 'V': compute the right generalized eigenvectors. */
  309. /* > \endverbatim */
  310. /* > */
  311. /* > \param[in] N */
  312. /* > \verbatim */
  313. /* > N is INTEGER */
  314. /* > The order of the matrices A, B, VL, and VR. N >= 0. */
  315. /* > \endverbatim */
  316. /* > */
  317. /* > \param[in,out] A */
  318. /* > \verbatim */
  319. /* > A is REAL array, dimension (LDA, N) */
  320. /* > On entry, the matrix A in the pair (A,B). */
  321. /* > On exit, A has been overwritten. */
  322. /* > \endverbatim */
  323. /* > */
  324. /* > \param[in] LDA */
  325. /* > \verbatim */
  326. /* > LDA is INTEGER */
  327. /* > The leading dimension of A. LDA >= f2cmax(1,N). */
  328. /* > \endverbatim */
  329. /* > */
  330. /* > \param[in,out] B */
  331. /* > \verbatim */
  332. /* > B is REAL array, dimension (LDB, N) */
  333. /* > On entry, the matrix B in the pair (A,B). */
  334. /* > On exit, B has been overwritten. */
  335. /* > \endverbatim */
  336. /* > */
  337. /* > \param[in] LDB */
  338. /* > \verbatim */
  339. /* > LDB is INTEGER */
  340. /* > The leading dimension of B. LDB >= f2cmax(1,N). */
  341. /* > \endverbatim */
  342. /* > */
  343. /* > \param[out] ALPHAR */
  344. /* > \verbatim */
  345. /* > ALPHAR is REAL array, dimension (N) */
  346. /* > \endverbatim */
  347. /* > */
  348. /* > \param[out] ALPHAI */
  349. /* > \verbatim */
  350. /* > ALPHAI is REAL array, dimension (N) */
  351. /* > \endverbatim */
  352. /* > */
  353. /* > \param[out] BETA */
  354. /* > \verbatim */
  355. /* > BETA is REAL array, dimension (N) */
  356. /* > On exit, (ALPHAR(j) + ALPHAI(j)*i)/BETA(j), j=1,...,N, will */
  357. /* > be the generalized eigenvalues. If ALPHAI(j) is zero, then */
  358. /* > the j-th eigenvalue is real; if positive, then the j-th and */
  359. /* > (j+1)-st eigenvalues are a complex conjugate pair, with */
  360. /* > ALPHAI(j+1) negative. */
  361. /* > */
  362. /* > Note: the quotients ALPHAR(j)/BETA(j) and ALPHAI(j)/BETA(j) */
  363. /* > may easily over- or underflow, and BETA(j) may even be zero. */
  364. /* > Thus, the user should avoid naively computing the ratio */
  365. /* > alpha/beta. However, ALPHAR and ALPHAI will be always less */
  366. /* > than and usually comparable with norm(A) in magnitude, and */
  367. /* > BETA always less than and usually comparable with norm(B). */
  368. /* > \endverbatim */
  369. /* > */
  370. /* > \param[out] VL */
  371. /* > \verbatim */
  372. /* > VL is REAL array, dimension (LDVL,N) */
  373. /* > If JOBVL = 'V', the left eigenvectors u(j) are stored one */
  374. /* > after another in the columns of VL, in the same order as */
  375. /* > their eigenvalues. If the j-th eigenvalue is real, then */
  376. /* > u(j) = VL(:,j), the j-th column of VL. If the j-th and */
  377. /* > (j+1)-th eigenvalues form a complex conjugate pair, then */
  378. /* > u(j) = VL(:,j)+i*VL(:,j+1) and u(j+1) = VL(:,j)-i*VL(:,j+1). */
  379. /* > Each eigenvector is scaled so the largest component has */
  380. /* > abs(real part)+abs(imag. part)=1. */
  381. /* > Not referenced if JOBVL = 'N'. */
  382. /* > \endverbatim */
  383. /* > */
  384. /* > \param[in] LDVL */
  385. /* > \verbatim */
  386. /* > LDVL is INTEGER */
  387. /* > The leading dimension of the matrix VL. LDVL >= 1, and */
  388. /* > if JOBVL = 'V', LDVL >= N. */
  389. /* > \endverbatim */
  390. /* > */
  391. /* > \param[out] VR */
  392. /* > \verbatim */
  393. /* > VR is REAL array, dimension (LDVR,N) */
  394. /* > If JOBVR = 'V', the right eigenvectors v(j) are stored one */
  395. /* > after another in the columns of VR, in the same order as */
  396. /* > their eigenvalues. If the j-th eigenvalue is real, then */
  397. /* > v(j) = VR(:,j), the j-th column of VR. If the j-th and */
  398. /* > (j+1)-th eigenvalues form a complex conjugate pair, then */
  399. /* > v(j) = VR(:,j)+i*VR(:,j+1) and v(j+1) = VR(:,j)-i*VR(:,j+1). */
  400. /* > Each eigenvector is scaled so the largest component has */
  401. /* > abs(real part)+abs(imag. part)=1. */
  402. /* > Not referenced if JOBVR = 'N'. */
  403. /* > \endverbatim */
  404. /* > */
  405. /* > \param[in] LDVR */
  406. /* > \verbatim */
  407. /* > LDVR is INTEGER */
  408. /* > The leading dimension of the matrix VR. LDVR >= 1, and */
  409. /* > if JOBVR = 'V', LDVR >= N. */
  410. /* > \endverbatim */
  411. /* > */
  412. /* > \param[out] WORK */
  413. /* > \verbatim */
  414. /* > WORK is REAL array, dimension (MAX(1,LWORK)) */
  415. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  416. /* > \endverbatim */
  417. /* > */
  418. /* > \param[in] LWORK */
  419. /* > \verbatim */
  420. /* > LWORK is INTEGER */
  421. /* > */
  422. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  423. /* > only calculates the optimal size of the WORK array, returns */
  424. /* > this value as the first entry of the WORK array, and no error */
  425. /* > message related to LWORK is issued by XERBLA. */
  426. /* > \endverbatim */
  427. /* > */
  428. /* > \param[out] INFO */
  429. /* > \verbatim */
  430. /* > INFO is INTEGER */
  431. /* > = 0: successful exit */
  432. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  433. /* > = 1,...,N: */
  434. /* > The QZ iteration failed. No eigenvectors have been */
  435. /* > calculated, but ALPHAR(j), ALPHAI(j), and BETA(j) */
  436. /* > should be correct for j=INFO+1,...,N. */
  437. /* > > N: =N+1: other than QZ iteration failed in SHGEQZ. */
  438. /* > =N+2: error return from STGEVC. */
  439. /* > \endverbatim */
  440. /* Authors: */
  441. /* ======== */
  442. /* > \author Univ. of Tennessee */
  443. /* > \author Univ. of California Berkeley */
  444. /* > \author Univ. of Colorado Denver */
  445. /* > \author NAG Ltd. */
  446. /* > \date January 2015 */
  447. /* > \ingroup realGEeigen */
  448. /* ===================================================================== */
  449. /* Subroutine */ void sggev3_(char *jobvl, char *jobvr, integer *n, real *a,
  450. integer *lda, real *b, integer *ldb, real *alphar, real *alphai, real
  451. *beta, real *vl, integer *ldvl, real *vr, integer *ldvr, real *work,
  452. integer *lwork, integer *info)
  453. {
  454. /* System generated locals */
  455. integer a_dim1, a_offset, b_dim1, b_offset, vl_dim1, vl_offset, vr_dim1,
  456. vr_offset, i__1, i__2;
  457. real r__1, r__2, r__3, r__4;
  458. /* Local variables */
  459. real anrm, bnrm;
  460. integer ierr, itau;
  461. real temp;
  462. logical ilvl, ilvr;
  463. integer iwrk;
  464. extern logical lsame_(char *, char *);
  465. integer ileft, icols, irows;
  466. extern /* Subroutine */ void sgghd3_(char *, char *, integer *, integer *,
  467. integer *, real *, integer *, real *, integer *, real *, integer *
  468. , real *, integer *, real *, integer *, integer *)
  469. ;
  470. integer jc;
  471. extern /* Subroutine */ void slabad_(real *, real *);
  472. integer in, jr;
  473. extern /* Subroutine */ void sggbak_(char *, char *, integer *, integer *,
  474. integer *, real *, real *, integer *, real *, integer *, integer *
  475. ), sggbal_(char *, integer *, real *, integer *,
  476. real *, integer *, integer *, integer *, real *, real *, real *,
  477. integer *);
  478. logical ilascl, ilbscl;
  479. extern real slamch_(char *), slange_(char *, integer *, integer *,
  480. real *, integer *, real *);
  481. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  482. logical ldumma[1];
  483. char chtemp[1];
  484. real bignum;
  485. extern /* Subroutine */ void slascl_(char *, integer *, integer *, real *,
  486. real *, integer *, integer *, real *, integer *, integer *);
  487. integer ijobvl, iright;
  488. extern /* Subroutine */ void sgeqrf_(integer *, integer *, real *, integer
  489. *, real *, real *, integer *, integer *);
  490. integer ijobvr;
  491. extern /* Subroutine */ void slacpy_(char *, integer *, integer *, real *,
  492. integer *, real *, integer *), slaset_(char *, integer *,
  493. integer *, real *, real *, real *, integer *), stgevc_(
  494. char *, char *, logical *, integer *, real *, integer *, real *,
  495. integer *, real *, integer *, real *, integer *, integer *,
  496. integer *, real *, integer *);
  497. real anrmto, bnrmto;
  498. extern /* Subroutine */ void shgeqz_(char *, char *, char *, integer *,
  499. integer *, integer *, real *, integer *, real *, integer *, real *
  500. , real *, real *, real *, integer *, real *, integer *, real *,
  501. integer *, integer *);
  502. real smlnum;
  503. extern /* Subroutine */ void sorgqr_(integer *, integer *, integer *, real
  504. *, integer *, real *, real *, integer *, integer *);
  505. integer lwkopt;
  506. logical lquery;
  507. extern /* Subroutine */ void sormqr_(char *, char *, integer *, integer *,
  508. integer *, real *, integer *, real *, real *, integer *, real *,
  509. integer *, integer *);
  510. integer ihi, ilo;
  511. real eps;
  512. logical ilv;
  513. /* -- LAPACK driver routine (version 3.6.0) -- */
  514. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  515. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  516. /* January 2015 */
  517. /* ===================================================================== */
  518. /* Decode the input arguments */
  519. /* Parameter adjustments */
  520. a_dim1 = *lda;
  521. a_offset = 1 + a_dim1 * 1;
  522. a -= a_offset;
  523. b_dim1 = *ldb;
  524. b_offset = 1 + b_dim1 * 1;
  525. b -= b_offset;
  526. --alphar;
  527. --alphai;
  528. --beta;
  529. vl_dim1 = *ldvl;
  530. vl_offset = 1 + vl_dim1 * 1;
  531. vl -= vl_offset;
  532. vr_dim1 = *ldvr;
  533. vr_offset = 1 + vr_dim1 * 1;
  534. vr -= vr_offset;
  535. --work;
  536. /* Function Body */
  537. if (lsame_(jobvl, "N")) {
  538. ijobvl = 1;
  539. ilvl = FALSE_;
  540. } else if (lsame_(jobvl, "V")) {
  541. ijobvl = 2;
  542. ilvl = TRUE_;
  543. } else {
  544. ijobvl = -1;
  545. ilvl = FALSE_;
  546. }
  547. if (lsame_(jobvr, "N")) {
  548. ijobvr = 1;
  549. ilvr = FALSE_;
  550. } else if (lsame_(jobvr, "V")) {
  551. ijobvr = 2;
  552. ilvr = TRUE_;
  553. } else {
  554. ijobvr = -1;
  555. ilvr = FALSE_;
  556. }
  557. ilv = ilvl || ilvr;
  558. /* Test the input arguments */
  559. *info = 0;
  560. lquery = *lwork == -1;
  561. if (ijobvl <= 0) {
  562. *info = -1;
  563. } else if (ijobvr <= 0) {
  564. *info = -2;
  565. } else if (*n < 0) {
  566. *info = -3;
  567. } else if (*lda < f2cmax(1,*n)) {
  568. *info = -5;
  569. } else if (*ldb < f2cmax(1,*n)) {
  570. *info = -7;
  571. } else if (*ldvl < 1 || ilvl && *ldvl < *n) {
  572. *info = -12;
  573. } else if (*ldvr < 1 || ilvr && *ldvr < *n) {
  574. *info = -14;
  575. } else /* if(complicated condition) */ {
  576. /* Computing MAX */
  577. i__1 = 1, i__2 = *n << 3;
  578. if (*lwork < f2cmax(i__1,i__2) && ! lquery) {
  579. *info = -16;
  580. }
  581. }
  582. /* Compute workspace */
  583. if (*info == 0) {
  584. sgeqrf_(n, n, &b[b_offset], ldb, &work[1], &work[1], &c_n1, &ierr);
  585. /* Computing MAX */
  586. i__1 = 1, i__2 = *n << 3, i__1 = f2cmax(i__1,i__2), i__2 = *n * 3 + (
  587. integer) work[1];
  588. lwkopt = f2cmax(i__1,i__2);
  589. sormqr_("L", "T", n, n, n, &b[b_offset], ldb, &work[1], &a[a_offset],
  590. lda, &work[1], &c_n1, &ierr);
  591. /* Computing MAX */
  592. i__1 = lwkopt, i__2 = *n * 3 + (integer) work[1];
  593. lwkopt = f2cmax(i__1,i__2);
  594. sgghd3_(jobvl, jobvr, n, &c__1, n, &a[a_offset], lda, &b[b_offset],
  595. ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, &work[1], &
  596. c_n1, &ierr);
  597. /* Computing MAX */
  598. i__1 = lwkopt, i__2 = *n * 3 + (integer) work[1];
  599. lwkopt = f2cmax(i__1,i__2);
  600. if (ilvl) {
  601. sorgqr_(n, n, n, &vl[vl_offset], ldvl, &work[1], &work[1], &c_n1,
  602. &ierr);
  603. /* Computing MAX */
  604. i__1 = lwkopt, i__2 = *n * 3 + (integer) work[1];
  605. lwkopt = f2cmax(i__1,i__2);
  606. shgeqz_("S", jobvl, jobvr, n, &c__1, n, &a[a_offset], lda, &b[
  607. b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vl[
  608. vl_offset], ldvl, &vr[vr_offset], ldvr, &work[1], &c_n1, &
  609. ierr);
  610. /* Computing MAX */
  611. i__1 = lwkopt, i__2 = (*n << 1) + (integer) work[1];
  612. lwkopt = f2cmax(i__1,i__2);
  613. } else {
  614. shgeqz_("E", jobvl, jobvr, n, &c__1, n, &a[a_offset], lda, &b[
  615. b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vl[
  616. vl_offset], ldvl, &vr[vr_offset], ldvr, &work[1], &c_n1, &
  617. ierr);
  618. /* Computing MAX */
  619. i__1 = lwkopt, i__2 = (*n << 1) + (integer) work[1];
  620. lwkopt = f2cmax(i__1,i__2);
  621. }
  622. work[1] = (real) lwkopt;
  623. }
  624. if (*info != 0) {
  625. i__1 = -(*info);
  626. xerbla_("SGGEV3 ", &i__1, (ftnlen)7);
  627. return;
  628. } else if (lquery) {
  629. return;
  630. }
  631. /* Quick return if possible */
  632. if (*n == 0) {
  633. return;
  634. }
  635. /* Get machine constants */
  636. eps = slamch_("P");
  637. smlnum = slamch_("S");
  638. bignum = 1.f / smlnum;
  639. slabad_(&smlnum, &bignum);
  640. smlnum = sqrt(smlnum) / eps;
  641. bignum = 1.f / smlnum;
  642. /* Scale A if f2cmax element outside range [SMLNUM,BIGNUM] */
  643. anrm = slange_("M", n, n, &a[a_offset], lda, &work[1]);
  644. ilascl = FALSE_;
  645. if (anrm > 0.f && anrm < smlnum) {
  646. anrmto = smlnum;
  647. ilascl = TRUE_;
  648. } else if (anrm > bignum) {
  649. anrmto = bignum;
  650. ilascl = TRUE_;
  651. }
  652. if (ilascl) {
  653. slascl_("G", &c__0, &c__0, &anrm, &anrmto, n, n, &a[a_offset], lda, &
  654. ierr);
  655. }
  656. /* Scale B if f2cmax element outside range [SMLNUM,BIGNUM] */
  657. bnrm = slange_("M", n, n, &b[b_offset], ldb, &work[1]);
  658. ilbscl = FALSE_;
  659. if (bnrm > 0.f && bnrm < smlnum) {
  660. bnrmto = smlnum;
  661. ilbscl = TRUE_;
  662. } else if (bnrm > bignum) {
  663. bnrmto = bignum;
  664. ilbscl = TRUE_;
  665. }
  666. if (ilbscl) {
  667. slascl_("G", &c__0, &c__0, &bnrm, &bnrmto, n, n, &b[b_offset], ldb, &
  668. ierr);
  669. }
  670. /* Permute the matrices A, B to isolate eigenvalues if possible */
  671. ileft = 1;
  672. iright = *n + 1;
  673. iwrk = iright + *n;
  674. sggbal_("P", n, &a[a_offset], lda, &b[b_offset], ldb, &ilo, &ihi, &work[
  675. ileft], &work[iright], &work[iwrk], &ierr);
  676. /* Reduce B to triangular form (QR decomposition of B) */
  677. irows = ihi + 1 - ilo;
  678. if (ilv) {
  679. icols = *n + 1 - ilo;
  680. } else {
  681. icols = irows;
  682. }
  683. itau = iwrk;
  684. iwrk = itau + irows;
  685. i__1 = *lwork + 1 - iwrk;
  686. sgeqrf_(&irows, &icols, &b[ilo + ilo * b_dim1], ldb, &work[itau], &work[
  687. iwrk], &i__1, &ierr);
  688. /* Apply the orthogonal transformation to matrix A */
  689. i__1 = *lwork + 1 - iwrk;
  690. sormqr_("L", "T", &irows, &icols, &irows, &b[ilo + ilo * b_dim1], ldb, &
  691. work[itau], &a[ilo + ilo * a_dim1], lda, &work[iwrk], &i__1, &
  692. ierr);
  693. /* Initialize VL */
  694. if (ilvl) {
  695. slaset_("Full", n, n, &c_b34, &c_b35, &vl[vl_offset], ldvl)
  696. ;
  697. if (irows > 1) {
  698. i__1 = irows - 1;
  699. i__2 = irows - 1;
  700. slacpy_("L", &i__1, &i__2, &b[ilo + 1 + ilo * b_dim1], ldb, &vl[
  701. ilo + 1 + ilo * vl_dim1], ldvl);
  702. }
  703. i__1 = *lwork + 1 - iwrk;
  704. sorgqr_(&irows, &irows, &irows, &vl[ilo + ilo * vl_dim1], ldvl, &work[
  705. itau], &work[iwrk], &i__1, &ierr);
  706. }
  707. /* Initialize VR */
  708. if (ilvr) {
  709. slaset_("Full", n, n, &c_b34, &c_b35, &vr[vr_offset], ldvr)
  710. ;
  711. }
  712. /* Reduce to generalized Hessenberg form */
  713. if (ilv) {
  714. /* Eigenvectors requested -- work on whole matrix. */
  715. i__1 = *lwork + 1 - iwrk;
  716. sgghd3_(jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[b_offset],
  717. ldb, &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, &work[iwrk],
  718. &i__1, &ierr);
  719. } else {
  720. i__1 = *lwork + 1 - iwrk;
  721. sgghd3_("N", "N", &irows, &c__1, &irows, &a[ilo + ilo * a_dim1], lda,
  722. &b[ilo + ilo * b_dim1], ldb, &vl[vl_offset], ldvl, &vr[
  723. vr_offset], ldvr, &work[iwrk], &i__1, &ierr);
  724. }
  725. /* Perform QZ algorithm (Compute eigenvalues, and optionally, the */
  726. /* Schur forms and Schur vectors) */
  727. iwrk = itau;
  728. if (ilv) {
  729. *(unsigned char *)chtemp = 'S';
  730. } else {
  731. *(unsigned char *)chtemp = 'E';
  732. }
  733. i__1 = *lwork + 1 - iwrk;
  734. shgeqz_(chtemp, jobvl, jobvr, n, &ilo, &ihi, &a[a_offset], lda, &b[
  735. b_offset], ldb, &alphar[1], &alphai[1], &beta[1], &vl[vl_offset],
  736. ldvl, &vr[vr_offset], ldvr, &work[iwrk], &i__1, &ierr);
  737. if (ierr != 0) {
  738. if (ierr > 0 && ierr <= *n) {
  739. *info = ierr;
  740. } else if (ierr > *n && ierr <= *n << 1) {
  741. *info = ierr - *n;
  742. } else {
  743. *info = *n + 1;
  744. }
  745. goto L110;
  746. }
  747. /* Compute Eigenvectors */
  748. if (ilv) {
  749. if (ilvl) {
  750. if (ilvr) {
  751. *(unsigned char *)chtemp = 'B';
  752. } else {
  753. *(unsigned char *)chtemp = 'L';
  754. }
  755. } else {
  756. *(unsigned char *)chtemp = 'R';
  757. }
  758. stgevc_(chtemp, "B", ldumma, n, &a[a_offset], lda, &b[b_offset], ldb,
  759. &vl[vl_offset], ldvl, &vr[vr_offset], ldvr, n, &in, &work[
  760. iwrk], &ierr);
  761. if (ierr != 0) {
  762. *info = *n + 2;
  763. goto L110;
  764. }
  765. /* Undo balancing on VL and VR and normalization */
  766. if (ilvl) {
  767. sggbak_("P", "L", n, &ilo, &ihi, &work[ileft], &work[iright], n, &
  768. vl[vl_offset], ldvl, &ierr);
  769. i__1 = *n;
  770. for (jc = 1; jc <= i__1; ++jc) {
  771. if (alphai[jc] < 0.f) {
  772. goto L50;
  773. }
  774. temp = 0.f;
  775. if (alphai[jc] == 0.f) {
  776. i__2 = *n;
  777. for (jr = 1; jr <= i__2; ++jr) {
  778. /* Computing MAX */
  779. r__2 = temp, r__3 = (r__1 = vl[jr + jc * vl_dim1],
  780. abs(r__1));
  781. temp = f2cmax(r__2,r__3);
  782. /* L10: */
  783. }
  784. } else {
  785. i__2 = *n;
  786. for (jr = 1; jr <= i__2; ++jr) {
  787. /* Computing MAX */
  788. r__3 = temp, r__4 = (r__1 = vl[jr + jc * vl_dim1],
  789. abs(r__1)) + (r__2 = vl[jr + (jc + 1) *
  790. vl_dim1], abs(r__2));
  791. temp = f2cmax(r__3,r__4);
  792. /* L20: */
  793. }
  794. }
  795. if (temp < smlnum) {
  796. goto L50;
  797. }
  798. temp = 1.f / temp;
  799. if (alphai[jc] == 0.f) {
  800. i__2 = *n;
  801. for (jr = 1; jr <= i__2; ++jr) {
  802. vl[jr + jc * vl_dim1] *= temp;
  803. /* L30: */
  804. }
  805. } else {
  806. i__2 = *n;
  807. for (jr = 1; jr <= i__2; ++jr) {
  808. vl[jr + jc * vl_dim1] *= temp;
  809. vl[jr + (jc + 1) * vl_dim1] *= temp;
  810. /* L40: */
  811. }
  812. }
  813. L50:
  814. ;
  815. }
  816. }
  817. if (ilvr) {
  818. sggbak_("P", "R", n, &ilo, &ihi, &work[ileft], &work[iright], n, &
  819. vr[vr_offset], ldvr, &ierr);
  820. i__1 = *n;
  821. for (jc = 1; jc <= i__1; ++jc) {
  822. if (alphai[jc] < 0.f) {
  823. goto L100;
  824. }
  825. temp = 0.f;
  826. if (alphai[jc] == 0.f) {
  827. i__2 = *n;
  828. for (jr = 1; jr <= i__2; ++jr) {
  829. /* Computing MAX */
  830. r__2 = temp, r__3 = (r__1 = vr[jr + jc * vr_dim1],
  831. abs(r__1));
  832. temp = f2cmax(r__2,r__3);
  833. /* L60: */
  834. }
  835. } else {
  836. i__2 = *n;
  837. for (jr = 1; jr <= i__2; ++jr) {
  838. /* Computing MAX */
  839. r__3 = temp, r__4 = (r__1 = vr[jr + jc * vr_dim1],
  840. abs(r__1)) + (r__2 = vr[jr + (jc + 1) *
  841. vr_dim1], abs(r__2));
  842. temp = f2cmax(r__3,r__4);
  843. /* L70: */
  844. }
  845. }
  846. if (temp < smlnum) {
  847. goto L100;
  848. }
  849. temp = 1.f / temp;
  850. if (alphai[jc] == 0.f) {
  851. i__2 = *n;
  852. for (jr = 1; jr <= i__2; ++jr) {
  853. vr[jr + jc * vr_dim1] *= temp;
  854. /* L80: */
  855. }
  856. } else {
  857. i__2 = *n;
  858. for (jr = 1; jr <= i__2; ++jr) {
  859. vr[jr + jc * vr_dim1] *= temp;
  860. vr[jr + (jc + 1) * vr_dim1] *= temp;
  861. /* L90: */
  862. }
  863. }
  864. L100:
  865. ;
  866. }
  867. }
  868. /* End of eigenvector calculation */
  869. }
  870. /* Undo scaling if necessary */
  871. L110:
  872. if (ilascl) {
  873. slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphar[1], n, &
  874. ierr);
  875. slascl_("G", &c__0, &c__0, &anrmto, &anrm, n, &c__1, &alphai[1], n, &
  876. ierr);
  877. }
  878. if (ilbscl) {
  879. slascl_("G", &c__0, &c__0, &bnrmto, &bnrm, n, &c__1, &beta[1], n, &
  880. ierr);
  881. }
  882. work[1] = (real) lwkopt;
  883. return;
  884. /* End of SGGEV3 */
  885. } /* sggev3_ */