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.

zlahef_rk.c 59 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935
  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 doublecomplex c_b1 = {1.,0.};
  381. static integer c__1 = 1;
  382. /* > \brief \b ZLAHEF_RK computes a partial factorization of a complex Hermitian indefinite matrix using bound
  383. ed Bunch-Kaufman (rook) diagonal pivoting method. */
  384. /* =========== DOCUMENTATION =========== */
  385. /* Online html documentation available at */
  386. /* http://www.netlib.org/lapack/explore-html/ */
  387. /* > \htmlonly */
  388. /* > Download ZLAHEF_RK + dependencies */
  389. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlahef_
  390. rk.f"> */
  391. /* > [TGZ]</a> */
  392. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlahef_
  393. rk.f"> */
  394. /* > [ZIP]</a> */
  395. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlahef_
  396. rk.f"> */
  397. /* > [TXT]</a> */
  398. /* > \endhtmlonly */
  399. /* Definition: */
  400. /* =========== */
  401. /* SUBROUTINE ZLAHEF_RK( UPLO, N, NB, KB, A, LDA, E, IPIV, W, LDW, */
  402. /* INFO ) */
  403. /* CHARACTER UPLO */
  404. /* INTEGER INFO, KB, LDA, LDW, N, NB */
  405. /* INTEGER IPIV( * ) */
  406. /* COMPLEX*16 A( LDA, * ), E( * ), W( LDW, * ) */
  407. /* > \par Purpose: */
  408. /* ============= */
  409. /* > */
  410. /* > \verbatim */
  411. /* > ZLAHEF_RK computes a partial factorization of a complex Hermitian */
  412. /* > matrix A using the bounded Bunch-Kaufman (rook) diagonal */
  413. /* > pivoting method. The partial factorization has the form: */
  414. /* > */
  415. /* > A = ( I U12 ) ( A11 0 ) ( I 0 ) if UPLO = 'U', or: */
  416. /* > ( 0 U22 ) ( 0 D ) ( U12**H U22**H ) */
  417. /* > */
  418. /* > A = ( L11 0 ) ( D 0 ) ( L11**H L21**H ) 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. /* > */
  424. /* > ZLAHEF_RK is an auxiliary routine called by ZHETRF_RK. It uses */
  425. /* > blocked code (calling Level 3 BLAS) to update the submatrix */
  426. /* > A11 (if UPLO = 'U') or A22 (if UPLO = 'L'). */
  427. /* > \endverbatim */
  428. /* Arguments: */
  429. /* ========== */
  430. /* > \param[in] UPLO */
  431. /* > \verbatim */
  432. /* > UPLO is CHARACTER*1 */
  433. /* > Specifies whether the upper or lower triangular part of the */
  434. /* > Hermitian matrix A is stored: */
  435. /* > = 'U': Upper triangular */
  436. /* > = 'L': Lower triangular */
  437. /* > \endverbatim */
  438. /* > */
  439. /* > \param[in] N */
  440. /* > \verbatim */
  441. /* > N is INTEGER */
  442. /* > The order of the matrix A. N >= 0. */
  443. /* > \endverbatim */
  444. /* > */
  445. /* > \param[in] NB */
  446. /* > \verbatim */
  447. /* > NB is INTEGER */
  448. /* > The maximum number of columns of the matrix A that should be */
  449. /* > factored. NB should be at least 2 to allow for 2-by-2 pivot */
  450. /* > blocks. */
  451. /* > \endverbatim */
  452. /* > */
  453. /* > \param[out] KB */
  454. /* > \verbatim */
  455. /* > KB is INTEGER */
  456. /* > The number of columns of A that were actually factored. */
  457. /* > KB is either NB-1 or NB, or N if N <= NB. */
  458. /* > \endverbatim */
  459. /* > */
  460. /* > \param[in,out] A */
  461. /* > \verbatim */
  462. /* > A is COMPLEX*16 array, dimension (LDA,N) */
  463. /* > On entry, the Hermitian matrix A. */
  464. /* > If UPLO = 'U': the leading N-by-N upper triangular part */
  465. /* > of A contains the upper triangular part of the matrix A, */
  466. /* > and the strictly lower triangular part of A is not */
  467. /* > referenced. */
  468. /* > */
  469. /* > If UPLO = 'L': the leading N-by-N lower triangular part */
  470. /* > of A contains the lower triangular part of the matrix A, */
  471. /* > and the strictly upper triangular part of A is not */
  472. /* > referenced. */
  473. /* > */
  474. /* > On exit, contains: */
  475. /* > a) ONLY diagonal elements of the Hermitian block diagonal */
  476. /* > matrix D on the diagonal of A, i.e. D(k,k) = A(k,k); */
  477. /* > (superdiagonal (or subdiagonal) elements of D */
  478. /* > are stored on exit in array E), and */
  479. /* > b) If UPLO = 'U': factor U in the superdiagonal part of A. */
  480. /* > If UPLO = 'L': factor L in the subdiagonal part of A. */
  481. /* > \endverbatim */
  482. /* > */
  483. /* > \param[in] LDA */
  484. /* > \verbatim */
  485. /* > LDA is INTEGER */
  486. /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
  487. /* > \endverbatim */
  488. /* > */
  489. /* > \param[out] E */
  490. /* > \verbatim */
  491. /* > E is COMPLEX*16 array, dimension (N) */
  492. /* > On exit, contains the superdiagonal (or subdiagonal) */
  493. /* > elements of the Hermitian block diagonal matrix D */
  494. /* > with 1-by-1 or 2-by-2 diagonal blocks, where */
  495. /* > If UPLO = 'U': E(i) = D(i-1,i), i=2:N, E(1) is set to 0; */
  496. /* > If UPLO = 'L': E(i) = D(i+1,i), i=1:N-1, E(N) is set to 0. */
  497. /* > */
  498. /* > NOTE: For 1-by-1 diagonal block D(k), where */
  499. /* > 1 <= k <= N, the element E(k) is set to 0 in both */
  500. /* > UPLO = 'U' or UPLO = 'L' cases. */
  501. /* > \endverbatim */
  502. /* > */
  503. /* > \param[out] IPIV */
  504. /* > \verbatim */
  505. /* > IPIV is INTEGER array, dimension (N) */
  506. /* > IPIV describes the permutation matrix P in the factorization */
  507. /* > of matrix A as follows. The absolute value of IPIV(k) */
  508. /* > represents the index of row and column that were */
  509. /* > interchanged with the k-th row and column. The value of UPLO */
  510. /* > describes the order in which the interchanges were applied. */
  511. /* > Also, the sign of IPIV represents the block structure of */
  512. /* > the Hermitian block diagonal matrix D with 1-by-1 or 2-by-2 */
  513. /* > diagonal blocks which correspond to 1 or 2 interchanges */
  514. /* > at each factorization step. */
  515. /* > */
  516. /* > If UPLO = 'U', */
  517. /* > ( in factorization order, k decreases from N to 1 ): */
  518. /* > a) A single positive entry IPIV(k) > 0 means: */
  519. /* > D(k,k) is a 1-by-1 diagonal block. */
  520. /* > If IPIV(k) != k, rows and columns k and IPIV(k) were */
  521. /* > interchanged in the submatrix A(1:N,N-KB+1:N); */
  522. /* > If IPIV(k) = k, no interchange occurred. */
  523. /* > */
  524. /* > */
  525. /* > b) A pair of consecutive negative entries */
  526. /* > IPIV(k) < 0 and IPIV(k-1) < 0 means: */
  527. /* > D(k-1:k,k-1:k) is a 2-by-2 diagonal block. */
  528. /* > (NOTE: negative entries in IPIV appear ONLY in pairs). */
  529. /* > 1) If -IPIV(k) != k, rows and columns */
  530. /* > k and -IPIV(k) were interchanged */
  531. /* > in the matrix A(1:N,N-KB+1:N). */
  532. /* > If -IPIV(k) = k, no interchange occurred. */
  533. /* > 2) If -IPIV(k-1) != k-1, rows and columns */
  534. /* > k-1 and -IPIV(k-1) were interchanged */
  535. /* > in the submatrix A(1:N,N-KB+1:N). */
  536. /* > If -IPIV(k-1) = k-1, no interchange occurred. */
  537. /* > */
  538. /* > c) In both cases a) and b) is always ABS( IPIV(k) ) <= k. */
  539. /* > */
  540. /* > d) NOTE: Any entry IPIV(k) is always NONZERO on output. */
  541. /* > */
  542. /* > If UPLO = 'L', */
  543. /* > ( in factorization order, k increases from 1 to N ): */
  544. /* > a) A single positive entry IPIV(k) > 0 means: */
  545. /* > D(k,k) is a 1-by-1 diagonal block. */
  546. /* > If IPIV(k) != k, rows and columns k and IPIV(k) were */
  547. /* > interchanged in the submatrix A(1:N,1:KB). */
  548. /* > If IPIV(k) = k, no interchange occurred. */
  549. /* > */
  550. /* > b) A pair of consecutive negative entries */
  551. /* > IPIV(k) < 0 and IPIV(k+1) < 0 means: */
  552. /* > D(k:k+1,k:k+1) is a 2-by-2 diagonal block. */
  553. /* > (NOTE: negative entries in IPIV appear ONLY in pairs). */
  554. /* > 1) If -IPIV(k) != k, rows and columns */
  555. /* > k and -IPIV(k) were interchanged */
  556. /* > in the submatrix A(1:N,1:KB). */
  557. /* > If -IPIV(k) = k, no interchange occurred. */
  558. /* > 2) If -IPIV(k+1) != k+1, rows and columns */
  559. /* > k-1 and -IPIV(k-1) were interchanged */
  560. /* > in the submatrix A(1:N,1:KB). */
  561. /* > If -IPIV(k+1) = k+1, no interchange occurred. */
  562. /* > */
  563. /* > c) In both cases a) and b) is always ABS( IPIV(k) ) >= k. */
  564. /* > */
  565. /* > d) NOTE: Any entry IPIV(k) is always NONZERO on output. */
  566. /* > \endverbatim */
  567. /* > */
  568. /* > \param[out] W */
  569. /* > \verbatim */
  570. /* > W is COMPLEX*16 array, dimension (LDW,NB) */
  571. /* > \endverbatim */
  572. /* > */
  573. /* > \param[in] LDW */
  574. /* > \verbatim */
  575. /* > LDW is INTEGER */
  576. /* > The leading dimension of the array W. LDW >= f2cmax(1,N). */
  577. /* > \endverbatim */
  578. /* > */
  579. /* > \param[out] INFO */
  580. /* > \verbatim */
  581. /* > INFO is INTEGER */
  582. /* > = 0: successful exit */
  583. /* > */
  584. /* > < 0: If INFO = -k, the k-th argument had an illegal value */
  585. /* > */
  586. /* > > 0: If INFO = k, the matrix A is singular, because: */
  587. /* > If UPLO = 'U': column k in the upper */
  588. /* > triangular part of A contains all zeros. */
  589. /* > If UPLO = 'L': column k in the lower */
  590. /* > triangular part of A contains all zeros. */
  591. /* > */
  592. /* > Therefore D(k,k) is exactly zero, and superdiagonal */
  593. /* > elements of column k of U (or subdiagonal elements of */
  594. /* > column k of L ) are all zeros. The factorization has */
  595. /* > been completed, but the block diagonal matrix D is */
  596. /* > exactly singular, and division by zero will occur if */
  597. /* > it is used to solve a system of equations. */
  598. /* > */
  599. /* > NOTE: INFO only stores the first occurrence of */
  600. /* > a singularity, any subsequent occurrence of singularity */
  601. /* > is not stored in INFO even though the factorization */
  602. /* > always completes. */
  603. /* > \endverbatim */
  604. /* Authors: */
  605. /* ======== */
  606. /* > \author Univ. of Tennessee */
  607. /* > \author Univ. of California Berkeley */
  608. /* > \author Univ. of Colorado Denver */
  609. /* > \author NAG Ltd. */
  610. /* > \date December 2016 */
  611. /* > \ingroup complex16HEcomputational */
  612. /* > \par Contributors: */
  613. /* ================== */
  614. /* > */
  615. /* > \verbatim */
  616. /* > */
  617. /* > December 2016, Igor Kozachenko, */
  618. /* > Computer Science Division, */
  619. /* > University of California, Berkeley */
  620. /* > */
  621. /* > September 2007, Sven Hammarling, Nicholas J. Higham, Craig Lucas, */
  622. /* > School of Mathematics, */
  623. /* > University of Manchester */
  624. /* > */
  625. /* > \endverbatim */
  626. /* ===================================================================== */
  627. /* Subroutine */ int zlahef_rk_(char *uplo, integer *n, integer *nb, integer
  628. *kb, doublecomplex *a, integer *lda, doublecomplex *e, integer *ipiv,
  629. doublecomplex *w, integer *ldw, integer *info)
  630. {
  631. /* System generated locals */
  632. integer a_dim1, a_offset, w_dim1, w_offset, i__1, i__2, i__3, i__4, i__5;
  633. doublereal d__1, d__2;
  634. doublecomplex z__1, z__2, z__3, z__4, z__5;
  635. /* Local variables */
  636. logical done;
  637. integer imax, jmax, j, k, p;
  638. doublereal t, alpha;
  639. extern logical lsame_(char *, char *);
  640. doublereal dtemp, sfmin;
  641. integer itemp;
  642. extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *,
  643. integer *, doublecomplex *, doublecomplex *, integer *,
  644. doublecomplex *, integer *, doublecomplex *, doublecomplex *,
  645. integer *);
  646. integer kstep;
  647. extern /* Subroutine */ int zgemv_(char *, integer *, integer *,
  648. doublecomplex *, doublecomplex *, integer *, doublecomplex *,
  649. integer *, doublecomplex *, doublecomplex *, integer *);
  650. doublereal r1;
  651. extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *,
  652. doublecomplex *, integer *), zswap_(integer *, doublecomplex *,
  653. integer *, doublecomplex *, integer *);
  654. doublecomplex d11, d21, d22;
  655. integer jb, ii, jj, kk;
  656. extern doublereal dlamch_(char *);
  657. integer kp;
  658. doublereal absakk;
  659. integer kw;
  660. extern /* Subroutine */ int zdscal_(integer *, doublereal *,
  661. doublecomplex *, integer *);
  662. doublereal colmax;
  663. extern /* Subroutine */ int zlacgv_(integer *, doublecomplex *, integer *)
  664. ;
  665. extern integer izamax_(integer *, doublecomplex *, integer *);
  666. doublereal rowmax;
  667. integer kkw;
  668. /* -- LAPACK computational routine (version 3.7.0) -- */
  669. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  670. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  671. /* December 2016 */
  672. /* ===================================================================== */
  673. /* Parameter adjustments */
  674. a_dim1 = *lda;
  675. a_offset = 1 + a_dim1 * 1;
  676. a -= a_offset;
  677. --e;
  678. --ipiv;
  679. w_dim1 = *ldw;
  680. w_offset = 1 + w_dim1 * 1;
  681. w -= w_offset;
  682. /* Function Body */
  683. *info = 0;
  684. /* Initialize ALPHA for use in choosing pivot block size. */
  685. alpha = (sqrt(17.) + 1.) / 8.;
  686. /* Compute machine safe minimum */
  687. sfmin = dlamch_("S");
  688. if (lsame_(uplo, "U")) {
  689. /* Factorize the trailing columns of A using the upper triangle */
  690. /* of A and working backwards, and compute the matrix W = U12*D */
  691. /* for use in updating A11 (note that conjg(W) is actually stored) */
  692. /* Initialize the first entry of array E, where superdiagonal */
  693. /* elements of D are stored */
  694. e[1].r = 0., e[1].i = 0.;
  695. /* K is the main loop index, decreasing from N in steps of 1 or 2 */
  696. k = *n;
  697. L10:
  698. /* KW is the column of W which corresponds to column K of A */
  699. kw = *nb + k - *n;
  700. /* Exit from loop */
  701. if (k <= *n - *nb + 1 && *nb < *n || k < 1) {
  702. goto L30;
  703. }
  704. kstep = 1;
  705. p = k;
  706. /* Copy column K of A to column KW of W and update it */
  707. if (k > 1) {
  708. i__1 = k - 1;
  709. zcopy_(&i__1, &a[k * a_dim1 + 1], &c__1, &w[kw * w_dim1 + 1], &
  710. c__1);
  711. }
  712. i__1 = k + kw * w_dim1;
  713. i__2 = k + k * a_dim1;
  714. d__1 = a[i__2].r;
  715. w[i__1].r = d__1, w[i__1].i = 0.;
  716. if (k < *n) {
  717. i__1 = *n - k;
  718. z__1.r = -1., z__1.i = 0.;
  719. zgemv_("No transpose", &k, &i__1, &z__1, &a[(k + 1) * a_dim1 + 1],
  720. lda, &w[k + (kw + 1) * w_dim1], ldw, &c_b1, &w[kw *
  721. w_dim1 + 1], &c__1);
  722. i__1 = k + kw * w_dim1;
  723. i__2 = k + kw * w_dim1;
  724. d__1 = w[i__2].r;
  725. w[i__1].r = d__1, w[i__1].i = 0.;
  726. }
  727. /* Determine rows and columns to be interchanged and whether */
  728. /* a 1-by-1 or 2-by-2 pivot block will be used */
  729. i__1 = k + kw * w_dim1;
  730. absakk = (d__1 = w[i__1].r, abs(d__1));
  731. /* IMAX is the row-index of the largest off-diagonal element in */
  732. /* column K, and COLMAX is its absolute value. */
  733. /* Determine both COLMAX and IMAX. */
  734. if (k > 1) {
  735. i__1 = k - 1;
  736. imax = izamax_(&i__1, &w[kw * w_dim1 + 1], &c__1);
  737. i__1 = imax + kw * w_dim1;
  738. colmax = (d__1 = w[i__1].r, abs(d__1)) + (d__2 = d_imag(&w[imax +
  739. kw * w_dim1]), abs(d__2));
  740. } else {
  741. colmax = 0.;
  742. }
  743. if (f2cmax(absakk,colmax) == 0.) {
  744. /* Column K is zero or underflow: set INFO and continue */
  745. if (*info == 0) {
  746. *info = k;
  747. }
  748. kp = k;
  749. i__1 = k + k * a_dim1;
  750. i__2 = k + kw * w_dim1;
  751. d__1 = w[i__2].r;
  752. a[i__1].r = d__1, a[i__1].i = 0.;
  753. if (k > 1) {
  754. i__1 = k - 1;
  755. zcopy_(&i__1, &w[kw * w_dim1 + 1], &c__1, &a[k * a_dim1 + 1],
  756. &c__1);
  757. }
  758. /* Set E( K ) to zero */
  759. if (k > 1) {
  760. i__1 = k;
  761. e[i__1].r = 0., e[i__1].i = 0.;
  762. }
  763. } else {
  764. /* ============================================================ */
  765. /* BEGIN pivot search */
  766. /* Case(1) */
  767. /* Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX */
  768. /* (used to handle NaN and Inf) */
  769. if (! (absakk < alpha * colmax)) {
  770. /* no interchange, use 1-by-1 pivot block */
  771. kp = k;
  772. } else {
  773. /* Lop until pivot found */
  774. done = FALSE_;
  775. L12:
  776. /* BEGIN pivot search loop body */
  777. /* Copy column IMAX to column KW-1 of W and update it */
  778. if (imax > 1) {
  779. i__1 = imax - 1;
  780. zcopy_(&i__1, &a[imax * a_dim1 + 1], &c__1, &w[(kw - 1) *
  781. w_dim1 + 1], &c__1);
  782. }
  783. i__1 = imax + (kw - 1) * w_dim1;
  784. i__2 = imax + imax * a_dim1;
  785. d__1 = a[i__2].r;
  786. w[i__1].r = d__1, w[i__1].i = 0.;
  787. i__1 = k - imax;
  788. zcopy_(&i__1, &a[imax + (imax + 1) * a_dim1], lda, &w[imax +
  789. 1 + (kw - 1) * w_dim1], &c__1);
  790. i__1 = k - imax;
  791. zlacgv_(&i__1, &w[imax + 1 + (kw - 1) * w_dim1], &c__1);
  792. if (k < *n) {
  793. i__1 = *n - k;
  794. z__1.r = -1., z__1.i = 0.;
  795. zgemv_("No transpose", &k, &i__1, &z__1, &a[(k + 1) *
  796. a_dim1 + 1], lda, &w[imax + (kw + 1) * w_dim1],
  797. ldw, &c_b1, &w[(kw - 1) * w_dim1 + 1], &c__1);
  798. i__1 = imax + (kw - 1) * w_dim1;
  799. i__2 = imax + (kw - 1) * w_dim1;
  800. d__1 = w[i__2].r;
  801. w[i__1].r = d__1, w[i__1].i = 0.;
  802. }
  803. /* JMAX is the column-index of the largest off-diagonal */
  804. /* element in row IMAX, and ROWMAX is its absolute value. */
  805. /* Determine both ROWMAX and JMAX. */
  806. if (imax != k) {
  807. i__1 = k - imax;
  808. jmax = imax + izamax_(&i__1, &w[imax + 1 + (kw - 1) *
  809. w_dim1], &c__1);
  810. i__1 = jmax + (kw - 1) * w_dim1;
  811. rowmax = (d__1 = w[i__1].r, abs(d__1)) + (d__2 = d_imag(&
  812. w[jmax + (kw - 1) * w_dim1]), abs(d__2));
  813. } else {
  814. rowmax = 0.;
  815. }
  816. if (imax > 1) {
  817. i__1 = imax - 1;
  818. itemp = izamax_(&i__1, &w[(kw - 1) * w_dim1 + 1], &c__1);
  819. i__1 = itemp + (kw - 1) * w_dim1;
  820. dtemp = (d__1 = w[i__1].r, abs(d__1)) + (d__2 = d_imag(&w[
  821. itemp + (kw - 1) * w_dim1]), abs(d__2));
  822. if (dtemp > rowmax) {
  823. rowmax = dtemp;
  824. jmax = itemp;
  825. }
  826. }
  827. /* Case(2) */
  828. /* Equivalent to testing for */
  829. /* ABS( REAL( W( IMAX,KW-1 ) ) ).GE.ALPHA*ROWMAX */
  830. /* (used to handle NaN and Inf) */
  831. i__1 = imax + (kw - 1) * w_dim1;
  832. if (! ((d__1 = w[i__1].r, abs(d__1)) < alpha * rowmax)) {
  833. /* interchange rows and columns K and IMAX, */
  834. /* use 1-by-1 pivot block */
  835. kp = imax;
  836. /* copy column KW-1 of W to column KW of W */
  837. zcopy_(&k, &w[(kw - 1) * w_dim1 + 1], &c__1, &w[kw *
  838. w_dim1 + 1], &c__1);
  839. done = TRUE_;
  840. /* Case(3) */
  841. /* Equivalent to testing for ROWMAX.EQ.COLMAX, */
  842. /* (used to handle NaN and Inf) */
  843. } else if (p == jmax || rowmax <= colmax) {
  844. /* interchange rows and columns K-1 and IMAX, */
  845. /* use 2-by-2 pivot block */
  846. kp = imax;
  847. kstep = 2;
  848. done = TRUE_;
  849. /* Case(4) */
  850. } else {
  851. /* Pivot not found: set params and repeat */
  852. p = imax;
  853. colmax = rowmax;
  854. imax = jmax;
  855. /* Copy updated JMAXth (next IMAXth) column to Kth of W */
  856. zcopy_(&k, &w[(kw - 1) * w_dim1 + 1], &c__1, &w[kw *
  857. w_dim1 + 1], &c__1);
  858. }
  859. /* END pivot search loop body */
  860. if (! done) {
  861. goto L12;
  862. }
  863. }
  864. /* END pivot search */
  865. /* ============================================================ */
  866. /* KK is the column of A where pivoting step stopped */
  867. kk = k - kstep + 1;
  868. /* KKW is the column of W which corresponds to column KK of A */
  869. kkw = *nb + kk - *n;
  870. /* Interchange rows and columns P and K. */
  871. /* Updated column P is already stored in column KW of W. */
  872. if (kstep == 2 && p != k) {
  873. /* Copy non-updated column K to column P of submatrix A */
  874. /* at step K. No need to copy element into columns */
  875. /* K and K-1 of A for 2-by-2 pivot, since these columns */
  876. /* will be later overwritten. */
  877. i__1 = p + p * a_dim1;
  878. i__2 = k + k * a_dim1;
  879. d__1 = a[i__2].r;
  880. a[i__1].r = d__1, a[i__1].i = 0.;
  881. i__1 = k - 1 - p;
  882. zcopy_(&i__1, &a[p + 1 + k * a_dim1], &c__1, &a[p + (p + 1) *
  883. a_dim1], lda);
  884. i__1 = k - 1 - p;
  885. zlacgv_(&i__1, &a[p + (p + 1) * a_dim1], lda);
  886. if (p > 1) {
  887. i__1 = p - 1;
  888. zcopy_(&i__1, &a[k * a_dim1 + 1], &c__1, &a[p * a_dim1 +
  889. 1], &c__1);
  890. }
  891. /* Interchange rows K and P in the last K+1 to N columns of A */
  892. /* (columns K and K-1 of A for 2-by-2 pivot will be */
  893. /* later overwritten). Interchange rows K and P */
  894. /* in last KKW to NB columns of W. */
  895. if (k < *n) {
  896. i__1 = *n - k;
  897. zswap_(&i__1, &a[k + (k + 1) * a_dim1], lda, &a[p + (k +
  898. 1) * a_dim1], lda);
  899. }
  900. i__1 = *n - kk + 1;
  901. zswap_(&i__1, &w[k + kkw * w_dim1], ldw, &w[p + kkw * w_dim1],
  902. ldw);
  903. }
  904. /* Interchange rows and columns KP and KK. */
  905. /* Updated column KP is already stored in column KKW of W. */
  906. if (kp != kk) {
  907. /* Copy non-updated column KK to column KP of submatrix A */
  908. /* at step K. No need to copy element into column K */
  909. /* (or K and K-1 for 2-by-2 pivot) of A, since these columns */
  910. /* will be later overwritten. */
  911. i__1 = kp + kp * a_dim1;
  912. i__2 = kk + kk * a_dim1;
  913. d__1 = a[i__2].r;
  914. a[i__1].r = d__1, a[i__1].i = 0.;
  915. i__1 = kk - 1 - kp;
  916. zcopy_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + (kp +
  917. 1) * a_dim1], lda);
  918. i__1 = kk - 1 - kp;
  919. zlacgv_(&i__1, &a[kp + (kp + 1) * a_dim1], lda);
  920. if (kp > 1) {
  921. i__1 = kp - 1;
  922. zcopy_(&i__1, &a[kk * a_dim1 + 1], &c__1, &a[kp * a_dim1
  923. + 1], &c__1);
  924. }
  925. /* Interchange rows KK and KP in last K+1 to N columns of A */
  926. /* (columns K (or K and K-1 for 2-by-2 pivot) of A will be */
  927. /* later overwritten). Interchange rows KK and KP */
  928. /* in last KKW to NB columns of W. */
  929. if (k < *n) {
  930. i__1 = *n - k;
  931. zswap_(&i__1, &a[kk + (k + 1) * a_dim1], lda, &a[kp + (k
  932. + 1) * a_dim1], lda);
  933. }
  934. i__1 = *n - kk + 1;
  935. zswap_(&i__1, &w[kk + kkw * w_dim1], ldw, &w[kp + kkw *
  936. w_dim1], ldw);
  937. }
  938. if (kstep == 1) {
  939. /* 1-by-1 pivot block D(k): column kw of W now holds */
  940. /* W(kw) = U(k)*D(k), */
  941. /* where U(k) is the k-th column of U */
  942. /* (1) Store subdiag. elements of column U(k) */
  943. /* and 1-by-1 block D(k) in column k of A. */
  944. /* (NOTE: Diagonal element U(k,k) is a UNIT element */
  945. /* and not stored) */
  946. /* A(k,k) := D(k,k) = W(k,kw) */
  947. /* A(1:k-1,k) := U(1:k-1,k) = W(1:k-1,kw)/D(k,k) */
  948. /* (NOTE: No need to use for Hermitian matrix */
  949. /* A( K, K ) = REAL( W( K, K) ) to separately copy diagonal */
  950. /* element D(k,k) from W (potentially saves only one load)) */
  951. zcopy_(&k, &w[kw * w_dim1 + 1], &c__1, &a[k * a_dim1 + 1], &
  952. c__1);
  953. if (k > 1) {
  954. /* (NOTE: No need to check if A(k,k) is NOT ZERO, */
  955. /* since that was ensured earlier in pivot search: */
  956. /* case A(k,k) = 0 falls into 2x2 pivot case(3)) */
  957. /* Handle division by a small number */
  958. i__1 = k + k * a_dim1;
  959. t = a[i__1].r;
  960. if (abs(t) >= sfmin) {
  961. r1 = 1. / t;
  962. i__1 = k - 1;
  963. zdscal_(&i__1, &r1, &a[k * a_dim1 + 1], &c__1);
  964. } else {
  965. i__1 = k - 1;
  966. for (ii = 1; ii <= i__1; ++ii) {
  967. i__2 = ii + k * a_dim1;
  968. i__3 = ii + k * a_dim1;
  969. z__1.r = a[i__3].r / t, z__1.i = a[i__3].i / t;
  970. a[i__2].r = z__1.r, a[i__2].i = z__1.i;
  971. /* L14: */
  972. }
  973. }
  974. /* (2) Conjugate column W(kw) */
  975. i__1 = k - 1;
  976. zlacgv_(&i__1, &w[kw * w_dim1 + 1], &c__1);
  977. /* Store the superdiagonal element of D in array E */
  978. i__1 = k;
  979. e[i__1].r = 0., e[i__1].i = 0.;
  980. }
  981. } else {
  982. /* 2-by-2 pivot block D(k): columns kw and kw-1 of W now hold */
  983. /* ( W(kw-1) W(kw) ) = ( U(k-1) U(k) )*D(k) */
  984. /* where U(k) and U(k-1) are the k-th and (k-1)-th columns */
  985. /* of U */
  986. /* (1) Store U(1:k-2,k-1) and U(1:k-2,k) and 2-by-2 */
  987. /* block D(k-1:k,k-1:k) in columns k-1 and k of A. */
  988. /* (NOTE: 2-by-2 diagonal block U(k-1:k,k-1:k) is a UNIT */
  989. /* block and not stored) */
  990. /* A(k-1:k,k-1:k) := D(k-1:k,k-1:k) = W(k-1:k,kw-1:kw) */
  991. /* A(1:k-2,k-1:k) := U(1:k-2,k:k-1:k) = */
  992. /* = W(1:k-2,kw-1:kw) * ( D(k-1:k,k-1:k)**(-1) ) */
  993. if (k > 2) {
  994. /* Factor out the columns of the inverse of 2-by-2 pivot */
  995. /* block D, so that each column contains 1, to reduce the */
  996. /* number of FLOPS when we multiply panel */
  997. /* ( W(kw-1) W(kw) ) by this inverse, i.e. by D**(-1). */
  998. /* D**(-1) = ( d11 cj(d21) )**(-1) = */
  999. /* ( d21 d22 ) */
  1000. /* = 1/(d11*d22-|d21|**2) * ( ( d22) (-cj(d21) ) ) = */
  1001. /* ( (-d21) ( d11 ) ) */
  1002. /* = 1/(|d21|**2) * 1/((d11/cj(d21))*(d22/d21)-1) * */
  1003. /* * ( d21*( d22/d21 ) conj(d21)*( - 1 ) ) = */
  1004. /* ( ( -1 ) ( d11/conj(d21) ) ) */
  1005. /* = 1/(|d21|**2) * 1/(D22*D11-1) * */
  1006. /* * ( d21*( D11 ) conj(d21)*( -1 ) ) = */
  1007. /* ( ( -1 ) ( D22 ) ) */
  1008. /* = (1/|d21|**2) * T * ( d21*( D11 ) conj(d21)*( -1 ) ) = */
  1009. /* ( ( -1 ) ( D22 ) ) */
  1010. /* = ( (T/conj(d21))*( D11 ) (T/d21)*( -1 ) ) = */
  1011. /* ( ( -1 ) ( D22 ) ) */
  1012. /* Handle division by a small number. (NOTE: order of */
  1013. /* operations is important) */
  1014. /* = ( T*(( D11 )/conj(D21)) T*(( -1 )/D21 ) ) */
  1015. /* ( (( -1 ) ) (( D22 ) ) ), */
  1016. /* where D11 = d22/d21, */
  1017. /* D22 = d11/conj(d21), */
  1018. /* D21 = d21, */
  1019. /* T = 1/(D22*D11-1). */
  1020. /* (NOTE: No need to check for division by ZERO, */
  1021. /* since that was ensured earlier in pivot search: */
  1022. /* (a) d21 != 0 in 2x2 pivot case(4), */
  1023. /* since |d21| should be larger than |d11| and |d22|; */
  1024. /* (b) (D22*D11 - 1) != 0, since from (a), */
  1025. /* both |D11| < 1, |D22| < 1, hence |D22*D11| << 1.) */
  1026. i__1 = k - 1 + kw * w_dim1;
  1027. d21.r = w[i__1].r, d21.i = w[i__1].i;
  1028. d_cnjg(&z__2, &d21);
  1029. z_div(&z__1, &w[k + kw * w_dim1], &z__2);
  1030. d11.r = z__1.r, d11.i = z__1.i;
  1031. z_div(&z__1, &w[k - 1 + (kw - 1) * w_dim1], &d21);
  1032. d22.r = z__1.r, d22.i = z__1.i;
  1033. z__1.r = d11.r * d22.r - d11.i * d22.i, z__1.i = d11.r *
  1034. d22.i + d11.i * d22.r;
  1035. t = 1. / (z__1.r - 1.);
  1036. /* Update elements in columns A(k-1) and A(k) as */
  1037. /* dot products of rows of ( W(kw-1) W(kw) ) and columns */
  1038. /* of D**(-1) */
  1039. i__1 = k - 2;
  1040. for (j = 1; j <= i__1; ++j) {
  1041. i__2 = j + (k - 1) * a_dim1;
  1042. i__3 = j + (kw - 1) * w_dim1;
  1043. z__4.r = d11.r * w[i__3].r - d11.i * w[i__3].i,
  1044. z__4.i = d11.r * w[i__3].i + d11.i * w[i__3]
  1045. .r;
  1046. i__4 = j + kw * w_dim1;
  1047. z__3.r = z__4.r - w[i__4].r, z__3.i = z__4.i - w[i__4]
  1048. .i;
  1049. z_div(&z__2, &z__3, &d21);
  1050. z__1.r = t * z__2.r, z__1.i = t * z__2.i;
  1051. a[i__2].r = z__1.r, a[i__2].i = z__1.i;
  1052. i__2 = j + k * a_dim1;
  1053. i__3 = j + kw * w_dim1;
  1054. z__4.r = d22.r * w[i__3].r - d22.i * w[i__3].i,
  1055. z__4.i = d22.r * w[i__3].i + d22.i * w[i__3]
  1056. .r;
  1057. i__4 = j + (kw - 1) * w_dim1;
  1058. z__3.r = z__4.r - w[i__4].r, z__3.i = z__4.i - w[i__4]
  1059. .i;
  1060. d_cnjg(&z__5, &d21);
  1061. z_div(&z__2, &z__3, &z__5);
  1062. z__1.r = t * z__2.r, z__1.i = t * z__2.i;
  1063. a[i__2].r = z__1.r, a[i__2].i = z__1.i;
  1064. /* L20: */
  1065. }
  1066. }
  1067. /* Copy diagonal elements of D(K) to A, */
  1068. /* copy superdiagonal element of D(K) to E(K) and */
  1069. /* ZERO out superdiagonal entry of A */
  1070. i__1 = k - 1 + (k - 1) * a_dim1;
  1071. i__2 = k - 1 + (kw - 1) * w_dim1;
  1072. a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
  1073. i__1 = k - 1 + k * a_dim1;
  1074. a[i__1].r = 0., a[i__1].i = 0.;
  1075. i__1 = k + k * a_dim1;
  1076. i__2 = k + kw * w_dim1;
  1077. a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
  1078. i__1 = k;
  1079. i__2 = k - 1 + kw * w_dim1;
  1080. e[i__1].r = w[i__2].r, e[i__1].i = w[i__2].i;
  1081. i__1 = k - 1;
  1082. e[i__1].r = 0., e[i__1].i = 0.;
  1083. /* (2) Conjugate columns W(kw) and W(kw-1) */
  1084. i__1 = k - 1;
  1085. zlacgv_(&i__1, &w[kw * w_dim1 + 1], &c__1);
  1086. i__1 = k - 2;
  1087. zlacgv_(&i__1, &w[(kw - 1) * w_dim1 + 1], &c__1);
  1088. }
  1089. /* End column K is nonsingular */
  1090. }
  1091. /* Store details of the interchanges in IPIV */
  1092. if (kstep == 1) {
  1093. ipiv[k] = kp;
  1094. } else {
  1095. ipiv[k] = -p;
  1096. ipiv[k - 1] = -kp;
  1097. }
  1098. /* Decrease K and return to the start of the main loop */
  1099. k -= kstep;
  1100. goto L10;
  1101. L30:
  1102. /* Update the upper triangle of A11 (= A(1:k,1:k)) as */
  1103. /* A11 := A11 - U12*D*U12**H = A11 - U12*W**H */
  1104. /* computing blocks of NB columns at a time (note that conjg(W) is */
  1105. /* actually stored) */
  1106. i__1 = -(*nb);
  1107. for (j = (k - 1) / *nb * *nb + 1; i__1 < 0 ? j >= 1 : j <= 1; j +=
  1108. i__1) {
  1109. /* Computing MIN */
  1110. i__2 = *nb, i__3 = k - j + 1;
  1111. jb = f2cmin(i__2,i__3);
  1112. /* Update the upper triangle of the diagonal block */
  1113. i__2 = j + jb - 1;
  1114. for (jj = j; jj <= i__2; ++jj) {
  1115. i__3 = jj + jj * a_dim1;
  1116. i__4 = jj + jj * a_dim1;
  1117. d__1 = a[i__4].r;
  1118. a[i__3].r = d__1, a[i__3].i = 0.;
  1119. i__3 = jj - j + 1;
  1120. i__4 = *n - k;
  1121. z__1.r = -1., z__1.i = 0.;
  1122. zgemv_("No transpose", &i__3, &i__4, &z__1, &a[j + (k + 1) *
  1123. a_dim1], lda, &w[jj + (kw + 1) * w_dim1], ldw, &c_b1,
  1124. &a[j + jj * a_dim1], &c__1);
  1125. i__3 = jj + jj * a_dim1;
  1126. i__4 = jj + jj * a_dim1;
  1127. d__1 = a[i__4].r;
  1128. a[i__3].r = d__1, a[i__3].i = 0.;
  1129. /* L40: */
  1130. }
  1131. /* Update the rectangular superdiagonal block */
  1132. if (j >= 2) {
  1133. i__2 = j - 1;
  1134. i__3 = *n - k;
  1135. z__1.r = -1., z__1.i = 0.;
  1136. zgemm_("No transpose", "Transpose", &i__2, &jb, &i__3, &z__1,
  1137. &a[(k + 1) * a_dim1 + 1], lda, &w[j + (kw + 1) *
  1138. w_dim1], ldw, &c_b1, &a[j * a_dim1 + 1], lda);
  1139. }
  1140. /* L50: */
  1141. }
  1142. /* Set KB to the number of columns factorized */
  1143. *kb = *n - k;
  1144. } else {
  1145. /* Factorize the leading columns of A using the lower triangle */
  1146. /* of A and working forwards, and compute the matrix W = L21*D */
  1147. /* for use in updating A22 (note that conjg(W) is actually stored) */
  1148. /* Initialize the unused last entry of the subdiagonal array E. */
  1149. i__1 = *n;
  1150. e[i__1].r = 0., e[i__1].i = 0.;
  1151. /* K is the main loop index, increasing from 1 in steps of 1 or 2 */
  1152. k = 1;
  1153. L70:
  1154. /* Exit from loop */
  1155. if (k >= *nb && *nb < *n || k > *n) {
  1156. goto L90;
  1157. }
  1158. kstep = 1;
  1159. p = k;
  1160. /* Copy column K of A to column K of W and update column K of W */
  1161. i__1 = k + k * w_dim1;
  1162. i__2 = k + k * a_dim1;
  1163. d__1 = a[i__2].r;
  1164. w[i__1].r = d__1, w[i__1].i = 0.;
  1165. if (k < *n) {
  1166. i__1 = *n - k;
  1167. zcopy_(&i__1, &a[k + 1 + k * a_dim1], &c__1, &w[k + 1 + k *
  1168. w_dim1], &c__1);
  1169. }
  1170. if (k > 1) {
  1171. i__1 = *n - k + 1;
  1172. i__2 = k - 1;
  1173. z__1.r = -1., z__1.i = 0.;
  1174. zgemv_("No transpose", &i__1, &i__2, &z__1, &a[k + a_dim1], lda, &
  1175. w[k + w_dim1], ldw, &c_b1, &w[k + k * w_dim1], &c__1);
  1176. i__1 = k + k * w_dim1;
  1177. i__2 = k + k * w_dim1;
  1178. d__1 = w[i__2].r;
  1179. w[i__1].r = d__1, w[i__1].i = 0.;
  1180. }
  1181. /* Determine rows and columns to be interchanged and whether */
  1182. /* a 1-by-1 or 2-by-2 pivot block will be used */
  1183. i__1 = k + k * w_dim1;
  1184. absakk = (d__1 = w[i__1].r, abs(d__1));
  1185. /* IMAX is the row-index of the largest off-diagonal element in */
  1186. /* column K, and COLMAX is its absolute value. */
  1187. /* Determine both COLMAX and IMAX. */
  1188. if (k < *n) {
  1189. i__1 = *n - k;
  1190. imax = k + izamax_(&i__1, &w[k + 1 + k * w_dim1], &c__1);
  1191. i__1 = imax + k * w_dim1;
  1192. colmax = (d__1 = w[i__1].r, abs(d__1)) + (d__2 = d_imag(&w[imax +
  1193. k * w_dim1]), abs(d__2));
  1194. } else {
  1195. colmax = 0.;
  1196. }
  1197. if (f2cmax(absakk,colmax) == 0.) {
  1198. /* Column K is zero or underflow: set INFO and continue */
  1199. if (*info == 0) {
  1200. *info = k;
  1201. }
  1202. kp = k;
  1203. i__1 = k + k * a_dim1;
  1204. i__2 = k + k * w_dim1;
  1205. d__1 = w[i__2].r;
  1206. a[i__1].r = d__1, a[i__1].i = 0.;
  1207. if (k < *n) {
  1208. i__1 = *n - k;
  1209. zcopy_(&i__1, &w[k + 1 + k * w_dim1], &c__1, &a[k + 1 + k *
  1210. a_dim1], &c__1);
  1211. }
  1212. /* Set E( K ) to zero */
  1213. if (k < *n) {
  1214. i__1 = k;
  1215. e[i__1].r = 0., e[i__1].i = 0.;
  1216. }
  1217. } else {
  1218. /* ============================================================ */
  1219. /* BEGIN pivot search */
  1220. /* Case(1) */
  1221. /* Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX */
  1222. /* (used to handle NaN and Inf) */
  1223. if (! (absakk < alpha * colmax)) {
  1224. /* no interchange, use 1-by-1 pivot block */
  1225. kp = k;
  1226. } else {
  1227. done = FALSE_;
  1228. /* Loop until pivot found */
  1229. L72:
  1230. /* BEGIN pivot search loop body */
  1231. /* Copy column IMAX to column k+1 of W and update it */
  1232. i__1 = imax - k;
  1233. zcopy_(&i__1, &a[imax + k * a_dim1], lda, &w[k + (k + 1) *
  1234. w_dim1], &c__1);
  1235. i__1 = imax - k;
  1236. zlacgv_(&i__1, &w[k + (k + 1) * w_dim1], &c__1);
  1237. i__1 = imax + (k + 1) * w_dim1;
  1238. i__2 = imax + imax * a_dim1;
  1239. d__1 = a[i__2].r;
  1240. w[i__1].r = d__1, w[i__1].i = 0.;
  1241. if (imax < *n) {
  1242. i__1 = *n - imax;
  1243. zcopy_(&i__1, &a[imax + 1 + imax * a_dim1], &c__1, &w[
  1244. imax + 1 + (k + 1) * w_dim1], &c__1);
  1245. }
  1246. if (k > 1) {
  1247. i__1 = *n - k + 1;
  1248. i__2 = k - 1;
  1249. z__1.r = -1., z__1.i = 0.;
  1250. zgemv_("No transpose", &i__1, &i__2, &z__1, &a[k + a_dim1]
  1251. , lda, &w[imax + w_dim1], ldw, &c_b1, &w[k + (k +
  1252. 1) * w_dim1], &c__1);
  1253. i__1 = imax + (k + 1) * w_dim1;
  1254. i__2 = imax + (k + 1) * w_dim1;
  1255. d__1 = w[i__2].r;
  1256. w[i__1].r = d__1, w[i__1].i = 0.;
  1257. }
  1258. /* JMAX is the column-index of the largest off-diagonal */
  1259. /* element in row IMAX, and ROWMAX is its absolute value. */
  1260. /* Determine both ROWMAX and JMAX. */
  1261. if (imax != k) {
  1262. i__1 = imax - k;
  1263. jmax = k - 1 + izamax_(&i__1, &w[k + (k + 1) * w_dim1], &
  1264. c__1);
  1265. i__1 = jmax + (k + 1) * w_dim1;
  1266. rowmax = (d__1 = w[i__1].r, abs(d__1)) + (d__2 = d_imag(&
  1267. w[jmax + (k + 1) * w_dim1]), abs(d__2));
  1268. } else {
  1269. rowmax = 0.;
  1270. }
  1271. if (imax < *n) {
  1272. i__1 = *n - imax;
  1273. itemp = imax + izamax_(&i__1, &w[imax + 1 + (k + 1) *
  1274. w_dim1], &c__1);
  1275. i__1 = itemp + (k + 1) * w_dim1;
  1276. dtemp = (d__1 = w[i__1].r, abs(d__1)) + (d__2 = d_imag(&w[
  1277. itemp + (k + 1) * w_dim1]), abs(d__2));
  1278. if (dtemp > rowmax) {
  1279. rowmax = dtemp;
  1280. jmax = itemp;
  1281. }
  1282. }
  1283. /* Case(2) */
  1284. /* Equivalent to testing for */
  1285. /* ABS( REAL( W( IMAX,K+1 ) ) ).GE.ALPHA*ROWMAX */
  1286. /* (used to handle NaN and Inf) */
  1287. i__1 = imax + (k + 1) * w_dim1;
  1288. if (! ((d__1 = w[i__1].r, abs(d__1)) < alpha * rowmax)) {
  1289. /* interchange rows and columns K and IMAX, */
  1290. /* use 1-by-1 pivot block */
  1291. kp = imax;
  1292. /* copy column K+1 of W to column K of W */
  1293. i__1 = *n - k + 1;
  1294. zcopy_(&i__1, &w[k + (k + 1) * w_dim1], &c__1, &w[k + k *
  1295. w_dim1], &c__1);
  1296. done = TRUE_;
  1297. /* Case(3) */
  1298. /* Equivalent to testing for ROWMAX.EQ.COLMAX, */
  1299. /* (used to handle NaN and Inf) */
  1300. } else if (p == jmax || rowmax <= colmax) {
  1301. /* interchange rows and columns K+1 and IMAX, */
  1302. /* use 2-by-2 pivot block */
  1303. kp = imax;
  1304. kstep = 2;
  1305. done = TRUE_;
  1306. /* Case(4) */
  1307. } else {
  1308. /* Pivot not found: set params and repeat */
  1309. p = imax;
  1310. colmax = rowmax;
  1311. imax = jmax;
  1312. /* Copy updated JMAXth (next IMAXth) column to Kth of W */
  1313. i__1 = *n - k + 1;
  1314. zcopy_(&i__1, &w[k + (k + 1) * w_dim1], &c__1, &w[k + k *
  1315. w_dim1], &c__1);
  1316. }
  1317. /* End pivot search loop body */
  1318. if (! done) {
  1319. goto L72;
  1320. }
  1321. }
  1322. /* END pivot search */
  1323. /* ============================================================ */
  1324. /* KK is the column of A where pivoting step stopped */
  1325. kk = k + kstep - 1;
  1326. /* Interchange rows and columns P and K (only for 2-by-2 pivot). */
  1327. /* Updated column P is already stored in column K of W. */
  1328. if (kstep == 2 && p != k) {
  1329. /* Copy non-updated column KK-1 to column P of submatrix A */
  1330. /* at step K. No need to copy element into columns */
  1331. /* K and K+1 of A for 2-by-2 pivot, since these columns */
  1332. /* will be later overwritten. */
  1333. i__1 = p + p * a_dim1;
  1334. i__2 = k + k * a_dim1;
  1335. d__1 = a[i__2].r;
  1336. a[i__1].r = d__1, a[i__1].i = 0.;
  1337. i__1 = p - k - 1;
  1338. zcopy_(&i__1, &a[k + 1 + k * a_dim1], &c__1, &a[p + (k + 1) *
  1339. a_dim1], lda);
  1340. i__1 = p - k - 1;
  1341. zlacgv_(&i__1, &a[p + (k + 1) * a_dim1], lda);
  1342. if (p < *n) {
  1343. i__1 = *n - p;
  1344. zcopy_(&i__1, &a[p + 1 + k * a_dim1], &c__1, &a[p + 1 + p
  1345. * a_dim1], &c__1);
  1346. }
  1347. /* Interchange rows K and P in first K-1 columns of A */
  1348. /* (columns K and K+1 of A for 2-by-2 pivot will be */
  1349. /* later overwritten). Interchange rows K and P */
  1350. /* in first KK columns of W. */
  1351. if (k > 1) {
  1352. i__1 = k - 1;
  1353. zswap_(&i__1, &a[k + a_dim1], lda, &a[p + a_dim1], lda);
  1354. }
  1355. zswap_(&kk, &w[k + w_dim1], ldw, &w[p + w_dim1], ldw);
  1356. }
  1357. /* Interchange rows and columns KP and KK. */
  1358. /* Updated column KP is already stored in column KK of W. */
  1359. if (kp != kk) {
  1360. /* Copy non-updated column KK to column KP of submatrix A */
  1361. /* at step K. No need to copy element into column K */
  1362. /* (or K and K+1 for 2-by-2 pivot) of A, since these columns */
  1363. /* will be later overwritten. */
  1364. i__1 = kp + kp * a_dim1;
  1365. i__2 = kk + kk * a_dim1;
  1366. d__1 = a[i__2].r;
  1367. a[i__1].r = d__1, a[i__1].i = 0.;
  1368. i__1 = kp - kk - 1;
  1369. zcopy_(&i__1, &a[kk + 1 + kk * a_dim1], &c__1, &a[kp + (kk +
  1370. 1) * a_dim1], lda);
  1371. i__1 = kp - kk - 1;
  1372. zlacgv_(&i__1, &a[kp + (kk + 1) * a_dim1], lda);
  1373. if (kp < *n) {
  1374. i__1 = *n - kp;
  1375. zcopy_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + 1
  1376. + kp * a_dim1], &c__1);
  1377. }
  1378. /* Interchange rows KK and KP in first K-1 columns of A */
  1379. /* (column K (or K and K+1 for 2-by-2 pivot) of A will be */
  1380. /* later overwritten). Interchange rows KK and KP */
  1381. /* in first KK columns of W. */
  1382. if (k > 1) {
  1383. i__1 = k - 1;
  1384. zswap_(&i__1, &a[kk + a_dim1], lda, &a[kp + a_dim1], lda);
  1385. }
  1386. zswap_(&kk, &w[kk + w_dim1], ldw, &w[kp + w_dim1], ldw);
  1387. }
  1388. if (kstep == 1) {
  1389. /* 1-by-1 pivot block D(k): column k of W now holds */
  1390. /* W(k) = L(k)*D(k), */
  1391. /* where L(k) is the k-th column of L */
  1392. /* (1) Store subdiag. elements of column L(k) */
  1393. /* and 1-by-1 block D(k) in column k of A. */
  1394. /* (NOTE: Diagonal element L(k,k) is a UNIT element */
  1395. /* and not stored) */
  1396. /* A(k,k) := D(k,k) = W(k,k) */
  1397. /* A(k+1:N,k) := L(k+1:N,k) = W(k+1:N,k)/D(k,k) */
  1398. /* (NOTE: No need to use for Hermitian matrix */
  1399. /* A( K, K ) = REAL( W( K, K) ) to separately copy diagonal */
  1400. /* element D(k,k) from W (potentially saves only one load)) */
  1401. i__1 = *n - k + 1;
  1402. zcopy_(&i__1, &w[k + k * w_dim1], &c__1, &a[k + k * a_dim1], &
  1403. c__1);
  1404. if (k < *n) {
  1405. /* (NOTE: No need to check if A(k,k) is NOT ZERO, */
  1406. /* since that was ensured earlier in pivot search: */
  1407. /* case A(k,k) = 0 falls into 2x2 pivot case(3)) */
  1408. /* Handle division by a small number */
  1409. i__1 = k + k * a_dim1;
  1410. t = a[i__1].r;
  1411. if (abs(t) >= sfmin) {
  1412. r1 = 1. / t;
  1413. i__1 = *n - k;
  1414. zdscal_(&i__1, &r1, &a[k + 1 + k * a_dim1], &c__1);
  1415. } else {
  1416. i__1 = *n;
  1417. for (ii = k + 1; ii <= i__1; ++ii) {
  1418. i__2 = ii + k * a_dim1;
  1419. i__3 = ii + k * a_dim1;
  1420. z__1.r = a[i__3].r / t, z__1.i = a[i__3].i / t;
  1421. a[i__2].r = z__1.r, a[i__2].i = z__1.i;
  1422. /* L74: */
  1423. }
  1424. }
  1425. /* (2) Conjugate column W(k) */
  1426. i__1 = *n - k;
  1427. zlacgv_(&i__1, &w[k + 1 + k * w_dim1], &c__1);
  1428. /* Store the subdiagonal element of D in array E */
  1429. i__1 = k;
  1430. e[i__1].r = 0., e[i__1].i = 0.;
  1431. }
  1432. } else {
  1433. /* 2-by-2 pivot block D(k): columns k and k+1 of W now hold */
  1434. /* ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k) */
  1435. /* where L(k) and L(k+1) are the k-th and (k+1)-th columns */
  1436. /* of L */
  1437. /* (1) Store L(k+2:N,k) and L(k+2:N,k+1) and 2-by-2 */
  1438. /* block D(k:k+1,k:k+1) in columns k and k+1 of A. */
  1439. /* NOTE: 2-by-2 diagonal block L(k:k+1,k:k+1) is a UNIT */
  1440. /* block and not stored. */
  1441. /* A(k:k+1,k:k+1) := D(k:k+1,k:k+1) = W(k:k+1,k:k+1) */
  1442. /* A(k+2:N,k:k+1) := L(k+2:N,k:k+1) = */
  1443. /* = W(k+2:N,k:k+1) * ( D(k:k+1,k:k+1)**(-1) ) */
  1444. if (k < *n - 1) {
  1445. /* Factor out the columns of the inverse of 2-by-2 pivot */
  1446. /* block D, so that each column contains 1, to reduce the */
  1447. /* number of FLOPS when we multiply panel */
  1448. /* ( W(kw-1) W(kw) ) by this inverse, i.e. by D**(-1). */
  1449. /* D**(-1) = ( d11 cj(d21) )**(-1) = */
  1450. /* ( d21 d22 ) */
  1451. /* = 1/(d11*d22-|d21|**2) * ( ( d22) (-cj(d21) ) ) = */
  1452. /* ( (-d21) ( d11 ) ) */
  1453. /* = 1/(|d21|**2) * 1/((d11/cj(d21))*(d22/d21)-1) * */
  1454. /* * ( d21*( d22/d21 ) conj(d21)*( - 1 ) ) = */
  1455. /* ( ( -1 ) ( d11/conj(d21) ) ) */
  1456. /* = 1/(|d21|**2) * 1/(D22*D11-1) * */
  1457. /* * ( d21*( D11 ) conj(d21)*( -1 ) ) = */
  1458. /* ( ( -1 ) ( D22 ) ) */
  1459. /* = (1/|d21|**2) * T * ( d21*( D11 ) conj(d21)*( -1 ) ) = */
  1460. /* ( ( -1 ) ( D22 ) ) */
  1461. /* = ( (T/conj(d21))*( D11 ) (T/d21)*( -1 ) ) = */
  1462. /* ( ( -1 ) ( D22 ) ) */
  1463. /* Handle division by a small number. (NOTE: order of */
  1464. /* operations is important) */
  1465. /* = ( T*(( D11 )/conj(D21)) T*(( -1 )/D21 ) ) */
  1466. /* ( (( -1 ) ) (( D22 ) ) ), */
  1467. /* where D11 = d22/d21, */
  1468. /* D22 = d11/conj(d21), */
  1469. /* D21 = d21, */
  1470. /* T = 1/(D22*D11-1). */
  1471. /* (NOTE: No need to check for division by ZERO, */
  1472. /* since that was ensured earlier in pivot search: */
  1473. /* (a) d21 != 0 in 2x2 pivot case(4), */
  1474. /* since |d21| should be larger than |d11| and |d22|; */
  1475. /* (b) (D22*D11 - 1) != 0, since from (a), */
  1476. /* both |D11| < 1, |D22| < 1, hence |D22*D11| << 1.) */
  1477. i__1 = k + 1 + k * w_dim1;
  1478. d21.r = w[i__1].r, d21.i = w[i__1].i;
  1479. z_div(&z__1, &w[k + 1 + (k + 1) * w_dim1], &d21);
  1480. d11.r = z__1.r, d11.i = z__1.i;
  1481. d_cnjg(&z__2, &d21);
  1482. z_div(&z__1, &w[k + k * w_dim1], &z__2);
  1483. d22.r = z__1.r, d22.i = z__1.i;
  1484. z__1.r = d11.r * d22.r - d11.i * d22.i, z__1.i = d11.r *
  1485. d22.i + d11.i * d22.r;
  1486. t = 1. / (z__1.r - 1.);
  1487. /* Update elements in columns A(k) and A(k+1) as */
  1488. /* dot products of rows of ( W(k) W(k+1) ) and columns */
  1489. /* of D**(-1) */
  1490. i__1 = *n;
  1491. for (j = k + 2; j <= i__1; ++j) {
  1492. i__2 = j + k * a_dim1;
  1493. i__3 = j + k * w_dim1;
  1494. z__4.r = d11.r * w[i__3].r - d11.i * w[i__3].i,
  1495. z__4.i = d11.r * w[i__3].i + d11.i * w[i__3]
  1496. .r;
  1497. i__4 = j + (k + 1) * w_dim1;
  1498. z__3.r = z__4.r - w[i__4].r, z__3.i = z__4.i - w[i__4]
  1499. .i;
  1500. d_cnjg(&z__5, &d21);
  1501. z_div(&z__2, &z__3, &z__5);
  1502. z__1.r = t * z__2.r, z__1.i = t * z__2.i;
  1503. a[i__2].r = z__1.r, a[i__2].i = z__1.i;
  1504. i__2 = j + (k + 1) * a_dim1;
  1505. i__3 = j + (k + 1) * w_dim1;
  1506. z__4.r = d22.r * w[i__3].r - d22.i * w[i__3].i,
  1507. z__4.i = d22.r * w[i__3].i + d22.i * w[i__3]
  1508. .r;
  1509. i__4 = j + k * w_dim1;
  1510. z__3.r = z__4.r - w[i__4].r, z__3.i = z__4.i - w[i__4]
  1511. .i;
  1512. z_div(&z__2, &z__3, &d21);
  1513. z__1.r = t * z__2.r, z__1.i = t * z__2.i;
  1514. a[i__2].r = z__1.r, a[i__2].i = z__1.i;
  1515. /* L80: */
  1516. }
  1517. }
  1518. /* Copy diagonal elements of D(K) to A, */
  1519. /* copy subdiagonal element of D(K) to E(K) and */
  1520. /* ZERO out subdiagonal entry of A */
  1521. i__1 = k + k * a_dim1;
  1522. i__2 = k + k * w_dim1;
  1523. a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
  1524. i__1 = k + 1 + k * a_dim1;
  1525. a[i__1].r = 0., a[i__1].i = 0.;
  1526. i__1 = k + 1 + (k + 1) * a_dim1;
  1527. i__2 = k + 1 + (k + 1) * w_dim1;
  1528. a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
  1529. i__1 = k;
  1530. i__2 = k + 1 + k * w_dim1;
  1531. e[i__1].r = w[i__2].r, e[i__1].i = w[i__2].i;
  1532. i__1 = k + 1;
  1533. e[i__1].r = 0., e[i__1].i = 0.;
  1534. /* (2) Conjugate columns W(k) and W(k+1) */
  1535. i__1 = *n - k;
  1536. zlacgv_(&i__1, &w[k + 1 + k * w_dim1], &c__1);
  1537. i__1 = *n - k - 1;
  1538. zlacgv_(&i__1, &w[k + 2 + (k + 1) * w_dim1], &c__1);
  1539. }
  1540. /* End column K is nonsingular */
  1541. }
  1542. /* Store details of the interchanges in IPIV */
  1543. if (kstep == 1) {
  1544. ipiv[k] = kp;
  1545. } else {
  1546. ipiv[k] = -p;
  1547. ipiv[k + 1] = -kp;
  1548. }
  1549. /* Increase K and return to the start of the main loop */
  1550. k += kstep;
  1551. goto L70;
  1552. L90:
  1553. /* Update the lower triangle of A22 (= A(k:n,k:n)) as */
  1554. /* A22 := A22 - L21*D*L21**H = A22 - L21*W**H */
  1555. /* computing blocks of NB columns at a time (note that conjg(W) is */
  1556. /* actually stored) */
  1557. i__1 = *n;
  1558. i__2 = *nb;
  1559. for (j = k; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  1560. /* Computing MIN */
  1561. i__3 = *nb, i__4 = *n - j + 1;
  1562. jb = f2cmin(i__3,i__4);
  1563. /* Update the lower triangle of the diagonal block */
  1564. i__3 = j + jb - 1;
  1565. for (jj = j; jj <= i__3; ++jj) {
  1566. i__4 = jj + jj * a_dim1;
  1567. i__5 = jj + jj * a_dim1;
  1568. d__1 = a[i__5].r;
  1569. a[i__4].r = d__1, a[i__4].i = 0.;
  1570. i__4 = j + jb - jj;
  1571. i__5 = k - 1;
  1572. z__1.r = -1., z__1.i = 0.;
  1573. zgemv_("No transpose", &i__4, &i__5, &z__1, &a[jj + a_dim1],
  1574. lda, &w[jj + w_dim1], ldw, &c_b1, &a[jj + jj * a_dim1]
  1575. , &c__1);
  1576. i__4 = jj + jj * a_dim1;
  1577. i__5 = jj + jj * a_dim1;
  1578. d__1 = a[i__5].r;
  1579. a[i__4].r = d__1, a[i__4].i = 0.;
  1580. /* L100: */
  1581. }
  1582. /* Update the rectangular subdiagonal block */
  1583. if (j + jb <= *n) {
  1584. i__3 = *n - j - jb + 1;
  1585. i__4 = k - 1;
  1586. z__1.r = -1., z__1.i = 0.;
  1587. zgemm_("No transpose", "Transpose", &i__3, &jb, &i__4, &z__1,
  1588. &a[j + jb + a_dim1], lda, &w[j + w_dim1], ldw, &c_b1,
  1589. &a[j + jb + j * a_dim1], lda);
  1590. }
  1591. /* L110: */
  1592. }
  1593. /* Set KB to the number of columns factorized */
  1594. *kb = k - 1;
  1595. }
  1596. return 0;
  1597. /* End of ZLAHEF_RK */
  1598. } /* zlahef_rk__ */