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.c 49 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638
  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 computes a partial factorization of a complex Hermitian indefinite matrix using the Bunc
  383. h-Kaufman diagonal pivoting method (blocked algorithm, calling Level 3 BLAS). */
  384. /* =========== DOCUMENTATION =========== */
  385. /* Online html documentation available at */
  386. /* http://www.netlib.org/lapack/explore-html/ */
  387. /* > \htmlonly */
  388. /* > Download ZLAHEF + dependencies */
  389. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlahef.
  390. f"> */
  391. /* > [TGZ]</a> */
  392. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlahef.
  393. f"> */
  394. /* > [ZIP]</a> */
  395. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlahef.
  396. f"> */
  397. /* > [TXT]</a> */
  398. /* > \endhtmlonly */
  399. /* Definition: */
  400. /* =========== */
  401. /* SUBROUTINE ZLAHEF( 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*16 A( LDA, * ), W( LDW, * ) */
  406. /* > \par Purpose: */
  407. /* ============= */
  408. /* > */
  409. /* > \verbatim */
  410. /* > */
  411. /* > ZLAHEF computes a partial factorization of a complex Hermitian */
  412. /* > matrix A using the Bunch-Kaufman diagonal pivoting method. The */
  413. /* > 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. /* > Note that U**H denotes the conjugate transpose of U. */
  424. /* > */
  425. /* > ZLAHEF is an auxiliary routine called by ZHETRF. 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. /* > Hermitian 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*16 array, dimension (LDA,N) */
  464. /* > On entry, the Hermitian 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*16 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 December 2016 */
  532. /* > \ingroup complex16HEcomputational */
  533. /* > \par Contributors: */
  534. /* ================== */
  535. /* > */
  536. /* > \verbatim */
  537. /* > */
  538. /* > December 2016, Igor Kozachenko, */
  539. /* > Computer Science Division, */
  540. /* > University of California, Berkeley */
  541. /* > \endverbatim */
  542. /* ===================================================================== */
  543. /* Subroutine */ int zlahef_(char *uplo, integer *n, integer *nb, integer *kb,
  544. doublecomplex *a, integer *lda, integer *ipiv, doublecomplex *w,
  545. integer *ldw, 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. doublereal d__1, d__2, d__3, d__4;
  550. doublecomplex z__1, z__2, z__3, z__4;
  551. /* Local variables */
  552. integer imax, jmax, j, k;
  553. doublereal t, alpha;
  554. extern logical lsame_(char *, char *);
  555. extern /* Subroutine */ int zgemm_(char *, char *, integer *, integer *,
  556. integer *, doublecomplex *, doublecomplex *, integer *,
  557. doublecomplex *, integer *, doublecomplex *, doublecomplex *,
  558. integer *);
  559. integer kstep;
  560. extern /* Subroutine */ int zgemv_(char *, integer *, integer *,
  561. doublecomplex *, doublecomplex *, integer *, doublecomplex *,
  562. integer *, doublecomplex *, doublecomplex *, integer *);
  563. doublereal r1;
  564. extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *,
  565. doublecomplex *, integer *), zswap_(integer *, doublecomplex *,
  566. integer *, doublecomplex *, integer *);
  567. doublecomplex d11, d21, d22;
  568. integer jb, jj, kk, jp, kp;
  569. doublereal absakk;
  570. integer kw;
  571. extern /* Subroutine */ int zdscal_(integer *, doublereal *,
  572. doublecomplex *, integer *);
  573. doublereal colmax;
  574. extern /* Subroutine */ int zlacgv_(integer *, doublecomplex *, integer *)
  575. ;
  576. extern integer izamax_(integer *, doublecomplex *, integer *);
  577. doublereal rowmax;
  578. integer kkw;
  579. /* -- LAPACK computational routine (version 3.7.0) -- */
  580. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  581. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  582. /* December 2016 */
  583. /* ===================================================================== */
  584. /* Parameter adjustments */
  585. a_dim1 = *lda;
  586. a_offset = 1 + a_dim1 * 1;
  587. a -= a_offset;
  588. --ipiv;
  589. w_dim1 = *ldw;
  590. w_offset = 1 + w_dim1 * 1;
  591. w -= w_offset;
  592. /* Function Body */
  593. *info = 0;
  594. /* Initialize ALPHA for use in choosing pivot block size. */
  595. alpha = (sqrt(17.) + 1.) / 8.;
  596. if (lsame_(uplo, "U")) {
  597. /* Factorize the trailing columns of A using the upper triangle */
  598. /* of A and working backwards, and compute the matrix W = U12*D */
  599. /* for use in updating A11 (note that conjg(W) is actually stored) */
  600. /* K is the main loop index, decreasing from N in steps of 1 or 2 */
  601. /* KW is the column of W which corresponds to column K of A */
  602. k = *n;
  603. L10:
  604. kw = *nb + k - *n;
  605. /* Exit from loop */
  606. if (k <= *n - *nb + 1 && *nb < *n || k < 1) {
  607. goto L30;
  608. }
  609. kstep = 1;
  610. /* Copy column K of A to column KW of W and update it */
  611. i__1 = k - 1;
  612. zcopy_(&i__1, &a[k * a_dim1 + 1], &c__1, &w[kw * w_dim1 + 1], &c__1);
  613. i__1 = k + kw * w_dim1;
  614. i__2 = k + k * a_dim1;
  615. d__1 = a[i__2].r;
  616. w[i__1].r = d__1, w[i__1].i = 0.;
  617. if (k < *n) {
  618. i__1 = *n - k;
  619. z__1.r = -1., z__1.i = 0.;
  620. zgemv_("No transpose", &k, &i__1, &z__1, &a[(k + 1) * a_dim1 + 1],
  621. lda, &w[k + (kw + 1) * w_dim1], ldw, &c_b1, &w[kw *
  622. w_dim1 + 1], &c__1);
  623. i__1 = k + kw * w_dim1;
  624. i__2 = k + kw * w_dim1;
  625. d__1 = w[i__2].r;
  626. w[i__1].r = d__1, w[i__1].i = 0.;
  627. }
  628. /* Determine rows and columns to be interchanged and whether */
  629. /* a 1-by-1 or 2-by-2 pivot block will be used */
  630. i__1 = k + kw * w_dim1;
  631. absakk = (d__1 = w[i__1].r, abs(d__1));
  632. /* IMAX is the row-index of the largest off-diagonal element in */
  633. /* column K, and COLMAX is its absolute value. */
  634. /* Determine both COLMAX and IMAX. */
  635. if (k > 1) {
  636. i__1 = k - 1;
  637. imax = izamax_(&i__1, &w[kw * w_dim1 + 1], &c__1);
  638. i__1 = imax + kw * w_dim1;
  639. colmax = (d__1 = w[i__1].r, abs(d__1)) + (d__2 = d_imag(&w[imax +
  640. kw * w_dim1]), abs(d__2));
  641. } else {
  642. colmax = 0.;
  643. }
  644. if (f2cmax(absakk,colmax) == 0.) {
  645. /* Column K is zero or underflow: set INFO and continue */
  646. if (*info == 0) {
  647. *info = k;
  648. }
  649. kp = k;
  650. i__1 = k + k * a_dim1;
  651. i__2 = k + k * a_dim1;
  652. d__1 = a[i__2].r;
  653. a[i__1].r = d__1, a[i__1].i = 0.;
  654. } else {
  655. /* ============================================================ */
  656. /* BEGIN pivot search */
  657. /* Case(1) */
  658. if (absakk >= alpha * colmax) {
  659. /* no interchange, use 1-by-1 pivot block */
  660. kp = k;
  661. } else {
  662. /* BEGIN pivot search along IMAX row */
  663. /* Copy column IMAX to column KW-1 of W and update it */
  664. i__1 = imax - 1;
  665. zcopy_(&i__1, &a[imax * a_dim1 + 1], &c__1, &w[(kw - 1) *
  666. w_dim1 + 1], &c__1);
  667. i__1 = imax + (kw - 1) * w_dim1;
  668. i__2 = imax + imax * a_dim1;
  669. d__1 = a[i__2].r;
  670. w[i__1].r = d__1, w[i__1].i = 0.;
  671. i__1 = k - imax;
  672. zcopy_(&i__1, &a[imax + (imax + 1) * a_dim1], lda, &w[imax +
  673. 1 + (kw - 1) * w_dim1], &c__1);
  674. i__1 = k - imax;
  675. zlacgv_(&i__1, &w[imax + 1 + (kw - 1) * w_dim1], &c__1);
  676. if (k < *n) {
  677. i__1 = *n - k;
  678. z__1.r = -1., z__1.i = 0.;
  679. zgemv_("No transpose", &k, &i__1, &z__1, &a[(k + 1) *
  680. a_dim1 + 1], lda, &w[imax + (kw + 1) * w_dim1],
  681. ldw, &c_b1, &w[(kw - 1) * w_dim1 + 1], &c__1);
  682. i__1 = imax + (kw - 1) * w_dim1;
  683. i__2 = imax + (kw - 1) * w_dim1;
  684. d__1 = w[i__2].r;
  685. w[i__1].r = d__1, w[i__1].i = 0.;
  686. }
  687. /* JMAX is the column-index of the largest off-diagonal */
  688. /* element in row IMAX, and ROWMAX is its absolute value. */
  689. /* Determine only ROWMAX. */
  690. i__1 = k - imax;
  691. jmax = imax + izamax_(&i__1, &w[imax + 1 + (kw - 1) * w_dim1],
  692. &c__1);
  693. i__1 = jmax + (kw - 1) * w_dim1;
  694. rowmax = (d__1 = w[i__1].r, abs(d__1)) + (d__2 = d_imag(&w[
  695. jmax + (kw - 1) * w_dim1]), abs(d__2));
  696. if (imax > 1) {
  697. i__1 = imax - 1;
  698. jmax = izamax_(&i__1, &w[(kw - 1) * w_dim1 + 1], &c__1);
  699. /* Computing MAX */
  700. i__1 = jmax + (kw - 1) * w_dim1;
  701. d__3 = rowmax, d__4 = (d__1 = w[i__1].r, abs(d__1)) + (
  702. d__2 = d_imag(&w[jmax + (kw - 1) * w_dim1]), abs(
  703. d__2));
  704. rowmax = f2cmax(d__3,d__4);
  705. }
  706. /* Case(2) */
  707. if (absakk >= alpha * colmax * (colmax / rowmax)) {
  708. /* no interchange, use 1-by-1 pivot block */
  709. kp = k;
  710. /* Case(3) */
  711. } else /* if(complicated condition) */ {
  712. i__1 = imax + (kw - 1) * w_dim1;
  713. if ((d__1 = w[i__1].r, abs(d__1)) >= alpha * rowmax) {
  714. /* interchange rows and columns K and IMAX, use 1-by-1 */
  715. /* pivot block */
  716. kp = imax;
  717. /* copy column KW-1 of W to column KW of W */
  718. zcopy_(&k, &w[(kw - 1) * w_dim1 + 1], &c__1, &w[kw *
  719. w_dim1 + 1], &c__1);
  720. /* Case(4) */
  721. } else {
  722. /* interchange rows and columns K-1 and IMAX, use 2-by-2 */
  723. /* pivot block */
  724. kp = imax;
  725. kstep = 2;
  726. }
  727. }
  728. /* END pivot search along IMAX row */
  729. }
  730. /* END pivot search */
  731. /* ============================================================ */
  732. /* KK is the column of A where pivoting step stopped */
  733. kk = k - kstep + 1;
  734. /* KKW is the column of W which corresponds to column KK of A */
  735. kkw = *nb + kk - *n;
  736. /* Interchange rows and columns KP and KK. */
  737. /* Updated column KP is already stored in column KKW of W. */
  738. if (kp != kk) {
  739. /* Copy non-updated column KK to column KP of submatrix A */
  740. /* at step K. No need to copy element into column K */
  741. /* (or K and K-1 for 2-by-2 pivot) of A, since these columns */
  742. /* will be later overwritten. */
  743. i__1 = kp + kp * a_dim1;
  744. i__2 = kk + kk * a_dim1;
  745. d__1 = a[i__2].r;
  746. a[i__1].r = d__1, a[i__1].i = 0.;
  747. i__1 = kk - 1 - kp;
  748. zcopy_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + (kp +
  749. 1) * a_dim1], lda);
  750. i__1 = kk - 1 - kp;
  751. zlacgv_(&i__1, &a[kp + (kp + 1) * a_dim1], lda);
  752. if (kp > 1) {
  753. i__1 = kp - 1;
  754. zcopy_(&i__1, &a[kk * a_dim1 + 1], &c__1, &a[kp * a_dim1
  755. + 1], &c__1);
  756. }
  757. /* Interchange rows KK and KP in last K+1 to N columns of A */
  758. /* (columns K (or K and K-1 for 2-by-2 pivot) of A will be */
  759. /* later overwritten). Interchange rows KK and KP */
  760. /* in last KKW to NB columns of W. */
  761. if (k < *n) {
  762. i__1 = *n - k;
  763. zswap_(&i__1, &a[kk + (k + 1) * a_dim1], lda, &a[kp + (k
  764. + 1) * a_dim1], lda);
  765. }
  766. i__1 = *n - kk + 1;
  767. zswap_(&i__1, &w[kk + kkw * w_dim1], ldw, &w[kp + kkw *
  768. w_dim1], ldw);
  769. }
  770. if (kstep == 1) {
  771. /* 1-by-1 pivot block D(k): column kw of W now holds */
  772. /* W(kw) = U(k)*D(k), */
  773. /* where U(k) is the k-th column of U */
  774. /* (1) Store subdiag. elements of column U(k) */
  775. /* and 1-by-1 block D(k) in column k of A. */
  776. /* (NOTE: Diagonal element U(k,k) is a UNIT element */
  777. /* and not stored) */
  778. /* A(k,k) := D(k,k) = W(k,kw) */
  779. /* A(1:k-1,k) := U(1:k-1,k) = W(1:k-1,kw)/D(k,k) */
  780. /* (NOTE: No need to use for Hermitian matrix */
  781. /* A( K, K ) = DBLE( W( K, K) ) to separately copy diagonal */
  782. /* element D(k,k) from W (potentially saves only one load)) */
  783. zcopy_(&k, &w[kw * w_dim1 + 1], &c__1, &a[k * a_dim1 + 1], &
  784. c__1);
  785. if (k > 1) {
  786. /* (NOTE: No need to check if A(k,k) is NOT ZERO, */
  787. /* since that was ensured earlier in pivot search: */
  788. /* case A(k,k) = 0 falls into 2x2 pivot case(4)) */
  789. i__1 = k + k * a_dim1;
  790. r1 = 1. / a[i__1].r;
  791. i__1 = k - 1;
  792. zdscal_(&i__1, &r1, &a[k * a_dim1 + 1], &c__1);
  793. /* (2) Conjugate column W(kw) */
  794. i__1 = k - 1;
  795. zlacgv_(&i__1, &w[kw * w_dim1 + 1], &c__1);
  796. }
  797. } else {
  798. /* 2-by-2 pivot block D(k): columns kw and kw-1 of W now hold */
  799. /* ( W(kw-1) W(kw) ) = ( U(k-1) U(k) )*D(k) */
  800. /* where U(k) and U(k-1) are the k-th and (k-1)-th columns */
  801. /* of U */
  802. /* (1) Store U(1:k-2,k-1) and U(1:k-2,k) and 2-by-2 */
  803. /* block D(k-1:k,k-1:k) in columns k-1 and k of A. */
  804. /* (NOTE: 2-by-2 diagonal block U(k-1:k,k-1:k) is a UNIT */
  805. /* block and not stored) */
  806. /* A(k-1:k,k-1:k) := D(k-1:k,k-1:k) = W(k-1:k,kw-1:kw) */
  807. /* A(1:k-2,k-1:k) := U(1:k-2,k:k-1:k) = */
  808. /* = W(1:k-2,kw-1:kw) * ( D(k-1:k,k-1:k)**(-1) ) */
  809. if (k > 2) {
  810. /* Factor out the columns of the inverse of 2-by-2 pivot */
  811. /* block D, so that each column contains 1, to reduce the */
  812. /* number of FLOPS when we multiply panel */
  813. /* ( W(kw-1) W(kw) ) by this inverse, i.e. by D**(-1). */
  814. /* D**(-1) = ( d11 cj(d21) )**(-1) = */
  815. /* ( d21 d22 ) */
  816. /* = 1/(d11*d22-|d21|**2) * ( ( d22) (-cj(d21) ) ) = */
  817. /* ( (-d21) ( d11 ) ) */
  818. /* = 1/(|d21|**2) * 1/((d11/cj(d21))*(d22/d21)-1) * */
  819. /* * ( d21*( d22/d21 ) conj(d21)*( - 1 ) ) = */
  820. /* ( ( -1 ) ( d11/conj(d21) ) ) */
  821. /* = 1/(|d21|**2) * 1/(D22*D11-1) * */
  822. /* * ( d21*( D11 ) conj(d21)*( -1 ) ) = */
  823. /* ( ( -1 ) ( D22 ) ) */
  824. /* = (1/|d21|**2) * T * ( d21*( D11 ) conj(d21)*( -1 ) ) = */
  825. /* ( ( -1 ) ( D22 ) ) */
  826. /* = ( (T/conj(d21))*( D11 ) (T/d21)*( -1 ) ) = */
  827. /* ( ( -1 ) ( D22 ) ) */
  828. /* = ( conj(D21)*( D11 ) D21*( -1 ) ) */
  829. /* ( ( -1 ) ( D22 ) ), */
  830. /* where D11 = d22/d21, */
  831. /* D22 = d11/conj(d21), */
  832. /* D21 = T/d21, */
  833. /* T = 1/(D22*D11-1). */
  834. /* (NOTE: No need to check for division by ZERO, */
  835. /* since that was ensured earlier in pivot search: */
  836. /* (a) d21 != 0, since in 2x2 pivot case(4) */
  837. /* |d21| should be larger than |d11| and |d22|; */
  838. /* (b) (D22*D11 - 1) != 0, since from (a), */
  839. /* both |D11| < 1, |D22| < 1, hence |D22*D11| << 1.) */
  840. i__1 = k - 1 + kw * w_dim1;
  841. d21.r = w[i__1].r, d21.i = w[i__1].i;
  842. d_cnjg(&z__2, &d21);
  843. z_div(&z__1, &w[k + kw * w_dim1], &z__2);
  844. d11.r = z__1.r, d11.i = z__1.i;
  845. z_div(&z__1, &w[k - 1 + (kw - 1) * w_dim1], &d21);
  846. d22.r = z__1.r, d22.i = z__1.i;
  847. z__1.r = d11.r * d22.r - d11.i * d22.i, z__1.i = d11.r *
  848. d22.i + d11.i * d22.r;
  849. t = 1. / (z__1.r - 1.);
  850. z__2.r = t, z__2.i = 0.;
  851. z_div(&z__1, &z__2, &d21);
  852. d21.r = z__1.r, d21.i = z__1.i;
  853. /* Update elements in columns A(k-1) and A(k) as */
  854. /* dot products of rows of ( W(kw-1) W(kw) ) and columns */
  855. /* of D**(-1) */
  856. i__1 = k - 2;
  857. for (j = 1; j <= i__1; ++j) {
  858. i__2 = j + (k - 1) * a_dim1;
  859. i__3 = j + (kw - 1) * w_dim1;
  860. z__3.r = d11.r * w[i__3].r - d11.i * w[i__3].i,
  861. z__3.i = d11.r * w[i__3].i + d11.i * w[i__3]
  862. .r;
  863. i__4 = j + kw * w_dim1;
  864. z__2.r = z__3.r - w[i__4].r, z__2.i = z__3.i - w[i__4]
  865. .i;
  866. z__1.r = d21.r * z__2.r - d21.i * z__2.i, z__1.i =
  867. d21.r * z__2.i + d21.i * z__2.r;
  868. a[i__2].r = z__1.r, a[i__2].i = z__1.i;
  869. i__2 = j + k * a_dim1;
  870. d_cnjg(&z__2, &d21);
  871. i__3 = j + kw * w_dim1;
  872. z__4.r = d22.r * w[i__3].r - d22.i * w[i__3].i,
  873. z__4.i = d22.r * w[i__3].i + d22.i * w[i__3]
  874. .r;
  875. i__4 = j + (kw - 1) * w_dim1;
  876. z__3.r = z__4.r - w[i__4].r, z__3.i = z__4.i - w[i__4]
  877. .i;
  878. z__1.r = z__2.r * z__3.r - z__2.i * z__3.i, z__1.i =
  879. z__2.r * z__3.i + z__2.i * z__3.r;
  880. a[i__2].r = z__1.r, a[i__2].i = z__1.i;
  881. /* L20: */
  882. }
  883. }
  884. /* Copy D(k) to A */
  885. i__1 = k - 1 + (k - 1) * a_dim1;
  886. i__2 = k - 1 + (kw - 1) * w_dim1;
  887. a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
  888. i__1 = k - 1 + k * a_dim1;
  889. i__2 = k - 1 + kw * w_dim1;
  890. a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
  891. i__1 = k + k * a_dim1;
  892. i__2 = k + kw * w_dim1;
  893. a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
  894. /* (2) Conjugate columns W(kw) and W(kw-1) */
  895. i__1 = k - 1;
  896. zlacgv_(&i__1, &w[kw * w_dim1 + 1], &c__1);
  897. i__1 = k - 2;
  898. zlacgv_(&i__1, &w[(kw - 1) * w_dim1 + 1], &c__1);
  899. }
  900. }
  901. /* Store details of the interchanges in IPIV */
  902. if (kstep == 1) {
  903. ipiv[k] = kp;
  904. } else {
  905. ipiv[k] = -kp;
  906. ipiv[k - 1] = -kp;
  907. }
  908. /* Decrease K and return to the start of the main loop */
  909. k -= kstep;
  910. goto L10;
  911. L30:
  912. /* Update the upper triangle of A11 (= A(1:k,1:k)) as */
  913. /* A11 := A11 - U12*D*U12**H = A11 - U12*W**H */
  914. /* computing blocks of NB columns at a time (note that conjg(W) is */
  915. /* actually stored) */
  916. i__1 = -(*nb);
  917. for (j = (k - 1) / *nb * *nb + 1; i__1 < 0 ? j >= 1 : j <= 1; j +=
  918. i__1) {
  919. /* Computing MIN */
  920. i__2 = *nb, i__3 = k - j + 1;
  921. jb = f2cmin(i__2,i__3);
  922. /* Update the upper triangle of the diagonal block */
  923. i__2 = j + jb - 1;
  924. for (jj = j; jj <= i__2; ++jj) {
  925. i__3 = jj + jj * a_dim1;
  926. i__4 = jj + jj * a_dim1;
  927. d__1 = a[i__4].r;
  928. a[i__3].r = d__1, a[i__3].i = 0.;
  929. i__3 = jj - j + 1;
  930. i__4 = *n - k;
  931. z__1.r = -1., z__1.i = 0.;
  932. zgemv_("No transpose", &i__3, &i__4, &z__1, &a[j + (k + 1) *
  933. a_dim1], lda, &w[jj + (kw + 1) * w_dim1], ldw, &c_b1,
  934. &a[j + jj * a_dim1], &c__1);
  935. i__3 = jj + jj * a_dim1;
  936. i__4 = jj + jj * a_dim1;
  937. d__1 = a[i__4].r;
  938. a[i__3].r = d__1, a[i__3].i = 0.;
  939. /* L40: */
  940. }
  941. /* Update the rectangular superdiagonal block */
  942. i__2 = j - 1;
  943. i__3 = *n - k;
  944. z__1.r = -1., z__1.i = 0.;
  945. zgemm_("No transpose", "Transpose", &i__2, &jb, &i__3, &z__1, &a[(
  946. k + 1) * a_dim1 + 1], lda, &w[j + (kw + 1) * w_dim1], ldw,
  947. &c_b1, &a[j * a_dim1 + 1], lda);
  948. /* L50: */
  949. }
  950. /* Put U12 in standard form by partially undoing the interchanges */
  951. /* in columns k+1:n looping backwards from k+1 to n */
  952. j = k + 1;
  953. L60:
  954. /* Undo the interchanges (if any) of rows JJ and JP at each */
  955. /* step J */
  956. /* (Here, J is a diagonal index) */
  957. jj = j;
  958. jp = ipiv[j];
  959. if (jp < 0) {
  960. jp = -jp;
  961. /* (Here, J is a diagonal index) */
  962. ++j;
  963. }
  964. /* (NOTE: Here, J is used to determine row length. Length N-J+1 */
  965. /* of the rows to swap back doesn't include diagonal element) */
  966. ++j;
  967. if (jp != jj && j <= *n) {
  968. i__1 = *n - j + 1;
  969. zswap_(&i__1, &a[jp + j * a_dim1], lda, &a[jj + j * a_dim1], lda);
  970. }
  971. if (j < *n) {
  972. goto L60;
  973. }
  974. /* Set KB to the number of columns factorized */
  975. *kb = *n - k;
  976. } else {
  977. /* Factorize the leading columns of A using the lower triangle */
  978. /* of A and working forwards, and compute the matrix W = L21*D */
  979. /* for use in updating A22 (note that conjg(W) is actually stored) */
  980. /* K is the main loop index, increasing from 1 in steps of 1 or 2 */
  981. k = 1;
  982. L70:
  983. /* Exit from loop */
  984. if (k >= *nb && *nb < *n || k > *n) {
  985. goto L90;
  986. }
  987. kstep = 1;
  988. /* Copy column K of A to column K of W and update it */
  989. i__1 = k + k * w_dim1;
  990. i__2 = k + k * a_dim1;
  991. d__1 = a[i__2].r;
  992. w[i__1].r = d__1, w[i__1].i = 0.;
  993. if (k < *n) {
  994. i__1 = *n - k;
  995. zcopy_(&i__1, &a[k + 1 + k * a_dim1], &c__1, &w[k + 1 + k *
  996. w_dim1], &c__1);
  997. }
  998. i__1 = *n - k + 1;
  999. i__2 = k - 1;
  1000. z__1.r = -1., z__1.i = 0.;
  1001. zgemv_("No transpose", &i__1, &i__2, &z__1, &a[k + a_dim1], lda, &w[k
  1002. + w_dim1], ldw, &c_b1, &w[k + k * w_dim1], &c__1);
  1003. i__1 = k + k * w_dim1;
  1004. i__2 = k + k * w_dim1;
  1005. d__1 = w[i__2].r;
  1006. w[i__1].r = d__1, w[i__1].i = 0.;
  1007. /* Determine rows and columns to be interchanged and whether */
  1008. /* a 1-by-1 or 2-by-2 pivot block will be used */
  1009. i__1 = k + k * w_dim1;
  1010. absakk = (d__1 = w[i__1].r, abs(d__1));
  1011. /* IMAX is the row-index of the largest off-diagonal element in */
  1012. /* column K, and COLMAX is its absolute value. */
  1013. /* Determine both COLMAX and IMAX. */
  1014. if (k < *n) {
  1015. i__1 = *n - k;
  1016. imax = k + izamax_(&i__1, &w[k + 1 + k * w_dim1], &c__1);
  1017. i__1 = imax + k * w_dim1;
  1018. colmax = (d__1 = w[i__1].r, abs(d__1)) + (d__2 = d_imag(&w[imax +
  1019. k * w_dim1]), abs(d__2));
  1020. } else {
  1021. colmax = 0.;
  1022. }
  1023. if (f2cmax(absakk,colmax) == 0.) {
  1024. /* Column K is zero or underflow: set INFO and continue */
  1025. if (*info == 0) {
  1026. *info = k;
  1027. }
  1028. kp = k;
  1029. i__1 = k + k * a_dim1;
  1030. i__2 = k + k * a_dim1;
  1031. d__1 = a[i__2].r;
  1032. a[i__1].r = d__1, a[i__1].i = 0.;
  1033. } else {
  1034. /* ============================================================ */
  1035. /* BEGIN pivot search */
  1036. /* Case(1) */
  1037. if (absakk >= alpha * colmax) {
  1038. /* no interchange, use 1-by-1 pivot block */
  1039. kp = k;
  1040. } else {
  1041. /* BEGIN pivot search along IMAX row */
  1042. /* Copy column IMAX to column K+1 of W and update it */
  1043. i__1 = imax - k;
  1044. zcopy_(&i__1, &a[imax + k * a_dim1], lda, &w[k + (k + 1) *
  1045. w_dim1], &c__1);
  1046. i__1 = imax - k;
  1047. zlacgv_(&i__1, &w[k + (k + 1) * w_dim1], &c__1);
  1048. i__1 = imax + (k + 1) * w_dim1;
  1049. i__2 = imax + imax * a_dim1;
  1050. d__1 = a[i__2].r;
  1051. w[i__1].r = d__1, w[i__1].i = 0.;
  1052. if (imax < *n) {
  1053. i__1 = *n - imax;
  1054. zcopy_(&i__1, &a[imax + 1 + imax * a_dim1], &c__1, &w[
  1055. imax + 1 + (k + 1) * w_dim1], &c__1);
  1056. }
  1057. i__1 = *n - k + 1;
  1058. i__2 = k - 1;
  1059. z__1.r = -1., z__1.i = 0.;
  1060. zgemv_("No transpose", &i__1, &i__2, &z__1, &a[k + a_dim1],
  1061. lda, &w[imax + w_dim1], ldw, &c_b1, &w[k + (k + 1) *
  1062. w_dim1], &c__1);
  1063. i__1 = imax + (k + 1) * w_dim1;
  1064. i__2 = imax + (k + 1) * w_dim1;
  1065. d__1 = w[i__2].r;
  1066. w[i__1].r = d__1, w[i__1].i = 0.;
  1067. /* JMAX is the column-index of the largest off-diagonal */
  1068. /* element in row IMAX, and ROWMAX is its absolute value. */
  1069. /* Determine only ROWMAX. */
  1070. i__1 = imax - k;
  1071. jmax = k - 1 + izamax_(&i__1, &w[k + (k + 1) * w_dim1], &c__1)
  1072. ;
  1073. i__1 = jmax + (k + 1) * w_dim1;
  1074. rowmax = (d__1 = w[i__1].r, abs(d__1)) + (d__2 = d_imag(&w[
  1075. jmax + (k + 1) * w_dim1]), abs(d__2));
  1076. if (imax < *n) {
  1077. i__1 = *n - imax;
  1078. jmax = imax + izamax_(&i__1, &w[imax + 1 + (k + 1) *
  1079. w_dim1], &c__1);
  1080. /* Computing MAX */
  1081. i__1 = jmax + (k + 1) * w_dim1;
  1082. d__3 = rowmax, d__4 = (d__1 = w[i__1].r, abs(d__1)) + (
  1083. d__2 = d_imag(&w[jmax + (k + 1) * w_dim1]), abs(
  1084. d__2));
  1085. rowmax = f2cmax(d__3,d__4);
  1086. }
  1087. /* Case(2) */
  1088. if (absakk >= alpha * colmax * (colmax / rowmax)) {
  1089. /* no interchange, use 1-by-1 pivot block */
  1090. kp = k;
  1091. /* Case(3) */
  1092. } else /* if(complicated condition) */ {
  1093. i__1 = imax + (k + 1) * w_dim1;
  1094. if ((d__1 = w[i__1].r, abs(d__1)) >= alpha * rowmax) {
  1095. /* interchange rows and columns K and IMAX, use 1-by-1 */
  1096. /* pivot block */
  1097. kp = imax;
  1098. /* copy column K+1 of W to column K of W */
  1099. i__1 = *n - k + 1;
  1100. zcopy_(&i__1, &w[k + (k + 1) * w_dim1], &c__1, &w[k +
  1101. k * w_dim1], &c__1);
  1102. /* Case(4) */
  1103. } else {
  1104. /* interchange rows and columns K+1 and IMAX, use 2-by-2 */
  1105. /* pivot block */
  1106. kp = imax;
  1107. kstep = 2;
  1108. }
  1109. }
  1110. /* END pivot search along IMAX row */
  1111. }
  1112. /* END pivot search */
  1113. /* ============================================================ */
  1114. /* KK is the column of A where pivoting step stopped */
  1115. kk = k + kstep - 1;
  1116. /* Interchange rows and columns KP and KK. */
  1117. /* Updated column KP is already stored in column KK of W. */
  1118. if (kp != kk) {
  1119. /* Copy non-updated column KK to column KP of submatrix A */
  1120. /* at step K. No need to copy element into column K */
  1121. /* (or K and K+1 for 2-by-2 pivot) of A, since these columns */
  1122. /* will be later overwritten. */
  1123. i__1 = kp + kp * a_dim1;
  1124. i__2 = kk + kk * a_dim1;
  1125. d__1 = a[i__2].r;
  1126. a[i__1].r = d__1, a[i__1].i = 0.;
  1127. i__1 = kp - kk - 1;
  1128. zcopy_(&i__1, &a[kk + 1 + kk * a_dim1], &c__1, &a[kp + (kk +
  1129. 1) * a_dim1], lda);
  1130. i__1 = kp - kk - 1;
  1131. zlacgv_(&i__1, &a[kp + (kk + 1) * a_dim1], lda);
  1132. if (kp < *n) {
  1133. i__1 = *n - kp;
  1134. zcopy_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + 1
  1135. + kp * a_dim1], &c__1);
  1136. }
  1137. /* Interchange rows KK and KP in first K-1 columns of A */
  1138. /* (columns K (or K and K+1 for 2-by-2 pivot) of A will be */
  1139. /* later overwritten). Interchange rows KK and KP */
  1140. /* in first KK columns of W. */
  1141. if (k > 1) {
  1142. i__1 = k - 1;
  1143. zswap_(&i__1, &a[kk + a_dim1], lda, &a[kp + a_dim1], lda);
  1144. }
  1145. zswap_(&kk, &w[kk + w_dim1], ldw, &w[kp + w_dim1], ldw);
  1146. }
  1147. if (kstep == 1) {
  1148. /* 1-by-1 pivot block D(k): column k of W now holds */
  1149. /* W(k) = L(k)*D(k), */
  1150. /* where L(k) is the k-th column of L */
  1151. /* (1) Store subdiag. elements of column L(k) */
  1152. /* and 1-by-1 block D(k) in column k of A. */
  1153. /* (NOTE: Diagonal element L(k,k) is a UNIT element */
  1154. /* and not stored) */
  1155. /* A(k,k) := D(k,k) = W(k,k) */
  1156. /* A(k+1:N,k) := L(k+1:N,k) = W(k+1:N,k)/D(k,k) */
  1157. /* (NOTE: No need to use for Hermitian matrix */
  1158. /* A( K, K ) = DBLE( W( K, K) ) to separately copy diagonal */
  1159. /* element D(k,k) from W (potentially saves only one load)) */
  1160. i__1 = *n - k + 1;
  1161. zcopy_(&i__1, &w[k + k * w_dim1], &c__1, &a[k + k * a_dim1], &
  1162. c__1);
  1163. if (k < *n) {
  1164. /* (NOTE: No need to check if A(k,k) is NOT ZERO, */
  1165. /* since that was ensured earlier in pivot search: */
  1166. /* case A(k,k) = 0 falls into 2x2 pivot case(4)) */
  1167. i__1 = k + k * a_dim1;
  1168. r1 = 1. / a[i__1].r;
  1169. i__1 = *n - k;
  1170. zdscal_(&i__1, &r1, &a[k + 1 + k * a_dim1], &c__1);
  1171. /* (2) Conjugate column W(k) */
  1172. i__1 = *n - k;
  1173. zlacgv_(&i__1, &w[k + 1 + k * w_dim1], &c__1);
  1174. }
  1175. } else {
  1176. /* 2-by-2 pivot block D(k): columns k and k+1 of W now hold */
  1177. /* ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k) */
  1178. /* where L(k) and L(k+1) are the k-th and (k+1)-th columns */
  1179. /* of L */
  1180. /* (1) Store L(k+2:N,k) and L(k+2:N,k+1) and 2-by-2 */
  1181. /* block D(k:k+1,k:k+1) in columns k and k+1 of A. */
  1182. /* (NOTE: 2-by-2 diagonal block L(k:k+1,k:k+1) is a UNIT */
  1183. /* block and not stored) */
  1184. /* A(k:k+1,k:k+1) := D(k:k+1,k:k+1) = W(k:k+1,k:k+1) */
  1185. /* A(k+2:N,k:k+1) := L(k+2:N,k:k+1) = */
  1186. /* = W(k+2:N,k:k+1) * ( D(k:k+1,k:k+1)**(-1) ) */
  1187. if (k < *n - 1) {
  1188. /* Factor out the columns of the inverse of 2-by-2 pivot */
  1189. /* block D, so that each column contains 1, to reduce the */
  1190. /* number of FLOPS when we multiply panel */
  1191. /* ( W(kw-1) W(kw) ) by this inverse, i.e. by D**(-1). */
  1192. /* D**(-1) = ( d11 cj(d21) )**(-1) = */
  1193. /* ( d21 d22 ) */
  1194. /* = 1/(d11*d22-|d21|**2) * ( ( d22) (-cj(d21) ) ) = */
  1195. /* ( (-d21) ( d11 ) ) */
  1196. /* = 1/(|d21|**2) * 1/((d11/cj(d21))*(d22/d21)-1) * */
  1197. /* * ( d21*( d22/d21 ) conj(d21)*( - 1 ) ) = */
  1198. /* ( ( -1 ) ( d11/conj(d21) ) ) */
  1199. /* = 1/(|d21|**2) * 1/(D22*D11-1) * */
  1200. /* * ( d21*( D11 ) conj(d21)*( -1 ) ) = */
  1201. /* ( ( -1 ) ( D22 ) ) */
  1202. /* = (1/|d21|**2) * T * ( d21*( D11 ) conj(d21)*( -1 ) ) = */
  1203. /* ( ( -1 ) ( D22 ) ) */
  1204. /* = ( (T/conj(d21))*( D11 ) (T/d21)*( -1 ) ) = */
  1205. /* ( ( -1 ) ( D22 ) ) */
  1206. /* = ( conj(D21)*( D11 ) D21*( -1 ) ) */
  1207. /* ( ( -1 ) ( D22 ) ), */
  1208. /* where D11 = d22/d21, */
  1209. /* D22 = d11/conj(d21), */
  1210. /* D21 = T/d21, */
  1211. /* T = 1/(D22*D11-1). */
  1212. /* (NOTE: No need to check for division by ZERO, */
  1213. /* since that was ensured earlier in pivot search: */
  1214. /* (a) d21 != 0, since in 2x2 pivot case(4) */
  1215. /* |d21| should be larger than |d11| and |d22|; */
  1216. /* (b) (D22*D11 - 1) != 0, since from (a), */
  1217. /* both |D11| < 1, |D22| < 1, hence |D22*D11| << 1.) */
  1218. i__1 = k + 1 + k * w_dim1;
  1219. d21.r = w[i__1].r, d21.i = w[i__1].i;
  1220. z_div(&z__1, &w[k + 1 + (k + 1) * w_dim1], &d21);
  1221. d11.r = z__1.r, d11.i = z__1.i;
  1222. d_cnjg(&z__2, &d21);
  1223. z_div(&z__1, &w[k + k * w_dim1], &z__2);
  1224. d22.r = z__1.r, d22.i = z__1.i;
  1225. z__1.r = d11.r * d22.r - d11.i * d22.i, z__1.i = d11.r *
  1226. d22.i + d11.i * d22.r;
  1227. t = 1. / (z__1.r - 1.);
  1228. z__2.r = t, z__2.i = 0.;
  1229. z_div(&z__1, &z__2, &d21);
  1230. d21.r = z__1.r, d21.i = z__1.i;
  1231. /* Update elements in columns A(k) and A(k+1) as */
  1232. /* dot products of rows of ( W(k) W(k+1) ) and columns */
  1233. /* of D**(-1) */
  1234. i__1 = *n;
  1235. for (j = k + 2; j <= i__1; ++j) {
  1236. i__2 = j + k * a_dim1;
  1237. d_cnjg(&z__2, &d21);
  1238. i__3 = j + k * w_dim1;
  1239. z__4.r = d11.r * w[i__3].r - d11.i * w[i__3].i,
  1240. z__4.i = d11.r * w[i__3].i + d11.i * w[i__3]
  1241. .r;
  1242. i__4 = j + (k + 1) * w_dim1;
  1243. z__3.r = z__4.r - w[i__4].r, z__3.i = z__4.i - w[i__4]
  1244. .i;
  1245. z__1.r = z__2.r * z__3.r - z__2.i * z__3.i, z__1.i =
  1246. z__2.r * z__3.i + z__2.i * z__3.r;
  1247. a[i__2].r = z__1.r, a[i__2].i = z__1.i;
  1248. i__2 = j + (k + 1) * a_dim1;
  1249. i__3 = j + (k + 1) * w_dim1;
  1250. z__3.r = d22.r * w[i__3].r - d22.i * w[i__3].i,
  1251. z__3.i = d22.r * w[i__3].i + d22.i * w[i__3]
  1252. .r;
  1253. i__4 = j + k * w_dim1;
  1254. z__2.r = z__3.r - w[i__4].r, z__2.i = z__3.i - w[i__4]
  1255. .i;
  1256. z__1.r = d21.r * z__2.r - d21.i * z__2.i, z__1.i =
  1257. d21.r * z__2.i + d21.i * z__2.r;
  1258. a[i__2].r = z__1.r, a[i__2].i = z__1.i;
  1259. /* L80: */
  1260. }
  1261. }
  1262. /* Copy D(k) to A */
  1263. i__1 = k + k * a_dim1;
  1264. i__2 = k + k * w_dim1;
  1265. a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
  1266. i__1 = k + 1 + k * a_dim1;
  1267. i__2 = k + 1 + k * w_dim1;
  1268. a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
  1269. i__1 = k + 1 + (k + 1) * a_dim1;
  1270. i__2 = k + 1 + (k + 1) * w_dim1;
  1271. a[i__1].r = w[i__2].r, a[i__1].i = w[i__2].i;
  1272. /* (2) Conjugate columns W(k) and W(k+1) */
  1273. i__1 = *n - k;
  1274. zlacgv_(&i__1, &w[k + 1 + k * w_dim1], &c__1);
  1275. i__1 = *n - k - 1;
  1276. zlacgv_(&i__1, &w[k + 2 + (k + 1) * w_dim1], &c__1);
  1277. }
  1278. }
  1279. /* Store details of the interchanges in IPIV */
  1280. if (kstep == 1) {
  1281. ipiv[k] = kp;
  1282. } else {
  1283. ipiv[k] = -kp;
  1284. ipiv[k + 1] = -kp;
  1285. }
  1286. /* Increase K and return to the start of the main loop */
  1287. k += kstep;
  1288. goto L70;
  1289. L90:
  1290. /* Update the lower triangle of A22 (= A(k:n,k:n)) as */
  1291. /* A22 := A22 - L21*D*L21**H = A22 - L21*W**H */
  1292. /* computing blocks of NB columns at a time (note that conjg(W) is */
  1293. /* actually stored) */
  1294. i__1 = *n;
  1295. i__2 = *nb;
  1296. for (j = k; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  1297. /* Computing MIN */
  1298. i__3 = *nb, i__4 = *n - j + 1;
  1299. jb = f2cmin(i__3,i__4);
  1300. /* Update the lower triangle of the diagonal block */
  1301. i__3 = j + jb - 1;
  1302. for (jj = j; jj <= i__3; ++jj) {
  1303. i__4 = jj + jj * a_dim1;
  1304. i__5 = jj + jj * a_dim1;
  1305. d__1 = a[i__5].r;
  1306. a[i__4].r = d__1, a[i__4].i = 0.;
  1307. i__4 = j + jb - jj;
  1308. i__5 = k - 1;
  1309. z__1.r = -1., z__1.i = 0.;
  1310. zgemv_("No transpose", &i__4, &i__5, &z__1, &a[jj + a_dim1],
  1311. lda, &w[jj + w_dim1], ldw, &c_b1, &a[jj + jj * a_dim1]
  1312. , &c__1);
  1313. i__4 = jj + jj * a_dim1;
  1314. i__5 = jj + jj * a_dim1;
  1315. d__1 = a[i__5].r;
  1316. a[i__4].r = d__1, a[i__4].i = 0.;
  1317. /* L100: */
  1318. }
  1319. /* Update the rectangular subdiagonal block */
  1320. if (j + jb <= *n) {
  1321. i__3 = *n - j - jb + 1;
  1322. i__4 = k - 1;
  1323. z__1.r = -1., z__1.i = 0.;
  1324. zgemm_("No transpose", "Transpose", &i__3, &jb, &i__4, &z__1,
  1325. &a[j + jb + a_dim1], lda, &w[j + w_dim1], ldw, &c_b1,
  1326. &a[j + jb + j * a_dim1], lda);
  1327. }
  1328. /* L110: */
  1329. }
  1330. /* Put L21 in standard form by partially undoing the interchanges */
  1331. /* of rows in columns 1:k-1 looping backwards from k-1 to 1 */
  1332. j = k - 1;
  1333. L120:
  1334. /* Undo the interchanges (if any) of rows JJ and JP at each */
  1335. /* step J */
  1336. /* (Here, J is a diagonal index) */
  1337. jj = j;
  1338. jp = ipiv[j];
  1339. if (jp < 0) {
  1340. jp = -jp;
  1341. /* (Here, J is a diagonal index) */
  1342. --j;
  1343. }
  1344. /* (NOTE: Here, J is used to determine row length. Length J */
  1345. /* of the rows to swap back doesn't include diagonal element) */
  1346. --j;
  1347. if (jp != jj && j >= 1) {
  1348. zswap_(&j, &a[jp + a_dim1], lda, &a[jj + a_dim1], lda);
  1349. }
  1350. if (j > 1) {
  1351. goto L120;
  1352. }
  1353. /* Set KB to the number of columns factorized */
  1354. *kb = k - 1;
  1355. }
  1356. return 0;
  1357. /* End of ZLAHEF */
  1358. } /* zlahef_ */