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.

dstemr.c 39 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209
  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. typedef int integer;
  18. typedef unsigned int uinteger;
  19. typedef char *address;
  20. typedef short int shortint;
  21. typedef float real;
  22. typedef double doublereal;
  23. typedef struct { real r, i; } complex;
  24. typedef struct { doublereal r, i; } doublecomplex;
  25. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  26. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  27. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  28. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  29. #define pCf(z) (*_pCf(z))
  30. #define pCd(z) (*_pCd(z))
  31. typedef int logical;
  32. typedef short int shortlogical;
  33. typedef char logical1;
  34. typedef char integer1;
  35. #define TRUE_ (1)
  36. #define FALSE_ (0)
  37. /* Extern is for use with -E */
  38. #ifndef Extern
  39. #define Extern extern
  40. #endif
  41. /* I/O stuff */
  42. typedef int flag;
  43. typedef int ftnlen;
  44. typedef int ftnint;
  45. /*external read, write*/
  46. typedef struct
  47. { flag cierr;
  48. ftnint ciunit;
  49. flag ciend;
  50. char *cifmt;
  51. ftnint cirec;
  52. } cilist;
  53. /*internal read, write*/
  54. typedef struct
  55. { flag icierr;
  56. char *iciunit;
  57. flag iciend;
  58. char *icifmt;
  59. ftnint icirlen;
  60. ftnint icirnum;
  61. } icilist;
  62. /*open*/
  63. typedef struct
  64. { flag oerr;
  65. ftnint ounit;
  66. char *ofnm;
  67. ftnlen ofnmlen;
  68. char *osta;
  69. char *oacc;
  70. char *ofm;
  71. ftnint orl;
  72. char *oblnk;
  73. } olist;
  74. /*close*/
  75. typedef struct
  76. { flag cerr;
  77. ftnint cunit;
  78. char *csta;
  79. } cllist;
  80. /*rewind, backspace, endfile*/
  81. typedef struct
  82. { flag aerr;
  83. ftnint aunit;
  84. } alist;
  85. /* inquire */
  86. typedef struct
  87. { flag inerr;
  88. ftnint inunit;
  89. char *infile;
  90. ftnlen infilen;
  91. ftnint *inex; /*parameters in standard's order*/
  92. ftnint *inopen;
  93. ftnint *innum;
  94. ftnint *innamed;
  95. char *inname;
  96. ftnlen innamlen;
  97. char *inacc;
  98. ftnlen inacclen;
  99. char *inseq;
  100. ftnlen inseqlen;
  101. char *indir;
  102. ftnlen indirlen;
  103. char *infmt;
  104. ftnlen infmtlen;
  105. char *inform;
  106. ftnint informlen;
  107. char *inunf;
  108. ftnlen inunflen;
  109. ftnint *inrecl;
  110. ftnint *innrec;
  111. char *inblank;
  112. ftnlen inblanklen;
  113. } inlist;
  114. #define VOID void
  115. union Multitype { /* for multiple entry points */
  116. integer1 g;
  117. shortint h;
  118. integer i;
  119. /* longint j; */
  120. real r;
  121. doublereal d;
  122. complex c;
  123. doublecomplex z;
  124. };
  125. typedef union Multitype Multitype;
  126. struct Vardesc { /* for Namelist */
  127. char *name;
  128. char *addr;
  129. ftnlen *dims;
  130. int type;
  131. };
  132. typedef struct Vardesc Vardesc;
  133. struct Namelist {
  134. char *name;
  135. Vardesc **vars;
  136. int nvars;
  137. };
  138. typedef struct Namelist Namelist;
  139. #define abs(x) ((x) >= 0 ? (x) : -(x))
  140. #define dabs(x) (fabs(x))
  141. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  142. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  143. #define dmin(a,b) (f2cmin(a,b))
  144. #define dmax(a,b) (f2cmax(a,b))
  145. #define bit_test(a,b) ((a) >> (b) & 1)
  146. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  147. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  148. #define abort_() { sig_die("Fortran abort routine called", 1); }
  149. #define c_abs(z) (cabsf(Cf(z)))
  150. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  151. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  152. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  153. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  154. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  155. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  156. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  157. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  158. #define d_abs(x) (fabs(*(x)))
  159. #define d_acos(x) (acos(*(x)))
  160. #define d_asin(x) (asin(*(x)))
  161. #define d_atan(x) (atan(*(x)))
  162. #define d_atn2(x, y) (atan2(*(x),*(y)))
  163. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  164. #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
  165. #define d_cos(x) (cos(*(x)))
  166. #define d_cosh(x) (cosh(*(x)))
  167. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  168. #define d_exp(x) (exp(*(x)))
  169. #define d_imag(z) (cimag(Cd(z)))
  170. #define r_imag(z) (cimag(Cf(z)))
  171. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  172. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  173. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  174. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  175. #define d_log(x) (log(*(x)))
  176. #define d_mod(x, y) (fmod(*(x), *(y)))
  177. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  178. #define d_nint(x) u_nint(*(x))
  179. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  180. #define d_sign(a,b) u_sign(*(a),*(b))
  181. #define r_sign(a,b) u_sign(*(a),*(b))
  182. #define d_sin(x) (sin(*(x)))
  183. #define d_sinh(x) (sinh(*(x)))
  184. #define d_sqrt(x) (sqrt(*(x)))
  185. #define d_tan(x) (tan(*(x)))
  186. #define d_tanh(x) (tanh(*(x)))
  187. #define i_abs(x) abs(*(x))
  188. #define i_dnnt(x) ((integer)u_nint(*(x)))
  189. #define i_len(s, n) (n)
  190. #define i_nint(x) ((integer)u_nint(*(x)))
  191. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  192. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  193. #define pow_si(B,E) spow_ui(*(B),*(E))
  194. #define pow_ri(B,E) spow_ui(*(B),*(E))
  195. #define pow_di(B,E) dpow_ui(*(B),*(E))
  196. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  197. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  198. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  199. #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++ = ' '; }
  200. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  201. #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]; }
  202. #define sig_die(s, kill) { exit(1); }
  203. #define s_stop(s, n) {exit(0);}
  204. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  205. #define z_abs(z) (cabs(Cd(z)))
  206. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  207. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  208. #define myexit_() break;
  209. #define mycycle() continue;
  210. #define myceiling(w) {ceil(w)}
  211. #define myhuge(w) {HUGE_VAL}
  212. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  213. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  214. /* procedure parameter types for -A and -C++ */
  215. #define F2C_proc_par_types 1
  216. #ifdef __cplusplus
  217. typedef logical (*L_fp)(...);
  218. #else
  219. typedef logical (*L_fp)();
  220. #endif
  221. static float spow_ui(float x, integer n) {
  222. float pow=1.0; unsigned long int u;
  223. if(n != 0) {
  224. if(n < 0) n = -n, x = 1/x;
  225. for(u = n; ; ) {
  226. if(u & 01) pow *= x;
  227. if(u >>= 1) x *= x;
  228. else break;
  229. }
  230. }
  231. return pow;
  232. }
  233. static double dpow_ui(double x, integer n) {
  234. double pow=1.0; unsigned long int u;
  235. if(n != 0) {
  236. if(n < 0) n = -n, x = 1/x;
  237. for(u = n; ; ) {
  238. if(u & 01) pow *= x;
  239. if(u >>= 1) x *= x;
  240. else break;
  241. }
  242. }
  243. return pow;
  244. }
  245. static _Complex float cpow_ui(_Complex float x, integer n) {
  246. _Complex float pow=1.0; unsigned long int u;
  247. if(n != 0) {
  248. if(n < 0) n = -n, x = 1/x;
  249. for(u = n; ; ) {
  250. if(u & 01) pow *= x;
  251. if(u >>= 1) x *= x;
  252. else break;
  253. }
  254. }
  255. return pow;
  256. }
  257. static _Complex double zpow_ui(_Complex double x, integer n) {
  258. _Complex double pow=1.0; unsigned long int u;
  259. if(n != 0) {
  260. if(n < 0) n = -n, x = 1/x;
  261. for(u = n; ; ) {
  262. if(u & 01) pow *= x;
  263. if(u >>= 1) x *= x;
  264. else break;
  265. }
  266. }
  267. return pow;
  268. }
  269. static integer pow_ii(integer x, integer n) {
  270. integer pow; unsigned long int u;
  271. if (n <= 0) {
  272. if (n == 0 || x == 1) pow = 1;
  273. else if (x != -1) pow = x == 0 ? 1/x : 0;
  274. else n = -n;
  275. }
  276. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  277. u = n;
  278. for(pow = 1; ; ) {
  279. if(u & 01) pow *= x;
  280. if(u >>= 1) x *= x;
  281. else break;
  282. }
  283. }
  284. return pow;
  285. }
  286. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  287. {
  288. double m; integer i, mi;
  289. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  290. if (w[i-1]>m) mi=i ,m=w[i-1];
  291. return mi-s+1;
  292. }
  293. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  294. {
  295. float m; integer i, mi;
  296. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  297. if (w[i-1]>m) mi=i ,m=w[i-1];
  298. return mi-s+1;
  299. }
  300. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  301. integer n = *n_, incx = *incx_, incy = *incy_, i;
  302. _Complex float zdotc = 0.0;
  303. if (incx == 1 && incy == 1) {
  304. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  305. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  306. }
  307. } else {
  308. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  309. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  310. }
  311. }
  312. pCf(z) = zdotc;
  313. }
  314. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  315. integer n = *n_, incx = *incx_, incy = *incy_, i;
  316. _Complex double zdotc = 0.0;
  317. if (incx == 1 && incy == 1) {
  318. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  319. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  320. }
  321. } else {
  322. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  323. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  324. }
  325. }
  326. pCd(z) = zdotc;
  327. }
  328. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  329. integer n = *n_, incx = *incx_, incy = *incy_, i;
  330. _Complex float zdotc = 0.0;
  331. if (incx == 1 && incy == 1) {
  332. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  333. zdotc += Cf(&x[i]) * Cf(&y[i]);
  334. }
  335. } else {
  336. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  337. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  338. }
  339. }
  340. pCf(z) = zdotc;
  341. }
  342. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  343. integer n = *n_, incx = *incx_, incy = *incy_, i;
  344. _Complex double zdotc = 0.0;
  345. if (incx == 1 && incy == 1) {
  346. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  347. zdotc += Cd(&x[i]) * Cd(&y[i]);
  348. }
  349. } else {
  350. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  351. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  352. }
  353. }
  354. pCd(z) = zdotc;
  355. }
  356. #endif
  357. /* -- translated by f2c (version 20000121).
  358. You must link the resulting object file with the libraries:
  359. -lf2c -lm (in that order)
  360. */
  361. /* Table of constant values */
  362. static integer c__1 = 1;
  363. static doublereal c_b18 = .001;
  364. /* > \brief \b DSTEMR */
  365. /* =========== DOCUMENTATION =========== */
  366. /* Online html documentation available at */
  367. /* http://www.netlib.org/lapack/explore-html/ */
  368. /* > \htmlonly */
  369. /* > Download DSTEMR + dependencies */
  370. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dstemr.
  371. f"> */
  372. /* > [TGZ]</a> */
  373. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dstemr.
  374. f"> */
  375. /* > [ZIP]</a> */
  376. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dstemr.
  377. f"> */
  378. /* > [TXT]</a> */
  379. /* > \endhtmlonly */
  380. /* Definition: */
  381. /* =========== */
  382. /* SUBROUTINE DSTEMR( JOBZ, RANGE, N, D, E, VL, VU, IL, IU, */
  383. /* M, W, Z, LDZ, NZC, ISUPPZ, TRYRAC, WORK, LWORK, */
  384. /* IWORK, LIWORK, INFO ) */
  385. /* CHARACTER JOBZ, RANGE */
  386. /* LOGICAL TRYRAC */
  387. /* INTEGER IL, INFO, IU, LDZ, NZC, LIWORK, LWORK, M, N */
  388. /* DOUBLE PRECISION VL, VU */
  389. /* INTEGER ISUPPZ( * ), IWORK( * ) */
  390. /* DOUBLE PRECISION D( * ), E( * ), W( * ), WORK( * ) */
  391. /* DOUBLE PRECISION Z( LDZ, * ) */
  392. /* > \par Purpose: */
  393. /* ============= */
  394. /* > */
  395. /* > \verbatim */
  396. /* > */
  397. /* > DSTEMR computes selected eigenvalues and, optionally, eigenvectors */
  398. /* > of a real symmetric tridiagonal matrix T. Any such unreduced matrix has */
  399. /* > a well defined set of pairwise different real eigenvalues, the corresponding */
  400. /* > real eigenvectors are pairwise orthogonal. */
  401. /* > */
  402. /* > The spectrum may be computed either completely or partially by specifying */
  403. /* > either an interval (VL,VU] or a range of indices IL:IU for the desired */
  404. /* > eigenvalues. */
  405. /* > */
  406. /* > Depending on the number of desired eigenvalues, these are computed either */
  407. /* > by bisection or the dqds algorithm. Numerically orthogonal eigenvectors are */
  408. /* > computed by the use of various suitable L D L^T factorizations near clusters */
  409. /* > of close eigenvalues (referred to as RRRs, Relatively Robust */
  410. /* > Representations). An informal sketch of the algorithm follows. */
  411. /* > */
  412. /* > For each unreduced block (submatrix) of T, */
  413. /* > (a) Compute T - sigma I = L D L^T, so that L and D */
  414. /* > define all the wanted eigenvalues to high relative accuracy. */
  415. /* > This means that small relative changes in the entries of D and L */
  416. /* > cause only small relative changes in the eigenvalues and */
  417. /* > eigenvectors. The standard (unfactored) representation of the */
  418. /* > tridiagonal matrix T does not have this property in general. */
  419. /* > (b) Compute the eigenvalues to suitable accuracy. */
  420. /* > If the eigenvectors are desired, the algorithm attains full */
  421. /* > accuracy of the computed eigenvalues only right before */
  422. /* > the corresponding vectors have to be computed, see steps c) and d). */
  423. /* > (c) For each cluster of close eigenvalues, select a new */
  424. /* > shift close to the cluster, find a new factorization, and refine */
  425. /* > the shifted eigenvalues to suitable accuracy. */
  426. /* > (d) For each eigenvalue with a large enough relative separation compute */
  427. /* > the corresponding eigenvector by forming a rank revealing twisted */
  428. /* > factorization. Go back to (c) for any clusters that remain. */
  429. /* > */
  430. /* > For more details, see: */
  431. /* > - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations */
  432. /* > to compute orthogonal eigenvectors of symmetric tridiagonal matrices," */
  433. /* > Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004. */
  434. /* > - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and */
  435. /* > Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25, */
  436. /* > 2004. Also LAPACK Working Note 154. */
  437. /* > - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric */
  438. /* > tridiagonal eigenvalue/eigenvector problem", */
  439. /* > Computer Science Division Technical Report No. UCB/CSD-97-971, */
  440. /* > UC Berkeley, May 1997. */
  441. /* > */
  442. /* > Further Details */
  443. /* > 1.DSTEMR works only on machines which follow IEEE-754 */
  444. /* > floating-point standard in their handling of infinities and NaNs. */
  445. /* > This permits the use of efficient inner loops avoiding a check for */
  446. /* > zero divisors. */
  447. /* > \endverbatim */
  448. /* Arguments: */
  449. /* ========== */
  450. /* > \param[in] JOBZ */
  451. /* > \verbatim */
  452. /* > JOBZ is CHARACTER*1 */
  453. /* > = 'N': Compute eigenvalues only; */
  454. /* > = 'V': Compute eigenvalues and eigenvectors. */
  455. /* > \endverbatim */
  456. /* > */
  457. /* > \param[in] RANGE */
  458. /* > \verbatim */
  459. /* > RANGE is CHARACTER*1 */
  460. /* > = 'A': all eigenvalues will be found. */
  461. /* > = 'V': all eigenvalues in the half-open interval (VL,VU] */
  462. /* > will be found. */
  463. /* > = 'I': the IL-th through IU-th eigenvalues will be found. */
  464. /* > \endverbatim */
  465. /* > */
  466. /* > \param[in] N */
  467. /* > \verbatim */
  468. /* > N is INTEGER */
  469. /* > The order of the matrix. N >= 0. */
  470. /* > \endverbatim */
  471. /* > */
  472. /* > \param[in,out] D */
  473. /* > \verbatim */
  474. /* > D is DOUBLE PRECISION array, dimension (N) */
  475. /* > On entry, the N diagonal elements of the tridiagonal matrix */
  476. /* > T. On exit, D is overwritten. */
  477. /* > \endverbatim */
  478. /* > */
  479. /* > \param[in,out] E */
  480. /* > \verbatim */
  481. /* > E is DOUBLE PRECISION array, dimension (N) */
  482. /* > On entry, the (N-1) subdiagonal elements of the tridiagonal */
  483. /* > matrix T in elements 1 to N-1 of E. E(N) need not be set on */
  484. /* > input, but is used internally as workspace. */
  485. /* > On exit, E is overwritten. */
  486. /* > \endverbatim */
  487. /* > */
  488. /* > \param[in] VL */
  489. /* > \verbatim */
  490. /* > VL is DOUBLE PRECISION */
  491. /* > */
  492. /* > If RANGE='V', the lower bound of the interval to */
  493. /* > be searched for eigenvalues. VL < VU. */
  494. /* > Not referenced if RANGE = 'A' or 'I'. */
  495. /* > \endverbatim */
  496. /* > */
  497. /* > \param[in] VU */
  498. /* > \verbatim */
  499. /* > VU is DOUBLE PRECISION */
  500. /* > */
  501. /* > If RANGE='V', the upper bound of the interval to */
  502. /* > be searched for eigenvalues. VL < VU. */
  503. /* > Not referenced if RANGE = 'A' or 'I'. */
  504. /* > \endverbatim */
  505. /* > */
  506. /* > \param[in] IL */
  507. /* > \verbatim */
  508. /* > IL is INTEGER */
  509. /* > */
  510. /* > If RANGE='I', the index of the */
  511. /* > smallest eigenvalue to be returned. */
  512. /* > 1 <= IL <= IU <= N, if N > 0. */
  513. /* > Not referenced if RANGE = 'A' or 'V'. */
  514. /* > \endverbatim */
  515. /* > */
  516. /* > \param[in] IU */
  517. /* > \verbatim */
  518. /* > IU is INTEGER */
  519. /* > */
  520. /* > If RANGE='I', the index of the */
  521. /* > largest eigenvalue to be returned. */
  522. /* > 1 <= IL <= IU <= N, if N > 0. */
  523. /* > Not referenced if RANGE = 'A' or 'V'. */
  524. /* > \endverbatim */
  525. /* > */
  526. /* > \param[out] M */
  527. /* > \verbatim */
  528. /* > M is INTEGER */
  529. /* > The total number of eigenvalues found. 0 <= M <= N. */
  530. /* > If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
  531. /* > \endverbatim */
  532. /* > */
  533. /* > \param[out] W */
  534. /* > \verbatim */
  535. /* > W is DOUBLE PRECISION array, dimension (N) */
  536. /* > The first M elements contain the selected eigenvalues in */
  537. /* > ascending order. */
  538. /* > \endverbatim */
  539. /* > */
  540. /* > \param[out] Z */
  541. /* > \verbatim */
  542. /* > Z is DOUBLE PRECISION array, dimension (LDZ, f2cmax(1,M) ) */
  543. /* > If JOBZ = 'V', and if INFO = 0, then the first M columns of Z */
  544. /* > contain the orthonormal eigenvectors of the matrix T */
  545. /* > corresponding to the selected eigenvalues, with the i-th */
  546. /* > column of Z holding the eigenvector associated with W(i). */
  547. /* > If JOBZ = 'N', then Z is not referenced. */
  548. /* > Note: the user must ensure that at least f2cmax(1,M) columns are */
  549. /* > supplied in the array Z; if RANGE = 'V', the exact value of M */
  550. /* > is not known in advance and can be computed with a workspace */
  551. /* > query by setting NZC = -1, see below. */
  552. /* > \endverbatim */
  553. /* > */
  554. /* > \param[in] LDZ */
  555. /* > \verbatim */
  556. /* > LDZ is INTEGER */
  557. /* > The leading dimension of the array Z. LDZ >= 1, and if */
  558. /* > JOBZ = 'V', then LDZ >= f2cmax(1,N). */
  559. /* > \endverbatim */
  560. /* > */
  561. /* > \param[in] NZC */
  562. /* > \verbatim */
  563. /* > NZC is INTEGER */
  564. /* > The number of eigenvectors to be held in the array Z. */
  565. /* > If RANGE = 'A', then NZC >= f2cmax(1,N). */
  566. /* > If RANGE = 'V', then NZC >= the number of eigenvalues in (VL,VU]. */
  567. /* > If RANGE = 'I', then NZC >= IU-IL+1. */
  568. /* > If NZC = -1, then a workspace query is assumed; the */
  569. /* > routine calculates the number of columns of the array Z that */
  570. /* > are needed to hold the eigenvectors. */
  571. /* > This value is returned as the first entry of the Z array, and */
  572. /* > no error message related to NZC is issued by XERBLA. */
  573. /* > \endverbatim */
  574. /* > */
  575. /* > \param[out] ISUPPZ */
  576. /* > \verbatim */
  577. /* > ISUPPZ is INTEGER array, dimension ( 2*f2cmax(1,M) ) */
  578. /* > The support of the eigenvectors in Z, i.e., the indices */
  579. /* > indicating the nonzero elements in Z. The i-th computed eigenvector */
  580. /* > is nonzero only in elements ISUPPZ( 2*i-1 ) through */
  581. /* > ISUPPZ( 2*i ). This is relevant in the case when the matrix */
  582. /* > is split. ISUPPZ is only accessed when JOBZ is 'V' and N > 0. */
  583. /* > \endverbatim */
  584. /* > */
  585. /* > \param[in,out] TRYRAC */
  586. /* > \verbatim */
  587. /* > TRYRAC is LOGICAL */
  588. /* > If TRYRAC = .TRUE., indicates that the code should check whether */
  589. /* > the tridiagonal matrix defines its eigenvalues to high relative */
  590. /* > accuracy. If so, the code uses relative-accuracy preserving */
  591. /* > algorithms that might be (a bit) slower depending on the matrix. */
  592. /* > If the matrix does not define its eigenvalues to high relative */
  593. /* > accuracy, the code can uses possibly faster algorithms. */
  594. /* > If TRYRAC = .FALSE., the code is not required to guarantee */
  595. /* > relatively accurate eigenvalues and can use the fastest possible */
  596. /* > techniques. */
  597. /* > On exit, a .TRUE. TRYRAC will be set to .FALSE. if the matrix */
  598. /* > does not define its eigenvalues to high relative accuracy. */
  599. /* > \endverbatim */
  600. /* > */
  601. /* > \param[out] WORK */
  602. /* > \verbatim */
  603. /* > WORK is DOUBLE PRECISION array, dimension (LWORK) */
  604. /* > On exit, if INFO = 0, WORK(1) returns the optimal */
  605. /* > (and minimal) LWORK. */
  606. /* > \endverbatim */
  607. /* > */
  608. /* > \param[in] LWORK */
  609. /* > \verbatim */
  610. /* > LWORK is INTEGER */
  611. /* > The dimension of the array WORK. LWORK >= f2cmax(1,18*N) */
  612. /* > if JOBZ = 'V', and LWORK >= f2cmax(1,12*N) if JOBZ = 'N'. */
  613. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  614. /* > only calculates the optimal size of the WORK array, returns */
  615. /* > this value as the first entry of the WORK array, and no error */
  616. /* > message related to LWORK is issued by XERBLA. */
  617. /* > \endverbatim */
  618. /* > */
  619. /* > \param[out] IWORK */
  620. /* > \verbatim */
  621. /* > IWORK is INTEGER array, dimension (LIWORK) */
  622. /* > On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
  623. /* > \endverbatim */
  624. /* > */
  625. /* > \param[in] LIWORK */
  626. /* > \verbatim */
  627. /* > LIWORK is INTEGER */
  628. /* > The dimension of the array IWORK. LIWORK >= f2cmax(1,10*N) */
  629. /* > if the eigenvectors are desired, and LIWORK >= f2cmax(1,8*N) */
  630. /* > if only the eigenvalues are to be computed. */
  631. /* > If LIWORK = -1, then a workspace query is assumed; the */
  632. /* > routine only calculates the optimal size of the IWORK array, */
  633. /* > returns this value as the first entry of the IWORK array, and */
  634. /* > no error message related to LIWORK is issued by XERBLA. */
  635. /* > \endverbatim */
  636. /* > */
  637. /* > \param[out] INFO */
  638. /* > \verbatim */
  639. /* > INFO is INTEGER */
  640. /* > On exit, INFO */
  641. /* > = 0: successful exit */
  642. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  643. /* > > 0: if INFO = 1X, internal error in DLARRE, */
  644. /* > if INFO = 2X, internal error in DLARRV. */
  645. /* > Here, the digit X = ABS( IINFO ) < 10, where IINFO is */
  646. /* > the nonzero error code returned by DLARRE or */
  647. /* > DLARRV, respectively. */
  648. /* > \endverbatim */
  649. /* Authors: */
  650. /* ======== */
  651. /* > \author Univ. of Tennessee */
  652. /* > \author Univ. of California Berkeley */
  653. /* > \author Univ. of Colorado Denver */
  654. /* > \author NAG Ltd. */
  655. /* > \date June 2016 */
  656. /* > \ingroup doubleOTHERcomputational */
  657. /* > \par Contributors: */
  658. /* ================== */
  659. /* > */
  660. /* > Beresford Parlett, University of California, Berkeley, USA \n */
  661. /* > Jim Demmel, University of California, Berkeley, USA \n */
  662. /* > Inderjit Dhillon, University of Texas, Austin, USA \n */
  663. /* > Osni Marques, LBNL/NERSC, USA \n */
  664. /* > Christof Voemel, University of California, Berkeley, USA */
  665. /* ===================================================================== */
  666. /* Subroutine */ int dstemr_(char *jobz, char *range, integer *n, doublereal *
  667. d__, doublereal *e, doublereal *vl, doublereal *vu, integer *il,
  668. integer *iu, integer *m, doublereal *w, doublereal *z__, integer *ldz,
  669. integer *nzc, integer *isuppz, logical *tryrac, doublereal *work,
  670. integer *lwork, integer *iwork, integer *liwork, integer *info)
  671. {
  672. /* System generated locals */
  673. integer z_dim1, z_offset, i__1, i__2;
  674. doublereal d__1, d__2;
  675. /* Local variables */
  676. integer indd, iend, jblk, wend;
  677. doublereal rmin, rmax;
  678. integer itmp;
  679. doublereal tnrm;
  680. extern /* Subroutine */ int dlae2_(doublereal *, doublereal *, doublereal
  681. *, doublereal *, doublereal *);
  682. integer inde2, itmp2;
  683. doublereal rtol1, rtol2;
  684. integer i__, j;
  685. extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
  686. integer *);
  687. doublereal scale;
  688. integer indgp;
  689. extern logical lsame_(char *, char *);
  690. integer iinfo, iindw, ilast;
  691. extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
  692. doublereal *, integer *), dswap_(integer *, doublereal *, integer
  693. *, doublereal *, integer *);
  694. integer lwmin;
  695. logical wantz;
  696. doublereal r1, r2;
  697. extern /* Subroutine */ int dlaev2_(doublereal *, doublereal *,
  698. doublereal *, doublereal *, doublereal *, doublereal *,
  699. doublereal *);
  700. integer jj;
  701. doublereal cs;
  702. integer in;
  703. extern doublereal dlamch_(char *);
  704. logical alleig, indeig;
  705. integer ibegin, iindbl;
  706. doublereal sn, wl;
  707. logical valeig;
  708. extern /* Subroutine */ int dlarrc_(char *, integer *, doublereal *,
  709. doublereal *, doublereal *, doublereal *, doublereal *, integer *,
  710. integer *, integer *, integer *), dlarre_(char *,
  711. integer *, doublereal *, doublereal *, integer *, integer *,
  712. doublereal *, doublereal *, doublereal *, doublereal *,
  713. doublereal *, doublereal *, integer *, integer *, integer *,
  714. doublereal *, doublereal *, doublereal *, integer *, integer *,
  715. doublereal *, doublereal *, doublereal *, integer *, integer *);
  716. integer wbegin;
  717. doublereal safmin, wu;
  718. extern /* Subroutine */ int dlarrj_(integer *, doublereal *, doublereal *,
  719. integer *, integer *, doublereal *, integer *, doublereal *,
  720. doublereal *, doublereal *, integer *, doublereal *, doublereal *,
  721. integer *), xerbla_(char *, integer *, ftnlen);
  722. doublereal bignum;
  723. integer inderr, iindwk, indgrs, offset;
  724. extern doublereal dlanst_(char *, integer *, doublereal *, doublereal *);
  725. extern /* Subroutine */ int dlarrr_(integer *, doublereal *, doublereal *,
  726. integer *), dlarrv_(integer *, doublereal *, doublereal *,
  727. doublereal *, doublereal *, doublereal *, integer *, integer *,
  728. integer *, integer *, doublereal *, doublereal *, doublereal *,
  729. doublereal *, doublereal *, doublereal *, integer *, integer *,
  730. doublereal *, doublereal *, integer *, integer *, doublereal *,
  731. integer *, integer *), dlasrt_(char *, integer *, doublereal *,
  732. integer *);
  733. doublereal thresh;
  734. integer iinspl, ifirst, indwrk, liwmin, nzcmin;
  735. doublereal pivmin;
  736. integer nsplit;
  737. doublereal smlnum;
  738. logical lquery, zquery;
  739. integer iil, iiu;
  740. doublereal eps, tmp;
  741. /* -- LAPACK computational routine (version 3.7.1) -- */
  742. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  743. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  744. /* June 2016 */
  745. /* ===================================================================== */
  746. /* Test the input parameters. */
  747. /* Parameter adjustments */
  748. --d__;
  749. --e;
  750. --w;
  751. z_dim1 = *ldz;
  752. z_offset = 1 + z_dim1 * 1;
  753. z__ -= z_offset;
  754. --isuppz;
  755. --work;
  756. --iwork;
  757. /* Function Body */
  758. wantz = lsame_(jobz, "V");
  759. alleig = lsame_(range, "A");
  760. valeig = lsame_(range, "V");
  761. indeig = lsame_(range, "I");
  762. lquery = *lwork == -1 || *liwork == -1;
  763. zquery = *nzc == -1;
  764. /* DSTEMR needs WORK of size 6*N, IWORK of size 3*N. */
  765. /* In addition, DLARRE needs WORK of size 6*N, IWORK of size 5*N. */
  766. /* Furthermore, DLARRV needs WORK of size 12*N, IWORK of size 7*N. */
  767. if (wantz) {
  768. lwmin = *n * 18;
  769. liwmin = *n * 10;
  770. } else {
  771. /* need less workspace if only the eigenvalues are wanted */
  772. lwmin = *n * 12;
  773. liwmin = *n << 3;
  774. }
  775. wl = 0.;
  776. wu = 0.;
  777. iil = 0;
  778. iiu = 0;
  779. nsplit = 0;
  780. if (valeig) {
  781. /* We do not reference VL, VU in the cases RANGE = 'I','A' */
  782. /* The interval (WL, WU] contains all the wanted eigenvalues. */
  783. /* It is either given by the user or computed in DLARRE. */
  784. wl = *vl;
  785. wu = *vu;
  786. } else if (indeig) {
  787. /* We do not reference IL, IU in the cases RANGE = 'V','A' */
  788. iil = *il;
  789. iiu = *iu;
  790. }
  791. *info = 0;
  792. if (! (wantz || lsame_(jobz, "N"))) {
  793. *info = -1;
  794. } else if (! (alleig || valeig || indeig)) {
  795. *info = -2;
  796. } else if (*n < 0) {
  797. *info = -3;
  798. } else if (valeig && *n > 0 && wu <= wl) {
  799. *info = -7;
  800. } else if (indeig && (iil < 1 || iil > *n)) {
  801. *info = -8;
  802. } else if (indeig && (iiu < iil || iiu > *n)) {
  803. *info = -9;
  804. } else if (*ldz < 1 || wantz && *ldz < *n) {
  805. *info = -13;
  806. } else if (*lwork < lwmin && ! lquery) {
  807. *info = -17;
  808. } else if (*liwork < liwmin && ! lquery) {
  809. *info = -19;
  810. }
  811. /* Get machine constants. */
  812. safmin = dlamch_("Safe minimum");
  813. eps = dlamch_("Precision");
  814. smlnum = safmin / eps;
  815. bignum = 1. / smlnum;
  816. rmin = sqrt(smlnum);
  817. /* Computing MIN */
  818. d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin));
  819. rmax = f2cmin(d__1,d__2);
  820. if (*info == 0) {
  821. work[1] = (doublereal) lwmin;
  822. iwork[1] = liwmin;
  823. if (wantz && alleig) {
  824. nzcmin = *n;
  825. } else if (wantz && valeig) {
  826. dlarrc_("T", n, vl, vu, &d__[1], &e[1], &safmin, &nzcmin, &itmp, &
  827. itmp2, info);
  828. } else if (wantz && indeig) {
  829. nzcmin = iiu - iil + 1;
  830. } else {
  831. /* WANTZ .EQ. FALSE. */
  832. nzcmin = 0;
  833. }
  834. if (zquery && *info == 0) {
  835. z__[z_dim1 + 1] = (doublereal) nzcmin;
  836. } else if (*nzc < nzcmin && ! zquery) {
  837. *info = -14;
  838. }
  839. }
  840. if (*info != 0) {
  841. i__1 = -(*info);
  842. xerbla_("DSTEMR", &i__1, (ftnlen)6);
  843. return 0;
  844. } else if (lquery || zquery) {
  845. return 0;
  846. }
  847. /* Handle N = 0, 1, and 2 cases immediately */
  848. *m = 0;
  849. if (*n == 0) {
  850. return 0;
  851. }
  852. if (*n == 1) {
  853. if (alleig || indeig) {
  854. *m = 1;
  855. w[1] = d__[1];
  856. } else {
  857. if (wl < d__[1] && wu >= d__[1]) {
  858. *m = 1;
  859. w[1] = d__[1];
  860. }
  861. }
  862. if (wantz && ! zquery) {
  863. z__[z_dim1 + 1] = 1.;
  864. isuppz[1] = 1;
  865. isuppz[2] = 1;
  866. }
  867. return 0;
  868. }
  869. if (*n == 2) {
  870. if (! wantz) {
  871. dlae2_(&d__[1], &e[1], &d__[2], &r1, &r2);
  872. } else if (wantz && ! zquery) {
  873. dlaev2_(&d__[1], &e[1], &d__[2], &r1, &r2, &cs, &sn);
  874. }
  875. if (alleig || valeig && r2 > wl && r2 <= wu || indeig && iil == 1) {
  876. ++(*m);
  877. w[*m] = r2;
  878. if (wantz && ! zquery) {
  879. z__[*m * z_dim1 + 1] = -sn;
  880. z__[*m * z_dim1 + 2] = cs;
  881. /* Note: At most one of SN and CS can be zero. */
  882. if (sn != 0.) {
  883. if (cs != 0.) {
  884. isuppz[(*m << 1) - 1] = 1;
  885. isuppz[*m * 2] = 2;
  886. } else {
  887. isuppz[(*m << 1) - 1] = 1;
  888. isuppz[*m * 2] = 1;
  889. }
  890. } else {
  891. isuppz[(*m << 1) - 1] = 2;
  892. isuppz[*m * 2] = 2;
  893. }
  894. }
  895. }
  896. if (alleig || valeig && r1 > wl && r1 <= wu || indeig && iiu == 2) {
  897. ++(*m);
  898. w[*m] = r1;
  899. if (wantz && ! zquery) {
  900. z__[*m * z_dim1 + 1] = cs;
  901. z__[*m * z_dim1 + 2] = sn;
  902. /* Note: At most one of SN and CS can be zero. */
  903. if (sn != 0.) {
  904. if (cs != 0.) {
  905. isuppz[(*m << 1) - 1] = 1;
  906. isuppz[*m * 2] = 2;
  907. } else {
  908. isuppz[(*m << 1) - 1] = 1;
  909. isuppz[*m * 2] = 1;
  910. }
  911. } else {
  912. isuppz[(*m << 1) - 1] = 2;
  913. isuppz[*m * 2] = 2;
  914. }
  915. }
  916. }
  917. } else {
  918. /* Continue with general N */
  919. indgrs = 1;
  920. inderr = (*n << 1) + 1;
  921. indgp = *n * 3 + 1;
  922. indd = (*n << 2) + 1;
  923. inde2 = *n * 5 + 1;
  924. indwrk = *n * 6 + 1;
  925. iinspl = 1;
  926. iindbl = *n + 1;
  927. iindw = (*n << 1) + 1;
  928. iindwk = *n * 3 + 1;
  929. /* Scale matrix to allowable range, if necessary. */
  930. /* The allowable range is related to the PIVMIN parameter; see the */
  931. /* comments in DLARRD. The preference for scaling small values */
  932. /* up is heuristic; we expect users' matrices not to be close to the */
  933. /* RMAX threshold. */
  934. scale = 1.;
  935. tnrm = dlanst_("M", n, &d__[1], &e[1]);
  936. if (tnrm > 0. && tnrm < rmin) {
  937. scale = rmin / tnrm;
  938. } else if (tnrm > rmax) {
  939. scale = rmax / tnrm;
  940. }
  941. if (scale != 1.) {
  942. dscal_(n, &scale, &d__[1], &c__1);
  943. i__1 = *n - 1;
  944. dscal_(&i__1, &scale, &e[1], &c__1);
  945. tnrm *= scale;
  946. if (valeig) {
  947. /* If eigenvalues in interval have to be found, */
  948. /* scale (WL, WU] accordingly */
  949. wl *= scale;
  950. wu *= scale;
  951. }
  952. }
  953. /* Compute the desired eigenvalues of the tridiagonal after splitting */
  954. /* into smaller subblocks if the corresponding off-diagonal elements */
  955. /* are small */
  956. /* THRESH is the splitting parameter for DLARRE */
  957. /* A negative THRESH forces the old splitting criterion based on the */
  958. /* size of the off-diagonal. A positive THRESH switches to splitting */
  959. /* which preserves relative accuracy. */
  960. if (*tryrac) {
  961. /* Test whether the matrix warrants the more expensive relative approach. */
  962. dlarrr_(n, &d__[1], &e[1], &iinfo);
  963. } else {
  964. /* The user does not care about relative accurately eigenvalues */
  965. iinfo = -1;
  966. }
  967. /* Set the splitting criterion */
  968. if (iinfo == 0) {
  969. thresh = eps;
  970. } else {
  971. thresh = -eps;
  972. /* relative accuracy is desired but T does not guarantee it */
  973. *tryrac = FALSE_;
  974. }
  975. if (*tryrac) {
  976. /* Copy original diagonal, needed to guarantee relative accuracy */
  977. dcopy_(n, &d__[1], &c__1, &work[indd], &c__1);
  978. }
  979. /* Store the squares of the offdiagonal values of T */
  980. i__1 = *n - 1;
  981. for (j = 1; j <= i__1; ++j) {
  982. /* Computing 2nd power */
  983. d__1 = e[j];
  984. work[inde2 + j - 1] = d__1 * d__1;
  985. /* L5: */
  986. }
  987. /* Set the tolerance parameters for bisection */
  988. if (! wantz) {
  989. /* DLARRE computes the eigenvalues to full precision. */
  990. rtol1 = eps * 4.;
  991. rtol2 = eps * 4.;
  992. } else {
  993. /* DLARRE computes the eigenvalues to less than full precision. */
  994. /* DLARRV will refine the eigenvalue approximations, and we can */
  995. /* need less accurate initial bisection in DLARRE. */
  996. /* Note: these settings do only affect the subset case and DLARRE */
  997. rtol1 = sqrt(eps);
  998. /* Computing MAX */
  999. d__1 = sqrt(eps) * .005, d__2 = eps * 4.;
  1000. rtol2 = f2cmax(d__1,d__2);
  1001. }
  1002. dlarre_(range, n, &wl, &wu, &iil, &iiu, &d__[1], &e[1], &work[inde2],
  1003. &rtol1, &rtol2, &thresh, &nsplit, &iwork[iinspl], m, &w[1], &
  1004. work[inderr], &work[indgp], &iwork[iindbl], &iwork[iindw], &
  1005. work[indgrs], &pivmin, &work[indwrk], &iwork[iindwk], &iinfo);
  1006. if (iinfo != 0) {
  1007. *info = abs(iinfo) + 10;
  1008. return 0;
  1009. }
  1010. /* Note that if RANGE .NE. 'V', DLARRE computes bounds on the desired */
  1011. /* part of the spectrum. All desired eigenvalues are contained in */
  1012. /* (WL,WU] */
  1013. if (wantz) {
  1014. /* Compute the desired eigenvectors corresponding to the computed */
  1015. /* eigenvalues */
  1016. dlarrv_(n, &wl, &wu, &d__[1], &e[1], &pivmin, &iwork[iinspl], m, &
  1017. c__1, m, &c_b18, &rtol1, &rtol2, &w[1], &work[inderr], &
  1018. work[indgp], &iwork[iindbl], &iwork[iindw], &work[indgrs],
  1019. &z__[z_offset], ldz, &isuppz[1], &work[indwrk], &iwork[
  1020. iindwk], &iinfo);
  1021. if (iinfo != 0) {
  1022. *info = abs(iinfo) + 20;
  1023. return 0;
  1024. }
  1025. } else {
  1026. /* DLARRE computes eigenvalues of the (shifted) root representation */
  1027. /* DLARRV returns the eigenvalues of the unshifted matrix. */
  1028. /* However, if the eigenvectors are not desired by the user, we need */
  1029. /* to apply the corresponding shifts from DLARRE to obtain the */
  1030. /* eigenvalues of the original matrix. */
  1031. i__1 = *m;
  1032. for (j = 1; j <= i__1; ++j) {
  1033. itmp = iwork[iindbl + j - 1];
  1034. w[j] += e[iwork[iinspl + itmp - 1]];
  1035. /* L20: */
  1036. }
  1037. }
  1038. if (*tryrac) {
  1039. /* Refine computed eigenvalues so that they are relatively accurate */
  1040. /* with respect to the original matrix T. */
  1041. ibegin = 1;
  1042. wbegin = 1;
  1043. i__1 = iwork[iindbl + *m - 1];
  1044. for (jblk = 1; jblk <= i__1; ++jblk) {
  1045. iend = iwork[iinspl + jblk - 1];
  1046. in = iend - ibegin + 1;
  1047. wend = wbegin - 1;
  1048. /* check if any eigenvalues have to be refined in this block */
  1049. L36:
  1050. if (wend < *m) {
  1051. if (iwork[iindbl + wend] == jblk) {
  1052. ++wend;
  1053. goto L36;
  1054. }
  1055. }
  1056. if (wend < wbegin) {
  1057. ibegin = iend + 1;
  1058. goto L39;
  1059. }
  1060. offset = iwork[iindw + wbegin - 1] - 1;
  1061. ifirst = iwork[iindw + wbegin - 1];
  1062. ilast = iwork[iindw + wend - 1];
  1063. rtol2 = eps * 4.;
  1064. dlarrj_(&in, &work[indd + ibegin - 1], &work[inde2 + ibegin -
  1065. 1], &ifirst, &ilast, &rtol2, &offset, &w[wbegin], &
  1066. work[inderr + wbegin - 1], &work[indwrk], &iwork[
  1067. iindwk], &pivmin, &tnrm, &iinfo);
  1068. ibegin = iend + 1;
  1069. wbegin = wend + 1;
  1070. L39:
  1071. ;
  1072. }
  1073. }
  1074. /* If matrix was scaled, then rescale eigenvalues appropriately. */
  1075. if (scale != 1.) {
  1076. d__1 = 1. / scale;
  1077. dscal_(m, &d__1, &w[1], &c__1);
  1078. }
  1079. }
  1080. /* If eigenvalues are not in increasing order, then sort them, */
  1081. /* possibly along with eigenvectors. */
  1082. if (nsplit > 1 || *n == 2) {
  1083. if (! wantz) {
  1084. dlasrt_("I", m, &w[1], &iinfo);
  1085. if (iinfo != 0) {
  1086. *info = 3;
  1087. return 0;
  1088. }
  1089. } else {
  1090. i__1 = *m - 1;
  1091. for (j = 1; j <= i__1; ++j) {
  1092. i__ = 0;
  1093. tmp = w[j];
  1094. i__2 = *m;
  1095. for (jj = j + 1; jj <= i__2; ++jj) {
  1096. if (w[jj] < tmp) {
  1097. i__ = jj;
  1098. tmp = w[jj];
  1099. }
  1100. /* L50: */
  1101. }
  1102. if (i__ != 0) {
  1103. w[i__] = w[j];
  1104. w[j] = tmp;
  1105. if (wantz) {
  1106. dswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j *
  1107. z_dim1 + 1], &c__1);
  1108. itmp = isuppz[(i__ << 1) - 1];
  1109. isuppz[(i__ << 1) - 1] = isuppz[(j << 1) - 1];
  1110. isuppz[(j << 1) - 1] = itmp;
  1111. itmp = isuppz[i__ * 2];
  1112. isuppz[i__ * 2] = isuppz[j * 2];
  1113. isuppz[j * 2] = itmp;
  1114. }
  1115. }
  1116. /* L60: */
  1117. }
  1118. }
  1119. }
  1120. work[1] = (doublereal) lwmin;
  1121. iwork[1] = liwmin;
  1122. return 0;
  1123. /* End of DSTEMR */
  1124. } /* dstemr_ */