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.

slaed2.c 28 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  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 real c_b3 = -1.f;
  381. static integer c__1 = 1;
  382. /* > \brief \b SLAED2 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 SLAED2 + dependencies */
  389. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slaed2.
  390. f"> */
  391. /* > [TGZ]</a> */
  392. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slaed2.
  393. f"> */
  394. /* > [ZIP]</a> */
  395. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slaed2.
  396. f"> */
  397. /* > [TXT]</a> */
  398. /* > \endhtmlonly */
  399. /* Definition: */
  400. /* =========== */
  401. /* SUBROUTINE SLAED2( 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. /* REAL RHO */
  405. /* INTEGER COLTYP( * ), INDX( * ), INDXC( * ), INDXP( * ), */
  406. /* $ INDXQ( * ) */
  407. /* REAL D( * ), DLAMDA( * ), Q( LDQ, * ), Q2( * ), */
  408. /* $ W( * ), Z( * ) */
  409. /* > \par Purpose: */
  410. /* ============= */
  411. /* > */
  412. /* > \verbatim */
  413. /* > */
  414. /* > SLAED2 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 REAL 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 REAL 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 REAL */
  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. /* > SLAED3. */
  485. /* > \endverbatim */
  486. /* > */
  487. /* > \param[in] Z */
  488. /* > \verbatim */
  489. /* > Z is REAL 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 REAL array, dimension (N) */
  500. /* > A copy of the first K eigenvalues which will be used by */
  501. /* > SLAED3 to form the secular equation. */
  502. /* > \endverbatim */
  503. /* > */
  504. /* > \param[out] W */
  505. /* > \verbatim */
  506. /* > W is REAL array, dimension (N) */
  507. /* > The first k values of the final deflation-altered z-vector */
  508. /* > which will be passed to SLAED3. */
  509. /* > \endverbatim */
  510. /* > */
  511. /* > \param[out] Q2 */
  512. /* > \verbatim */
  513. /* > Q2 is REAL array, dimension (N1**2+(N-N1)**2) */
  514. /* > A copy of the first K eigenvectors which will be used by */
  515. /* > SLAED3 in a matrix multiply (SGEMM) 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 slaed2_(integer *k, integer *n, integer *n1, real *d__,
  579. real *q, integer *ldq, integer *indxq, real *rho, real *z__, real *
  580. dlamda, real *w, real *q2, integer *indx, integer *indxc, integer *
  581. indxp, integer *coltyp, integer *info)
  582. {
  583. /* System generated locals */
  584. integer q_dim1, q_offset, i__1, i__2;
  585. real r__1, r__2, r__3, r__4;
  586. /* Local variables */
  587. integer imax, jmax, ctot[4];
  588. extern /* Subroutine */ int srot_(integer *, real *, integer *, real *,
  589. integer *, real *, real *);
  590. real c__;
  591. integer i__, j;
  592. real s, t;
  593. extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
  594. integer k2;
  595. extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *,
  596. integer *);
  597. integer n2;
  598. extern real slapy2_(real *, real *);
  599. integer ct, nj, pj, js;
  600. extern real slamch_(char *);
  601. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  602. extern integer isamax_(integer *, real *, integer *);
  603. extern /* Subroutine */ int slamrg_(integer *, integer *, real *, integer
  604. *, integer *, integer *), slacpy_(char *, integer *, integer *,
  605. real *, integer *, real *, integer *);
  606. integer iq1, iq2, n1p1;
  607. real eps, tau, tol;
  608. integer psm[4];
  609. /* -- LAPACK computational routine (version 3.7.0) -- */
  610. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  611. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  612. /* December 2016 */
  613. /* ===================================================================== */
  614. /* Test the input parameters. */
  615. /* Parameter adjustments */
  616. --d__;
  617. q_dim1 = *ldq;
  618. q_offset = 1 + q_dim1 * 1;
  619. q -= q_offset;
  620. --indxq;
  621. --z__;
  622. --dlamda;
  623. --w;
  624. --q2;
  625. --indx;
  626. --indxc;
  627. --indxp;
  628. --coltyp;
  629. /* Function Body */
  630. *info = 0;
  631. if (*n < 0) {
  632. *info = -2;
  633. } else if (*ldq < f2cmax(1,*n)) {
  634. *info = -6;
  635. } else /* if(complicated condition) */ {
  636. /* Computing MIN */
  637. i__1 = 1, i__2 = *n / 2;
  638. if (f2cmin(i__1,i__2) > *n1 || *n / 2 < *n1) {
  639. *info = -3;
  640. }
  641. }
  642. if (*info != 0) {
  643. i__1 = -(*info);
  644. xerbla_("SLAED2", &i__1, (ftnlen)6);
  645. return 0;
  646. }
  647. /* Quick return if possible */
  648. if (*n == 0) {
  649. return 0;
  650. }
  651. n2 = *n - *n1;
  652. n1p1 = *n1 + 1;
  653. if (*rho < 0.f) {
  654. sscal_(&n2, &c_b3, &z__[n1p1], &c__1);
  655. }
  656. /* Normalize z so that norm(z) = 1. Since z is the concatenation of */
  657. /* two normalized vectors, norm2(z) = sqrt(2). */
  658. t = 1.f / sqrt(2.f);
  659. sscal_(n, &t, &z__[1], &c__1);
  660. /* RHO = ABS( norm(z)**2 * RHO ) */
  661. *rho = (r__1 = *rho * 2.f, abs(r__1));
  662. /* Sort the eigenvalues into increasing order */
  663. i__1 = *n;
  664. for (i__ = n1p1; i__ <= i__1; ++i__) {
  665. indxq[i__] += *n1;
  666. /* L10: */
  667. }
  668. /* re-integrate the deflated parts from the last pass */
  669. i__1 = *n;
  670. for (i__ = 1; i__ <= i__1; ++i__) {
  671. dlamda[i__] = d__[indxq[i__]];
  672. /* L20: */
  673. }
  674. slamrg_(n1, &n2, &dlamda[1], &c__1, &c__1, &indxc[1]);
  675. i__1 = *n;
  676. for (i__ = 1; i__ <= i__1; ++i__) {
  677. indx[i__] = indxq[indxc[i__]];
  678. /* L30: */
  679. }
  680. /* Calculate the allowable deflation tolerance */
  681. imax = isamax_(n, &z__[1], &c__1);
  682. jmax = isamax_(n, &d__[1], &c__1);
  683. eps = slamch_("Epsilon");
  684. /* Computing MAX */
  685. r__3 = (r__1 = d__[jmax], abs(r__1)), r__4 = (r__2 = z__[imax], abs(r__2))
  686. ;
  687. tol = eps * 8.f * f2cmax(r__3,r__4);
  688. /* If the rank-1 modifier is small enough, no more needs to be done */
  689. /* except to reorganize Q so that its columns correspond with the */
  690. /* elements in D. */
  691. if (*rho * (r__1 = z__[imax], abs(r__1)) <= tol) {
  692. *k = 0;
  693. iq2 = 1;
  694. i__1 = *n;
  695. for (j = 1; j <= i__1; ++j) {
  696. i__ = indx[j];
  697. scopy_(n, &q[i__ * q_dim1 + 1], &c__1, &q2[iq2], &c__1);
  698. dlamda[j] = d__[i__];
  699. iq2 += *n;
  700. /* L40: */
  701. }
  702. slacpy_("A", n, n, &q2[1], n, &q[q_offset], ldq);
  703. scopy_(n, &dlamda[1], &c__1, &d__[1], &c__1);
  704. goto L190;
  705. }
  706. /* If there are multiple eigenvalues then the problem deflates. Here */
  707. /* the number of equal eigenvalues are found. As each equal */
  708. /* eigenvalue is found, an elementary reflector is computed to rotate */
  709. /* the corresponding eigensubspace so that the corresponding */
  710. /* components of Z are zero in this new basis. */
  711. i__1 = *n1;
  712. for (i__ = 1; i__ <= i__1; ++i__) {
  713. coltyp[i__] = 1;
  714. /* L50: */
  715. }
  716. i__1 = *n;
  717. for (i__ = n1p1; i__ <= i__1; ++i__) {
  718. coltyp[i__] = 3;
  719. /* L60: */
  720. }
  721. *k = 0;
  722. k2 = *n + 1;
  723. i__1 = *n;
  724. for (j = 1; j <= i__1; ++j) {
  725. nj = indx[j];
  726. if (*rho * (r__1 = z__[nj], abs(r__1)) <= tol) {
  727. /* Deflate due to small z component. */
  728. --k2;
  729. coltyp[nj] = 4;
  730. indxp[k2] = nj;
  731. if (j == *n) {
  732. goto L100;
  733. }
  734. } else {
  735. pj = nj;
  736. goto L80;
  737. }
  738. /* L70: */
  739. }
  740. L80:
  741. ++j;
  742. nj = indx[j];
  743. if (j > *n) {
  744. goto L100;
  745. }
  746. if (*rho * (r__1 = z__[nj], abs(r__1)) <= tol) {
  747. /* Deflate due to small z component. */
  748. --k2;
  749. coltyp[nj] = 4;
  750. indxp[k2] = nj;
  751. } else {
  752. /* Check if eigenvalues are close enough to allow deflation. */
  753. s = z__[pj];
  754. c__ = z__[nj];
  755. /* Find sqrt(a**2+b**2) without overflow or */
  756. /* destructive underflow. */
  757. tau = slapy2_(&c__, &s);
  758. t = d__[nj] - d__[pj];
  759. c__ /= tau;
  760. s = -s / tau;
  761. if ((r__1 = t * c__ * s, abs(r__1)) <= tol) {
  762. /* Deflation is possible. */
  763. z__[nj] = tau;
  764. z__[pj] = 0.f;
  765. if (coltyp[nj] != coltyp[pj]) {
  766. coltyp[nj] = 2;
  767. }
  768. coltyp[pj] = 4;
  769. srot_(n, &q[pj * q_dim1 + 1], &c__1, &q[nj * q_dim1 + 1], &c__1, &
  770. c__, &s);
  771. /* Computing 2nd power */
  772. r__1 = c__;
  773. /* Computing 2nd power */
  774. r__2 = s;
  775. t = d__[pj] * (r__1 * r__1) + d__[nj] * (r__2 * r__2);
  776. /* Computing 2nd power */
  777. r__1 = s;
  778. /* Computing 2nd power */
  779. r__2 = c__;
  780. d__[nj] = d__[pj] * (r__1 * r__1) + d__[nj] * (r__2 * r__2);
  781. d__[pj] = t;
  782. --k2;
  783. i__ = 1;
  784. L90:
  785. if (k2 + i__ <= *n) {
  786. if (d__[pj] < d__[indxp[k2 + i__]]) {
  787. indxp[k2 + i__ - 1] = indxp[k2 + i__];
  788. indxp[k2 + i__] = pj;
  789. ++i__;
  790. goto L90;
  791. } else {
  792. indxp[k2 + i__ - 1] = pj;
  793. }
  794. } else {
  795. indxp[k2 + i__ - 1] = pj;
  796. }
  797. pj = nj;
  798. } else {
  799. ++(*k);
  800. dlamda[*k] = d__[pj];
  801. w[*k] = z__[pj];
  802. indxp[*k] = pj;
  803. pj = nj;
  804. }
  805. }
  806. goto L80;
  807. L100:
  808. /* Record the last eigenvalue. */
  809. ++(*k);
  810. dlamda[*k] = d__[pj];
  811. w[*k] = z__[pj];
  812. indxp[*k] = pj;
  813. /* Count up the total number of the various types of columns, then */
  814. /* form a permutation which positions the four column types into */
  815. /* four uniform groups (although one or more of these groups may be */
  816. /* empty). */
  817. for (j = 1; j <= 4; ++j) {
  818. ctot[j - 1] = 0;
  819. /* L110: */
  820. }
  821. i__1 = *n;
  822. for (j = 1; j <= i__1; ++j) {
  823. ct = coltyp[j];
  824. ++ctot[ct - 1];
  825. /* L120: */
  826. }
  827. /* PSM(*) = Position in SubMatrix (of types 1 through 4) */
  828. psm[0] = 1;
  829. psm[1] = ctot[0] + 1;
  830. psm[2] = psm[1] + ctot[1];
  831. psm[3] = psm[2] + ctot[2];
  832. *k = *n - ctot[3];
  833. /* Fill out the INDXC array so that the permutation which it induces */
  834. /* will place all type-1 columns first, all type-2 columns next, */
  835. /* then all type-3's, and finally all type-4's. */
  836. i__1 = *n;
  837. for (j = 1; j <= i__1; ++j) {
  838. js = indxp[j];
  839. ct = coltyp[js];
  840. indx[psm[ct - 1]] = js;
  841. indxc[psm[ct - 1]] = j;
  842. ++psm[ct - 1];
  843. /* L130: */
  844. }
  845. /* Sort the eigenvalues and corresponding eigenvectors into DLAMDA */
  846. /* and Q2 respectively. The eigenvalues/vectors which were not */
  847. /* deflated go into the first K slots of DLAMDA and Q2 respectively, */
  848. /* while those which were deflated go into the last N - K slots. */
  849. i__ = 1;
  850. iq1 = 1;
  851. iq2 = (ctot[0] + ctot[1]) * *n1 + 1;
  852. i__1 = ctot[0];
  853. for (j = 1; j <= i__1; ++j) {
  854. js = indx[i__];
  855. scopy_(n1, &q[js * q_dim1 + 1], &c__1, &q2[iq1], &c__1);
  856. z__[i__] = d__[js];
  857. ++i__;
  858. iq1 += *n1;
  859. /* L140: */
  860. }
  861. i__1 = ctot[1];
  862. for (j = 1; j <= i__1; ++j) {
  863. js = indx[i__];
  864. scopy_(n1, &q[js * q_dim1 + 1], &c__1, &q2[iq1], &c__1);
  865. scopy_(&n2, &q[*n1 + 1 + js * q_dim1], &c__1, &q2[iq2], &c__1);
  866. z__[i__] = d__[js];
  867. ++i__;
  868. iq1 += *n1;
  869. iq2 += n2;
  870. /* L150: */
  871. }
  872. i__1 = ctot[2];
  873. for (j = 1; j <= i__1; ++j) {
  874. js = indx[i__];
  875. scopy_(&n2, &q[*n1 + 1 + js * q_dim1], &c__1, &q2[iq2], &c__1);
  876. z__[i__] = d__[js];
  877. ++i__;
  878. iq2 += n2;
  879. /* L160: */
  880. }
  881. iq1 = iq2;
  882. i__1 = ctot[3];
  883. for (j = 1; j <= i__1; ++j) {
  884. js = indx[i__];
  885. scopy_(n, &q[js * q_dim1 + 1], &c__1, &q2[iq2], &c__1);
  886. iq2 += *n;
  887. z__[i__] = d__[js];
  888. ++i__;
  889. /* L170: */
  890. }
  891. /* The deflated eigenvalues and their corresponding vectors go back */
  892. /* into the last N - K slots of D and Q respectively. */
  893. if (*k < *n) {
  894. slacpy_("A", n, &ctot[3], &q2[iq1], n, &q[(*k + 1) * q_dim1 + 1], ldq);
  895. i__1 = *n - *k;
  896. scopy_(&i__1, &z__[*k + 1], &c__1, &d__[*k + 1], &c__1);
  897. }
  898. /* Copy CTOT into COLTYP for referencing in SLAED3. */
  899. for (j = 1; j <= 4; ++j) {
  900. coltyp[j] = ctot[j - 1];
  901. /* L180: */
  902. }
  903. L190:
  904. return 0;
  905. /* End of SLAED2 */
  906. } /* slaed2_ */