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.

chptrf.c 35 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239
  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. typedef int integer;
  18. typedef unsigned int uinteger;
  19. typedef char *address;
  20. typedef short int shortint;
  21. typedef float real;
  22. typedef double doublereal;
  23. typedef struct { real r, i; } complex;
  24. typedef struct { doublereal r, i; } doublecomplex;
  25. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  26. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  27. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  28. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  29. #define pCf(z) (*_pCf(z))
  30. #define pCd(z) (*_pCd(z))
  31. typedef int logical;
  32. typedef short int shortlogical;
  33. typedef char logical1;
  34. typedef char integer1;
  35. #define TRUE_ (1)
  36. #define FALSE_ (0)
  37. /* Extern is for use with -E */
  38. #ifndef Extern
  39. #define Extern extern
  40. #endif
  41. /* I/O stuff */
  42. typedef int flag;
  43. typedef int ftnlen;
  44. typedef int ftnint;
  45. /*external read, write*/
  46. typedef struct
  47. { flag cierr;
  48. ftnint ciunit;
  49. flag ciend;
  50. char *cifmt;
  51. ftnint cirec;
  52. } cilist;
  53. /*internal read, write*/
  54. typedef struct
  55. { flag icierr;
  56. char *iciunit;
  57. flag iciend;
  58. char *icifmt;
  59. ftnint icirlen;
  60. ftnint icirnum;
  61. } icilist;
  62. /*open*/
  63. typedef struct
  64. { flag oerr;
  65. ftnint ounit;
  66. char *ofnm;
  67. ftnlen ofnmlen;
  68. char *osta;
  69. char *oacc;
  70. char *ofm;
  71. ftnint orl;
  72. char *oblnk;
  73. } olist;
  74. /*close*/
  75. typedef struct
  76. { flag cerr;
  77. ftnint cunit;
  78. char *csta;
  79. } cllist;
  80. /*rewind, backspace, endfile*/
  81. typedef struct
  82. { flag aerr;
  83. ftnint aunit;
  84. } alist;
  85. /* inquire */
  86. typedef struct
  87. { flag inerr;
  88. ftnint inunit;
  89. char *infile;
  90. ftnlen infilen;
  91. ftnint *inex; /*parameters in standard's order*/
  92. ftnint *inopen;
  93. ftnint *innum;
  94. ftnint *innamed;
  95. char *inname;
  96. ftnlen innamlen;
  97. char *inacc;
  98. ftnlen inacclen;
  99. char *inseq;
  100. ftnlen inseqlen;
  101. char *indir;
  102. ftnlen indirlen;
  103. char *infmt;
  104. ftnlen infmtlen;
  105. char *inform;
  106. ftnint informlen;
  107. char *inunf;
  108. ftnlen inunflen;
  109. ftnint *inrecl;
  110. ftnint *innrec;
  111. char *inblank;
  112. ftnlen inblanklen;
  113. } inlist;
  114. #define VOID void
  115. union Multitype { /* for multiple entry points */
  116. integer1 g;
  117. shortint h;
  118. integer i;
  119. /* longint j; */
  120. real r;
  121. doublereal d;
  122. complex c;
  123. doublecomplex z;
  124. };
  125. typedef union Multitype Multitype;
  126. struct Vardesc { /* for Namelist */
  127. char *name;
  128. char *addr;
  129. ftnlen *dims;
  130. int type;
  131. };
  132. typedef struct Vardesc Vardesc;
  133. struct Namelist {
  134. char *name;
  135. Vardesc **vars;
  136. int nvars;
  137. };
  138. typedef struct Namelist Namelist;
  139. #define abs(x) ((x) >= 0 ? (x) : -(x))
  140. #define dabs(x) (fabs(x))
  141. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  142. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  143. #define dmin(a,b) (f2cmin(a,b))
  144. #define dmax(a,b) (f2cmax(a,b))
  145. #define bit_test(a,b) ((a) >> (b) & 1)
  146. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  147. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  148. #define abort_() { sig_die("Fortran abort routine called", 1); }
  149. #define c_abs(z) (cabsf(Cf(z)))
  150. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  151. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  152. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  153. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  154. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  155. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  156. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  157. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  158. #define d_abs(x) (fabs(*(x)))
  159. #define d_acos(x) (acos(*(x)))
  160. #define d_asin(x) (asin(*(x)))
  161. #define d_atan(x) (atan(*(x)))
  162. #define d_atn2(x, y) (atan2(*(x),*(y)))
  163. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  164. #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
  165. #define d_cos(x) (cos(*(x)))
  166. #define d_cosh(x) (cosh(*(x)))
  167. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  168. #define d_exp(x) (exp(*(x)))
  169. #define d_imag(z) (cimag(Cd(z)))
  170. #define r_imag(z) (cimag(Cf(z)))
  171. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  172. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  173. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  174. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  175. #define d_log(x) (log(*(x)))
  176. #define d_mod(x, y) (fmod(*(x), *(y)))
  177. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  178. #define d_nint(x) u_nint(*(x))
  179. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  180. #define d_sign(a,b) u_sign(*(a),*(b))
  181. #define r_sign(a,b) u_sign(*(a),*(b))
  182. #define d_sin(x) (sin(*(x)))
  183. #define d_sinh(x) (sinh(*(x)))
  184. #define d_sqrt(x) (sqrt(*(x)))
  185. #define d_tan(x) (tan(*(x)))
  186. #define d_tanh(x) (tanh(*(x)))
  187. #define i_abs(x) abs(*(x))
  188. #define i_dnnt(x) ((integer)u_nint(*(x)))
  189. #define i_len(s, n) (n)
  190. #define i_nint(x) ((integer)u_nint(*(x)))
  191. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  192. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  193. #define pow_si(B,E) spow_ui(*(B),*(E))
  194. #define pow_ri(B,E) spow_ui(*(B),*(E))
  195. #define pow_di(B,E) dpow_ui(*(B),*(E))
  196. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  197. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  198. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  199. #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++ = ' '; }
  200. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  201. #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]; }
  202. #define sig_die(s, kill) { exit(1); }
  203. #define s_stop(s, n) {exit(0);}
  204. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  205. #define z_abs(z) (cabs(Cd(z)))
  206. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  207. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  208. #define myexit_() break;
  209. #define mycycle() continue;
  210. #define myceiling(w) {ceil(w)}
  211. #define myhuge(w) {HUGE_VAL}
  212. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  213. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  214. /* procedure parameter types for -A and -C++ */
  215. #define F2C_proc_par_types 1
  216. #ifdef __cplusplus
  217. typedef logical (*L_fp)(...);
  218. #else
  219. typedef logical (*L_fp)();
  220. #endif
  221. static float spow_ui(float x, integer n) {
  222. float pow=1.0; unsigned long int u;
  223. if(n != 0) {
  224. if(n < 0) n = -n, x = 1/x;
  225. for(u = n; ; ) {
  226. if(u & 01) pow *= x;
  227. if(u >>= 1) x *= x;
  228. else break;
  229. }
  230. }
  231. return pow;
  232. }
  233. static double dpow_ui(double x, integer n) {
  234. double pow=1.0; unsigned long int u;
  235. if(n != 0) {
  236. if(n < 0) n = -n, x = 1/x;
  237. for(u = n; ; ) {
  238. if(u & 01) pow *= x;
  239. if(u >>= 1) x *= x;
  240. else break;
  241. }
  242. }
  243. return pow;
  244. }
  245. static _Complex float cpow_ui(_Complex float x, integer n) {
  246. _Complex float pow=1.0; unsigned long int u;
  247. if(n != 0) {
  248. if(n < 0) n = -n, x = 1/x;
  249. for(u = n; ; ) {
  250. if(u & 01) pow *= x;
  251. if(u >>= 1) x *= x;
  252. else break;
  253. }
  254. }
  255. return pow;
  256. }
  257. static _Complex double zpow_ui(_Complex double x, integer n) {
  258. _Complex double pow=1.0; unsigned long int u;
  259. if(n != 0) {
  260. if(n < 0) n = -n, x = 1/x;
  261. for(u = n; ; ) {
  262. if(u & 01) pow *= x;
  263. if(u >>= 1) x *= x;
  264. else break;
  265. }
  266. }
  267. return pow;
  268. }
  269. static integer pow_ii(integer x, integer n) {
  270. integer pow; unsigned long int u;
  271. if (n <= 0) {
  272. if (n == 0 || x == 1) pow = 1;
  273. else if (x != -1) pow = x == 0 ? 1/x : 0;
  274. else n = -n;
  275. }
  276. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  277. u = n;
  278. for(pow = 1; ; ) {
  279. if(u & 01) pow *= x;
  280. if(u >>= 1) x *= x;
  281. else break;
  282. }
  283. }
  284. return pow;
  285. }
  286. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  287. {
  288. double m; integer i, mi;
  289. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  290. if (w[i-1]>m) mi=i ,m=w[i-1];
  291. return mi-s+1;
  292. }
  293. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  294. {
  295. float m; integer i, mi;
  296. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  297. if (w[i-1]>m) mi=i ,m=w[i-1];
  298. return mi-s+1;
  299. }
  300. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  301. integer n = *n_, incx = *incx_, incy = *incy_, i;
  302. _Complex float zdotc = 0.0;
  303. if (incx == 1 && incy == 1) {
  304. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  305. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  306. }
  307. } else {
  308. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  309. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  310. }
  311. }
  312. pCf(z) = zdotc;
  313. }
  314. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  315. integer n = *n_, incx = *incx_, incy = *incy_, i;
  316. _Complex double zdotc = 0.0;
  317. if (incx == 1 && incy == 1) {
  318. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  319. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  320. }
  321. } else {
  322. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  323. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  324. }
  325. }
  326. pCd(z) = zdotc;
  327. }
  328. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  329. integer n = *n_, incx = *incx_, incy = *incy_, i;
  330. _Complex float zdotc = 0.0;
  331. if (incx == 1 && incy == 1) {
  332. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  333. zdotc += Cf(&x[i]) * Cf(&y[i]);
  334. }
  335. } else {
  336. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  337. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  338. }
  339. }
  340. pCf(z) = zdotc;
  341. }
  342. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  343. integer n = *n_, incx = *incx_, incy = *incy_, i;
  344. _Complex double zdotc = 0.0;
  345. if (incx == 1 && incy == 1) {
  346. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  347. zdotc += Cd(&x[i]) * Cd(&y[i]);
  348. }
  349. } else {
  350. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  351. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  352. }
  353. }
  354. pCd(z) = zdotc;
  355. }
  356. #endif
  357. /* -- translated by f2c (version 20000121).
  358. You must link the resulting object file with the libraries:
  359. -lf2c -lm (in that order)
  360. */
  361. /* Table of constant values */
  362. static integer c__1 = 1;
  363. /* > \brief \b CHPTRF */
  364. /* =========== DOCUMENTATION =========== */
  365. /* Online html documentation available at */
  366. /* http://www.netlib.org/lapack/explore-html/ */
  367. /* > \htmlonly */
  368. /* > Download CHPTRF + dependencies */
  369. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chptrf.
  370. f"> */
  371. /* > [TGZ]</a> */
  372. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chptrf.
  373. f"> */
  374. /* > [ZIP]</a> */
  375. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chptrf.
  376. f"> */
  377. /* > [TXT]</a> */
  378. /* > \endhtmlonly */
  379. /* Definition: */
  380. /* =========== */
  381. /* SUBROUTINE CHPTRF( UPLO, N, AP, IPIV, INFO ) */
  382. /* CHARACTER UPLO */
  383. /* INTEGER INFO, N */
  384. /* INTEGER IPIV( * ) */
  385. /* COMPLEX AP( * ) */
  386. /* > \par Purpose: */
  387. /* ============= */
  388. /* > */
  389. /* > \verbatim */
  390. /* > */
  391. /* > CHPTRF computes the factorization of a complex Hermitian packed */
  392. /* > matrix A using the Bunch-Kaufman diagonal pivoting method: */
  393. /* > */
  394. /* > A = U*D*U**H or A = L*D*L**H */
  395. /* > */
  396. /* > where U (or L) is a product of permutation and unit upper (lower) */
  397. /* > triangular matrices, and D is Hermitian and block diagonal with */
  398. /* > 1-by-1 and 2-by-2 diagonal blocks. */
  399. /* > \endverbatim */
  400. /* Arguments: */
  401. /* ========== */
  402. /* > \param[in] UPLO */
  403. /* > \verbatim */
  404. /* > UPLO is CHARACTER*1 */
  405. /* > = 'U': Upper triangle of A is stored; */
  406. /* > = 'L': Lower triangle of A is stored. */
  407. /* > \endverbatim */
  408. /* > */
  409. /* > \param[in] N */
  410. /* > \verbatim */
  411. /* > N is INTEGER */
  412. /* > The order of the matrix A. N >= 0. */
  413. /* > \endverbatim */
  414. /* > */
  415. /* > \param[in,out] AP */
  416. /* > \verbatim */
  417. /* > AP is COMPLEX array, dimension (N*(N+1)/2) */
  418. /* > On entry, the upper or lower triangle of the Hermitian matrix */
  419. /* > A, packed columnwise in a linear array. The j-th column of A */
  420. /* > is stored in the array AP as follows: */
  421. /* > if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */
  422. /* > if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n. */
  423. /* > */
  424. /* > On exit, the block diagonal matrix D and the multipliers used */
  425. /* > to obtain the factor U or L, stored as a packed triangular */
  426. /* > matrix overwriting A (see below for further details). */
  427. /* > \endverbatim */
  428. /* > */
  429. /* > \param[out] IPIV */
  430. /* > \verbatim */
  431. /* > IPIV is INTEGER array, dimension (N) */
  432. /* > Details of the interchanges and the block structure of D. */
  433. /* > If IPIV(k) > 0, then rows and columns k and IPIV(k) were */
  434. /* > interchanged and D(k,k) is a 1-by-1 diagonal block. */
  435. /* > If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, then rows and */
  436. /* > columns k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k) */
  437. /* > is a 2-by-2 diagonal block. If UPLO = 'L' and IPIV(k) = */
  438. /* > IPIV(k+1) < 0, then rows and columns k+1 and -IPIV(k) were */
  439. /* > interchanged and D(k:k+1,k:k+1) is a 2-by-2 diagonal block. */
  440. /* > \endverbatim */
  441. /* > */
  442. /* > \param[out] INFO */
  443. /* > \verbatim */
  444. /* > INFO is INTEGER */
  445. /* > = 0: successful exit */
  446. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  447. /* > > 0: if INFO = i, D(i,i) is exactly zero. The factorization */
  448. /* > has been completed, but the block diagonal matrix D is */
  449. /* > exactly singular, and division by zero will occur if it */
  450. /* > is used to solve a system of equations. */
  451. /* > \endverbatim */
  452. /* Authors: */
  453. /* ======== */
  454. /* > \author Univ. of Tennessee */
  455. /* > \author Univ. of California Berkeley */
  456. /* > \author Univ. of Colorado Denver */
  457. /* > \author NAG Ltd. */
  458. /* > \date December 2016 */
  459. /* > \ingroup complexOTHERcomputational */
  460. /* > \par Further Details: */
  461. /* ===================== */
  462. /* > */
  463. /* > \verbatim */
  464. /* > */
  465. /* > If UPLO = 'U', then A = U*D*U**H, where */
  466. /* > U = P(n)*U(n)* ... *P(k)U(k)* ..., */
  467. /* > i.e., U is a product of terms P(k)*U(k), where k decreases from n to */
  468. /* > 1 in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */
  469. /* > and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as */
  470. /* > defined by IPIV(k), and U(k) is a unit upper triangular matrix, such */
  471. /* > that if the diagonal block D(k) is of order s (s = 1 or 2), then */
  472. /* > */
  473. /* > ( I v 0 ) k-s */
  474. /* > U(k) = ( 0 I 0 ) s */
  475. /* > ( 0 0 I ) n-k */
  476. /* > k-s s n-k */
  477. /* > */
  478. /* > If s = 1, D(k) overwrites A(k,k), and v overwrites A(1:k-1,k). */
  479. /* > If s = 2, the upper triangle of D(k) overwrites A(k-1,k-1), A(k-1,k), */
  480. /* > and A(k,k), and v overwrites A(1:k-2,k-1:k). */
  481. /* > */
  482. /* > If UPLO = 'L', then A = L*D*L**H, where */
  483. /* > L = P(1)*L(1)* ... *P(k)*L(k)* ..., */
  484. /* > i.e., L is a product of terms P(k)*L(k), where k increases from 1 to */
  485. /* > n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */
  486. /* > and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as */
  487. /* > defined by IPIV(k), and L(k) is a unit lower triangular matrix, such */
  488. /* > that if the diagonal block D(k) is of order s (s = 1 or 2), then */
  489. /* > */
  490. /* > ( I 0 0 ) k-1 */
  491. /* > L(k) = ( 0 I 0 ) s */
  492. /* > ( 0 v I ) n-k-s+1 */
  493. /* > k-1 s n-k-s+1 */
  494. /* > */
  495. /* > If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k). */
  496. /* > If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k), */
  497. /* > and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1). */
  498. /* > \endverbatim */
  499. /* > \par Contributors: */
  500. /* ================== */
  501. /* > */
  502. /* > J. Lewis, Boeing Computer Services Company */
  503. /* > */
  504. /* ===================================================================== */
  505. /* Subroutine */ int chptrf_(char *uplo, integer *n, complex *ap, integer *
  506. ipiv, integer *info)
  507. {
  508. /* System generated locals */
  509. integer i__1, i__2, i__3, i__4, i__5, i__6;
  510. real r__1, r__2, r__3, r__4;
  511. complex q__1, q__2, q__3, q__4, q__5, q__6;
  512. /* Local variables */
  513. extern /* Subroutine */ int chpr_(char *, integer *, real *, complex *,
  514. integer *, complex *);
  515. integer imax, jmax;
  516. real d__;
  517. integer i__, j, k;
  518. complex t;
  519. real alpha;
  520. extern logical lsame_(char *, char *);
  521. extern /* Subroutine */ int cswap_(integer *, complex *, integer *,
  522. complex *, integer *);
  523. integer kstep;
  524. logical upper;
  525. real r1, d11;
  526. complex d12;
  527. real d22;
  528. complex d21;
  529. extern real slapy2_(real *, real *);
  530. integer kc, kk, kp;
  531. real absakk;
  532. complex wk;
  533. integer kx;
  534. extern integer icamax_(integer *, complex *, integer *);
  535. real tt;
  536. extern /* Subroutine */ int csscal_(integer *, real *, complex *, integer
  537. *), xerbla_(char *, integer *, ftnlen);
  538. real colmax, rowmax;
  539. integer knc, kpc, npp;
  540. complex wkm1, wkp1;
  541. /* -- LAPACK computational routine (version 3.7.0) -- */
  542. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  543. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  544. /* December 2016 */
  545. /* ===================================================================== */
  546. /* Test the input parameters. */
  547. /* Parameter adjustments */
  548. --ipiv;
  549. --ap;
  550. /* Function Body */
  551. *info = 0;
  552. upper = lsame_(uplo, "U");
  553. if (! upper && ! lsame_(uplo, "L")) {
  554. *info = -1;
  555. } else if (*n < 0) {
  556. *info = -2;
  557. }
  558. if (*info != 0) {
  559. i__1 = -(*info);
  560. xerbla_("CHPTRF", &i__1, (ftnlen)6);
  561. return 0;
  562. }
  563. /* Initialize ALPHA for use in choosing pivot block size. */
  564. alpha = (sqrt(17.f) + 1.f) / 8.f;
  565. if (upper) {
  566. /* Factorize A as U*D*U**H using the upper triangle of A */
  567. /* K is the main loop index, decreasing from N to 1 in steps of */
  568. /* 1 or 2 */
  569. k = *n;
  570. kc = (*n - 1) * *n / 2 + 1;
  571. L10:
  572. knc = kc;
  573. /* If K < 1, exit from loop */
  574. if (k < 1) {
  575. goto L110;
  576. }
  577. kstep = 1;
  578. /* Determine rows and columns to be interchanged and whether */
  579. /* a 1-by-1 or 2-by-2 pivot block will be used */
  580. i__1 = kc + k - 1;
  581. absakk = (r__1 = ap[i__1].r, abs(r__1));
  582. /* IMAX is the row-index of the largest off-diagonal element in */
  583. /* column K, and COLMAX is its absolute value */
  584. if (k > 1) {
  585. i__1 = k - 1;
  586. imax = icamax_(&i__1, &ap[kc], &c__1);
  587. i__1 = kc + imax - 1;
  588. colmax = (r__1 = ap[i__1].r, abs(r__1)) + (r__2 = r_imag(&ap[kc +
  589. imax - 1]), abs(r__2));
  590. } else {
  591. colmax = 0.f;
  592. }
  593. if (f2cmax(absakk,colmax) == 0.f) {
  594. /* Column K is zero: set INFO and continue */
  595. if (*info == 0) {
  596. *info = k;
  597. }
  598. kp = k;
  599. i__1 = kc + k - 1;
  600. i__2 = kc + k - 1;
  601. r__1 = ap[i__2].r;
  602. ap[i__1].r = r__1, ap[i__1].i = 0.f;
  603. } else {
  604. if (absakk >= alpha * colmax) {
  605. /* no interchange, use 1-by-1 pivot block */
  606. kp = k;
  607. } else {
  608. /* JMAX is the column-index of the largest off-diagonal */
  609. /* element in row IMAX, and ROWMAX is its absolute value */
  610. rowmax = 0.f;
  611. jmax = imax;
  612. kx = imax * (imax + 1) / 2 + imax;
  613. i__1 = k;
  614. for (j = imax + 1; j <= i__1; ++j) {
  615. i__2 = kx;
  616. if ((r__1 = ap[i__2].r, abs(r__1)) + (r__2 = r_imag(&ap[
  617. kx]), abs(r__2)) > rowmax) {
  618. i__2 = kx;
  619. rowmax = (r__1 = ap[i__2].r, abs(r__1)) + (r__2 =
  620. r_imag(&ap[kx]), abs(r__2));
  621. jmax = j;
  622. }
  623. kx += j;
  624. /* L20: */
  625. }
  626. kpc = (imax - 1) * imax / 2 + 1;
  627. if (imax > 1) {
  628. i__1 = imax - 1;
  629. jmax = icamax_(&i__1, &ap[kpc], &c__1);
  630. /* Computing MAX */
  631. i__1 = kpc + jmax - 1;
  632. r__3 = rowmax, r__4 = (r__1 = ap[i__1].r, abs(r__1)) + (
  633. r__2 = r_imag(&ap[kpc + jmax - 1]), abs(r__2));
  634. rowmax = f2cmax(r__3,r__4);
  635. }
  636. if (absakk >= alpha * colmax * (colmax / rowmax)) {
  637. /* no interchange, use 1-by-1 pivot block */
  638. kp = k;
  639. } else /* if(complicated condition) */ {
  640. i__1 = kpc + imax - 1;
  641. if ((r__1 = ap[i__1].r, abs(r__1)) >= alpha * rowmax) {
  642. /* interchange rows and columns K and IMAX, use 1-by-1 */
  643. /* pivot block */
  644. kp = imax;
  645. } else {
  646. /* interchange rows and columns K-1 and IMAX, use 2-by-2 */
  647. /* pivot block */
  648. kp = imax;
  649. kstep = 2;
  650. }
  651. }
  652. }
  653. kk = k - kstep + 1;
  654. if (kstep == 2) {
  655. knc = knc - k + 1;
  656. }
  657. if (kp != kk) {
  658. /* Interchange rows and columns KK and KP in the leading */
  659. /* submatrix A(1:k,1:k) */
  660. i__1 = kp - 1;
  661. cswap_(&i__1, &ap[knc], &c__1, &ap[kpc], &c__1);
  662. kx = kpc + kp - 1;
  663. i__1 = kk - 1;
  664. for (j = kp + 1; j <= i__1; ++j) {
  665. kx = kx + j - 1;
  666. r_cnjg(&q__1, &ap[knc + j - 1]);
  667. t.r = q__1.r, t.i = q__1.i;
  668. i__2 = knc + j - 1;
  669. r_cnjg(&q__1, &ap[kx]);
  670. ap[i__2].r = q__1.r, ap[i__2].i = q__1.i;
  671. i__2 = kx;
  672. ap[i__2].r = t.r, ap[i__2].i = t.i;
  673. /* L30: */
  674. }
  675. i__1 = kx + kk - 1;
  676. r_cnjg(&q__1, &ap[kx + kk - 1]);
  677. ap[i__1].r = q__1.r, ap[i__1].i = q__1.i;
  678. i__1 = knc + kk - 1;
  679. r1 = ap[i__1].r;
  680. i__1 = knc + kk - 1;
  681. i__2 = kpc + kp - 1;
  682. r__1 = ap[i__2].r;
  683. ap[i__1].r = r__1, ap[i__1].i = 0.f;
  684. i__1 = kpc + kp - 1;
  685. ap[i__1].r = r1, ap[i__1].i = 0.f;
  686. if (kstep == 2) {
  687. i__1 = kc + k - 1;
  688. i__2 = kc + k - 1;
  689. r__1 = ap[i__2].r;
  690. ap[i__1].r = r__1, ap[i__1].i = 0.f;
  691. i__1 = kc + k - 2;
  692. t.r = ap[i__1].r, t.i = ap[i__1].i;
  693. i__1 = kc + k - 2;
  694. i__2 = kc + kp - 1;
  695. ap[i__1].r = ap[i__2].r, ap[i__1].i = ap[i__2].i;
  696. i__1 = kc + kp - 1;
  697. ap[i__1].r = t.r, ap[i__1].i = t.i;
  698. }
  699. } else {
  700. i__1 = kc + k - 1;
  701. i__2 = kc + k - 1;
  702. r__1 = ap[i__2].r;
  703. ap[i__1].r = r__1, ap[i__1].i = 0.f;
  704. if (kstep == 2) {
  705. i__1 = kc - 1;
  706. i__2 = kc - 1;
  707. r__1 = ap[i__2].r;
  708. ap[i__1].r = r__1, ap[i__1].i = 0.f;
  709. }
  710. }
  711. /* Update the leading submatrix */
  712. if (kstep == 1) {
  713. /* 1-by-1 pivot block D(k): column k now holds */
  714. /* W(k) = U(k)*D(k) */
  715. /* where U(k) is the k-th column of U */
  716. /* Perform a rank-1 update of A(1:k-1,1:k-1) as */
  717. /* A := A - U(k)*D(k)*U(k)**H = A - W(k)*1/D(k)*W(k)**H */
  718. i__1 = kc + k - 1;
  719. r1 = 1.f / ap[i__1].r;
  720. i__1 = k - 1;
  721. r__1 = -r1;
  722. chpr_(uplo, &i__1, &r__1, &ap[kc], &c__1, &ap[1]);
  723. /* Store U(k) in column k */
  724. i__1 = k - 1;
  725. csscal_(&i__1, &r1, &ap[kc], &c__1);
  726. } else {
  727. /* 2-by-2 pivot block D(k): columns k and k-1 now hold */
  728. /* ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k) */
  729. /* where U(k) and U(k-1) are the k-th and (k-1)-th columns */
  730. /* of U */
  731. /* Perform a rank-2 update of A(1:k-2,1:k-2) as */
  732. /* A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**H */
  733. /* = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )**H */
  734. if (k > 2) {
  735. i__1 = k - 1 + (k - 1) * k / 2;
  736. r__1 = ap[i__1].r;
  737. r__2 = r_imag(&ap[k - 1 + (k - 1) * k / 2]);
  738. d__ = slapy2_(&r__1, &r__2);
  739. i__1 = k - 1 + (k - 2) * (k - 1) / 2;
  740. d22 = ap[i__1].r / d__;
  741. i__1 = k + (k - 1) * k / 2;
  742. d11 = ap[i__1].r / d__;
  743. tt = 1.f / (d11 * d22 - 1.f);
  744. i__1 = k - 1 + (k - 1) * k / 2;
  745. q__1.r = ap[i__1].r / d__, q__1.i = ap[i__1].i / d__;
  746. d12.r = q__1.r, d12.i = q__1.i;
  747. d__ = tt / d__;
  748. for (j = k - 2; j >= 1; --j) {
  749. i__1 = j + (k - 2) * (k - 1) / 2;
  750. q__3.r = d11 * ap[i__1].r, q__3.i = d11 * ap[i__1].i;
  751. r_cnjg(&q__5, &d12);
  752. i__2 = j + (k - 1) * k / 2;
  753. q__4.r = q__5.r * ap[i__2].r - q__5.i * ap[i__2].i,
  754. q__4.i = q__5.r * ap[i__2].i + q__5.i * ap[
  755. i__2].r;
  756. q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i;
  757. q__1.r = d__ * q__2.r, q__1.i = d__ * q__2.i;
  758. wkm1.r = q__1.r, wkm1.i = q__1.i;
  759. i__1 = j + (k - 1) * k / 2;
  760. q__3.r = d22 * ap[i__1].r, q__3.i = d22 * ap[i__1].i;
  761. i__2 = j + (k - 2) * (k - 1) / 2;
  762. q__4.r = d12.r * ap[i__2].r - d12.i * ap[i__2].i,
  763. q__4.i = d12.r * ap[i__2].i + d12.i * ap[i__2]
  764. .r;
  765. q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i;
  766. q__1.r = d__ * q__2.r, q__1.i = d__ * q__2.i;
  767. wk.r = q__1.r, wk.i = q__1.i;
  768. for (i__ = j; i__ >= 1; --i__) {
  769. i__1 = i__ + (j - 1) * j / 2;
  770. i__2 = i__ + (j - 1) * j / 2;
  771. i__3 = i__ + (k - 1) * k / 2;
  772. r_cnjg(&q__4, &wk);
  773. q__3.r = ap[i__3].r * q__4.r - ap[i__3].i *
  774. q__4.i, q__3.i = ap[i__3].r * q__4.i + ap[
  775. i__3].i * q__4.r;
  776. q__2.r = ap[i__2].r - q__3.r, q__2.i = ap[i__2].i
  777. - q__3.i;
  778. i__4 = i__ + (k - 2) * (k - 1) / 2;
  779. r_cnjg(&q__6, &wkm1);
  780. q__5.r = ap[i__4].r * q__6.r - ap[i__4].i *
  781. q__6.i, q__5.i = ap[i__4].r * q__6.i + ap[
  782. i__4].i * q__6.r;
  783. q__1.r = q__2.r - q__5.r, q__1.i = q__2.i -
  784. q__5.i;
  785. ap[i__1].r = q__1.r, ap[i__1].i = q__1.i;
  786. /* L40: */
  787. }
  788. i__1 = j + (k - 1) * k / 2;
  789. ap[i__1].r = wk.r, ap[i__1].i = wk.i;
  790. i__1 = j + (k - 2) * (k - 1) / 2;
  791. ap[i__1].r = wkm1.r, ap[i__1].i = wkm1.i;
  792. i__1 = j + (j - 1) * j / 2;
  793. i__2 = j + (j - 1) * j / 2;
  794. r__1 = ap[i__2].r;
  795. q__1.r = r__1, q__1.i = 0.f;
  796. ap[i__1].r = q__1.r, ap[i__1].i = q__1.i;
  797. /* L50: */
  798. }
  799. }
  800. }
  801. }
  802. /* Store details of the interchanges in IPIV */
  803. if (kstep == 1) {
  804. ipiv[k] = kp;
  805. } else {
  806. ipiv[k] = -kp;
  807. ipiv[k - 1] = -kp;
  808. }
  809. /* Decrease K and return to the start of the main loop */
  810. k -= kstep;
  811. kc = knc - k;
  812. goto L10;
  813. } else {
  814. /* Factorize A as L*D*L**H using the lower triangle of A */
  815. /* K is the main loop index, increasing from 1 to N in steps of */
  816. /* 1 or 2 */
  817. k = 1;
  818. kc = 1;
  819. npp = *n * (*n + 1) / 2;
  820. L60:
  821. knc = kc;
  822. /* If K > N, exit from loop */
  823. if (k > *n) {
  824. goto L110;
  825. }
  826. kstep = 1;
  827. /* Determine rows and columns to be interchanged and whether */
  828. /* a 1-by-1 or 2-by-2 pivot block will be used */
  829. i__1 = kc;
  830. absakk = (r__1 = ap[i__1].r, abs(r__1));
  831. /* IMAX is the row-index of the largest off-diagonal element in */
  832. /* column K, and COLMAX is its absolute value */
  833. if (k < *n) {
  834. i__1 = *n - k;
  835. imax = k + icamax_(&i__1, &ap[kc + 1], &c__1);
  836. i__1 = kc + imax - k;
  837. colmax = (r__1 = ap[i__1].r, abs(r__1)) + (r__2 = r_imag(&ap[kc +
  838. imax - k]), abs(r__2));
  839. } else {
  840. colmax = 0.f;
  841. }
  842. if (f2cmax(absakk,colmax) == 0.f) {
  843. /* Column K is zero: set INFO and continue */
  844. if (*info == 0) {
  845. *info = k;
  846. }
  847. kp = k;
  848. i__1 = kc;
  849. i__2 = kc;
  850. r__1 = ap[i__2].r;
  851. ap[i__1].r = r__1, ap[i__1].i = 0.f;
  852. } else {
  853. if (absakk >= alpha * colmax) {
  854. /* no interchange, use 1-by-1 pivot block */
  855. kp = k;
  856. } else {
  857. /* JMAX is the column-index of the largest off-diagonal */
  858. /* element in row IMAX, and ROWMAX is its absolute value */
  859. rowmax = 0.f;
  860. kx = kc + imax - k;
  861. i__1 = imax - 1;
  862. for (j = k; j <= i__1; ++j) {
  863. i__2 = kx;
  864. if ((r__1 = ap[i__2].r, abs(r__1)) + (r__2 = r_imag(&ap[
  865. kx]), abs(r__2)) > rowmax) {
  866. i__2 = kx;
  867. rowmax = (r__1 = ap[i__2].r, abs(r__1)) + (r__2 =
  868. r_imag(&ap[kx]), abs(r__2));
  869. jmax = j;
  870. }
  871. kx = kx + *n - j;
  872. /* L70: */
  873. }
  874. kpc = npp - (*n - imax + 1) * (*n - imax + 2) / 2 + 1;
  875. if (imax < *n) {
  876. i__1 = *n - imax;
  877. jmax = imax + icamax_(&i__1, &ap[kpc + 1], &c__1);
  878. /* Computing MAX */
  879. i__1 = kpc + jmax - imax;
  880. r__3 = rowmax, r__4 = (r__1 = ap[i__1].r, abs(r__1)) + (
  881. r__2 = r_imag(&ap[kpc + jmax - imax]), abs(r__2));
  882. rowmax = f2cmax(r__3,r__4);
  883. }
  884. if (absakk >= alpha * colmax * (colmax / rowmax)) {
  885. /* no interchange, use 1-by-1 pivot block */
  886. kp = k;
  887. } else /* if(complicated condition) */ {
  888. i__1 = kpc;
  889. if ((r__1 = ap[i__1].r, abs(r__1)) >= alpha * rowmax) {
  890. /* interchange rows and columns K and IMAX, use 1-by-1 */
  891. /* pivot block */
  892. kp = imax;
  893. } else {
  894. /* interchange rows and columns K+1 and IMAX, use 2-by-2 */
  895. /* pivot block */
  896. kp = imax;
  897. kstep = 2;
  898. }
  899. }
  900. }
  901. kk = k + kstep - 1;
  902. if (kstep == 2) {
  903. knc = knc + *n - k + 1;
  904. }
  905. if (kp != kk) {
  906. /* Interchange rows and columns KK and KP in the trailing */
  907. /* submatrix A(k:n,k:n) */
  908. if (kp < *n) {
  909. i__1 = *n - kp;
  910. cswap_(&i__1, &ap[knc + kp - kk + 1], &c__1, &ap[kpc + 1],
  911. &c__1);
  912. }
  913. kx = knc + kp - kk;
  914. i__1 = kp - 1;
  915. for (j = kk + 1; j <= i__1; ++j) {
  916. kx = kx + *n - j + 1;
  917. r_cnjg(&q__1, &ap[knc + j - kk]);
  918. t.r = q__1.r, t.i = q__1.i;
  919. i__2 = knc + j - kk;
  920. r_cnjg(&q__1, &ap[kx]);
  921. ap[i__2].r = q__1.r, ap[i__2].i = q__1.i;
  922. i__2 = kx;
  923. ap[i__2].r = t.r, ap[i__2].i = t.i;
  924. /* L80: */
  925. }
  926. i__1 = knc + kp - kk;
  927. r_cnjg(&q__1, &ap[knc + kp - kk]);
  928. ap[i__1].r = q__1.r, ap[i__1].i = q__1.i;
  929. i__1 = knc;
  930. r1 = ap[i__1].r;
  931. i__1 = knc;
  932. i__2 = kpc;
  933. r__1 = ap[i__2].r;
  934. ap[i__1].r = r__1, ap[i__1].i = 0.f;
  935. i__1 = kpc;
  936. ap[i__1].r = r1, ap[i__1].i = 0.f;
  937. if (kstep == 2) {
  938. i__1 = kc;
  939. i__2 = kc;
  940. r__1 = ap[i__2].r;
  941. ap[i__1].r = r__1, ap[i__1].i = 0.f;
  942. i__1 = kc + 1;
  943. t.r = ap[i__1].r, t.i = ap[i__1].i;
  944. i__1 = kc + 1;
  945. i__2 = kc + kp - k;
  946. ap[i__1].r = ap[i__2].r, ap[i__1].i = ap[i__2].i;
  947. i__1 = kc + kp - k;
  948. ap[i__1].r = t.r, ap[i__1].i = t.i;
  949. }
  950. } else {
  951. i__1 = kc;
  952. i__2 = kc;
  953. r__1 = ap[i__2].r;
  954. ap[i__1].r = r__1, ap[i__1].i = 0.f;
  955. if (kstep == 2) {
  956. i__1 = knc;
  957. i__2 = knc;
  958. r__1 = ap[i__2].r;
  959. ap[i__1].r = r__1, ap[i__1].i = 0.f;
  960. }
  961. }
  962. /* Update the trailing submatrix */
  963. if (kstep == 1) {
  964. /* 1-by-1 pivot block D(k): column k now holds */
  965. /* W(k) = L(k)*D(k) */
  966. /* where L(k) is the k-th column of L */
  967. if (k < *n) {
  968. /* Perform a rank-1 update of A(k+1:n,k+1:n) as */
  969. /* A := A - L(k)*D(k)*L(k)**H = A - W(k)*(1/D(k))*W(k)**H */
  970. i__1 = kc;
  971. r1 = 1.f / ap[i__1].r;
  972. i__1 = *n - k;
  973. r__1 = -r1;
  974. chpr_(uplo, &i__1, &r__1, &ap[kc + 1], &c__1, &ap[kc + *n
  975. - k + 1]);
  976. /* Store L(k) in column K */
  977. i__1 = *n - k;
  978. csscal_(&i__1, &r1, &ap[kc + 1], &c__1);
  979. }
  980. } else {
  981. /* 2-by-2 pivot block D(k): columns K and K+1 now hold */
  982. /* ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k) */
  983. /* where L(k) and L(k+1) are the k-th and (k+1)-th columns */
  984. /* of L */
  985. if (k < *n - 1) {
  986. /* Perform a rank-2 update of A(k+2:n,k+2:n) as */
  987. /* A := A - ( L(k) L(k+1) )*D(k)*( L(k) L(k+1) )**H */
  988. /* = A - ( W(k) W(k+1) )*inv(D(k))*( W(k) W(k+1) )**H */
  989. /* where L(k) and L(k+1) are the k-th and (k+1)-th */
  990. /* columns of L */
  991. i__1 = k + 1 + (k - 1) * ((*n << 1) - k) / 2;
  992. r__1 = ap[i__1].r;
  993. r__2 = r_imag(&ap[k + 1 + (k - 1) * ((*n << 1) - k) / 2]);
  994. d__ = slapy2_(&r__1, &r__2);
  995. i__1 = k + 1 + k * ((*n << 1) - k - 1) / 2;
  996. d11 = ap[i__1].r / d__;
  997. i__1 = k + (k - 1) * ((*n << 1) - k) / 2;
  998. d22 = ap[i__1].r / d__;
  999. tt = 1.f / (d11 * d22 - 1.f);
  1000. i__1 = k + 1 + (k - 1) * ((*n << 1) - k) / 2;
  1001. q__1.r = ap[i__1].r / d__, q__1.i = ap[i__1].i / d__;
  1002. d21.r = q__1.r, d21.i = q__1.i;
  1003. d__ = tt / d__;
  1004. i__1 = *n;
  1005. for (j = k + 2; j <= i__1; ++j) {
  1006. i__2 = j + (k - 1) * ((*n << 1) - k) / 2;
  1007. q__3.r = d11 * ap[i__2].r, q__3.i = d11 * ap[i__2].i;
  1008. i__3 = j + k * ((*n << 1) - k - 1) / 2;
  1009. q__4.r = d21.r * ap[i__3].r - d21.i * ap[i__3].i,
  1010. q__4.i = d21.r * ap[i__3].i + d21.i * ap[i__3]
  1011. .r;
  1012. q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i;
  1013. q__1.r = d__ * q__2.r, q__1.i = d__ * q__2.i;
  1014. wk.r = q__1.r, wk.i = q__1.i;
  1015. i__2 = j + k * ((*n << 1) - k - 1) / 2;
  1016. q__3.r = d22 * ap[i__2].r, q__3.i = d22 * ap[i__2].i;
  1017. r_cnjg(&q__5, &d21);
  1018. i__3 = j + (k - 1) * ((*n << 1) - k) / 2;
  1019. q__4.r = q__5.r * ap[i__3].r - q__5.i * ap[i__3].i,
  1020. q__4.i = q__5.r * ap[i__3].i + q__5.i * ap[
  1021. i__3].r;
  1022. q__2.r = q__3.r - q__4.r, q__2.i = q__3.i - q__4.i;
  1023. q__1.r = d__ * q__2.r, q__1.i = d__ * q__2.i;
  1024. wkp1.r = q__1.r, wkp1.i = q__1.i;
  1025. i__2 = *n;
  1026. for (i__ = j; i__ <= i__2; ++i__) {
  1027. i__3 = i__ + (j - 1) * ((*n << 1) - j) / 2;
  1028. i__4 = i__ + (j - 1) * ((*n << 1) - j) / 2;
  1029. i__5 = i__ + (k - 1) * ((*n << 1) - k) / 2;
  1030. r_cnjg(&q__4, &wk);
  1031. q__3.r = ap[i__5].r * q__4.r - ap[i__5].i *
  1032. q__4.i, q__3.i = ap[i__5].r * q__4.i + ap[
  1033. i__5].i * q__4.r;
  1034. q__2.r = ap[i__4].r - q__3.r, q__2.i = ap[i__4].i
  1035. - q__3.i;
  1036. i__6 = i__ + k * ((*n << 1) - k - 1) / 2;
  1037. r_cnjg(&q__6, &wkp1);
  1038. q__5.r = ap[i__6].r * q__6.r - ap[i__6].i *
  1039. q__6.i, q__5.i = ap[i__6].r * q__6.i + ap[
  1040. i__6].i * q__6.r;
  1041. q__1.r = q__2.r - q__5.r, q__1.i = q__2.i -
  1042. q__5.i;
  1043. ap[i__3].r = q__1.r, ap[i__3].i = q__1.i;
  1044. /* L90: */
  1045. }
  1046. i__2 = j + (k - 1) * ((*n << 1) - k) / 2;
  1047. ap[i__2].r = wk.r, ap[i__2].i = wk.i;
  1048. i__2 = j + k * ((*n << 1) - k - 1) / 2;
  1049. ap[i__2].r = wkp1.r, ap[i__2].i = wkp1.i;
  1050. i__2 = j + (j - 1) * ((*n << 1) - j) / 2;
  1051. i__3 = j + (j - 1) * ((*n << 1) - j) / 2;
  1052. r__1 = ap[i__3].r;
  1053. q__1.r = r__1, q__1.i = 0.f;
  1054. ap[i__2].r = q__1.r, ap[i__2].i = q__1.i;
  1055. /* L100: */
  1056. }
  1057. }
  1058. }
  1059. }
  1060. /* Store details of the interchanges in IPIV */
  1061. if (kstep == 1) {
  1062. ipiv[k] = kp;
  1063. } else {
  1064. ipiv[k] = -kp;
  1065. ipiv[k + 1] = -kp;
  1066. }
  1067. /* Increase K and return to the start of the main loop */
  1068. k += kstep;
  1069. kc = knc + *n - k + 2;
  1070. goto L60;
  1071. }
  1072. L110:
  1073. return 0;
  1074. /* End of CHPTRF */
  1075. } /* chptrf_ */