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.

dlaed2.c 28 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  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_b3 = -1.;
  381. static integer c__1 = 1;
  382. /* > \brief \b DLAED2 used by sstedc. Merges eigenvalues and deflates secular equation. Used when the original
  383. matrix is tridiagonal. */
  384. /* =========== DOCUMENTATION =========== */
  385. /* Online html documentation available at */
  386. /* http://www.netlib.org/lapack/explore-html/ */
  387. /* > \htmlonly */
  388. /* > Download DLAED2 + dependencies */
  389. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlaed2.
  390. f"> */
  391. /* > [TGZ]</a> */
  392. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlaed2.
  393. f"> */
  394. /* > [ZIP]</a> */
  395. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlaed2.
  396. f"> */
  397. /* > [TXT]</a> */
  398. /* > \endhtmlonly */
  399. /* Definition: */
  400. /* =========== */
  401. /* SUBROUTINE DLAED2( K, N, N1, D, Q, LDQ, INDXQ, RHO, Z, DLAMDA, W, */
  402. /* Q2, INDX, INDXC, INDXP, COLTYP, INFO ) */
  403. /* INTEGER INFO, K, LDQ, N, N1 */
  404. /* DOUBLE PRECISION RHO */
  405. /* INTEGER COLTYP( * ), INDX( * ), INDXC( * ), INDXP( * ), */
  406. /* $ INDXQ( * ) */
  407. /* DOUBLE PRECISION D( * ), DLAMDA( * ), Q( LDQ, * ), Q2( * ), */
  408. /* $ W( * ), Z( * ) */
  409. /* > \par Purpose: */
  410. /* ============= */
  411. /* > */
  412. /* > \verbatim */
  413. /* > */
  414. /* > DLAED2 merges the two sets of eigenvalues together into a single */
  415. /* > sorted set. Then it tries to deflate the size of the problem. */
  416. /* > There are two ways in which deflation can occur: when two or more */
  417. /* > eigenvalues are close together or if there is a tiny entry in the */
  418. /* > Z vector. For each such occurrence the order of the related secular */
  419. /* > equation problem is reduced by one. */
  420. /* > \endverbatim */
  421. /* Arguments: */
  422. /* ========== */
  423. /* > \param[out] K */
  424. /* > \verbatim */
  425. /* > K is INTEGER */
  426. /* > The number of non-deflated eigenvalues, and the order of the */
  427. /* > related secular equation. 0 <= K <=N. */
  428. /* > \endverbatim */
  429. /* > */
  430. /* > \param[in] N */
  431. /* > \verbatim */
  432. /* > N is INTEGER */
  433. /* > The dimension of the symmetric tridiagonal matrix. N >= 0. */
  434. /* > \endverbatim */
  435. /* > */
  436. /* > \param[in] N1 */
  437. /* > \verbatim */
  438. /* > N1 is INTEGER */
  439. /* > The location of the last eigenvalue in the leading sub-matrix. */
  440. /* > f2cmin(1,N) <= N1 <= N/2. */
  441. /* > \endverbatim */
  442. /* > */
  443. /* > \param[in,out] D */
  444. /* > \verbatim */
  445. /* > D is DOUBLE PRECISION array, dimension (N) */
  446. /* > On entry, D contains the eigenvalues of the two submatrices to */
  447. /* > be combined. */
  448. /* > On exit, D contains the trailing (N-K) updated eigenvalues */
  449. /* > (those which were deflated) sorted into increasing order. */
  450. /* > \endverbatim */
  451. /* > */
  452. /* > \param[in,out] Q */
  453. /* > \verbatim */
  454. /* > Q is DOUBLE PRECISION array, dimension (LDQ, N) */
  455. /* > On entry, Q contains the eigenvectors of two submatrices in */
  456. /* > the two square blocks with corners at (1,1), (N1,N1) */
  457. /* > and (N1+1, N1+1), (N,N). */
  458. /* > On exit, Q contains the trailing (N-K) updated eigenvectors */
  459. /* > (those which were deflated) in its last N-K columns. */
  460. /* > \endverbatim */
  461. /* > */
  462. /* > \param[in] LDQ */
  463. /* > \verbatim */
  464. /* > LDQ is INTEGER */
  465. /* > The leading dimension of the array Q. LDQ >= f2cmax(1,N). */
  466. /* > \endverbatim */
  467. /* > */
  468. /* > \param[in,out] INDXQ */
  469. /* > \verbatim */
  470. /* > INDXQ is INTEGER array, dimension (N) */
  471. /* > The permutation which separately sorts the two sub-problems */
  472. /* > in D into ascending order. Note that elements in the second */
  473. /* > half of this permutation must first have N1 added to their */
  474. /* > values. Destroyed on exit. */
  475. /* > \endverbatim */
  476. /* > */
  477. /* > \param[in,out] RHO */
  478. /* > \verbatim */
  479. /* > RHO is DOUBLE PRECISION */
  480. /* > On entry, the off-diagonal element associated with the rank-1 */
  481. /* > cut which originally split the two submatrices which are now */
  482. /* > being recombined. */
  483. /* > On exit, RHO has been modified to the value required by */
  484. /* > DLAED3. */
  485. /* > \endverbatim */
  486. /* > */
  487. /* > \param[in] Z */
  488. /* > \verbatim */
  489. /* > Z is DOUBLE PRECISION array, dimension (N) */
  490. /* > On entry, Z contains the updating vector (the last */
  491. /* > row of the first sub-eigenvector matrix and the first row of */
  492. /* > the second sub-eigenvector matrix). */
  493. /* > On exit, the contents of Z have been destroyed by the updating */
  494. /* > process. */
  495. /* > \endverbatim */
  496. /* > */
  497. /* > \param[out] DLAMDA */
  498. /* > \verbatim */
  499. /* > DLAMDA is DOUBLE PRECISION array, dimension (N) */
  500. /* > A copy of the first K eigenvalues which will be used by */
  501. /* > DLAED3 to form the secular equation. */
  502. /* > \endverbatim */
  503. /* > */
  504. /* > \param[out] W */
  505. /* > \verbatim */
  506. /* > W is DOUBLE PRECISION array, dimension (N) */
  507. /* > The first k values of the final deflation-altered z-vector */
  508. /* > which will be passed to DLAED3. */
  509. /* > \endverbatim */
  510. /* > */
  511. /* > \param[out] Q2 */
  512. /* > \verbatim */
  513. /* > Q2 is DOUBLE PRECISION array, dimension (N1**2+(N-N1)**2) */
  514. /* > A copy of the first K eigenvectors which will be used by */
  515. /* > DLAED3 in a matrix multiply (DGEMM) to solve for the new */
  516. /* > eigenvectors. */
  517. /* > \endverbatim */
  518. /* > */
  519. /* > \param[out] INDX */
  520. /* > \verbatim */
  521. /* > INDX is INTEGER array, dimension (N) */
  522. /* > The permutation used to sort the contents of DLAMDA into */
  523. /* > ascending order. */
  524. /* > \endverbatim */
  525. /* > */
  526. /* > \param[out] INDXC */
  527. /* > \verbatim */
  528. /* > INDXC is INTEGER array, dimension (N) */
  529. /* > The permutation used to arrange the columns of the deflated */
  530. /* > Q matrix into three groups: the first group contains non-zero */
  531. /* > elements only at and above N1, the second contains */
  532. /* > non-zero elements only below N1, and the third is dense. */
  533. /* > \endverbatim */
  534. /* > */
  535. /* > \param[out] INDXP */
  536. /* > \verbatim */
  537. /* > INDXP is INTEGER array, dimension (N) */
  538. /* > The permutation used to place deflated values of D at the end */
  539. /* > of the array. INDXP(1:K) points to the nondeflated D-values */
  540. /* > and INDXP(K+1:N) points to the deflated eigenvalues. */
  541. /* > \endverbatim */
  542. /* > */
  543. /* > \param[out] COLTYP */
  544. /* > \verbatim */
  545. /* > COLTYP is INTEGER array, dimension (N) */
  546. /* > During execution, a label which will indicate which of the */
  547. /* > following types a column in the Q2 matrix is: */
  548. /* > 1 : non-zero in the upper half only; */
  549. /* > 2 : dense; */
  550. /* > 3 : non-zero in the lower half only; */
  551. /* > 4 : deflated. */
  552. /* > On exit, COLTYP(i) is the number of columns of type i, */
  553. /* > for i=1 to 4 only. */
  554. /* > \endverbatim */
  555. /* > */
  556. /* > \param[out] INFO */
  557. /* > \verbatim */
  558. /* > INFO is INTEGER */
  559. /* > = 0: successful exit. */
  560. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  561. /* > \endverbatim */
  562. /* Authors: */
  563. /* ======== */
  564. /* > \author Univ. of Tennessee */
  565. /* > \author Univ. of California Berkeley */
  566. /* > \author Univ. of Colorado Denver */
  567. /* > \author NAG Ltd. */
  568. /* > \date December 2016 */
  569. /* > \ingroup auxOTHERcomputational */
  570. /* > \par Contributors: */
  571. /* ================== */
  572. /* > */
  573. /* > Jeff Rutter, Computer Science Division, University of California */
  574. /* > at Berkeley, USA \n */
  575. /* > Modified by Francoise Tisseur, University of Tennessee */
  576. /* > */
  577. /* ===================================================================== */
  578. /* Subroutine */ int dlaed2_(integer *k, integer *n, integer *n1, doublereal *
  579. d__, doublereal *q, integer *ldq, integer *indxq, doublereal *rho,
  580. doublereal *z__, doublereal *dlamda, doublereal *w, doublereal *q2,
  581. integer *indx, integer *indxc, integer *indxp, integer *coltyp,
  582. integer *info)
  583. {
  584. /* System generated locals */
  585. integer q_dim1, q_offset, i__1, i__2;
  586. doublereal d__1, d__2, d__3, d__4;
  587. /* Local variables */
  588. integer imax, jmax;
  589. extern /* Subroutine */ int drot_(integer *, doublereal *, integer *,
  590. doublereal *, integer *, doublereal *, doublereal *);
  591. integer ctot[4];
  592. doublereal c__;
  593. integer i__, j;
  594. doublereal s, t;
  595. extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
  596. integer *), dcopy_(integer *, doublereal *, integer *, doublereal
  597. *, integer *);
  598. integer k2, n2;
  599. extern doublereal dlapy2_(doublereal *, doublereal *);
  600. integer ct, nj;
  601. extern doublereal dlamch_(char *);
  602. integer pj, js;
  603. extern integer idamax_(integer *, doublereal *, integer *);
  604. extern /* Subroutine */ int dlamrg_(integer *, integer *, doublereal *,
  605. integer *, integer *, integer *), dlacpy_(char *, integer *,
  606. integer *, doublereal *, integer *, doublereal *, integer *), xerbla_(char *, integer *, ftnlen);
  607. integer iq1, iq2, n1p1;
  608. doublereal eps, tau, tol;
  609. integer psm[4];
  610. /* -- LAPACK computational routine (version 3.7.0) -- */
  611. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  612. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  613. /* December 2016 */
  614. /* ===================================================================== */
  615. /* Test the input parameters. */
  616. /* Parameter adjustments */
  617. --d__;
  618. q_dim1 = *ldq;
  619. q_offset = 1 + q_dim1 * 1;
  620. q -= q_offset;
  621. --indxq;
  622. --z__;
  623. --dlamda;
  624. --w;
  625. --q2;
  626. --indx;
  627. --indxc;
  628. --indxp;
  629. --coltyp;
  630. /* Function Body */
  631. *info = 0;
  632. if (*n < 0) {
  633. *info = -2;
  634. } else if (*ldq < f2cmax(1,*n)) {
  635. *info = -6;
  636. } else /* if(complicated condition) */ {
  637. /* Computing MIN */
  638. i__1 = 1, i__2 = *n / 2;
  639. if (f2cmin(i__1,i__2) > *n1 || *n / 2 < *n1) {
  640. *info = -3;
  641. }
  642. }
  643. if (*info != 0) {
  644. i__1 = -(*info);
  645. xerbla_("DLAED2", &i__1, (ftnlen)6);
  646. return 0;
  647. }
  648. /* Quick return if possible */
  649. if (*n == 0) {
  650. return 0;
  651. }
  652. n2 = *n - *n1;
  653. n1p1 = *n1 + 1;
  654. if (*rho < 0.) {
  655. dscal_(&n2, &c_b3, &z__[n1p1], &c__1);
  656. }
  657. /* Normalize z so that norm(z) = 1. Since z is the concatenation of */
  658. /* two normalized vectors, norm2(z) = sqrt(2). */
  659. t = 1. / sqrt(2.);
  660. dscal_(n, &t, &z__[1], &c__1);
  661. /* RHO = ABS( norm(z)**2 * RHO ) */
  662. *rho = (d__1 = *rho * 2., abs(d__1));
  663. /* Sort the eigenvalues into increasing order */
  664. i__1 = *n;
  665. for (i__ = n1p1; i__ <= i__1; ++i__) {
  666. indxq[i__] += *n1;
  667. /* L10: */
  668. }
  669. /* re-integrate the deflated parts from the last pass */
  670. i__1 = *n;
  671. for (i__ = 1; i__ <= i__1; ++i__) {
  672. dlamda[i__] = d__[indxq[i__]];
  673. /* L20: */
  674. }
  675. dlamrg_(n1, &n2, &dlamda[1], &c__1, &c__1, &indxc[1]);
  676. i__1 = *n;
  677. for (i__ = 1; i__ <= i__1; ++i__) {
  678. indx[i__] = indxq[indxc[i__]];
  679. /* L30: */
  680. }
  681. /* Calculate the allowable deflation tolerance */
  682. imax = idamax_(n, &z__[1], &c__1);
  683. jmax = idamax_(n, &d__[1], &c__1);
  684. eps = dlamch_("Epsilon");
  685. /* Computing MAX */
  686. d__3 = (d__1 = d__[jmax], abs(d__1)), d__4 = (d__2 = z__[imax], abs(d__2))
  687. ;
  688. tol = eps * 8. * f2cmax(d__3,d__4);
  689. /* If the rank-1 modifier is small enough, no more needs to be done */
  690. /* except to reorganize Q so that its columns correspond with the */
  691. /* elements in D. */
  692. if (*rho * (d__1 = z__[imax], abs(d__1)) <= tol) {
  693. *k = 0;
  694. iq2 = 1;
  695. i__1 = *n;
  696. for (j = 1; j <= i__1; ++j) {
  697. i__ = indx[j];
  698. dcopy_(n, &q[i__ * q_dim1 + 1], &c__1, &q2[iq2], &c__1);
  699. dlamda[j] = d__[i__];
  700. iq2 += *n;
  701. /* L40: */
  702. }
  703. dlacpy_("A", n, n, &q2[1], n, &q[q_offset], ldq);
  704. dcopy_(n, &dlamda[1], &c__1, &d__[1], &c__1);
  705. goto L190;
  706. }
  707. /* If there are multiple eigenvalues then the problem deflates. Here */
  708. /* the number of equal eigenvalues are found. As each equal */
  709. /* eigenvalue is found, an elementary reflector is computed to rotate */
  710. /* the corresponding eigensubspace so that the corresponding */
  711. /* components of Z are zero in this new basis. */
  712. i__1 = *n1;
  713. for (i__ = 1; i__ <= i__1; ++i__) {
  714. coltyp[i__] = 1;
  715. /* L50: */
  716. }
  717. i__1 = *n;
  718. for (i__ = n1p1; i__ <= i__1; ++i__) {
  719. coltyp[i__] = 3;
  720. /* L60: */
  721. }
  722. *k = 0;
  723. k2 = *n + 1;
  724. i__1 = *n;
  725. for (j = 1; j <= i__1; ++j) {
  726. nj = indx[j];
  727. if (*rho * (d__1 = z__[nj], abs(d__1)) <= tol) {
  728. /* Deflate due to small z component. */
  729. --k2;
  730. coltyp[nj] = 4;
  731. indxp[k2] = nj;
  732. if (j == *n) {
  733. goto L100;
  734. }
  735. } else {
  736. pj = nj;
  737. goto L80;
  738. }
  739. /* L70: */
  740. }
  741. L80:
  742. ++j;
  743. nj = indx[j];
  744. if (j > *n) {
  745. goto L100;
  746. }
  747. if (*rho * (d__1 = z__[nj], abs(d__1)) <= tol) {
  748. /* Deflate due to small z component. */
  749. --k2;
  750. coltyp[nj] = 4;
  751. indxp[k2] = nj;
  752. } else {
  753. /* Check if eigenvalues are close enough to allow deflation. */
  754. s = z__[pj];
  755. c__ = z__[nj];
  756. /* Find sqrt(a**2+b**2) without overflow or */
  757. /* destructive underflow. */
  758. tau = dlapy2_(&c__, &s);
  759. t = d__[nj] - d__[pj];
  760. c__ /= tau;
  761. s = -s / tau;
  762. if ((d__1 = t * c__ * s, abs(d__1)) <= tol) {
  763. /* Deflation is possible. */
  764. z__[nj] = tau;
  765. z__[pj] = 0.;
  766. if (coltyp[nj] != coltyp[pj]) {
  767. coltyp[nj] = 2;
  768. }
  769. coltyp[pj] = 4;
  770. drot_(n, &q[pj * q_dim1 + 1], &c__1, &q[nj * q_dim1 + 1], &c__1, &
  771. c__, &s);
  772. /* Computing 2nd power */
  773. d__1 = c__;
  774. /* Computing 2nd power */
  775. d__2 = s;
  776. t = d__[pj] * (d__1 * d__1) + d__[nj] * (d__2 * d__2);
  777. /* Computing 2nd power */
  778. d__1 = s;
  779. /* Computing 2nd power */
  780. d__2 = c__;
  781. d__[nj] = d__[pj] * (d__1 * d__1) + d__[nj] * (d__2 * d__2);
  782. d__[pj] = t;
  783. --k2;
  784. i__ = 1;
  785. L90:
  786. if (k2 + i__ <= *n) {
  787. if (d__[pj] < d__[indxp[k2 + i__]]) {
  788. indxp[k2 + i__ - 1] = indxp[k2 + i__];
  789. indxp[k2 + i__] = pj;
  790. ++i__;
  791. goto L90;
  792. } else {
  793. indxp[k2 + i__ - 1] = pj;
  794. }
  795. } else {
  796. indxp[k2 + i__ - 1] = pj;
  797. }
  798. pj = nj;
  799. } else {
  800. ++(*k);
  801. dlamda[*k] = d__[pj];
  802. w[*k] = z__[pj];
  803. indxp[*k] = pj;
  804. pj = nj;
  805. }
  806. }
  807. goto L80;
  808. L100:
  809. /* Record the last eigenvalue. */
  810. ++(*k);
  811. dlamda[*k] = d__[pj];
  812. w[*k] = z__[pj];
  813. indxp[*k] = pj;
  814. /* Count up the total number of the various types of columns, then */
  815. /* form a permutation which positions the four column types into */
  816. /* four uniform groups (although one or more of these groups may be */
  817. /* empty). */
  818. for (j = 1; j <= 4; ++j) {
  819. ctot[j - 1] = 0;
  820. /* L110: */
  821. }
  822. i__1 = *n;
  823. for (j = 1; j <= i__1; ++j) {
  824. ct = coltyp[j];
  825. ++ctot[ct - 1];
  826. /* L120: */
  827. }
  828. /* PSM(*) = Position in SubMatrix (of types 1 through 4) */
  829. psm[0] = 1;
  830. psm[1] = ctot[0] + 1;
  831. psm[2] = psm[1] + ctot[1];
  832. psm[3] = psm[2] + ctot[2];
  833. *k = *n - ctot[3];
  834. /* Fill out the INDXC array so that the permutation which it induces */
  835. /* will place all type-1 columns first, all type-2 columns next, */
  836. /* then all type-3's, and finally all type-4's. */
  837. i__1 = *n;
  838. for (j = 1; j <= i__1; ++j) {
  839. js = indxp[j];
  840. ct = coltyp[js];
  841. indx[psm[ct - 1]] = js;
  842. indxc[psm[ct - 1]] = j;
  843. ++psm[ct - 1];
  844. /* L130: */
  845. }
  846. /* Sort the eigenvalues and corresponding eigenvectors into DLAMDA */
  847. /* and Q2 respectively. The eigenvalues/vectors which were not */
  848. /* deflated go into the first K slots of DLAMDA and Q2 respectively, */
  849. /* while those which were deflated go into the last N - K slots. */
  850. i__ = 1;
  851. iq1 = 1;
  852. iq2 = (ctot[0] + ctot[1]) * *n1 + 1;
  853. i__1 = ctot[0];
  854. for (j = 1; j <= i__1; ++j) {
  855. js = indx[i__];
  856. dcopy_(n1, &q[js * q_dim1 + 1], &c__1, &q2[iq1], &c__1);
  857. z__[i__] = d__[js];
  858. ++i__;
  859. iq1 += *n1;
  860. /* L140: */
  861. }
  862. i__1 = ctot[1];
  863. for (j = 1; j <= i__1; ++j) {
  864. js = indx[i__];
  865. dcopy_(n1, &q[js * q_dim1 + 1], &c__1, &q2[iq1], &c__1);
  866. dcopy_(&n2, &q[*n1 + 1 + js * q_dim1], &c__1, &q2[iq2], &c__1);
  867. z__[i__] = d__[js];
  868. ++i__;
  869. iq1 += *n1;
  870. iq2 += n2;
  871. /* L150: */
  872. }
  873. i__1 = ctot[2];
  874. for (j = 1; j <= i__1; ++j) {
  875. js = indx[i__];
  876. dcopy_(&n2, &q[*n1 + 1 + js * q_dim1], &c__1, &q2[iq2], &c__1);
  877. z__[i__] = d__[js];
  878. ++i__;
  879. iq2 += n2;
  880. /* L160: */
  881. }
  882. iq1 = iq2;
  883. i__1 = ctot[3];
  884. for (j = 1; j <= i__1; ++j) {
  885. js = indx[i__];
  886. dcopy_(n, &q[js * q_dim1 + 1], &c__1, &q2[iq2], &c__1);
  887. iq2 += *n;
  888. z__[i__] = d__[js];
  889. ++i__;
  890. /* L170: */
  891. }
  892. /* The deflated eigenvalues and their corresponding vectors go back */
  893. /* into the last N - K slots of D and Q respectively. */
  894. if (*k < *n) {
  895. dlacpy_("A", n, &ctot[3], &q2[iq1], n, &q[(*k + 1) * q_dim1 + 1], ldq);
  896. i__1 = *n - *k;
  897. dcopy_(&i__1, &z__[*k + 1], &c__1, &d__[*k + 1], &c__1);
  898. }
  899. /* Copy CTOT into COLTYP for referencing in DLAED3. */
  900. for (j = 1; j <= 4; ++j) {
  901. coltyp[j] = ctot[j - 1];
  902. /* L180: */
  903. }
  904. L190:
  905. return 0;
  906. /* End of DLAED2 */
  907. } /* dlaed2_ */