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.

slasyf_rook.c 42 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <complex.h>
  6. #ifdef complex
  7. #undef complex
  8. #endif
  9. #ifdef I
  10. #undef I
  11. #endif
  12. #if defined(_WIN64)
  13. typedef long long BLASLONG;
  14. typedef unsigned long long BLASULONG;
  15. #else
  16. typedef long BLASLONG;
  17. typedef unsigned long BLASULONG;
  18. #endif
  19. #ifdef LAPACK_ILP64
  20. typedef BLASLONG blasint;
  21. #if defined(_WIN64)
  22. #define blasabs(x) llabs(x)
  23. #else
  24. #define blasabs(x) labs(x)
  25. #endif
  26. #else
  27. typedef int blasint;
  28. #define blasabs(x) abs(x)
  29. #endif
  30. typedef blasint integer;
  31. typedef unsigned int uinteger;
  32. typedef char *address;
  33. typedef short int shortint;
  34. typedef float real;
  35. typedef double doublereal;
  36. typedef struct { real r, i; } complex;
  37. typedef struct { doublereal r, i; } doublecomplex;
  38. #ifdef _MSC_VER
  39. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  40. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  41. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  42. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  43. #else
  44. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  47. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  48. #endif
  49. #define pCf(z) (*_pCf(z))
  50. #define pCd(z) (*_pCd(z))
  51. typedef blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  172. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  217. #define pow_si(B,E) spow_ui(*(B),*(E))
  218. #define pow_ri(B,E) spow_ui(*(B),*(E))
  219. #define pow_di(B,E) dpow_ui(*(B),*(E))
  220. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  221. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  222. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  223. #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++ = ' '; }
  224. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  225. #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]; }
  226. #define sig_die(s, kill) { exit(1); }
  227. #define s_stop(s, n) {exit(0);}
  228. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  229. #define z_abs(z) (cabs(Cd(z)))
  230. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  231. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  232. #define myexit_() break;
  233. #define mycycle() continue;
  234. #define myceiling(w) {ceil(w)}
  235. #define myhuge(w) {HUGE_VAL}
  236. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  237. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  238. /* procedure parameter types for -A and -C++ */
  239. #ifdef __cplusplus
  240. typedef logical (*L_fp)(...);
  241. #else
  242. typedef logical (*L_fp)();
  243. #endif
  244. static float spow_ui(float x, integer n) {
  245. float pow=1.0; unsigned long int u;
  246. if(n != 0) {
  247. if(n < 0) n = -n, x = 1/x;
  248. for(u = n; ; ) {
  249. if(u & 01) pow *= x;
  250. if(u >>= 1) x *= x;
  251. else break;
  252. }
  253. }
  254. return pow;
  255. }
  256. static double dpow_ui(double x, integer n) {
  257. double pow=1.0; unsigned long int u;
  258. if(n != 0) {
  259. if(n < 0) n = -n, x = 1/x;
  260. for(u = n; ; ) {
  261. if(u & 01) pow *= x;
  262. if(u >>= 1) x *= x;
  263. else break;
  264. }
  265. }
  266. return pow;
  267. }
  268. #ifdef _MSC_VER
  269. static _Fcomplex cpow_ui(complex x, integer n) {
  270. complex pow={1.0,0.0}; unsigned long int u;
  271. if(n != 0) {
  272. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  273. for(u = n; ; ) {
  274. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  275. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  276. else break;
  277. }
  278. }
  279. _Fcomplex p={pow.r, pow.i};
  280. return p;
  281. }
  282. #else
  283. static _Complex float cpow_ui(_Complex float x, integer n) {
  284. _Complex float pow=1.0; unsigned long int u;
  285. if(n != 0) {
  286. if(n < 0) n = -n, x = 1/x;
  287. for(u = n; ; ) {
  288. if(u & 01) pow *= x;
  289. if(u >>= 1) x *= x;
  290. else break;
  291. }
  292. }
  293. return pow;
  294. }
  295. #endif
  296. #ifdef _MSC_VER
  297. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  298. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  299. if(n != 0) {
  300. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  301. for(u = n; ; ) {
  302. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  303. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  304. else break;
  305. }
  306. }
  307. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  308. return p;
  309. }
  310. #else
  311. static _Complex double zpow_ui(_Complex double x, integer n) {
  312. _Complex double pow=1.0; unsigned long int u;
  313. if(n != 0) {
  314. if(n < 0) n = -n, x = 1/x;
  315. for(u = n; ; ) {
  316. if(u & 01) pow *= x;
  317. if(u >>= 1) x *= x;
  318. else break;
  319. }
  320. }
  321. return pow;
  322. }
  323. #endif
  324. static integer pow_ii(integer x, integer n) {
  325. integer pow; unsigned long int u;
  326. if (n <= 0) {
  327. if (n == 0 || x == 1) pow = 1;
  328. else if (x != -1) pow = x == 0 ? 1/x : 0;
  329. else n = -n;
  330. }
  331. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  332. u = n;
  333. for(pow = 1; ; ) {
  334. if(u & 01) pow *= x;
  335. if(u >>= 1) x *= x;
  336. else break;
  337. }
  338. }
  339. return pow;
  340. }
  341. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  342. {
  343. double m; integer i, mi;
  344. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  345. if (w[i-1]>m) mi=i ,m=w[i-1];
  346. return mi-s+1;
  347. }
  348. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  349. {
  350. float m; integer i, mi;
  351. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  352. if (w[i-1]>m) mi=i ,m=w[i-1];
  353. return mi-s+1;
  354. }
  355. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  356. integer n = *n_, incx = *incx_, incy = *incy_, i;
  357. #ifdef _MSC_VER
  358. _Fcomplex zdotc = {0.0, 0.0};
  359. if (incx == 1 && incy == 1) {
  360. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  361. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  362. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  363. }
  364. } else {
  365. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  366. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  367. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  368. }
  369. }
  370. pCf(z) = zdotc;
  371. }
  372. #else
  373. _Complex float zdotc = 0.0;
  374. if (incx == 1 && incy == 1) {
  375. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  376. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  377. }
  378. } else {
  379. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  380. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  381. }
  382. }
  383. pCf(z) = zdotc;
  384. }
  385. #endif
  386. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  387. integer n = *n_, incx = *incx_, incy = *incy_, i;
  388. #ifdef _MSC_VER
  389. _Dcomplex zdotc = {0.0, 0.0};
  390. if (incx == 1 && incy == 1) {
  391. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  392. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  393. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  394. }
  395. } else {
  396. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  397. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  398. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  399. }
  400. }
  401. pCd(z) = zdotc;
  402. }
  403. #else
  404. _Complex double zdotc = 0.0;
  405. if (incx == 1 && incy == 1) {
  406. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  407. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  408. }
  409. } else {
  410. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  411. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  412. }
  413. }
  414. pCd(z) = zdotc;
  415. }
  416. #endif
  417. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  418. integer n = *n_, incx = *incx_, incy = *incy_, i;
  419. #ifdef _MSC_VER
  420. _Fcomplex zdotc = {0.0, 0.0};
  421. if (incx == 1 && incy == 1) {
  422. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  423. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  424. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  425. }
  426. } else {
  427. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  428. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  429. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  430. }
  431. }
  432. pCf(z) = zdotc;
  433. }
  434. #else
  435. _Complex float zdotc = 0.0;
  436. if (incx == 1 && incy == 1) {
  437. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  438. zdotc += Cf(&x[i]) * Cf(&y[i]);
  439. }
  440. } else {
  441. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  442. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  443. }
  444. }
  445. pCf(z) = zdotc;
  446. }
  447. #endif
  448. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  449. integer n = *n_, incx = *incx_, incy = *incy_, i;
  450. #ifdef _MSC_VER
  451. _Dcomplex zdotc = {0.0, 0.0};
  452. if (incx == 1 && incy == 1) {
  453. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  454. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  455. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  456. }
  457. } else {
  458. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  459. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  460. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  461. }
  462. }
  463. pCd(z) = zdotc;
  464. }
  465. #else
  466. _Complex double zdotc = 0.0;
  467. if (incx == 1 && incy == 1) {
  468. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  469. zdotc += Cd(&x[i]) * Cd(&y[i]);
  470. }
  471. } else {
  472. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  473. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  474. }
  475. }
  476. pCd(z) = zdotc;
  477. }
  478. #endif
  479. /* -- translated by f2c (version 20000121).
  480. You must link the resulting object file with the libraries:
  481. -lf2c -lm (in that order)
  482. */
  483. /* Table of constant values */
  484. static integer c__1 = 1;
  485. static real c_b9 = -1.f;
  486. static real c_b10 = 1.f;
  487. /* > \brief \b SLASYF_ROOK computes a partial factorization of a real symmetric matrix using the bounded Bunch
  488. -Kaufman ("rook") diagonal pivoting method. */
  489. /* =========== DOCUMENTATION =========== */
  490. /* Online html documentation available at */
  491. /* http://www.netlib.org/lapack/explore-html/ */
  492. /* > \htmlonly */
  493. /* > Download SLASYF_ROOK + dependencies */
  494. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slasyf_
  495. rook.f"> */
  496. /* > [TGZ]</a> */
  497. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slasyf_
  498. rook.f"> */
  499. /* > [ZIP]</a> */
  500. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slasyf_
  501. rook.f"> */
  502. /* > [TXT]</a> */
  503. /* > \endhtmlonly */
  504. /* Definition: */
  505. /* =========== */
  506. /* SUBROUTINE SLASYF_ROOK( UPLO, N, NB, KB, A, LDA, IPIV, W, LDW, INFO ) */
  507. /* CHARACTER UPLO */
  508. /* INTEGER INFO, KB, LDA, LDW, N, NB */
  509. /* INTEGER IPIV( * ) */
  510. /* REAL A( LDA, * ), W( LDW, * ) */
  511. /* > \par Purpose: */
  512. /* ============= */
  513. /* > */
  514. /* > \verbatim */
  515. /* > */
  516. /* > SLASYF_ROOK computes a partial factorization of a real symmetric */
  517. /* > matrix A using the bounded Bunch-Kaufman ("rook") diagonal */
  518. /* > pivoting method. The partial factorization has the form: */
  519. /* > */
  520. /* > A = ( I U12 ) ( A11 0 ) ( I 0 ) if UPLO = 'U', or: */
  521. /* > ( 0 U22 ) ( 0 D ) ( U12**T U22**T ) */
  522. /* > */
  523. /* > A = ( L11 0 ) ( D 0 ) ( L11**T L21**T ) if UPLO = 'L' */
  524. /* > ( L21 I ) ( 0 A22 ) ( 0 I ) */
  525. /* > */
  526. /* > where the order of D is at most NB. The actual order is returned in */
  527. /* > the argument KB, and is either NB or NB-1, or N if N <= NB. */
  528. /* > */
  529. /* > SLASYF_ROOK is an auxiliary routine called by SSYTRF_ROOK. It uses */
  530. /* > blocked code (calling Level 3 BLAS) to update the submatrix */
  531. /* > A11 (if UPLO = 'U') or A22 (if UPLO = 'L'). */
  532. /* > \endverbatim */
  533. /* Arguments: */
  534. /* ========== */
  535. /* > \param[in] UPLO */
  536. /* > \verbatim */
  537. /* > UPLO is CHARACTER*1 */
  538. /* > Specifies whether the upper or lower triangular part of the */
  539. /* > symmetric matrix A is stored: */
  540. /* > = 'U': Upper triangular */
  541. /* > = 'L': Lower triangular */
  542. /* > \endverbatim */
  543. /* > */
  544. /* > \param[in] N */
  545. /* > \verbatim */
  546. /* > N is INTEGER */
  547. /* > The order of the matrix A. N >= 0. */
  548. /* > \endverbatim */
  549. /* > */
  550. /* > \param[in] NB */
  551. /* > \verbatim */
  552. /* > NB is INTEGER */
  553. /* > The maximum number of columns of the matrix A that should be */
  554. /* > factored. NB should be at least 2 to allow for 2-by-2 pivot */
  555. /* > blocks. */
  556. /* > \endverbatim */
  557. /* > */
  558. /* > \param[out] KB */
  559. /* > \verbatim */
  560. /* > KB is INTEGER */
  561. /* > The number of columns of A that were actually factored. */
  562. /* > KB is either NB-1 or NB, or N if N <= NB. */
  563. /* > \endverbatim */
  564. /* > */
  565. /* > \param[in,out] A */
  566. /* > \verbatim */
  567. /* > A is REAL array, dimension (LDA,N) */
  568. /* > On entry, the symmetric matrix A. If UPLO = 'U', the leading */
  569. /* > n-by-n upper triangular part of A contains the upper */
  570. /* > triangular part of the matrix A, and the strictly lower */
  571. /* > triangular part of A is not referenced. If UPLO = 'L', the */
  572. /* > leading n-by-n lower triangular part of A contains the lower */
  573. /* > triangular part of the matrix A, and the strictly upper */
  574. /* > triangular part of A is not referenced. */
  575. /* > On exit, A contains details of the partial factorization. */
  576. /* > \endverbatim */
  577. /* > */
  578. /* > \param[in] LDA */
  579. /* > \verbatim */
  580. /* > LDA is INTEGER */
  581. /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
  582. /* > \endverbatim */
  583. /* > */
  584. /* > \param[out] IPIV */
  585. /* > \verbatim */
  586. /* > IPIV is INTEGER array, dimension (N) */
  587. /* > Details of the interchanges and the block structure of D. */
  588. /* > */
  589. /* > If UPLO = 'U': */
  590. /* > Only the last KB elements of IPIV are set. */
  591. /* > */
  592. /* > If IPIV(k) > 0, then rows and columns k and IPIV(k) were */
  593. /* > interchanged and D(k,k) is a 1-by-1 diagonal block. */
  594. /* > */
  595. /* > If IPIV(k) < 0 and IPIV(k-1) < 0, then rows and */
  596. /* > columns k and -IPIV(k) were interchanged and rows and */
  597. /* > columns k-1 and -IPIV(k-1) were inerchaged, */
  598. /* > D(k-1:k,k-1:k) is a 2-by-2 diagonal block. */
  599. /* > */
  600. /* > If UPLO = 'L': */
  601. /* > Only the first KB elements of IPIV are set. */
  602. /* > */
  603. /* > If IPIV(k) > 0, then rows and columns k and IPIV(k) */
  604. /* > were interchanged and D(k,k) is a 1-by-1 diagonal block. */
  605. /* > */
  606. /* > If IPIV(k) < 0 and IPIV(k+1) < 0, then rows and */
  607. /* > columns k and -IPIV(k) were interchanged and rows and */
  608. /* > columns k+1 and -IPIV(k+1) were inerchaged, */
  609. /* > D(k:k+1,k:k+1) is a 2-by-2 diagonal block. */
  610. /* > \endverbatim */
  611. /* > */
  612. /* > \param[out] W */
  613. /* > \verbatim */
  614. /* > W is REAL array, dimension (LDW,NB) */
  615. /* > \endverbatim */
  616. /* > */
  617. /* > \param[in] LDW */
  618. /* > \verbatim */
  619. /* > LDW is INTEGER */
  620. /* > The leading dimension of the array W. LDW >= f2cmax(1,N). */
  621. /* > \endverbatim */
  622. /* > */
  623. /* > \param[out] INFO */
  624. /* > \verbatim */
  625. /* > INFO is INTEGER */
  626. /* > = 0: successful exit */
  627. /* > > 0: if INFO = k, D(k,k) is exactly zero. The factorization */
  628. /* > has been completed, but the block diagonal matrix D is */
  629. /* > exactly singular. */
  630. /* > \endverbatim */
  631. /* Authors: */
  632. /* ======== */
  633. /* > \author Univ. of Tennessee */
  634. /* > \author Univ. of California Berkeley */
  635. /* > \author Univ. of Colorado Denver */
  636. /* > \author NAG Ltd. */
  637. /* > \date November 2013 */
  638. /* > \ingroup realSYcomputational */
  639. /* > \par Contributors: */
  640. /* ================== */
  641. /* > */
  642. /* > \verbatim */
  643. /* > */
  644. /* > November 2013, Igor Kozachenko, */
  645. /* > Computer Science Division, */
  646. /* > University of California, Berkeley */
  647. /* > */
  648. /* > September 2007, Sven Hammarling, Nicholas J. Higham, Craig Lucas, */
  649. /* > School of Mathematics, */
  650. /* > University of Manchester */
  651. /* > */
  652. /* > \endverbatim */
  653. /* ===================================================================== */
  654. /* Subroutine */ void slasyf_rook_(char *uplo, integer *n, integer *nb,
  655. integer *kb, real *a, integer *lda, integer *ipiv, real *w, integer *
  656. ldw, integer *info)
  657. {
  658. /* System generated locals */
  659. integer a_dim1, a_offset, w_dim1, w_offset, i__1, i__2, i__3, i__4, i__5;
  660. real r__1;
  661. /* Local variables */
  662. logical done;
  663. integer imax, jmax, j, k, p;
  664. real t, alpha;
  665. extern logical lsame_(char *, char *);
  666. extern /* Subroutine */ void sscal_(integer *, real *, real *, integer *),
  667. sgemm_(char *, char *, integer *, integer *, integer *, real *,
  668. real *, integer *, real *, integer *, real *, real *, integer *);
  669. real sfmin;
  670. integer itemp;
  671. extern /* Subroutine */ void sgemv_(char *, integer *, integer *, real *,
  672. real *, integer *, real *, integer *, real *, real *, integer *);
  673. integer kstep;
  674. real stemp;
  675. extern /* Subroutine */ void scopy_(integer *, real *, integer *, real *,
  676. integer *), sswap_(integer *, real *, integer *, real *, integer *
  677. );
  678. real r1, d11, d12, d21, d22;
  679. integer jb, ii, jj, kk, kp;
  680. real absakk;
  681. integer kw;
  682. extern real slamch_(char *);
  683. extern integer isamax_(integer *, real *, integer *);
  684. real colmax;
  685. integer jp1, jp2;
  686. real rowmax;
  687. integer kkw;
  688. /* -- LAPACK computational routine (version 3.5.0) -- */
  689. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  690. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  691. /* November 2013 */
  692. /* ===================================================================== */
  693. /* Parameter adjustments */
  694. a_dim1 = *lda;
  695. a_offset = 1 + a_dim1 * 1;
  696. a -= a_offset;
  697. --ipiv;
  698. w_dim1 = *ldw;
  699. w_offset = 1 + w_dim1 * 1;
  700. w -= w_offset;
  701. /* Function Body */
  702. *info = 0;
  703. /* Initialize ALPHA for use in choosing pivot block size. */
  704. alpha = (sqrt(17.f) + 1.f) / 8.f;
  705. /* Compute machine safe minimum */
  706. sfmin = slamch_("S");
  707. if (lsame_(uplo, "U")) {
  708. /* Factorize the trailing columns of A using the upper triangle */
  709. /* of A and working backwards, and compute the matrix W = U12*D */
  710. /* for use in updating A11 */
  711. /* K is the main loop index, decreasing from N in steps of 1 or 2 */
  712. k = *n;
  713. L10:
  714. /* KW is the column of W which corresponds to column K of A */
  715. kw = *nb + k - *n;
  716. /* Exit from loop */
  717. if (k <= *n - *nb + 1 && *nb < *n || k < 1) {
  718. goto L30;
  719. }
  720. kstep = 1;
  721. p = k;
  722. /* Copy column K of A to column KW of W and update it */
  723. scopy_(&k, &a[k * a_dim1 + 1], &c__1, &w[kw * w_dim1 + 1], &c__1);
  724. if (k < *n) {
  725. i__1 = *n - k;
  726. sgemv_("No transpose", &k, &i__1, &c_b9, &a[(k + 1) * a_dim1 + 1],
  727. lda, &w[k + (kw + 1) * w_dim1], ldw, &c_b10, &w[kw *
  728. w_dim1 + 1], &c__1);
  729. }
  730. /* Determine rows and columns to be interchanged and whether */
  731. /* a 1-by-1 or 2-by-2 pivot block will be used */
  732. absakk = (r__1 = w[k + kw * w_dim1], abs(r__1));
  733. /* IMAX is the row-index of the largest off-diagonal element in */
  734. /* column K, and COLMAX is its absolute value. */
  735. /* Determine both COLMAX and IMAX. */
  736. if (k > 1) {
  737. i__1 = k - 1;
  738. imax = isamax_(&i__1, &w[kw * w_dim1 + 1], &c__1);
  739. colmax = (r__1 = w[imax + kw * w_dim1], abs(r__1));
  740. } else {
  741. colmax = 0.f;
  742. }
  743. if (f2cmax(absakk,colmax) == 0.f) {
  744. /* Column K is zero or underflow: set INFO and continue */
  745. if (*info == 0) {
  746. *info = k;
  747. }
  748. kp = k;
  749. scopy_(&k, &w[kw * w_dim1 + 1], &c__1, &a[k * a_dim1 + 1], &c__1);
  750. } else {
  751. /* ============================================================ */
  752. /* Test for interchange */
  753. /* Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX */
  754. /* (used to handle NaN and Inf) */
  755. if (! (absakk < alpha * colmax)) {
  756. /* no interchange, use 1-by-1 pivot block */
  757. kp = k;
  758. } else {
  759. done = FALSE_;
  760. /* Loop until pivot found */
  761. L12:
  762. /* Begin pivot search loop body */
  763. /* Copy column IMAX to column KW-1 of W and update it */
  764. scopy_(&imax, &a[imax * a_dim1 + 1], &c__1, &w[(kw - 1) *
  765. w_dim1 + 1], &c__1);
  766. i__1 = k - imax;
  767. scopy_(&i__1, &a[imax + (imax + 1) * a_dim1], lda, &w[imax +
  768. 1 + (kw - 1) * w_dim1], &c__1);
  769. if (k < *n) {
  770. i__1 = *n - k;
  771. sgemv_("No transpose", &k, &i__1, &c_b9, &a[(k + 1) *
  772. a_dim1 + 1], lda, &w[imax + (kw + 1) * w_dim1],
  773. ldw, &c_b10, &w[(kw - 1) * w_dim1 + 1], &c__1);
  774. }
  775. /* JMAX is the column-index of the largest off-diagonal */
  776. /* element in row IMAX, and ROWMAX is its absolute value. */
  777. /* Determine both ROWMAX and JMAX. */
  778. if (imax != k) {
  779. i__1 = k - imax;
  780. jmax = imax + isamax_(&i__1, &w[imax + 1 + (kw - 1) *
  781. w_dim1], &c__1);
  782. rowmax = (r__1 = w[jmax + (kw - 1) * w_dim1], abs(r__1));
  783. } else {
  784. rowmax = 0.f;
  785. }
  786. if (imax > 1) {
  787. i__1 = imax - 1;
  788. itemp = isamax_(&i__1, &w[(kw - 1) * w_dim1 + 1], &c__1);
  789. stemp = (r__1 = w[itemp + (kw - 1) * w_dim1], abs(r__1));
  790. if (stemp > rowmax) {
  791. rowmax = stemp;
  792. jmax = itemp;
  793. }
  794. }
  795. /* Equivalent to testing for */
  796. /* ABS( W( IMAX, KW-1 ) ).GE.ALPHA*ROWMAX */
  797. /* (used to handle NaN and Inf) */
  798. if (! ((r__1 = w[imax + (kw - 1) * w_dim1], abs(r__1)) <
  799. alpha * rowmax)) {
  800. /* interchange rows and columns K and IMAX, */
  801. /* use 1-by-1 pivot block */
  802. kp = imax;
  803. /* copy column KW-1 of W to column KW of W */
  804. scopy_(&k, &w[(kw - 1) * w_dim1 + 1], &c__1, &w[kw *
  805. w_dim1 + 1], &c__1);
  806. done = TRUE_;
  807. /* Equivalent to testing for ROWMAX.EQ.COLMAX, */
  808. /* (used to handle NaN and Inf) */
  809. } else if (p == jmax || rowmax <= colmax) {
  810. /* interchange rows and columns K-1 and IMAX, */
  811. /* use 2-by-2 pivot block */
  812. kp = imax;
  813. kstep = 2;
  814. done = TRUE_;
  815. } else {
  816. /* Pivot not found: set params and repeat */
  817. p = imax;
  818. colmax = rowmax;
  819. imax = jmax;
  820. /* Copy updated JMAXth (next IMAXth) column to Kth of W */
  821. scopy_(&k, &w[(kw - 1) * w_dim1 + 1], &c__1, &w[kw *
  822. w_dim1 + 1], &c__1);
  823. }
  824. /* End pivot search loop body */
  825. if (! done) {
  826. goto L12;
  827. }
  828. }
  829. /* ============================================================ */
  830. kk = k - kstep + 1;
  831. /* KKW is the column of W which corresponds to column KK of A */
  832. kkw = *nb + kk - *n;
  833. if (kstep == 2 && p != k) {
  834. /* Copy non-updated column K to column P */
  835. i__1 = k - p;
  836. scopy_(&i__1, &a[p + 1 + k * a_dim1], &c__1, &a[p + (p + 1) *
  837. a_dim1], lda);
  838. scopy_(&p, &a[k * a_dim1 + 1], &c__1, &a[p * a_dim1 + 1], &
  839. c__1);
  840. /* Interchange rows K and P in last N-K+1 columns of A */
  841. /* and last N-K+2 columns of W */
  842. i__1 = *n - k + 1;
  843. sswap_(&i__1, &a[k + k * a_dim1], lda, &a[p + k * a_dim1],
  844. lda);
  845. i__1 = *n - kk + 1;
  846. sswap_(&i__1, &w[k + kkw * w_dim1], ldw, &w[p + kkw * w_dim1],
  847. ldw);
  848. }
  849. /* Updated column KP is already stored in column KKW of W */
  850. if (kp != kk) {
  851. /* Copy non-updated column KK to column KP */
  852. a[kp + k * a_dim1] = a[kk + k * a_dim1];
  853. i__1 = k - 1 - kp;
  854. scopy_(&i__1, &a[kp + 1 + kk * a_dim1], &c__1, &a[kp + (kp +
  855. 1) * a_dim1], lda);
  856. scopy_(&kp, &a[kk * a_dim1 + 1], &c__1, &a[kp * a_dim1 + 1], &
  857. c__1);
  858. /* Interchange rows KK and KP in last N-KK+1 columns */
  859. /* of A and W */
  860. i__1 = *n - kk + 1;
  861. sswap_(&i__1, &a[kk + kk * a_dim1], lda, &a[kp + kk * a_dim1],
  862. lda);
  863. i__1 = *n - kk + 1;
  864. sswap_(&i__1, &w[kk + kkw * w_dim1], ldw, &w[kp + kkw *
  865. w_dim1], ldw);
  866. }
  867. if (kstep == 1) {
  868. /* 1-by-1 pivot block D(k): column KW of W now holds */
  869. /* W(k) = U(k)*D(k) */
  870. /* where U(k) is the k-th column of U */
  871. /* Store U(k) in column k of A */
  872. scopy_(&k, &w[kw * w_dim1 + 1], &c__1, &a[k * a_dim1 + 1], &
  873. c__1);
  874. if (k > 1) {
  875. if ((r__1 = a[k + k * a_dim1], abs(r__1)) >= sfmin) {
  876. r1 = 1.f / a[k + k * a_dim1];
  877. i__1 = k - 1;
  878. sscal_(&i__1, &r1, &a[k * a_dim1 + 1], &c__1);
  879. } else if (a[k + k * a_dim1] != 0.f) {
  880. i__1 = k - 1;
  881. for (ii = 1; ii <= i__1; ++ii) {
  882. a[ii + k * a_dim1] /= a[k + k * a_dim1];
  883. /* L14: */
  884. }
  885. }
  886. }
  887. } else {
  888. /* 2-by-2 pivot block D(k): columns KW and KW-1 of W now */
  889. /* hold */
  890. /* ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k) */
  891. /* where U(k) and U(k-1) are the k-th and (k-1)-th columns */
  892. /* of U */
  893. if (k > 2) {
  894. /* Store U(k) and U(k-1) in columns k and k-1 of A */
  895. d12 = w[k - 1 + kw * w_dim1];
  896. d11 = w[k + kw * w_dim1] / d12;
  897. d22 = w[k - 1 + (kw - 1) * w_dim1] / d12;
  898. t = 1.f / (d11 * d22 - 1.f);
  899. i__1 = k - 2;
  900. for (j = 1; j <= i__1; ++j) {
  901. a[j + (k - 1) * a_dim1] = t * ((d11 * w[j + (kw - 1) *
  902. w_dim1] - w[j + kw * w_dim1]) / d12);
  903. a[j + k * a_dim1] = t * ((d22 * w[j + kw * w_dim1] -
  904. w[j + (kw - 1) * w_dim1]) / d12);
  905. /* L20: */
  906. }
  907. }
  908. /* Copy D(k) to A */
  909. a[k - 1 + (k - 1) * a_dim1] = w[k - 1 + (kw - 1) * w_dim1];
  910. a[k - 1 + k * a_dim1] = w[k - 1 + kw * w_dim1];
  911. a[k + k * a_dim1] = w[k + kw * w_dim1];
  912. }
  913. }
  914. /* Store details of the interchanges in IPIV */
  915. if (kstep == 1) {
  916. ipiv[k] = kp;
  917. } else {
  918. ipiv[k] = -p;
  919. ipiv[k - 1] = -kp;
  920. }
  921. /* Decrease K and return to the start of the main loop */
  922. k -= kstep;
  923. goto L10;
  924. L30:
  925. /* Update the upper triangle of A11 (= A(1:k,1:k)) as */
  926. /* A11 := A11 - U12*D*U12**T = A11 - U12*W**T */
  927. /* computing blocks of NB columns at a time */
  928. i__1 = -(*nb);
  929. for (j = (k - 1) / *nb * *nb + 1; i__1 < 0 ? j >= 1 : j <= 1; j +=
  930. i__1) {
  931. /* Computing MIN */
  932. i__2 = *nb, i__3 = k - j + 1;
  933. jb = f2cmin(i__2,i__3);
  934. /* Update the upper triangle of the diagonal block */
  935. i__2 = j + jb - 1;
  936. for (jj = j; jj <= i__2; ++jj) {
  937. i__3 = jj - j + 1;
  938. i__4 = *n - k;
  939. sgemv_("No transpose", &i__3, &i__4, &c_b9, &a[j + (k + 1) *
  940. a_dim1], lda, &w[jj + (kw + 1) * w_dim1], ldw, &c_b10,
  941. &a[j + jj * a_dim1], &c__1);
  942. /* L40: */
  943. }
  944. /* Update the rectangular superdiagonal block */
  945. if (j >= 2) {
  946. i__2 = j - 1;
  947. i__3 = *n - k;
  948. sgemm_("No transpose", "Transpose", &i__2, &jb, &i__3, &c_b9,
  949. &a[(k + 1) * a_dim1 + 1], lda, &w[j + (kw + 1) *
  950. w_dim1], ldw, &c_b10, &a[j * a_dim1 + 1], lda);
  951. }
  952. /* L50: */
  953. }
  954. /* Put U12 in standard form by partially undoing the interchanges */
  955. /* in columns k+1:n */
  956. j = k + 1;
  957. L60:
  958. kstep = 1;
  959. jp1 = 1;
  960. jj = j;
  961. jp2 = ipiv[j];
  962. if (jp2 < 0) {
  963. jp2 = -jp2;
  964. ++j;
  965. jp1 = -ipiv[j];
  966. kstep = 2;
  967. }
  968. ++j;
  969. if (jp2 != jj && j <= *n) {
  970. i__1 = *n - j + 1;
  971. sswap_(&i__1, &a[jp2 + j * a_dim1], lda, &a[jj + j * a_dim1], lda)
  972. ;
  973. }
  974. jj = j - 1;
  975. if (jp1 != jj && kstep == 2) {
  976. i__1 = *n - j + 1;
  977. sswap_(&i__1, &a[jp1 + j * a_dim1], lda, &a[jj + j * a_dim1], lda)
  978. ;
  979. }
  980. if (j <= *n) {
  981. goto L60;
  982. }
  983. /* Set KB to the number of columns factorized */
  984. *kb = *n - k;
  985. } else {
  986. /* Factorize the leading columns of A using the lower triangle */
  987. /* of A and working forwards, and compute the matrix W = L21*D */
  988. /* for use in updating A22 */
  989. /* K is the main loop index, increasing from 1 in steps of 1 or 2 */
  990. k = 1;
  991. L70:
  992. /* Exit from loop */
  993. if (k >= *nb && *nb < *n || k > *n) {
  994. goto L90;
  995. }
  996. kstep = 1;
  997. p = k;
  998. /* Copy column K of A to column K of W and update it */
  999. i__1 = *n - k + 1;
  1000. scopy_(&i__1, &a[k + k * a_dim1], &c__1, &w[k + k * w_dim1], &c__1);
  1001. if (k > 1) {
  1002. i__1 = *n - k + 1;
  1003. i__2 = k - 1;
  1004. sgemv_("No transpose", &i__1, &i__2, &c_b9, &a[k + a_dim1], lda, &
  1005. w[k + w_dim1], ldw, &c_b10, &w[k + k * w_dim1], &c__1);
  1006. }
  1007. /* Determine rows and columns to be interchanged and whether */
  1008. /* a 1-by-1 or 2-by-2 pivot block will be used */
  1009. absakk = (r__1 = w[k + k * w_dim1], abs(r__1));
  1010. /* IMAX is the row-index of the largest off-diagonal element in */
  1011. /* column K, and COLMAX is its absolute value. */
  1012. /* Determine both COLMAX and IMAX. */
  1013. if (k < *n) {
  1014. i__1 = *n - k;
  1015. imax = k + isamax_(&i__1, &w[k + 1 + k * w_dim1], &c__1);
  1016. colmax = (r__1 = w[imax + k * w_dim1], abs(r__1));
  1017. } else {
  1018. colmax = 0.f;
  1019. }
  1020. if (f2cmax(absakk,colmax) == 0.f) {
  1021. /* Column K is zero or underflow: set INFO and continue */
  1022. if (*info == 0) {
  1023. *info = k;
  1024. }
  1025. kp = k;
  1026. i__1 = *n - k + 1;
  1027. scopy_(&i__1, &w[k + k * w_dim1], &c__1, &a[k + k * a_dim1], &
  1028. c__1);
  1029. } else {
  1030. /* ============================================================ */
  1031. /* Test for interchange */
  1032. /* Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX */
  1033. /* (used to handle NaN and Inf) */
  1034. if (! (absakk < alpha * colmax)) {
  1035. /* no interchange, use 1-by-1 pivot block */
  1036. kp = k;
  1037. } else {
  1038. done = FALSE_;
  1039. /* Loop until pivot found */
  1040. L72:
  1041. /* Begin pivot search loop body */
  1042. /* Copy column IMAX to column K+1 of W and update it */
  1043. i__1 = imax - k;
  1044. scopy_(&i__1, &a[imax + k * a_dim1], lda, &w[k + (k + 1) *
  1045. w_dim1], &c__1);
  1046. i__1 = *n - imax + 1;
  1047. scopy_(&i__1, &a[imax + imax * a_dim1], &c__1, &w[imax + (k +
  1048. 1) * w_dim1], &c__1);
  1049. if (k > 1) {
  1050. i__1 = *n - k + 1;
  1051. i__2 = k - 1;
  1052. sgemv_("No transpose", &i__1, &i__2, &c_b9, &a[k + a_dim1]
  1053. , lda, &w[imax + w_dim1], ldw, &c_b10, &w[k + (k
  1054. + 1) * w_dim1], &c__1);
  1055. }
  1056. /* JMAX is the column-index of the largest off-diagonal */
  1057. /* element in row IMAX, and ROWMAX is its absolute value. */
  1058. /* Determine both ROWMAX and JMAX. */
  1059. if (imax != k) {
  1060. i__1 = imax - k;
  1061. jmax = k - 1 + isamax_(&i__1, &w[k + (k + 1) * w_dim1], &
  1062. c__1);
  1063. rowmax = (r__1 = w[jmax + (k + 1) * w_dim1], abs(r__1));
  1064. } else {
  1065. rowmax = 0.f;
  1066. }
  1067. if (imax < *n) {
  1068. i__1 = *n - imax;
  1069. itemp = imax + isamax_(&i__1, &w[imax + 1 + (k + 1) *
  1070. w_dim1], &c__1);
  1071. stemp = (r__1 = w[itemp + (k + 1) * w_dim1], abs(r__1));
  1072. if (stemp > rowmax) {
  1073. rowmax = stemp;
  1074. jmax = itemp;
  1075. }
  1076. }
  1077. /* Equivalent to testing for */
  1078. /* ABS( W( IMAX, K+1 ) ).GE.ALPHA*ROWMAX */
  1079. /* (used to handle NaN and Inf) */
  1080. if (! ((r__1 = w[imax + (k + 1) * w_dim1], abs(r__1)) < alpha
  1081. * rowmax)) {
  1082. /* interchange rows and columns K and IMAX, */
  1083. /* use 1-by-1 pivot block */
  1084. kp = imax;
  1085. /* copy column K+1 of W to column K of W */
  1086. i__1 = *n - k + 1;
  1087. scopy_(&i__1, &w[k + (k + 1) * w_dim1], &c__1, &w[k + k *
  1088. w_dim1], &c__1);
  1089. done = TRUE_;
  1090. /* Equivalent to testing for ROWMAX.EQ.COLMAX, */
  1091. /* (used to handle NaN and Inf) */
  1092. } else if (p == jmax || rowmax <= colmax) {
  1093. /* interchange rows and columns K+1 and IMAX, */
  1094. /* use 2-by-2 pivot block */
  1095. kp = imax;
  1096. kstep = 2;
  1097. done = TRUE_;
  1098. } else {
  1099. /* Pivot not found: set params and repeat */
  1100. p = imax;
  1101. colmax = rowmax;
  1102. imax = jmax;
  1103. /* Copy updated JMAXth (next IMAXth) column to Kth of W */
  1104. i__1 = *n - k + 1;
  1105. scopy_(&i__1, &w[k + (k + 1) * w_dim1], &c__1, &w[k + k *
  1106. w_dim1], &c__1);
  1107. }
  1108. /* End pivot search loop body */
  1109. if (! done) {
  1110. goto L72;
  1111. }
  1112. }
  1113. /* ============================================================ */
  1114. kk = k + kstep - 1;
  1115. if (kstep == 2 && p != k) {
  1116. /* Copy non-updated column K to column P */
  1117. i__1 = p - k;
  1118. scopy_(&i__1, &a[k + k * a_dim1], &c__1, &a[p + k * a_dim1],
  1119. lda);
  1120. i__1 = *n - p + 1;
  1121. scopy_(&i__1, &a[p + k * a_dim1], &c__1, &a[p + p * a_dim1], &
  1122. c__1);
  1123. /* Interchange rows K and P in first K columns of A */
  1124. /* and first K+1 columns of W */
  1125. sswap_(&k, &a[k + a_dim1], lda, &a[p + a_dim1], lda);
  1126. sswap_(&kk, &w[k + w_dim1], ldw, &w[p + w_dim1], ldw);
  1127. }
  1128. /* Updated column KP is already stored in column KK of W */
  1129. if (kp != kk) {
  1130. /* Copy non-updated column KK to column KP */
  1131. a[kp + k * a_dim1] = a[kk + k * a_dim1];
  1132. i__1 = kp - k - 1;
  1133. scopy_(&i__1, &a[k + 1 + kk * a_dim1], &c__1, &a[kp + (k + 1)
  1134. * a_dim1], lda);
  1135. i__1 = *n - kp + 1;
  1136. scopy_(&i__1, &a[kp + kk * a_dim1], &c__1, &a[kp + kp *
  1137. a_dim1], &c__1);
  1138. /* Interchange rows KK and KP in first KK columns of A and W */
  1139. sswap_(&kk, &a[kk + a_dim1], lda, &a[kp + a_dim1], lda);
  1140. sswap_(&kk, &w[kk + w_dim1], ldw, &w[kp + w_dim1], ldw);
  1141. }
  1142. if (kstep == 1) {
  1143. /* 1-by-1 pivot block D(k): column k of W now holds */
  1144. /* W(k) = L(k)*D(k) */
  1145. /* where L(k) is the k-th column of L */
  1146. /* Store L(k) in column k of A */
  1147. i__1 = *n - k + 1;
  1148. scopy_(&i__1, &w[k + k * w_dim1], &c__1, &a[k + k * a_dim1], &
  1149. c__1);
  1150. if (k < *n) {
  1151. if ((r__1 = a[k + k * a_dim1], abs(r__1)) >= sfmin) {
  1152. r1 = 1.f / a[k + k * a_dim1];
  1153. i__1 = *n - k;
  1154. sscal_(&i__1, &r1, &a[k + 1 + k * a_dim1], &c__1);
  1155. } else if (a[k + k * a_dim1] != 0.f) {
  1156. i__1 = *n;
  1157. for (ii = k + 1; ii <= i__1; ++ii) {
  1158. a[ii + k * a_dim1] /= a[k + k * a_dim1];
  1159. /* L74: */
  1160. }
  1161. }
  1162. }
  1163. } else {
  1164. /* 2-by-2 pivot block D(k): columns k and k+1 of W now hold */
  1165. /* ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k) */
  1166. /* where L(k) and L(k+1) are the k-th and (k+1)-th columns */
  1167. /* of L */
  1168. if (k < *n - 1) {
  1169. /* Store L(k) and L(k+1) in columns k and k+1 of A */
  1170. d21 = w[k + 1 + k * w_dim1];
  1171. d11 = w[k + 1 + (k + 1) * w_dim1] / d21;
  1172. d22 = w[k + k * w_dim1] / d21;
  1173. t = 1.f / (d11 * d22 - 1.f);
  1174. i__1 = *n;
  1175. for (j = k + 2; j <= i__1; ++j) {
  1176. a[j + k * a_dim1] = t * ((d11 * w[j + k * w_dim1] - w[
  1177. j + (k + 1) * w_dim1]) / d21);
  1178. a[j + (k + 1) * a_dim1] = t * ((d22 * w[j + (k + 1) *
  1179. w_dim1] - w[j + k * w_dim1]) / d21);
  1180. /* L80: */
  1181. }
  1182. }
  1183. /* Copy D(k) to A */
  1184. a[k + k * a_dim1] = w[k + k * w_dim1];
  1185. a[k + 1 + k * a_dim1] = w[k + 1 + k * w_dim1];
  1186. a[k + 1 + (k + 1) * a_dim1] = w[k + 1 + (k + 1) * w_dim1];
  1187. }
  1188. }
  1189. /* Store details of the interchanges in IPIV */
  1190. if (kstep == 1) {
  1191. ipiv[k] = kp;
  1192. } else {
  1193. ipiv[k] = -p;
  1194. ipiv[k + 1] = -kp;
  1195. }
  1196. /* Increase K and return to the start of the main loop */
  1197. k += kstep;
  1198. goto L70;
  1199. L90:
  1200. /* Update the lower triangle of A22 (= A(k:n,k:n)) as */
  1201. /* A22 := A22 - L21*D*L21**T = A22 - L21*W**T */
  1202. /* computing blocks of NB columns at a time */
  1203. i__1 = *n;
  1204. i__2 = *nb;
  1205. for (j = k; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  1206. /* Computing MIN */
  1207. i__3 = *nb, i__4 = *n - j + 1;
  1208. jb = f2cmin(i__3,i__4);
  1209. /* Update the lower triangle of the diagonal block */
  1210. i__3 = j + jb - 1;
  1211. for (jj = j; jj <= i__3; ++jj) {
  1212. i__4 = j + jb - jj;
  1213. i__5 = k - 1;
  1214. sgemv_("No transpose", &i__4, &i__5, &c_b9, &a[jj + a_dim1],
  1215. lda, &w[jj + w_dim1], ldw, &c_b10, &a[jj + jj *
  1216. a_dim1], &c__1);
  1217. /* L100: */
  1218. }
  1219. /* Update the rectangular subdiagonal block */
  1220. if (j + jb <= *n) {
  1221. i__3 = *n - j - jb + 1;
  1222. i__4 = k - 1;
  1223. sgemm_("No transpose", "Transpose", &i__3, &jb, &i__4, &c_b9,
  1224. &a[j + jb + a_dim1], lda, &w[j + w_dim1], ldw, &c_b10,
  1225. &a[j + jb + j * a_dim1], lda);
  1226. }
  1227. /* L110: */
  1228. }
  1229. /* Put L21 in standard form by partially undoing the interchanges */
  1230. /* in columns 1:k-1 */
  1231. j = k - 1;
  1232. L120:
  1233. kstep = 1;
  1234. jp1 = 1;
  1235. jj = j;
  1236. jp2 = ipiv[j];
  1237. if (jp2 < 0) {
  1238. jp2 = -jp2;
  1239. --j;
  1240. jp1 = -ipiv[j];
  1241. kstep = 2;
  1242. }
  1243. --j;
  1244. if (jp2 != jj && j >= 1) {
  1245. sswap_(&j, &a[jp2 + a_dim1], lda, &a[jj + a_dim1], lda);
  1246. }
  1247. jj = j + 1;
  1248. if (jp1 != jj && kstep == 2) {
  1249. sswap_(&j, &a[jp1 + a_dim1], lda, &a[jj + a_dim1], lda);
  1250. }
  1251. if (j >= 1) {
  1252. goto L120;
  1253. }
  1254. /* Set KB to the number of columns factorized */
  1255. *kb = k - 1;
  1256. }
  1257. return;
  1258. /* End of SLASYF_ROOK */
  1259. } /* slasyf_rook__ */