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 40 kB

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