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.

cstemr.c 39 kB

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