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.

clasyf.c 43 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443
  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 complex c_b1 = {1.f,0.f};
  381. static integer c__1 = 1;
  382. /* > \brief \b CLASYF computes a partial factorization of a complex symmetric matrix using the Bunch-Kaufman d
  383. iagonal pivoting method. */
  384. /* =========== DOCUMENTATION =========== */
  385. /* Online html documentation available at */
  386. /* http://www.netlib.org/lapack/explore-html/ */
  387. /* > \htmlonly */
  388. /* > Download CLASYF + dependencies */
  389. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clasyf.
  390. f"> */
  391. /* > [TGZ]</a> */
  392. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clasyf.
  393. f"> */
  394. /* > [ZIP]</a> */
  395. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clasyf.
  396. f"> */
  397. /* > [TXT]</a> */
  398. /* > \endhtmlonly */
  399. /* Definition: */
  400. /* =========== */
  401. /* SUBROUTINE CLASYF( UPLO, N, NB, KB, A, LDA, IPIV, W, LDW, INFO ) */
  402. /* CHARACTER UPLO */
  403. /* INTEGER INFO, KB, LDA, LDW, N, NB */
  404. /* INTEGER IPIV( * ) */
  405. /* COMPLEX A( LDA, * ), W( LDW, * ) */
  406. /* > \par Purpose: */
  407. /* ============= */
  408. /* > */
  409. /* > \verbatim */
  410. /* > */
  411. /* > CLASYF computes a partial factorization of a complex symmetric matrix */
  412. /* > A using the Bunch-Kaufman diagonal pivoting method. The partial */
  413. /* > factorization has the form: */
  414. /* > */
  415. /* > A = ( I U12 ) ( A11 0 ) ( I 0 ) if UPLO = 'U', or: */
  416. /* > ( 0 U22 ) ( 0 D ) ( U12**T U22**T ) */
  417. /* > */
  418. /* > A = ( L11 0 ) ( D 0 ) ( L11**T L21**T ) if UPLO = 'L' */
  419. /* > ( L21 I ) ( 0 A22 ) ( 0 I ) */
  420. /* > */
  421. /* > where the order of D is at most NB. The actual order is returned in */
  422. /* > the argument KB, and is either NB or NB-1, or N if N <= NB. */
  423. /* > Note that U**T denotes the transpose of U. */
  424. /* > */
  425. /* > CLASYF is an auxiliary routine called by CSYTRF. It uses blocked code */
  426. /* > (calling Level 3 BLAS) to update the submatrix A11 (if UPLO = 'U') or */
  427. /* > A22 (if UPLO = 'L'). */
  428. /* > \endverbatim */
  429. /* Arguments: */
  430. /* ========== */
  431. /* > \param[in] UPLO */
  432. /* > \verbatim */
  433. /* > UPLO is CHARACTER*1 */
  434. /* > Specifies whether the upper or lower triangular part of the */
  435. /* > symmetric matrix A is stored: */
  436. /* > = 'U': Upper triangular */
  437. /* > = 'L': Lower triangular */
  438. /* > \endverbatim */
  439. /* > */
  440. /* > \param[in] N */
  441. /* > \verbatim */
  442. /* > N is INTEGER */
  443. /* > The order of the matrix A. N >= 0. */
  444. /* > \endverbatim */
  445. /* > */
  446. /* > \param[in] NB */
  447. /* > \verbatim */
  448. /* > NB is INTEGER */
  449. /* > The maximum number of columns of the matrix A that should be */
  450. /* > factored. NB should be at least 2 to allow for 2-by-2 pivot */
  451. /* > blocks. */
  452. /* > \endverbatim */
  453. /* > */
  454. /* > \param[out] KB */
  455. /* > \verbatim */
  456. /* > KB is INTEGER */
  457. /* > The number of columns of A that were actually factored. */
  458. /* > KB is either NB-1 or NB, or N if N <= NB. */
  459. /* > \endverbatim */
  460. /* > */
  461. /* > \param[in,out] A */
  462. /* > \verbatim */
  463. /* > A is COMPLEX array, dimension (LDA,N) */
  464. /* > On entry, the symmetric matrix A. If UPLO = 'U', the leading */
  465. /* > n-by-n upper triangular part of A contains the upper */
  466. /* > triangular part of the matrix A, and the strictly lower */
  467. /* > triangular part of A is not referenced. If UPLO = 'L', the */
  468. /* > leading n-by-n lower triangular part of A contains the lower */
  469. /* > triangular part of the matrix A, and the strictly upper */
  470. /* > triangular part of A is not referenced. */
  471. /* > On exit, A contains details of the partial factorization. */
  472. /* > \endverbatim */
  473. /* > */
  474. /* > \param[in] LDA */
  475. /* > \verbatim */
  476. /* > LDA is INTEGER */
  477. /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
  478. /* > \endverbatim */
  479. /* > */
  480. /* > \param[out] IPIV */
  481. /* > \verbatim */
  482. /* > IPIV is INTEGER array, dimension (N) */
  483. /* > Details of the interchanges and the block structure of D. */
  484. /* > */
  485. /* > If UPLO = 'U': */
  486. /* > Only the last KB elements of IPIV are set. */
  487. /* > */
  488. /* > If IPIV(k) > 0, then rows and columns k and IPIV(k) were */
  489. /* > interchanged and D(k,k) is a 1-by-1 diagonal block. */
  490. /* > */
  491. /* > If IPIV(k) = IPIV(k-1) < 0, then rows and columns */
  492. /* > k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k) */
  493. /* > is a 2-by-2 diagonal block. */
  494. /* > */
  495. /* > If UPLO = 'L': */
  496. /* > Only the first KB elements of IPIV are set. */
  497. /* > */
  498. /* > If IPIV(k) > 0, then rows and columns k and IPIV(k) were */
  499. /* > interchanged and D(k,k) is a 1-by-1 diagonal block. */
  500. /* > */
  501. /* > If IPIV(k) = IPIV(k+1) < 0, then rows and columns */
  502. /* > k+1 and -IPIV(k) were interchanged and D(k:k+1,k:k+1) */
  503. /* > is a 2-by-2 diagonal block. */
  504. /* > \endverbatim */
  505. /* > */
  506. /* > \param[out] W */
  507. /* > \verbatim */
  508. /* > W is COMPLEX array, dimension (LDW,NB) */
  509. /* > \endverbatim */
  510. /* > */
  511. /* > \param[in] LDW */
  512. /* > \verbatim */
  513. /* > LDW is INTEGER */
  514. /* > The leading dimension of the array W. LDW >= f2cmax(1,N). */
  515. /* > \endverbatim */
  516. /* > */
  517. /* > \param[out] INFO */
  518. /* > \verbatim */
  519. /* > INFO is INTEGER */
  520. /* > = 0: successful exit */
  521. /* > > 0: if INFO = k, D(k,k) is exactly zero. The factorization */
  522. /* > has been completed, but the block diagonal matrix D is */
  523. /* > exactly singular. */
  524. /* > \endverbatim */
  525. /* Authors: */
  526. /* ======== */
  527. /* > \author Univ. of Tennessee */
  528. /* > \author Univ. of California Berkeley */
  529. /* > \author Univ. of Colorado Denver */
  530. /* > \author NAG Ltd. */
  531. /* > \date November 2013 */
  532. /* > \ingroup complexSYcomputational */
  533. /* > \par Contributors: */
  534. /* ================== */
  535. /* > */
  536. /* > \verbatim */
  537. /* > */
  538. /* > November 2013, Igor Kozachenko, */
  539. /* > Computer Science Division, */
  540. /* > University of California, Berkeley */
  541. /* > \endverbatim */
  542. /* ===================================================================== */
  543. /* Subroutine */ int clasyf_(char *uplo, integer *n, integer *nb, integer *kb,
  544. complex *a, integer *lda, integer *ipiv, complex *w, integer *ldw,
  545. integer *info)
  546. {
  547. /* System generated locals */
  548. integer a_dim1, a_offset, w_dim1, w_offset, i__1, i__2, i__3, i__4, i__5;
  549. real r__1, r__2, r__3, r__4;
  550. complex q__1, q__2, q__3;
  551. /* Local variables */
  552. integer imax, jmax, j, k;
  553. complex t;
  554. real alpha;
  555. extern /* Subroutine */ int cscal_(integer *, complex *, complex *,
  556. integer *), cgemm_(char *, char *, integer *, integer *, integer *
  557. , complex *, complex *, integer *, complex *, integer *, complex *
  558. , complex *, integer *);
  559. extern logical lsame_(char *, char *);
  560. extern /* Subroutine */ int cgemv_(char *, integer *, integer *, complex *
  561. , complex *, integer *, complex *, integer *, complex *, complex *
  562. , integer *), ccopy_(integer *, complex *, integer *,
  563. complex *, integer *), cswap_(integer *, complex *, integer *,
  564. complex *, integer *);
  565. integer kstep;
  566. complex r1, d11, d21, d22;
  567. integer jb, jj, kk, jp, kp;
  568. real absakk;
  569. integer kw;
  570. extern integer icamax_(integer *, complex *, integer *);
  571. real colmax, rowmax;
  572. integer kkw;
  573. /* -- LAPACK computational routine (version 3.5.0) -- */
  574. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  575. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  576. /* November 2013 */
  577. /* ===================================================================== */
  578. /* Parameter adjustments */
  579. a_dim1 = *lda;
  580. a_offset = 1 + a_dim1 * 1;
  581. a -= a_offset;
  582. --ipiv;
  583. w_dim1 = *ldw;
  584. w_offset = 1 + w_dim1 * 1;
  585. w -= w_offset;
  586. /* Function Body */
  587. *info = 0;
  588. /* Initialize ALPHA for use in choosing pivot block size. */
  589. alpha = (sqrt(17.f) + 1.f) / 8.f;
  590. if (lsame_(uplo, "U")) {
  591. /* Factorize the trailing columns of A using the upper triangle */
  592. /* of A and working backwards, and compute the matrix W = U12*D */
  593. /* for use in updating A11 */
  594. /* K is the main loop index, decreasing from N in steps of 1 or 2 */
  595. /* KW is the column of W which corresponds to column K of A */
  596. k = *n;
  597. L10:
  598. kw = *nb + k - *n;
  599. /* Exit from loop */
  600. if (k <= *n - *nb + 1 && *nb < *n || k < 1) {
  601. goto L30;
  602. }
  603. /* Copy column K of A to column KW of W and update it */
  604. ccopy_(&k, &a[k * a_dim1 + 1], &c__1, &w[kw * w_dim1 + 1], &c__1);
  605. if (k < *n) {
  606. i__1 = *n - k;
  607. q__1.r = -1.f, q__1.i = 0.f;
  608. cgemv_("No transpose", &k, &i__1, &q__1, &a[(k + 1) * a_dim1 + 1],
  609. lda, &w[k + (kw + 1) * w_dim1], ldw, &c_b1, &w[kw *
  610. w_dim1 + 1], &c__1);
  611. }
  612. kstep = 1;
  613. /* Determine rows and columns to be interchanged and whether */
  614. /* a 1-by-1 or 2-by-2 pivot block will be used */
  615. i__1 = k + kw * w_dim1;
  616. absakk = (r__1 = w[i__1].r, abs(r__1)) + (r__2 = r_imag(&w[k + kw *
  617. w_dim1]), abs(r__2));
  618. /* IMAX is the row-index of the largest off-diagonal element in */
  619. /* column K, and COLMAX is its absolute value. */
  620. /* Determine both COLMAX and IMAX. */
  621. if (k > 1) {
  622. i__1 = k - 1;
  623. imax = icamax_(&i__1, &w[kw * w_dim1 + 1], &c__1);
  624. i__1 = imax + kw * w_dim1;
  625. colmax = (r__1 = w[i__1].r, abs(r__1)) + (r__2 = r_imag(&w[imax +
  626. kw * w_dim1]), abs(r__2));
  627. } else {
  628. colmax = 0.f;
  629. }
  630. if (f2cmax(absakk,colmax) == 0.f) {
  631. /* Column K is zero or underflow: set INFO and continue */
  632. if (*info == 0) {
  633. *info = k;
  634. }
  635. kp = k;
  636. } else {
  637. if (absakk >= alpha * colmax) {
  638. /* no interchange, use 1-by-1 pivot block */
  639. kp = k;
  640. } else {
  641. /* Copy column IMAX to column KW-1 of W and update it */
  642. ccopy_(&imax, &a[imax * a_dim1 + 1], &c__1, &w[(kw - 1) *
  643. w_dim1 + 1], &c__1);
  644. i__1 = k - imax;
  645. ccopy_(&i__1, &a[imax + (imax + 1) * a_dim1], lda, &w[imax +
  646. 1 + (kw - 1) * w_dim1], &c__1);
  647. if (k < *n) {
  648. i__1 = *n - k;
  649. q__1.r = -1.f, q__1.i = 0.f;
  650. cgemv_("No transpose", &k, &i__1, &q__1, &a[(k + 1) *
  651. a_dim1 + 1], lda, &w[imax + (kw + 1) * w_dim1],
  652. ldw, &c_b1, &w[(kw - 1) * w_dim1 + 1], &c__1);
  653. }
  654. /* JMAX is the column-index of the largest off-diagonal */
  655. /* element in row IMAX, and ROWMAX is its absolute value */
  656. i__1 = k - imax;
  657. jmax = imax + icamax_(&i__1, &w[imax + 1 + (kw - 1) * w_dim1],
  658. &c__1);
  659. i__1 = jmax + (kw - 1) * w_dim1;
  660. rowmax = (r__1 = w[i__1].r, abs(r__1)) + (r__2 = r_imag(&w[
  661. jmax + (kw - 1) * w_dim1]), abs(r__2));
  662. if (imax > 1) {
  663. i__1 = imax - 1;
  664. jmax = icamax_(&i__1, &w[(kw - 1) * w_dim1 + 1], &c__1);
  665. /* Computing MAX */
  666. i__1 = jmax + (kw - 1) * w_dim1;
  667. r__3 = rowmax, r__4 = (r__1 = w[i__1].r, abs(r__1)) + (
  668. r__2 = r_imag(&w[jmax + (kw - 1) * w_dim1]), abs(
  669. r__2));
  670. rowmax = f2cmax(r__3,r__4);
  671. }
  672. if (absakk >= alpha * colmax * (colmax / rowmax)) {
  673. /* no interchange, use 1-by-1 pivot block */
  674. kp = k;
  675. } else /* if(complicated condition) */ {
  676. i__1 = imax + (kw - 1) * w_dim1;
  677. if ((r__1 = w[i__1].r, abs(r__1)) + (r__2 = r_imag(&w[
  678. imax + (kw - 1) * w_dim1]), abs(r__2)) >= alpha *
  679. rowmax) {
  680. /* interchange rows and columns K and IMAX, use 1-by-1 */
  681. /* pivot block */
  682. kp = imax;
  683. /* copy column KW-1 of W to column KW of W */
  684. ccopy_(&k, &w[(kw - 1) * w_dim1 + 1], &c__1, &w[kw *
  685. w_dim1 + 1], &c__1);
  686. } else {
  687. /* interchange rows and columns K-1 and IMAX, use 2-by-2 */
  688. /* pivot block */
  689. kp = imax;
  690. kstep = 2;
  691. }
  692. }
  693. }
  694. /* ============================================================ */
  695. /* KK is the column of A where pivoting step stopped */
  696. kk = k - kstep + 1;
  697. /* KKW is the column of W which corresponds to column KK of A */
  698. kkw = *nb + kk - *n;
  699. /* Interchange rows and columns KP and KK. */
  700. /* Updated column KP is already stored in column KKW of W. */
  701. if (kp != kk) {
  702. /* Copy non-updated column KK to column KP of submatrix A */
  703. /* at step K. No need to copy element into column K */
  704. /* (or K and K-1 for 2-by-2 pivot) of A, since these columns */
  705. /* will be later overwritten. */
  706. i__1 = kp + kp * a_dim1;
  707. i__2 = kk + kk * a_dim1;
  708. a[i__1].r = a[i__2].r, a[i__1].i = a[i__2].i;
  709. i__1 = kk - 1 - kp;
  710. ccopy_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + (kp +
  711. 1) * a_dim1], lda);
  712. if (kp > 1) {
  713. i__1 = kp - 1;
  714. ccopy_(&i__1, &a[kk * a_dim1 + 1], &c__1, &a[kp * a_dim1
  715. + 1], &c__1);
  716. }
  717. /* Interchange rows KK and KP in last K+1 to N columns of A */
  718. /* (columns K (or K and K-1 for 2-by-2 pivot) of A will be */
  719. /* later overwritten). Interchange rows KK and KP */
  720. /* in last KKW to NB columns of W. */
  721. if (k < *n) {
  722. i__1 = *n - k;
  723. cswap_(&i__1, &a[kk + (k + 1) * a_dim1], lda, &a[kp + (k
  724. + 1) * a_dim1], lda);
  725. }
  726. i__1 = *n - kk + 1;
  727. cswap_(&i__1, &w[kk + kkw * w_dim1], ldw, &w[kp + kkw *
  728. w_dim1], ldw);
  729. }
  730. if (kstep == 1) {
  731. /* 1-by-1 pivot block D(k): column kw of W now holds */
  732. /* W(kw) = U(k)*D(k), */
  733. /* where U(k) is the k-th column of U */
  734. /* Store subdiag. elements of column U(k) */
  735. /* and 1-by-1 block D(k) in column k of A. */
  736. /* NOTE: Diagonal element U(k,k) is a UNIT element */
  737. /* and not stored. */
  738. /* A(k,k) := D(k,k) = W(k,kw) */
  739. /* A(1:k-1,k) := U(1:k-1,k) = W(1:k-1,kw)/D(k,k) */
  740. ccopy_(&k, &w[kw * w_dim1 + 1], &c__1, &a[k * a_dim1 + 1], &
  741. c__1);
  742. c_div(&q__1, &c_b1, &a[k + k * a_dim1]);
  743. r1.r = q__1.r, r1.i = q__1.i;
  744. i__1 = k - 1;
  745. cscal_(&i__1, &r1, &a[k * a_dim1 + 1], &c__1);
  746. } else {
  747. /* 2-by-2 pivot block D(k): columns kw and kw-1 of W now hold */
  748. /* ( W(kw-1) W(kw) ) = ( U(k-1) U(k) )*D(k) */
  749. /* where U(k) and U(k-1) are the k-th and (k-1)-th columns */
  750. /* of U */
  751. /* Store U(1:k-2,k-1) and U(1:k-2,k) and 2-by-2 */
  752. /* block D(k-1:k,k-1:k) in columns k-1 and k of A. */
  753. /* NOTE: 2-by-2 diagonal block U(k-1:k,k-1:k) is a UNIT */
  754. /* block and not stored. */
  755. /* A(k-1:k,k-1:k) := D(k-1:k,k-1:k) = W(k-1:k,kw-1:kw) */
  756. /* A(1:k-2,k-1:k) := U(1:k-2,k:k-1:k) = */
  757. /* = W(1:k-2,kw-1:kw) * ( D(k-1:k,k-1:k)**(-1) ) */
  758. if (k > 2) {
  759. /* Compose the columns of the inverse of 2-by-2 pivot */
  760. /* block D in the following way to reduce the number */
  761. /* of FLOPS when we myltiply panel ( W(kw-1) W(kw) ) by */
  762. /* this inverse */
  763. /* D**(-1) = ( d11 d21 )**(-1) = */
  764. /* ( d21 d22 ) */
  765. /* = 1/(d11*d22-d21**2) * ( ( d22 ) (-d21 ) ) = */
  766. /* ( (-d21 ) ( d11 ) ) */
  767. /* = 1/d21 * 1/((d11/d21)*(d22/d21)-1) * */
  768. /* * ( ( d22/d21 ) ( -1 ) ) = */
  769. /* ( ( -1 ) ( d11/d21 ) ) */
  770. /* = 1/d21 * 1/(D22*D11-1) * ( ( D11 ) ( -1 ) ) = */
  771. /* ( ( -1 ) ( D22 ) ) */
  772. /* = 1/d21 * T * ( ( D11 ) ( -1 ) ) */
  773. /* ( ( -1 ) ( D22 ) ) */
  774. /* = D21 * ( ( D11 ) ( -1 ) ) */
  775. /* ( ( -1 ) ( D22 ) ) */
  776. i__1 = k - 1 + kw * w_dim1;
  777. d21.r = w[i__1].r, d21.i = w[i__1].i;
  778. c_div(&q__1, &w[k + kw * w_dim1], &d21);
  779. d11.r = q__1.r, d11.i = q__1.i;
  780. c_div(&q__1, &w[k - 1 + (kw - 1) * w_dim1], &d21);
  781. d22.r = q__1.r, d22.i = q__1.i;
  782. q__3.r = d11.r * d22.r - d11.i * d22.i, q__3.i = d11.r *
  783. d22.i + d11.i * d22.r;
  784. q__2.r = q__3.r - 1.f, q__2.i = q__3.i + 0.f;
  785. c_div(&q__1, &c_b1, &q__2);
  786. t.r = q__1.r, t.i = q__1.i;
  787. /* Update elements in columns A(k-1) and A(k) as */
  788. /* dot products of rows of ( W(kw-1) W(kw) ) and columns */
  789. /* of D**(-1) */
  790. c_div(&q__1, &t, &d21);
  791. d21.r = q__1.r, d21.i = q__1.i;
  792. i__1 = k - 2;
  793. for (j = 1; j <= i__1; ++j) {
  794. i__2 = j + (k - 1) * a_dim1;
  795. i__3 = j + (kw - 1) * w_dim1;
  796. q__3.r = d11.r * w[i__3].r - d11.i * w[i__3].i,
  797. q__3.i = d11.r * w[i__3].i + d11.i * w[i__3]
  798. .r;
  799. i__4 = j + kw * w_dim1;
  800. q__2.r = q__3.r - w[i__4].r, q__2.i = q__3.i - w[i__4]
  801. .i;
  802. q__1.r = d21.r * q__2.r - d21.i * q__2.i, q__1.i =
  803. d21.r * q__2.i + d21.i * q__2.r;
  804. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  805. i__2 = j + k * a_dim1;
  806. i__3 = j + kw * w_dim1;
  807. q__3.r = d22.r * w[i__3].r - d22.i * w[i__3].i,
  808. q__3.i = d22.r * w[i__3].i + d22.i * w[i__3]
  809. .r;
  810. i__4 = j + (kw - 1) * w_dim1;
  811. q__2.r = q__3.r - w[i__4].r, q__2.i = q__3.i - w[i__4]
  812. .i;
  813. q__1.r = d21.r * q__2.r - d21.i * q__2.i, q__1.i =
  814. d21.r * q__2.i + d21.i * q__2.r;
  815. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  816. /* L20: */
  817. }
  818. }
  819. /* Copy D(k) to A */
  820. i__1 = k - 1 + (k - 1) * a_dim1;
  821. i__2 = k - 1 + (kw - 1) * w_dim1;
  822. a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
  823. i__1 = k - 1 + k * a_dim1;
  824. i__2 = k - 1 + kw * w_dim1;
  825. a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
  826. i__1 = k + k * a_dim1;
  827. i__2 = k + kw * w_dim1;
  828. a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
  829. }
  830. }
  831. /* Store details of the interchanges in IPIV */
  832. if (kstep == 1) {
  833. ipiv[k] = kp;
  834. } else {
  835. ipiv[k] = -kp;
  836. ipiv[k - 1] = -kp;
  837. }
  838. /* Decrease K and return to the start of the main loop */
  839. k -= kstep;
  840. goto L10;
  841. L30:
  842. /* Update the upper triangle of A11 (= A(1:k,1:k)) as */
  843. /* A11 := A11 - U12*D*U12**T = A11 - U12*W**T */
  844. /* computing blocks of NB columns at a time */
  845. i__1 = -(*nb);
  846. for (j = (k - 1) / *nb * *nb + 1; i__1 < 0 ? j >= 1 : j <= 1; j +=
  847. i__1) {
  848. /* Computing MIN */
  849. i__2 = *nb, i__3 = k - j + 1;
  850. jb = f2cmin(i__2,i__3);
  851. /* Update the upper triangle of the diagonal block */
  852. i__2 = j + jb - 1;
  853. for (jj = j; jj <= i__2; ++jj) {
  854. i__3 = jj - j + 1;
  855. i__4 = *n - k;
  856. q__1.r = -1.f, q__1.i = 0.f;
  857. cgemv_("No transpose", &i__3, &i__4, &q__1, &a[j + (k + 1) *
  858. a_dim1], lda, &w[jj + (kw + 1) * w_dim1], ldw, &c_b1,
  859. &a[j + jj * a_dim1], &c__1);
  860. /* L40: */
  861. }
  862. /* Update the rectangular superdiagonal block */
  863. i__2 = j - 1;
  864. i__3 = *n - k;
  865. q__1.r = -1.f, q__1.i = 0.f;
  866. cgemm_("No transpose", "Transpose", &i__2, &jb, &i__3, &q__1, &a[(
  867. k + 1) * a_dim1 + 1], lda, &w[j + (kw + 1) * w_dim1], ldw,
  868. &c_b1, &a[j * a_dim1 + 1], lda);
  869. /* L50: */
  870. }
  871. /* Put U12 in standard form by partially undoing the interchanges */
  872. /* in columns k+1:n looping backwards from k+1 to n */
  873. j = k + 1;
  874. L60:
  875. /* Undo the interchanges (if any) of rows JJ and JP at each */
  876. /* step J */
  877. /* (Here, J is a diagonal index) */
  878. jj = j;
  879. jp = ipiv[j];
  880. if (jp < 0) {
  881. jp = -jp;
  882. /* (Here, J is a diagonal index) */
  883. ++j;
  884. }
  885. /* (NOTE: Here, J is used to determine row length. Length N-J+1 */
  886. /* of the rows to swap back doesn't include diagonal element) */
  887. ++j;
  888. if (jp != jj && j <= *n) {
  889. i__1 = *n - j + 1;
  890. cswap_(&i__1, &a[jp + j * a_dim1], lda, &a[jj + j * a_dim1], lda);
  891. }
  892. if (j < *n) {
  893. goto L60;
  894. }
  895. /* Set KB to the number of columns factorized */
  896. *kb = *n - k;
  897. } else {
  898. /* Factorize the leading columns of A using the lower triangle */
  899. /* of A and working forwards, and compute the matrix W = L21*D */
  900. /* for use in updating A22 */
  901. /* K is the main loop index, increasing from 1 in steps of 1 or 2 */
  902. k = 1;
  903. L70:
  904. /* Exit from loop */
  905. if (k >= *nb && *nb < *n || k > *n) {
  906. goto L90;
  907. }
  908. /* Copy column K of A to column K of W and update it */
  909. i__1 = *n - k + 1;
  910. ccopy_(&i__1, &a[k + k * a_dim1], &c__1, &w[k + k * w_dim1], &c__1);
  911. i__1 = *n - k + 1;
  912. i__2 = k - 1;
  913. q__1.r = -1.f, q__1.i = 0.f;
  914. cgemv_("No transpose", &i__1, &i__2, &q__1, &a[k + a_dim1], lda, &w[k
  915. + w_dim1], ldw, &c_b1, &w[k + k * w_dim1], &c__1);
  916. kstep = 1;
  917. /* Determine rows and columns to be interchanged and whether */
  918. /* a 1-by-1 or 2-by-2 pivot block will be used */
  919. i__1 = k + k * w_dim1;
  920. absakk = (r__1 = w[i__1].r, abs(r__1)) + (r__2 = r_imag(&w[k + k *
  921. w_dim1]), abs(r__2));
  922. /* IMAX is the row-index of the largest off-diagonal element in */
  923. /* column K, and COLMAX is its absolute value. */
  924. /* Determine both COLMAX and IMAX. */
  925. if (k < *n) {
  926. i__1 = *n - k;
  927. imax = k + icamax_(&i__1, &w[k + 1 + k * w_dim1], &c__1);
  928. i__1 = imax + k * w_dim1;
  929. colmax = (r__1 = w[i__1].r, abs(r__1)) + (r__2 = r_imag(&w[imax +
  930. k * w_dim1]), abs(r__2));
  931. } else {
  932. colmax = 0.f;
  933. }
  934. if (f2cmax(absakk,colmax) == 0.f) {
  935. /* Column K is zero or underflow: set INFO and continue */
  936. if (*info == 0) {
  937. *info = k;
  938. }
  939. kp = k;
  940. } else {
  941. if (absakk >= alpha * colmax) {
  942. /* no interchange, use 1-by-1 pivot block */
  943. kp = k;
  944. } else {
  945. /* Copy column IMAX to column K+1 of W and update it */
  946. i__1 = imax - k;
  947. ccopy_(&i__1, &a[imax + k * a_dim1], lda, &w[k + (k + 1) *
  948. w_dim1], &c__1);
  949. i__1 = *n - imax + 1;
  950. ccopy_(&i__1, &a[imax + imax * a_dim1], &c__1, &w[imax + (k +
  951. 1) * w_dim1], &c__1);
  952. i__1 = *n - k + 1;
  953. i__2 = k - 1;
  954. q__1.r = -1.f, q__1.i = 0.f;
  955. cgemv_("No transpose", &i__1, &i__2, &q__1, &a[k + a_dim1],
  956. lda, &w[imax + w_dim1], ldw, &c_b1, &w[k + (k + 1) *
  957. w_dim1], &c__1);
  958. /* JMAX is the column-index of the largest off-diagonal */
  959. /* element in row IMAX, and ROWMAX is its absolute value */
  960. i__1 = imax - k;
  961. jmax = k - 1 + icamax_(&i__1, &w[k + (k + 1) * w_dim1], &c__1)
  962. ;
  963. i__1 = jmax + (k + 1) * w_dim1;
  964. rowmax = (r__1 = w[i__1].r, abs(r__1)) + (r__2 = r_imag(&w[
  965. jmax + (k + 1) * w_dim1]), abs(r__2));
  966. if (imax < *n) {
  967. i__1 = *n - imax;
  968. jmax = imax + icamax_(&i__1, &w[imax + 1 + (k + 1) *
  969. w_dim1], &c__1);
  970. /* Computing MAX */
  971. i__1 = jmax + (k + 1) * w_dim1;
  972. r__3 = rowmax, r__4 = (r__1 = w[i__1].r, abs(r__1)) + (
  973. r__2 = r_imag(&w[jmax + (k + 1) * w_dim1]), abs(
  974. r__2));
  975. rowmax = f2cmax(r__3,r__4);
  976. }
  977. if (absakk >= alpha * colmax * (colmax / rowmax)) {
  978. /* no interchange, use 1-by-1 pivot block */
  979. kp = k;
  980. } else /* if(complicated condition) */ {
  981. i__1 = imax + (k + 1) * w_dim1;
  982. if ((r__1 = w[i__1].r, abs(r__1)) + (r__2 = r_imag(&w[
  983. imax + (k + 1) * w_dim1]), abs(r__2)) >= alpha *
  984. rowmax) {
  985. /* interchange rows and columns K and IMAX, use 1-by-1 */
  986. /* pivot block */
  987. kp = imax;
  988. /* copy column K+1 of W to column K of W */
  989. i__1 = *n - k + 1;
  990. ccopy_(&i__1, &w[k + (k + 1) * w_dim1], &c__1, &w[k +
  991. k * w_dim1], &c__1);
  992. } else {
  993. /* interchange rows and columns K+1 and IMAX, use 2-by-2 */
  994. /* pivot block */
  995. kp = imax;
  996. kstep = 2;
  997. }
  998. }
  999. }
  1000. /* ============================================================ */
  1001. /* KK is the column of A where pivoting step stopped */
  1002. kk = k + kstep - 1;
  1003. /* Interchange rows and columns KP and KK. */
  1004. /* Updated column KP is already stored in column KK of W. */
  1005. if (kp != kk) {
  1006. /* Copy non-updated column KK to column KP of submatrix A */
  1007. /* at step K. No need to copy element into column K */
  1008. /* (or K and K+1 for 2-by-2 pivot) of A, since these columns */
  1009. /* will be later overwritten. */
  1010. i__1 = kp + kp * a_dim1;
  1011. i__2 = kk + kk * a_dim1;
  1012. a[i__1].r = a[i__2].r, a[i__1].i = a[i__2].i;
  1013. i__1 = kp - kk - 1;
  1014. ccopy_(&i__1, &a[kk + 1 + kk * a_dim1], &c__1, &a[kp + (kk +
  1015. 1) * a_dim1], lda);
  1016. if (kp < *n) {
  1017. i__1 = *n - kp;
  1018. ccopy_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + 1
  1019. + kp * a_dim1], &c__1);
  1020. }
  1021. /* Interchange rows KK and KP in first K-1 columns of A */
  1022. /* (columns K (or K and K+1 for 2-by-2 pivot) of A will be */
  1023. /* later overwritten). Interchange rows KK and KP */
  1024. /* in first KK columns of W. */
  1025. if (k > 1) {
  1026. i__1 = k - 1;
  1027. cswap_(&i__1, &a[kk + a_dim1], lda, &a[kp + a_dim1], lda);
  1028. }
  1029. cswap_(&kk, &w[kk + w_dim1], ldw, &w[kp + w_dim1], ldw);
  1030. }
  1031. if (kstep == 1) {
  1032. /* 1-by-1 pivot block D(k): column k of W now holds */
  1033. /* W(k) = L(k)*D(k), */
  1034. /* where L(k) is the k-th column of L */
  1035. /* Store subdiag. elements of column L(k) */
  1036. /* and 1-by-1 block D(k) in column k of A. */
  1037. /* (NOTE: Diagonal element L(k,k) is a UNIT element */
  1038. /* and not stored) */
  1039. /* A(k,k) := D(k,k) = W(k,k) */
  1040. /* A(k+1:N,k) := L(k+1:N,k) = W(k+1:N,k)/D(k,k) */
  1041. i__1 = *n - k + 1;
  1042. ccopy_(&i__1, &w[k + k * w_dim1], &c__1, &a[k + k * a_dim1], &
  1043. c__1);
  1044. if (k < *n) {
  1045. c_div(&q__1, &c_b1, &a[k + k * a_dim1]);
  1046. r1.r = q__1.r, r1.i = q__1.i;
  1047. i__1 = *n - k;
  1048. cscal_(&i__1, &r1, &a[k + 1 + k * a_dim1], &c__1);
  1049. }
  1050. } else {
  1051. /* 2-by-2 pivot block D(k): columns k and k+1 of W now hold */
  1052. /* ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k) */
  1053. /* where L(k) and L(k+1) are the k-th and (k+1)-th columns */
  1054. /* of L */
  1055. /* Store L(k+2:N,k) and L(k+2:N,k+1) and 2-by-2 */
  1056. /* block D(k:k+1,k:k+1) in columns k and k+1 of A. */
  1057. /* (NOTE: 2-by-2 diagonal block L(k:k+1,k:k+1) is a UNIT */
  1058. /* block and not stored) */
  1059. /* A(k:k+1,k:k+1) := D(k:k+1,k:k+1) = W(k:k+1,k:k+1) */
  1060. /* A(k+2:N,k:k+1) := L(k+2:N,k:k+1) = */
  1061. /* = W(k+2:N,k:k+1) * ( D(k:k+1,k:k+1)**(-1) ) */
  1062. if (k < *n - 1) {
  1063. /* Compose the columns of the inverse of 2-by-2 pivot */
  1064. /* block D in the following way to reduce the number */
  1065. /* of FLOPS when we myltiply panel ( W(k) W(k+1) ) by */
  1066. /* this inverse */
  1067. /* D**(-1) = ( d11 d21 )**(-1) = */
  1068. /* ( d21 d22 ) */
  1069. /* = 1/(d11*d22-d21**2) * ( ( d22 ) (-d21 ) ) = */
  1070. /* ( (-d21 ) ( d11 ) ) */
  1071. /* = 1/d21 * 1/((d11/d21)*(d22/d21)-1) * */
  1072. /* * ( ( d22/d21 ) ( -1 ) ) = */
  1073. /* ( ( -1 ) ( d11/d21 ) ) */
  1074. /* = 1/d21 * 1/(D22*D11-1) * ( ( D11 ) ( -1 ) ) = */
  1075. /* ( ( -1 ) ( D22 ) ) */
  1076. /* = 1/d21 * T * ( ( D11 ) ( -1 ) ) */
  1077. /* ( ( -1 ) ( D22 ) ) */
  1078. /* = D21 * ( ( D11 ) ( -1 ) ) */
  1079. /* ( ( -1 ) ( D22 ) ) */
  1080. i__1 = k + 1 + k * w_dim1;
  1081. d21.r = w[i__1].r, d21.i = w[i__1].i;
  1082. c_div(&q__1, &w[k + 1 + (k + 1) * w_dim1], &d21);
  1083. d11.r = q__1.r, d11.i = q__1.i;
  1084. c_div(&q__1, &w[k + k * w_dim1], &d21);
  1085. d22.r = q__1.r, d22.i = q__1.i;
  1086. q__3.r = d11.r * d22.r - d11.i * d22.i, q__3.i = d11.r *
  1087. d22.i + d11.i * d22.r;
  1088. q__2.r = q__3.r - 1.f, q__2.i = q__3.i + 0.f;
  1089. c_div(&q__1, &c_b1, &q__2);
  1090. t.r = q__1.r, t.i = q__1.i;
  1091. c_div(&q__1, &t, &d21);
  1092. d21.r = q__1.r, d21.i = q__1.i;
  1093. /* Update elements in columns A(k) and A(k+1) as */
  1094. /* dot products of rows of ( W(k) W(k+1) ) and columns */
  1095. /* of D**(-1) */
  1096. i__1 = *n;
  1097. for (j = k + 2; j <= i__1; ++j) {
  1098. i__2 = j + k * a_dim1;
  1099. i__3 = j + k * w_dim1;
  1100. q__3.r = d11.r * w[i__3].r - d11.i * w[i__3].i,
  1101. q__3.i = d11.r * w[i__3].i + d11.i * w[i__3]
  1102. .r;
  1103. i__4 = j + (k + 1) * w_dim1;
  1104. q__2.r = q__3.r - w[i__4].r, q__2.i = q__3.i - w[i__4]
  1105. .i;
  1106. q__1.r = d21.r * q__2.r - d21.i * q__2.i, q__1.i =
  1107. d21.r * q__2.i + d21.i * q__2.r;
  1108. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  1109. i__2 = j + (k + 1) * a_dim1;
  1110. i__3 = j + (k + 1) * w_dim1;
  1111. q__3.r = d22.r * w[i__3].r - d22.i * w[i__3].i,
  1112. q__3.i = d22.r * w[i__3].i + d22.i * w[i__3]
  1113. .r;
  1114. i__4 = j + k * w_dim1;
  1115. q__2.r = q__3.r - w[i__4].r, q__2.i = q__3.i - w[i__4]
  1116. .i;
  1117. q__1.r = d21.r * q__2.r - d21.i * q__2.i, q__1.i =
  1118. d21.r * q__2.i + d21.i * q__2.r;
  1119. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  1120. /* L80: */
  1121. }
  1122. }
  1123. /* Copy D(k) to A */
  1124. i__1 = k + k * a_dim1;
  1125. i__2 = k + k * w_dim1;
  1126. a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
  1127. i__1 = k + 1 + k * a_dim1;
  1128. i__2 = k + 1 + k * w_dim1;
  1129. a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
  1130. i__1 = k + 1 + (k + 1) * a_dim1;
  1131. i__2 = k + 1 + (k + 1) * w_dim1;
  1132. a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
  1133. }
  1134. }
  1135. /* Store details of the interchanges in IPIV */
  1136. if (kstep == 1) {
  1137. ipiv[k] = kp;
  1138. } else {
  1139. ipiv[k] = -kp;
  1140. ipiv[k + 1] = -kp;
  1141. }
  1142. /* Increase K and return to the start of the main loop */
  1143. k += kstep;
  1144. goto L70;
  1145. L90:
  1146. /* Update the lower triangle of A22 (= A(k:n,k:n)) as */
  1147. /* A22 := A22 - L21*D*L21**T = A22 - L21*W**T */
  1148. /* computing blocks of NB columns at a time */
  1149. i__1 = *n;
  1150. i__2 = *nb;
  1151. for (j = k; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  1152. /* Computing MIN */
  1153. i__3 = *nb, i__4 = *n - j + 1;
  1154. jb = f2cmin(i__3,i__4);
  1155. /* Update the lower triangle of the diagonal block */
  1156. i__3 = j + jb - 1;
  1157. for (jj = j; jj <= i__3; ++jj) {
  1158. i__4 = j + jb - jj;
  1159. i__5 = k - 1;
  1160. q__1.r = -1.f, q__1.i = 0.f;
  1161. cgemv_("No transpose", &i__4, &i__5, &q__1, &a[jj + a_dim1],
  1162. lda, &w[jj + w_dim1], ldw, &c_b1, &a[jj + jj * a_dim1]
  1163. , &c__1);
  1164. /* L100: */
  1165. }
  1166. /* Update the rectangular subdiagonal block */
  1167. if (j + jb <= *n) {
  1168. i__3 = *n - j - jb + 1;
  1169. i__4 = k - 1;
  1170. q__1.r = -1.f, q__1.i = 0.f;
  1171. cgemm_("No transpose", "Transpose", &i__3, &jb, &i__4, &q__1,
  1172. &a[j + jb + a_dim1], lda, &w[j + w_dim1], ldw, &c_b1,
  1173. &a[j + jb + j * a_dim1], lda);
  1174. }
  1175. /* L110: */
  1176. }
  1177. /* Put L21 in standard form by partially undoing the interchanges */
  1178. /* of rows in columns 1:k-1 looping backwards from k-1 to 1 */
  1179. j = k - 1;
  1180. L120:
  1181. /* Undo the interchanges (if any) of rows JJ and JP at each */
  1182. /* step J */
  1183. /* (Here, J is a diagonal index) */
  1184. jj = j;
  1185. jp = ipiv[j];
  1186. if (jp < 0) {
  1187. jp = -jp;
  1188. /* (Here, J is a diagonal index) */
  1189. --j;
  1190. }
  1191. /* (NOTE: Here, J is used to determine row length. Length J */
  1192. /* of the rows to swap back doesn't include diagonal element) */
  1193. --j;
  1194. if (jp != jj && j >= 1) {
  1195. cswap_(&j, &a[jp + a_dim1], lda, &a[jj + a_dim1], lda);
  1196. }
  1197. if (j > 1) {
  1198. goto L120;
  1199. }
  1200. /* Set KB to the number of columns factorized */
  1201. *kb = k - 1;
  1202. }
  1203. return 0;
  1204. /* End of CLASYF */
  1205. } /* clasyf_ */