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.

slarrv.c 51 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486
  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 real c_b5 = 0.f;
  363. static integer c__1 = 1;
  364. static integer c__2 = 2;
  365. /* > \brief \b SLARRV computes the eigenvectors of the tridiagonal matrix T = L D LT given L, D and the eigenv
  366. alues of L D LT. */
  367. /* =========== DOCUMENTATION =========== */
  368. /* Online html documentation available at */
  369. /* http://www.netlib.org/lapack/explore-html/ */
  370. /* > \htmlonly */
  371. /* > Download SLARRV + dependencies */
  372. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slarrv.
  373. f"> */
  374. /* > [TGZ]</a> */
  375. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slarrv.
  376. f"> */
  377. /* > [ZIP]</a> */
  378. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slarrv.
  379. f"> */
  380. /* > [TXT]</a> */
  381. /* > \endhtmlonly */
  382. /* Definition: */
  383. /* =========== */
  384. /* SUBROUTINE SLARRV( N, VL, VU, D, L, PIVMIN, */
  385. /* ISPLIT, M, DOL, DOU, MINRGP, */
  386. /* RTOL1, RTOL2, W, WERR, WGAP, */
  387. /* IBLOCK, INDEXW, GERS, Z, LDZ, ISUPPZ, */
  388. /* WORK, IWORK, INFO ) */
  389. /* INTEGER DOL, DOU, INFO, LDZ, M, N */
  390. /* REAL MINRGP, PIVMIN, RTOL1, RTOL2, VL, VU */
  391. /* INTEGER IBLOCK( * ), INDEXW( * ), ISPLIT( * ), */
  392. /* $ ISUPPZ( * ), IWORK( * ) */
  393. /* REAL D( * ), GERS( * ), L( * ), W( * ), WERR( * ), */
  394. /* $ WGAP( * ), WORK( * ) */
  395. /* REAL Z( LDZ, * ) */
  396. /* > \par Purpose: */
  397. /* ============= */
  398. /* > */
  399. /* > \verbatim */
  400. /* > */
  401. /* > SLARRV computes the eigenvectors of the tridiagonal matrix */
  402. /* > T = L D L**T given L, D and APPROXIMATIONS to the eigenvalues of L D L**T. */
  403. /* > The input eigenvalues should have been computed by SLARRE. */
  404. /* > \endverbatim */
  405. /* Arguments: */
  406. /* ========== */
  407. /* > \param[in] N */
  408. /* > \verbatim */
  409. /* > N is INTEGER */
  410. /* > The order of the matrix. N >= 0. */
  411. /* > \endverbatim */
  412. /* > */
  413. /* > \param[in] VL */
  414. /* > \verbatim */
  415. /* > VL is REAL */
  416. /* > Lower bound of the interval that contains the desired */
  417. /* > eigenvalues. VL < VU. Needed to compute gaps on the left or right */
  418. /* > end of the extremal eigenvalues in the desired RANGE. */
  419. /* > \endverbatim */
  420. /* > */
  421. /* > \param[in] VU */
  422. /* > \verbatim */
  423. /* > VU is REAL */
  424. /* > Upper bound of the interval that contains the desired */
  425. /* > eigenvalues. VL < VU. */
  426. /* > Note: VU is currently not used by this implementation of SLARRV, VU is */
  427. /* > passed to SLARRV because it could be used compute gaps on the right end */
  428. /* > of the extremal eigenvalues. However, with not much initial accuracy in */
  429. /* > LAMBDA and VU, the formula can lead to an overestimation of the right gap */
  430. /* > and thus to inadequately early RQI 'convergence'. This is currently */
  431. /* > prevented this by forcing a small right gap. And so it turns out that VU */
  432. /* > is currently not used by this implementation of SLARRV. */
  433. /* > \endverbatim */
  434. /* > */
  435. /* > \param[in,out] D */
  436. /* > \verbatim */
  437. /* > D is REAL array, dimension (N) */
  438. /* > On entry, the N diagonal elements of the diagonal matrix D. */
  439. /* > On exit, D may be overwritten. */
  440. /* > \endverbatim */
  441. /* > */
  442. /* > \param[in,out] L */
  443. /* > \verbatim */
  444. /* > L is REAL array, dimension (N) */
  445. /* > On entry, the (N-1) subdiagonal elements of the unit */
  446. /* > bidiagonal matrix L are in elements 1 to N-1 of L */
  447. /* > (if the matrix is not split.) At the end of each block */
  448. /* > is stored the corresponding shift as given by SLARRE. */
  449. /* > On exit, L is overwritten. */
  450. /* > \endverbatim */
  451. /* > */
  452. /* > \param[in] PIVMIN */
  453. /* > \verbatim */
  454. /* > PIVMIN is REAL */
  455. /* > The minimum pivot allowed in the Sturm sequence. */
  456. /* > \endverbatim */
  457. /* > */
  458. /* > \param[in] ISPLIT */
  459. /* > \verbatim */
  460. /* > ISPLIT is INTEGER array, dimension (N) */
  461. /* > The splitting points, at which T breaks up into blocks. */
  462. /* > The first block consists of rows/columns 1 to */
  463. /* > ISPLIT( 1 ), the second of rows/columns ISPLIT( 1 )+1 */
  464. /* > through ISPLIT( 2 ), etc. */
  465. /* > \endverbatim */
  466. /* > */
  467. /* > \param[in] M */
  468. /* > \verbatim */
  469. /* > M is INTEGER */
  470. /* > The total number of input eigenvalues. 0 <= M <= N. */
  471. /* > \endverbatim */
  472. /* > */
  473. /* > \param[in] DOL */
  474. /* > \verbatim */
  475. /* > DOL is INTEGER */
  476. /* > \endverbatim */
  477. /* > */
  478. /* > \param[in] DOU */
  479. /* > \verbatim */
  480. /* > DOU is INTEGER */
  481. /* > If the user wants to compute only selected eigenvectors from all */
  482. /* > the eigenvalues supplied, he can specify an index range DOL:DOU. */
  483. /* > Or else the setting DOL=1, DOU=M should be applied. */
  484. /* > Note that DOL and DOU refer to the order in which the eigenvalues */
  485. /* > are stored in W. */
  486. /* > If the user wants to compute only selected eigenpairs, then */
  487. /* > the columns DOL-1 to DOU+1 of the eigenvector space Z contain the */
  488. /* > computed eigenvectors. All other columns of Z are set to zero. */
  489. /* > \endverbatim */
  490. /* > */
  491. /* > \param[in] MINRGP */
  492. /* > \verbatim */
  493. /* > MINRGP is REAL */
  494. /* > \endverbatim */
  495. /* > */
  496. /* > \param[in] RTOL1 */
  497. /* > \verbatim */
  498. /* > RTOL1 is REAL */
  499. /* > \endverbatim */
  500. /* > */
  501. /* > \param[in] RTOL2 */
  502. /* > \verbatim */
  503. /* > RTOL2 is REAL */
  504. /* > Parameters for bisection. */
  505. /* > An interval [LEFT,RIGHT] has converged if */
  506. /* > RIGHT-LEFT < MAX( RTOL1*GAP, RTOL2*MAX(|LEFT|,|RIGHT|) ) */
  507. /* > \endverbatim */
  508. /* > */
  509. /* > \param[in,out] W */
  510. /* > \verbatim */
  511. /* > W is REAL array, dimension (N) */
  512. /* > The first M elements of W contain the APPROXIMATE eigenvalues for */
  513. /* > which eigenvectors are to be computed. The eigenvalues */
  514. /* > should be grouped by split-off block and ordered from */
  515. /* > smallest to largest within the block ( The output array */
  516. /* > W from SLARRE is expected here ). Furthermore, they are with */
  517. /* > respect to the shift of the corresponding root representation */
  518. /* > for their block. On exit, W holds the eigenvalues of the */
  519. /* > UNshifted matrix. */
  520. /* > \endverbatim */
  521. /* > */
  522. /* > \param[in,out] WERR */
  523. /* > \verbatim */
  524. /* > WERR is REAL array, dimension (N) */
  525. /* > The first M elements contain the semiwidth of the uncertainty */
  526. /* > interval of the corresponding eigenvalue in W */
  527. /* > \endverbatim */
  528. /* > */
  529. /* > \param[in,out] WGAP */
  530. /* > \verbatim */
  531. /* > WGAP is REAL array, dimension (N) */
  532. /* > The separation from the right neighbor eigenvalue in W. */
  533. /* > \endverbatim */
  534. /* > */
  535. /* > \param[in] IBLOCK */
  536. /* > \verbatim */
  537. /* > IBLOCK is INTEGER array, dimension (N) */
  538. /* > The indices of the blocks (submatrices) associated with the */
  539. /* > corresponding eigenvalues in W; IBLOCK(i)=1 if eigenvalue */
  540. /* > W(i) belongs to the first block from the top, =2 if W(i) */
  541. /* > belongs to the second block, etc. */
  542. /* > \endverbatim */
  543. /* > */
  544. /* > \param[in] INDEXW */
  545. /* > \verbatim */
  546. /* > INDEXW is INTEGER array, dimension (N) */
  547. /* > The indices of the eigenvalues within each block (submatrix); */
  548. /* > for example, INDEXW(i)= 10 and IBLOCK(i)=2 imply that the */
  549. /* > i-th eigenvalue W(i) is the 10-th eigenvalue in the second block. */
  550. /* > \endverbatim */
  551. /* > */
  552. /* > \param[in] GERS */
  553. /* > \verbatim */
  554. /* > GERS is REAL array, dimension (2*N) */
  555. /* > The N Gerschgorin intervals (the i-th Gerschgorin interval */
  556. /* > is (GERS(2*i-1), GERS(2*i)). The Gerschgorin intervals should */
  557. /* > be computed from the original UNshifted matrix. */
  558. /* > \endverbatim */
  559. /* > */
  560. /* > \param[out] Z */
  561. /* > \verbatim */
  562. /* > Z is REAL array, dimension (LDZ, f2cmax(1,M) ) */
  563. /* > If INFO = 0, the first M columns of Z contain the */
  564. /* > orthonormal eigenvectors of the matrix T */
  565. /* > corresponding to the input eigenvalues, with the i-th */
  566. /* > column of Z holding the eigenvector associated with W(i). */
  567. /* > Note: the user must ensure that at least f2cmax(1,M) columns are */
  568. /* > supplied in the array Z. */
  569. /* > \endverbatim */
  570. /* > */
  571. /* > \param[in] LDZ */
  572. /* > \verbatim */
  573. /* > LDZ is INTEGER */
  574. /* > The leading dimension of the array Z. LDZ >= 1, and if */
  575. /* > JOBZ = 'V', LDZ >= f2cmax(1,N). */
  576. /* > \endverbatim */
  577. /* > */
  578. /* > \param[out] ISUPPZ */
  579. /* > \verbatim */
  580. /* > ISUPPZ is INTEGER array, dimension ( 2*f2cmax(1,M) ) */
  581. /* > The support of the eigenvectors in Z, i.e., the indices */
  582. /* > indicating the nonzero elements in Z. The I-th eigenvector */
  583. /* > is nonzero only in elements ISUPPZ( 2*I-1 ) through */
  584. /* > ISUPPZ( 2*I ). */
  585. /* > \endverbatim */
  586. /* > */
  587. /* > \param[out] WORK */
  588. /* > \verbatim */
  589. /* > WORK is REAL array, dimension (12*N) */
  590. /* > \endverbatim */
  591. /* > */
  592. /* > \param[out] IWORK */
  593. /* > \verbatim */
  594. /* > IWORK is INTEGER array, dimension (7*N) */
  595. /* > \endverbatim */
  596. /* > */
  597. /* > \param[out] INFO */
  598. /* > \verbatim */
  599. /* > INFO is INTEGER */
  600. /* > = 0: successful exit */
  601. /* > */
  602. /* > > 0: A problem occurred in SLARRV. */
  603. /* > < 0: One of the called subroutines signaled an internal problem. */
  604. /* > Needs inspection of the corresponding parameter IINFO */
  605. /* > for further information. */
  606. /* > */
  607. /* > =-1: Problem in SLARRB when refining a child's eigenvalues. */
  608. /* > =-2: Problem in SLARRF when computing the RRR of a child. */
  609. /* > When a child is inside a tight cluster, it can be difficult */
  610. /* > to find an RRR. A partial remedy from the user's point of */
  611. /* > view is to make the parameter MINRGP smaller and recompile. */
  612. /* > However, as the orthogonality of the computed vectors is */
  613. /* > proportional to 1/MINRGP, the user should be aware that */
  614. /* > he might be trading in precision when he decreases MINRGP. */
  615. /* > =-3: Problem in SLARRB when refining a single eigenvalue */
  616. /* > after the Rayleigh correction was rejected. */
  617. /* > = 5: The Rayleigh Quotient Iteration failed to converge to */
  618. /* > full accuracy in MAXITR steps. */
  619. /* > \endverbatim */
  620. /* Authors: */
  621. /* ======== */
  622. /* > \author Univ. of Tennessee */
  623. /* > \author Univ. of California Berkeley */
  624. /* > \author Univ. of Colorado Denver */
  625. /* > \author NAG Ltd. */
  626. /* > \date June 2016 */
  627. /* > \ingroup realOTHERauxiliary */
  628. /* > \par Contributors: */
  629. /* ================== */
  630. /* > */
  631. /* > Beresford Parlett, University of California, Berkeley, USA \n */
  632. /* > Jim Demmel, University of California, Berkeley, USA \n */
  633. /* > Inderjit Dhillon, University of Texas, Austin, USA \n */
  634. /* > Osni Marques, LBNL/NERSC, USA \n */
  635. /* > Christof Voemel, University of California, Berkeley, USA */
  636. /* ===================================================================== */
  637. /* Subroutine */ int slarrv_(integer *n, real *vl, real *vu, real *d__, real *
  638. l, real *pivmin, integer *isplit, integer *m, integer *dol, integer *
  639. dou, real *minrgp, real *rtol1, real *rtol2, real *w, real *werr,
  640. real *wgap, integer *iblock, integer *indexw, real *gers, real *z__,
  641. integer *ldz, integer *isuppz, real *work, integer *iwork, integer *
  642. info)
  643. {
  644. /* System generated locals */
  645. integer z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
  646. real r__1, r__2;
  647. logical L__1;
  648. /* Local variables */
  649. integer iend, jblk;
  650. real lgap;
  651. integer done;
  652. real rgap, left;
  653. integer wend, iter;
  654. real bstw;
  655. integer minwsize, itmp1, i__, j, k, p, q, indld;
  656. real fudge;
  657. integer idone;
  658. real sigma;
  659. integer iinfo, iindr;
  660. real resid;
  661. extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
  662. logical eskip;
  663. real right;
  664. integer nclus, zfrom;
  665. extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *,
  666. integer *);
  667. real rqtol;
  668. integer iindc1, iindc2, miniwsize;
  669. extern /* Subroutine */ int slar1v_(integer *, integer *, integer *, real
  670. *, real *, real *, real *, real *, real *, real *, real *,
  671. logical *, integer *, real *, real *, integer *, integer *, real *
  672. , real *, real *, real *);
  673. logical stp2ii;
  674. real lambda;
  675. integer ii;
  676. real gl;
  677. integer im, in;
  678. real gu;
  679. integer ibegin, indeig;
  680. logical needbs;
  681. integer indlld;
  682. real sgndef, mingma;
  683. extern real slamch_(char *);
  684. integer oldien, oldncl, wbegin, negcnt;
  685. real spdiam;
  686. integer oldcls;
  687. real savgap;
  688. integer ndepth;
  689. real ssigma;
  690. logical usedbs;
  691. integer iindwk, offset;
  692. real gaptol;
  693. extern /* Subroutine */ int slarrb_(integer *, real *, real *, integer *,
  694. integer *, real *, real *, integer *, real *, real *, real *,
  695. real *, integer *, real *, real *, integer *, integer *), slarrf_(
  696. integer *, real *, real *, real *, integer *, integer *, real *,
  697. real *, real *, real *, real *, real *, real *, real *, real *,
  698. real *, real *, integer *);
  699. integer newcls, oldfst, indwrk, windex, oldlst;
  700. logical usedrq;
  701. integer newfst, newftt, parity, windmn, isupmn, newlst, windpl, zusedl,
  702. newsiz, zusedu, zusedw;
  703. real bstres, nrminv;
  704. logical tryrqc;
  705. integer isupmx;
  706. real rqcorr;
  707. extern /* Subroutine */ int slaset_(char *, integer *, integer *, real *,
  708. real *, real *, integer *);
  709. real gap, eps, tau, tol, tmp;
  710. integer zto;
  711. real ztz;
  712. /* -- LAPACK auxiliary routine (version 3.8.0) -- */
  713. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  714. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  715. /* June 2016 */
  716. /* ===================================================================== */
  717. /* Parameter adjustments */
  718. --d__;
  719. --l;
  720. --isplit;
  721. --w;
  722. --werr;
  723. --wgap;
  724. --iblock;
  725. --indexw;
  726. --gers;
  727. z_dim1 = *ldz;
  728. z_offset = 1 + z_dim1 * 1;
  729. z__ -= z_offset;
  730. --isuppz;
  731. --work;
  732. --iwork;
  733. /* Function Body */
  734. *info = 0;
  735. /* Quick return if possible */
  736. if (*n <= 0 || *m <= 0) {
  737. return 0;
  738. }
  739. /* The first N entries of WORK are reserved for the eigenvalues */
  740. indld = *n + 1;
  741. indlld = (*n << 1) + 1;
  742. indwrk = *n * 3 + 1;
  743. minwsize = *n * 12;
  744. i__1 = minwsize;
  745. for (i__ = 1; i__ <= i__1; ++i__) {
  746. work[i__] = 0.f;
  747. /* L5: */
  748. }
  749. /* IWORK(IINDR+1:IINDR+N) hold the twist indices R for the */
  750. /* factorization used to compute the FP vector */
  751. iindr = 0;
  752. /* IWORK(IINDC1+1:IINC2+N) are used to store the clusters of the current */
  753. /* layer and the one above. */
  754. iindc1 = *n;
  755. iindc2 = *n << 1;
  756. iindwk = *n * 3 + 1;
  757. miniwsize = *n * 7;
  758. i__1 = miniwsize;
  759. for (i__ = 1; i__ <= i__1; ++i__) {
  760. iwork[i__] = 0;
  761. /* L10: */
  762. }
  763. zusedl = 1;
  764. if (*dol > 1) {
  765. /* Set lower bound for use of Z */
  766. zusedl = *dol - 1;
  767. }
  768. zusedu = *m;
  769. if (*dou < *m) {
  770. /* Set lower bound for use of Z */
  771. zusedu = *dou + 1;
  772. }
  773. /* The width of the part of Z that is used */
  774. zusedw = zusedu - zusedl + 1;
  775. slaset_("Full", n, &zusedw, &c_b5, &c_b5, &z__[zusedl * z_dim1 + 1], ldz);
  776. eps = slamch_("Precision");
  777. rqtol = eps * 2.f;
  778. /* Set expert flags for standard code. */
  779. tryrqc = TRUE_;
  780. if (*dol == 1 && *dou == *m) {
  781. } else {
  782. /* Only selected eigenpairs are computed. Since the other evalues */
  783. /* are not refined by RQ iteration, bisection has to compute to full */
  784. /* accuracy. */
  785. *rtol1 = eps * 4.f;
  786. *rtol2 = eps * 4.f;
  787. }
  788. /* The entries WBEGIN:WEND in W, WERR, WGAP correspond to the */
  789. /* desired eigenvalues. The support of the nonzero eigenvector */
  790. /* entries is contained in the interval IBEGIN:IEND. */
  791. /* Remark that if k eigenpairs are desired, then the eigenvectors */
  792. /* are stored in k contiguous columns of Z. */
  793. /* DONE is the number of eigenvectors already computed */
  794. done = 0;
  795. ibegin = 1;
  796. wbegin = 1;
  797. i__1 = iblock[*m];
  798. for (jblk = 1; jblk <= i__1; ++jblk) {
  799. iend = isplit[jblk];
  800. sigma = l[iend];
  801. /* Find the eigenvectors of the submatrix indexed IBEGIN */
  802. /* through IEND. */
  803. wend = wbegin - 1;
  804. L15:
  805. if (wend < *m) {
  806. if (iblock[wend + 1] == jblk) {
  807. ++wend;
  808. goto L15;
  809. }
  810. }
  811. if (wend < wbegin) {
  812. ibegin = iend + 1;
  813. goto L170;
  814. } else if (wend < *dol || wbegin > *dou) {
  815. ibegin = iend + 1;
  816. wbegin = wend + 1;
  817. goto L170;
  818. }
  819. /* Find local spectral diameter of the block */
  820. gl = gers[(ibegin << 1) - 1];
  821. gu = gers[ibegin * 2];
  822. i__2 = iend;
  823. for (i__ = ibegin + 1; i__ <= i__2; ++i__) {
  824. /* Computing MIN */
  825. r__1 = gers[(i__ << 1) - 1];
  826. gl = f2cmin(r__1,gl);
  827. /* Computing MAX */
  828. r__1 = gers[i__ * 2];
  829. gu = f2cmax(r__1,gu);
  830. /* L20: */
  831. }
  832. spdiam = gu - gl;
  833. /* OLDIEN is the last index of the previous block */
  834. oldien = ibegin - 1;
  835. /* Calculate the size of the current block */
  836. in = iend - ibegin + 1;
  837. /* The number of eigenvalues in the current block */
  838. im = wend - wbegin + 1;
  839. /* This is for a 1x1 block */
  840. if (ibegin == iend) {
  841. ++done;
  842. z__[ibegin + wbegin * z_dim1] = 1.f;
  843. isuppz[(wbegin << 1) - 1] = ibegin;
  844. isuppz[wbegin * 2] = ibegin;
  845. w[wbegin] += sigma;
  846. work[wbegin] = w[wbegin];
  847. ibegin = iend + 1;
  848. ++wbegin;
  849. goto L170;
  850. }
  851. /* The desired (shifted) eigenvalues are stored in W(WBEGIN:WEND) */
  852. /* Note that these can be approximations, in this case, the corresp. */
  853. /* entries of WERR give the size of the uncertainty interval. */
  854. /* The eigenvalue approximations will be refined when necessary as */
  855. /* high relative accuracy is required for the computation of the */
  856. /* corresponding eigenvectors. */
  857. scopy_(&im, &w[wbegin], &c__1, &work[wbegin], &c__1);
  858. /* We store in W the eigenvalue approximations w.r.t. the original */
  859. /* matrix T. */
  860. i__2 = im;
  861. for (i__ = 1; i__ <= i__2; ++i__) {
  862. w[wbegin + i__ - 1] += sigma;
  863. /* L30: */
  864. }
  865. /* NDEPTH is the current depth of the representation tree */
  866. ndepth = 0;
  867. /* PARITY is either 1 or 0 */
  868. parity = 1;
  869. /* NCLUS is the number of clusters for the next level of the */
  870. /* representation tree, we start with NCLUS = 1 for the root */
  871. nclus = 1;
  872. iwork[iindc1 + 1] = 1;
  873. iwork[iindc1 + 2] = im;
  874. /* IDONE is the number of eigenvectors already computed in the current */
  875. /* block */
  876. idone = 0;
  877. /* loop while( IDONE.LT.IM ) */
  878. /* generate the representation tree for the current block and */
  879. /* compute the eigenvectors */
  880. L40:
  881. if (idone < im) {
  882. /* This is a crude protection against infinitely deep trees */
  883. if (ndepth > *m) {
  884. *info = -2;
  885. return 0;
  886. }
  887. /* breadth first processing of the current level of the representation */
  888. /* tree: OLDNCL = number of clusters on current level */
  889. oldncl = nclus;
  890. /* reset NCLUS to count the number of child clusters */
  891. nclus = 0;
  892. parity = 1 - parity;
  893. if (parity == 0) {
  894. oldcls = iindc1;
  895. newcls = iindc2;
  896. } else {
  897. oldcls = iindc2;
  898. newcls = iindc1;
  899. }
  900. /* Process the clusters on the current level */
  901. i__2 = oldncl;
  902. for (i__ = 1; i__ <= i__2; ++i__) {
  903. j = oldcls + (i__ << 1);
  904. /* OLDFST, OLDLST = first, last index of current cluster. */
  905. /* cluster indices start with 1 and are relative */
  906. /* to WBEGIN when accessing W, WGAP, WERR, Z */
  907. oldfst = iwork[j - 1];
  908. oldlst = iwork[j];
  909. if (ndepth > 0) {
  910. /* Retrieve relatively robust representation (RRR) of cluster */
  911. /* that has been computed at the previous level */
  912. /* The RRR is stored in Z and overwritten once the eigenvectors */
  913. /* have been computed or when the cluster is refined */
  914. if (*dol == 1 && *dou == *m) {
  915. /* Get representation from location of the leftmost evalue */
  916. /* of the cluster */
  917. j = wbegin + oldfst - 1;
  918. } else {
  919. if (wbegin + oldfst - 1 < *dol) {
  920. /* Get representation from the left end of Z array */
  921. j = *dol - 1;
  922. } else if (wbegin + oldfst - 1 > *dou) {
  923. /* Get representation from the right end of Z array */
  924. j = *dou;
  925. } else {
  926. j = wbegin + oldfst - 1;
  927. }
  928. }
  929. scopy_(&in, &z__[ibegin + j * z_dim1], &c__1, &d__[ibegin]
  930. , &c__1);
  931. i__3 = in - 1;
  932. scopy_(&i__3, &z__[ibegin + (j + 1) * z_dim1], &c__1, &l[
  933. ibegin], &c__1);
  934. sigma = z__[iend + (j + 1) * z_dim1];
  935. /* Set the corresponding entries in Z to zero */
  936. slaset_("Full", &in, &c__2, &c_b5, &c_b5, &z__[ibegin + j
  937. * z_dim1], ldz);
  938. }
  939. /* Compute DL and DLL of current RRR */
  940. i__3 = iend - 1;
  941. for (j = ibegin; j <= i__3; ++j) {
  942. tmp = d__[j] * l[j];
  943. work[indld - 1 + j] = tmp;
  944. work[indlld - 1 + j] = tmp * l[j];
  945. /* L50: */
  946. }
  947. if (ndepth > 0) {
  948. /* P and Q are index of the first and last eigenvalue to compute */
  949. /* within the current block */
  950. p = indexw[wbegin - 1 + oldfst];
  951. q = indexw[wbegin - 1 + oldlst];
  952. /* Offset for the arrays WORK, WGAP and WERR, i.e., the P-OFFSET */
  953. /* through the Q-OFFSET elements of these arrays are to be used. */
  954. /* OFFSET = P-OLDFST */
  955. offset = indexw[wbegin] - 1;
  956. /* perform limited bisection (if necessary) to get approximate */
  957. /* eigenvalues to the precision needed. */
  958. slarrb_(&in, &d__[ibegin], &work[indlld + ibegin - 1], &p,
  959. &q, rtol1, rtol2, &offset, &work[wbegin], &wgap[
  960. wbegin], &werr[wbegin], &work[indwrk], &iwork[
  961. iindwk], pivmin, &spdiam, &in, &iinfo);
  962. if (iinfo != 0) {
  963. *info = -1;
  964. return 0;
  965. }
  966. /* We also recompute the extremal gaps. W holds all eigenvalues */
  967. /* of the unshifted matrix and must be used for computation */
  968. /* of WGAP, the entries of WORK might stem from RRRs with */
  969. /* different shifts. The gaps from WBEGIN-1+OLDFST to */
  970. /* WBEGIN-1+OLDLST are correctly computed in SLARRB. */
  971. /* However, we only allow the gaps to become greater since */
  972. /* this is what should happen when we decrease WERR */
  973. if (oldfst > 1) {
  974. /* Computing MAX */
  975. r__1 = wgap[wbegin + oldfst - 2], r__2 = w[wbegin +
  976. oldfst - 1] - werr[wbegin + oldfst - 1] - w[
  977. wbegin + oldfst - 2] - werr[wbegin + oldfst -
  978. 2];
  979. wgap[wbegin + oldfst - 2] = f2cmax(r__1,r__2);
  980. }
  981. if (wbegin + oldlst - 1 < wend) {
  982. /* Computing MAX */
  983. r__1 = wgap[wbegin + oldlst - 1], r__2 = w[wbegin +
  984. oldlst] - werr[wbegin + oldlst] - w[wbegin +
  985. oldlst - 1] - werr[wbegin + oldlst - 1];
  986. wgap[wbegin + oldlst - 1] = f2cmax(r__1,r__2);
  987. }
  988. /* Each time the eigenvalues in WORK get refined, we store */
  989. /* the newly found approximation with all shifts applied in W */
  990. i__3 = oldlst;
  991. for (j = oldfst; j <= i__3; ++j) {
  992. w[wbegin + j - 1] = work[wbegin + j - 1] + sigma;
  993. /* L53: */
  994. }
  995. }
  996. /* Process the current node. */
  997. newfst = oldfst;
  998. i__3 = oldlst;
  999. for (j = oldfst; j <= i__3; ++j) {
  1000. if (j == oldlst) {
  1001. /* we are at the right end of the cluster, this is also the */
  1002. /* boundary of the child cluster */
  1003. newlst = j;
  1004. } else if (wgap[wbegin + j - 1] >= *minrgp * (r__1 = work[
  1005. wbegin + j - 1], abs(r__1))) {
  1006. /* the right relative gap is big enough, the child cluster */
  1007. /* (NEWFST,..,NEWLST) is well separated from the following */
  1008. newlst = j;
  1009. } else {
  1010. /* inside a child cluster, the relative gap is not */
  1011. /* big enough. */
  1012. goto L140;
  1013. }
  1014. /* Compute size of child cluster found */
  1015. newsiz = newlst - newfst + 1;
  1016. /* NEWFTT is the place in Z where the new RRR or the computed */
  1017. /* eigenvector is to be stored */
  1018. if (*dol == 1 && *dou == *m) {
  1019. /* Store representation at location of the leftmost evalue */
  1020. /* of the cluster */
  1021. newftt = wbegin + newfst - 1;
  1022. } else {
  1023. if (wbegin + newfst - 1 < *dol) {
  1024. /* Store representation at the left end of Z array */
  1025. newftt = *dol - 1;
  1026. } else if (wbegin + newfst - 1 > *dou) {
  1027. /* Store representation at the right end of Z array */
  1028. newftt = *dou;
  1029. } else {
  1030. newftt = wbegin + newfst - 1;
  1031. }
  1032. }
  1033. if (newsiz > 1) {
  1034. /* Current child is not a singleton but a cluster. */
  1035. /* Compute and store new representation of child. */
  1036. /* Compute left and right cluster gap. */
  1037. /* LGAP and RGAP are not computed from WORK because */
  1038. /* the eigenvalue approximations may stem from RRRs */
  1039. /* different shifts. However, W hold all eigenvalues */
  1040. /* of the unshifted matrix. Still, the entries in WGAP */
  1041. /* have to be computed from WORK since the entries */
  1042. /* in W might be of the same order so that gaps are not */
  1043. /* exhibited correctly for very close eigenvalues. */
  1044. if (newfst == 1) {
  1045. /* Computing MAX */
  1046. r__1 = 0.f, r__2 = w[wbegin] - werr[wbegin] - *vl;
  1047. lgap = f2cmax(r__1,r__2);
  1048. } else {
  1049. lgap = wgap[wbegin + newfst - 2];
  1050. }
  1051. rgap = wgap[wbegin + newlst - 1];
  1052. /* Compute left- and rightmost eigenvalue of child */
  1053. /* to high precision in order to shift as close */
  1054. /* as possible and obtain as large relative gaps */
  1055. /* as possible */
  1056. for (k = 1; k <= 2; ++k) {
  1057. if (k == 1) {
  1058. p = indexw[wbegin - 1 + newfst];
  1059. } else {
  1060. p = indexw[wbegin - 1 + newlst];
  1061. }
  1062. offset = indexw[wbegin] - 1;
  1063. slarrb_(&in, &d__[ibegin], &work[indlld + ibegin
  1064. - 1], &p, &p, &rqtol, &rqtol, &offset, &
  1065. work[wbegin], &wgap[wbegin], &werr[wbegin]
  1066. , &work[indwrk], &iwork[iindwk], pivmin, &
  1067. spdiam, &in, &iinfo);
  1068. /* L55: */
  1069. }
  1070. if (wbegin + newlst - 1 < *dol || wbegin + newfst - 1
  1071. > *dou) {
  1072. /* if the cluster contains no desired eigenvalues */
  1073. /* skip the computation of that branch of the rep. tree */
  1074. /* We could skip before the refinement of the extremal */
  1075. /* eigenvalues of the child, but then the representation */
  1076. /* tree could be different from the one when nothing is */
  1077. /* skipped. For this reason we skip at this place. */
  1078. idone = idone + newlst - newfst + 1;
  1079. goto L139;
  1080. }
  1081. /* Compute RRR of child cluster. */
  1082. /* Note that the new RRR is stored in Z */
  1083. /* SLARRF needs LWORK = 2*N */
  1084. slarrf_(&in, &d__[ibegin], &l[ibegin], &work[indld +
  1085. ibegin - 1], &newfst, &newlst, &work[wbegin],
  1086. &wgap[wbegin], &werr[wbegin], &spdiam, &lgap,
  1087. &rgap, pivmin, &tau, &z__[ibegin + newftt *
  1088. z_dim1], &z__[ibegin + (newftt + 1) * z_dim1],
  1089. &work[indwrk], &iinfo);
  1090. if (iinfo == 0) {
  1091. /* a new RRR for the cluster was found by SLARRF */
  1092. /* update shift and store it */
  1093. ssigma = sigma + tau;
  1094. z__[iend + (newftt + 1) * z_dim1] = ssigma;
  1095. /* WORK() are the midpoints and WERR() the semi-width */
  1096. /* Note that the entries in W are unchanged. */
  1097. i__4 = newlst;
  1098. for (k = newfst; k <= i__4; ++k) {
  1099. fudge = eps * 3.f * (r__1 = work[wbegin + k -
  1100. 1], abs(r__1));
  1101. work[wbegin + k - 1] -= tau;
  1102. fudge += eps * 4.f * (r__1 = work[wbegin + k
  1103. - 1], abs(r__1));
  1104. /* Fudge errors */
  1105. werr[wbegin + k - 1] += fudge;
  1106. /* Gaps are not fudged. Provided that WERR is small */
  1107. /* when eigenvalues are close, a zero gap indicates */
  1108. /* that a new representation is needed for resolving */
  1109. /* the cluster. A fudge could lead to a wrong decision */
  1110. /* of judging eigenvalues 'separated' which in */
  1111. /* reality are not. This could have a negative impact */
  1112. /* on the orthogonality of the computed eigenvectors. */
  1113. /* L116: */
  1114. }
  1115. ++nclus;
  1116. k = newcls + (nclus << 1);
  1117. iwork[k - 1] = newfst;
  1118. iwork[k] = newlst;
  1119. } else {
  1120. *info = -2;
  1121. return 0;
  1122. }
  1123. } else {
  1124. /* Compute eigenvector of singleton */
  1125. iter = 0;
  1126. tol = log((real) in) * 4.f * eps;
  1127. k = newfst;
  1128. windex = wbegin + k - 1;
  1129. /* Computing MAX */
  1130. i__4 = windex - 1;
  1131. windmn = f2cmax(i__4,1);
  1132. /* Computing MIN */
  1133. i__4 = windex + 1;
  1134. windpl = f2cmin(i__4,*m);
  1135. lambda = work[windex];
  1136. ++done;
  1137. /* Check if eigenvector computation is to be skipped */
  1138. if (windex < *dol || windex > *dou) {
  1139. eskip = TRUE_;
  1140. goto L125;
  1141. } else {
  1142. eskip = FALSE_;
  1143. }
  1144. left = work[windex] - werr[windex];
  1145. right = work[windex] + werr[windex];
  1146. indeig = indexw[windex];
  1147. /* Note that since we compute the eigenpairs for a child, */
  1148. /* all eigenvalue approximations are w.r.t the same shift. */
  1149. /* In this case, the entries in WORK should be used for */
  1150. /* computing the gaps since they exhibit even very small */
  1151. /* differences in the eigenvalues, as opposed to the */
  1152. /* entries in W which might "look" the same. */
  1153. if (k == 1) {
  1154. /* In the case RANGE='I' and with not much initial */
  1155. /* accuracy in LAMBDA and VL, the formula */
  1156. /* LGAP = MAX( ZERO, (SIGMA - VL) + LAMBDA ) */
  1157. /* can lead to an overestimation of the left gap and */
  1158. /* thus to inadequately early RQI 'convergence'. */
  1159. /* Prevent this by forcing a small left gap. */
  1160. /* Computing MAX */
  1161. r__1 = abs(left), r__2 = abs(right);
  1162. lgap = eps * f2cmax(r__1,r__2);
  1163. } else {
  1164. lgap = wgap[windmn];
  1165. }
  1166. if (k == im) {
  1167. /* In the case RANGE='I' and with not much initial */
  1168. /* accuracy in LAMBDA and VU, the formula */
  1169. /* can lead to an overestimation of the right gap and */
  1170. /* thus to inadequately early RQI 'convergence'. */
  1171. /* Prevent this by forcing a small right gap. */
  1172. /* Computing MAX */
  1173. r__1 = abs(left), r__2 = abs(right);
  1174. rgap = eps * f2cmax(r__1,r__2);
  1175. } else {
  1176. rgap = wgap[windex];
  1177. }
  1178. gap = f2cmin(lgap,rgap);
  1179. if (k == 1 || k == im) {
  1180. /* The eigenvector support can become wrong */
  1181. /* because significant entries could be cut off due to a */
  1182. /* large GAPTOL parameter in LAR1V. Prevent this. */
  1183. gaptol = 0.f;
  1184. } else {
  1185. gaptol = gap * eps;
  1186. }
  1187. isupmn = in;
  1188. isupmx = 1;
  1189. /* Update WGAP so that it holds the minimum gap */
  1190. /* to the left or the right. This is crucial in the */
  1191. /* case where bisection is used to ensure that the */
  1192. /* eigenvalue is refined up to the required precision. */
  1193. /* The correct value is restored afterwards. */
  1194. savgap = wgap[windex];
  1195. wgap[windex] = gap;
  1196. /* We want to use the Rayleigh Quotient Correction */
  1197. /* as often as possible since it converges quadratically */
  1198. /* when we are close enough to the desired eigenvalue. */
  1199. /* However, the Rayleigh Quotient can have the wrong sign */
  1200. /* and lead us away from the desired eigenvalue. In this */
  1201. /* case, the best we can do is to use bisection. */
  1202. usedbs = FALSE_;
  1203. usedrq = FALSE_;
  1204. /* Bisection is initially turned off unless it is forced */
  1205. needbs = ! tryrqc;
  1206. L120:
  1207. /* Check if bisection should be used to refine eigenvalue */
  1208. if (needbs) {
  1209. /* Take the bisection as new iterate */
  1210. usedbs = TRUE_;
  1211. itmp1 = iwork[iindr + windex];
  1212. offset = indexw[wbegin] - 1;
  1213. r__1 = eps * 2.f;
  1214. slarrb_(&in, &d__[ibegin], &work[indlld + ibegin
  1215. - 1], &indeig, &indeig, &c_b5, &r__1, &
  1216. offset, &work[wbegin], &wgap[wbegin], &
  1217. werr[wbegin], &work[indwrk], &iwork[
  1218. iindwk], pivmin, &spdiam, &itmp1, &iinfo);
  1219. if (iinfo != 0) {
  1220. *info = -3;
  1221. return 0;
  1222. }
  1223. lambda = work[windex];
  1224. /* Reset twist index from inaccurate LAMBDA to */
  1225. /* force computation of true MINGMA */
  1226. iwork[iindr + windex] = 0;
  1227. }
  1228. /* Given LAMBDA, compute the eigenvector. */
  1229. L__1 = ! usedbs;
  1230. slar1v_(&in, &c__1, &in, &lambda, &d__[ibegin], &l[
  1231. ibegin], &work[indld + ibegin - 1], &work[
  1232. indlld + ibegin - 1], pivmin, &gaptol, &z__[
  1233. ibegin + windex * z_dim1], &L__1, &negcnt, &
  1234. ztz, &mingma, &iwork[iindr + windex], &isuppz[
  1235. (windex << 1) - 1], &nrminv, &resid, &rqcorr,
  1236. &work[indwrk]);
  1237. if (iter == 0) {
  1238. bstres = resid;
  1239. bstw = lambda;
  1240. } else if (resid < bstres) {
  1241. bstres = resid;
  1242. bstw = lambda;
  1243. }
  1244. /* Computing MIN */
  1245. i__4 = isupmn, i__5 = isuppz[(windex << 1) - 1];
  1246. isupmn = f2cmin(i__4,i__5);
  1247. /* Computing MAX */
  1248. i__4 = isupmx, i__5 = isuppz[windex * 2];
  1249. isupmx = f2cmax(i__4,i__5);
  1250. ++iter;
  1251. /* sin alpha <= |resid|/gap */
  1252. /* Note that both the residual and the gap are */
  1253. /* proportional to the matrix, so ||T|| doesn't play */
  1254. /* a role in the quotient */
  1255. /* Convergence test for Rayleigh-Quotient iteration */
  1256. /* (omitted when Bisection has been used) */
  1257. if (resid > tol * gap && abs(rqcorr) > rqtol * abs(
  1258. lambda) && ! usedbs) {
  1259. /* We need to check that the RQCORR update doesn't */
  1260. /* move the eigenvalue away from the desired one and */
  1261. /* towards a neighbor. -> protection with bisection */
  1262. if (indeig <= negcnt) {
  1263. /* The wanted eigenvalue lies to the left */
  1264. sgndef = -1.f;
  1265. } else {
  1266. /* The wanted eigenvalue lies to the right */
  1267. sgndef = 1.f;
  1268. }
  1269. /* We only use the RQCORR if it improves the */
  1270. /* the iterate reasonably. */
  1271. if (rqcorr * sgndef >= 0.f && lambda + rqcorr <=
  1272. right && lambda + rqcorr >= left) {
  1273. usedrq = TRUE_;
  1274. /* Store new midpoint of bisection interval in WORK */
  1275. if (sgndef == 1.f) {
  1276. /* The current LAMBDA is on the left of the true */
  1277. /* eigenvalue */
  1278. left = lambda;
  1279. /* We prefer to assume that the error estimate */
  1280. /* is correct. We could make the interval not */
  1281. /* as a bracket but to be modified if the RQCORR */
  1282. /* chooses to. In this case, the RIGHT side should */
  1283. /* be modified as follows: */
  1284. /* RIGHT = MAX(RIGHT, LAMBDA + RQCORR) */
  1285. } else {
  1286. /* The current LAMBDA is on the right of the true */
  1287. /* eigenvalue */
  1288. right = lambda;
  1289. /* See comment about assuming the error estimate is */
  1290. /* correct above. */
  1291. /* LEFT = MIN(LEFT, LAMBDA + RQCORR) */
  1292. }
  1293. work[windex] = (right + left) * .5f;
  1294. /* Take RQCORR since it has the correct sign and */
  1295. /* improves the iterate reasonably */
  1296. lambda += rqcorr;
  1297. /* Update width of error interval */
  1298. werr[windex] = (right - left) * .5f;
  1299. } else {
  1300. needbs = TRUE_;
  1301. }
  1302. if (right - left < rqtol * abs(lambda)) {
  1303. /* The eigenvalue is computed to bisection accuracy */
  1304. /* compute eigenvector and stop */
  1305. usedbs = TRUE_;
  1306. goto L120;
  1307. } else if (iter < 10) {
  1308. goto L120;
  1309. } else if (iter == 10) {
  1310. needbs = TRUE_;
  1311. goto L120;
  1312. } else {
  1313. *info = 5;
  1314. return 0;
  1315. }
  1316. } else {
  1317. stp2ii = FALSE_;
  1318. if (usedrq && usedbs && bstres <= resid) {
  1319. lambda = bstw;
  1320. stp2ii = TRUE_;
  1321. }
  1322. if (stp2ii) {
  1323. /* improve error angle by second step */
  1324. L__1 = ! usedbs;
  1325. slar1v_(&in, &c__1, &in, &lambda, &d__[ibegin]
  1326. , &l[ibegin], &work[indld + ibegin -
  1327. 1], &work[indlld + ibegin - 1],
  1328. pivmin, &gaptol, &z__[ibegin + windex
  1329. * z_dim1], &L__1, &negcnt, &ztz, &
  1330. mingma, &iwork[iindr + windex], &
  1331. isuppz[(windex << 1) - 1], &nrminv, &
  1332. resid, &rqcorr, &work[indwrk]);
  1333. }
  1334. work[windex] = lambda;
  1335. }
  1336. /* Compute FP-vector support w.r.t. whole matrix */
  1337. isuppz[(windex << 1) - 1] += oldien;
  1338. isuppz[windex * 2] += oldien;
  1339. zfrom = isuppz[(windex << 1) - 1];
  1340. zto = isuppz[windex * 2];
  1341. isupmn += oldien;
  1342. isupmx += oldien;
  1343. /* Ensure vector is ok if support in the RQI has changed */
  1344. if (isupmn < zfrom) {
  1345. i__4 = zfrom - 1;
  1346. for (ii = isupmn; ii <= i__4; ++ii) {
  1347. z__[ii + windex * z_dim1] = 0.f;
  1348. /* L122: */
  1349. }
  1350. }
  1351. if (isupmx > zto) {
  1352. i__4 = isupmx;
  1353. for (ii = zto + 1; ii <= i__4; ++ii) {
  1354. z__[ii + windex * z_dim1] = 0.f;
  1355. /* L123: */
  1356. }
  1357. }
  1358. i__4 = zto - zfrom + 1;
  1359. sscal_(&i__4, &nrminv, &z__[zfrom + windex * z_dim1],
  1360. &c__1);
  1361. L125:
  1362. /* Update W */
  1363. w[windex] = lambda + sigma;
  1364. /* Recompute the gaps on the left and right */
  1365. /* But only allow them to become larger and not */
  1366. /* smaller (which can only happen through "bad" */
  1367. /* cancellation and doesn't reflect the theory */
  1368. /* where the initial gaps are underestimated due */
  1369. /* to WERR being too crude.) */
  1370. if (! eskip) {
  1371. if (k > 1) {
  1372. /* Computing MAX */
  1373. r__1 = wgap[windmn], r__2 = w[windex] - werr[
  1374. windex] - w[windmn] - werr[windmn];
  1375. wgap[windmn] = f2cmax(r__1,r__2);
  1376. }
  1377. if (windex < wend) {
  1378. /* Computing MAX */
  1379. r__1 = savgap, r__2 = w[windpl] - werr[windpl]
  1380. - w[windex] - werr[windex];
  1381. wgap[windex] = f2cmax(r__1,r__2);
  1382. }
  1383. }
  1384. ++idone;
  1385. }
  1386. /* here ends the code for the current child */
  1387. L139:
  1388. /* Proceed to any remaining child nodes */
  1389. newfst = j + 1;
  1390. L140:
  1391. ;
  1392. }
  1393. /* L150: */
  1394. }
  1395. ++ndepth;
  1396. goto L40;
  1397. }
  1398. ibegin = iend + 1;
  1399. wbegin = wend + 1;
  1400. L170:
  1401. ;
  1402. }
  1403. return 0;
  1404. /* End of SLARRV */
  1405. } /* slarrv_ */