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.

dlasyf_rk.c 46 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <complex.h>
  6. #ifdef complex
  7. #undef complex
  8. #endif
  9. #ifdef I
  10. #undef I
  11. #endif
  12. #if defined(_WIN64)
  13. typedef long long BLASLONG;
  14. typedef unsigned long long BLASULONG;
  15. #else
  16. typedef long BLASLONG;
  17. typedef unsigned long BLASULONG;
  18. #endif
  19. #ifdef LAPACK_ILP64
  20. typedef BLASLONG blasint;
  21. #if defined(_WIN64)
  22. #define blasabs(x) llabs(x)
  23. #else
  24. #define blasabs(x) labs(x)
  25. #endif
  26. #else
  27. typedef int blasint;
  28. #define blasabs(x) abs(x)
  29. #endif
  30. typedef blasint integer;
  31. typedef unsigned int uinteger;
  32. typedef char *address;
  33. typedef short int shortint;
  34. typedef float real;
  35. typedef double doublereal;
  36. typedef struct { real r, i; } complex;
  37. typedef struct { doublereal r, i; } doublecomplex;
  38. #ifdef _MSC_VER
  39. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  40. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  41. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  42. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  43. #else
  44. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  47. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  48. #endif
  49. #define pCf(z) (*_pCf(z))
  50. #define pCd(z) (*_pCd(z))
  51. typedef blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  172. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  217. #define pow_si(B,E) spow_ui(*(B),*(E))
  218. #define pow_ri(B,E) spow_ui(*(B),*(E))
  219. #define pow_di(B,E) dpow_ui(*(B),*(E))
  220. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  221. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  222. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  223. #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++ = ' '; }
  224. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  225. #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]; }
  226. #define sig_die(s, kill) { exit(1); }
  227. #define s_stop(s, n) {exit(0);}
  228. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  229. #define z_abs(z) (cabs(Cd(z)))
  230. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  231. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  232. #define myexit_() break;
  233. #define mycycle() continue;
  234. #define myceiling(w) {ceil(w)}
  235. #define myhuge(w) {HUGE_VAL}
  236. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  237. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  238. /* procedure parameter types for -A and -C++ */
  239. #ifdef __cplusplus
  240. typedef logical (*L_fp)(...);
  241. #else
  242. typedef logical (*L_fp)();
  243. #endif
  244. static float spow_ui(float x, integer n) {
  245. float pow=1.0; unsigned long int u;
  246. if(n != 0) {
  247. if(n < 0) n = -n, x = 1/x;
  248. for(u = n; ; ) {
  249. if(u & 01) pow *= x;
  250. if(u >>= 1) x *= x;
  251. else break;
  252. }
  253. }
  254. return pow;
  255. }
  256. static double dpow_ui(double x, integer n) {
  257. double pow=1.0; unsigned long int u;
  258. if(n != 0) {
  259. if(n < 0) n = -n, x = 1/x;
  260. for(u = n; ; ) {
  261. if(u & 01) pow *= x;
  262. if(u >>= 1) x *= x;
  263. else break;
  264. }
  265. }
  266. return pow;
  267. }
  268. #ifdef _MSC_VER
  269. static _Fcomplex cpow_ui(complex x, integer n) {
  270. complex pow={1.0,0.0}; unsigned long int u;
  271. if(n != 0) {
  272. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  273. for(u = n; ; ) {
  274. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  275. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  276. else break;
  277. }
  278. }
  279. _Fcomplex p={pow.r, pow.i};
  280. return p;
  281. }
  282. #else
  283. static _Complex float cpow_ui(_Complex float x, integer n) {
  284. _Complex float pow=1.0; unsigned long int u;
  285. if(n != 0) {
  286. if(n < 0) n = -n, x = 1/x;
  287. for(u = n; ; ) {
  288. if(u & 01) pow *= x;
  289. if(u >>= 1) x *= x;
  290. else break;
  291. }
  292. }
  293. return pow;
  294. }
  295. #endif
  296. #ifdef _MSC_VER
  297. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  298. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  299. if(n != 0) {
  300. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  301. for(u = n; ; ) {
  302. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  303. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  304. else break;
  305. }
  306. }
  307. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  308. return p;
  309. }
  310. #else
  311. static _Complex double zpow_ui(_Complex double x, integer n) {
  312. _Complex double pow=1.0; unsigned long int u;
  313. if(n != 0) {
  314. if(n < 0) n = -n, x = 1/x;
  315. for(u = n; ; ) {
  316. if(u & 01) pow *= x;
  317. if(u >>= 1) x *= x;
  318. else break;
  319. }
  320. }
  321. return pow;
  322. }
  323. #endif
  324. static integer pow_ii(integer x, integer n) {
  325. integer pow; unsigned long int u;
  326. if (n <= 0) {
  327. if (n == 0 || x == 1) pow = 1;
  328. else if (x != -1) pow = x == 0 ? 1/x : 0;
  329. else n = -n;
  330. }
  331. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  332. u = n;
  333. for(pow = 1; ; ) {
  334. if(u & 01) pow *= x;
  335. if(u >>= 1) x *= x;
  336. else break;
  337. }
  338. }
  339. return pow;
  340. }
  341. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  342. {
  343. double m; integer i, mi;
  344. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  345. if (w[i-1]>m) mi=i ,m=w[i-1];
  346. return mi-s+1;
  347. }
  348. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  349. {
  350. float m; integer i, mi;
  351. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  352. if (w[i-1]>m) mi=i ,m=w[i-1];
  353. return mi-s+1;
  354. }
  355. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  356. integer n = *n_, incx = *incx_, incy = *incy_, i;
  357. #ifdef _MSC_VER
  358. _Fcomplex zdotc = {0.0, 0.0};
  359. if (incx == 1 && incy == 1) {
  360. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  361. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  362. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  363. }
  364. } else {
  365. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  366. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  367. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  368. }
  369. }
  370. pCf(z) = zdotc;
  371. }
  372. #else
  373. _Complex float zdotc = 0.0;
  374. if (incx == 1 && incy == 1) {
  375. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  376. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  377. }
  378. } else {
  379. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  380. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  381. }
  382. }
  383. pCf(z) = zdotc;
  384. }
  385. #endif
  386. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  387. integer n = *n_, incx = *incx_, incy = *incy_, i;
  388. #ifdef _MSC_VER
  389. _Dcomplex zdotc = {0.0, 0.0};
  390. if (incx == 1 && incy == 1) {
  391. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  392. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  393. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  394. }
  395. } else {
  396. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  397. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  398. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  399. }
  400. }
  401. pCd(z) = zdotc;
  402. }
  403. #else
  404. _Complex double zdotc = 0.0;
  405. if (incx == 1 && incy == 1) {
  406. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  407. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  408. }
  409. } else {
  410. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  411. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  412. }
  413. }
  414. pCd(z) = zdotc;
  415. }
  416. #endif
  417. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  418. integer n = *n_, incx = *incx_, incy = *incy_, i;
  419. #ifdef _MSC_VER
  420. _Fcomplex zdotc = {0.0, 0.0};
  421. if (incx == 1 && incy == 1) {
  422. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  423. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  424. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  425. }
  426. } else {
  427. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  428. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  429. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  430. }
  431. }
  432. pCf(z) = zdotc;
  433. }
  434. #else
  435. _Complex float zdotc = 0.0;
  436. if (incx == 1 && incy == 1) {
  437. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  438. zdotc += Cf(&x[i]) * Cf(&y[i]);
  439. }
  440. } else {
  441. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  442. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  443. }
  444. }
  445. pCf(z) = zdotc;
  446. }
  447. #endif
  448. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  449. integer n = *n_, incx = *incx_, incy = *incy_, i;
  450. #ifdef _MSC_VER
  451. _Dcomplex zdotc = {0.0, 0.0};
  452. if (incx == 1 && incy == 1) {
  453. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  454. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  455. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  456. }
  457. } else {
  458. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  459. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  460. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  461. }
  462. }
  463. pCd(z) = zdotc;
  464. }
  465. #else
  466. _Complex double zdotc = 0.0;
  467. if (incx == 1 && incy == 1) {
  468. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  469. zdotc += Cd(&x[i]) * Cd(&y[i]);
  470. }
  471. } else {
  472. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  473. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  474. }
  475. }
  476. pCd(z) = zdotc;
  477. }
  478. #endif
  479. /* -- translated by f2c (version 20000121).
  480. You must link the resulting object file with the libraries:
  481. -lf2c -lm (in that order)
  482. */
  483. /* Table of constant values */
  484. static integer c__1 = 1;
  485. static doublereal c_b9 = -1.;
  486. static doublereal c_b10 = 1.;
  487. /* > \brief \b DLASYF_RK computes a partial factorization of a real symmetric indefinite matrix using bounded
  488. Bunch-Kaufman (rook) diagonal pivoting method. */
  489. /* =========== DOCUMENTATION =========== */
  490. /* Online html documentation available at */
  491. /* http://www.netlib.org/lapack/explore-html/ */
  492. /* > \htmlonly */
  493. /* > Download DLASYF_RK + dependencies */
  494. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlasyf_
  495. rk.f"> */
  496. /* > [TGZ]</a> */
  497. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlasyf_
  498. rk.f"> */
  499. /* > [ZIP]</a> */
  500. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlasyf_
  501. rk.f"> */
  502. /* > [TXT]</a> */
  503. /* > \endhtmlonly */
  504. /* Definition: */
  505. /* =========== */
  506. /* SUBROUTINE DLASYF_RK( UPLO, N, NB, KB, A, LDA, E, IPIV, W, LDW, */
  507. /* INFO ) */
  508. /* CHARACTER UPLO */
  509. /* INTEGER INFO, KB, LDA, LDW, N, NB */
  510. /* INTEGER IPIV( * ) */
  511. /* DOUBLE PRECISION A( LDA, * ), E( * ), W( LDW, * ) */
  512. /* > \par Purpose: */
  513. /* ============= */
  514. /* > */
  515. /* > \verbatim */
  516. /* > DLASYF_RK computes a partial factorization of a real symmetric */
  517. /* > matrix A using the bounded Bunch-Kaufman (rook) diagonal */
  518. /* > pivoting method. The partial factorization has the form: */
  519. /* > */
  520. /* > A = ( I U12 ) ( A11 0 ) ( I 0 ) if UPLO = 'U', or: */
  521. /* > ( 0 U22 ) ( 0 D ) ( U12**T U22**T ) */
  522. /* > */
  523. /* > A = ( L11 0 ) ( D 0 ) ( L11**T L21**T ) if UPLO = 'L', */
  524. /* > ( L21 I ) ( 0 A22 ) ( 0 I ) */
  525. /* > */
  526. /* > where the order of D is at most NB. The actual order is returned in */
  527. /* > the argument KB, and is either NB or NB-1, or N if N <= NB. */
  528. /* > */
  529. /* > DLASYF_RK is an auxiliary routine called by DSYTRF_RK. It uses */
  530. /* > blocked code (calling Level 3 BLAS) to update the submatrix */
  531. /* > A11 (if UPLO = 'U') or A22 (if UPLO = 'L'). */
  532. /* > \endverbatim */
  533. /* Arguments: */
  534. /* ========== */
  535. /* > \param[in] UPLO */
  536. /* > \verbatim */
  537. /* > UPLO is CHARACTER*1 */
  538. /* > Specifies whether the upper or lower triangular part of the */
  539. /* > symmetric matrix A is stored: */
  540. /* > = 'U': Upper triangular */
  541. /* > = 'L': Lower triangular */
  542. /* > \endverbatim */
  543. /* > */
  544. /* > \param[in] N */
  545. /* > \verbatim */
  546. /* > N is INTEGER */
  547. /* > The order of the matrix A. N >= 0. */
  548. /* > \endverbatim */
  549. /* > */
  550. /* > \param[in] NB */
  551. /* > \verbatim */
  552. /* > NB is INTEGER */
  553. /* > The maximum number of columns of the matrix A that should be */
  554. /* > factored. NB should be at least 2 to allow for 2-by-2 pivot */
  555. /* > blocks. */
  556. /* > \endverbatim */
  557. /* > */
  558. /* > \param[out] KB */
  559. /* > \verbatim */
  560. /* > KB is INTEGER */
  561. /* > The number of columns of A that were actually factored. */
  562. /* > KB is either NB-1 or NB, or N if N <= NB. */
  563. /* > \endverbatim */
  564. /* > */
  565. /* > \param[in,out] A */
  566. /* > \verbatim */
  567. /* > A is DOUBLE PRECISION array, dimension (LDA,N) */
  568. /* > On entry, the symmetric matrix A. */
  569. /* > If UPLO = 'U': the leading N-by-N upper triangular part */
  570. /* > of A contains the upper triangular part of the matrix A, */
  571. /* > and the strictly lower triangular part of A is not */
  572. /* > referenced. */
  573. /* > */
  574. /* > If UPLO = 'L': the leading N-by-N lower triangular part */
  575. /* > of A contains the lower triangular part of the matrix A, */
  576. /* > and the strictly upper triangular part of A is not */
  577. /* > referenced. */
  578. /* > */
  579. /* > On exit, contains: */
  580. /* > a) ONLY diagonal elements of the symmetric block diagonal */
  581. /* > matrix D on the diagonal of A, i.e. D(k,k) = A(k,k); */
  582. /* > (superdiagonal (or subdiagonal) elements of D */
  583. /* > are stored on exit in array E), and */
  584. /* > b) If UPLO = 'U': factor U in the superdiagonal part of A. */
  585. /* > If UPLO = 'L': factor L in the subdiagonal part of A. */
  586. /* > \endverbatim */
  587. /* > */
  588. /* > \param[in] LDA */
  589. /* > \verbatim */
  590. /* > LDA is INTEGER */
  591. /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
  592. /* > \endverbatim */
  593. /* > */
  594. /* > \param[out] E */
  595. /* > \verbatim */
  596. /* > E is DOUBLE PRECISION array, dimension (N) */
  597. /* > On exit, contains the superdiagonal (or subdiagonal) */
  598. /* > elements of the symmetric block diagonal matrix D */
  599. /* > with 1-by-1 or 2-by-2 diagonal blocks, where */
  600. /* > If UPLO = 'U': E(i) = D(i-1,i), i=2:N, E(1) is set to 0; */
  601. /* > If UPLO = 'L': E(i) = D(i+1,i), i=1:N-1, E(N) is set to 0. */
  602. /* > */
  603. /* > NOTE: For 1-by-1 diagonal block D(k), where */
  604. /* > 1 <= k <= N, the element E(k) is set to 0 in both */
  605. /* > UPLO = 'U' or UPLO = 'L' cases. */
  606. /* > \endverbatim */
  607. /* > */
  608. /* > \param[out] IPIV */
  609. /* > \verbatim */
  610. /* > IPIV is INTEGER array, dimension (N) */
  611. /* > IPIV describes the permutation matrix P in the factorization */
  612. /* > of matrix A as follows. The absolute value of IPIV(k) */
  613. /* > represents the index of row and column that were */
  614. /* > interchanged with the k-th row and column. The value of UPLO */
  615. /* > describes the order in which the interchanges were applied. */
  616. /* > Also, the sign of IPIV represents the block structure of */
  617. /* > the symmetric block diagonal matrix D with 1-by-1 or 2-by-2 */
  618. /* > diagonal blocks which correspond to 1 or 2 interchanges */
  619. /* > at each factorization step. */
  620. /* > */
  621. /* > If UPLO = 'U', */
  622. /* > ( in factorization order, k decreases from N to 1 ): */
  623. /* > a) A single positive entry IPIV(k) > 0 means: */
  624. /* > D(k,k) is a 1-by-1 diagonal block. */
  625. /* > If IPIV(k) != k, rows and columns k and IPIV(k) were */
  626. /* > interchanged in the submatrix A(1:N,N-KB+1:N); */
  627. /* > If IPIV(k) = k, no interchange occurred. */
  628. /* > */
  629. /* > */
  630. /* > b) A pair of consecutive negative entries */
  631. /* > IPIV(k) < 0 and IPIV(k-1) < 0 means: */
  632. /* > D(k-1:k,k-1:k) is a 2-by-2 diagonal block. */
  633. /* > (NOTE: negative entries in IPIV appear ONLY in pairs). */
  634. /* > 1) If -IPIV(k) != k, rows and columns */
  635. /* > k and -IPIV(k) were interchanged */
  636. /* > in the matrix A(1:N,N-KB+1:N). */
  637. /* > If -IPIV(k) = k, no interchange occurred. */
  638. /* > 2) If -IPIV(k-1) != k-1, rows and columns */
  639. /* > k-1 and -IPIV(k-1) were interchanged */
  640. /* > in the submatrix A(1:N,N-KB+1:N). */
  641. /* > If -IPIV(k-1) = k-1, no interchange occurred. */
  642. /* > */
  643. /* > c) In both cases a) and b) is always ABS( IPIV(k) ) <= k. */
  644. /* > */
  645. /* > d) NOTE: Any entry IPIV(k) is always NONZERO on output. */
  646. /* > */
  647. /* > If UPLO = 'L', */
  648. /* > ( in factorization order, k increases from 1 to N ): */
  649. /* > a) A single positive entry IPIV(k) > 0 means: */
  650. /* > D(k,k) is a 1-by-1 diagonal block. */
  651. /* > If IPIV(k) != k, rows and columns k and IPIV(k) were */
  652. /* > interchanged in the submatrix A(1:N,1:KB). */
  653. /* > If IPIV(k) = k, no interchange occurred. */
  654. /* > */
  655. /* > b) A pair of consecutive negative entries */
  656. /* > IPIV(k) < 0 and IPIV(k+1) < 0 means: */
  657. /* > D(k:k+1,k:k+1) is a 2-by-2 diagonal block. */
  658. /* > (NOTE: negative entries in IPIV appear ONLY in pairs). */
  659. /* > 1) If -IPIV(k) != k, rows and columns */
  660. /* > k and -IPIV(k) were interchanged */
  661. /* > in the submatrix A(1:N,1:KB). */
  662. /* > If -IPIV(k) = k, no interchange occurred. */
  663. /* > 2) If -IPIV(k+1) != k+1, rows and columns */
  664. /* > k-1 and -IPIV(k-1) were interchanged */
  665. /* > in the submatrix A(1:N,1:KB). */
  666. /* > If -IPIV(k+1) = k+1, no interchange occurred. */
  667. /* > */
  668. /* > c) In both cases a) and b) is always ABS( IPIV(k) ) >= k. */
  669. /* > */
  670. /* > d) NOTE: Any entry IPIV(k) is always NONZERO on output. */
  671. /* > \endverbatim */
  672. /* > */
  673. /* > \param[out] W */
  674. /* > \verbatim */
  675. /* > W is DOUBLE PRECISION array, dimension (LDW,NB) */
  676. /* > \endverbatim */
  677. /* > */
  678. /* > \param[in] LDW */
  679. /* > \verbatim */
  680. /* > LDW is INTEGER */
  681. /* > The leading dimension of the array W. LDW >= f2cmax(1,N). */
  682. /* > \endverbatim */
  683. /* > */
  684. /* > \param[out] INFO */
  685. /* > \verbatim */
  686. /* > INFO is INTEGER */
  687. /* > = 0: successful exit */
  688. /* > */
  689. /* > < 0: If INFO = -k, the k-th argument had an illegal value */
  690. /* > */
  691. /* > > 0: If INFO = k, the matrix A is singular, because: */
  692. /* > If UPLO = 'U': column k in the upper */
  693. /* > triangular part of A contains all zeros. */
  694. /* > If UPLO = 'L': column k in the lower */
  695. /* > triangular part of A contains all zeros. */
  696. /* > */
  697. /* > Therefore D(k,k) is exactly zero, and superdiagonal */
  698. /* > elements of column k of U (or subdiagonal elements of */
  699. /* > column k of L ) are all zeros. The factorization has */
  700. /* > been completed, but the block diagonal matrix D is */
  701. /* > exactly singular, and division by zero will occur if */
  702. /* > it is used to solve a system of equations. */
  703. /* > */
  704. /* > NOTE: INFO only stores the first occurrence of */
  705. /* > a singularity, any subsequent occurrence of singularity */
  706. /* > is not stored in INFO even though the factorization */
  707. /* > always completes. */
  708. /* > \endverbatim */
  709. /* Authors: */
  710. /* ======== */
  711. /* > \author Univ. of Tennessee */
  712. /* > \author Univ. of California Berkeley */
  713. /* > \author Univ. of Colorado Denver */
  714. /* > \author NAG Ltd. */
  715. /* > \date December 2016 */
  716. /* > \ingroup doubleSYcomputational */
  717. /* > \par Contributors: */
  718. /* ================== */
  719. /* > */
  720. /* > \verbatim */
  721. /* > */
  722. /* > December 2016, Igor Kozachenko, */
  723. /* > Computer Science Division, */
  724. /* > University of California, Berkeley */
  725. /* > */
  726. /* > September 2007, Sven Hammarling, Nicholas J. Higham, Craig Lucas, */
  727. /* > School of Mathematics, */
  728. /* > University of Manchester */
  729. /* > */
  730. /* > \endverbatim */
  731. /* ===================================================================== */
  732. /* Subroutine */ void dlasyf_rk_(char *uplo, integer *n, integer *nb, integer
  733. *kb, doublereal *a, integer *lda, doublereal *e, integer *ipiv,
  734. doublereal *w, integer *ldw, integer *info)
  735. {
  736. /* System generated locals */
  737. integer a_dim1, a_offset, w_dim1, w_offset, i__1, i__2, i__3, i__4, i__5;
  738. doublereal d__1;
  739. /* Local variables */
  740. logical done;
  741. integer imax, jmax, j, k, p;
  742. doublereal t, alpha;
  743. extern /* Subroutine */ void dscal_(integer *, doublereal *, doublereal *,
  744. integer *), dgemm_(char *, char *, integer *, integer *, integer *
  745. , doublereal *, doublereal *, integer *, doublereal *, integer *,
  746. doublereal *, doublereal *, integer *);
  747. extern logical lsame_(char *, char *);
  748. extern /* Subroutine */ void dgemv_(char *, integer *, integer *,
  749. doublereal *, doublereal *, integer *, doublereal *, integer *,
  750. doublereal *, doublereal *, integer *);
  751. doublereal dtemp, sfmin;
  752. integer itemp;
  753. extern /* Subroutine */ void dcopy_(integer *, doublereal *, integer *,
  754. doublereal *, integer *), dswap_(integer *, doublereal *, integer
  755. *, doublereal *, integer *);
  756. integer kstep;
  757. doublereal r1, d11, d12, d21, d22;
  758. integer jb, ii, jj, kk;
  759. extern doublereal dlamch_(char *);
  760. integer kp;
  761. doublereal absakk;
  762. integer kw;
  763. extern integer idamax_(integer *, doublereal *, integer *);
  764. doublereal colmax, rowmax;
  765. integer kkw;
  766. /* -- LAPACK computational routine (version 3.7.0) -- */
  767. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  768. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  769. /* December 2016 */
  770. /* ===================================================================== */
  771. /* Parameter adjustments */
  772. a_dim1 = *lda;
  773. a_offset = 1 + a_dim1 * 1;
  774. a -= a_offset;
  775. --e;
  776. --ipiv;
  777. w_dim1 = *ldw;
  778. w_offset = 1 + w_dim1 * 1;
  779. w -= w_offset;
  780. /* Function Body */
  781. *info = 0;
  782. /* Initialize ALPHA for use in choosing pivot block size. */
  783. alpha = (sqrt(17.) + 1.) / 8.;
  784. /* Compute machine safe minimum */
  785. sfmin = dlamch_("S");
  786. if (lsame_(uplo, "U")) {
  787. /* Factorize the trailing columns of A using the upper triangle */
  788. /* of A and working backwards, and compute the matrix W = U12*D */
  789. /* for use in updating A11 */
  790. /* Initialize the first entry of array E, where superdiagonal */
  791. /* elements of D are stored */
  792. e[1] = 0.;
  793. /* K is the main loop index, decreasing from N in steps of 1 or 2 */
  794. k = *n;
  795. L10:
  796. /* KW is the column of W which corresponds to column K of A */
  797. kw = *nb + k - *n;
  798. /* Exit from loop */
  799. if (k <= *n - *nb + 1 && *nb < *n || k < 1) {
  800. goto L30;
  801. }
  802. kstep = 1;
  803. p = k;
  804. /* Copy column K of A to column KW of W and update it */
  805. dcopy_(&k, &a[k * a_dim1 + 1], &c__1, &w[kw * w_dim1 + 1], &c__1);
  806. if (k < *n) {
  807. i__1 = *n - k;
  808. dgemv_("No transpose", &k, &i__1, &c_b9, &a[(k + 1) * a_dim1 + 1],
  809. lda, &w[k + (kw + 1) * w_dim1], ldw, &c_b10, &w[kw *
  810. w_dim1 + 1], &c__1);
  811. }
  812. /* Determine rows and columns to be interchanged and whether */
  813. /* a 1-by-1 or 2-by-2 pivot block will be used */
  814. absakk = (d__1 = w[k + kw * w_dim1], abs(d__1));
  815. /* IMAX is the row-index of the largest off-diagonal element in */
  816. /* column K, and COLMAX is its absolute value. */
  817. /* Determine both COLMAX and IMAX. */
  818. if (k > 1) {
  819. i__1 = k - 1;
  820. imax = idamax_(&i__1, &w[kw * w_dim1 + 1], &c__1);
  821. colmax = (d__1 = w[imax + kw * w_dim1], abs(d__1));
  822. } else {
  823. colmax = 0.;
  824. }
  825. if (f2cmax(absakk,colmax) == 0.) {
  826. /* Column K is zero or underflow: set INFO and continue */
  827. if (*info == 0) {
  828. *info = k;
  829. }
  830. kp = k;
  831. dcopy_(&k, &w[kw * w_dim1 + 1], &c__1, &a[k * a_dim1 + 1], &c__1);
  832. /* Set E( K ) to zero */
  833. if (k > 1) {
  834. e[k] = 0.;
  835. }
  836. } else {
  837. /* ============================================================ */
  838. /* Test for interchange */
  839. /* Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX */
  840. /* (used to handle NaN and Inf) */
  841. if (! (absakk < alpha * colmax)) {
  842. /* no interchange, use 1-by-1 pivot block */
  843. kp = k;
  844. } else {
  845. done = FALSE_;
  846. /* Loop until pivot found */
  847. L12:
  848. /* Begin pivot search loop body */
  849. /* Copy column IMAX to column KW-1 of W and update it */
  850. dcopy_(&imax, &a[imax * a_dim1 + 1], &c__1, &w[(kw - 1) *
  851. w_dim1 + 1], &c__1);
  852. i__1 = k - imax;
  853. dcopy_(&i__1, &a[imax + (imax + 1) * a_dim1], lda, &w[imax +
  854. 1 + (kw - 1) * w_dim1], &c__1);
  855. if (k < *n) {
  856. i__1 = *n - k;
  857. dgemv_("No transpose", &k, &i__1, &c_b9, &a[(k + 1) *
  858. a_dim1 + 1], lda, &w[imax + (kw + 1) * w_dim1],
  859. ldw, &c_b10, &w[(kw - 1) * w_dim1 + 1], &c__1);
  860. }
  861. /* JMAX is the column-index of the largest off-diagonal */
  862. /* element in row IMAX, and ROWMAX is its absolute value. */
  863. /* Determine both ROWMAX and JMAX. */
  864. if (imax != k) {
  865. i__1 = k - imax;
  866. jmax = imax + idamax_(&i__1, &w[imax + 1 + (kw - 1) *
  867. w_dim1], &c__1);
  868. rowmax = (d__1 = w[jmax + (kw - 1) * w_dim1], abs(d__1));
  869. } else {
  870. rowmax = 0.;
  871. }
  872. if (imax > 1) {
  873. i__1 = imax - 1;
  874. itemp = idamax_(&i__1, &w[(kw - 1) * w_dim1 + 1], &c__1);
  875. dtemp = (d__1 = w[itemp + (kw - 1) * w_dim1], abs(d__1));
  876. if (dtemp > rowmax) {
  877. rowmax = dtemp;
  878. jmax = itemp;
  879. }
  880. }
  881. /* Equivalent to testing for */
  882. /* ABS( W( IMAX, KW-1 ) ).GE.ALPHA*ROWMAX */
  883. /* (used to handle NaN and Inf) */
  884. if (! ((d__1 = w[imax + (kw - 1) * w_dim1], abs(d__1)) <
  885. alpha * rowmax)) {
  886. /* interchange rows and columns K and IMAX, */
  887. /* use 1-by-1 pivot block */
  888. kp = imax;
  889. /* copy column KW-1 of W to column KW of W */
  890. dcopy_(&k, &w[(kw - 1) * w_dim1 + 1], &c__1, &w[kw *
  891. w_dim1 + 1], &c__1);
  892. done = TRUE_;
  893. /* Equivalent to testing for ROWMAX.EQ.COLMAX, */
  894. /* (used to handle NaN and Inf) */
  895. } else if (p == jmax || rowmax <= colmax) {
  896. /* interchange rows and columns K-1 and IMAX, */
  897. /* use 2-by-2 pivot block */
  898. kp = imax;
  899. kstep = 2;
  900. done = TRUE_;
  901. } else {
  902. /* Pivot not found: set params and repeat */
  903. p = imax;
  904. colmax = rowmax;
  905. imax = jmax;
  906. /* Copy updated JMAXth (next IMAXth) column to Kth of W */
  907. dcopy_(&k, &w[(kw - 1) * w_dim1 + 1], &c__1, &w[kw *
  908. w_dim1 + 1], &c__1);
  909. }
  910. /* End pivot search loop body */
  911. if (! done) {
  912. goto L12;
  913. }
  914. }
  915. /* ============================================================ */
  916. kk = k - kstep + 1;
  917. /* KKW is the column of W which corresponds to column KK of A */
  918. kkw = *nb + kk - *n;
  919. if (kstep == 2 && p != k) {
  920. /* Copy non-updated column K to column P */
  921. i__1 = k - p;
  922. dcopy_(&i__1, &a[p + 1 + k * a_dim1], &c__1, &a[p + (p + 1) *
  923. a_dim1], lda);
  924. dcopy_(&p, &a[k * a_dim1 + 1], &c__1, &a[p * a_dim1 + 1], &
  925. c__1);
  926. /* Interchange rows K and P in last N-K+1 columns of A */
  927. /* and last N-K+2 columns of W */
  928. i__1 = *n - k + 1;
  929. dswap_(&i__1, &a[k + k * a_dim1], lda, &a[p + k * a_dim1],
  930. lda);
  931. i__1 = *n - kk + 1;
  932. dswap_(&i__1, &w[k + kkw * w_dim1], ldw, &w[p + kkw * w_dim1],
  933. ldw);
  934. }
  935. /* Updated column KP is already stored in column KKW of W */
  936. if (kp != kk) {
  937. /* Copy non-updated column KK to column KP */
  938. a[kp + k * a_dim1] = a[kk + k * a_dim1];
  939. i__1 = k - 1 - kp;
  940. dcopy_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + (kp +
  941. 1) * a_dim1], lda);
  942. dcopy_(&kp, &a[kk * a_dim1 + 1], &c__1, &a[kp * a_dim1 + 1], &
  943. c__1);
  944. /* Interchange rows KK and KP in last N-KK+1 columns */
  945. /* of A and W */
  946. i__1 = *n - kk + 1;
  947. dswap_(&i__1, &a[kk + kk * a_dim1], lda, &a[kp + kk * a_dim1],
  948. lda);
  949. i__1 = *n - kk + 1;
  950. dswap_(&i__1, &w[kk + kkw * w_dim1], ldw, &w[kp + kkw *
  951. w_dim1], ldw);
  952. }
  953. if (kstep == 1) {
  954. /* 1-by-1 pivot block D(k): column KW of W now holds */
  955. /* W(k) = U(k)*D(k) */
  956. /* where U(k) is the k-th column of U */
  957. /* Store U(k) in column k of A */
  958. dcopy_(&k, &w[kw * w_dim1 + 1], &c__1, &a[k * a_dim1 + 1], &
  959. c__1);
  960. if (k > 1) {
  961. if ((d__1 = a[k + k * a_dim1], abs(d__1)) >= sfmin) {
  962. r1 = 1. / a[k + k * a_dim1];
  963. i__1 = k - 1;
  964. dscal_(&i__1, &r1, &a[k * a_dim1 + 1], &c__1);
  965. } else if (a[k + k * a_dim1] != 0.) {
  966. i__1 = k - 1;
  967. for (ii = 1; ii <= i__1; ++ii) {
  968. a[ii + k * a_dim1] /= a[k + k * a_dim1];
  969. /* L14: */
  970. }
  971. }
  972. /* Store the superdiagonal element of D in array E */
  973. e[k] = 0.;
  974. }
  975. } else {
  976. /* 2-by-2 pivot block D(k): columns KW and KW-1 of W now */
  977. /* hold */
  978. /* ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k) */
  979. /* where U(k) and U(k-1) are the k-th and (k-1)-th columns */
  980. /* of U */
  981. if (k > 2) {
  982. /* Store U(k) and U(k-1) in columns k and k-1 of A */
  983. d12 = w[k - 1 + kw * w_dim1];
  984. d11 = w[k + kw * w_dim1] / d12;
  985. d22 = w[k - 1 + (kw - 1) * w_dim1] / d12;
  986. t = 1. / (d11 * d22 - 1.);
  987. i__1 = k - 2;
  988. for (j = 1; j <= i__1; ++j) {
  989. a[j + (k - 1) * a_dim1] = t * ((d11 * w[j + (kw - 1) *
  990. w_dim1] - w[j + kw * w_dim1]) / d12);
  991. a[j + k * a_dim1] = t * ((d22 * w[j + kw * w_dim1] -
  992. w[j + (kw - 1) * w_dim1]) / d12);
  993. /* L20: */
  994. }
  995. }
  996. /* Copy diagonal elements of D(K) to A, */
  997. /* copy superdiagonal element of D(K) to E(K) and */
  998. /* ZERO out superdiagonal entry of A */
  999. a[k - 1 + (k - 1) * a_dim1] = w[k - 1 + (kw - 1) * w_dim1];
  1000. a[k - 1 + k * a_dim1] = 0.;
  1001. a[k + k * a_dim1] = w[k + kw * w_dim1];
  1002. e[k] = w[k - 1 + kw * w_dim1];
  1003. e[k - 1] = 0.;
  1004. }
  1005. /* End column K is nonsingular */
  1006. }
  1007. /* Store details of the interchanges in IPIV */
  1008. if (kstep == 1) {
  1009. ipiv[k] = kp;
  1010. } else {
  1011. ipiv[k] = -p;
  1012. ipiv[k - 1] = -kp;
  1013. }
  1014. /* Decrease K and return to the start of the main loop */
  1015. k -= kstep;
  1016. goto L10;
  1017. L30:
  1018. /* Update the upper triangle of A11 (= A(1:k,1:k)) as */
  1019. /* A11 := A11 - U12*D*U12**T = A11 - U12*W**T */
  1020. /* computing blocks of NB columns at a time */
  1021. i__1 = -(*nb);
  1022. for (j = (k - 1) / *nb * *nb + 1; i__1 < 0 ? j >= 1 : j <= 1; j +=
  1023. i__1) {
  1024. /* Computing MIN */
  1025. i__2 = *nb, i__3 = k - j + 1;
  1026. jb = f2cmin(i__2,i__3);
  1027. /* Update the upper triangle of the diagonal block */
  1028. i__2 = j + jb - 1;
  1029. for (jj = j; jj <= i__2; ++jj) {
  1030. i__3 = jj - j + 1;
  1031. i__4 = *n - k;
  1032. dgemv_("No transpose", &i__3, &i__4, &c_b9, &a[j + (k + 1) *
  1033. a_dim1], lda, &w[jj + (kw + 1) * w_dim1], ldw, &c_b10,
  1034. &a[j + jj * a_dim1], &c__1);
  1035. /* L40: */
  1036. }
  1037. /* Update the rectangular superdiagonal block */
  1038. if (j >= 2) {
  1039. i__2 = j - 1;
  1040. i__3 = *n - k;
  1041. dgemm_("No transpose", "Transpose", &i__2, &jb, &i__3, &c_b9,
  1042. &a[(k + 1) * a_dim1 + 1], lda, &w[j + (kw + 1) *
  1043. w_dim1], ldw, &c_b10, &a[j * a_dim1 + 1], lda);
  1044. }
  1045. /* L50: */
  1046. }
  1047. /* Set KB to the number of columns factorized */
  1048. *kb = *n - k;
  1049. } else {
  1050. /* Factorize the leading columns of A using the lower triangle */
  1051. /* of A and working forwards, and compute the matrix W = L21*D */
  1052. /* for use in updating A22 */
  1053. /* Initialize the unused last entry of the subdiagonal array E. */
  1054. e[*n] = 0.;
  1055. /* K is the main loop index, increasing from 1 in steps of 1 or 2 */
  1056. k = 1;
  1057. L70:
  1058. /* Exit from loop */
  1059. if (k >= *nb && *nb < *n || k > *n) {
  1060. goto L90;
  1061. }
  1062. kstep = 1;
  1063. p = k;
  1064. /* Copy column K of A to column K of W and update it */
  1065. i__1 = *n - k + 1;
  1066. dcopy_(&i__1, &a[k + k * a_dim1], &c__1, &w[k + k * w_dim1], &c__1);
  1067. if (k > 1) {
  1068. i__1 = *n - k + 1;
  1069. i__2 = k - 1;
  1070. dgemv_("No transpose", &i__1, &i__2, &c_b9, &a[k + a_dim1], lda, &
  1071. w[k + w_dim1], ldw, &c_b10, &w[k + k * w_dim1], &c__1);
  1072. }
  1073. /* Determine rows and columns to be interchanged and whether */
  1074. /* a 1-by-1 or 2-by-2 pivot block will be used */
  1075. absakk = (d__1 = w[k + k * w_dim1], abs(d__1));
  1076. /* IMAX is the row-index of the largest off-diagonal element in */
  1077. /* column K, and COLMAX is its absolute value. */
  1078. /* Determine both COLMAX and IMAX. */
  1079. if (k < *n) {
  1080. i__1 = *n - k;
  1081. imax = k + idamax_(&i__1, &w[k + 1 + k * w_dim1], &c__1);
  1082. colmax = (d__1 = w[imax + k * w_dim1], abs(d__1));
  1083. } else {
  1084. colmax = 0.;
  1085. }
  1086. if (f2cmax(absakk,colmax) == 0.) {
  1087. /* Column K is zero or underflow: set INFO and continue */
  1088. if (*info == 0) {
  1089. *info = k;
  1090. }
  1091. kp = k;
  1092. i__1 = *n - k + 1;
  1093. dcopy_(&i__1, &w[k + k * w_dim1], &c__1, &a[k + k * a_dim1], &
  1094. c__1);
  1095. /* Set E( K ) to zero */
  1096. if (k < *n) {
  1097. e[k] = 0.;
  1098. }
  1099. } else {
  1100. /* ============================================================ */
  1101. /* Test for interchange */
  1102. /* Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX */
  1103. /* (used to handle NaN and Inf) */
  1104. if (! (absakk < alpha * colmax)) {
  1105. /* no interchange, use 1-by-1 pivot block */
  1106. kp = k;
  1107. } else {
  1108. done = FALSE_;
  1109. /* Loop until pivot found */
  1110. L72:
  1111. /* Begin pivot search loop body */
  1112. /* Copy column IMAX to column K+1 of W and update it */
  1113. i__1 = imax - k;
  1114. dcopy_(&i__1, &a[imax + k * a_dim1], lda, &w[k + (k + 1) *
  1115. w_dim1], &c__1);
  1116. i__1 = *n - imax + 1;
  1117. dcopy_(&i__1, &a[imax + imax * a_dim1], &c__1, &w[imax + (k +
  1118. 1) * w_dim1], &c__1);
  1119. if (k > 1) {
  1120. i__1 = *n - k + 1;
  1121. i__2 = k - 1;
  1122. dgemv_("No transpose", &i__1, &i__2, &c_b9, &a[k + a_dim1]
  1123. , lda, &w[imax + w_dim1], ldw, &c_b10, &w[k + (k
  1124. + 1) * w_dim1], &c__1);
  1125. }
  1126. /* JMAX is the column-index of the largest off-diagonal */
  1127. /* element in row IMAX, and ROWMAX is its absolute value. */
  1128. /* Determine both ROWMAX and JMAX. */
  1129. if (imax != k) {
  1130. i__1 = imax - k;
  1131. jmax = k - 1 + idamax_(&i__1, &w[k + (k + 1) * w_dim1], &
  1132. c__1);
  1133. rowmax = (d__1 = w[jmax + (k + 1) * w_dim1], abs(d__1));
  1134. } else {
  1135. rowmax = 0.;
  1136. }
  1137. if (imax < *n) {
  1138. i__1 = *n - imax;
  1139. itemp = imax + idamax_(&i__1, &w[imax + 1 + (k + 1) *
  1140. w_dim1], &c__1);
  1141. dtemp = (d__1 = w[itemp + (k + 1) * w_dim1], abs(d__1));
  1142. if (dtemp > rowmax) {
  1143. rowmax = dtemp;
  1144. jmax = itemp;
  1145. }
  1146. }
  1147. /* Equivalent to testing for */
  1148. /* ABS( W( IMAX, K+1 ) ).GE.ALPHA*ROWMAX */
  1149. /* (used to handle NaN and Inf) */
  1150. if (! ((d__1 = w[imax + (k + 1) * w_dim1], abs(d__1)) < alpha
  1151. * rowmax)) {
  1152. /* interchange rows and columns K and IMAX, */
  1153. /* use 1-by-1 pivot block */
  1154. kp = imax;
  1155. /* copy column K+1 of W to column K of W */
  1156. i__1 = *n - k + 1;
  1157. dcopy_(&i__1, &w[k + (k + 1) * w_dim1], &c__1, &w[k + k *
  1158. w_dim1], &c__1);
  1159. done = TRUE_;
  1160. /* Equivalent to testing for ROWMAX.EQ.COLMAX, */
  1161. /* (used to handle NaN and Inf) */
  1162. } else if (p == jmax || rowmax <= colmax) {
  1163. /* interchange rows and columns K+1 and IMAX, */
  1164. /* use 2-by-2 pivot block */
  1165. kp = imax;
  1166. kstep = 2;
  1167. done = TRUE_;
  1168. } else {
  1169. /* Pivot not found: set params and repeat */
  1170. p = imax;
  1171. colmax = rowmax;
  1172. imax = jmax;
  1173. /* Copy updated JMAXth (next IMAXth) column to Kth of W */
  1174. i__1 = *n - k + 1;
  1175. dcopy_(&i__1, &w[k + (k + 1) * w_dim1], &c__1, &w[k + k *
  1176. w_dim1], &c__1);
  1177. }
  1178. /* End pivot search loop body */
  1179. if (! done) {
  1180. goto L72;
  1181. }
  1182. }
  1183. /* ============================================================ */
  1184. kk = k + kstep - 1;
  1185. if (kstep == 2 && p != k) {
  1186. /* Copy non-updated column K to column P */
  1187. i__1 = p - k;
  1188. dcopy_(&i__1, &a[k + k * a_dim1], &c__1, &a[p + k * a_dim1],
  1189. lda);
  1190. i__1 = *n - p + 1;
  1191. dcopy_(&i__1, &a[p + k * a_dim1], &c__1, &a[p + p * a_dim1], &
  1192. c__1);
  1193. /* Interchange rows K and P in first K columns of A */
  1194. /* and first K+1 columns of W */
  1195. dswap_(&k, &a[k + a_dim1], lda, &a[p + a_dim1], lda);
  1196. dswap_(&kk, &w[k + w_dim1], ldw, &w[p + w_dim1], ldw);
  1197. }
  1198. /* Updated column KP is already stored in column KK of W */
  1199. if (kp != kk) {
  1200. /* Copy non-updated column KK to column KP */
  1201. a[kp + k * a_dim1] = a[kk + k * a_dim1];
  1202. i__1 = kp - k - 1;
  1203. dcopy_(&i__1, &a[k + 1 + kk * a_dim1], &c__1, &a[kp + (k + 1)
  1204. * a_dim1], lda);
  1205. i__1 = *n - kp + 1;
  1206. dcopy_(&i__1, &a[kp + kk * a_dim1], &c__1, &a[kp + kp *
  1207. a_dim1], &c__1);
  1208. /* Interchange rows KK and KP in first KK columns of A and W */
  1209. dswap_(&kk, &a[kk + a_dim1], lda, &a[kp + a_dim1], lda);
  1210. dswap_(&kk, &w[kk + w_dim1], ldw, &w[kp + w_dim1], ldw);
  1211. }
  1212. if (kstep == 1) {
  1213. /* 1-by-1 pivot block D(k): column k of W now holds */
  1214. /* W(k) = L(k)*D(k) */
  1215. /* where L(k) is the k-th column of L */
  1216. /* Store L(k) in column k of A */
  1217. i__1 = *n - k + 1;
  1218. dcopy_(&i__1, &w[k + k * w_dim1], &c__1, &a[k + k * a_dim1], &
  1219. c__1);
  1220. if (k < *n) {
  1221. if ((d__1 = a[k + k * a_dim1], abs(d__1)) >= sfmin) {
  1222. r1 = 1. / a[k + k * a_dim1];
  1223. i__1 = *n - k;
  1224. dscal_(&i__1, &r1, &a[k + 1 + k * a_dim1], &c__1);
  1225. } else if (a[k + k * a_dim1] != 0.) {
  1226. i__1 = *n;
  1227. for (ii = k + 1; ii <= i__1; ++ii) {
  1228. a[ii + k * a_dim1] /= a[k + k * a_dim1];
  1229. /* L74: */
  1230. }
  1231. }
  1232. /* Store the subdiagonal element of D in array E */
  1233. e[k] = 0.;
  1234. }
  1235. } else {
  1236. /* 2-by-2 pivot block D(k): columns k and k+1 of W now hold */
  1237. /* ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k) */
  1238. /* where L(k) and L(k+1) are the k-th and (k+1)-th columns */
  1239. /* of L */
  1240. if (k < *n - 1) {
  1241. /* Store L(k) and L(k+1) in columns k and k+1 of A */
  1242. d21 = w[k + 1 + k * w_dim1];
  1243. d11 = w[k + 1 + (k + 1) * w_dim1] / d21;
  1244. d22 = w[k + k * w_dim1] / d21;
  1245. t = 1. / (d11 * d22 - 1.);
  1246. i__1 = *n;
  1247. for (j = k + 2; j <= i__1; ++j) {
  1248. a[j + k * a_dim1] = t * ((d11 * w[j + k * w_dim1] - w[
  1249. j + (k + 1) * w_dim1]) / d21);
  1250. a[j + (k + 1) * a_dim1] = t * ((d22 * w[j + (k + 1) *
  1251. w_dim1] - w[j + k * w_dim1]) / d21);
  1252. /* L80: */
  1253. }
  1254. }
  1255. /* Copy diagonal elements of D(K) to A, */
  1256. /* copy subdiagonal element of D(K) to E(K) and */
  1257. /* ZERO out subdiagonal entry of A */
  1258. a[k + k * a_dim1] = w[k + k * w_dim1];
  1259. a[k + 1 + k * a_dim1] = 0.;
  1260. a[k + 1 + (k + 1) * a_dim1] = w[k + 1 + (k + 1) * w_dim1];
  1261. e[k] = w[k + 1 + k * w_dim1];
  1262. e[k + 1] = 0.;
  1263. }
  1264. /* End column K is nonsingular */
  1265. }
  1266. /* Store details of the interchanges in IPIV */
  1267. if (kstep == 1) {
  1268. ipiv[k] = kp;
  1269. } else {
  1270. ipiv[k] = -p;
  1271. ipiv[k + 1] = -kp;
  1272. }
  1273. /* Increase K and return to the start of the main loop */
  1274. k += kstep;
  1275. goto L70;
  1276. L90:
  1277. /* Update the lower triangle of A22 (= A(k:n,k:n)) as */
  1278. /* A22 := A22 - L21*D*L21**T = A22 - L21*W**T */
  1279. /* computing blocks of NB columns at a time */
  1280. i__1 = *n;
  1281. i__2 = *nb;
  1282. for (j = k; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  1283. /* Computing MIN */
  1284. i__3 = *nb, i__4 = *n - j + 1;
  1285. jb = f2cmin(i__3,i__4);
  1286. /* Update the lower triangle of the diagonal block */
  1287. i__3 = j + jb - 1;
  1288. for (jj = j; jj <= i__3; ++jj) {
  1289. i__4 = j + jb - jj;
  1290. i__5 = k - 1;
  1291. dgemv_("No transpose", &i__4, &i__5, &c_b9, &a[jj + a_dim1],
  1292. lda, &w[jj + w_dim1], ldw, &c_b10, &a[jj + jj *
  1293. a_dim1], &c__1);
  1294. /* L100: */
  1295. }
  1296. /* Update the rectangular subdiagonal block */
  1297. if (j + jb <= *n) {
  1298. i__3 = *n - j - jb + 1;
  1299. i__4 = k - 1;
  1300. dgemm_("No transpose", "Transpose", &i__3, &jb, &i__4, &c_b9,
  1301. &a[j + jb + a_dim1], lda, &w[j + w_dim1], ldw, &c_b10,
  1302. &a[j + jb + j * a_dim1], lda);
  1303. }
  1304. /* L110: */
  1305. }
  1306. /* Set KB to the number of columns factorized */
  1307. *kb = k - 1;
  1308. }
  1309. return;
  1310. /* End of DLASYF_RK */
  1311. } /* dlasyf_rk__ */