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.

ssptrf.c 29 kB

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