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

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