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.

sstemr.c 38 kB

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