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.

chetf2.c 36 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  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 integer c__1 = 1;
  381. /* > \brief \b CHETF2 computes the factorization of a complex Hermitian matrix, using the diagonal pivoting me
  382. thod (unblocked algorithm calling Level 2 BLAS). */
  383. /* =========== DOCUMENTATION =========== */
  384. /* Online html documentation available at */
  385. /* http://www.netlib.org/lapack/explore-html/ */
  386. /* > \htmlonly */
  387. /* > Download CHETF2 + dependencies */
  388. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chetf2.
  389. f"> */
  390. /* > [TGZ]</a> */
  391. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetf2.
  392. f"> */
  393. /* > [ZIP]</a> */
  394. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetf2.
  395. f"> */
  396. /* > [TXT]</a> */
  397. /* > \endhtmlonly */
  398. /* Definition: */
  399. /* =========== */
  400. /* SUBROUTINE CHETF2( UPLO, N, A, LDA, IPIV, INFO ) */
  401. /* CHARACTER UPLO */
  402. /* INTEGER INFO, LDA, N */
  403. /* INTEGER IPIV( * ) */
  404. /* COMPLEX A( LDA, * ) */
  405. /* > \par Purpose: */
  406. /* ============= */
  407. /* > */
  408. /* > \verbatim */
  409. /* > */
  410. /* > CHETF2 computes the factorization of a complex Hermitian matrix A */
  411. /* > using the Bunch-Kaufman diagonal pivoting method: */
  412. /* > */
  413. /* > A = U*D*U**H or A = L*D*L**H */
  414. /* > */
  415. /* > where U (or L) is a product of permutation and unit upper (lower) */
  416. /* > triangular matrices, U**H is the conjugate transpose of U, and D is */
  417. /* > Hermitian and block diagonal with 1-by-1 and 2-by-2 diagonal blocks. */
  418. /* > */
  419. /* > This is the unblocked version of the algorithm, calling Level 2 BLAS. */
  420. /* > \endverbatim */
  421. /* Arguments: */
  422. /* ========== */
  423. /* > \param[in] UPLO */
  424. /* > \verbatim */
  425. /* > UPLO is CHARACTER*1 */
  426. /* > Specifies whether the upper or lower triangular part of the */
  427. /* > Hermitian matrix A is stored: */
  428. /* > = 'U': Upper triangular */
  429. /* > = 'L': Lower triangular */
  430. /* > \endverbatim */
  431. /* > */
  432. /* > \param[in] N */
  433. /* > \verbatim */
  434. /* > N is INTEGER */
  435. /* > The order of the matrix A. N >= 0. */
  436. /* > \endverbatim */
  437. /* > */
  438. /* > \param[in,out] A */
  439. /* > \verbatim */
  440. /* > A is COMPLEX array, dimension (LDA,N) */
  441. /* > On entry, the Hermitian matrix A. If UPLO = 'U', the leading */
  442. /* > n-by-n upper triangular part of A contains the upper */
  443. /* > triangular part of the matrix A, and the strictly lower */
  444. /* > triangular part of A is not referenced. If UPLO = 'L', the */
  445. /* > leading n-by-n lower triangular part of A contains the lower */
  446. /* > triangular part of the matrix A, and the strictly upper */
  447. /* > triangular part of A is not referenced. */
  448. /* > */
  449. /* > On exit, the block diagonal matrix D and the multipliers used */
  450. /* > to obtain the factor U or L (see below for further details). */
  451. /* > \endverbatim */
  452. /* > */
  453. /* > \param[in] LDA */
  454. /* > \verbatim */
  455. /* > LDA is INTEGER */
  456. /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
  457. /* > \endverbatim */
  458. /* > */
  459. /* > \param[out] IPIV */
  460. /* > \verbatim */
  461. /* > IPIV is INTEGER array, dimension (N) */
  462. /* > Details of the interchanges and the block structure of D. */
  463. /* > */
  464. /* > If UPLO = 'U': */
  465. /* > If IPIV(k) > 0, then rows and columns k and IPIV(k) were */
  466. /* > interchanged and D(k,k) is a 1-by-1 diagonal block. */
  467. /* > */
  468. /* > If IPIV(k) = IPIV(k-1) < 0, then rows and columns */
  469. /* > k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k) */
  470. /* > is a 2-by-2 diagonal block. */
  471. /* > */
  472. /* > If UPLO = 'L': */
  473. /* > If IPIV(k) > 0, then rows and columns k and IPIV(k) were */
  474. /* > interchanged and D(k,k) is a 1-by-1 diagonal block. */
  475. /* > */
  476. /* > If IPIV(k) = IPIV(k+1) < 0, then rows and columns */
  477. /* > k+1 and -IPIV(k) were interchanged and D(k:k+1,k:k+1) */
  478. /* > is a 2-by-2 diagonal block. */
  479. /* > \endverbatim */
  480. /* > */
  481. /* > \param[out] INFO */
  482. /* > \verbatim */
  483. /* > INFO is INTEGER */
  484. /* > = 0: successful exit */
  485. /* > < 0: if INFO = -k, the k-th argument had an illegal value */
  486. /* > > 0: if INFO = k, D(k,k) is exactly zero. The factorization */
  487. /* > has been completed, but the block diagonal matrix D is */
  488. /* > exactly singular, and division by zero will occur if it */
  489. /* > is used to solve a system of equations. */
  490. /* > \endverbatim */
  491. /* Authors: */
  492. /* ======== */
  493. /* > \author Univ. of Tennessee */
  494. /* > \author Univ. of California Berkeley */
  495. /* > \author Univ. of Colorado Denver */
  496. /* > \author NAG Ltd. */
  497. /* > \date December 2016 */
  498. /* > \ingroup complexHEcomputational */
  499. /* > \par Further Details: */
  500. /* ===================== */
  501. /* > */
  502. /* > \verbatim */
  503. /* > */
  504. /* > 09-29-06 - patch from */
  505. /* > Bobby Cheng, MathWorks */
  506. /* > */
  507. /* > Replace l.210 and l.392 */
  508. /* > IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN */
  509. /* > by */
  510. /* > IF( (MAX( ABSAKK, COLMAX ).EQ.ZERO) .OR. SISNAN(ABSAKK) ) THEN */
  511. /* > */
  512. /* > 01-01-96 - Based on modifications by */
  513. /* > J. Lewis, Boeing Computer Services Company */
  514. /* > A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA */
  515. /* > */
  516. /* > If UPLO = 'U', then A = U*D*U**H, where */
  517. /* > U = P(n)*U(n)* ... *P(k)U(k)* ..., */
  518. /* > i.e., U is a product of terms P(k)*U(k), where k decreases from n to */
  519. /* > 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */
  520. /* > and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as */
  521. /* > defined by IPIV(k), and U(k) is a unit upper triangular matrix, such */
  522. /* > that if the diagonal block D(k) is of order s (s = 1 or 2), then */
  523. /* > */
  524. /* > ( I v 0 ) k-s */
  525. /* > U(k) = ( 0 I 0 ) s */
  526. /* > ( 0 0 I ) n-k */
  527. /* > k-s s n-k */
  528. /* > */
  529. /* > If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k). */
  530. /* > If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k), */
  531. /* > and A(k,k), and v overwrites A(1:k-2,k-1:k). */
  532. /* > */
  533. /* > If UPLO = 'L', then A = L*D*L**H, where */
  534. /* > L = P(1)*L(1)* ... *P(k)*L(k)* ..., */
  535. /* > i.e., L is a product of terms P(k)*L(k), where k increases from 1 to */
  536. /* > n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */
  537. /* > and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as */
  538. /* > defined by IPIV(k), and L(k) is a unit lower triangular matrix, such */
  539. /* > that if the diagonal block D(k) is of order s (s = 1 or 2), then */
  540. /* > */
  541. /* > ( I 0 0 ) k-1 */
  542. /* > L(k) = ( 0 I 0 ) s */
  543. /* > ( 0 v I ) n-k-s+1 */
  544. /* > k-1 s n-k-s+1 */
  545. /* > */
  546. /* > If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k). */
  547. /* > If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k), */
  548. /* > and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1). */
  549. /* > \endverbatim */
  550. /* > */
  551. /* ===================================================================== */
  552. /* Subroutine */ int chetf2_(char *uplo, integer *n, complex *a, integer *lda,
  553. integer *ipiv, integer *info)
  554. {
  555. /* System generated locals */
  556. integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5, i__6;
  557. real r__1, r__2, r__3, r__4;
  558. complex q__1, q__2, q__3, q__4, q__5, q__6;
  559. /* Local variables */
  560. extern /* Subroutine */ int cher_(char *, integer *, real *, complex *,
  561. integer *, complex *, integer *);
  562. integer imax, jmax;
  563. real d__;
  564. integer i__, j, k;
  565. complex t;
  566. real alpha;
  567. extern logical lsame_(char *, char *);
  568. extern /* Subroutine */ int cswap_(integer *, complex *, integer *,
  569. complex *, integer *);
  570. integer kstep;
  571. logical upper;
  572. real r1, d11;
  573. complex d12;
  574. real d22;
  575. complex d21;
  576. extern real slapy2_(real *, real *);
  577. integer kk, kp;
  578. real absakk;
  579. complex wk;
  580. extern integer icamax_(integer *, complex *, integer *);
  581. real tt;
  582. extern /* Subroutine */ int csscal_(integer *, real *, complex *, integer
  583. *), xerbla_(char *, integer *, ftnlen);
  584. real colmax;
  585. extern logical sisnan_(real *);
  586. real rowmax;
  587. complex wkm1, wkp1;
  588. /* -- LAPACK computational routine (version 3.7.0) -- */
  589. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  590. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  591. /* December 2016 */
  592. /* ===================================================================== */
  593. /* Test the input parameters. */
  594. /* Parameter adjustments */
  595. a_dim1 = *lda;
  596. a_offset = 1 + a_dim1 * 1;
  597. a -= a_offset;
  598. --ipiv;
  599. /* Function Body */
  600. *info = 0;
  601. upper = lsame_(uplo, "U");
  602. if (! upper && ! lsame_(uplo, "L")) {
  603. *info = -1;
  604. } else if (*n < 0) {
  605. *info = -2;
  606. } else if (*lda < f2cmax(1,*n)) {
  607. *info = -4;
  608. }
  609. if (*info != 0) {
  610. i__1 = -(*info);
  611. xerbla_("CHETF2", &i__1, (ftnlen)6);
  612. return 0;
  613. }
  614. /* Initialize ALPHA for use in choosing pivot block size. */
  615. alpha = (sqrt(17.f) + 1.f) / 8.f;
  616. if (upper) {
  617. /* Factorize A as U*D*U**H using the upper triangle of A */
  618. /* K is the main loop index, decreasing from N to 1 in steps of */
  619. /* 1 or 2 */
  620. k = *n;
  621. L10:
  622. /* If K < 1, exit from loop */
  623. if (k < 1) {
  624. goto L90;
  625. }
  626. kstep = 1;
  627. /* Determine rows and columns to be interchanged and whether */
  628. /* a 1-by-1 or 2-by-2 pivot block will be used */
  629. i__1 = k + k * a_dim1;
  630. absakk = (r__1 = a[i__1].r, abs(r__1));
  631. /* IMAX is the row-index of the largest off-diagonal element in */
  632. /* column K, and COLMAX is its absolute value. */
  633. /* Determine both COLMAX and IMAX. */
  634. if (k > 1) {
  635. i__1 = k - 1;
  636. imax = icamax_(&i__1, &a[k * a_dim1 + 1], &c__1);
  637. i__1 = imax + k * a_dim1;
  638. colmax = (r__1 = a[i__1].r, abs(r__1)) + (r__2 = r_imag(&a[imax +
  639. k * a_dim1]), abs(r__2));
  640. } else {
  641. colmax = 0.f;
  642. }
  643. if (f2cmax(absakk,colmax) == 0.f || sisnan_(&absakk)) {
  644. /* Column K is or underflow, or contains a NaN: */
  645. /* 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. r__1 = a[i__2].r;
  653. a[i__1].r = r__1, a[i__1].i = 0.f;
  654. } else {
  655. if (absakk >= alpha * colmax) {
  656. /* no interchange, use 1-by-1 pivot block */
  657. kp = k;
  658. } else {
  659. /* JMAX is the column-index of the largest off-diagonal */
  660. /* element in row IMAX, and ROWMAX is its absolute value */
  661. i__1 = k - imax;
  662. jmax = imax + icamax_(&i__1, &a[imax + (imax + 1) * a_dim1],
  663. lda);
  664. i__1 = imax + jmax * a_dim1;
  665. rowmax = (r__1 = a[i__1].r, abs(r__1)) + (r__2 = r_imag(&a[
  666. imax + jmax * a_dim1]), abs(r__2));
  667. if (imax > 1) {
  668. i__1 = imax - 1;
  669. jmax = icamax_(&i__1, &a[imax * a_dim1 + 1], &c__1);
  670. /* Computing MAX */
  671. i__1 = jmax + imax * a_dim1;
  672. r__3 = rowmax, r__4 = (r__1 = a[i__1].r, abs(r__1)) + (
  673. r__2 = r_imag(&a[jmax + imax * a_dim1]), abs(r__2)
  674. );
  675. rowmax = f2cmax(r__3,r__4);
  676. }
  677. if (absakk >= alpha * colmax * (colmax / rowmax)) {
  678. /* no interchange, use 1-by-1 pivot block */
  679. kp = k;
  680. } else /* if(complicated condition) */ {
  681. i__1 = imax + imax * a_dim1;
  682. if ((r__1 = a[i__1].r, abs(r__1)) >= alpha * rowmax) {
  683. /* interchange rows and columns K and IMAX, use 1-by-1 */
  684. /* pivot block */
  685. kp = imax;
  686. } else {
  687. /* interchange rows and columns K-1 and IMAX, use 2-by-2 */
  688. /* pivot block */
  689. kp = imax;
  690. kstep = 2;
  691. }
  692. }
  693. }
  694. kk = k - kstep + 1;
  695. if (kp != kk) {
  696. /* Interchange rows and columns KK and KP in the leading */
  697. /* submatrix A(1:k,1:k) */
  698. i__1 = kp - 1;
  699. cswap_(&i__1, &a[kk * a_dim1 + 1], &c__1, &a[kp * a_dim1 + 1],
  700. &c__1);
  701. i__1 = kk - 1;
  702. for (j = kp + 1; j <= i__1; ++j) {
  703. r_cnjg(&q__1, &a[j + kk * a_dim1]);
  704. t.r = q__1.r, t.i = q__1.i;
  705. i__2 = j + kk * a_dim1;
  706. r_cnjg(&q__1, &a[kp + j * a_dim1]);
  707. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  708. i__2 = kp + j * a_dim1;
  709. a[i__2].r = t.r, a[i__2].i = t.i;
  710. /* L20: */
  711. }
  712. i__1 = kp + kk * a_dim1;
  713. r_cnjg(&q__1, &a[kp + kk * a_dim1]);
  714. a[i__1].r = q__1.r, a[i__1].i = q__1.i;
  715. i__1 = kk + kk * a_dim1;
  716. r1 = a[i__1].r;
  717. i__1 = kk + kk * a_dim1;
  718. i__2 = kp + kp * a_dim1;
  719. r__1 = a[i__2].r;
  720. a[i__1].r = r__1, a[i__1].i = 0.f;
  721. i__1 = kp + kp * a_dim1;
  722. a[i__1].r = r1, a[i__1].i = 0.f;
  723. if (kstep == 2) {
  724. i__1 = k + k * a_dim1;
  725. i__2 = k + k * a_dim1;
  726. r__1 = a[i__2].r;
  727. a[i__1].r = r__1, a[i__1].i = 0.f;
  728. i__1 = k - 1 + k * a_dim1;
  729. t.r = a[i__1].r, t.i = a[i__1].i;
  730. i__1 = k - 1 + k * a_dim1;
  731. i__2 = kp + k * a_dim1;
  732. a[i__1].r = a[i__2].r, a[i__1].i = a[i__2].i;
  733. i__1 = kp + k * a_dim1;
  734. a[i__1].r = t.r, a[i__1].i = t.i;
  735. }
  736. } else {
  737. i__1 = k + k * a_dim1;
  738. i__2 = k + k * a_dim1;
  739. r__1 = a[i__2].r;
  740. a[i__1].r = r__1, a[i__1].i = 0.f;
  741. if (kstep == 2) {
  742. i__1 = k - 1 + (k - 1) * a_dim1;
  743. i__2 = k - 1 + (k - 1) * a_dim1;
  744. r__1 = a[i__2].r;
  745. a[i__1].r = r__1, a[i__1].i = 0.f;
  746. }
  747. }
  748. /* Update the leading submatrix */
  749. if (kstep == 1) {
  750. /* 1-by-1 pivot block D(k): column k now holds */
  751. /* W(k) = U(k)*D(k) */
  752. /* where U(k) is the k-th column of U */
  753. /* Perform a rank-1 update of A(1:k-1,1:k-1) as */
  754. /* A := A - U(k)*D(k)*U(k)**H = A - W(k)*1/D(k)*W(k)**H */
  755. i__1 = k + k * a_dim1;
  756. r1 = 1.f / a[i__1].r;
  757. i__1 = k - 1;
  758. r__1 = -r1;
  759. cher_(uplo, &i__1, &r__1, &a[k * a_dim1 + 1], &c__1, &a[
  760. a_offset], lda);
  761. /* Store U(k) in column k */
  762. i__1 = k - 1;
  763. csscal_(&i__1, &r1, &a[k * a_dim1 + 1], &c__1);
  764. } else {
  765. /* 2-by-2 pivot block D(k): columns k and k-1 now hold */
  766. /* ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k) */
  767. /* where U(k) and U(k-1) are the k-th and (k-1)-th columns */
  768. /* of U */
  769. /* Perform a rank-2 update of A(1:k-2,1:k-2) as */
  770. /* A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**H */
  771. /* = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )**H */
  772. if (k > 2) {
  773. i__1 = k - 1 + k * a_dim1;
  774. r__1 = a[i__1].r;
  775. r__2 = r_imag(&a[k - 1 + k * a_dim1]);
  776. d__ = slapy2_(&r__1, &r__2);
  777. i__1 = k - 1 + (k - 1) * a_dim1;
  778. d22 = a[i__1].r / d__;
  779. i__1 = k + k * a_dim1;
  780. d11 = a[i__1].r / d__;
  781. tt = 1.f / (d11 * d22 - 1.f);
  782. i__1 = k - 1 + k * a_dim1;
  783. q__1.r = a[i__1].r / d__, q__1.i = a[i__1].i / d__;
  784. d12.r = q__1.r, d12.i = q__1.i;
  785. d__ = tt / d__;
  786. for (j = k - 2; j >= 1; --j) {
  787. i__1 = j + (k - 1) * a_dim1;
  788. q__3.r = d11 * a[i__1].r, q__3.i = d11 * a[i__1].i;
  789. r_cnjg(&q__5, &d12);
  790. i__2 = j + k * a_dim1;
  791. q__4.r = q__5.r * a[i__2].r - q__5.i * a[i__2].i,
  792. q__4.i = q__5.r * a[i__2].i + q__5.i * a[i__2]
  793. .r;
  794. q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i;
  795. q__1.r = d__ * q__2.r, q__1.i = d__ * q__2.i;
  796. wkm1.r = q__1.r, wkm1.i = q__1.i;
  797. i__1 = j + k * a_dim1;
  798. q__3.r = d22 * a[i__1].r, q__3.i = d22 * a[i__1].i;
  799. i__2 = j + (k - 1) * a_dim1;
  800. q__4.r = d12.r * a[i__2].r - d12.i * a[i__2].i,
  801. q__4.i = d12.r * a[i__2].i + d12.i * a[i__2]
  802. .r;
  803. q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i;
  804. q__1.r = d__ * q__2.r, q__1.i = d__ * q__2.i;
  805. wk.r = q__1.r, wk.i = q__1.i;
  806. for (i__ = j; i__ >= 1; --i__) {
  807. i__1 = i__ + j * a_dim1;
  808. i__2 = i__ + j * a_dim1;
  809. i__3 = i__ + k * a_dim1;
  810. r_cnjg(&q__4, &wk);
  811. q__3.r = a[i__3].r * q__4.r - a[i__3].i * q__4.i,
  812. q__3.i = a[i__3].r * q__4.i + a[i__3].i *
  813. q__4.r;
  814. q__2.r = a[i__2].r - q__3.r, q__2.i = a[i__2].i -
  815. q__3.i;
  816. i__4 = i__ + (k - 1) * a_dim1;
  817. r_cnjg(&q__6, &wkm1);
  818. q__5.r = a[i__4].r * q__6.r - a[i__4].i * q__6.i,
  819. q__5.i = a[i__4].r * q__6.i + a[i__4].i *
  820. q__6.r;
  821. q__1.r = q__2.r - q__5.r, q__1.i = q__2.i -
  822. q__5.i;
  823. a[i__1].r = q__1.r, a[i__1].i = q__1.i;
  824. /* L30: */
  825. }
  826. i__1 = j + k * a_dim1;
  827. a[i__1].r = wk.r, a[i__1].i = wk.i;
  828. i__1 = j + (k - 1) * a_dim1;
  829. a[i__1].r = wkm1.r, a[i__1].i = wkm1.i;
  830. i__1 = j + j * a_dim1;
  831. i__2 = j + j * a_dim1;
  832. r__1 = a[i__2].r;
  833. q__1.r = r__1, q__1.i = 0.f;
  834. a[i__1].r = q__1.r, a[i__1].i = q__1.i;
  835. /* L40: */
  836. }
  837. }
  838. }
  839. }
  840. /* Store details of the interchanges in IPIV */
  841. if (kstep == 1) {
  842. ipiv[k] = kp;
  843. } else {
  844. ipiv[k] = -kp;
  845. ipiv[k - 1] = -kp;
  846. }
  847. /* Decrease K and return to the start of the main loop */
  848. k -= kstep;
  849. goto L10;
  850. } else {
  851. /* Factorize A as L*D*L**H using the lower triangle of A */
  852. /* K is the main loop index, increasing from 1 to N in steps of */
  853. /* 1 or 2 */
  854. k = 1;
  855. L50:
  856. /* If K > N, exit from loop */
  857. if (k > *n) {
  858. goto L90;
  859. }
  860. kstep = 1;
  861. /* Determine rows and columns to be interchanged and whether */
  862. /* a 1-by-1 or 2-by-2 pivot block will be used */
  863. i__1 = k + k * a_dim1;
  864. absakk = (r__1 = a[i__1].r, abs(r__1));
  865. /* IMAX is the row-index of the largest off-diagonal element in */
  866. /* column K, and COLMAX is its absolute value. */
  867. /* Determine both COLMAX and IMAX. */
  868. if (k < *n) {
  869. i__1 = *n - k;
  870. imax = k + icamax_(&i__1, &a[k + 1 + k * a_dim1], &c__1);
  871. i__1 = imax + k * a_dim1;
  872. colmax = (r__1 = a[i__1].r, abs(r__1)) + (r__2 = r_imag(&a[imax +
  873. k * a_dim1]), abs(r__2));
  874. } else {
  875. colmax = 0.f;
  876. }
  877. if (f2cmax(absakk,colmax) == 0.f || sisnan_(&absakk)) {
  878. /* Column K is zero or underflow, contains a NaN: */
  879. /* set INFO and continue */
  880. if (*info == 0) {
  881. *info = k;
  882. }
  883. kp = k;
  884. i__1 = k + k * a_dim1;
  885. i__2 = k + k * a_dim1;
  886. r__1 = a[i__2].r;
  887. a[i__1].r = r__1, a[i__1].i = 0.f;
  888. } else {
  889. if (absakk >= alpha * colmax) {
  890. /* no interchange, use 1-by-1 pivot block */
  891. kp = k;
  892. } else {
  893. /* JMAX is the column-index of the largest off-diagonal */
  894. /* element in row IMAX, and ROWMAX is its absolute value */
  895. i__1 = imax - k;
  896. jmax = k - 1 + icamax_(&i__1, &a[imax + k * a_dim1], lda);
  897. i__1 = imax + jmax * a_dim1;
  898. rowmax = (r__1 = a[i__1].r, abs(r__1)) + (r__2 = r_imag(&a[
  899. imax + jmax * a_dim1]), abs(r__2));
  900. if (imax < *n) {
  901. i__1 = *n - imax;
  902. jmax = imax + icamax_(&i__1, &a[imax + 1 + imax * a_dim1],
  903. &c__1);
  904. /* Computing MAX */
  905. i__1 = jmax + imax * a_dim1;
  906. r__3 = rowmax, r__4 = (r__1 = a[i__1].r, abs(r__1)) + (
  907. r__2 = r_imag(&a[jmax + imax * a_dim1]), abs(r__2)
  908. );
  909. rowmax = f2cmax(r__3,r__4);
  910. }
  911. if (absakk >= alpha * colmax * (colmax / rowmax)) {
  912. /* no interchange, use 1-by-1 pivot block */
  913. kp = k;
  914. } else /* if(complicated condition) */ {
  915. i__1 = imax + imax * a_dim1;
  916. if ((r__1 = a[i__1].r, abs(r__1)) >= alpha * rowmax) {
  917. /* interchange rows and columns K and IMAX, use 1-by-1 */
  918. /* pivot block */
  919. kp = imax;
  920. } else {
  921. /* interchange rows and columns K+1 and IMAX, use 2-by-2 */
  922. /* pivot block */
  923. kp = imax;
  924. kstep = 2;
  925. }
  926. }
  927. }
  928. kk = k + kstep - 1;
  929. if (kp != kk) {
  930. /* Interchange rows and columns KK and KP in the trailing */
  931. /* submatrix A(k:n,k:n) */
  932. if (kp < *n) {
  933. i__1 = *n - kp;
  934. cswap_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + 1
  935. + kp * a_dim1], &c__1);
  936. }
  937. i__1 = kp - 1;
  938. for (j = kk + 1; j <= i__1; ++j) {
  939. r_cnjg(&q__1, &a[j + kk * a_dim1]);
  940. t.r = q__1.r, t.i = q__1.i;
  941. i__2 = j + kk * a_dim1;
  942. r_cnjg(&q__1, &a[kp + j * a_dim1]);
  943. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  944. i__2 = kp + j * a_dim1;
  945. a[i__2].r = t.r, a[i__2].i = t.i;
  946. /* L60: */
  947. }
  948. i__1 = kp + kk * a_dim1;
  949. r_cnjg(&q__1, &a[kp + kk * a_dim1]);
  950. a[i__1].r = q__1.r, a[i__1].i = q__1.i;
  951. i__1 = kk + kk * a_dim1;
  952. r1 = a[i__1].r;
  953. i__1 = kk + kk * a_dim1;
  954. i__2 = kp + kp * a_dim1;
  955. r__1 = a[i__2].r;
  956. a[i__1].r = r__1, a[i__1].i = 0.f;
  957. i__1 = kp + kp * a_dim1;
  958. a[i__1].r = r1, a[i__1].i = 0.f;
  959. if (kstep == 2) {
  960. i__1 = k + k * a_dim1;
  961. i__2 = k + k * a_dim1;
  962. r__1 = a[i__2].r;
  963. a[i__1].r = r__1, a[i__1].i = 0.f;
  964. i__1 = k + 1 + k * a_dim1;
  965. t.r = a[i__1].r, t.i = a[i__1].i;
  966. i__1 = k + 1 + k * a_dim1;
  967. i__2 = kp + k * a_dim1;
  968. a[i__1].r = a[i__2].r, a[i__1].i = a[i__2].i;
  969. i__1 = kp + k * a_dim1;
  970. a[i__1].r = t.r, a[i__1].i = t.i;
  971. }
  972. } else {
  973. i__1 = k + k * a_dim1;
  974. i__2 = k + k * a_dim1;
  975. r__1 = a[i__2].r;
  976. a[i__1].r = r__1, a[i__1].i = 0.f;
  977. if (kstep == 2) {
  978. i__1 = k + 1 + (k + 1) * a_dim1;
  979. i__2 = k + 1 + (k + 1) * a_dim1;
  980. r__1 = a[i__2].r;
  981. a[i__1].r = r__1, a[i__1].i = 0.f;
  982. }
  983. }
  984. /* Update the trailing submatrix */
  985. if (kstep == 1) {
  986. /* 1-by-1 pivot block D(k): column k now holds */
  987. /* W(k) = L(k)*D(k) */
  988. /* where L(k) is the k-th column of L */
  989. if (k < *n) {
  990. /* Perform a rank-1 update of A(k+1:n,k+1:n) as */
  991. /* A := A - L(k)*D(k)*L(k)**H = A - W(k)*(1/D(k))*W(k)**H */
  992. i__1 = k + k * a_dim1;
  993. r1 = 1.f / a[i__1].r;
  994. i__1 = *n - k;
  995. r__1 = -r1;
  996. cher_(uplo, &i__1, &r__1, &a[k + 1 + k * a_dim1], &c__1, &
  997. a[k + 1 + (k + 1) * a_dim1], lda);
  998. /* Store L(k) in column K */
  999. i__1 = *n - k;
  1000. csscal_(&i__1, &r1, &a[k + 1 + k * a_dim1], &c__1);
  1001. }
  1002. } else {
  1003. /* 2-by-2 pivot block D(k) */
  1004. if (k < *n - 1) {
  1005. /* Perform a rank-2 update of A(k+2:n,k+2:n) as */
  1006. /* A := A - ( L(k) L(k+1) )*D(k)*( L(k) L(k+1) )**H */
  1007. /* = A - ( W(k) W(k+1) )*inv(D(k))*( W(k) W(k+1) )**H */
  1008. /* where L(k) and L(k+1) are the k-th and (k+1)-th */
  1009. /* columns of L */
  1010. i__1 = k + 1 + k * a_dim1;
  1011. r__1 = a[i__1].r;
  1012. r__2 = r_imag(&a[k + 1 + k * a_dim1]);
  1013. d__ = slapy2_(&r__1, &r__2);
  1014. i__1 = k + 1 + (k + 1) * a_dim1;
  1015. d11 = a[i__1].r / d__;
  1016. i__1 = k + k * a_dim1;
  1017. d22 = a[i__1].r / d__;
  1018. tt = 1.f / (d11 * d22 - 1.f);
  1019. i__1 = k + 1 + k * a_dim1;
  1020. q__1.r = a[i__1].r / d__, q__1.i = a[i__1].i / d__;
  1021. d21.r = q__1.r, d21.i = q__1.i;
  1022. d__ = tt / d__;
  1023. i__1 = *n;
  1024. for (j = k + 2; j <= i__1; ++j) {
  1025. i__2 = j + k * a_dim1;
  1026. q__3.r = d11 * a[i__2].r, q__3.i = d11 * a[i__2].i;
  1027. i__3 = j + (k + 1) * a_dim1;
  1028. q__4.r = d21.r * a[i__3].r - d21.i * a[i__3].i,
  1029. q__4.i = d21.r * a[i__3].i + d21.i * a[i__3]
  1030. .r;
  1031. q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i;
  1032. q__1.r = d__ * q__2.r, q__1.i = d__ * q__2.i;
  1033. wk.r = q__1.r, wk.i = q__1.i;
  1034. i__2 = j + (k + 1) * a_dim1;
  1035. q__3.r = d22 * a[i__2].r, q__3.i = d22 * a[i__2].i;
  1036. r_cnjg(&q__5, &d21);
  1037. i__3 = j + k * a_dim1;
  1038. q__4.r = q__5.r * a[i__3].r - q__5.i * a[i__3].i,
  1039. q__4.i = q__5.r * a[i__3].i + q__5.i * a[i__3]
  1040. .r;
  1041. q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i;
  1042. q__1.r = d__ * q__2.r, q__1.i = d__ * q__2.i;
  1043. wkp1.r = q__1.r, wkp1.i = q__1.i;
  1044. i__2 = *n;
  1045. for (i__ = j; i__ <= i__2; ++i__) {
  1046. i__3 = i__ + j * a_dim1;
  1047. i__4 = i__ + j * a_dim1;
  1048. i__5 = i__ + k * a_dim1;
  1049. r_cnjg(&q__4, &wk);
  1050. q__3.r = a[i__5].r * q__4.r - a[i__5].i * q__4.i,
  1051. q__3.i = a[i__5].r * q__4.i + a[i__5].i *
  1052. q__4.r;
  1053. q__2.r = a[i__4].r - q__3.r, q__2.i = a[i__4].i -
  1054. q__3.i;
  1055. i__6 = i__ + (k + 1) * a_dim1;
  1056. r_cnjg(&q__6, &wkp1);
  1057. q__5.r = a[i__6].r * q__6.r - a[i__6].i * q__6.i,
  1058. q__5.i = a[i__6].r * q__6.i + a[i__6].i *
  1059. q__6.r;
  1060. q__1.r = q__2.r - q__5.r, q__1.i = q__2.i -
  1061. q__5.i;
  1062. a[i__3].r = q__1.r, a[i__3].i = q__1.i;
  1063. /* L70: */
  1064. }
  1065. i__2 = j + k * a_dim1;
  1066. a[i__2].r = wk.r, a[i__2].i = wk.i;
  1067. i__2 = j + (k + 1) * a_dim1;
  1068. a[i__2].r = wkp1.r, a[i__2].i = wkp1.i;
  1069. i__2 = j + j * a_dim1;
  1070. i__3 = j + j * a_dim1;
  1071. r__1 = a[i__3].r;
  1072. q__1.r = r__1, q__1.i = 0.f;
  1073. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  1074. /* L80: */
  1075. }
  1076. }
  1077. }
  1078. }
  1079. /* Store details of the interchanges in IPIV */
  1080. if (kstep == 1) {
  1081. ipiv[k] = kp;
  1082. } else {
  1083. ipiv[k] = -kp;
  1084. ipiv[k + 1] = -kp;
  1085. }
  1086. /* Increase K and return to the start of the main loop */
  1087. k += kstep;
  1088. goto L50;
  1089. }
  1090. L90:
  1091. return 0;
  1092. /* End of CHETF2 */
  1093. } /* chetf2_ */