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.

shseqr.c 28 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  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 real c_b11 = 0.f;
  236. static real c_b12 = 1.f;
  237. static integer c__12 = 12;
  238. static integer c__2 = 2;
  239. static integer c__49 = 49;
  240. /* > \brief \b SHSEQR */
  241. /* =========== DOCUMENTATION =========== */
  242. /* Online html documentation available at */
  243. /* http://www.netlib.org/lapack/explore-html/ */
  244. /* > \htmlonly */
  245. /* > Download SHSEQR + dependencies */
  246. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/shseqr.
  247. f"> */
  248. /* > [TGZ]</a> */
  249. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/shseqr.
  250. f"> */
  251. /* > [ZIP]</a> */
  252. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/shseqr.
  253. f"> */
  254. /* > [TXT]</a> */
  255. /* > \endhtmlonly */
  256. /* Definition: */
  257. /* =========== */
  258. /* SUBROUTINE SHSEQR( JOB, COMPZ, N, ILO, IHI, H, LDH, WR, WI, Z, */
  259. /* LDZ, WORK, LWORK, INFO ) */
  260. /* INTEGER IHI, ILO, INFO, LDH, LDZ, LWORK, N */
  261. /* CHARACTER COMPZ, JOB */
  262. /* REAL H( LDH, * ), WI( * ), WORK( * ), WR( * ), */
  263. /* $ Z( LDZ, * ) */
  264. /* > \par Purpose: */
  265. /* ============= */
  266. /* > */
  267. /* > \verbatim */
  268. /* > */
  269. /* > SHSEQR computes the eigenvalues of a Hessenberg matrix H */
  270. /* > and, optionally, the matrices T and Z from the Schur decomposition */
  271. /* > H = Z T Z**T, where T is an upper quasi-triangular matrix (the */
  272. /* > Schur form), and Z is the orthogonal matrix of Schur vectors. */
  273. /* > */
  274. /* > Optionally Z may be postmultiplied into an input orthogonal */
  275. /* > matrix Q so that this routine can give the Schur factorization */
  276. /* > of a matrix A which has been reduced to the Hessenberg form H */
  277. /* > by the orthogonal matrix Q: A = Q*H*Q**T = (QZ)*T*(QZ)**T. */
  278. /* > \endverbatim */
  279. /* Arguments: */
  280. /* ========== */
  281. /* > \param[in] JOB */
  282. /* > \verbatim */
  283. /* > JOB is CHARACTER*1 */
  284. /* > = 'E': compute eigenvalues only; */
  285. /* > = 'S': compute eigenvalues and the Schur form T. */
  286. /* > \endverbatim */
  287. /* > */
  288. /* > \param[in] COMPZ */
  289. /* > \verbatim */
  290. /* > COMPZ is CHARACTER*1 */
  291. /* > = 'N': no Schur vectors are computed; */
  292. /* > = 'I': Z is initialized to the unit matrix and the matrix Z */
  293. /* > of Schur vectors of H is returned; */
  294. /* > = 'V': Z must contain an orthogonal matrix Q on entry, and */
  295. /* > the product Q*Z is returned. */
  296. /* > \endverbatim */
  297. /* > */
  298. /* > \param[in] N */
  299. /* > \verbatim */
  300. /* > N is INTEGER */
  301. /* > The order of the matrix H. N >= 0. */
  302. /* > \endverbatim */
  303. /* > */
  304. /* > \param[in] ILO */
  305. /* > \verbatim */
  306. /* > ILO is INTEGER */
  307. /* > \endverbatim */
  308. /* > */
  309. /* > \param[in] IHI */
  310. /* > \verbatim */
  311. /* > IHI is INTEGER */
  312. /* > */
  313. /* > It is assumed that H is already upper triangular in rows */
  314. /* > and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally */
  315. /* > set by a previous call to SGEBAL, and then passed to ZGEHRD */
  316. /* > when the matrix output by SGEBAL is reduced to Hessenberg */
  317. /* > form. Otherwise ILO and IHI should be set to 1 and N */
  318. /* > respectively. If N > 0, then 1 <= ILO <= IHI <= N. */
  319. /* > If N = 0, then ILO = 1 and IHI = 0. */
  320. /* > \endverbatim */
  321. /* > */
  322. /* > \param[in,out] H */
  323. /* > \verbatim */
  324. /* > H is REAL array, dimension (LDH,N) */
  325. /* > On entry, the upper Hessenberg matrix H. */
  326. /* > On exit, if INFO = 0 and JOB = 'S', then H contains the */
  327. /* > upper quasi-triangular matrix T from the Schur decomposition */
  328. /* > (the Schur form); 2-by-2 diagonal blocks (corresponding to */
  329. /* > complex conjugate pairs of eigenvalues) are returned in */
  330. /* > standard form, with H(i,i) = H(i+1,i+1) and */
  331. /* > H(i+1,i)*H(i,i+1) < 0. If INFO = 0 and JOB = 'E', the */
  332. /* > contents of H are unspecified on exit. (The output value of */
  333. /* > H when INFO > 0 is given under the description of INFO */
  334. /* > below.) */
  335. /* > */
  336. /* > Unlike earlier versions of SHSEQR, this subroutine may */
  337. /* > explicitly H(i,j) = 0 for i > j and j = 1, 2, ... ILO-1 */
  338. /* > or j = IHI+1, IHI+2, ... N. */
  339. /* > \endverbatim */
  340. /* > */
  341. /* > \param[in] LDH */
  342. /* > \verbatim */
  343. /* > LDH is INTEGER */
  344. /* > The leading dimension of the array H. LDH >= f2cmax(1,N). */
  345. /* > \endverbatim */
  346. /* > */
  347. /* > \param[out] WR */
  348. /* > \verbatim */
  349. /* > WR is REAL array, dimension (N) */
  350. /* > \endverbatim */
  351. /* > */
  352. /* > \param[out] WI */
  353. /* > \verbatim */
  354. /* > WI is REAL array, dimension (N) */
  355. /* > */
  356. /* > The real and imaginary parts, respectively, of the computed */
  357. /* > eigenvalues. If two eigenvalues are computed as a complex */
  358. /* > conjugate pair, they are stored in consecutive elements of */
  359. /* > WR and WI, say the i-th and (i+1)th, with WI(i) > 0 and */
  360. /* > WI(i+1) < 0. If JOB = 'S', the eigenvalues are stored in */
  361. /* > the same order as on the diagonal of the Schur form returned */
  362. /* > in H, with WR(i) = H(i,i) and, if H(i:i+1,i:i+1) is a 2-by-2 */
  363. /* > diagonal block, WI(i) = sqrt(-H(i+1,i)*H(i,i+1)) and */
  364. /* > WI(i+1) = -WI(i). */
  365. /* > \endverbatim */
  366. /* > */
  367. /* > \param[in,out] Z */
  368. /* > \verbatim */
  369. /* > Z is REAL array, dimension (LDZ,N) */
  370. /* > If COMPZ = 'N', Z is not referenced. */
  371. /* > If COMPZ = 'I', on entry Z need not be set and on exit, */
  372. /* > if INFO = 0, Z contains the orthogonal matrix Z of the Schur */
  373. /* > vectors of H. If COMPZ = 'V', on entry Z must contain an */
  374. /* > N-by-N matrix Q, which is assumed to be equal to the unit */
  375. /* > matrix except for the submatrix Z(ILO:IHI,ILO:IHI). On exit, */
  376. /* > if INFO = 0, Z contains Q*Z. */
  377. /* > Normally Q is the orthogonal matrix generated by SORGHR */
  378. /* > after the call to SGEHRD which formed the Hessenberg matrix */
  379. /* > H. (The output value of Z when INFO > 0 is given under */
  380. /* > the description of INFO below.) */
  381. /* > \endverbatim */
  382. /* > */
  383. /* > \param[in] LDZ */
  384. /* > \verbatim */
  385. /* > LDZ is INTEGER */
  386. /* > The leading dimension of the array Z. if COMPZ = 'I' or */
  387. /* > COMPZ = 'V', then LDZ >= MAX(1,N). Otherwise, LDZ >= 1. */
  388. /* > \endverbatim */
  389. /* > */
  390. /* > \param[out] WORK */
  391. /* > \verbatim */
  392. /* > WORK is REAL array, dimension (LWORK) */
  393. /* > On exit, if INFO = 0, WORK(1) returns an estimate of */
  394. /* > the optimal value for LWORK. */
  395. /* > \endverbatim */
  396. /* > */
  397. /* > \param[in] LWORK */
  398. /* > \verbatim */
  399. /* > LWORK is INTEGER */
  400. /* > The dimension of the array WORK. LWORK >= f2cmax(1,N) */
  401. /* > is sufficient and delivers very good and sometimes */
  402. /* > optimal performance. However, LWORK as large as 11*N */
  403. /* > may be required for optimal performance. A workspace */
  404. /* > query is recommended to determine the optimal workspace */
  405. /* > size. */
  406. /* > */
  407. /* > If LWORK = -1, then SHSEQR does a workspace query. */
  408. /* > In this case, SHSEQR checks the input parameters and */
  409. /* > estimates the optimal workspace size for the given */
  410. /* > values of N, ILO and IHI. The estimate is returned */
  411. /* > in WORK(1). No error message related to LWORK is */
  412. /* > issued by XERBLA. Neither H nor Z are accessed. */
  413. /* > \endverbatim */
  414. /* > */
  415. /* > \param[out] INFO */
  416. /* > \verbatim */
  417. /* > INFO is INTEGER */
  418. /* > = 0: successful exit */
  419. /* > < 0: if INFO = -i, the i-th argument had an illegal */
  420. /* > value */
  421. /* > > 0: if INFO = i, SHSEQR failed to compute all of */
  422. /* > the eigenvalues. Elements 1:ilo-1 and i+1:n of WR */
  423. /* > and WI contain those eigenvalues which have been */
  424. /* > successfully computed. (Failures are rare.) */
  425. /* > */
  426. /* > If INFO > 0 and JOB = 'E', then on exit, the */
  427. /* > remaining unconverged eigenvalues are the eigen- */
  428. /* > values of the upper Hessenberg matrix rows and */
  429. /* > columns ILO through INFO of the final, output */
  430. /* > value of H. */
  431. /* > */
  432. /* > If INFO > 0 and JOB = 'S', then on exit */
  433. /* > */
  434. /* > (*) (initial value of H)*U = U*(final value of H) */
  435. /* > */
  436. /* > where U is an orthogonal matrix. The final */
  437. /* > value of H is upper Hessenberg and quasi-triangular */
  438. /* > in rows and columns INFO+1 through IHI. */
  439. /* > */
  440. /* > If INFO > 0 and COMPZ = 'V', then on exit */
  441. /* > */
  442. /* > (final value of Z) = (initial value of Z)*U */
  443. /* > */
  444. /* > where U is the orthogonal matrix in (*) (regard- */
  445. /* > less of the value of JOB.) */
  446. /* > */
  447. /* > If INFO > 0 and COMPZ = 'I', then on exit */
  448. /* > (final value of Z) = U */
  449. /* > where U is the orthogonal matrix in (*) (regard- */
  450. /* > less of the value of JOB.) */
  451. /* > */
  452. /* > If INFO > 0 and COMPZ = 'N', then Z is not */
  453. /* > accessed. */
  454. /* > \endverbatim */
  455. /* Authors: */
  456. /* ======== */
  457. /* > \author Univ. of Tennessee */
  458. /* > \author Univ. of California Berkeley */
  459. /* > \author Univ. of Colorado Denver */
  460. /* > \author NAG Ltd. */
  461. /* > \date December 2016 */
  462. /* > \ingroup realOTHERcomputational */
  463. /* > \par Contributors: */
  464. /* ================== */
  465. /* > */
  466. /* > Karen Braman and Ralph Byers, Department of Mathematics, */
  467. /* > University of Kansas, USA */
  468. /* > \par Further Details: */
  469. /* ===================== */
  470. /* > */
  471. /* > \verbatim */
  472. /* > */
  473. /* > Default values supplied by */
  474. /* > ILAENV(ISPEC,'SHSEQR',JOB(:1)//COMPZ(:1),N,ILO,IHI,LWORK). */
  475. /* > It is suggested that these defaults be adjusted in order */
  476. /* > to attain best performance in each particular */
  477. /* > computational environment. */
  478. /* > */
  479. /* > ISPEC=12: The SLAHQR vs SLAQR0 crossover point. */
  480. /* > Default: 75. (Must be at least 11.) */
  481. /* > */
  482. /* > ISPEC=13: Recommended deflation window size. */
  483. /* > This depends on ILO, IHI and NS. NS is the */
  484. /* > number of simultaneous shifts returned */
  485. /* > by ILAENV(ISPEC=15). (See ISPEC=15 below.) */
  486. /* > The default for (IHI-ILO+1) <= 500 is NS. */
  487. /* > The default for (IHI-ILO+1) > 500 is 3*NS/2. */
  488. /* > */
  489. /* > ISPEC=14: Nibble crossover point. (See IPARMQ for */
  490. /* > details.) Default: 14% of deflation window */
  491. /* > size. */
  492. /* > */
  493. /* > ISPEC=15: Number of simultaneous shifts in a multishift */
  494. /* > QR iteration. */
  495. /* > */
  496. /* > If IHI-ILO+1 is ... */
  497. /* > */
  498. /* > greater than ...but less ... the */
  499. /* > or equal to ... than default is */
  500. /* > */
  501. /* > 1 30 NS = 2(+) */
  502. /* > 30 60 NS = 4(+) */
  503. /* > 60 150 NS = 10(+) */
  504. /* > 150 590 NS = ** */
  505. /* > 590 3000 NS = 64 */
  506. /* > 3000 6000 NS = 128 */
  507. /* > 6000 infinity NS = 256 */
  508. /* > */
  509. /* > (+) By default some or all matrices of this order */
  510. /* > are passed to the implicit double shift routine */
  511. /* > SLAHQR and this parameter is ignored. See */
  512. /* > ISPEC=12 above and comments in IPARMQ for */
  513. /* > details. */
  514. /* > */
  515. /* > (**) The asterisks (**) indicate an ad-hoc */
  516. /* > function of N increasing from 10 to 64. */
  517. /* > */
  518. /* > ISPEC=16: Select structured matrix multiply. */
  519. /* > If the number of simultaneous shifts (specified */
  520. /* > by ISPEC=15) is less than 14, then the default */
  521. /* > for ISPEC=16 is 0. Otherwise the default for */
  522. /* > ISPEC=16 is 2. */
  523. /* > \endverbatim */
  524. /* > \par References: */
  525. /* ================ */
  526. /* > */
  527. /* > K. Braman, R. Byers and R. Mathias, The Multi-Shift QR */
  528. /* > Algorithm Part I: Maintaining Well Focused Shifts, and Level 3 */
  529. /* > Performance, SIAM Journal of Matrix Analysis, volume 23, pages */
  530. /* > 929--947, 2002. */
  531. /* > \n */
  532. /* > K. Braman, R. Byers and R. Mathias, The Multi-Shift QR */
  533. /* > Algorithm Part II: Aggressive Early Deflation, SIAM Journal */
  534. /* > of Matrix Analysis, volume 23, pages 948--973, 2002. */
  535. /* ===================================================================== */
  536. /* Subroutine */ void shseqr_(char *job, char *compz, integer *n, integer *ilo,
  537. integer *ihi, real *h__, integer *ldh, real *wr, real *wi, real *z__,
  538. integer *ldz, real *work, integer *lwork, integer *info)
  539. {
  540. /* System generated locals */
  541. address a__1[2];
  542. integer h_dim1, h_offset, z_dim1, z_offset, i__1, i__2[2], i__3;
  543. real r__1;
  544. char ch__1[2];
  545. /* Local variables */
  546. integer kbot, nmin, i__;
  547. extern logical lsame_(char *, char *);
  548. logical initz;
  549. real workl[49];
  550. logical wantt, wantz;
  551. extern /* Subroutine */ void slaqr0_(logical *, logical *, integer *,
  552. integer *, integer *, real *, integer *, real *, real *, integer *
  553. , integer *, real *, integer *, real *, integer *, integer *);
  554. real hl[2401] /* was [49][49] */;
  555. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  556. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  557. integer *, integer *, ftnlen, ftnlen);
  558. extern /* Subroutine */ void slahqr_(logical *, logical *, integer *,
  559. integer *, integer *, real *, integer *, real *, real *, integer *
  560. , integer *, real *, integer *, integer *), slacpy_(char *,
  561. integer *, integer *, real *, integer *, real *, integer *), slaset_(char *, integer *, integer *, real *, real *,
  562. real *, integer *);
  563. logical lquery;
  564. /* -- LAPACK computational routine (version 3.7.0) -- */
  565. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  566. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  567. /* December 2016 */
  568. /* ===================================================================== */
  569. /* ==== Matrices of order NTINY or smaller must be processed by */
  570. /* . SLAHQR because of insufficient subdiagonal scratch space. */
  571. /* . (This is a hard limit.) ==== */
  572. /* ==== NL allocates some local workspace to help small matrices */
  573. /* . through a rare SLAHQR failure. NL > NTINY = 15 is */
  574. /* . required and NL <= NMIN = ILAENV(ISPEC=12,...) is recom- */
  575. /* . mended. (The default value of NMIN is 75.) Using NL = 49 */
  576. /* . allows up to six simultaneous shifts and a 16-by-16 */
  577. /* . deflation window. ==== */
  578. /* ==== Decode and check the input parameters. ==== */
  579. /* Parameter adjustments */
  580. h_dim1 = *ldh;
  581. h_offset = 1 + h_dim1 * 1;
  582. h__ -= h_offset;
  583. --wr;
  584. --wi;
  585. z_dim1 = *ldz;
  586. z_offset = 1 + z_dim1 * 1;
  587. z__ -= z_offset;
  588. --work;
  589. /* Function Body */
  590. wantt = lsame_(job, "S");
  591. initz = lsame_(compz, "I");
  592. wantz = initz || lsame_(compz, "V");
  593. work[1] = (real) f2cmax(1,*n);
  594. lquery = *lwork == -1;
  595. *info = 0;
  596. if (! lsame_(job, "E") && ! wantt) {
  597. *info = -1;
  598. } else if (! lsame_(compz, "N") && ! wantz) {
  599. *info = -2;
  600. } else if (*n < 0) {
  601. *info = -3;
  602. } else if (*ilo < 1 || *ilo > f2cmax(1,*n)) {
  603. *info = -4;
  604. } else if (*ihi < f2cmin(*ilo,*n) || *ihi > *n) {
  605. *info = -5;
  606. } else if (*ldh < f2cmax(1,*n)) {
  607. *info = -7;
  608. } else if (*ldz < 1 || wantz && *ldz < f2cmax(1,*n)) {
  609. *info = -11;
  610. } else if (*lwork < f2cmax(1,*n) && ! lquery) {
  611. *info = -13;
  612. }
  613. if (*info != 0) {
  614. /* ==== Quick return in case of invalid argument. ==== */
  615. i__1 = -(*info);
  616. xerbla_("SHSEQR", &i__1, (ftnlen)6);
  617. return;
  618. } else if (*n == 0) {
  619. /* ==== Quick return in case N = 0; nothing to do. ==== */
  620. return;
  621. } else if (lquery) {
  622. /* ==== Quick return in case of a workspace query ==== */
  623. slaqr0_(&wantt, &wantz, n, ilo, ihi, &h__[h_offset], ldh, &wr[1], &wi[
  624. 1], ilo, ihi, &z__[z_offset], ldz, &work[1], lwork, info);
  625. /* ==== Ensure reported workspace size is backward-compatible with */
  626. /* . previous LAPACK versions. ==== */
  627. /* Computing MAX */
  628. r__1 = (real) f2cmax(1,*n);
  629. work[1] = f2cmax(r__1,work[1]);
  630. return;
  631. } else {
  632. /* ==== copy eigenvalues isolated by SGEBAL ==== */
  633. i__1 = *ilo - 1;
  634. for (i__ = 1; i__ <= i__1; ++i__) {
  635. wr[i__] = h__[i__ + i__ * h_dim1];
  636. wi[i__] = 0.f;
  637. /* L10: */
  638. }
  639. i__1 = *n;
  640. for (i__ = *ihi + 1; i__ <= i__1; ++i__) {
  641. wr[i__] = h__[i__ + i__ * h_dim1];
  642. wi[i__] = 0.f;
  643. /* L20: */
  644. }
  645. /* ==== Initialize Z, if requested ==== */
  646. if (initz) {
  647. slaset_("A", n, n, &c_b11, &c_b12, &z__[z_offset], ldz)
  648. ;
  649. }
  650. /* ==== Quick return if possible ==== */
  651. if (*ilo == *ihi) {
  652. wr[*ilo] = h__[*ilo + *ilo * h_dim1];
  653. wi[*ilo] = 0.f;
  654. return;
  655. }
  656. /* ==== SLAHQR/SLAQR0 crossover point ==== */
  657. /* Writing concatenation */
  658. i__2[0] = 1, a__1[0] = job;
  659. i__2[1] = 1, a__1[1] = compz;
  660. s_cat(ch__1, a__1, i__2, &c__2, (ftnlen)2);
  661. nmin = ilaenv_(&c__12, "SHSEQR", ch__1, n, ilo, ihi, lwork, (ftnlen)6,
  662. (ftnlen)2);
  663. nmin = f2cmax(15,nmin);
  664. /* ==== SLAQR0 for big matrices; SLAHQR for small ones ==== */
  665. if (*n > nmin) {
  666. slaqr0_(&wantt, &wantz, n, ilo, ihi, &h__[h_offset], ldh, &wr[1],
  667. &wi[1], ilo, ihi, &z__[z_offset], ldz, &work[1], lwork,
  668. info);
  669. } else {
  670. /* ==== Small matrix ==== */
  671. slahqr_(&wantt, &wantz, n, ilo, ihi, &h__[h_offset], ldh, &wr[1],
  672. &wi[1], ilo, ihi, &z__[z_offset], ldz, info);
  673. if (*info > 0) {
  674. /* ==== A rare SLAHQR failure! SLAQR0 sometimes succeeds */
  675. /* . when SLAHQR fails. ==== */
  676. kbot = *info;
  677. if (*n >= 49) {
  678. /* ==== Larger matrices have enough subdiagonal scratch */
  679. /* . space to call SLAQR0 directly. ==== */
  680. slaqr0_(&wantt, &wantz, n, ilo, &kbot, &h__[h_offset],
  681. ldh, &wr[1], &wi[1], ilo, ihi, &z__[z_offset],
  682. ldz, &work[1], lwork, info);
  683. } else {
  684. /* ==== Tiny matrices don't have enough subdiagonal */
  685. /* . scratch space to benefit from SLAQR0. Hence, */
  686. /* . tiny matrices must be copied into a larger */
  687. /* . array before calling SLAQR0. ==== */
  688. slacpy_("A", n, n, &h__[h_offset], ldh, hl, &c__49);
  689. hl[*n + 1 + *n * 49 - 50] = 0.f;
  690. i__1 = 49 - *n;
  691. slaset_("A", &c__49, &i__1, &c_b11, &c_b11, &hl[(*n + 1) *
  692. 49 - 49], &c__49);
  693. slaqr0_(&wantt, &wantz, &c__49, ilo, &kbot, hl, &c__49, &
  694. wr[1], &wi[1], ilo, ihi, &z__[z_offset], ldz,
  695. workl, &c__49, info);
  696. if (wantt || *info != 0) {
  697. slacpy_("A", n, n, hl, &c__49, &h__[h_offset], ldh);
  698. }
  699. }
  700. }
  701. }
  702. /* ==== Clear out the trash, if necessary. ==== */
  703. if ((wantt || *info != 0) && *n > 2) {
  704. i__1 = *n - 2;
  705. i__3 = *n - 2;
  706. slaset_("L", &i__1, &i__3, &c_b11, &c_b11, &h__[h_dim1 + 3], ldh);
  707. }
  708. /* ==== Ensure reported workspace size is backward-compatible with */
  709. /* . previous LAPACK versions. ==== */
  710. /* Computing MAX */
  711. r__1 = (real) f2cmax(1,*n);
  712. work[1] = f2cmax(r__1,work[1]);
  713. }
  714. /* ==== End of SHSEQR ==== */
  715. return;
  716. } /* shseqr_ */