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.

zhptrf.c 35 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262
  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 ZHPTRF */
  382. /* =========== DOCUMENTATION =========== */
  383. /* Online html documentation available at */
  384. /* http://www.netlib.org/lapack/explore-html/ */
  385. /* > \htmlonly */
  386. /* > Download ZHPTRF + dependencies */
  387. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhptrf.
  388. f"> */
  389. /* > [TGZ]</a> */
  390. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhptrf.
  391. f"> */
  392. /* > [ZIP]</a> */
  393. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhptrf.
  394. f"> */
  395. /* > [TXT]</a> */
  396. /* > \endhtmlonly */
  397. /* Definition: */
  398. /* =========== */
  399. /* SUBROUTINE ZHPTRF( UPLO, N, AP, IPIV, INFO ) */
  400. /* CHARACTER UPLO */
  401. /* INTEGER INFO, N */
  402. /* INTEGER IPIV( * ) */
  403. /* COMPLEX*16 AP( * ) */
  404. /* > \par Purpose: */
  405. /* ============= */
  406. /* > */
  407. /* > \verbatim */
  408. /* > */
  409. /* > ZHPTRF 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*16 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 complex16OTHERcomputational */
  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. /* Subroutine */ int zhptrf_(char *uplo, integer *n, doublecomplex *ap,
  523. integer *ipiv, integer *info)
  524. {
  525. /* System generated locals */
  526. integer i__1, i__2, i__3, i__4, i__5, i__6;
  527. doublereal d__1, d__2, d__3, d__4;
  528. doublecomplex z__1, z__2, z__3, z__4, z__5, z__6;
  529. /* Local variables */
  530. integer imax, jmax;
  531. extern /* Subroutine */ int zhpr_(char *, integer *, doublereal *,
  532. doublecomplex *, integer *, doublecomplex *);
  533. doublereal d__;
  534. integer i__, j, k;
  535. doublecomplex t;
  536. doublereal alpha;
  537. extern logical lsame_(char *, char *);
  538. integer kstep;
  539. logical upper;
  540. doublereal r1;
  541. extern /* Subroutine */ int zswap_(integer *, doublecomplex *, integer *,
  542. doublecomplex *, integer *);
  543. extern doublereal dlapy2_(doublereal *, doublereal *);
  544. doublereal d11;
  545. doublecomplex d12;
  546. doublereal d22;
  547. doublecomplex d21;
  548. integer kc, kk, kp;
  549. doublereal absakk;
  550. doublecomplex wk;
  551. integer kx;
  552. doublereal tt;
  553. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen), zdscal_(
  554. integer *, doublereal *, doublecomplex *, integer *);
  555. doublereal colmax;
  556. extern integer izamax_(integer *, doublecomplex *, integer *);
  557. doublereal rowmax;
  558. integer knc, kpc, npp;
  559. doublecomplex wkm1, wkp1;
  560. /* -- LAPACK computational routine (version 3.7.0) -- */
  561. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  562. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  563. /* December 2016 */
  564. /* ===================================================================== */
  565. /* Test the input parameters. */
  566. /* Parameter adjustments */
  567. --ipiv;
  568. --ap;
  569. /* Function Body */
  570. *info = 0;
  571. upper = lsame_(uplo, "U");
  572. if (! upper && ! lsame_(uplo, "L")) {
  573. *info = -1;
  574. } else if (*n < 0) {
  575. *info = -2;
  576. }
  577. if (*info != 0) {
  578. i__1 = -(*info);
  579. xerbla_("ZHPTRF", &i__1, (ftnlen)6);
  580. return 0;
  581. }
  582. /* Initialize ALPHA for use in choosing pivot block size. */
  583. alpha = (sqrt(17.) + 1.) / 8.;
  584. if (upper) {
  585. /* Factorize A as U*D*U**H using the upper triangle of A */
  586. /* K is the main loop index, decreasing from N to 1 in steps of */
  587. /* 1 or 2 */
  588. k = *n;
  589. kc = (*n - 1) * *n / 2 + 1;
  590. L10:
  591. knc = kc;
  592. /* If K < 1, exit from loop */
  593. if (k < 1) {
  594. goto L110;
  595. }
  596. kstep = 1;
  597. /* Determine rows and columns to be interchanged and whether */
  598. /* a 1-by-1 or 2-by-2 pivot block will be used */
  599. i__1 = kc + k - 1;
  600. absakk = (d__1 = ap[i__1].r, abs(d__1));
  601. /* IMAX is the row-index of the largest off-diagonal element in */
  602. /* column K, and COLMAX is its absolute value */
  603. if (k > 1) {
  604. i__1 = k - 1;
  605. imax = izamax_(&i__1, &ap[kc], &c__1);
  606. i__1 = kc + imax - 1;
  607. colmax = (d__1 = ap[i__1].r, abs(d__1)) + (d__2 = d_imag(&ap[kc +
  608. imax - 1]), abs(d__2));
  609. } else {
  610. colmax = 0.;
  611. }
  612. if (f2cmax(absakk,colmax) == 0.) {
  613. /* Column K is zero: set INFO and continue */
  614. if (*info == 0) {
  615. *info = k;
  616. }
  617. kp = k;
  618. i__1 = kc + k - 1;
  619. i__2 = kc + k - 1;
  620. d__1 = ap[i__2].r;
  621. ap[i__1].r = d__1, ap[i__1].i = 0.;
  622. } else {
  623. if (absakk >= alpha * colmax) {
  624. /* no interchange, use 1-by-1 pivot block */
  625. kp = k;
  626. } else {
  627. /* JMAX is the column-index of the largest off-diagonal */
  628. /* element in row IMAX, and ROWMAX is its absolute value */
  629. rowmax = 0.;
  630. jmax = imax;
  631. kx = imax * (imax + 1) / 2 + imax;
  632. i__1 = k;
  633. for (j = imax + 1; j <= i__1; ++j) {
  634. i__2 = kx;
  635. if ((d__1 = ap[i__2].r, abs(d__1)) + (d__2 = d_imag(&ap[
  636. kx]), abs(d__2)) > rowmax) {
  637. i__2 = kx;
  638. rowmax = (d__1 = ap[i__2].r, abs(d__1)) + (d__2 =
  639. d_imag(&ap[kx]), abs(d__2));
  640. jmax = j;
  641. }
  642. kx += j;
  643. /* L20: */
  644. }
  645. kpc = (imax - 1) * imax / 2 + 1;
  646. if (imax > 1) {
  647. i__1 = imax - 1;
  648. jmax = izamax_(&i__1, &ap[kpc], &c__1);
  649. /* Computing MAX */
  650. i__1 = kpc + jmax - 1;
  651. d__3 = rowmax, d__4 = (d__1 = ap[i__1].r, abs(d__1)) + (
  652. d__2 = d_imag(&ap[kpc + jmax - 1]), abs(d__2));
  653. rowmax = f2cmax(d__3,d__4);
  654. }
  655. if (absakk >= alpha * colmax * (colmax / rowmax)) {
  656. /* no interchange, use 1-by-1 pivot block */
  657. kp = k;
  658. } else /* if(complicated condition) */ {
  659. i__1 = kpc + imax - 1;
  660. if ((d__1 = ap[i__1].r, abs(d__1)) >= alpha * rowmax) {
  661. /* interchange rows and columns K and IMAX, use 1-by-1 */
  662. /* pivot block */
  663. kp = imax;
  664. } else {
  665. /* interchange rows and columns K-1 and IMAX, use 2-by-2 */
  666. /* pivot block */
  667. kp = imax;
  668. kstep = 2;
  669. }
  670. }
  671. }
  672. kk = k - kstep + 1;
  673. if (kstep == 2) {
  674. knc = knc - k + 1;
  675. }
  676. if (kp != kk) {
  677. /* Interchange rows and columns KK and KP in the leading */
  678. /* submatrix A(1:k,1:k) */
  679. i__1 = kp - 1;
  680. zswap_(&i__1, &ap[knc], &c__1, &ap[kpc], &c__1);
  681. kx = kpc + kp - 1;
  682. i__1 = kk - 1;
  683. for (j = kp + 1; j <= i__1; ++j) {
  684. kx = kx + j - 1;
  685. d_cnjg(&z__1, &ap[knc + j - 1]);
  686. t.r = z__1.r, t.i = z__1.i;
  687. i__2 = knc + j - 1;
  688. d_cnjg(&z__1, &ap[kx]);
  689. ap[i__2].r = z__1.r, ap[i__2].i = z__1.i;
  690. i__2 = kx;
  691. ap[i__2].r = t.r, ap[i__2].i = t.i;
  692. /* L30: */
  693. }
  694. i__1 = kx + kk - 1;
  695. d_cnjg(&z__1, &ap[kx + kk - 1]);
  696. ap[i__1].r = z__1.r, ap[i__1].i = z__1.i;
  697. i__1 = knc + kk - 1;
  698. r1 = ap[i__1].r;
  699. i__1 = knc + kk - 1;
  700. i__2 = kpc + kp - 1;
  701. d__1 = ap[i__2].r;
  702. ap[i__1].r = d__1, ap[i__1].i = 0.;
  703. i__1 = kpc + kp - 1;
  704. ap[i__1].r = r1, ap[i__1].i = 0.;
  705. if (kstep == 2) {
  706. i__1 = kc + k - 1;
  707. i__2 = kc + k - 1;
  708. d__1 = ap[i__2].r;
  709. ap[i__1].r = d__1, ap[i__1].i = 0.;
  710. i__1 = kc + k - 2;
  711. t.r = ap[i__1].r, t.i = ap[i__1].i;
  712. i__1 = kc + k - 2;
  713. i__2 = kc + kp - 1;
  714. ap[i__1].r = ap[i__2].r, ap[i__1].i = ap[i__2].i;
  715. i__1 = kc + kp - 1;
  716. ap[i__1].r = t.r, ap[i__1].i = t.i;
  717. }
  718. } else {
  719. i__1 = kc + k - 1;
  720. i__2 = kc + k - 1;
  721. d__1 = ap[i__2].r;
  722. ap[i__1].r = d__1, ap[i__1].i = 0.;
  723. if (kstep == 2) {
  724. i__1 = kc - 1;
  725. i__2 = kc - 1;
  726. d__1 = ap[i__2].r;
  727. ap[i__1].r = d__1, ap[i__1].i = 0.;
  728. }
  729. }
  730. /* Update the leading submatrix */
  731. if (kstep == 1) {
  732. /* 1-by-1 pivot block D(k): column k now holds */
  733. /* W(k) = U(k)*D(k) */
  734. /* where U(k) is the k-th column of U */
  735. /* Perform a rank-1 update of A(1:k-1,1:k-1) as */
  736. /* A := A - U(k)*D(k)*U(k)**H = A - W(k)*1/D(k)*W(k)**H */
  737. i__1 = kc + k - 1;
  738. r1 = 1. / ap[i__1].r;
  739. i__1 = k - 1;
  740. d__1 = -r1;
  741. zhpr_(uplo, &i__1, &d__1, &ap[kc], &c__1, &ap[1]);
  742. /* Store U(k) in column k */
  743. i__1 = k - 1;
  744. zdscal_(&i__1, &r1, &ap[kc], &c__1);
  745. } else {
  746. /* 2-by-2 pivot block D(k): columns k and k-1 now hold */
  747. /* ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k) */
  748. /* where U(k) and U(k-1) are the k-th and (k-1)-th columns */
  749. /* of U */
  750. /* Perform a rank-2 update of A(1:k-2,1:k-2) as */
  751. /* A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**H */
  752. /* = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )**H */
  753. if (k > 2) {
  754. i__1 = k - 1 + (k - 1) * k / 2;
  755. d__1 = ap[i__1].r;
  756. d__2 = d_imag(&ap[k - 1 + (k - 1) * k / 2]);
  757. d__ = dlapy2_(&d__1, &d__2);
  758. i__1 = k - 1 + (k - 2) * (k - 1) / 2;
  759. d22 = ap[i__1].r / d__;
  760. i__1 = k + (k - 1) * k / 2;
  761. d11 = ap[i__1].r / d__;
  762. tt = 1. / (d11 * d22 - 1.);
  763. i__1 = k - 1 + (k - 1) * k / 2;
  764. z__1.r = ap[i__1].r / d__, z__1.i = ap[i__1].i / d__;
  765. d12.r = z__1.r, d12.i = z__1.i;
  766. d__ = tt / d__;
  767. for (j = k - 2; j >= 1; --j) {
  768. i__1 = j + (k - 2) * (k - 1) / 2;
  769. z__3.r = d11 * ap[i__1].r, z__3.i = d11 * ap[i__1].i;
  770. d_cnjg(&z__5, &d12);
  771. i__2 = j + (k - 1) * k / 2;
  772. z__4.r = z__5.r * ap[i__2].r - z__5.i * ap[i__2].i,
  773. z__4.i = z__5.r * ap[i__2].i + z__5.i * ap[
  774. i__2].r;
  775. z__2.r = z__3.r - z__4.r, z__2.i = z__3.i - z__4.i;
  776. z__1.r = d__ * z__2.r, z__1.i = d__ * z__2.i;
  777. wkm1.r = z__1.r, wkm1.i = z__1.i;
  778. i__1 = j + (k - 1) * k / 2;
  779. z__3.r = d22 * ap[i__1].r, z__3.i = d22 * ap[i__1].i;
  780. i__2 = j + (k - 2) * (k - 1) / 2;
  781. z__4.r = d12.r * ap[i__2].r - d12.i * ap[i__2].i,
  782. z__4.i = d12.r * ap[i__2].i + d12.i * ap[i__2]
  783. .r;
  784. z__2.r = z__3.r - z__4.r, z__2.i = z__3.i - z__4.i;
  785. z__1.r = d__ * z__2.r, z__1.i = d__ * z__2.i;
  786. wk.r = z__1.r, wk.i = z__1.i;
  787. for (i__ = j; i__ >= 1; --i__) {
  788. i__1 = i__ + (j - 1) * j / 2;
  789. i__2 = i__ + (j - 1) * j / 2;
  790. i__3 = i__ + (k - 1) * k / 2;
  791. d_cnjg(&z__4, &wk);
  792. z__3.r = ap[i__3].r * z__4.r - ap[i__3].i *
  793. z__4.i, z__3.i = ap[i__3].r * z__4.i + ap[
  794. i__3].i * z__4.r;
  795. z__2.r = ap[i__2].r - z__3.r, z__2.i = ap[i__2].i
  796. - z__3.i;
  797. i__4 = i__ + (k - 2) * (k - 1) / 2;
  798. d_cnjg(&z__6, &wkm1);
  799. z__5.r = ap[i__4].r * z__6.r - ap[i__4].i *
  800. z__6.i, z__5.i = ap[i__4].r * z__6.i + ap[
  801. i__4].i * z__6.r;
  802. z__1.r = z__2.r - z__5.r, z__1.i = z__2.i -
  803. z__5.i;
  804. ap[i__1].r = z__1.r, ap[i__1].i = z__1.i;
  805. /* L40: */
  806. }
  807. i__1 = j + (k - 1) * k / 2;
  808. ap[i__1].r = wk.r, ap[i__1].i = wk.i;
  809. i__1 = j + (k - 2) * (k - 1) / 2;
  810. ap[i__1].r = wkm1.r, ap[i__1].i = wkm1.i;
  811. i__1 = j + (j - 1) * j / 2;
  812. i__2 = j + (j - 1) * j / 2;
  813. d__1 = ap[i__2].r;
  814. z__1.r = d__1, z__1.i = 0.;
  815. ap[i__1].r = z__1.r, ap[i__1].i = z__1.i;
  816. /* L50: */
  817. }
  818. }
  819. }
  820. }
  821. /* Store details of the interchanges in IPIV */
  822. if (kstep == 1) {
  823. ipiv[k] = kp;
  824. } else {
  825. ipiv[k] = -kp;
  826. ipiv[k - 1] = -kp;
  827. }
  828. /* Decrease K and return to the start of the main loop */
  829. k -= kstep;
  830. kc = knc - k;
  831. goto L10;
  832. } else {
  833. /* Factorize A as L*D*L**H using the lower triangle of A */
  834. /* K is the main loop index, increasing from 1 to N in steps of */
  835. /* 1 or 2 */
  836. k = 1;
  837. kc = 1;
  838. npp = *n * (*n + 1) / 2;
  839. L60:
  840. knc = kc;
  841. /* If K > N, exit from loop */
  842. if (k > *n) {
  843. goto L110;
  844. }
  845. kstep = 1;
  846. /* Determine rows and columns to be interchanged and whether */
  847. /* a 1-by-1 or 2-by-2 pivot block will be used */
  848. i__1 = kc;
  849. absakk = (d__1 = ap[i__1].r, abs(d__1));
  850. /* IMAX is the row-index of the largest off-diagonal element in */
  851. /* column K, and COLMAX is its absolute value */
  852. if (k < *n) {
  853. i__1 = *n - k;
  854. imax = k + izamax_(&i__1, &ap[kc + 1], &c__1);
  855. i__1 = kc + imax - k;
  856. colmax = (d__1 = ap[i__1].r, abs(d__1)) + (d__2 = d_imag(&ap[kc +
  857. imax - k]), abs(d__2));
  858. } else {
  859. colmax = 0.;
  860. }
  861. if (f2cmax(absakk,colmax) == 0.) {
  862. /* Column K is zero: set INFO and continue */
  863. if (*info == 0) {
  864. *info = k;
  865. }
  866. kp = k;
  867. i__1 = kc;
  868. i__2 = kc;
  869. d__1 = ap[i__2].r;
  870. ap[i__1].r = d__1, ap[i__1].i = 0.;
  871. } else {
  872. if (absakk >= alpha * colmax) {
  873. /* no interchange, use 1-by-1 pivot block */
  874. kp = k;
  875. } else {
  876. /* JMAX is the column-index of the largest off-diagonal */
  877. /* element in row IMAX, and ROWMAX is its absolute value */
  878. rowmax = 0.;
  879. kx = kc + imax - k;
  880. i__1 = imax - 1;
  881. for (j = k; j <= i__1; ++j) {
  882. i__2 = kx;
  883. if ((d__1 = ap[i__2].r, abs(d__1)) + (d__2 = d_imag(&ap[
  884. kx]), abs(d__2)) > rowmax) {
  885. i__2 = kx;
  886. rowmax = (d__1 = ap[i__2].r, abs(d__1)) + (d__2 =
  887. d_imag(&ap[kx]), abs(d__2));
  888. jmax = j;
  889. }
  890. kx = kx + *n - j;
  891. /* L70: */
  892. }
  893. kpc = npp - (*n - imax + 1) * (*n - imax + 2) / 2 + 1;
  894. if (imax < *n) {
  895. i__1 = *n - imax;
  896. jmax = imax + izamax_(&i__1, &ap[kpc + 1], &c__1);
  897. /* Computing MAX */
  898. i__1 = kpc + jmax - imax;
  899. d__3 = rowmax, d__4 = (d__1 = ap[i__1].r, abs(d__1)) + (
  900. d__2 = d_imag(&ap[kpc + jmax - imax]), abs(d__2));
  901. rowmax = f2cmax(d__3,d__4);
  902. }
  903. if (absakk >= alpha * colmax * (colmax / rowmax)) {
  904. /* no interchange, use 1-by-1 pivot block */
  905. kp = k;
  906. } else /* if(complicated condition) */ {
  907. i__1 = kpc;
  908. if ((d__1 = ap[i__1].r, abs(d__1)) >= alpha * rowmax) {
  909. /* interchange rows and columns K and IMAX, use 1-by-1 */
  910. /* pivot block */
  911. kp = imax;
  912. } else {
  913. /* interchange rows and columns K+1 and IMAX, use 2-by-2 */
  914. /* pivot block */
  915. kp = imax;
  916. kstep = 2;
  917. }
  918. }
  919. }
  920. kk = k + kstep - 1;
  921. if (kstep == 2) {
  922. knc = knc + *n - k + 1;
  923. }
  924. if (kp != kk) {
  925. /* Interchange rows and columns KK and KP in the trailing */
  926. /* submatrix A(k:n,k:n) */
  927. if (kp < *n) {
  928. i__1 = *n - kp;
  929. zswap_(&i__1, &ap[knc + kp - kk + 1], &c__1, &ap[kpc + 1],
  930. &c__1);
  931. }
  932. kx = knc + kp - kk;
  933. i__1 = kp - 1;
  934. for (j = kk + 1; j <= i__1; ++j) {
  935. kx = kx + *n - j + 1;
  936. d_cnjg(&z__1, &ap[knc + j - kk]);
  937. t.r = z__1.r, t.i = z__1.i;
  938. i__2 = knc + j - kk;
  939. d_cnjg(&z__1, &ap[kx]);
  940. ap[i__2].r = z__1.r, ap[i__2].i = z__1.i;
  941. i__2 = kx;
  942. ap[i__2].r = t.r, ap[i__2].i = t.i;
  943. /* L80: */
  944. }
  945. i__1 = knc + kp - kk;
  946. d_cnjg(&z__1, &ap[knc + kp - kk]);
  947. ap[i__1].r = z__1.r, ap[i__1].i = z__1.i;
  948. i__1 = knc;
  949. r1 = ap[i__1].r;
  950. i__1 = knc;
  951. i__2 = kpc;
  952. d__1 = ap[i__2].r;
  953. ap[i__1].r = d__1, ap[i__1].i = 0.;
  954. i__1 = kpc;
  955. ap[i__1].r = r1, ap[i__1].i = 0.;
  956. if (kstep == 2) {
  957. i__1 = kc;
  958. i__2 = kc;
  959. d__1 = ap[i__2].r;
  960. ap[i__1].r = d__1, ap[i__1].i = 0.;
  961. i__1 = kc + 1;
  962. t.r = ap[i__1].r, t.i = ap[i__1].i;
  963. i__1 = kc + 1;
  964. i__2 = kc + kp - k;
  965. ap[i__1].r = ap[i__2].r, ap[i__1].i = ap[i__2].i;
  966. i__1 = kc + kp - k;
  967. ap[i__1].r = t.r, ap[i__1].i = t.i;
  968. }
  969. } else {
  970. i__1 = kc;
  971. i__2 = kc;
  972. d__1 = ap[i__2].r;
  973. ap[i__1].r = d__1, ap[i__1].i = 0.;
  974. if (kstep == 2) {
  975. i__1 = knc;
  976. i__2 = knc;
  977. d__1 = ap[i__2].r;
  978. ap[i__1].r = d__1, ap[i__1].i = 0.;
  979. }
  980. }
  981. /* Update the trailing submatrix */
  982. if (kstep == 1) {
  983. /* 1-by-1 pivot block D(k): column k now holds */
  984. /* W(k) = L(k)*D(k) */
  985. /* where L(k) is the k-th column of L */
  986. if (k < *n) {
  987. /* Perform a rank-1 update of A(k+1:n,k+1:n) as */
  988. /* A := A - L(k)*D(k)*L(k)**H = A - W(k)*(1/D(k))*W(k)**H */
  989. i__1 = kc;
  990. r1 = 1. / ap[i__1].r;
  991. i__1 = *n - k;
  992. d__1 = -r1;
  993. zhpr_(uplo, &i__1, &d__1, &ap[kc + 1], &c__1, &ap[kc + *n
  994. - k + 1]);
  995. /* Store L(k) in column K */
  996. i__1 = *n - k;
  997. zdscal_(&i__1, &r1, &ap[kc + 1], &c__1);
  998. }
  999. } else {
  1000. /* 2-by-2 pivot block D(k): columns K and K+1 now hold */
  1001. /* ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k) */
  1002. /* where L(k) and L(k+1) are the k-th and (k+1)-th columns */
  1003. /* of L */
  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 - 1) * ((*n << 1) - k) / 2;
  1011. d__1 = ap[i__1].r;
  1012. d__2 = d_imag(&ap[k + 1 + (k - 1) * ((*n << 1) - k) / 2]);
  1013. d__ = dlapy2_(&d__1, &d__2);
  1014. i__1 = k + 1 + k * ((*n << 1) - k - 1) / 2;
  1015. d11 = ap[i__1].r / d__;
  1016. i__1 = k + (k - 1) * ((*n << 1) - k) / 2;
  1017. d22 = ap[i__1].r / d__;
  1018. tt = 1. / (d11 * d22 - 1.);
  1019. i__1 = k + 1 + (k - 1) * ((*n << 1) - k) / 2;
  1020. z__1.r = ap[i__1].r / d__, z__1.i = ap[i__1].i / d__;
  1021. d21.r = z__1.r, d21.i = z__1.i;
  1022. d__ = tt / d__;
  1023. i__1 = *n;
  1024. for (j = k + 2; j <= i__1; ++j) {
  1025. i__2 = j + (k - 1) * ((*n << 1) - k) / 2;
  1026. z__3.r = d11 * ap[i__2].r, z__3.i = d11 * ap[i__2].i;
  1027. i__3 = j + k * ((*n << 1) - k - 1) / 2;
  1028. z__4.r = d21.r * ap[i__3].r - d21.i * ap[i__3].i,
  1029. z__4.i = d21.r * ap[i__3].i + d21.i * ap[i__3]
  1030. .r;
  1031. z__2.r = z__3.r - z__4.r, z__2.i = z__3.i - z__4.i;
  1032. z__1.r = d__ * z__2.r, z__1.i = d__ * z__2.i;
  1033. wk.r = z__1.r, wk.i = z__1.i;
  1034. i__2 = j + k * ((*n << 1) - k - 1) / 2;
  1035. z__3.r = d22 * ap[i__2].r, z__3.i = d22 * ap[i__2].i;
  1036. d_cnjg(&z__5, &d21);
  1037. i__3 = j + (k - 1) * ((*n << 1) - k) / 2;
  1038. z__4.r = z__5.r * ap[i__3].r - z__5.i * ap[i__3].i,
  1039. z__4.i = z__5.r * ap[i__3].i + z__5.i * ap[
  1040. i__3].r;
  1041. z__2.r = z__3.r - z__4.r, z__2.i = z__3.i - z__4.i;
  1042. z__1.r = d__ * z__2.r, z__1.i = d__ * z__2.i;
  1043. wkp1.r = z__1.r, wkp1.i = z__1.i;
  1044. i__2 = *n;
  1045. for (i__ = j; i__ <= i__2; ++i__) {
  1046. i__3 = i__ + (j - 1) * ((*n << 1) - j) / 2;
  1047. i__4 = i__ + (j - 1) * ((*n << 1) - j) / 2;
  1048. i__5 = i__ + (k - 1) * ((*n << 1) - k) / 2;
  1049. d_cnjg(&z__4, &wk);
  1050. z__3.r = ap[i__5].r * z__4.r - ap[i__5].i *
  1051. z__4.i, z__3.i = ap[i__5].r * z__4.i + ap[
  1052. i__5].i * z__4.r;
  1053. z__2.r = ap[i__4].r - z__3.r, z__2.i = ap[i__4].i
  1054. - z__3.i;
  1055. i__6 = i__ + k * ((*n << 1) - k - 1) / 2;
  1056. d_cnjg(&z__6, &wkp1);
  1057. z__5.r = ap[i__6].r * z__6.r - ap[i__6].i *
  1058. z__6.i, z__5.i = ap[i__6].r * z__6.i + ap[
  1059. i__6].i * z__6.r;
  1060. z__1.r = z__2.r - z__5.r, z__1.i = z__2.i -
  1061. z__5.i;
  1062. ap[i__3].r = z__1.r, ap[i__3].i = z__1.i;
  1063. /* L90: */
  1064. }
  1065. i__2 = j + (k - 1) * ((*n << 1) - k) / 2;
  1066. ap[i__2].r = wk.r, ap[i__2].i = wk.i;
  1067. i__2 = j + k * ((*n << 1) - k - 1) / 2;
  1068. ap[i__2].r = wkp1.r, ap[i__2].i = wkp1.i;
  1069. i__2 = j + (j - 1) * ((*n << 1) - j) / 2;
  1070. i__3 = j + (j - 1) * ((*n << 1) - j) / 2;
  1071. d__1 = ap[i__3].r;
  1072. z__1.r = d__1, z__1.i = 0.;
  1073. ap[i__2].r = z__1.r, ap[i__2].i = z__1.i;
  1074. /* L100: */
  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. kc = knc + *n - k + 2;
  1089. goto L60;
  1090. }
  1091. L110:
  1092. return 0;
  1093. /* End of ZHPTRF */
  1094. } /* zhptrf_ */