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.

dlarrv.c 52 kB

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