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.

zstemr.c 40 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  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 doublereal c_b18 = .001;
  382. /* > \brief \b ZSTEMR */
  383. /* =========== DOCUMENTATION =========== */
  384. /* Online html documentation available at */
  385. /* http://www.netlib.org/lapack/explore-html/ */
  386. /* > \htmlonly */
  387. /* > Download ZSTEMR + dependencies */
  388. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zstemr.
  389. f"> */
  390. /* > [TGZ]</a> */
  391. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zstemr.
  392. f"> */
  393. /* > [ZIP]</a> */
  394. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zstemr.
  395. f"> */
  396. /* > [TXT]</a> */
  397. /* > \endhtmlonly */
  398. /* Definition: */
  399. /* =========== */
  400. /* SUBROUTINE ZSTEMR( JOBZ, RANGE, N, D, E, VL, VU, IL, IU, */
  401. /* M, W, Z, LDZ, NZC, ISUPPZ, TRYRAC, WORK, LWORK, */
  402. /* IWORK, LIWORK, INFO ) */
  403. /* CHARACTER JOBZ, RANGE */
  404. /* LOGICAL TRYRAC */
  405. /* INTEGER IL, INFO, IU, LDZ, NZC, LIWORK, LWORK, M, N */
  406. /* DOUBLE PRECISION VL, VU */
  407. /* INTEGER ISUPPZ( * ), IWORK( * ) */
  408. /* DOUBLE PRECISION D( * ), E( * ), W( * ), WORK( * ) */
  409. /* COMPLEX*16 Z( LDZ, * ) */
  410. /* > \par Purpose: */
  411. /* ============= */
  412. /* > */
  413. /* > \verbatim */
  414. /* > */
  415. /* > ZSTEMR computes selected eigenvalues and, optionally, eigenvectors */
  416. /* > of a real symmetric tridiagonal matrix T. Any such unreduced matrix has */
  417. /* > a well defined set of pairwise different real eigenvalues, the corresponding */
  418. /* > real eigenvectors are pairwise orthogonal. */
  419. /* > */
  420. /* > The spectrum may be computed either completely or partially by specifying */
  421. /* > either an interval (VL,VU] or a range of indices IL:IU for the desired */
  422. /* > eigenvalues. */
  423. /* > */
  424. /* > Depending on the number of desired eigenvalues, these are computed either */
  425. /* > by bisection or the dqds algorithm. Numerically orthogonal eigenvectors are */
  426. /* > computed by the use of various suitable L D L^T factorizations near clusters */
  427. /* > of close eigenvalues (referred to as RRRs, Relatively Robust */
  428. /* > Representations). An informal sketch of the algorithm follows. */
  429. /* > */
  430. /* > For each unreduced block (submatrix) of T, */
  431. /* > (a) Compute T - sigma I = L D L^T, so that L and D */
  432. /* > define all the wanted eigenvalues to high relative accuracy. */
  433. /* > This means that small relative changes in the entries of D and L */
  434. /* > cause only small relative changes in the eigenvalues and */
  435. /* > eigenvectors. The standard (unfactored) representation of the */
  436. /* > tridiagonal matrix T does not have this property in general. */
  437. /* > (b) Compute the eigenvalues to suitable accuracy. */
  438. /* > If the eigenvectors are desired, the algorithm attains full */
  439. /* > accuracy of the computed eigenvalues only right before */
  440. /* > the corresponding vectors have to be computed, see steps c) and d). */
  441. /* > (c) For each cluster of close eigenvalues, select a new */
  442. /* > shift close to the cluster, find a new factorization, and refine */
  443. /* > the shifted eigenvalues to suitable accuracy. */
  444. /* > (d) For each eigenvalue with a large enough relative separation compute */
  445. /* > the corresponding eigenvector by forming a rank revealing twisted */
  446. /* > factorization. Go back to (c) for any clusters that remain. */
  447. /* > */
  448. /* > For more details, see: */
  449. /* > - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations */
  450. /* > to compute orthogonal eigenvectors of symmetric tridiagonal matrices," */
  451. /* > Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004. */
  452. /* > - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and */
  453. /* > Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25, */
  454. /* > 2004. Also LAPACK Working Note 154. */
  455. /* > - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric */
  456. /* > tridiagonal eigenvalue/eigenvector problem", */
  457. /* > Computer Science Division Technical Report No. UCB/CSD-97-971, */
  458. /* > UC Berkeley, May 1997. */
  459. /* > */
  460. /* > Further Details */
  461. /* > 1.ZSTEMR works only on machines which follow IEEE-754 */
  462. /* > floating-point standard in their handling of infinities and NaNs. */
  463. /* > This permits the use of efficient inner loops avoiding a check for */
  464. /* > zero divisors. */
  465. /* > */
  466. /* > 2. LAPACK routines can be used to reduce a complex Hermitean matrix to */
  467. /* > real symmetric tridiagonal form. */
  468. /* > */
  469. /* > (Any complex Hermitean tridiagonal matrix has real values on its diagonal */
  470. /* > and potentially complex numbers on its off-diagonals. By applying a */
  471. /* > similarity transform with an appropriate diagonal matrix */
  472. /* > diag(1,e^{i \phy_1}, ... , e^{i \phy_{n-1}}), the complex Hermitean */
  473. /* > matrix can be transformed into a real symmetric matrix and complex */
  474. /* > arithmetic can be entirely avoided.) */
  475. /* > */
  476. /* > While the eigenvectors of the real symmetric tridiagonal matrix are real, */
  477. /* > the eigenvectors of original complex Hermitean matrix have complex entries */
  478. /* > in general. */
  479. /* > Since LAPACK drivers overwrite the matrix data with the eigenvectors, */
  480. /* > ZSTEMR accepts complex workspace to facilitate interoperability */
  481. /* > with ZUNMTR or ZUPMTR. */
  482. /* > \endverbatim */
  483. /* Arguments: */
  484. /* ========== */
  485. /* > \param[in] JOBZ */
  486. /* > \verbatim */
  487. /* > JOBZ is CHARACTER*1 */
  488. /* > = 'N': Compute eigenvalues only; */
  489. /* > = 'V': Compute eigenvalues and eigenvectors. */
  490. /* > \endverbatim */
  491. /* > */
  492. /* > \param[in] RANGE */
  493. /* > \verbatim */
  494. /* > RANGE is CHARACTER*1 */
  495. /* > = 'A': all eigenvalues will be found. */
  496. /* > = 'V': all eigenvalues in the half-open interval (VL,VU] */
  497. /* > will be found. */
  498. /* > = 'I': the IL-th through IU-th eigenvalues will be found. */
  499. /* > \endverbatim */
  500. /* > */
  501. /* > \param[in] N */
  502. /* > \verbatim */
  503. /* > N is INTEGER */
  504. /* > The order of the matrix. N >= 0. */
  505. /* > \endverbatim */
  506. /* > */
  507. /* > \param[in,out] D */
  508. /* > \verbatim */
  509. /* > D is DOUBLE PRECISION array, dimension (N) */
  510. /* > On entry, the N diagonal elements of the tridiagonal matrix */
  511. /* > T. On exit, D is overwritten. */
  512. /* > \endverbatim */
  513. /* > */
  514. /* > \param[in,out] E */
  515. /* > \verbatim */
  516. /* > E is DOUBLE PRECISION array, dimension (N) */
  517. /* > On entry, the (N-1) subdiagonal elements of the tridiagonal */
  518. /* > matrix T in elements 1 to N-1 of E. E(N) need not be set on */
  519. /* > input, but is used internally as workspace. */
  520. /* > On exit, E is overwritten. */
  521. /* > \endverbatim */
  522. /* > */
  523. /* > \param[in] VL */
  524. /* > \verbatim */
  525. /* > VL is DOUBLE PRECISION */
  526. /* > */
  527. /* > If RANGE='V', the lower bound of the interval to */
  528. /* > be searched for eigenvalues. VL < VU. */
  529. /* > Not referenced if RANGE = 'A' or 'I'. */
  530. /* > \endverbatim */
  531. /* > */
  532. /* > \param[in] VU */
  533. /* > \verbatim */
  534. /* > VU is DOUBLE PRECISION */
  535. /* > */
  536. /* > If RANGE='V', the upper bound of the interval to */
  537. /* > be searched for eigenvalues. VL < VU. */
  538. /* > Not referenced if RANGE = 'A' or 'I'. */
  539. /* > \endverbatim */
  540. /* > */
  541. /* > \param[in] IL */
  542. /* > \verbatim */
  543. /* > IL is INTEGER */
  544. /* > */
  545. /* > If RANGE='I', the index of the */
  546. /* > smallest eigenvalue to be returned. */
  547. /* > 1 <= IL <= IU <= N, if N > 0. */
  548. /* > Not referenced if RANGE = 'A' or 'V'. */
  549. /* > \endverbatim */
  550. /* > */
  551. /* > \param[in] IU */
  552. /* > \verbatim */
  553. /* > IU is INTEGER */
  554. /* > */
  555. /* > If RANGE='I', the index of the */
  556. /* > largest eigenvalue to be returned. */
  557. /* > 1 <= IL <= IU <= N, if N > 0. */
  558. /* > Not referenced if RANGE = 'A' or 'V'. */
  559. /* > \endverbatim */
  560. /* > */
  561. /* > \param[out] M */
  562. /* > \verbatim */
  563. /* > M is INTEGER */
  564. /* > The total number of eigenvalues found. 0 <= M <= N. */
  565. /* > If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
  566. /* > \endverbatim */
  567. /* > */
  568. /* > \param[out] W */
  569. /* > \verbatim */
  570. /* > W is DOUBLE PRECISION array, dimension (N) */
  571. /* > The first M elements contain the selected eigenvalues in */
  572. /* > ascending order. */
  573. /* > \endverbatim */
  574. /* > */
  575. /* > \param[out] Z */
  576. /* > \verbatim */
  577. /* > Z is COMPLEX*16 array, dimension (LDZ, f2cmax(1,M) ) */
  578. /* > If JOBZ = 'V', and if INFO = 0, then the first M columns of Z */
  579. /* > contain the orthonormal eigenvectors of the matrix T */
  580. /* > corresponding to the selected eigenvalues, with the i-th */
  581. /* > column of Z holding the eigenvector associated with W(i). */
  582. /* > If JOBZ = 'N', then Z is not referenced. */
  583. /* > Note: the user must ensure that at least f2cmax(1,M) columns are */
  584. /* > supplied in the array Z; if RANGE = 'V', the exact value of M */
  585. /* > is not known in advance and can be computed with a workspace */
  586. /* > query by setting NZC = -1, see below. */
  587. /* > \endverbatim */
  588. /* > */
  589. /* > \param[in] LDZ */
  590. /* > \verbatim */
  591. /* > LDZ is INTEGER */
  592. /* > The leading dimension of the array Z. LDZ >= 1, and if */
  593. /* > JOBZ = 'V', then LDZ >= f2cmax(1,N). */
  594. /* > \endverbatim */
  595. /* > */
  596. /* > \param[in] NZC */
  597. /* > \verbatim */
  598. /* > NZC is INTEGER */
  599. /* > The number of eigenvectors to be held in the array Z. */
  600. /* > If RANGE = 'A', then NZC >= f2cmax(1,N). */
  601. /* > If RANGE = 'V', then NZC >= the number of eigenvalues in (VL,VU]. */
  602. /* > If RANGE = 'I', then NZC >= IU-IL+1. */
  603. /* > If NZC = -1, then a workspace query is assumed; the */
  604. /* > routine calculates the number of columns of the array Z that */
  605. /* > are needed to hold the eigenvectors. */
  606. /* > This value is returned as the first entry of the Z array, and */
  607. /* > no error message related to NZC is issued by XERBLA. */
  608. /* > \endverbatim */
  609. /* > */
  610. /* > \param[out] ISUPPZ */
  611. /* > \verbatim */
  612. /* > ISUPPZ is INTEGER array, dimension ( 2*f2cmax(1,M) ) */
  613. /* > The support of the eigenvectors in Z, i.e., the indices */
  614. /* > indicating the nonzero elements in Z. The i-th computed eigenvector */
  615. /* > is nonzero only in elements ISUPPZ( 2*i-1 ) through */
  616. /* > ISUPPZ( 2*i ). This is relevant in the case when the matrix */
  617. /* > is split. ISUPPZ is only accessed when JOBZ is 'V' and N > 0. */
  618. /* > \endverbatim */
  619. /* > */
  620. /* > \param[in,out] TRYRAC */
  621. /* > \verbatim */
  622. /* > TRYRAC is LOGICAL */
  623. /* > If TRYRAC = .TRUE., indicates that the code should check whether */
  624. /* > the tridiagonal matrix defines its eigenvalues to high relative */
  625. /* > accuracy. If so, the code uses relative-accuracy preserving */
  626. /* > algorithms that might be (a bit) slower depending on the matrix. */
  627. /* > If the matrix does not define its eigenvalues to high relative */
  628. /* > accuracy, the code can uses possibly faster algorithms. */
  629. /* > If TRYRAC = .FALSE., the code is not required to guarantee */
  630. /* > relatively accurate eigenvalues and can use the fastest possible */
  631. /* > techniques. */
  632. /* > On exit, a .TRUE. TRYRAC will be set to .FALSE. if the matrix */
  633. /* > does not define its eigenvalues to high relative accuracy. */
  634. /* > \endverbatim */
  635. /* > */
  636. /* > \param[out] WORK */
  637. /* > \verbatim */
  638. /* > WORK is DOUBLE PRECISION array, dimension (LWORK) */
  639. /* > On exit, if INFO = 0, WORK(1) returns the optimal */
  640. /* > (and minimal) LWORK. */
  641. /* > \endverbatim */
  642. /* > */
  643. /* > \param[in] LWORK */
  644. /* > \verbatim */
  645. /* > LWORK is INTEGER */
  646. /* > The dimension of the array WORK. LWORK >= f2cmax(1,18*N) */
  647. /* > if JOBZ = 'V', and LWORK >= f2cmax(1,12*N) if JOBZ = 'N'. */
  648. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  649. /* > only calculates the optimal size of the WORK array, returns */
  650. /* > this value as the first entry of the WORK array, and no error */
  651. /* > message related to LWORK is issued by XERBLA. */
  652. /* > \endverbatim */
  653. /* > */
  654. /* > \param[out] IWORK */
  655. /* > \verbatim */
  656. /* > IWORK is INTEGER array, dimension (LIWORK) */
  657. /* > On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
  658. /* > \endverbatim */
  659. /* > */
  660. /* > \param[in] LIWORK */
  661. /* > \verbatim */
  662. /* > LIWORK is INTEGER */
  663. /* > The dimension of the array IWORK. LIWORK >= f2cmax(1,10*N) */
  664. /* > if the eigenvectors are desired, and LIWORK >= f2cmax(1,8*N) */
  665. /* > if only the eigenvalues are to be computed. */
  666. /* > If LIWORK = -1, then a workspace query is assumed; the */
  667. /* > routine only calculates the optimal size of the IWORK array, */
  668. /* > returns this value as the first entry of the IWORK array, and */
  669. /* > no error message related to LIWORK is issued by XERBLA. */
  670. /* > \endverbatim */
  671. /* > */
  672. /* > \param[out] INFO */
  673. /* > \verbatim */
  674. /* > INFO is INTEGER */
  675. /* > On exit, INFO */
  676. /* > = 0: successful exit */
  677. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  678. /* > > 0: if INFO = 1X, internal error in DLARRE, */
  679. /* > if INFO = 2X, internal error in ZLARRV. */
  680. /* > Here, the digit X = ABS( IINFO ) < 10, where IINFO is */
  681. /* > the nonzero error code returned by DLARRE or */
  682. /* > ZLARRV, respectively. */
  683. /* > \endverbatim */
  684. /* Authors: */
  685. /* ======== */
  686. /* > \author Univ. of Tennessee */
  687. /* > \author Univ. of California Berkeley */
  688. /* > \author Univ. of Colorado Denver */
  689. /* > \author NAG Ltd. */
  690. /* > \date June 2016 */
  691. /* > \ingroup complex16OTHERcomputational */
  692. /* > \par Contributors: */
  693. /* ================== */
  694. /* > */
  695. /* > Beresford Parlett, University of California, Berkeley, USA \n */
  696. /* > Jim Demmel, University of California, Berkeley, USA \n */
  697. /* > Inderjit Dhillon, University of Texas, Austin, USA \n */
  698. /* > Osni Marques, LBNL/NERSC, USA \n */
  699. /* > Christof Voemel, University of California, Berkeley, USA \n */
  700. /* ===================================================================== */
  701. /* Subroutine */ int zstemr_(char *jobz, char *range, integer *n, doublereal *
  702. d__, doublereal *e, doublereal *vl, doublereal *vu, integer *il,
  703. integer *iu, integer *m, doublereal *w, doublecomplex *z__, integer *
  704. ldz, integer *nzc, integer *isuppz, logical *tryrac, doublereal *work,
  705. integer *lwork, integer *iwork, integer *liwork, integer *info)
  706. {
  707. /* System generated locals */
  708. integer z_dim1, z_offset, i__1, i__2;
  709. doublereal d__1, d__2;
  710. /* Local variables */
  711. integer indd, iend, jblk, wend;
  712. doublereal rmin, rmax;
  713. integer itmp;
  714. doublereal tnrm;
  715. extern /* Subroutine */ int dlae2_(doublereal *, doublereal *, doublereal
  716. *, doublereal *, doublereal *);
  717. integer inde2, itmp2;
  718. doublereal rtol1, rtol2;
  719. integer i__, j;
  720. extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
  721. integer *);
  722. doublereal scale;
  723. integer indgp;
  724. extern logical lsame_(char *, char *);
  725. integer iinfo, iindw, ilast;
  726. extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
  727. doublereal *, integer *);
  728. integer lwmin;
  729. logical wantz;
  730. doublereal r1, r2;
  731. extern /* Subroutine */ int zswap_(integer *, doublecomplex *, integer *,
  732. doublecomplex *, integer *), dlaev2_(doublereal *, doublereal *,
  733. doublereal *, doublereal *, doublereal *, doublereal *,
  734. doublereal *);
  735. integer jj;
  736. doublereal cs;
  737. integer in;
  738. extern doublereal dlamch_(char *);
  739. logical alleig, indeig;
  740. integer ibegin, iindbl;
  741. doublereal sn, wl;
  742. logical valeig;
  743. extern /* Subroutine */ int dlarrc_(char *, integer *, doublereal *,
  744. doublereal *, doublereal *, doublereal *, doublereal *, integer *,
  745. integer *, integer *, integer *), dlarre_(char *,
  746. integer *, doublereal *, doublereal *, integer *, integer *,
  747. doublereal *, doublereal *, doublereal *, doublereal *,
  748. doublereal *, doublereal *, integer *, integer *, integer *,
  749. doublereal *, doublereal *, doublereal *, integer *, integer *,
  750. doublereal *, doublereal *, doublereal *, integer *, integer *);
  751. integer wbegin;
  752. doublereal safmin, wu;
  753. extern /* Subroutine */ int dlarrj_(integer *, doublereal *, doublereal *,
  754. integer *, integer *, doublereal *, integer *, doublereal *,
  755. doublereal *, doublereal *, integer *, doublereal *, doublereal *,
  756. integer *), xerbla_(char *, integer *, ftnlen);
  757. doublereal bignum;
  758. integer inderr, iindwk, indgrs, offset;
  759. extern doublereal dlanst_(char *, integer *, doublereal *, doublereal *);
  760. extern /* Subroutine */ int dlarrr_(integer *, doublereal *, doublereal *,
  761. integer *), dlasrt_(char *, integer *, doublereal *, integer *);
  762. doublereal thresh;
  763. integer iinspl, indwrk, ifirst, liwmin, nzcmin;
  764. doublereal pivmin;
  765. integer nsplit;
  766. doublereal smlnum;
  767. extern /* Subroutine */ int zlarrv_(integer *, doublereal *, doublereal *,
  768. doublereal *, doublereal *, doublereal *, integer *, integer *,
  769. integer *, integer *, doublereal *, doublereal *, doublereal *,
  770. doublereal *, doublereal *, doublereal *, integer *, integer *,
  771. doublereal *, doublecomplex *, integer *, integer *, doublereal *,
  772. integer *, integer *);
  773. logical lquery, zquery;
  774. integer iil, iiu;
  775. doublereal eps, tmp;
  776. /* -- LAPACK computational routine (version 3.7.1) -- */
  777. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  778. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  779. /* June 2016 */
  780. /* ===================================================================== */
  781. /* Test the input parameters. */
  782. /* Parameter adjustments */
  783. --d__;
  784. --e;
  785. --w;
  786. z_dim1 = *ldz;
  787. z_offset = 1 + z_dim1 * 1;
  788. z__ -= z_offset;
  789. --isuppz;
  790. --work;
  791. --iwork;
  792. /* Function Body */
  793. wantz = lsame_(jobz, "V");
  794. alleig = lsame_(range, "A");
  795. valeig = lsame_(range, "V");
  796. indeig = lsame_(range, "I");
  797. lquery = *lwork == -1 || *liwork == -1;
  798. zquery = *nzc == -1;
  799. /* DSTEMR needs WORK of size 6*N, IWORK of size 3*N. */
  800. /* In addition, DLARRE needs WORK of size 6*N, IWORK of size 5*N. */
  801. /* Furthermore, ZLARRV needs WORK of size 12*N, IWORK of size 7*N. */
  802. if (wantz) {
  803. lwmin = *n * 18;
  804. liwmin = *n * 10;
  805. } else {
  806. /* need less workspace if only the eigenvalues are wanted */
  807. lwmin = *n * 12;
  808. liwmin = *n << 3;
  809. }
  810. wl = 0.;
  811. wu = 0.;
  812. iil = 0;
  813. iiu = 0;
  814. nsplit = 0;
  815. if (valeig) {
  816. /* We do not reference VL, VU in the cases RANGE = 'I','A' */
  817. /* The interval (WL, WU] contains all the wanted eigenvalues. */
  818. /* It is either given by the user or computed in DLARRE. */
  819. wl = *vl;
  820. wu = *vu;
  821. } else if (indeig) {
  822. /* We do not reference IL, IU in the cases RANGE = 'V','A' */
  823. iil = *il;
  824. iiu = *iu;
  825. }
  826. *info = 0;
  827. if (! (wantz || lsame_(jobz, "N"))) {
  828. *info = -1;
  829. } else if (! (alleig || valeig || indeig)) {
  830. *info = -2;
  831. } else if (*n < 0) {
  832. *info = -3;
  833. } else if (valeig && *n > 0 && wu <= wl) {
  834. *info = -7;
  835. } else if (indeig && (iil < 1 || iil > *n)) {
  836. *info = -8;
  837. } else if (indeig && (iiu < iil || iiu > *n)) {
  838. *info = -9;
  839. } else if (*ldz < 1 || wantz && *ldz < *n) {
  840. *info = -13;
  841. } else if (*lwork < lwmin && ! lquery) {
  842. *info = -17;
  843. } else if (*liwork < liwmin && ! lquery) {
  844. *info = -19;
  845. }
  846. /* Get machine constants. */
  847. safmin = dlamch_("Safe minimum");
  848. eps = dlamch_("Precision");
  849. smlnum = safmin / eps;
  850. bignum = 1. / smlnum;
  851. rmin = sqrt(smlnum);
  852. /* Computing MIN */
  853. d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin));
  854. rmax = f2cmin(d__1,d__2);
  855. if (*info == 0) {
  856. work[1] = (doublereal) lwmin;
  857. iwork[1] = liwmin;
  858. if (wantz && alleig) {
  859. nzcmin = *n;
  860. } else if (wantz && valeig) {
  861. dlarrc_("T", n, vl, vu, &d__[1], &e[1], &safmin, &nzcmin, &itmp, &
  862. itmp2, info);
  863. } else if (wantz && indeig) {
  864. nzcmin = iiu - iil + 1;
  865. } else {
  866. /* WANTZ .EQ. FALSE. */
  867. nzcmin = 0;
  868. }
  869. if (zquery && *info == 0) {
  870. i__1 = z_dim1 + 1;
  871. z__[i__1].r = (doublereal) nzcmin, z__[i__1].i = 0.;
  872. } else if (*nzc < nzcmin && ! zquery) {
  873. *info = -14;
  874. }
  875. }
  876. if (*info != 0) {
  877. i__1 = -(*info);
  878. xerbla_("ZSTEMR", &i__1, (ftnlen)6);
  879. return 0;
  880. } else if (lquery || zquery) {
  881. return 0;
  882. }
  883. /* Handle N = 0, 1, and 2 cases immediately */
  884. *m = 0;
  885. if (*n == 0) {
  886. return 0;
  887. }
  888. if (*n == 1) {
  889. if (alleig || indeig) {
  890. *m = 1;
  891. w[1] = d__[1];
  892. } else {
  893. if (wl < d__[1] && wu >= d__[1]) {
  894. *m = 1;
  895. w[1] = d__[1];
  896. }
  897. }
  898. if (wantz && ! zquery) {
  899. i__1 = z_dim1 + 1;
  900. z__[i__1].r = 1., z__[i__1].i = 0.;
  901. isuppz[1] = 1;
  902. isuppz[2] = 1;
  903. }
  904. return 0;
  905. }
  906. if (*n == 2) {
  907. if (! wantz) {
  908. dlae2_(&d__[1], &e[1], &d__[2], &r1, &r2);
  909. } else if (wantz && ! zquery) {
  910. dlaev2_(&d__[1], &e[1], &d__[2], &r1, &r2, &cs, &sn);
  911. }
  912. if (alleig || valeig && r2 > wl && r2 <= wu || indeig && iil == 1) {
  913. ++(*m);
  914. w[*m] = r2;
  915. if (wantz && ! zquery) {
  916. i__1 = *m * z_dim1 + 1;
  917. d__1 = -sn;
  918. z__[i__1].r = d__1, z__[i__1].i = 0.;
  919. i__1 = *m * z_dim1 + 2;
  920. z__[i__1].r = cs, z__[i__1].i = 0.;
  921. /* Note: At most one of SN and CS can be zero. */
  922. if (sn != 0.) {
  923. if (cs != 0.) {
  924. isuppz[(*m << 1) - 1] = 1;
  925. isuppz[*m * 2] = 2;
  926. } else {
  927. isuppz[(*m << 1) - 1] = 1;
  928. isuppz[*m * 2] = 1;
  929. }
  930. } else {
  931. isuppz[(*m << 1) - 1] = 2;
  932. isuppz[*m * 2] = 2;
  933. }
  934. }
  935. }
  936. if (alleig || valeig && r1 > wl && r1 <= wu || indeig && iiu == 2) {
  937. ++(*m);
  938. w[*m] = r1;
  939. if (wantz && ! zquery) {
  940. i__1 = *m * z_dim1 + 1;
  941. z__[i__1].r = cs, z__[i__1].i = 0.;
  942. i__1 = *m * z_dim1 + 2;
  943. z__[i__1].r = sn, z__[i__1].i = 0.;
  944. /* Note: At most one of SN and CS can be zero. */
  945. if (sn != 0.) {
  946. if (cs != 0.) {
  947. isuppz[(*m << 1) - 1] = 1;
  948. isuppz[*m * 2] = 2;
  949. } else {
  950. isuppz[(*m << 1) - 1] = 1;
  951. isuppz[*m * 2] = 1;
  952. }
  953. } else {
  954. isuppz[(*m << 1) - 1] = 2;
  955. isuppz[*m * 2] = 2;
  956. }
  957. }
  958. }
  959. } else {
  960. /* Continue with general N */
  961. indgrs = 1;
  962. inderr = (*n << 1) + 1;
  963. indgp = *n * 3 + 1;
  964. indd = (*n << 2) + 1;
  965. inde2 = *n * 5 + 1;
  966. indwrk = *n * 6 + 1;
  967. iinspl = 1;
  968. iindbl = *n + 1;
  969. iindw = (*n << 1) + 1;
  970. iindwk = *n * 3 + 1;
  971. /* Scale matrix to allowable range, if necessary. */
  972. /* The allowable range is related to the PIVMIN parameter; see the */
  973. /* comments in DLARRD. The preference for scaling small values */
  974. /* up is heuristic; we expect users' matrices not to be close to the */
  975. /* RMAX threshold. */
  976. scale = 1.;
  977. tnrm = dlanst_("M", n, &d__[1], &e[1]);
  978. if (tnrm > 0. && tnrm < rmin) {
  979. scale = rmin / tnrm;
  980. } else if (tnrm > rmax) {
  981. scale = rmax / tnrm;
  982. }
  983. if (scale != 1.) {
  984. dscal_(n, &scale, &d__[1], &c__1);
  985. i__1 = *n - 1;
  986. dscal_(&i__1, &scale, &e[1], &c__1);
  987. tnrm *= scale;
  988. if (valeig) {
  989. /* If eigenvalues in interval have to be found, */
  990. /* scale (WL, WU] accordingly */
  991. wl *= scale;
  992. wu *= scale;
  993. }
  994. }
  995. /* Compute the desired eigenvalues of the tridiagonal after splitting */
  996. /* into smaller subblocks if the corresponding off-diagonal elements */
  997. /* are small */
  998. /* THRESH is the splitting parameter for DLARRE */
  999. /* A negative THRESH forces the old splitting criterion based on the */
  1000. /* size of the off-diagonal. A positive THRESH switches to splitting */
  1001. /* which preserves relative accuracy. */
  1002. if (*tryrac) {
  1003. /* Test whether the matrix warrants the more expensive relative approach. */
  1004. dlarrr_(n, &d__[1], &e[1], &iinfo);
  1005. } else {
  1006. /* The user does not care about relative accurately eigenvalues */
  1007. iinfo = -1;
  1008. }
  1009. /* Set the splitting criterion */
  1010. if (iinfo == 0) {
  1011. thresh = eps;
  1012. } else {
  1013. thresh = -eps;
  1014. /* relative accuracy is desired but T does not guarantee it */
  1015. *tryrac = FALSE_;
  1016. }
  1017. if (*tryrac) {
  1018. /* Copy original diagonal, needed to guarantee relative accuracy */
  1019. dcopy_(n, &d__[1], &c__1, &work[indd], &c__1);
  1020. }
  1021. /* Store the squares of the offdiagonal values of T */
  1022. i__1 = *n - 1;
  1023. for (j = 1; j <= i__1; ++j) {
  1024. /* Computing 2nd power */
  1025. d__1 = e[j];
  1026. work[inde2 + j - 1] = d__1 * d__1;
  1027. /* L5: */
  1028. }
  1029. /* Set the tolerance parameters for bisection */
  1030. if (! wantz) {
  1031. /* DLARRE computes the eigenvalues to full precision. */
  1032. rtol1 = eps * 4.;
  1033. rtol2 = eps * 4.;
  1034. } else {
  1035. /* DLARRE computes the eigenvalues to less than full precision. */
  1036. /* ZLARRV will refine the eigenvalue approximations, and we only */
  1037. /* need less accurate initial bisection in DLARRE. */
  1038. /* Note: these settings do only affect the subset case and DLARRE */
  1039. rtol1 = sqrt(eps);
  1040. /* Computing MAX */
  1041. d__1 = sqrt(eps) * .005, d__2 = eps * 4.;
  1042. rtol2 = f2cmax(d__1,d__2);
  1043. }
  1044. dlarre_(range, n, &wl, &wu, &iil, &iiu, &d__[1], &e[1], &work[inde2],
  1045. &rtol1, &rtol2, &thresh, &nsplit, &iwork[iinspl], m, &w[1], &
  1046. work[inderr], &work[indgp], &iwork[iindbl], &iwork[iindw], &
  1047. work[indgrs], &pivmin, &work[indwrk], &iwork[iindwk], &iinfo);
  1048. if (iinfo != 0) {
  1049. *info = abs(iinfo) + 10;
  1050. return 0;
  1051. }
  1052. /* Note that if RANGE .NE. 'V', DLARRE computes bounds on the desired */
  1053. /* part of the spectrum. All desired eigenvalues are contained in */
  1054. /* (WL,WU] */
  1055. if (wantz) {
  1056. /* Compute the desired eigenvectors corresponding to the computed */
  1057. /* eigenvalues */
  1058. zlarrv_(n, &wl, &wu, &d__[1], &e[1], &pivmin, &iwork[iinspl], m, &
  1059. c__1, m, &c_b18, &rtol1, &rtol2, &w[1], &work[inderr], &
  1060. work[indgp], &iwork[iindbl], &iwork[iindw], &work[indgrs],
  1061. &z__[z_offset], ldz, &isuppz[1], &work[indwrk], &iwork[
  1062. iindwk], &iinfo);
  1063. if (iinfo != 0) {
  1064. *info = abs(iinfo) + 20;
  1065. return 0;
  1066. }
  1067. } else {
  1068. /* DLARRE computes eigenvalues of the (shifted) root representation */
  1069. /* ZLARRV returns the eigenvalues of the unshifted matrix. */
  1070. /* However, if the eigenvectors are not desired by the user, we need */
  1071. /* to apply the corresponding shifts from DLARRE to obtain the */
  1072. /* eigenvalues of the original matrix. */
  1073. i__1 = *m;
  1074. for (j = 1; j <= i__1; ++j) {
  1075. itmp = iwork[iindbl + j - 1];
  1076. w[j] += e[iwork[iinspl + itmp - 1]];
  1077. /* L20: */
  1078. }
  1079. }
  1080. if (*tryrac) {
  1081. /* Refine computed eigenvalues so that they are relatively accurate */
  1082. /* with respect to the original matrix T. */
  1083. ibegin = 1;
  1084. wbegin = 1;
  1085. i__1 = iwork[iindbl + *m - 1];
  1086. for (jblk = 1; jblk <= i__1; ++jblk) {
  1087. iend = iwork[iinspl + jblk - 1];
  1088. in = iend - ibegin + 1;
  1089. wend = wbegin - 1;
  1090. /* check if any eigenvalues have to be refined in this block */
  1091. L36:
  1092. if (wend < *m) {
  1093. if (iwork[iindbl + wend] == jblk) {
  1094. ++wend;
  1095. goto L36;
  1096. }
  1097. }
  1098. if (wend < wbegin) {
  1099. ibegin = iend + 1;
  1100. goto L39;
  1101. }
  1102. offset = iwork[iindw + wbegin - 1] - 1;
  1103. ifirst = iwork[iindw + wbegin - 1];
  1104. ilast = iwork[iindw + wend - 1];
  1105. rtol2 = eps * 4.;
  1106. dlarrj_(&in, &work[indd + ibegin - 1], &work[inde2 + ibegin -
  1107. 1], &ifirst, &ilast, &rtol2, &offset, &w[wbegin], &
  1108. work[inderr + wbegin - 1], &work[indwrk], &iwork[
  1109. iindwk], &pivmin, &tnrm, &iinfo);
  1110. ibegin = iend + 1;
  1111. wbegin = wend + 1;
  1112. L39:
  1113. ;
  1114. }
  1115. }
  1116. /* If matrix was scaled, then rescale eigenvalues appropriately. */
  1117. if (scale != 1.) {
  1118. d__1 = 1. / scale;
  1119. dscal_(m, &d__1, &w[1], &c__1);
  1120. }
  1121. }
  1122. /* If eigenvalues are not in increasing order, then sort them, */
  1123. /* possibly along with eigenvectors. */
  1124. if (nsplit > 1 || *n == 2) {
  1125. if (! wantz) {
  1126. dlasrt_("I", m, &w[1], &iinfo);
  1127. if (iinfo != 0) {
  1128. *info = 3;
  1129. return 0;
  1130. }
  1131. } else {
  1132. i__1 = *m - 1;
  1133. for (j = 1; j <= i__1; ++j) {
  1134. i__ = 0;
  1135. tmp = w[j];
  1136. i__2 = *m;
  1137. for (jj = j + 1; jj <= i__2; ++jj) {
  1138. if (w[jj] < tmp) {
  1139. i__ = jj;
  1140. tmp = w[jj];
  1141. }
  1142. /* L50: */
  1143. }
  1144. if (i__ != 0) {
  1145. w[i__] = w[j];
  1146. w[j] = tmp;
  1147. if (wantz) {
  1148. zswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j *
  1149. z_dim1 + 1], &c__1);
  1150. itmp = isuppz[(i__ << 1) - 1];
  1151. isuppz[(i__ << 1) - 1] = isuppz[(j << 1) - 1];
  1152. isuppz[(j << 1) - 1] = itmp;
  1153. itmp = isuppz[i__ * 2];
  1154. isuppz[i__ * 2] = isuppz[j * 2];
  1155. isuppz[j * 2] = itmp;
  1156. }
  1157. }
  1158. /* L60: */
  1159. }
  1160. }
  1161. }
  1162. work[1] = (doublereal) lwmin;
  1163. iwork[1] = liwmin;
  1164. return 0;
  1165. /* End of ZSTEMR */
  1166. } /* zstemr_ */