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

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