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.

dsptrf.c 29 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052
  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 DSPTRF */
  364. /* =========== DOCUMENTATION =========== */
  365. /* Online html documentation available at */
  366. /* http://www.netlib.org/lapack/explore-html/ */
  367. /* > \htmlonly */
  368. /* > Download DSPTRF + dependencies */
  369. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsptrf.
  370. f"> */
  371. /* > [TGZ]</a> */
  372. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsptrf.
  373. f"> */
  374. /* > [ZIP]</a> */
  375. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsptrf.
  376. f"> */
  377. /* > [TXT]</a> */
  378. /* > \endhtmlonly */
  379. /* Definition: */
  380. /* =========== */
  381. /* SUBROUTINE DSPTRF( UPLO, N, AP, IPIV, INFO ) */
  382. /* CHARACTER UPLO */
  383. /* INTEGER INFO, N */
  384. /* INTEGER IPIV( * ) */
  385. /* DOUBLE PRECISION AP( * ) */
  386. /* > \par Purpose: */
  387. /* ============= */
  388. /* > */
  389. /* > \verbatim */
  390. /* > */
  391. /* > DSPTRF computes the factorization of a real symmetric matrix A stored */
  392. /* > in packed format using the Bunch-Kaufman diagonal pivoting method: */
  393. /* > */
  394. /* > A = U*D*U**T or A = L*D*L**T */
  395. /* > */
  396. /* > where U (or L) is a product of permutation and unit upper (lower) */
  397. /* > triangular matrices, and D is symmetric 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 DOUBLE PRECISION array, dimension (N*(N+1)/2) */
  418. /* > On entry, the upper or lower triangle of the symmetric 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 doubleOTHERcomputational */
  460. /* > \par Further Details: */
  461. /* ===================== */
  462. /* > */
  463. /* > \verbatim */
  464. /* > */
  465. /* > If UPLO = 'U', then A = U*D*U**T, 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**T, where */
  483. /* > L = P(1)*L(1)* ... *P(k)*L(k)* ..., */
  484. /* > i.e., L is a product of terms P(k)*L(k), where k increases from 1 to */
  485. /* > n in steps of 1 or 2, and D is a block diagonal matrix with 1-by-1 */
  486. /* > and 2-by-2 diagonal blocks D(k). P(k) is a permutation matrix as */
  487. /* > defined by IPIV(k), and L(k) is a unit lower triangular matrix, such */
  488. /* > that if the diagonal block D(k) is of order s (s = 1 or 2), then */
  489. /* > */
  490. /* > ( I 0 0 ) k-1 */
  491. /* > L(k) = ( 0 I 0 ) s */
  492. /* > ( 0 v I ) n-k-s+1 */
  493. /* > k-1 s n-k-s+1 */
  494. /* > */
  495. /* > If s = 1, D(k) overwrites A(k,k), and v overwrites A(k+1:n,k). */
  496. /* > If s = 2, the lower triangle of D(k) overwrites A(k,k), A(k+1,k), */
  497. /* > and A(k+1,k+1), and v overwrites A(k+2:n,k:k+1). */
  498. /* > \endverbatim */
  499. /* > \par Contributors: */
  500. /* ================== */
  501. /* > */
  502. /* > J. Lewis, Boeing Computer Services Company */
  503. /* > */
  504. /* ===================================================================== */
  505. /* Subroutine */ int dsptrf_(char *uplo, integer *n, doublereal *ap, integer *
  506. ipiv, integer *info)
  507. {
  508. /* System generated locals */
  509. integer i__1, i__2;
  510. doublereal d__1, d__2, d__3;
  511. /* Local variables */
  512. integer imax, jmax;
  513. extern /* Subroutine */ int dspr_(char *, integer *, doublereal *,
  514. doublereal *, integer *, doublereal *);
  515. integer i__, j, k;
  516. doublereal t, alpha;
  517. extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
  518. integer *);
  519. extern logical lsame_(char *, char *);
  520. extern /* Subroutine */ int dswap_(integer *, doublereal *, integer *,
  521. doublereal *, integer *);
  522. integer kstep;
  523. logical upper;
  524. doublereal r1, d11, d12, d21, d22;
  525. integer kc, kk, kp;
  526. doublereal absakk, wk;
  527. integer kx;
  528. extern integer idamax_(integer *, doublereal *, integer *);
  529. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  530. doublereal colmax, rowmax;
  531. integer knc, kpc, npp;
  532. doublereal wkm1, wkp1;
  533. /* -- LAPACK computational routine (version 3.7.0) -- */
  534. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  535. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  536. /* December 2016 */
  537. /* ===================================================================== */
  538. /* Test the input parameters. */
  539. /* Parameter adjustments */
  540. --ipiv;
  541. --ap;
  542. /* Function Body */
  543. *info = 0;
  544. upper = lsame_(uplo, "U");
  545. if (! upper && ! lsame_(uplo, "L")) {
  546. *info = -1;
  547. } else if (*n < 0) {
  548. *info = -2;
  549. }
  550. if (*info != 0) {
  551. i__1 = -(*info);
  552. xerbla_("DSPTRF", &i__1, (ftnlen)6);
  553. return 0;
  554. }
  555. /* Initialize ALPHA for use in choosing pivot block size. */
  556. alpha = (sqrt(17.) + 1.) / 8.;
  557. if (upper) {
  558. /* Factorize A as U*D*U**T using the upper triangle of A */
  559. /* K is the main loop index, decreasing from N to 1 in steps of */
  560. /* 1 or 2 */
  561. k = *n;
  562. kc = (*n - 1) * *n / 2 + 1;
  563. L10:
  564. knc = kc;
  565. /* If K < 1, exit from loop */
  566. if (k < 1) {
  567. goto L110;
  568. }
  569. kstep = 1;
  570. /* Determine rows and columns to be interchanged and whether */
  571. /* a 1-by-1 or 2-by-2 pivot block will be used */
  572. absakk = (d__1 = ap[kc + k - 1], abs(d__1));
  573. /* IMAX is the row-index of the largest off-diagonal element in */
  574. /* column K, and COLMAX is its absolute value */
  575. if (k > 1) {
  576. i__1 = k - 1;
  577. imax = idamax_(&i__1, &ap[kc], &c__1);
  578. colmax = (d__1 = ap[kc + imax - 1], abs(d__1));
  579. } else {
  580. colmax = 0.;
  581. }
  582. if (f2cmax(absakk,colmax) == 0.) {
  583. /* Column K is zero: set INFO and continue */
  584. if (*info == 0) {
  585. *info = k;
  586. }
  587. kp = k;
  588. } else {
  589. if (absakk >= alpha * colmax) {
  590. /* no interchange, use 1-by-1 pivot block */
  591. kp = k;
  592. } else {
  593. rowmax = 0.;
  594. jmax = imax;
  595. kx = imax * (imax + 1) / 2 + imax;
  596. i__1 = k;
  597. for (j = imax + 1; j <= i__1; ++j) {
  598. if ((d__1 = ap[kx], abs(d__1)) > rowmax) {
  599. rowmax = (d__1 = ap[kx], abs(d__1));
  600. jmax = j;
  601. }
  602. kx += j;
  603. /* L20: */
  604. }
  605. kpc = (imax - 1) * imax / 2 + 1;
  606. if (imax > 1) {
  607. i__1 = imax - 1;
  608. jmax = idamax_(&i__1, &ap[kpc], &c__1);
  609. /* Computing MAX */
  610. d__2 = rowmax, d__3 = (d__1 = ap[kpc + jmax - 1], abs(
  611. d__1));
  612. rowmax = f2cmax(d__2,d__3);
  613. }
  614. if (absakk >= alpha * colmax * (colmax / rowmax)) {
  615. /* no interchange, use 1-by-1 pivot block */
  616. kp = k;
  617. } else if ((d__1 = ap[kpc + imax - 1], abs(d__1)) >= alpha *
  618. rowmax) {
  619. /* interchange rows and columns K and IMAX, use 1-by-1 */
  620. /* pivot block */
  621. kp = imax;
  622. } else {
  623. /* interchange rows and columns K-1 and IMAX, use 2-by-2 */
  624. /* pivot block */
  625. kp = imax;
  626. kstep = 2;
  627. }
  628. }
  629. kk = k - kstep + 1;
  630. if (kstep == 2) {
  631. knc = knc - k + 1;
  632. }
  633. if (kp != kk) {
  634. /* Interchange rows and columns KK and KP in the leading */
  635. /* submatrix A(1:k,1:k) */
  636. i__1 = kp - 1;
  637. dswap_(&i__1, &ap[knc], &c__1, &ap[kpc], &c__1);
  638. kx = kpc + kp - 1;
  639. i__1 = kk - 1;
  640. for (j = kp + 1; j <= i__1; ++j) {
  641. kx = kx + j - 1;
  642. t = ap[knc + j - 1];
  643. ap[knc + j - 1] = ap[kx];
  644. ap[kx] = t;
  645. /* L30: */
  646. }
  647. t = ap[knc + kk - 1];
  648. ap[knc + kk - 1] = ap[kpc + kp - 1];
  649. ap[kpc + kp - 1] = t;
  650. if (kstep == 2) {
  651. t = ap[kc + k - 2];
  652. ap[kc + k - 2] = ap[kc + kp - 1];
  653. ap[kc + kp - 1] = t;
  654. }
  655. }
  656. /* Update the leading submatrix */
  657. if (kstep == 1) {
  658. /* 1-by-1 pivot block D(k): column k now holds */
  659. /* W(k) = U(k)*D(k) */
  660. /* where U(k) is the k-th column of U */
  661. /* Perform a rank-1 update of A(1:k-1,1:k-1) as */
  662. /* A := A - U(k)*D(k)*U(k)**T = A - W(k)*1/D(k)*W(k)**T */
  663. r1 = 1. / ap[kc + k - 1];
  664. i__1 = k - 1;
  665. d__1 = -r1;
  666. dspr_(uplo, &i__1, &d__1, &ap[kc], &c__1, &ap[1]);
  667. /* Store U(k) in column k */
  668. i__1 = k - 1;
  669. dscal_(&i__1, &r1, &ap[kc], &c__1);
  670. } else {
  671. /* 2-by-2 pivot block D(k): columns k and k-1 now hold */
  672. /* ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k) */
  673. /* where U(k) and U(k-1) are the k-th and (k-1)-th columns */
  674. /* of U */
  675. /* Perform a rank-2 update of A(1:k-2,1:k-2) as */
  676. /* A := A - ( U(k-1) U(k) )*D(k)*( U(k-1) U(k) )**T */
  677. /* = A - ( W(k-1) W(k) )*inv(D(k))*( W(k-1) W(k) )**T */
  678. if (k > 2) {
  679. d12 = ap[k - 1 + (k - 1) * k / 2];
  680. d22 = ap[k - 1 + (k - 2) * (k - 1) / 2] / d12;
  681. d11 = ap[k + (k - 1) * k / 2] / d12;
  682. t = 1. / (d11 * d22 - 1.);
  683. d12 = t / d12;
  684. for (j = k - 2; j >= 1; --j) {
  685. wkm1 = d12 * (d11 * ap[j + (k - 2) * (k - 1) / 2] -
  686. ap[j + (k - 1) * k / 2]);
  687. wk = d12 * (d22 * ap[j + (k - 1) * k / 2] - ap[j + (k
  688. - 2) * (k - 1) / 2]);
  689. for (i__ = j; i__ >= 1; --i__) {
  690. ap[i__ + (j - 1) * j / 2] = ap[i__ + (j - 1) * j /
  691. 2] - ap[i__ + (k - 1) * k / 2] * wk - ap[
  692. i__ + (k - 2) * (k - 1) / 2] * wkm1;
  693. /* L40: */
  694. }
  695. ap[j + (k - 1) * k / 2] = wk;
  696. ap[j + (k - 2) * (k - 1) / 2] = wkm1;
  697. /* L50: */
  698. }
  699. }
  700. }
  701. }
  702. /* Store details of the interchanges in IPIV */
  703. if (kstep == 1) {
  704. ipiv[k] = kp;
  705. } else {
  706. ipiv[k] = -kp;
  707. ipiv[k - 1] = -kp;
  708. }
  709. /* Decrease K and return to the start of the main loop */
  710. k -= kstep;
  711. kc = knc - k;
  712. goto L10;
  713. } else {
  714. /* Factorize A as L*D*L**T using the lower triangle of A */
  715. /* K is the main loop index, increasing from 1 to N in steps of */
  716. /* 1 or 2 */
  717. k = 1;
  718. kc = 1;
  719. npp = *n * (*n + 1) / 2;
  720. L60:
  721. knc = kc;
  722. /* If K > N, exit from loop */
  723. if (k > *n) {
  724. goto L110;
  725. }
  726. kstep = 1;
  727. /* Determine rows and columns to be interchanged and whether */
  728. /* a 1-by-1 or 2-by-2 pivot block will be used */
  729. absakk = (d__1 = ap[kc], abs(d__1));
  730. /* IMAX is the row-index of the largest off-diagonal element in */
  731. /* column K, and COLMAX is its absolute value */
  732. if (k < *n) {
  733. i__1 = *n - k;
  734. imax = k + idamax_(&i__1, &ap[kc + 1], &c__1);
  735. colmax = (d__1 = ap[kc + imax - k], abs(d__1));
  736. } else {
  737. colmax = 0.;
  738. }
  739. if (f2cmax(absakk,colmax) == 0.) {
  740. /* Column K is zero: set INFO and continue */
  741. if (*info == 0) {
  742. *info = k;
  743. }
  744. kp = k;
  745. } else {
  746. if (absakk >= alpha * colmax) {
  747. /* no interchange, use 1-by-1 pivot block */
  748. kp = k;
  749. } else {
  750. /* JMAX is the column-index of the largest off-diagonal */
  751. /* element in row IMAX, and ROWMAX is its absolute value */
  752. rowmax = 0.;
  753. kx = kc + imax - k;
  754. i__1 = imax - 1;
  755. for (j = k; j <= i__1; ++j) {
  756. if ((d__1 = ap[kx], abs(d__1)) > rowmax) {
  757. rowmax = (d__1 = ap[kx], abs(d__1));
  758. jmax = j;
  759. }
  760. kx = kx + *n - j;
  761. /* L70: */
  762. }
  763. kpc = npp - (*n - imax + 1) * (*n - imax + 2) / 2 + 1;
  764. if (imax < *n) {
  765. i__1 = *n - imax;
  766. jmax = imax + idamax_(&i__1, &ap[kpc + 1], &c__1);
  767. /* Computing MAX */
  768. d__2 = rowmax, d__3 = (d__1 = ap[kpc + jmax - imax], abs(
  769. d__1));
  770. rowmax = f2cmax(d__2,d__3);
  771. }
  772. if (absakk >= alpha * colmax * (colmax / rowmax)) {
  773. /* no interchange, use 1-by-1 pivot block */
  774. kp = k;
  775. } else if ((d__1 = ap[kpc], abs(d__1)) >= alpha * rowmax) {
  776. /* interchange rows and columns K and IMAX, use 1-by-1 */
  777. /* pivot block */
  778. kp = imax;
  779. } else {
  780. /* interchange rows and columns K+1 and IMAX, use 2-by-2 */
  781. /* pivot block */
  782. kp = imax;
  783. kstep = 2;
  784. }
  785. }
  786. kk = k + kstep - 1;
  787. if (kstep == 2) {
  788. knc = knc + *n - k + 1;
  789. }
  790. if (kp != kk) {
  791. /* Interchange rows and columns KK and KP in the trailing */
  792. /* submatrix A(k:n,k:n) */
  793. if (kp < *n) {
  794. i__1 = *n - kp;
  795. dswap_(&i__1, &ap[knc + kp - kk + 1], &c__1, &ap[kpc + 1],
  796. &c__1);
  797. }
  798. kx = knc + kp - kk;
  799. i__1 = kp - 1;
  800. for (j = kk + 1; j <= i__1; ++j) {
  801. kx = kx + *n - j + 1;
  802. t = ap[knc + j - kk];
  803. ap[knc + j - kk] = ap[kx];
  804. ap[kx] = t;
  805. /* L80: */
  806. }
  807. t = ap[knc];
  808. ap[knc] = ap[kpc];
  809. ap[kpc] = t;
  810. if (kstep == 2) {
  811. t = ap[kc + 1];
  812. ap[kc + 1] = ap[kc + kp - k];
  813. ap[kc + kp - k] = t;
  814. }
  815. }
  816. /* Update the trailing submatrix */
  817. if (kstep == 1) {
  818. /* 1-by-1 pivot block D(k): column k now holds */
  819. /* W(k) = L(k)*D(k) */
  820. /* where L(k) is the k-th column of L */
  821. if (k < *n) {
  822. /* Perform a rank-1 update of A(k+1:n,k+1:n) as */
  823. /* A := A - L(k)*D(k)*L(k)**T = A - W(k)*(1/D(k))*W(k)**T */
  824. r1 = 1. / ap[kc];
  825. i__1 = *n - k;
  826. d__1 = -r1;
  827. dspr_(uplo, &i__1, &d__1, &ap[kc + 1], &c__1, &ap[kc + *n
  828. - k + 1]);
  829. /* Store L(k) in column K */
  830. i__1 = *n - k;
  831. dscal_(&i__1, &r1, &ap[kc + 1], &c__1);
  832. }
  833. } else {
  834. /* 2-by-2 pivot block D(k): columns K and K+1 now hold */
  835. /* ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k) */
  836. /* where L(k) and L(k+1) are the k-th and (k+1)-th columns */
  837. /* of L */
  838. if (k < *n - 1) {
  839. /* Perform a rank-2 update of A(k+2:n,k+2:n) as */
  840. /* A := A - ( L(k) L(k+1) )*D(k)*( L(k) L(k+1) )**T */
  841. /* = A - ( W(k) W(k+1) )*inv(D(k))*( W(k) W(k+1) )**T */
  842. /* where L(k) and L(k+1) are the k-th and (k+1)-th */
  843. /* columns of L */
  844. d21 = ap[k + 1 + (k - 1) * ((*n << 1) - k) / 2];
  845. d11 = ap[k + 1 + k * ((*n << 1) - k - 1) / 2] / d21;
  846. d22 = ap[k + (k - 1) * ((*n << 1) - k) / 2] / d21;
  847. t = 1. / (d11 * d22 - 1.);
  848. d21 = t / d21;
  849. i__1 = *n;
  850. for (j = k + 2; j <= i__1; ++j) {
  851. wk = d21 * (d11 * ap[j + (k - 1) * ((*n << 1) - k) /
  852. 2] - ap[j + k * ((*n << 1) - k - 1) / 2]);
  853. wkp1 = d21 * (d22 * ap[j + k * ((*n << 1) - k - 1) /
  854. 2] - ap[j + (k - 1) * ((*n << 1) - k) / 2]);
  855. i__2 = *n;
  856. for (i__ = j; i__ <= i__2; ++i__) {
  857. ap[i__ + (j - 1) * ((*n << 1) - j) / 2] = ap[i__
  858. + (j - 1) * ((*n << 1) - j) / 2] - ap[i__
  859. + (k - 1) * ((*n << 1) - k) / 2] * wk -
  860. ap[i__ + k * ((*n << 1) - k - 1) / 2] *
  861. wkp1;
  862. /* L90: */
  863. }
  864. ap[j + (k - 1) * ((*n << 1) - k) / 2] = wk;
  865. ap[j + k * ((*n << 1) - k - 1) / 2] = wkp1;
  866. /* L100: */
  867. }
  868. }
  869. }
  870. }
  871. /* Store details of the interchanges in IPIV */
  872. if (kstep == 1) {
  873. ipiv[k] = kp;
  874. } else {
  875. ipiv[k] = -kp;
  876. ipiv[k + 1] = -kp;
  877. }
  878. /* Increase K and return to the start of the main loop */
  879. k += kstep;
  880. kc = knc + *n - k + 2;
  881. goto L60;
  882. }
  883. L110:
  884. return 0;
  885. /* End of DSPTRF */
  886. } /* dsptrf_ */