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.

cheevr.c 39 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205
  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__10 = 10;
  381. static integer c__1 = 1;
  382. static integer c__2 = 2;
  383. static integer c__3 = 3;
  384. static integer c__4 = 4;
  385. static integer c_n1 = -1;
  386. /* > \brief <b> CHEEVR computes the eigenvalues and, optionally, the left and/or right eigenvectors for HE mat
  387. rices</b> */
  388. /* =========== DOCUMENTATION =========== */
  389. /* Online html documentation available at */
  390. /* http://www.netlib.org/lapack/explore-html/ */
  391. /* > \htmlonly */
  392. /* > Download CHEEVR + dependencies */
  393. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cheevr.
  394. f"> */
  395. /* > [TGZ]</a> */
  396. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cheevr.
  397. f"> */
  398. /* > [ZIP]</a> */
  399. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cheevr.
  400. f"> */
  401. /* > [TXT]</a> */
  402. /* > \endhtmlonly */
  403. /* Definition: */
  404. /* =========== */
  405. /* SUBROUTINE CHEEVR( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU, */
  406. /* ABSTOL, M, W, Z, LDZ, ISUPPZ, WORK, LWORK, */
  407. /* RWORK, LRWORK, IWORK, LIWORK, INFO ) */
  408. /* CHARACTER JOBZ, RANGE, UPLO */
  409. /* INTEGER IL, INFO, IU, LDA, LDZ, LIWORK, LRWORK, LWORK, */
  410. /* $ M, N */
  411. /* REAL ABSTOL, VL, VU */
  412. /* INTEGER ISUPPZ( * ), IWORK( * ) */
  413. /* REAL RWORK( * ), W( * ) */
  414. /* COMPLEX A( LDA, * ), WORK( * ), Z( LDZ, * ) */
  415. /* > \par Purpose: */
  416. /* ============= */
  417. /* > */
  418. /* > \verbatim */
  419. /* > */
  420. /* > CHEEVR computes selected eigenvalues and, optionally, eigenvectors */
  421. /* > of a complex Hermitian matrix A. Eigenvalues and eigenvectors can */
  422. /* > be selected by specifying either a range of values or a range of */
  423. /* > indices for the desired eigenvalues. */
  424. /* > */
  425. /* > CHEEVR first reduces the matrix A to tridiagonal form T with a call */
  426. /* > to CHETRD. Then, whenever possible, CHEEVR calls CSTEMR to compute */
  427. /* > the eigenspectrum using Relatively Robust Representations. CSTEMR */
  428. /* > computes eigenvalues by the dqds algorithm, while orthogonal */
  429. /* > eigenvectors are computed from various "good" L D L^T representations */
  430. /* > (also known as Relatively Robust Representations). Gram-Schmidt */
  431. /* > orthogonalization is avoided as far as possible. More specifically, */
  432. /* > the various steps of the algorithm are as follows. */
  433. /* > */
  434. /* > For each unreduced block (submatrix) of T, */
  435. /* > (a) Compute T - sigma I = L D L^T, so that L and D */
  436. /* > define all the wanted eigenvalues to high relative accuracy. */
  437. /* > This means that small relative changes in the entries of D and L */
  438. /* > cause only small relative changes in the eigenvalues and */
  439. /* > eigenvectors. The standard (unfactored) representation of the */
  440. /* > tridiagonal matrix T does not have this property in general. */
  441. /* > (b) Compute the eigenvalues to suitable accuracy. */
  442. /* > If the eigenvectors are desired, the algorithm attains full */
  443. /* > accuracy of the computed eigenvalues only right before */
  444. /* > the corresponding vectors have to be computed, see steps c) and d). */
  445. /* > (c) For each cluster of close eigenvalues, select a new */
  446. /* > shift close to the cluster, find a new factorization, and refine */
  447. /* > the shifted eigenvalues to suitable accuracy. */
  448. /* > (d) For each eigenvalue with a large enough relative separation compute */
  449. /* > the corresponding eigenvector by forming a rank revealing twisted */
  450. /* > factorization. Go back to (c) for any clusters that remain. */
  451. /* > */
  452. /* > The desired accuracy of the output can be specified by the input */
  453. /* > parameter ABSTOL. */
  454. /* > */
  455. /* > For more details, see DSTEMR's documentation and: */
  456. /* > - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations */
  457. /* > to compute orthogonal eigenvectors of symmetric tridiagonal matrices," */
  458. /* > Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004. */
  459. /* > - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and */
  460. /* > Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25, */
  461. /* > 2004. Also LAPACK Working Note 154. */
  462. /* > - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric */
  463. /* > tridiagonal eigenvalue/eigenvector problem", */
  464. /* > Computer Science Division Technical Report No. UCB/CSD-97-971, */
  465. /* > UC Berkeley, May 1997. */
  466. /* > */
  467. /* > */
  468. /* > Note 1 : CHEEVR calls CSTEMR when the full spectrum is requested */
  469. /* > on machines which conform to the ieee-754 floating point standard. */
  470. /* > CHEEVR calls SSTEBZ and CSTEIN on non-ieee machines and */
  471. /* > when partial spectrum requests are made. */
  472. /* > */
  473. /* > Normal execution of CSTEMR may create NaNs and infinities and */
  474. /* > hence may abort due to a floating point exception in environments */
  475. /* > which do not handle NaNs and infinities in the ieee standard default */
  476. /* > manner. */
  477. /* > \endverbatim */
  478. /* Arguments: */
  479. /* ========== */
  480. /* > \param[in] JOBZ */
  481. /* > \verbatim */
  482. /* > JOBZ is CHARACTER*1 */
  483. /* > = 'N': Compute eigenvalues only; */
  484. /* > = 'V': Compute eigenvalues and eigenvectors. */
  485. /* > \endverbatim */
  486. /* > */
  487. /* > \param[in] RANGE */
  488. /* > \verbatim */
  489. /* > RANGE is CHARACTER*1 */
  490. /* > = 'A': all eigenvalues will be found. */
  491. /* > = 'V': all eigenvalues in the half-open interval (VL,VU] */
  492. /* > will be found. */
  493. /* > = 'I': the IL-th through IU-th eigenvalues will be found. */
  494. /* > For RANGE = 'V' or 'I' and IU - IL < N - 1, SSTEBZ and */
  495. /* > CSTEIN are called */
  496. /* > \endverbatim */
  497. /* > */
  498. /* > \param[in] UPLO */
  499. /* > \verbatim */
  500. /* > UPLO is CHARACTER*1 */
  501. /* > = 'U': Upper triangle of A is stored; */
  502. /* > = 'L': Lower triangle of A is stored. */
  503. /* > \endverbatim */
  504. /* > */
  505. /* > \param[in] N */
  506. /* > \verbatim */
  507. /* > N is INTEGER */
  508. /* > The order of the matrix A. N >= 0. */
  509. /* > \endverbatim */
  510. /* > */
  511. /* > \param[in,out] A */
  512. /* > \verbatim */
  513. /* > A is COMPLEX array, dimension (LDA, N) */
  514. /* > On entry, the Hermitian matrix A. If UPLO = 'U', the */
  515. /* > leading N-by-N upper triangular part of A contains the */
  516. /* > upper triangular part of the matrix A. If UPLO = 'L', */
  517. /* > the leading N-by-N lower triangular part of A contains */
  518. /* > the lower triangular part of the matrix A. */
  519. /* > On exit, the lower triangle (if UPLO='L') or the upper */
  520. /* > triangle (if UPLO='U') of A, including the diagonal, is */
  521. /* > destroyed. */
  522. /* > \endverbatim */
  523. /* > */
  524. /* > \param[in] LDA */
  525. /* > \verbatim */
  526. /* > LDA is INTEGER */
  527. /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
  528. /* > \endverbatim */
  529. /* > */
  530. /* > \param[in] VL */
  531. /* > \verbatim */
  532. /* > VL is REAL */
  533. /* > If RANGE='V', the lower bound of the interval to */
  534. /* > be searched for eigenvalues. VL < VU. */
  535. /* > Not referenced if RANGE = 'A' or 'I'. */
  536. /* > \endverbatim */
  537. /* > */
  538. /* > \param[in] VU */
  539. /* > \verbatim */
  540. /* > VU is REAL */
  541. /* > If RANGE='V', the upper bound of the interval to */
  542. /* > be searched for eigenvalues. VL < VU. */
  543. /* > Not referenced if RANGE = 'A' or 'I'. */
  544. /* > \endverbatim */
  545. /* > */
  546. /* > \param[in] IL */
  547. /* > \verbatim */
  548. /* > IL is INTEGER */
  549. /* > If RANGE='I', the index of the */
  550. /* > smallest eigenvalue to be returned. */
  551. /* > 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
  552. /* > Not referenced if RANGE = 'A' or 'V'. */
  553. /* > \endverbatim */
  554. /* > */
  555. /* > \param[in] IU */
  556. /* > \verbatim */
  557. /* > IU is INTEGER */
  558. /* > If RANGE='I', the index of the */
  559. /* > largest eigenvalue to be returned. */
  560. /* > 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
  561. /* > Not referenced if RANGE = 'A' or 'V'. */
  562. /* > \endverbatim */
  563. /* > */
  564. /* > \param[in] ABSTOL */
  565. /* > \verbatim */
  566. /* > ABSTOL is REAL */
  567. /* > The absolute error tolerance for the eigenvalues. */
  568. /* > An approximate eigenvalue is accepted as converged */
  569. /* > when it is determined to lie in an interval [a,b] */
  570. /* > of width less than or equal to */
  571. /* > */
  572. /* > ABSTOL + EPS * f2cmax( |a|,|b| ) , */
  573. /* > */
  574. /* > where EPS is the machine precision. If ABSTOL is less than */
  575. /* > or equal to zero, then EPS*|T| will be used in its place, */
  576. /* > where |T| is the 1-norm of the tridiagonal matrix obtained */
  577. /* > by reducing A to tridiagonal form. */
  578. /* > */
  579. /* > See "Computing Small Singular Values of Bidiagonal Matrices */
  580. /* > with Guaranteed High Relative Accuracy," by Demmel and */
  581. /* > Kahan, LAPACK Working Note #3. */
  582. /* > */
  583. /* > If high relative accuracy is important, set ABSTOL to */
  584. /* > SLAMCH( 'Safe minimum' ). Doing so will guarantee that */
  585. /* > eigenvalues are computed to high relative accuracy when */
  586. /* > possible in future releases. The current code does not */
  587. /* > make any guarantees about high relative accuracy, but */
  588. /* > future releases will. See J. Barlow and J. Demmel, */
  589. /* > "Computing Accurate Eigensystems of Scaled Diagonally */
  590. /* > Dominant Matrices", LAPACK Working Note #7, for a discussion */
  591. /* > of which matrices define their eigenvalues to high relative */
  592. /* > accuracy. */
  593. /* > \endverbatim */
  594. /* > */
  595. /* > \param[out] M */
  596. /* > \verbatim */
  597. /* > M is INTEGER */
  598. /* > The total number of eigenvalues found. 0 <= M <= N. */
  599. /* > If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
  600. /* > \endverbatim */
  601. /* > */
  602. /* > \param[out] W */
  603. /* > \verbatim */
  604. /* > W is REAL array, dimension (N) */
  605. /* > The first M elements contain the selected eigenvalues in */
  606. /* > ascending order. */
  607. /* > \endverbatim */
  608. /* > */
  609. /* > \param[out] Z */
  610. /* > \verbatim */
  611. /* > Z is COMPLEX array, dimension (LDZ, f2cmax(1,M)) */
  612. /* > If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
  613. /* > contain the orthonormal eigenvectors of the matrix A */
  614. /* > corresponding to the selected eigenvalues, with the i-th */
  615. /* > column of Z holding the eigenvector associated with W(i). */
  616. /* > If JOBZ = 'N', then Z is not referenced. */
  617. /* > Note: the user must ensure that at least f2cmax(1,M) columns are */
  618. /* > supplied in the array Z; if RANGE = 'V', the exact value of M */
  619. /* > is not known in advance and an upper bound must be used. */
  620. /* > \endverbatim */
  621. /* > */
  622. /* > \param[in] LDZ */
  623. /* > \verbatim */
  624. /* > LDZ is INTEGER */
  625. /* > The leading dimension of the array Z. LDZ >= 1, and if */
  626. /* > JOBZ = 'V', LDZ >= f2cmax(1,N). */
  627. /* > \endverbatim */
  628. /* > */
  629. /* > \param[out] ISUPPZ */
  630. /* > \verbatim */
  631. /* > ISUPPZ is INTEGER array, dimension ( 2*f2cmax(1,M) ) */
  632. /* > The support of the eigenvectors in Z, i.e., the indices */
  633. /* > indicating the nonzero elements in Z. The i-th eigenvector */
  634. /* > is nonzero only in elements ISUPPZ( 2*i-1 ) through */
  635. /* > ISUPPZ( 2*i ). This is an output of CSTEMR (tridiagonal */
  636. /* > matrix). The support of the eigenvectors of A is typically */
  637. /* > 1:N because of the unitary transformations applied by CUNMTR. */
  638. /* > Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1 */
  639. /* > \endverbatim */
  640. /* > */
  641. /* > \param[out] WORK */
  642. /* > \verbatim */
  643. /* > WORK is COMPLEX array, dimension (MAX(1,LWORK)) */
  644. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  645. /* > \endverbatim */
  646. /* > */
  647. /* > \param[in] LWORK */
  648. /* > \verbatim */
  649. /* > LWORK is INTEGER */
  650. /* > The length of the array WORK. LWORK >= f2cmax(1,2*N). */
  651. /* > For optimal efficiency, LWORK >= (NB+1)*N, */
  652. /* > where NB is the f2cmax of the blocksize for CHETRD and for */
  653. /* > CUNMTR as returned by ILAENV. */
  654. /* > */
  655. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  656. /* > only calculates the optimal sizes of the WORK, RWORK and */
  657. /* > IWORK arrays, returns these values as the first entries of */
  658. /* > the WORK, RWORK and IWORK arrays, and no error message */
  659. /* > related to LWORK or LRWORK or LIWORK is issued by XERBLA. */
  660. /* > \endverbatim */
  661. /* > */
  662. /* > \param[out] RWORK */
  663. /* > \verbatim */
  664. /* > RWORK is REAL array, dimension (MAX(1,LRWORK)) */
  665. /* > On exit, if INFO = 0, RWORK(1) returns the optimal */
  666. /* > (and minimal) LRWORK. */
  667. /* > \endverbatim */
  668. /* > */
  669. /* > \param[in] LRWORK */
  670. /* > \verbatim */
  671. /* > LRWORK is INTEGER */
  672. /* > The length of the array RWORK. LRWORK >= f2cmax(1,24*N). */
  673. /* > */
  674. /* > If LRWORK = -1, then a workspace query is assumed; the */
  675. /* > routine only calculates the optimal sizes of the WORK, RWORK */
  676. /* > and IWORK arrays, returns these values as the first entries */
  677. /* > of the WORK, RWORK and IWORK arrays, and no error message */
  678. /* > related to LWORK or LRWORK or LIWORK is issued by XERBLA. */
  679. /* > \endverbatim */
  680. /* > */
  681. /* > \param[out] IWORK */
  682. /* > \verbatim */
  683. /* > IWORK is INTEGER array, dimension (MAX(1,LIWORK)) */
  684. /* > On exit, if INFO = 0, IWORK(1) returns the optimal */
  685. /* > (and minimal) LIWORK. */
  686. /* > \endverbatim */
  687. /* > */
  688. /* > \param[in] LIWORK */
  689. /* > \verbatim */
  690. /* > LIWORK is INTEGER */
  691. /* > The dimension of the array IWORK. LIWORK >= f2cmax(1,10*N). */
  692. /* > */
  693. /* > If LIWORK = -1, then a workspace query is assumed; the */
  694. /* > routine only calculates the optimal sizes of the WORK, RWORK */
  695. /* > and IWORK arrays, returns these values as the first entries */
  696. /* > of the WORK, RWORK and IWORK arrays, and no error message */
  697. /* > related to LWORK or LRWORK or LIWORK is issued by XERBLA. */
  698. /* > \endverbatim */
  699. /* > */
  700. /* > \param[out] INFO */
  701. /* > \verbatim */
  702. /* > INFO is INTEGER */
  703. /* > = 0: successful exit */
  704. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  705. /* > > 0: Internal error */
  706. /* > \endverbatim */
  707. /* Authors: */
  708. /* ======== */
  709. /* > \author Univ. of Tennessee */
  710. /* > \author Univ. of California Berkeley */
  711. /* > \author Univ. of Colorado Denver */
  712. /* > \author NAG Ltd. */
  713. /* > \date June 2016 */
  714. /* > \ingroup complexHEeigen */
  715. /* > \par Contributors: */
  716. /* ================== */
  717. /* > */
  718. /* > Inderjit Dhillon, IBM Almaden, USA \n */
  719. /* > Osni Marques, LBNL/NERSC, USA \n */
  720. /* > Ken Stanley, Computer Science Division, University of */
  721. /* > California at Berkeley, USA \n */
  722. /* > Jason Riedy, Computer Science Division, University of */
  723. /* > California at Berkeley, USA \n */
  724. /* > */
  725. /* ===================================================================== */
  726. /* Subroutine */ int cheevr_(char *jobz, char *range, char *uplo, integer *n,
  727. complex *a, integer *lda, real *vl, real *vu, integer *il, integer *
  728. iu, real *abstol, integer *m, real *w, complex *z__, integer *ldz,
  729. integer *isuppz, complex *work, integer *lwork, real *rwork, integer *
  730. lrwork, integer *iwork, integer *liwork, integer *info)
  731. {
  732. /* System generated locals */
  733. integer a_dim1, a_offset, z_dim1, z_offset, i__1, i__2;
  734. real r__1, r__2;
  735. /* Local variables */
  736. real anrm;
  737. integer imax;
  738. real rmin, rmax;
  739. logical test;
  740. integer itmp1, i__, j, indrd, indre;
  741. real sigma;
  742. extern logical lsame_(char *, char *);
  743. integer iinfo;
  744. extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
  745. char order[1];
  746. integer indwk;
  747. extern /* Subroutine */ int cswap_(integer *, complex *, integer *,
  748. complex *, integer *);
  749. integer lwmin;
  750. logical lower;
  751. extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *,
  752. integer *);
  753. logical wantz;
  754. integer nb, jj;
  755. logical alleig, indeig;
  756. integer iscale, ieeeok, indibl, indrdd, indifl, indree;
  757. logical valeig;
  758. extern real slamch_(char *);
  759. extern /* Subroutine */ int chetrd_(char *, integer *, complex *, integer
  760. *, real *, real *, complex *, complex *, integer *, integer *), csscal_(integer *, real *, complex *, integer *);
  761. real safmin;
  762. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  763. integer *, integer *, ftnlen, ftnlen);
  764. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  765. real abstll, bignum;
  766. integer indtau, indisp;
  767. extern /* Subroutine */ int cstein_(integer *, real *, real *, integer *,
  768. real *, integer *, integer *, complex *, integer *, real *,
  769. integer *, integer *, integer *);
  770. integer indiwo, indwkn;
  771. extern real clansy_(char *, char *, integer *, complex *, integer *, real
  772. *);
  773. extern /* Subroutine */ int cstemr_(char *, char *, integer *, real *,
  774. real *, real *, real *, integer *, integer *, integer *, real *,
  775. complex *, integer *, integer *, integer *, logical *, real *,
  776. integer *, integer *, integer *, integer *);
  777. integer indrwk, liwmin;
  778. logical tryrac;
  779. extern /* Subroutine */ int ssterf_(integer *, real *, real *, integer *);
  780. integer lrwmin, llwrkn, llwork, nsplit;
  781. real smlnum;
  782. extern /* Subroutine */ int cunmtr_(char *, char *, char *, integer *,
  783. integer *, complex *, integer *, complex *, complex *, integer *,
  784. complex *, integer *, integer *), sstebz_(
  785. char *, char *, integer *, real *, real *, integer *, integer *,
  786. real *, real *, real *, integer *, integer *, real *, integer *,
  787. integer *, real *, integer *, integer *);
  788. logical lquery;
  789. integer lwkopt;
  790. real eps, vll, vuu;
  791. integer llrwork;
  792. real tmp1;
  793. /* -- LAPACK driver routine (version 3.7.0) -- */
  794. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  795. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  796. /* June 2016 */
  797. /* ===================================================================== */
  798. /* Test the input parameters. */
  799. /* Parameter adjustments */
  800. a_dim1 = *lda;
  801. a_offset = 1 + a_dim1 * 1;
  802. a -= a_offset;
  803. --w;
  804. z_dim1 = *ldz;
  805. z_offset = 1 + z_dim1 * 1;
  806. z__ -= z_offset;
  807. --isuppz;
  808. --work;
  809. --rwork;
  810. --iwork;
  811. /* Function Body */
  812. ieeeok = ilaenv_(&c__10, "CHEEVR", "N", &c__1, &c__2, &c__3, &c__4, (
  813. ftnlen)6, (ftnlen)1);
  814. lower = lsame_(uplo, "L");
  815. wantz = lsame_(jobz, "V");
  816. alleig = lsame_(range, "A");
  817. valeig = lsame_(range, "V");
  818. indeig = lsame_(range, "I");
  819. lquery = *lwork == -1 || *lrwork == -1 || *liwork == -1;
  820. /* Computing MAX */
  821. i__1 = 1, i__2 = *n * 24;
  822. lrwmin = f2cmax(i__1,i__2);
  823. /* Computing MAX */
  824. i__1 = 1, i__2 = *n * 10;
  825. liwmin = f2cmax(i__1,i__2);
  826. /* Computing MAX */
  827. i__1 = 1, i__2 = *n << 1;
  828. lwmin = f2cmax(i__1,i__2);
  829. *info = 0;
  830. if (! (wantz || lsame_(jobz, "N"))) {
  831. *info = -1;
  832. } else if (! (alleig || valeig || indeig)) {
  833. *info = -2;
  834. } else if (! (lower || lsame_(uplo, "U"))) {
  835. *info = -3;
  836. } else if (*n < 0) {
  837. *info = -4;
  838. } else if (*lda < f2cmax(1,*n)) {
  839. *info = -6;
  840. } else {
  841. if (valeig) {
  842. if (*n > 0 && *vu <= *vl) {
  843. *info = -8;
  844. }
  845. } else if (indeig) {
  846. if (*il < 1 || *il > f2cmax(1,*n)) {
  847. *info = -9;
  848. } else if (*iu < f2cmin(*n,*il) || *iu > *n) {
  849. *info = -10;
  850. }
  851. }
  852. }
  853. if (*info == 0) {
  854. if (*ldz < 1 || wantz && *ldz < *n) {
  855. *info = -15;
  856. }
  857. }
  858. if (*info == 0) {
  859. nb = ilaenv_(&c__1, "CHETRD", uplo, n, &c_n1, &c_n1, &c_n1, (ftnlen)6,
  860. (ftnlen)1);
  861. /* Computing MAX */
  862. i__1 = nb, i__2 = ilaenv_(&c__1, "CUNMTR", uplo, n, &c_n1, &c_n1, &
  863. c_n1, (ftnlen)6, (ftnlen)1);
  864. nb = f2cmax(i__1,i__2);
  865. /* Computing MAX */
  866. i__1 = (nb + 1) * *n;
  867. lwkopt = f2cmax(i__1,lwmin);
  868. work[1].r = (real) lwkopt, work[1].i = 0.f;
  869. rwork[1] = (real) lrwmin;
  870. iwork[1] = liwmin;
  871. if (*lwork < lwmin && ! lquery) {
  872. *info = -18;
  873. } else if (*lrwork < lrwmin && ! lquery) {
  874. *info = -20;
  875. } else if (*liwork < liwmin && ! lquery) {
  876. *info = -22;
  877. }
  878. }
  879. if (*info != 0) {
  880. i__1 = -(*info);
  881. xerbla_("CHEEVR", &i__1, (ftnlen)6);
  882. return 0;
  883. } else if (lquery) {
  884. return 0;
  885. }
  886. /* Quick return if possible */
  887. *m = 0;
  888. if (*n == 0) {
  889. work[1].r = 1.f, work[1].i = 0.f;
  890. return 0;
  891. }
  892. if (*n == 1) {
  893. work[1].r = 2.f, work[1].i = 0.f;
  894. if (alleig || indeig) {
  895. *m = 1;
  896. i__1 = a_dim1 + 1;
  897. w[1] = a[i__1].r;
  898. } else {
  899. i__1 = a_dim1 + 1;
  900. i__2 = a_dim1 + 1;
  901. if (*vl < a[i__1].r && *vu >= a[i__2].r) {
  902. *m = 1;
  903. i__1 = a_dim1 + 1;
  904. w[1] = a[i__1].r;
  905. }
  906. }
  907. if (wantz) {
  908. i__1 = z_dim1 + 1;
  909. z__[i__1].r = 1.f, z__[i__1].i = 0.f;
  910. isuppz[1] = 1;
  911. isuppz[2] = 1;
  912. }
  913. return 0;
  914. }
  915. /* Get machine constants. */
  916. safmin = slamch_("Safe minimum");
  917. eps = slamch_("Precision");
  918. smlnum = safmin / eps;
  919. bignum = 1.f / smlnum;
  920. rmin = sqrt(smlnum);
  921. /* Computing MIN */
  922. r__1 = sqrt(bignum), r__2 = 1.f / sqrt(sqrt(safmin));
  923. rmax = f2cmin(r__1,r__2);
  924. /* Scale matrix to allowable range, if necessary. */
  925. iscale = 0;
  926. abstll = *abstol;
  927. if (valeig) {
  928. vll = *vl;
  929. vuu = *vu;
  930. }
  931. anrm = clansy_("M", uplo, n, &a[a_offset], lda, &rwork[1]);
  932. if (anrm > 0.f && anrm < rmin) {
  933. iscale = 1;
  934. sigma = rmin / anrm;
  935. } else if (anrm > rmax) {
  936. iscale = 1;
  937. sigma = rmax / anrm;
  938. }
  939. if (iscale == 1) {
  940. if (lower) {
  941. i__1 = *n;
  942. for (j = 1; j <= i__1; ++j) {
  943. i__2 = *n - j + 1;
  944. csscal_(&i__2, &sigma, &a[j + j * a_dim1], &c__1);
  945. /* L10: */
  946. }
  947. } else {
  948. i__1 = *n;
  949. for (j = 1; j <= i__1; ++j) {
  950. csscal_(&j, &sigma, &a[j * a_dim1 + 1], &c__1);
  951. /* L20: */
  952. }
  953. }
  954. if (*abstol > 0.f) {
  955. abstll = *abstol * sigma;
  956. }
  957. if (valeig) {
  958. vll = *vl * sigma;
  959. vuu = *vu * sigma;
  960. }
  961. }
  962. /* Initialize indices into workspaces. Note: The IWORK indices are */
  963. /* used only if SSTERF or CSTEMR fail. */
  964. /* WORK(INDTAU:INDTAU+N-1) stores the complex scalar factors of the */
  965. /* elementary reflectors used in CHETRD. */
  966. indtau = 1;
  967. /* INDWK is the starting offset of the remaining complex workspace, */
  968. /* and LLWORK is the remaining complex workspace size. */
  969. indwk = indtau + *n;
  970. llwork = *lwork - indwk + 1;
  971. /* RWORK(INDRD:INDRD+N-1) stores the real tridiagonal's diagonal */
  972. /* entries. */
  973. indrd = 1;
  974. /* RWORK(INDRE:INDRE+N-1) stores the off-diagonal entries of the */
  975. /* tridiagonal matrix from CHETRD. */
  976. indre = indrd + *n;
  977. /* RWORK(INDRDD:INDRDD+N-1) is a copy of the diagonal entries over */
  978. /* -written by CSTEMR (the SSTERF path copies the diagonal to W). */
  979. indrdd = indre + *n;
  980. /* RWORK(INDREE:INDREE+N-1) is a copy of the off-diagonal entries over */
  981. /* -written while computing the eigenvalues in SSTERF and CSTEMR. */
  982. indree = indrdd + *n;
  983. /* INDRWK is the starting offset of the left-over real workspace, and */
  984. /* LLRWORK is the remaining workspace size. */
  985. indrwk = indree + *n;
  986. llrwork = *lrwork - indrwk + 1;
  987. /* IWORK(INDIBL:INDIBL+M-1) corresponds to IBLOCK in SSTEBZ and */
  988. /* stores the block indices of each of the M<=N eigenvalues. */
  989. indibl = 1;
  990. /* IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in SSTEBZ and */
  991. /* stores the starting and finishing indices of each block. */
  992. indisp = indibl + *n;
  993. /* IWORK(INDIFL:INDIFL+N-1) stores the indices of eigenvectors */
  994. /* that corresponding to eigenvectors that fail to converge in */
  995. /* SSTEIN. This information is discarded; if any fail, the driver */
  996. /* returns INFO > 0. */
  997. indifl = indisp + *n;
  998. /* INDIWO is the offset of the remaining integer workspace. */
  999. indiwo = indifl + *n;
  1000. /* Call CHETRD to reduce Hermitian matrix to tridiagonal form. */
  1001. chetrd_(uplo, n, &a[a_offset], lda, &rwork[indrd], &rwork[indre], &work[
  1002. indtau], &work[indwk], &llwork, &iinfo);
  1003. /* If all eigenvalues are desired */
  1004. /* then call SSTERF or CSTEMR and CUNMTR. */
  1005. test = FALSE_;
  1006. if (indeig) {
  1007. if (*il == 1 && *iu == *n) {
  1008. test = TRUE_;
  1009. }
  1010. }
  1011. if ((alleig || test) && ieeeok == 1) {
  1012. if (! wantz) {
  1013. scopy_(n, &rwork[indrd], &c__1, &w[1], &c__1);
  1014. i__1 = *n - 1;
  1015. scopy_(&i__1, &rwork[indre], &c__1, &rwork[indree], &c__1);
  1016. ssterf_(n, &w[1], &rwork[indree], info);
  1017. } else {
  1018. i__1 = *n - 1;
  1019. scopy_(&i__1, &rwork[indre], &c__1, &rwork[indree], &c__1);
  1020. scopy_(n, &rwork[indrd], &c__1, &rwork[indrdd], &c__1);
  1021. if (*abstol <= *n * 2.f * eps) {
  1022. tryrac = TRUE_;
  1023. } else {
  1024. tryrac = FALSE_;
  1025. }
  1026. cstemr_(jobz, "A", n, &rwork[indrdd], &rwork[indree], vl, vu, il,
  1027. iu, m, &w[1], &z__[z_offset], ldz, n, &isuppz[1], &tryrac,
  1028. &rwork[indrwk], &llrwork, &iwork[1], liwork, info);
  1029. /* Apply unitary matrix used in reduction to tridiagonal */
  1030. /* form to eigenvectors returned by CSTEMR. */
  1031. if (wantz && *info == 0) {
  1032. indwkn = indwk;
  1033. llwrkn = *lwork - indwkn + 1;
  1034. cunmtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau]
  1035. , &z__[z_offset], ldz, &work[indwkn], &llwrkn, &iinfo);
  1036. }
  1037. }
  1038. if (*info == 0) {
  1039. *m = *n;
  1040. goto L30;
  1041. }
  1042. *info = 0;
  1043. }
  1044. /* Otherwise, call SSTEBZ and, if eigenvectors are desired, CSTEIN. */
  1045. /* Also call SSTEBZ and CSTEIN if CSTEMR fails. */
  1046. if (wantz) {
  1047. *(unsigned char *)order = 'B';
  1048. } else {
  1049. *(unsigned char *)order = 'E';
  1050. }
  1051. sstebz_(range, order, n, &vll, &vuu, il, iu, &abstll, &rwork[indrd], &
  1052. rwork[indre], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &
  1053. rwork[indrwk], &iwork[indiwo], info);
  1054. if (wantz) {
  1055. cstein_(n, &rwork[indrd], &rwork[indre], m, &w[1], &iwork[indibl], &
  1056. iwork[indisp], &z__[z_offset], ldz, &rwork[indrwk], &iwork[
  1057. indiwo], &iwork[indifl], info);
  1058. /* Apply unitary matrix used in reduction to tridiagonal */
  1059. /* form to eigenvectors returned by CSTEIN. */
  1060. indwkn = indwk;
  1061. llwrkn = *lwork - indwkn + 1;
  1062. cunmtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau], &z__[
  1063. z_offset], ldz, &work[indwkn], &llwrkn, &iinfo);
  1064. }
  1065. /* If matrix was scaled, then rescale eigenvalues appropriately. */
  1066. L30:
  1067. if (iscale == 1) {
  1068. if (*info == 0) {
  1069. imax = *m;
  1070. } else {
  1071. imax = *info - 1;
  1072. }
  1073. r__1 = 1.f / sigma;
  1074. sscal_(&imax, &r__1, &w[1], &c__1);
  1075. }
  1076. /* If eigenvalues are not in order, then sort them, along with */
  1077. /* eigenvectors. */
  1078. if (wantz) {
  1079. i__1 = *m - 1;
  1080. for (j = 1; j <= i__1; ++j) {
  1081. i__ = 0;
  1082. tmp1 = w[j];
  1083. i__2 = *m;
  1084. for (jj = j + 1; jj <= i__2; ++jj) {
  1085. if (w[jj] < tmp1) {
  1086. i__ = jj;
  1087. tmp1 = w[jj];
  1088. }
  1089. /* L40: */
  1090. }
  1091. if (i__ != 0) {
  1092. itmp1 = iwork[indibl + i__ - 1];
  1093. w[i__] = w[j];
  1094. iwork[indibl + i__ - 1] = iwork[indibl + j - 1];
  1095. w[j] = tmp1;
  1096. iwork[indibl + j - 1] = itmp1;
  1097. cswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1],
  1098. &c__1);
  1099. }
  1100. /* L50: */
  1101. }
  1102. }
  1103. /* Set WORK(1) to optimal workspace size. */
  1104. work[1].r = (real) lwkopt, work[1].i = 0.f;
  1105. rwork[1] = (real) lrwmin;
  1106. iwork[1] = liwmin;
  1107. return 0;
  1108. /* End of CHEEVR */
  1109. } /* cheevr_ */