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.

dlasq2.c 28 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  1. /* f2c.h -- Standard Fortran to C header file */
  2. /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
  3. - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
  4. #ifndef F2C_INCLUDE
  5. #define F2C_INCLUDE
  6. #include <math.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <complex.h>
  11. #ifdef complex
  12. #undef complex
  13. #endif
  14. #ifdef I
  15. #undef I
  16. #endif
  17. #if defined(_WIN64)
  18. typedef long long BLASLONG;
  19. typedef unsigned long long BLASULONG;
  20. #else
  21. typedef long BLASLONG;
  22. typedef unsigned long BLASULONG;
  23. #endif
  24. #ifdef LAPACK_ILP64
  25. typedef BLASLONG blasint;
  26. #if defined(_WIN64)
  27. #define blasabs(x) llabs(x)
  28. #else
  29. #define blasabs(x) labs(x)
  30. #endif
  31. #else
  32. typedef int blasint;
  33. #define blasabs(x) abs(x)
  34. #endif
  35. typedef blasint integer;
  36. typedef unsigned int uinteger;
  37. typedef char *address;
  38. typedef short int shortint;
  39. typedef float real;
  40. typedef double doublereal;
  41. typedef struct { real r, i; } complex;
  42. typedef struct { doublereal r, i; } doublecomplex;
  43. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  44. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  46. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  47. #define pCf(z) (*_pCf(z))
  48. #define pCd(z) (*_pCd(z))
  49. typedef int logical;
  50. typedef short int shortlogical;
  51. typedef char logical1;
  52. typedef char integer1;
  53. #define TRUE_ (1)
  54. #define FALSE_ (0)
  55. /* Extern is for use with -E */
  56. #ifndef Extern
  57. #define Extern extern
  58. #endif
  59. /* I/O stuff */
  60. typedef int flag;
  61. typedef int ftnlen;
  62. typedef int ftnint;
  63. /*external read, write*/
  64. typedef struct
  65. { flag cierr;
  66. ftnint ciunit;
  67. flag ciend;
  68. char *cifmt;
  69. ftnint cirec;
  70. } cilist;
  71. /*internal read, write*/
  72. typedef struct
  73. { flag icierr;
  74. char *iciunit;
  75. flag iciend;
  76. char *icifmt;
  77. ftnint icirlen;
  78. ftnint icirnum;
  79. } icilist;
  80. /*open*/
  81. typedef struct
  82. { flag oerr;
  83. ftnint ounit;
  84. char *ofnm;
  85. ftnlen ofnmlen;
  86. char *osta;
  87. char *oacc;
  88. char *ofm;
  89. ftnint orl;
  90. char *oblnk;
  91. } olist;
  92. /*close*/
  93. typedef struct
  94. { flag cerr;
  95. ftnint cunit;
  96. char *csta;
  97. } cllist;
  98. /*rewind, backspace, endfile*/
  99. typedef struct
  100. { flag aerr;
  101. ftnint aunit;
  102. } alist;
  103. /* inquire */
  104. typedef struct
  105. { flag inerr;
  106. ftnint inunit;
  107. char *infile;
  108. ftnlen infilen;
  109. ftnint *inex; /*parameters in standard's order*/
  110. ftnint *inopen;
  111. ftnint *innum;
  112. ftnint *innamed;
  113. char *inname;
  114. ftnlen innamlen;
  115. char *inacc;
  116. ftnlen inacclen;
  117. char *inseq;
  118. ftnlen inseqlen;
  119. char *indir;
  120. ftnlen indirlen;
  121. char *infmt;
  122. ftnlen infmtlen;
  123. char *inform;
  124. ftnint informlen;
  125. char *inunf;
  126. ftnlen inunflen;
  127. ftnint *inrecl;
  128. ftnint *innrec;
  129. char *inblank;
  130. ftnlen inblanklen;
  131. } inlist;
  132. #define VOID void
  133. union Multitype { /* for multiple entry points */
  134. integer1 g;
  135. shortint h;
  136. integer i;
  137. /* longint j; */
  138. real r;
  139. doublereal d;
  140. complex c;
  141. doublecomplex z;
  142. };
  143. typedef union Multitype Multitype;
  144. struct Vardesc { /* for Namelist */
  145. char *name;
  146. char *addr;
  147. ftnlen *dims;
  148. int type;
  149. };
  150. typedef struct Vardesc Vardesc;
  151. struct Namelist {
  152. char *name;
  153. Vardesc **vars;
  154. int nvars;
  155. };
  156. typedef struct Namelist Namelist;
  157. #define abs(x) ((x) >= 0 ? (x) : -(x))
  158. #define dabs(x) (fabs(x))
  159. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  160. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  161. #define dmin(a,b) (f2cmin(a,b))
  162. #define dmax(a,b) (f2cmax(a,b))
  163. #define bit_test(a,b) ((a) >> (b) & 1)
  164. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  165. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  166. #define abort_() { sig_die("Fortran abort routine called", 1); }
  167. #define c_abs(z) (cabsf(Cf(z)))
  168. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  169. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  170. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  171. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  172. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  173. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  174. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  175. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  176. #define d_abs(x) (fabs(*(x)))
  177. #define d_acos(x) (acos(*(x)))
  178. #define d_asin(x) (asin(*(x)))
  179. #define d_atan(x) (atan(*(x)))
  180. #define d_atn2(x, y) (atan2(*(x),*(y)))
  181. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  182. #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
  183. #define d_cos(x) (cos(*(x)))
  184. #define d_cosh(x) (cosh(*(x)))
  185. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  186. #define d_exp(x) (exp(*(x)))
  187. #define d_imag(z) (cimag(Cd(z)))
  188. #define r_imag(z) (cimag(Cf(z)))
  189. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  190. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  191. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  192. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  193. #define d_log(x) (log(*(x)))
  194. #define d_mod(x, y) (fmod(*(x), *(y)))
  195. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  196. #define d_nint(x) u_nint(*(x))
  197. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  198. #define d_sign(a,b) u_sign(*(a),*(b))
  199. #define r_sign(a,b) u_sign(*(a),*(b))
  200. #define d_sin(x) (sin(*(x)))
  201. #define d_sinh(x) (sinh(*(x)))
  202. #define d_sqrt(x) (sqrt(*(x)))
  203. #define d_tan(x) (tan(*(x)))
  204. #define d_tanh(x) (tanh(*(x)))
  205. #define i_abs(x) abs(*(x))
  206. #define i_dnnt(x) ((integer)u_nint(*(x)))
  207. #define i_len(s, n) (n)
  208. #define i_nint(x) ((integer)u_nint(*(x)))
  209. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  210. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  211. #define pow_si(B,E) spow_ui(*(B),*(E))
  212. #define pow_ri(B,E) spow_ui(*(B),*(E))
  213. #define pow_di(B,E) dpow_ui(*(B),*(E))
  214. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  215. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  216. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  217. #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
  218. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  219. #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
  220. #define sig_die(s, kill) { exit(1); }
  221. #define s_stop(s, n) {exit(0);}
  222. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  223. #define z_abs(z) (cabs(Cd(z)))
  224. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  225. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  226. #define myexit_() break;
  227. #define mycycle() continue;
  228. #define myceiling(w) {ceil(w)}
  229. #define myhuge(w) {HUGE_VAL}
  230. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  231. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  232. /* procedure parameter types for -A and -C++ */
  233. #define F2C_proc_par_types 1
  234. #ifdef __cplusplus
  235. typedef logical (*L_fp)(...);
  236. #else
  237. typedef logical (*L_fp)();
  238. #endif
  239. static float spow_ui(float x, integer n) {
  240. float pow=1.0; unsigned long int u;
  241. if(n != 0) {
  242. if(n < 0) n = -n, x = 1/x;
  243. for(u = n; ; ) {
  244. if(u & 01) pow *= x;
  245. if(u >>= 1) x *= x;
  246. else break;
  247. }
  248. }
  249. return pow;
  250. }
  251. static double dpow_ui(double x, integer n) {
  252. double pow=1.0; unsigned long int u;
  253. if(n != 0) {
  254. if(n < 0) n = -n, x = 1/x;
  255. for(u = n; ; ) {
  256. if(u & 01) pow *= x;
  257. if(u >>= 1) x *= x;
  258. else break;
  259. }
  260. }
  261. return pow;
  262. }
  263. static _Complex float cpow_ui(_Complex float x, integer n) {
  264. _Complex float pow=1.0; unsigned long int u;
  265. if(n != 0) {
  266. if(n < 0) n = -n, x = 1/x;
  267. for(u = n; ; ) {
  268. if(u & 01) pow *= x;
  269. if(u >>= 1) x *= x;
  270. else break;
  271. }
  272. }
  273. return pow;
  274. }
  275. static _Complex double zpow_ui(_Complex double x, integer n) {
  276. _Complex double pow=1.0; unsigned long int u;
  277. if(n != 0) {
  278. if(n < 0) n = -n, x = 1/x;
  279. for(u = n; ; ) {
  280. if(u & 01) pow *= x;
  281. if(u >>= 1) x *= x;
  282. else break;
  283. }
  284. }
  285. return pow;
  286. }
  287. static integer pow_ii(integer x, integer n) {
  288. integer pow; unsigned long int u;
  289. if (n <= 0) {
  290. if (n == 0 || x == 1) pow = 1;
  291. else if (x != -1) pow = x == 0 ? 1/x : 0;
  292. else n = -n;
  293. }
  294. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  295. u = n;
  296. for(pow = 1; ; ) {
  297. if(u & 01) pow *= x;
  298. if(u >>= 1) x *= x;
  299. else break;
  300. }
  301. }
  302. return pow;
  303. }
  304. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  305. {
  306. double m; integer i, mi;
  307. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  308. if (w[i-1]>m) mi=i ,m=w[i-1];
  309. return mi-s+1;
  310. }
  311. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  312. {
  313. float m; integer i, mi;
  314. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  315. if (w[i-1]>m) mi=i ,m=w[i-1];
  316. return mi-s+1;
  317. }
  318. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  319. integer n = *n_, incx = *incx_, incy = *incy_, i;
  320. _Complex float zdotc = 0.0;
  321. if (incx == 1 && incy == 1) {
  322. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  323. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  324. }
  325. } else {
  326. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  327. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  328. }
  329. }
  330. pCf(z) = zdotc;
  331. }
  332. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  333. integer n = *n_, incx = *incx_, incy = *incy_, i;
  334. _Complex double zdotc = 0.0;
  335. if (incx == 1 && incy == 1) {
  336. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  337. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  338. }
  339. } else {
  340. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  341. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  342. }
  343. }
  344. pCd(z) = zdotc;
  345. }
  346. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  347. integer n = *n_, incx = *incx_, incy = *incy_, i;
  348. _Complex float zdotc = 0.0;
  349. if (incx == 1 && incy == 1) {
  350. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  351. zdotc += Cf(&x[i]) * Cf(&y[i]);
  352. }
  353. } else {
  354. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  355. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  356. }
  357. }
  358. pCf(z) = zdotc;
  359. }
  360. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  361. integer n = *n_, incx = *incx_, incy = *incy_, i;
  362. _Complex double zdotc = 0.0;
  363. if (incx == 1 && incy == 1) {
  364. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  365. zdotc += Cd(&x[i]) * Cd(&y[i]);
  366. }
  367. } else {
  368. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  369. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  370. }
  371. }
  372. pCd(z) = zdotc;
  373. }
  374. #endif
  375. /* -- translated by f2c (version 20000121).
  376. You must link the resulting object file with the libraries:
  377. -lf2c -lm (in that order)
  378. */
  379. /* Table of constant values */
  380. static integer c__1 = 1;
  381. static integer c__2 = 2;
  382. static integer c__10 = 10;
  383. static integer c__3 = 3;
  384. static integer c__4 = 4;
  385. static integer c__11 = 11;
  386. /* > \brief \b DLASQ2 computes all the eigenvalues of the symmetric positive definite tridiagonal matrix assoc
  387. iated with the qd Array Z to high relative accuracy. Used by sbdsqr and sstegr. */
  388. /* =========== DOCUMENTATION =========== */
  389. /* Online html documentation available at */
  390. /* http://www.netlib.org/lapack/explore-html/ */
  391. /* > \htmlonly */
  392. /* > Download DLASQ2 + dependencies */
  393. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlasq2.
  394. f"> */
  395. /* > [TGZ]</a> */
  396. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlasq2.
  397. f"> */
  398. /* > [ZIP]</a> */
  399. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlasq2.
  400. f"> */
  401. /* > [TXT]</a> */
  402. /* > \endhtmlonly */
  403. /* Definition: */
  404. /* =========== */
  405. /* SUBROUTINE DLASQ2( N, Z, INFO ) */
  406. /* INTEGER INFO, N */
  407. /* DOUBLE PRECISION Z( * ) */
  408. /* > \par Purpose: */
  409. /* ============= */
  410. /* > */
  411. /* > \verbatim */
  412. /* > */
  413. /* > DLASQ2 computes all the eigenvalues of the symmetric positive */
  414. /* > definite tridiagonal matrix associated with the qd array Z to high */
  415. /* > relative accuracy are computed to high relative accuracy, in the */
  416. /* > absence of denormalization, underflow and overflow. */
  417. /* > */
  418. /* > To see the relation of Z to the tridiagonal matrix, let L be a */
  419. /* > unit lower bidiagonal matrix with subdiagonals Z(2,4,6,,..) and */
  420. /* > let U be an upper bidiagonal matrix with 1's above and diagonal */
  421. /* > Z(1,3,5,,..). The tridiagonal is L*U or, if you prefer, the */
  422. /* > symmetric tridiagonal to which it is similar. */
  423. /* > */
  424. /* > Note : DLASQ2 defines a logical variable, IEEE, which is true */
  425. /* > on machines which follow ieee-754 floating-point standard in their */
  426. /* > handling of infinities and NaNs, and false otherwise. This variable */
  427. /* > is passed to DLASQ3. */
  428. /* > \endverbatim */
  429. /* Arguments: */
  430. /* ========== */
  431. /* > \param[in] N */
  432. /* > \verbatim */
  433. /* > N is INTEGER */
  434. /* > The number of rows and columns in the matrix. N >= 0. */
  435. /* > \endverbatim */
  436. /* > */
  437. /* > \param[in,out] Z */
  438. /* > \verbatim */
  439. /* > Z is DOUBLE PRECISION array, dimension ( 4*N ) */
  440. /* > On entry Z holds the qd array. On exit, entries 1 to N hold */
  441. /* > the eigenvalues in decreasing order, Z( 2*N+1 ) holds the */
  442. /* > trace, and Z( 2*N+2 ) holds the sum of the eigenvalues. If */
  443. /* > N > 2, then Z( 2*N+3 ) holds the iteration count, Z( 2*N+4 ) */
  444. /* > holds NDIVS/NIN^2, and Z( 2*N+5 ) holds the percentage of */
  445. /* > shifts that failed. */
  446. /* > \endverbatim */
  447. /* > */
  448. /* > \param[out] INFO */
  449. /* > \verbatim */
  450. /* > INFO is INTEGER */
  451. /* > = 0: successful exit */
  452. /* > < 0: if the i-th argument is a scalar and had an illegal */
  453. /* > value, then INFO = -i, if the i-th argument is an */
  454. /* > array and the j-entry had an illegal value, then */
  455. /* > INFO = -(i*100+j) */
  456. /* > > 0: the algorithm failed */
  457. /* > = 1, a split was marked by a positive value in E */
  458. /* > = 2, current block of Z not diagonalized after 100*N */
  459. /* > iterations (in inner while loop). On exit Z holds */
  460. /* > a qd array with the same eigenvalues as the given Z. */
  461. /* > = 3, termination criterion of outer while loop not met */
  462. /* > (program created more than N unreduced blocks) */
  463. /* > \endverbatim */
  464. /* Authors: */
  465. /* ======== */
  466. /* > \author Univ. of Tennessee */
  467. /* > \author Univ. of California Berkeley */
  468. /* > \author Univ. of Colorado Denver */
  469. /* > \author NAG Ltd. */
  470. /* > \date December 2016 */
  471. /* > \ingroup auxOTHERcomputational */
  472. /* > \par Further Details: */
  473. /* ===================== */
  474. /* > */
  475. /* > \verbatim */
  476. /* > */
  477. /* > Local Variables: I0:N0 defines a current unreduced segment of Z. */
  478. /* > The shifts are accumulated in SIGMA. Iteration count is in ITER. */
  479. /* > Ping-pong is controlled by PP (alternates between 0 and 1). */
  480. /* > \endverbatim */
  481. /* > */
  482. /* ===================================================================== */
  483. /* Subroutine */ int dlasq2_(integer *n, doublereal *z__, integer *info)
  484. {
  485. /* System generated locals */
  486. integer i__1, i__2, i__3;
  487. doublereal d__1, d__2;
  488. /* Local variables */
  489. logical ieee;
  490. integer nbig;
  491. doublereal dmin__, emin, emax;
  492. integer kmin, ndiv, iter;
  493. doublereal qmin, temp, qmax, zmax;
  494. integer splt;
  495. doublereal dmin1, dmin2, d__, e, g;
  496. integer k;
  497. doublereal s, t;
  498. integer nfail;
  499. doublereal desig, trace, sigma;
  500. integer iinfo;
  501. doublereal tempe, tempq;
  502. integer i0, i1, i4, n0, n1, ttype;
  503. extern /* Subroutine */ int dlasq3_(integer *, integer *, doublereal *,
  504. integer *, doublereal *, doublereal *, doublereal *, doublereal *,
  505. integer *, integer *, integer *, logical *, integer *,
  506. doublereal *, doublereal *, doublereal *, doublereal *,
  507. doublereal *, doublereal *, doublereal *);
  508. doublereal dn;
  509. extern doublereal dlamch_(char *);
  510. integer pp;
  511. doublereal deemin;
  512. integer iwhila, iwhilb;
  513. doublereal oldemn, safmin;
  514. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  515. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  516. integer *, integer *, ftnlen, ftnlen);
  517. extern /* Subroutine */ int dlasrt_(char *, integer *, doublereal *,
  518. integer *);
  519. doublereal dn1, dn2, dee, eps, tau, tol;
  520. integer ipn4;
  521. doublereal tol2;
  522. /* -- LAPACK computational routine (version 3.7.0) -- */
  523. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  524. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  525. /* December 2016 */
  526. /* ===================================================================== */
  527. /* Test the input arguments. */
  528. /* (in case DLASQ2 is not called by DLASQ1) */
  529. /* Parameter adjustments */
  530. --z__;
  531. /* Function Body */
  532. *info = 0;
  533. eps = dlamch_("Precision");
  534. safmin = dlamch_("Safe minimum");
  535. tol = eps * 100.;
  536. /* Computing 2nd power */
  537. d__1 = tol;
  538. tol2 = d__1 * d__1;
  539. if (*n < 0) {
  540. *info = -1;
  541. xerbla_("DLASQ2", &c__1, (ftnlen)6);
  542. return 0;
  543. } else if (*n == 0) {
  544. return 0;
  545. } else if (*n == 1) {
  546. /* 1-by-1 case. */
  547. if (z__[1] < 0.) {
  548. *info = -201;
  549. xerbla_("DLASQ2", &c__2, (ftnlen)6);
  550. }
  551. return 0;
  552. } else if (*n == 2) {
  553. /* 2-by-2 case. */
  554. if (z__[1] < 0.) {
  555. *info = -201;
  556. xerbla_("DLASQ2", &c__2, (ftnlen)6);
  557. return 0;
  558. } else if (z__[2] < 0.) {
  559. *info = -202;
  560. xerbla_("DLASQ2", &c__2, (ftnlen)6);
  561. return 0;
  562. } else if (z__[3] < 0.) {
  563. *info = -203;
  564. xerbla_("DLASQ2", &c__2, (ftnlen)6);
  565. return 0;
  566. } else if (z__[3] > z__[1]) {
  567. d__ = z__[3];
  568. z__[3] = z__[1];
  569. z__[1] = d__;
  570. }
  571. z__[5] = z__[1] + z__[2] + z__[3];
  572. if (z__[2] > z__[3] * tol2) {
  573. t = (z__[1] - z__[3] + z__[2]) * .5;
  574. s = z__[3] * (z__[2] / t);
  575. if (s <= t) {
  576. s = z__[3] * (z__[2] / (t * (sqrt(s / t + 1.) + 1.)));
  577. } else {
  578. s = z__[3] * (z__[2] / (t + sqrt(t) * sqrt(t + s)));
  579. }
  580. t = z__[1] + (s + z__[2]);
  581. z__[3] *= z__[1] / t;
  582. z__[1] = t;
  583. }
  584. z__[2] = z__[3];
  585. z__[6] = z__[2] + z__[1];
  586. return 0;
  587. }
  588. /* Check for negative data and compute sums of q's and e's. */
  589. z__[*n * 2] = 0.;
  590. emin = z__[2];
  591. qmax = 0.;
  592. zmax = 0.;
  593. d__ = 0.;
  594. e = 0.;
  595. i__1 = *n - 1 << 1;
  596. for (k = 1; k <= i__1; k += 2) {
  597. if (z__[k] < 0.) {
  598. *info = -(k + 200);
  599. xerbla_("DLASQ2", &c__2, (ftnlen)6);
  600. return 0;
  601. } else if (z__[k + 1] < 0.) {
  602. *info = -(k + 201);
  603. xerbla_("DLASQ2", &c__2, (ftnlen)6);
  604. return 0;
  605. }
  606. d__ += z__[k];
  607. e += z__[k + 1];
  608. /* Computing MAX */
  609. d__1 = qmax, d__2 = z__[k];
  610. qmax = f2cmax(d__1,d__2);
  611. /* Computing MIN */
  612. d__1 = emin, d__2 = z__[k + 1];
  613. emin = f2cmin(d__1,d__2);
  614. /* Computing MAX */
  615. d__1 = f2cmax(qmax,zmax), d__2 = z__[k + 1];
  616. zmax = f2cmax(d__1,d__2);
  617. /* L10: */
  618. }
  619. if (z__[(*n << 1) - 1] < 0.) {
  620. *info = -((*n << 1) + 199);
  621. xerbla_("DLASQ2", &c__2, (ftnlen)6);
  622. return 0;
  623. }
  624. d__ += z__[(*n << 1) - 1];
  625. /* Computing MAX */
  626. d__1 = qmax, d__2 = z__[(*n << 1) - 1];
  627. qmax = f2cmax(d__1,d__2);
  628. zmax = f2cmax(qmax,zmax);
  629. /* Check for diagonality. */
  630. if (e == 0.) {
  631. i__1 = *n;
  632. for (k = 2; k <= i__1; ++k) {
  633. z__[k] = z__[(k << 1) - 1];
  634. /* L20: */
  635. }
  636. dlasrt_("D", n, &z__[1], &iinfo);
  637. z__[(*n << 1) - 1] = d__;
  638. return 0;
  639. }
  640. trace = d__ + e;
  641. /* Check for zero data. */
  642. if (trace == 0.) {
  643. z__[(*n << 1) - 1] = 0.;
  644. return 0;
  645. }
  646. /* Check whether the machine is IEEE conformable. */
  647. ieee = ilaenv_(&c__10, "DLASQ2", "N", &c__1, &c__2, &c__3, &c__4, (ftnlen)
  648. 6, (ftnlen)1) == 1 && ilaenv_(&c__11, "DLASQ2", "N", &c__1, &c__2,
  649. &c__3, &c__4, (ftnlen)6, (ftnlen)1) == 1;
  650. /* Rearrange data for locality: Z=(q1,qq1,e1,ee1,q2,qq2,e2,ee2,...). */
  651. for (k = *n << 1; k >= 2; k += -2) {
  652. z__[k * 2] = 0.;
  653. z__[(k << 1) - 1] = z__[k];
  654. z__[(k << 1) - 2] = 0.;
  655. z__[(k << 1) - 3] = z__[k - 1];
  656. /* L30: */
  657. }
  658. i0 = 1;
  659. n0 = *n;
  660. /* Reverse the qd-array, if warranted. */
  661. if (z__[(i0 << 2) - 3] * 1.5 < z__[(n0 << 2) - 3]) {
  662. ipn4 = i0 + n0 << 2;
  663. i__1 = i0 + n0 - 1 << 1;
  664. for (i4 = i0 << 2; i4 <= i__1; i4 += 4) {
  665. temp = z__[i4 - 3];
  666. z__[i4 - 3] = z__[ipn4 - i4 - 3];
  667. z__[ipn4 - i4 - 3] = temp;
  668. temp = z__[i4 - 1];
  669. z__[i4 - 1] = z__[ipn4 - i4 - 5];
  670. z__[ipn4 - i4 - 5] = temp;
  671. /* L40: */
  672. }
  673. }
  674. /* Initial split checking via dqd and Li's test. */
  675. pp = 0;
  676. for (k = 1; k <= 2; ++k) {
  677. d__ = z__[(n0 << 2) + pp - 3];
  678. i__1 = (i0 << 2) + pp;
  679. for (i4 = (n0 - 1 << 2) + pp; i4 >= i__1; i4 += -4) {
  680. if (z__[i4 - 1] <= tol2 * d__) {
  681. z__[i4 - 1] = 0.;
  682. d__ = z__[i4 - 3];
  683. } else {
  684. d__ = z__[i4 - 3] * (d__ / (d__ + z__[i4 - 1]));
  685. }
  686. /* L50: */
  687. }
  688. /* dqd maps Z to ZZ plus Li's test. */
  689. emin = z__[(i0 << 2) + pp + 1];
  690. d__ = z__[(i0 << 2) + pp - 3];
  691. i__1 = (n0 - 1 << 2) + pp;
  692. for (i4 = (i0 << 2) + pp; i4 <= i__1; i4 += 4) {
  693. z__[i4 - (pp << 1) - 2] = d__ + z__[i4 - 1];
  694. if (z__[i4 - 1] <= tol2 * d__) {
  695. z__[i4 - 1] = 0.;
  696. z__[i4 - (pp << 1) - 2] = d__;
  697. z__[i4 - (pp << 1)] = 0.;
  698. d__ = z__[i4 + 1];
  699. } else if (safmin * z__[i4 + 1] < z__[i4 - (pp << 1) - 2] &&
  700. safmin * z__[i4 - (pp << 1) - 2] < z__[i4 + 1]) {
  701. temp = z__[i4 + 1] / z__[i4 - (pp << 1) - 2];
  702. z__[i4 - (pp << 1)] = z__[i4 - 1] * temp;
  703. d__ *= temp;
  704. } else {
  705. z__[i4 - (pp << 1)] = z__[i4 + 1] * (z__[i4 - 1] / z__[i4 - (
  706. pp << 1) - 2]);
  707. d__ = z__[i4 + 1] * (d__ / z__[i4 - (pp << 1) - 2]);
  708. }
  709. /* Computing MIN */
  710. d__1 = emin, d__2 = z__[i4 - (pp << 1)];
  711. emin = f2cmin(d__1,d__2);
  712. /* L60: */
  713. }
  714. z__[(n0 << 2) - pp - 2] = d__;
  715. /* Now find qmax. */
  716. qmax = z__[(i0 << 2) - pp - 2];
  717. i__1 = (n0 << 2) - pp - 2;
  718. for (i4 = (i0 << 2) - pp + 2; i4 <= i__1; i4 += 4) {
  719. /* Computing MAX */
  720. d__1 = qmax, d__2 = z__[i4];
  721. qmax = f2cmax(d__1,d__2);
  722. /* L70: */
  723. }
  724. /* Prepare for the next iteration on K. */
  725. pp = 1 - pp;
  726. /* L80: */
  727. }
  728. /* Initialise variables to pass to DLASQ3. */
  729. ttype = 0;
  730. dmin1 = 0.;
  731. dmin2 = 0.;
  732. dn = 0.;
  733. dn1 = 0.;
  734. dn2 = 0.;
  735. g = 0.;
  736. tau = 0.;
  737. iter = 2;
  738. nfail = 0;
  739. ndiv = n0 - i0 << 1;
  740. i__1 = *n + 1;
  741. for (iwhila = 1; iwhila <= i__1; ++iwhila) {
  742. if (n0 < 1) {
  743. goto L170;
  744. }
  745. /* While array unfinished do */
  746. /* E(N0) holds the value of SIGMA when submatrix in I0:N0 */
  747. /* splits from the rest of the array, but is negated. */
  748. desig = 0.;
  749. if (n0 == *n) {
  750. sigma = 0.;
  751. } else {
  752. sigma = -z__[(n0 << 2) - 1];
  753. }
  754. if (sigma < 0.) {
  755. *info = 1;
  756. return 0;
  757. }
  758. /* Find last unreduced submatrix's top index I0, find QMAX and */
  759. /* EMIN. Find Gershgorin-type bound if Q's much greater than E's. */
  760. emax = 0.;
  761. if (n0 > i0) {
  762. emin = (d__1 = z__[(n0 << 2) - 5], abs(d__1));
  763. } else {
  764. emin = 0.;
  765. }
  766. qmin = z__[(n0 << 2) - 3];
  767. qmax = qmin;
  768. for (i4 = n0 << 2; i4 >= 8; i4 += -4) {
  769. if (z__[i4 - 5] <= 0.) {
  770. goto L100;
  771. }
  772. if (qmin >= emax * 4.) {
  773. /* Computing MIN */
  774. d__1 = qmin, d__2 = z__[i4 - 3];
  775. qmin = f2cmin(d__1,d__2);
  776. /* Computing MAX */
  777. d__1 = emax, d__2 = z__[i4 - 5];
  778. emax = f2cmax(d__1,d__2);
  779. }
  780. /* Computing MAX */
  781. d__1 = qmax, d__2 = z__[i4 - 7] + z__[i4 - 5];
  782. qmax = f2cmax(d__1,d__2);
  783. /* Computing MIN */
  784. d__1 = emin, d__2 = z__[i4 - 5];
  785. emin = f2cmin(d__1,d__2);
  786. /* L90: */
  787. }
  788. i4 = 4;
  789. L100:
  790. i0 = i4 / 4;
  791. pp = 0;
  792. if (n0 - i0 > 1) {
  793. dee = z__[(i0 << 2) - 3];
  794. deemin = dee;
  795. kmin = i0;
  796. i__2 = (n0 << 2) - 3;
  797. for (i4 = (i0 << 2) + 1; i4 <= i__2; i4 += 4) {
  798. dee = z__[i4] * (dee / (dee + z__[i4 - 2]));
  799. if (dee <= deemin) {
  800. deemin = dee;
  801. kmin = (i4 + 3) / 4;
  802. }
  803. /* L110: */
  804. }
  805. if (kmin - i0 << 1 < n0 - kmin && deemin <= z__[(n0 << 2) - 3] *
  806. .5) {
  807. ipn4 = i0 + n0 << 2;
  808. pp = 2;
  809. i__2 = i0 + n0 - 1 << 1;
  810. for (i4 = i0 << 2; i4 <= i__2; i4 += 4) {
  811. temp = z__[i4 - 3];
  812. z__[i4 - 3] = z__[ipn4 - i4 - 3];
  813. z__[ipn4 - i4 - 3] = temp;
  814. temp = z__[i4 - 2];
  815. z__[i4 - 2] = z__[ipn4 - i4 - 2];
  816. z__[ipn4 - i4 - 2] = temp;
  817. temp = z__[i4 - 1];
  818. z__[i4 - 1] = z__[ipn4 - i4 - 5];
  819. z__[ipn4 - i4 - 5] = temp;
  820. temp = z__[i4];
  821. z__[i4] = z__[ipn4 - i4 - 4];
  822. z__[ipn4 - i4 - 4] = temp;
  823. /* L120: */
  824. }
  825. }
  826. }
  827. /* Put -(initial shift) into DMIN. */
  828. /* Computing MAX */
  829. d__1 = 0., d__2 = qmin - sqrt(qmin) * 2. * sqrt(emax);
  830. dmin__ = -f2cmax(d__1,d__2);
  831. /* Now I0:N0 is unreduced. */
  832. /* PP = 0 for ping, PP = 1 for pong. */
  833. /* PP = 2 indicates that flipping was applied to the Z array and */
  834. /* and that the tests for deflation upon entry in DLASQ3 */
  835. /* should not be performed. */
  836. nbig = (n0 - i0 + 1) * 100;
  837. i__2 = nbig;
  838. for (iwhilb = 1; iwhilb <= i__2; ++iwhilb) {
  839. if (i0 > n0) {
  840. goto L150;
  841. }
  842. /* While submatrix unfinished take a good dqds step. */
  843. dlasq3_(&i0, &n0, &z__[1], &pp, &dmin__, &sigma, &desig, &qmax, &
  844. nfail, &iter, &ndiv, &ieee, &ttype, &dmin1, &dmin2, &dn, &
  845. dn1, &dn2, &g, &tau);
  846. pp = 1 - pp;
  847. /* When EMIN is very small check for splits. */
  848. if (pp == 0 && n0 - i0 >= 3) {
  849. if (z__[n0 * 4] <= tol2 * qmax || z__[(n0 << 2) - 1] <= tol2 *
  850. sigma) {
  851. splt = i0 - 1;
  852. qmax = z__[(i0 << 2) - 3];
  853. emin = z__[(i0 << 2) - 1];
  854. oldemn = z__[i0 * 4];
  855. i__3 = n0 - 3 << 2;
  856. for (i4 = i0 << 2; i4 <= i__3; i4 += 4) {
  857. if (z__[i4] <= tol2 * z__[i4 - 3] || z__[i4 - 1] <=
  858. tol2 * sigma) {
  859. z__[i4 - 1] = -sigma;
  860. splt = i4 / 4;
  861. qmax = 0.;
  862. emin = z__[i4 + 3];
  863. oldemn = z__[i4 + 4];
  864. } else {
  865. /* Computing MAX */
  866. d__1 = qmax, d__2 = z__[i4 + 1];
  867. qmax = f2cmax(d__1,d__2);
  868. /* Computing MIN */
  869. d__1 = emin, d__2 = z__[i4 - 1];
  870. emin = f2cmin(d__1,d__2);
  871. /* Computing MIN */
  872. d__1 = oldemn, d__2 = z__[i4];
  873. oldemn = f2cmin(d__1,d__2);
  874. }
  875. /* L130: */
  876. }
  877. z__[(n0 << 2) - 1] = emin;
  878. z__[n0 * 4] = oldemn;
  879. i0 = splt + 1;
  880. }
  881. }
  882. /* L140: */
  883. }
  884. *info = 2;
  885. /* Maximum number of iterations exceeded, restore the shift */
  886. /* SIGMA and place the new d's and e's in a qd array. */
  887. /* This might need to be done for several blocks */
  888. i1 = i0;
  889. n1 = n0;
  890. L145:
  891. tempq = z__[(i0 << 2) - 3];
  892. z__[(i0 << 2) - 3] += sigma;
  893. i__2 = n0;
  894. for (k = i0 + 1; k <= i__2; ++k) {
  895. tempe = z__[(k << 2) - 5];
  896. z__[(k << 2) - 5] *= tempq / z__[(k << 2) - 7];
  897. tempq = z__[(k << 2) - 3];
  898. z__[(k << 2) - 3] = z__[(k << 2) - 3] + sigma + tempe - z__[(k <<
  899. 2) - 5];
  900. }
  901. /* Prepare to do this on the previous block if there is one */
  902. if (i1 > 1) {
  903. n1 = i1 - 1;
  904. while(i1 >= 2 && z__[(i1 << 2) - 5] >= 0.) {
  905. --i1;
  906. }
  907. sigma = -z__[(n1 << 2) - 1];
  908. goto L145;
  909. }
  910. i__2 = *n;
  911. for (k = 1; k <= i__2; ++k) {
  912. z__[(k << 1) - 1] = z__[(k << 2) - 3];
  913. /* Only the block 1..N0 is unfinished. The rest of the e's */
  914. /* must be essentially zero, although sometimes other data */
  915. /* has been stored in them. */
  916. if (k < n0) {
  917. z__[k * 2] = z__[(k << 2) - 1];
  918. } else {
  919. z__[k * 2] = 0.;
  920. }
  921. }
  922. return 0;
  923. /* end IWHILB */
  924. L150:
  925. /* L160: */
  926. ;
  927. }
  928. *info = 3;
  929. return 0;
  930. /* end IWHILA */
  931. L170:
  932. /* Move q's to the front. */
  933. i__1 = *n;
  934. for (k = 2; k <= i__1; ++k) {
  935. z__[k] = z__[(k << 2) - 3];
  936. /* L180: */
  937. }
  938. /* Sort and compute sum of eigenvalues. */
  939. dlasrt_("D", n, &z__[1], &iinfo);
  940. e = 0.;
  941. for (k = *n; k >= 1; --k) {
  942. e += z__[k];
  943. /* L190: */
  944. }
  945. /* Store trace, sum(eigenvalues) and information on performance. */
  946. z__[(*n << 1) + 1] = trace;
  947. z__[(*n << 1) + 2] = e;
  948. z__[(*n << 1) + 3] = (doublereal) iter;
  949. /* Computing 2nd power */
  950. i__1 = *n;
  951. z__[(*n << 1) + 4] = (doublereal) ndiv / (doublereal) (i__1 * i__1);
  952. z__[(*n << 1) + 5] = nfail * 100. / (doublereal) iter;
  953. return 0;
  954. /* End of DLASQ2 */
  955. } /* dlasq2_ */