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.

strsyl3.c 62 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066
  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]/Cd(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. #define myexp_(w) my_expfunc(w)
  239. static int my_expfunc(float *x) {int e; (void)frexpf(*x,&e); return e;}
  240. /* procedure parameter types for -A and -C++ */
  241. #ifdef __cplusplus
  242. typedef logical (*L_fp)(...);
  243. #else
  244. typedef logical (*L_fp)();
  245. #endif
  246. static float spow_ui(float x, integer n) {
  247. float pow=1.0; unsigned long int u;
  248. if(n != 0) {
  249. if(n < 0) n = -n, x = 1/x;
  250. for(u = n; ; ) {
  251. if(u & 01) pow *= x;
  252. if(u >>= 1) x *= x;
  253. else break;
  254. }
  255. }
  256. return pow;
  257. }
  258. static double dpow_ui(double x, integer n) {
  259. double pow=1.0; unsigned long int u;
  260. if(n != 0) {
  261. if(n < 0) n = -n, x = 1/x;
  262. for(u = n; ; ) {
  263. if(u & 01) pow *= x;
  264. if(u >>= 1) x *= x;
  265. else break;
  266. }
  267. }
  268. return pow;
  269. }
  270. #ifdef _MSC_VER
  271. static _Fcomplex cpow_ui(complex x, integer n) {
  272. complex pow={1.0,0.0}; unsigned long int u;
  273. if(n != 0) {
  274. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  275. for(u = n; ; ) {
  276. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  277. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  278. else break;
  279. }
  280. }
  281. _Fcomplex p={pow.r, pow.i};
  282. return p;
  283. }
  284. #else
  285. static _Complex float cpow_ui(_Complex float x, integer n) {
  286. _Complex float pow=1.0; unsigned long int u;
  287. if(n != 0) {
  288. if(n < 0) n = -n, x = 1/x;
  289. for(u = n; ; ) {
  290. if(u & 01) pow *= x;
  291. if(u >>= 1) x *= x;
  292. else break;
  293. }
  294. }
  295. return pow;
  296. }
  297. #endif
  298. #ifdef _MSC_VER
  299. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  300. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  301. if(n != 0) {
  302. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  303. for(u = n; ; ) {
  304. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  305. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  306. else break;
  307. }
  308. }
  309. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  310. return p;
  311. }
  312. #else
  313. static _Complex double zpow_ui(_Complex double x, integer n) {
  314. _Complex double pow=1.0; unsigned long int u;
  315. if(n != 0) {
  316. if(n < 0) n = -n, x = 1/x;
  317. for(u = n; ; ) {
  318. if(u & 01) pow *= x;
  319. if(u >>= 1) x *= x;
  320. else break;
  321. }
  322. }
  323. return pow;
  324. }
  325. #endif
  326. static integer pow_ii(integer x, integer n) {
  327. integer pow; unsigned long int u;
  328. if (n <= 0) {
  329. if (n == 0 || x == 1) pow = 1;
  330. else if (x != -1) pow = x == 0 ? 1/x : 0;
  331. else n = -n;
  332. }
  333. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  334. u = n;
  335. for(pow = 1; ; ) {
  336. if(u & 01) pow *= x;
  337. if(u >>= 1) x *= x;
  338. else break;
  339. }
  340. }
  341. return pow;
  342. }
  343. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  344. {
  345. double m; integer i, mi;
  346. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  347. if (w[i-1]>m) mi=i ,m=w[i-1];
  348. return mi-s+1;
  349. }
  350. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  351. {
  352. float m; integer i, mi;
  353. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  354. if (w[i-1]>m) mi=i ,m=w[i-1];
  355. return mi-s+1;
  356. }
  357. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  358. integer n = *n_, incx = *incx_, incy = *incy_, i;
  359. #ifdef _MSC_VER
  360. _Fcomplex zdotc = {0.0, 0.0};
  361. if (incx == 1 && incy == 1) {
  362. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  363. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  364. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  365. }
  366. } else {
  367. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  368. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  369. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  370. }
  371. }
  372. pCf(z) = zdotc;
  373. }
  374. #else
  375. _Complex float zdotc = 0.0;
  376. if (incx == 1 && incy == 1) {
  377. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  378. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  379. }
  380. } else {
  381. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  382. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  383. }
  384. }
  385. pCf(z) = zdotc;
  386. }
  387. #endif
  388. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  389. integer n = *n_, incx = *incx_, incy = *incy_, i;
  390. #ifdef _MSC_VER
  391. _Dcomplex zdotc = {0.0, 0.0};
  392. if (incx == 1 && incy == 1) {
  393. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  394. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  395. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  396. }
  397. } else {
  398. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  399. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  400. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  401. }
  402. }
  403. pCd(z) = zdotc;
  404. }
  405. #else
  406. _Complex double zdotc = 0.0;
  407. if (incx == 1 && incy == 1) {
  408. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  409. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  410. }
  411. } else {
  412. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  413. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  414. }
  415. }
  416. pCd(z) = zdotc;
  417. }
  418. #endif
  419. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  420. integer n = *n_, incx = *incx_, incy = *incy_, i;
  421. #ifdef _MSC_VER
  422. _Fcomplex zdotc = {0.0, 0.0};
  423. if (incx == 1 && incy == 1) {
  424. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  425. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  426. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  427. }
  428. } else {
  429. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  430. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  431. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  432. }
  433. }
  434. pCf(z) = zdotc;
  435. }
  436. #else
  437. _Complex float zdotc = 0.0;
  438. if (incx == 1 && incy == 1) {
  439. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  440. zdotc += Cf(&x[i]) * Cf(&y[i]);
  441. }
  442. } else {
  443. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  444. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  445. }
  446. }
  447. pCf(z) = zdotc;
  448. }
  449. #endif
  450. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  451. integer n = *n_, incx = *incx_, incy = *incy_, i;
  452. #ifdef _MSC_VER
  453. _Dcomplex zdotc = {0.0, 0.0};
  454. if (incx == 1 && incy == 1) {
  455. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  456. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  457. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  458. }
  459. } else {
  460. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  461. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  462. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  463. }
  464. }
  465. pCd(z) = zdotc;
  466. }
  467. #else
  468. _Complex double zdotc = 0.0;
  469. if (incx == 1 && incy == 1) {
  470. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  471. zdotc += Cd(&x[i]) * Cd(&y[i]);
  472. }
  473. } else {
  474. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  475. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  476. }
  477. }
  478. pCd(z) = zdotc;
  479. }
  480. #endif
  481. /* -- translated by f2c (version 20000121).
  482. You must link the resulting object file with the libraries:
  483. -lf2c -lm (in that order)
  484. */
  485. /* Table of constant values */
  486. static integer c__1 = 1;
  487. static integer c_n1 = -1;
  488. static real c_b19 = 2.f;
  489. static real c_b31 = -1.f;
  490. static real c_b32 = 1.f;
  491. /* > \brief \b STRSYL3 */
  492. /* Definition: */
  493. /* =========== */
  494. /* > \par Purpose */
  495. /* ============= */
  496. /* > */
  497. /* > \verbatim */
  498. /* > */
  499. /* > STRSYL3 solves the real Sylvester matrix equation: */
  500. /* > */
  501. /* > op(A)*X + X*op(B) = scale*C or */
  502. /* > op(A)*X - X*op(B) = scale*C, */
  503. /* > */
  504. /* > where op(A) = A or A**T, and A and B are both upper quasi- */
  505. /* > triangular. A is M-by-M and B is N-by-N; the right hand side C and */
  506. /* > the solution X are M-by-N; and scale is an output scale factor, set */
  507. /* > <= 1 to avoid overflow in X. */
  508. /* > */
  509. /* > A and B must be in Schur canonical form (as returned by SHSEQR), that */
  510. /* > is, block upper triangular with 1-by-1 and 2-by-2 diagonal blocks; */
  511. /* > each 2-by-2 diagonal block has its diagonal elements equal and its */
  512. /* > off-diagonal elements of opposite sign. */
  513. /* > */
  514. /* > This is the block version of the algorithm. */
  515. /* > \endverbatim */
  516. /* Arguments */
  517. /* ========= */
  518. /* > \param[in] TRANA */
  519. /* > \verbatim */
  520. /* > TRANA is CHARACTER*1 */
  521. /* > Specifies the option op(A): */
  522. /* > = 'N': op(A) = A (No transpose) */
  523. /* > = 'T': op(A) = A**T (Transpose) */
  524. /* > = 'C': op(A) = A**H (Conjugate transpose = Transpose) */
  525. /* > \endverbatim */
  526. /* > */
  527. /* > \param[in] TRANB */
  528. /* > \verbatim */
  529. /* > TRANB is CHARACTER*1 */
  530. /* > Specifies the option op(B): */
  531. /* > = 'N': op(B) = B (No transpose) */
  532. /* > = 'T': op(B) = B**T (Transpose) */
  533. /* > = 'C': op(B) = B**H (Conjugate transpose = Transpose) */
  534. /* > \endverbatim */
  535. /* > */
  536. /* > \param[in] ISGN */
  537. /* > \verbatim */
  538. /* > ISGN is INTEGER */
  539. /* > Specifies the sign in the equation: */
  540. /* > = +1: solve op(A)*X + X*op(B) = scale*C */
  541. /* > = -1: solve op(A)*X - X*op(B) = scale*C */
  542. /* > \endverbatim */
  543. /* > */
  544. /* > \param[in] M */
  545. /* > \verbatim */
  546. /* > M is INTEGER */
  547. /* > The order of the matrix A, and the number of rows in the */
  548. /* > matrices X and C. M >= 0. */
  549. /* > \endverbatim */
  550. /* > */
  551. /* > \param[in] N */
  552. /* > \verbatim */
  553. /* > N is INTEGER */
  554. /* > The order of the matrix B, and the number of columns in the */
  555. /* > matrices X and C. N >= 0. */
  556. /* > \endverbatim */
  557. /* > */
  558. /* > \param[in] A */
  559. /* > \verbatim */
  560. /* > A is REAL array, dimension (LDA,M) */
  561. /* > The upper quasi-triangular matrix A, in Schur canonical form. */
  562. /* > \endverbatim */
  563. /* > */
  564. /* > \param[in] LDA */
  565. /* > \verbatim */
  566. /* > LDA is INTEGER */
  567. /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
  568. /* > \endverbatim */
  569. /* > */
  570. /* > \param[in] B */
  571. /* > \verbatim */
  572. /* > B is REAL array, dimension (LDB,N) */
  573. /* > The upper quasi-triangular matrix B, in Schur canonical form. */
  574. /* > \endverbatim */
  575. /* > */
  576. /* > \param[in] LDB */
  577. /* > \verbatim */
  578. /* > LDB is INTEGER */
  579. /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */
  580. /* > \endverbatim */
  581. /* > */
  582. /* > \param[in,out] C */
  583. /* > \verbatim */
  584. /* > C is REAL array, dimension (LDC,N) */
  585. /* > On entry, the M-by-N right hand side matrix C. */
  586. /* > On exit, C is overwritten by the solution matrix X. */
  587. /* > \endverbatim */
  588. /* > */
  589. /* > \param[in] LDC */
  590. /* > \verbatim */
  591. /* > LDC is INTEGER */
  592. /* > The leading dimension of the array C. LDC >= f2cmax(1,M) */
  593. /* > \endverbatim */
  594. /* > */
  595. /* > \param[out] SCALE */
  596. /* > \verbatim */
  597. /* > SCALE is REAL */
  598. /* > The scale factor, scale, set <= 1 to avoid overflow in X. */
  599. /* > \endverbatim */
  600. /* > */
  601. /* > \param[out] IWORK */
  602. /* > \verbatim */
  603. /* > IWORK is INTEGER array, dimension (MAX(1,LIWORK)) */
  604. /* > On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK. */
  605. /* > \endverbatim */
  606. /* > */
  607. /* > \param[in] LIWORK */
  608. /* > \verbatim */
  609. /* > IWORK is INTEGER */
  610. /* > The dimension of the array IWORK. LIWORK >= ((M + NB - 1) / NB + 1) */
  611. /* > + ((N + NB - 1) / NB + 1), where NB is the optimal block size. */
  612. /* > */
  613. /* > If LIWORK = -1, then a workspace query is assumed; the routine */
  614. /* > only calculates the optimal dimension of the IWORK array, */
  615. /* > returns this value as the first entry of the IWORK array, and */
  616. /* > no error message related to LIWORK is issued by XERBLA. */
  617. /* > \endverbatim */
  618. /* > */
  619. /* > \param[out] SWORK */
  620. /* > \verbatim */
  621. /* > SWORK is REAL array, dimension (MAX(2, ROWS), */
  622. /* > MAX(1,COLS)). */
  623. /* > On exit, if INFO = 0, SWORK(1) returns the optimal value ROWS */
  624. /* > and SWORK(2) returns the optimal COLS. */
  625. /* > \endverbatim */
  626. /* > */
  627. /* > \param[in] LDSWORK */
  628. /* > \verbatim */
  629. /* > LDSWORK is INTEGER */
  630. /* > LDSWORK >= MAX(2,ROWS), where ROWS = ((M + NB - 1) / NB + 1) */
  631. /* > and NB is the optimal block size. */
  632. /* > */
  633. /* > If LDSWORK = -1, then a workspace query is assumed; the routine */
  634. /* > only calculates the optimal dimensions of the SWORK matrix, */
  635. /* > returns these values as the first and second entry of the SWORK */
  636. /* > matrix, and no error message related LWORK is issued by XERBLA. */
  637. /* > \endverbatim */
  638. /* > */
  639. /* > \param[out] INFO */
  640. /* > \verbatim */
  641. /* > INFO is INTEGER */
  642. /* > = 0: successful exit */
  643. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  644. /* > = 1: A and B have common or very close eigenvalues; perturbed */
  645. /* > values were used to solve the equation (but the matrices */
  646. /* > A and B are unchanged). */
  647. /* > \endverbatim */
  648. /* ===================================================================== */
  649. /* References: */
  650. /* E. S. Quintana-Orti and R. A. Van De Geijn (2003). Formal derivation of */
  651. /* algorithms: The triangular Sylvester equation, ACM Transactions */
  652. /* on Mathematical Software (TOMS), volume 29, pages 218--243. */
  653. /* A. Schwarz and C. C. Kjelgaard Mikkelsen (2020). Robust Task-Parallel */
  654. /* Solution of the Triangular Sylvester Equation. Lecture Notes in */
  655. /* Computer Science, vol 12043, pages 82--92, Springer. */
  656. /* Contributor: */
  657. /* Angelika Schwarz, Umea University, Sweden. */
  658. /* ===================================================================== */
  659. /* Subroutine */ void strsyl3_(char *trana, char *tranb, integer *isgn,
  660. integer *m, integer *n, real *a, integer *lda, real *b, integer *ldb,
  661. real *c__, integer *ldc, real *scale, integer *iwork, integer *liwork,
  662. real *swork, integer *ldswork, integer *info)
  663. {
  664. /* System generated locals */
  665. integer a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset, swork_dim1,
  666. swork_offset, i__1, i__2, i__3, i__4, i__5, i__6;
  667. real r__1, r__2, r__3;
  668. /* Local variables */
  669. real scal, anrm, bnrm, cnrm;
  670. integer awrk, bwrk;
  671. logical skip;
  672. real *wnrm, xnrm;
  673. integer i__, j, k, l;
  674. extern logical lsame_(char *, char *);
  675. integer iinfo;
  676. extern /* Subroutine */ void sscal_(integer *, real *, real *, integer *),
  677. sgemm_(char *, char *, integer *, integer *, integer *, real *,
  678. real *, integer *, real *, integer *, real *, real *, integer *);
  679. integer i1, i2, j1, j2, k1, k2, l1;
  680. // extern integer myexp_(real *);
  681. integer l2, nb, pc, jj, ll;
  682. real scaloc;
  683. extern real slamch_(char *), slange_(char *, integer *, integer *,
  684. real *, integer *, real *);
  685. real scamin;
  686. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  687. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  688. integer *, integer *, ftnlen, ftnlen);
  689. real bignum;
  690. extern /* Subroutine */ void slascl_(char *, integer *, integer *, real *,
  691. real *, integer *, integer *, real *, integer *, integer *);
  692. extern real slarmm_(real *, real *, real *);
  693. logical notrna, notrnb;
  694. real smlnum;
  695. logical lquery;
  696. extern /* Subroutine */ void strsyl_(char *, char *, integer *, integer *,
  697. integer *, real *, integer *, real *, integer *, real *, integer *
  698. , real *, integer *);
  699. integer nba, nbb;
  700. real buf, sgn;
  701. /* Decode and Test input parameters */
  702. /* Parameter adjustments */
  703. a_dim1 = *lda;
  704. a_offset = 1 + a_dim1 * 1;
  705. a -= a_offset;
  706. b_dim1 = *ldb;
  707. b_offset = 1 + b_dim1 * 1;
  708. b -= b_offset;
  709. c_dim1 = *ldc;
  710. c_offset = 1 + c_dim1 * 1;
  711. c__ -= c_offset;
  712. --iwork;
  713. swork_dim1 = *ldswork;
  714. swork_offset = 1 + swork_dim1 * 1;
  715. swork -= swork_offset;
  716. /* Function Body */
  717. notrna = lsame_(trana, "N");
  718. notrnb = lsame_(tranb, "N");
  719. /* Use the same block size for all matrices. */
  720. /* Computing MAX */
  721. i__1 = 8, i__2 = ilaenv_(&c__1, "STRSYL", "", m, n, &c_n1, &c_n1, (ftnlen)
  722. 6, (ftnlen)0);
  723. nb = f2cmax(i__1,i__2);
  724. /* Compute number of blocks in A and B */
  725. /* Computing MAX */
  726. i__1 = 1, i__2 = (*m + nb - 1) / nb;
  727. nba = f2cmax(i__1,i__2);
  728. /* Computing MAX */
  729. i__1 = 1, i__2 = (*n + nb - 1) / nb;
  730. nbb = f2cmax(i__1,i__2);
  731. /* Compute workspace */
  732. *info = 0;
  733. lquery = *liwork == -1 || *ldswork == -1;
  734. iwork[1] = nba + nbb + 2;
  735. if (lquery) {
  736. *ldswork = 2;
  737. swork[swork_dim1 + 1] = (real) f2cmax(nba,nbb);
  738. swork[swork_dim1 + 2] = (real) ((nbb << 1) + nba);
  739. }
  740. /* Test the input arguments */
  741. if (! notrna && ! lsame_(trana, "T") && ! lsame_(
  742. trana, "C")) {
  743. *info = -1;
  744. } else if (! notrnb && ! lsame_(tranb, "T") && !
  745. lsame_(tranb, "C")) {
  746. *info = -2;
  747. } else if (*isgn != 1 && *isgn != -1) {
  748. *info = -3;
  749. } else if (*m < 0) {
  750. *info = -4;
  751. } else if (*n < 0) {
  752. *info = -5;
  753. } else if (*lda < f2cmax(1,*m)) {
  754. *info = -7;
  755. } else if (*ldb < f2cmax(1,*n)) {
  756. *info = -9;
  757. } else if (*ldc < f2cmax(1,*m)) {
  758. *info = -11;
  759. } else if (! lquery && *liwork < iwork[1]) {
  760. *info = -14;
  761. } else if (! lquery && *ldswork < f2cmax(nba,nbb)) {
  762. *info = -16;
  763. }
  764. if (*info != 0) {
  765. i__1 = -(*info);
  766. xerbla_("STRSYL3", &i__1, 7);
  767. return;
  768. } else if (lquery) {
  769. return;
  770. }
  771. /* Quick return if possible */
  772. *scale = 1.f;
  773. if (*m == 0 || *n == 0) {
  774. return;
  775. }
  776. /* Use unblocked code for small problems or if insufficient */
  777. /* workspaces are provided */
  778. if (f2cmin(nba,nbb) == 1 || *ldswork < f2cmax(nba,nbb) || *liwork < iwork[1]) {
  779. strsyl_(trana, tranb, isgn, m, n, &a[a_offset], lda, &b[b_offset],
  780. ldb, &c__[c_offset], ldc, scale, info);
  781. return;
  782. }
  783. /* REAL WNRM( MAX( M, N ) ) */
  784. wnrm=(real*)malloc (f2cmax(*m,*n)*sizeof(real));
  785. /* Set constants to control overflow */
  786. smlnum = slamch_("S");
  787. bignum = 1.f / smlnum;
  788. /* Partition A such that 2-by-2 blocks on the diagonal are not split */
  789. skip = FALSE_;
  790. i__1 = nba;
  791. for (i__ = 1; i__ <= i__1; ++i__) {
  792. iwork[i__] = (i__ - 1) * nb + 1;
  793. }
  794. iwork[nba + 1] = *m + 1;
  795. i__1 = nba;
  796. for (k = 1; k <= i__1; ++k) {
  797. l1 = iwork[k];
  798. l2 = iwork[k + 1] - 1;
  799. i__2 = l2;
  800. for (l = l1; l <= i__2; ++l) {
  801. if (skip) {
  802. skip = FALSE_;
  803. mycycle_();
  804. }
  805. if (l >= *m) {
  806. /* A( M, M ) is a 1-by-1 block */
  807. mycycle_();
  808. }
  809. if (a[l + (l + 1) * a_dim1] != 0.f && a[l + 1 + l * a_dim1] !=
  810. 0.f) {
  811. /* Check if 2-by-2 block is split */
  812. if (l + 1 == iwork[k + 1]) {
  813. ++iwork[k + 1];
  814. mycycle_();
  815. }
  816. skip = TRUE_;
  817. }
  818. }
  819. }
  820. iwork[nba + 1] = *m + 1;
  821. if (iwork[nba] >= iwork[nba + 1]) {
  822. iwork[nba] = iwork[nba + 1];
  823. --nba;
  824. }
  825. /* Partition B such that 2-by-2 blocks on the diagonal are not split */
  826. pc = nba + 1;
  827. skip = FALSE_;
  828. i__1 = nbb;
  829. for (i__ = 1; i__ <= i__1; ++i__) {
  830. iwork[pc + i__] = (i__ - 1) * nb + 1;
  831. }
  832. iwork[pc + nbb + 1] = *n + 1;
  833. i__1 = nbb;
  834. for (k = 1; k <= i__1; ++k) {
  835. l1 = iwork[pc + k];
  836. l2 = iwork[pc + k + 1] - 1;
  837. i__2 = l2;
  838. for (l = l1; l <= i__2; ++l) {
  839. if (skip) {
  840. skip = FALSE_;
  841. mycycle_();
  842. }
  843. if (l >= *n) {
  844. /* B( N, N ) is a 1-by-1 block */
  845. mycycle_();
  846. }
  847. if (b[l + (l + 1) * b_dim1] != 0.f && b[l + 1 + l * b_dim1] !=
  848. 0.f) {
  849. /* Check if 2-by-2 block is split */
  850. if (l + 1 == iwork[pc + k + 1]) {
  851. ++iwork[pc + k + 1];
  852. mycycle_();
  853. }
  854. skip = TRUE_;
  855. }
  856. }
  857. }
  858. iwork[pc + nbb + 1] = *n + 1;
  859. if (iwork[pc + nbb] >= iwork[pc + nbb + 1]) {
  860. iwork[pc + nbb] = iwork[pc + nbb + 1];
  861. --nbb;
  862. }
  863. /* Set local scaling factors - must never attain zero. */
  864. i__1 = nbb;
  865. for (l = 1; l <= i__1; ++l) {
  866. i__2 = nba;
  867. for (k = 1; k <= i__2; ++k) {
  868. swork[k + l * swork_dim1] = 1.f;
  869. }
  870. }
  871. /* Fallback scaling factor to prevent flushing of SWORK( K, L ) to zero. */
  872. /* This scaling is to ensure compatibility with TRSYL and may get flushed. */
  873. buf = 1.f;
  874. /* Compute upper bounds of blocks of A and B */
  875. awrk = nbb;
  876. i__1 = nba;
  877. for (k = 1; k <= i__1; ++k) {
  878. k1 = iwork[k];
  879. k2 = iwork[k + 1];
  880. i__2 = nba;
  881. for (l = k; l <= i__2; ++l) {
  882. l1 = iwork[l];
  883. l2 = iwork[l + 1];
  884. if (notrna) {
  885. i__3 = k2 - k1;
  886. i__4 = l2 - l1;
  887. swork[k + (awrk + l) * swork_dim1] = slange_("I", &i__3, &
  888. i__4, &a[k1 + l1 * a_dim1], lda, wnrm);
  889. } else {
  890. i__3 = k2 - k1;
  891. i__4 = l2 - l1;
  892. swork[l + (awrk + k) * swork_dim1] = slange_("1", &i__3, &
  893. i__4, &a[k1 + l1 * a_dim1], lda, wnrm);
  894. }
  895. }
  896. }
  897. bwrk = nbb + nba;
  898. i__1 = nbb;
  899. for (k = 1; k <= i__1; ++k) {
  900. k1 = iwork[pc + k];
  901. k2 = iwork[pc + k + 1];
  902. i__2 = nbb;
  903. for (l = k; l <= i__2; ++l) {
  904. l1 = iwork[pc + l];
  905. l2 = iwork[pc + l + 1];
  906. if (notrnb) {
  907. i__3 = k2 - k1;
  908. i__4 = l2 - l1;
  909. swork[k + (bwrk + l) * swork_dim1] = slange_("I", &i__3, &
  910. i__4, &b[k1 + l1 * b_dim1], ldb, wnrm);
  911. } else {
  912. i__3 = k2 - k1;
  913. i__4 = l2 - l1;
  914. swork[l + (bwrk + k) * swork_dim1] = slange_("1", &i__3, &
  915. i__4, &b[k1 + l1 * b_dim1], ldb, wnrm);
  916. }
  917. }
  918. }
  919. sgn = (real) (*isgn);
  920. if (notrna && notrnb) {
  921. /* Solve A*X + ISGN*X*B = scale*C. */
  922. /* The (K,L)th block of X is determined starting from */
  923. /* bottom-left corner column by column by */
  924. /* A(K,K)*X(K,L) + ISGN*X(K,L)*B(L,L) = C(K,L) - R(K,L) */
  925. /* Where */
  926. /* M L-1 */
  927. /* R(K,L) = SUM [A(K,I)*X(I,L)] + ISGN*SUM [X(K,J)*B(J,L)]. */
  928. /* I=K+1 J=1 */
  929. /* Start loop over block rows (index = K) and block columns (index = L) */
  930. for (k = nba; k >= 1; --k) {
  931. /* K1: row index of the first row in X( K, L ) */
  932. /* K2: row index of the first row in X( K+1, L ) */
  933. /* so the K2 - K1 is the column count of the block X( K, L ) */
  934. k1 = iwork[k];
  935. k2 = iwork[k + 1];
  936. i__1 = nbb;
  937. for (l = 1; l <= i__1; ++l) {
  938. /* L1: column index of the first column in X( K, L ) */
  939. /* L2: column index of the first column in X( K, L + 1) */
  940. /* so that L2 - L1 is the row count of the block X( K, L ) */
  941. l1 = iwork[pc + l];
  942. l2 = iwork[pc + l + 1];
  943. i__2 = k2 - k1;
  944. i__3 = l2 - l1;
  945. strsyl_(trana, tranb, isgn, &i__2, &i__3, &a[k1 + k1 * a_dim1]
  946. , lda, &b[l1 + l1 * b_dim1], ldb, &c__[k1 + l1 *
  947. c_dim1], ldc, &scaloc, &iinfo);
  948. *info = f2cmax(*info,iinfo);
  949. if (scaloc * swork[k + l * swork_dim1] == 0.f) {
  950. if (scaloc == 0.f) {
  951. /* The magnitude of the largest entry of X(K1:K2-1, L1:L2-1) */
  952. /* is larger than the product of BIGNUM**2 and cannot be */
  953. /* represented in the form (1/SCALE)*X(K1:K2-1, L1:L2-1). */
  954. /* Mark the computation as pointless. */
  955. buf = 0.f;
  956. } else {
  957. /* Use second scaling factor to prevent flushing to zero. */
  958. i__2 = myexp_(&scaloc);
  959. buf *= pow_ri(&c_b19, &i__2);
  960. }
  961. i__2 = nbb;
  962. for (jj = 1; jj <= i__2; ++jj) {
  963. i__3 = nba;
  964. for (ll = 1; ll <= i__3; ++ll) {
  965. /* Bound by BIGNUM to not introduce Inf. The value */
  966. /* is irrelevant; corresponding entries of the */
  967. /* solution will be flushed in consistency scaling. */
  968. /* Computing MIN */
  969. i__4 = myexp_(&scaloc);
  970. r__1 = bignum, r__2 = swork[ll + jj * swork_dim1]
  971. / pow_ri(&c_b19, &i__4);
  972. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  973. }
  974. }
  975. }
  976. swork[k + l * swork_dim1] = scaloc * swork[k + l * swork_dim1]
  977. ;
  978. i__2 = k2 - k1;
  979. i__3 = l2 - l1;
  980. xnrm = slange_("I", &i__2, &i__3, &c__[k1 + l1 * c_dim1], ldc,
  981. wnrm);
  982. for (i__ = k - 1; i__ >= 1; --i__) {
  983. /* C( I, L ) := C( I, L ) - A( I, K ) * C( K, L ) */
  984. i1 = iwork[i__];
  985. i2 = iwork[i__ + 1];
  986. /* Compute scaling factor to survive the linear update */
  987. /* simulating consistent scaling. */
  988. i__2 = i2 - i1;
  989. i__3 = l2 - l1;
  990. cnrm = slange_("I", &i__2, &i__3, &c__[i1 + l1 * c_dim1],
  991. ldc, wnrm);
  992. /* Computing MIN */
  993. r__1 = swork[i__ + l * swork_dim1], r__2 = swork[k + l *
  994. swork_dim1];
  995. scamin = f2cmin(r__1,r__2);
  996. cnrm *= scamin / swork[i__ + l * swork_dim1];
  997. xnrm *= scamin / swork[k + l * swork_dim1];
  998. anrm = swork[i__ + (awrk + k) * swork_dim1];
  999. scaloc = slarmm_(&anrm, &xnrm, &cnrm);
  1000. if (scaloc * scamin == 0.f) {
  1001. /* Use second scaling factor to prevent flushing to zero. */
  1002. i__2 = myexp_(&scaloc);
  1003. buf *= pow_ri(&c_b19, &i__2);
  1004. i__2 = nbb;
  1005. for (jj = 1; jj <= i__2; ++jj) {
  1006. i__3 = nba;
  1007. for (ll = 1; ll <= i__3; ++ll) {
  1008. /* Computing MIN */
  1009. i__4 = myexp_(&scaloc);
  1010. r__1 = bignum, r__2 = swork[ll + jj *
  1011. swork_dim1] / pow_ri(&c_b19, &i__4);
  1012. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1013. }
  1014. }
  1015. i__2 = myexp_(&scaloc);
  1016. scamin /= pow_ri(&c_b19, &i__2);
  1017. i__2 = myexp_(&scaloc);
  1018. scaloc /= pow_ri(&c_b19, &i__2);
  1019. }
  1020. cnrm *= scaloc;
  1021. xnrm *= scaloc;
  1022. /* Simultaneously apply the robust update factor and the */
  1023. /* consistency scaling factor to C( I, L ) and C( K, L ). */
  1024. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1025. if (scal != 1.f) {
  1026. i__2 = l2 - 1;
  1027. for (jj = l1; jj <= i__2; ++jj) {
  1028. i__3 = k2 - k1;
  1029. sscal_(&i__3, &scal, &c__[k1 + jj * c_dim1], &
  1030. c__1);
  1031. }
  1032. }
  1033. scal = scamin / swork[i__ + l * swork_dim1] * scaloc;
  1034. if (scal != 1.f) {
  1035. i__2 = l2 - 1;
  1036. for (ll = l1; ll <= i__2; ++ll) {
  1037. i__3 = i2 - i1;
  1038. sscal_(&i__3, &scal, &c__[i1 + ll * c_dim1], &
  1039. c__1);
  1040. }
  1041. }
  1042. /* Record current scaling factor */
  1043. swork[k + l * swork_dim1] = scamin * scaloc;
  1044. swork[i__ + l * swork_dim1] = scamin * scaloc;
  1045. i__2 = i2 - i1;
  1046. i__3 = l2 - l1;
  1047. i__4 = k2 - k1;
  1048. sgemm_("N", "N", &i__2, &i__3, &i__4, &c_b31, &a[i1 + k1 *
  1049. a_dim1], lda, &c__[k1 + l1 * c_dim1], ldc, &
  1050. c_b32, &c__[i1 + l1 * c_dim1], ldc);
  1051. }
  1052. i__2 = nbb;
  1053. for (j = l + 1; j <= i__2; ++j) {
  1054. /* C( K, J ) := C( K, J ) - SGN * C( K, L ) * B( L, J ) */
  1055. j1 = iwork[pc + j];
  1056. j2 = iwork[pc + j + 1];
  1057. /* Compute scaling factor to survive the linear update */
  1058. /* simulating consistent scaling. */
  1059. i__3 = k2 - k1;
  1060. i__4 = j2 - j1;
  1061. cnrm = slange_("I", &i__3, &i__4, &c__[k1 + j1 * c_dim1],
  1062. ldc, wnrm);
  1063. /* Computing MIN */
  1064. r__1 = swork[k + j * swork_dim1], r__2 = swork[k + l *
  1065. swork_dim1];
  1066. scamin = f2cmin(r__1,r__2);
  1067. cnrm *= scamin / swork[k + j * swork_dim1];
  1068. xnrm *= scamin / swork[k + l * swork_dim1];
  1069. bnrm = swork[l + (bwrk + j) * swork_dim1];
  1070. scaloc = slarmm_(&bnrm, &xnrm, &cnrm);
  1071. if (scaloc * scamin == 0.f) {
  1072. /* Use second scaling factor to prevent flushing to zero. */
  1073. i__3 = myexp_(&scaloc);
  1074. buf *= pow_ri(&c_b19, &i__3);
  1075. i__3 = nbb;
  1076. for (jj = 1; jj <= i__3; ++jj) {
  1077. i__4 = nba;
  1078. for (ll = 1; ll <= i__4; ++ll) {
  1079. /* Computing MIN */
  1080. i__5 = myexp_(&scaloc);
  1081. r__1 = bignum, r__2 = swork[ll + jj *
  1082. swork_dim1] / pow_ri(&c_b19, &i__5);
  1083. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1084. }
  1085. }
  1086. i__3 = myexp_(&scaloc);
  1087. scamin /= pow_ri(&c_b19, &i__3);
  1088. i__3 = myexp_(&scaloc);
  1089. scaloc /= pow_ri(&c_b19, &i__3);
  1090. }
  1091. cnrm *= scaloc;
  1092. xnrm *= scaloc;
  1093. /* Simultaneously apply the robust update factor and the */
  1094. /* consistency scaling factor to C( K, J ) and C( K, L). */
  1095. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1096. if (scal != 1.f) {
  1097. i__3 = l2 - 1;
  1098. for (ll = l1; ll <= i__3; ++ll) {
  1099. i__4 = k2 - k1;
  1100. sscal_(&i__4, &scal, &c__[k1 + ll * c_dim1], &
  1101. c__1);
  1102. }
  1103. }
  1104. scal = scamin / swork[k + j * swork_dim1] * scaloc;
  1105. if (scal != 1.f) {
  1106. i__3 = j2 - 1;
  1107. for (jj = j1; jj <= i__3; ++jj) {
  1108. i__4 = k2 - k1;
  1109. sscal_(&i__4, &scal, &c__[k1 + jj * c_dim1], &
  1110. c__1);
  1111. }
  1112. }
  1113. /* Record current scaling factor */
  1114. swork[k + l * swork_dim1] = scamin * scaloc;
  1115. swork[k + j * swork_dim1] = scamin * scaloc;
  1116. i__3 = k2 - k1;
  1117. i__4 = j2 - j1;
  1118. i__5 = l2 - l1;
  1119. r__1 = -sgn;
  1120. sgemm_("N", "N", &i__3, &i__4, &i__5, &r__1, &c__[k1 + l1
  1121. * c_dim1], ldc, &b[l1 + j1 * b_dim1], ldb, &c_b32,
  1122. &c__[k1 + j1 * c_dim1], ldc);
  1123. }
  1124. }
  1125. }
  1126. } else if (! notrna && notrnb) {
  1127. /* Solve A**T*X + ISGN*X*B = scale*C. */
  1128. /* The (K,L)th block of X is determined starting from */
  1129. /* upper-left corner column by column by */
  1130. /* A(K,K)**T*X(K,L) + ISGN*X(K,L)*B(L,L) = C(K,L) - R(K,L) */
  1131. /* Where */
  1132. /* K-1 L-1 */
  1133. /* R(K,L) = SUM [A(I,K)**T*X(I,L)] +ISGN*SUM [X(K,J)*B(J,L)] */
  1134. /* I=1 J=1 */
  1135. /* Start loop over block rows (index = K) and block columns (index = L) */
  1136. i__1 = nba;
  1137. for (k = 1; k <= i__1; ++k) {
  1138. /* K1: row index of the first row in X( K, L ) */
  1139. /* K2: row index of the first row in X( K+1, L ) */
  1140. /* so the K2 - K1 is the column count of the block X( K, L ) */
  1141. k1 = iwork[k];
  1142. k2 = iwork[k + 1];
  1143. i__2 = nbb;
  1144. for (l = 1; l <= i__2; ++l) {
  1145. /* L1: column index of the first column in X( K, L ) */
  1146. /* L2: column index of the first column in X( K, L + 1) */
  1147. /* so that L2 - L1 is the row count of the block X( K, L ) */
  1148. l1 = iwork[pc + l];
  1149. l2 = iwork[pc + l + 1];
  1150. i__3 = k2 - k1;
  1151. i__4 = l2 - l1;
  1152. strsyl_(trana, tranb, isgn, &i__3, &i__4, &a[k1 + k1 * a_dim1]
  1153. , lda, &b[l1 + l1 * b_dim1], ldb, &c__[k1 + l1 *
  1154. c_dim1], ldc, &scaloc, &iinfo);
  1155. *info = f2cmax(*info,iinfo);
  1156. if (scaloc * swork[k + l * swork_dim1] == 0.f) {
  1157. if (scaloc == 0.f) {
  1158. /* The magnitude of the largest entry of X(K1:K2-1, L1:L2-1) */
  1159. /* is larger than the product of BIGNUM**2 and cannot be */
  1160. /* represented in the form (1/SCALE)*X(K1:K2-1, L1:L2-1). */
  1161. /* Mark the computation as pointless. */
  1162. buf = 0.f;
  1163. } else {
  1164. /* Use second scaling factor to prevent flushing to zero. */
  1165. i__3 = myexp_(&scaloc);
  1166. buf *= pow_ri(&c_b19, &i__3);
  1167. }
  1168. i__3 = nbb;
  1169. for (jj = 1; jj <= i__3; ++jj) {
  1170. i__4 = nba;
  1171. for (ll = 1; ll <= i__4; ++ll) {
  1172. /* Bound by BIGNUM to not introduce Inf. The value */
  1173. /* is irrelevant; corresponding entries of the */
  1174. /* solution will be flushed in consistency scaling. */
  1175. /* Computing MIN */
  1176. i__5 = myexp_(&scaloc);
  1177. r__1 = bignum, r__2 = swork[ll + jj * swork_dim1]
  1178. / pow_ri(&c_b19, &i__5);
  1179. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1180. }
  1181. }
  1182. }
  1183. swork[k + l * swork_dim1] = scaloc * swork[k + l * swork_dim1]
  1184. ;
  1185. i__3 = k2 - k1;
  1186. i__4 = l2 - l1;
  1187. xnrm = slange_("I", &i__3, &i__4, &c__[k1 + l1 * c_dim1], ldc,
  1188. wnrm);
  1189. i__3 = nba;
  1190. for (i__ = k + 1; i__ <= i__3; ++i__) {
  1191. /* C( I, L ) := C( I, L ) - A( K, I )**T * C( K, L ) */
  1192. i1 = iwork[i__];
  1193. i2 = iwork[i__ + 1];
  1194. /* Compute scaling factor to survive the linear update */
  1195. /* simulating consistent scaling. */
  1196. i__4 = i2 - i1;
  1197. i__5 = l2 - l1;
  1198. cnrm = slange_("I", &i__4, &i__5, &c__[i1 + l1 * c_dim1],
  1199. ldc, wnrm);
  1200. /* Computing MIN */
  1201. r__1 = swork[i__ + l * swork_dim1], r__2 = swork[k + l *
  1202. swork_dim1];
  1203. scamin = f2cmin(r__1,r__2);
  1204. cnrm *= scamin / swork[i__ + l * swork_dim1];
  1205. xnrm *= scamin / swork[k + l * swork_dim1];
  1206. anrm = swork[i__ + (awrk + k) * swork_dim1];
  1207. scaloc = slarmm_(&anrm, &xnrm, &cnrm);
  1208. if (scaloc * scamin == 0.f) {
  1209. /* Use second scaling factor to prevent flushing to zero. */
  1210. i__4 = myexp_(&scaloc);
  1211. buf *= pow_ri(&c_b19, &i__4);
  1212. i__4 = nbb;
  1213. for (jj = 1; jj <= i__4; ++jj) {
  1214. i__5 = nba;
  1215. for (ll = 1; ll <= i__5; ++ll) {
  1216. /* Computing MIN */
  1217. i__6 = myexp_(&scaloc);
  1218. r__1 = bignum, r__2 = swork[ll + jj *
  1219. swork_dim1] / pow_ri(&c_b19, &i__6);
  1220. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1221. }
  1222. }
  1223. i__4 = myexp_(&scaloc);
  1224. scamin /= pow_ri(&c_b19, &i__4);
  1225. i__4 = myexp_(&scaloc);
  1226. scaloc /= pow_ri(&c_b19, &i__4);
  1227. }
  1228. cnrm *= scaloc;
  1229. xnrm *= scaloc;
  1230. /* Simultaneously apply the robust update factor and the */
  1231. /* consistency scaling factor to to C( I, L ) and C( K, L ). */
  1232. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1233. if (scal != 1.f) {
  1234. i__4 = l2 - 1;
  1235. for (ll = l1; ll <= i__4; ++ll) {
  1236. i__5 = k2 - k1;
  1237. sscal_(&i__5, &scal, &c__[k1 + ll * c_dim1], &
  1238. c__1);
  1239. }
  1240. }
  1241. scal = scamin / swork[i__ + l * swork_dim1] * scaloc;
  1242. if (scal != 1.f) {
  1243. i__4 = l2 - 1;
  1244. for (ll = l1; ll <= i__4; ++ll) {
  1245. i__5 = i2 - i1;
  1246. sscal_(&i__5, &scal, &c__[i1 + ll * c_dim1], &
  1247. c__1);
  1248. }
  1249. }
  1250. /* Record current scaling factor */
  1251. swork[k + l * swork_dim1] = scamin * scaloc;
  1252. swork[i__ + l * swork_dim1] = scamin * scaloc;
  1253. i__4 = i2 - i1;
  1254. i__5 = l2 - l1;
  1255. i__6 = k2 - k1;
  1256. sgemm_("T", "N", &i__4, &i__5, &i__6, &c_b31, &a[k1 + i1 *
  1257. a_dim1], lda, &c__[k1 + l1 * c_dim1], ldc, &
  1258. c_b32, &c__[i1 + l1 * c_dim1], ldc);
  1259. }
  1260. i__3 = nbb;
  1261. for (j = l + 1; j <= i__3; ++j) {
  1262. /* C( K, J ) := C( K, J ) - SGN * C( K, L ) * B( L, J ) */
  1263. j1 = iwork[pc + j];
  1264. j2 = iwork[pc + j + 1];
  1265. /* Compute scaling factor to survive the linear update */
  1266. /* simulating consistent scaling. */
  1267. i__4 = k2 - k1;
  1268. i__5 = j2 - j1;
  1269. cnrm = slange_("I", &i__4, &i__5, &c__[k1 + j1 * c_dim1],
  1270. ldc, wnrm);
  1271. /* Computing MIN */
  1272. r__1 = swork[k + j * swork_dim1], r__2 = swork[k + l *
  1273. swork_dim1];
  1274. scamin = f2cmin(r__1,r__2);
  1275. cnrm *= scamin / swork[k + j * swork_dim1];
  1276. xnrm *= scamin / swork[k + l * swork_dim1];
  1277. bnrm = swork[l + (bwrk + j) * swork_dim1];
  1278. scaloc = slarmm_(&bnrm, &xnrm, &cnrm);
  1279. if (scaloc * scamin == 0.f) {
  1280. /* Use second scaling factor to prevent flushing to zero. */
  1281. i__4 = myexp_(&scaloc);
  1282. buf *= pow_ri(&c_b19, &i__4);
  1283. i__4 = nbb;
  1284. for (jj = 1; jj <= i__4; ++jj) {
  1285. i__5 = nba;
  1286. for (ll = 1; ll <= i__5; ++ll) {
  1287. /* Computing MIN */
  1288. i__6 = myexp_(&scaloc);
  1289. r__1 = bignum, r__2 = swork[ll + jj *
  1290. swork_dim1] / pow_ri(&c_b19, &i__6);
  1291. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1292. }
  1293. }
  1294. i__4 = myexp_(&scaloc);
  1295. scamin /= pow_ri(&c_b19, &i__4);
  1296. i__4 = myexp_(&scaloc);
  1297. scaloc /= pow_ri(&c_b19, &i__4);
  1298. }
  1299. cnrm *= scaloc;
  1300. xnrm *= scaloc;
  1301. /* Simultaneously apply the robust update factor and the */
  1302. /* consistency scaling factor to to C( K, J ) and C( K, L ). */
  1303. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1304. if (scal != 1.f) {
  1305. i__4 = l2 - 1;
  1306. for (ll = l1; ll <= i__4; ++ll) {
  1307. i__5 = k2 - k1;
  1308. sscal_(&i__5, &scal, &c__[k1 + ll * c_dim1], &
  1309. c__1);
  1310. }
  1311. }
  1312. scal = scamin / swork[k + j * swork_dim1] * scaloc;
  1313. if (scal != 1.f) {
  1314. i__4 = j2 - 1;
  1315. for (jj = j1; jj <= i__4; ++jj) {
  1316. i__5 = k2 - k1;
  1317. sscal_(&i__5, &scal, &c__[k1 + jj * c_dim1], &
  1318. c__1);
  1319. }
  1320. }
  1321. /* Record current scaling factor */
  1322. swork[k + l * swork_dim1] = scamin * scaloc;
  1323. swork[k + j * swork_dim1] = scamin * scaloc;
  1324. i__4 = k2 - k1;
  1325. i__5 = j2 - j1;
  1326. i__6 = l2 - l1;
  1327. r__1 = -sgn;
  1328. sgemm_("N", "N", &i__4, &i__5, &i__6, &r__1, &c__[k1 + l1
  1329. * c_dim1], ldc, &b[l1 + j1 * b_dim1], ldb, &c_b32,
  1330. &c__[k1 + j1 * c_dim1], ldc);
  1331. }
  1332. }
  1333. }
  1334. } else if (! notrna && ! notrnb) {
  1335. /* Solve A**T*X + ISGN*X*B**T = scale*C. */
  1336. /* The (K,L)th block of X is determined starting from */
  1337. /* top-right corner column by column by */
  1338. /* A(K,K)**T*X(K,L) + ISGN*X(K,L)*B(L,L)**T = C(K,L) - R(K,L) */
  1339. /* Where */
  1340. /* K-1 N */
  1341. /* R(K,L) = SUM [A(I,K)**T*X(I,L)] + ISGN*SUM [X(K,J)*B(L,J)**T]. */
  1342. /* I=1 J=L+1 */
  1343. /* Start loop over block rows (index = K) and block columns (index = L) */
  1344. i__1 = nba;
  1345. for (k = 1; k <= i__1; ++k) {
  1346. /* K1: row index of the first row in X( K, L ) */
  1347. /* K2: row index of the first row in X( K+1, L ) */
  1348. /* so the K2 - K1 is the column count of the block X( K, L ) */
  1349. k1 = iwork[k];
  1350. k2 = iwork[k + 1];
  1351. for (l = nbb; l >= 1; --l) {
  1352. /* L1: column index of the first column in X( K, L ) */
  1353. /* L2: column index of the first column in X( K, L + 1) */
  1354. /* so that L2 - L1 is the row count of the block X( K, L ) */
  1355. l1 = iwork[pc + l];
  1356. l2 = iwork[pc + l + 1];
  1357. i__2 = k2 - k1;
  1358. i__3 = l2 - l1;
  1359. strsyl_(trana, tranb, isgn, &i__2, &i__3, &a[k1 + k1 * a_dim1]
  1360. , lda, &b[l1 + l1 * b_dim1], ldb, &c__[k1 + l1 *
  1361. c_dim1], ldc, &scaloc, &iinfo);
  1362. *info = f2cmax(*info,iinfo);
  1363. if (scaloc * swork[k + l * swork_dim1] == 0.f) {
  1364. if (scaloc == 0.f) {
  1365. /* The magnitude of the largest entry of X(K1:K2-1, L1:L2-1) */
  1366. /* is larger than the product of BIGNUM**2 and cannot be */
  1367. /* represented in the form (1/SCALE)*X(K1:K2-1, L1:L2-1). */
  1368. /* Mark the computation as pointless. */
  1369. buf = 0.f;
  1370. } else {
  1371. /* Use second scaling factor to prevent flushing to zero. */
  1372. i__2 = myexp_(&scaloc);
  1373. buf *= pow_ri(&c_b19, &i__2);
  1374. }
  1375. i__2 = nbb;
  1376. for (jj = 1; jj <= i__2; ++jj) {
  1377. i__3 = nba;
  1378. for (ll = 1; ll <= i__3; ++ll) {
  1379. /* Bound by BIGNUM to not introduce Inf. The value */
  1380. /* is irrelevant; corresponding entries of the */
  1381. /* solution will be flushed in consistency scaling. */
  1382. /* Computing MIN */
  1383. i__4 = myexp_(&scaloc);
  1384. r__1 = bignum, r__2 = swork[ll + jj * swork_dim1]
  1385. / pow_ri(&c_b19, &i__4);
  1386. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1387. }
  1388. }
  1389. }
  1390. swork[k + l * swork_dim1] = scaloc * swork[k + l * swork_dim1]
  1391. ;
  1392. i__2 = k2 - k1;
  1393. i__3 = l2 - l1;
  1394. xnrm = slange_("I", &i__2, &i__3, &c__[k1 + l1 * c_dim1], ldc,
  1395. wnrm);
  1396. i__2 = nba;
  1397. for (i__ = k + 1; i__ <= i__2; ++i__) {
  1398. /* C( I, L ) := C( I, L ) - A( K, I )**T * C( K, L ) */
  1399. i1 = iwork[i__];
  1400. i2 = iwork[i__ + 1];
  1401. /* Compute scaling factor to survive the linear update */
  1402. /* simulating consistent scaling. */
  1403. i__3 = i2 - i1;
  1404. i__4 = l2 - l1;
  1405. cnrm = slange_("I", &i__3, &i__4, &c__[i1 + l1 * c_dim1],
  1406. ldc, wnrm);
  1407. /* Computing MIN */
  1408. r__1 = swork[i__ + l * swork_dim1], r__2 = swork[k + l *
  1409. swork_dim1];
  1410. scamin = f2cmin(r__1,r__2);
  1411. cnrm *= scamin / swork[i__ + l * swork_dim1];
  1412. xnrm *= scamin / swork[k + l * swork_dim1];
  1413. anrm = swork[i__ + (awrk + k) * swork_dim1];
  1414. scaloc = slarmm_(&anrm, &xnrm, &cnrm);
  1415. if (scaloc * scamin == 0.f) {
  1416. /* Use second scaling factor to prevent flushing to zero. */
  1417. i__3 = myexp_(&scaloc);
  1418. buf *= pow_ri(&c_b19, &i__3);
  1419. i__3 = nbb;
  1420. for (jj = 1; jj <= i__3; ++jj) {
  1421. i__4 = nba;
  1422. for (ll = 1; ll <= i__4; ++ll) {
  1423. /* Computing MIN */
  1424. i__5 = myexp_(&scaloc);
  1425. r__1 = bignum, r__2 = swork[ll + jj *
  1426. swork_dim1] / pow_ri(&c_b19, &i__5);
  1427. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1428. }
  1429. }
  1430. i__3 = myexp_(&scaloc);
  1431. scamin /= pow_ri(&c_b19, &i__3);
  1432. i__3 = myexp_(&scaloc);
  1433. scaloc /= pow_ri(&c_b19, &i__3);
  1434. }
  1435. cnrm *= scaloc;
  1436. xnrm *= scaloc;
  1437. /* Simultaneously apply the robust update factor and the */
  1438. /* consistency scaling factor to C( I, L ) and C( K, L ). */
  1439. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1440. if (scal != 1.f) {
  1441. i__3 = l2 - 1;
  1442. for (ll = l1; ll <= i__3; ++ll) {
  1443. i__4 = k2 - k1;
  1444. sscal_(&i__4, &scal, &c__[k1 + ll * c_dim1], &
  1445. c__1);
  1446. }
  1447. }
  1448. scal = scamin / swork[i__ + l * swork_dim1] * scaloc;
  1449. if (scal != 1.f) {
  1450. i__3 = l2 - 1;
  1451. for (ll = l1; ll <= i__3; ++ll) {
  1452. i__4 = i2 - i1;
  1453. sscal_(&i__4, &scal, &c__[i1 + ll * c_dim1], &
  1454. c__1);
  1455. }
  1456. }
  1457. /* Record current scaling factor */
  1458. swork[k + l * swork_dim1] = scamin * scaloc;
  1459. swork[i__ + l * swork_dim1] = scamin * scaloc;
  1460. i__3 = i2 - i1;
  1461. i__4 = l2 - l1;
  1462. i__5 = k2 - k1;
  1463. sgemm_("T", "N", &i__3, &i__4, &i__5, &c_b31, &a[k1 + i1 *
  1464. a_dim1], lda, &c__[k1 + l1 * c_dim1], ldc, &
  1465. c_b32, &c__[i1 + l1 * c_dim1], ldc);
  1466. }
  1467. i__2 = l - 1;
  1468. for (j = 1; j <= i__2; ++j) {
  1469. /* C( K, J ) := C( K, J ) - SGN * C( K, L ) * B( J, L )**T */
  1470. j1 = iwork[pc + j];
  1471. j2 = iwork[pc + j + 1];
  1472. /* Compute scaling factor to survive the linear update */
  1473. /* simulating consistent scaling. */
  1474. i__3 = k2 - k1;
  1475. i__4 = j2 - j1;
  1476. cnrm = slange_("I", &i__3, &i__4, &c__[k1 + j1 * c_dim1],
  1477. ldc, wnrm);
  1478. /* Computing MIN */
  1479. r__1 = swork[k + j * swork_dim1], r__2 = swork[k + l *
  1480. swork_dim1];
  1481. scamin = f2cmin(r__1,r__2);
  1482. cnrm *= scamin / swork[k + j * swork_dim1];
  1483. xnrm *= scamin / swork[k + l * swork_dim1];
  1484. bnrm = swork[l + (bwrk + j) * swork_dim1];
  1485. scaloc = slarmm_(&bnrm, &xnrm, &cnrm);
  1486. if (scaloc * scamin == 0.f) {
  1487. /* Use second scaling factor to prevent flushing to zero. */
  1488. i__3 = myexp_(&scaloc);
  1489. buf *= pow_ri(&c_b19, &i__3);
  1490. i__3 = nbb;
  1491. for (jj = 1; jj <= i__3; ++jj) {
  1492. i__4 = nba;
  1493. for (ll = 1; ll <= i__4; ++ll) {
  1494. /* Computing MIN */
  1495. i__5 = myexp_(&scaloc);
  1496. r__1 = bignum, r__2 = swork[ll + jj *
  1497. swork_dim1] / pow_ri(&c_b19, &i__5);
  1498. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1499. }
  1500. }
  1501. i__3 = myexp_(&scaloc);
  1502. scamin /= pow_ri(&c_b19, &i__3);
  1503. i__3 = myexp_(&scaloc);
  1504. scaloc /= pow_ri(&c_b19, &i__3);
  1505. }
  1506. cnrm *= scaloc;
  1507. xnrm *= scaloc;
  1508. /* Simultaneously apply the robust update factor and the */
  1509. /* consistency scaling factor to C( K, J ) and C( K, L ). */
  1510. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1511. if (scal != 1.f) {
  1512. i__3 = l2 - 1;
  1513. for (ll = l1; ll <= i__3; ++ll) {
  1514. i__4 = k2 - k1;
  1515. sscal_(&i__4, &scal, &c__[k1 + ll * c_dim1], &
  1516. c__1);
  1517. }
  1518. }
  1519. scal = scamin / swork[k + j * swork_dim1] * scaloc;
  1520. if (scal != 1.f) {
  1521. i__3 = j2 - 1;
  1522. for (jj = j1; jj <= i__3; ++jj) {
  1523. i__4 = k2 - k1;
  1524. sscal_(&i__4, &scal, &c__[k1 + jj * c_dim1], &
  1525. c__1);
  1526. }
  1527. }
  1528. /* Record current scaling factor */
  1529. swork[k + l * swork_dim1] = scamin * scaloc;
  1530. swork[k + j * swork_dim1] = scamin * scaloc;
  1531. i__3 = k2 - k1;
  1532. i__4 = j2 - j1;
  1533. i__5 = l2 - l1;
  1534. r__1 = -sgn;
  1535. sgemm_("N", "T", &i__3, &i__4, &i__5, &r__1, &c__[k1 + l1
  1536. * c_dim1], ldc, &b[j1 + l1 * b_dim1], ldb, &c_b32,
  1537. &c__[k1 + j1 * c_dim1], ldc);
  1538. }
  1539. }
  1540. }
  1541. } else if (notrna && ! notrnb) {
  1542. /* Solve A*X + ISGN*X*B**T = scale*C. */
  1543. /* The (K,L)th block of X is determined starting from */
  1544. /* bottom-right corner column by column by */
  1545. /* A(K,K)*X(K,L) + ISGN*X(K,L)*B(L,L)**T = C(K,L) - R(K,L) */
  1546. /* Where */
  1547. /* M N */
  1548. /* R(K,L) = SUM [A(K,I)*X(I,L)] + ISGN*SUM [X(K,J)*B(L,J)**T]. */
  1549. /* I=K+1 J=L+1 */
  1550. /* Start loop over block rows (index = K) and block columns (index = L) */
  1551. for (k = nba; k >= 1; --k) {
  1552. /* K1: row index of the first row in X( K, L ) */
  1553. /* K2: row index of the first row in X( K+1, L ) */
  1554. /* so the K2 - K1 is the column count of the block X( K, L ) */
  1555. k1 = iwork[k];
  1556. k2 = iwork[k + 1];
  1557. for (l = nbb; l >= 1; --l) {
  1558. /* L1: column index of the first column in X( K, L ) */
  1559. /* L2: column index of the first column in X( K, L + 1) */
  1560. /* so that L2 - L1 is the row count of the block X( K, L ) */
  1561. l1 = iwork[pc + l];
  1562. l2 = iwork[pc + l + 1];
  1563. i__1 = k2 - k1;
  1564. i__2 = l2 - l1;
  1565. strsyl_(trana, tranb, isgn, &i__1, &i__2, &a[k1 + k1 * a_dim1]
  1566. , lda, &b[l1 + l1 * b_dim1], ldb, &c__[k1 + l1 *
  1567. c_dim1], ldc, &scaloc, &iinfo);
  1568. *info = f2cmax(*info,iinfo);
  1569. if (scaloc * swork[k + l * swork_dim1] == 0.f) {
  1570. if (scaloc == 0.f) {
  1571. /* The magnitude of the largest entry of X(K1:K2-1, L1:L2-1) */
  1572. /* is larger than the product of BIGNUM**2 and cannot be */
  1573. /* represented in the form (1/SCALE)*X(K1:K2-1, L1:L2-1). */
  1574. /* Mark the computation as pointless. */
  1575. buf = 0.f;
  1576. } else {
  1577. /* Use second scaling factor to prevent flushing to zero. */
  1578. i__1 = myexp_(&scaloc);
  1579. buf *= pow_ri(&c_b19, &i__1);
  1580. }
  1581. i__1 = nbb;
  1582. for (jj = 1; jj <= i__1; ++jj) {
  1583. i__2 = nba;
  1584. for (ll = 1; ll <= i__2; ++ll) {
  1585. /* Bound by BIGNUM to not introduce Inf. The value */
  1586. /* is irrelevant; corresponding entries of the */
  1587. /* solution will be flushed in consistency scaling. */
  1588. /* Computing MIN */
  1589. i__3 = myexp_(&scaloc);
  1590. r__1 = bignum, r__2 = swork[ll + jj * swork_dim1]
  1591. / pow_ri(&c_b19, &i__3);
  1592. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1593. }
  1594. }
  1595. }
  1596. swork[k + l * swork_dim1] = scaloc * swork[k + l * swork_dim1]
  1597. ;
  1598. i__1 = k2 - k1;
  1599. i__2 = l2 - l1;
  1600. xnrm = slange_("I", &i__1, &i__2, &c__[k1 + l1 * c_dim1], ldc,
  1601. wnrm);
  1602. i__1 = k - 1;
  1603. for (i__ = 1; i__ <= i__1; ++i__) {
  1604. /* C( I, L ) := C( I, L ) - A( I, K ) * C( K, L ) */
  1605. i1 = iwork[i__];
  1606. i2 = iwork[i__ + 1];
  1607. /* Compute scaling factor to survive the linear update */
  1608. /* simulating consistent scaling. */
  1609. i__2 = i2 - i1;
  1610. i__3 = l2 - l1;
  1611. cnrm = slange_("I", &i__2, &i__3, &c__[i1 + l1 * c_dim1],
  1612. ldc, wnrm);
  1613. /* Computing MIN */
  1614. r__1 = swork[i__ + l * swork_dim1], r__2 = swork[k + l *
  1615. swork_dim1];
  1616. scamin = f2cmin(r__1,r__2);
  1617. cnrm *= scamin / swork[i__ + l * swork_dim1];
  1618. xnrm *= scamin / swork[k + l * swork_dim1];
  1619. anrm = swork[i__ + (awrk + k) * swork_dim1];
  1620. scaloc = slarmm_(&anrm, &xnrm, &cnrm);
  1621. if (scaloc * scamin == 0.f) {
  1622. /* Use second scaling factor to prevent flushing to zero. */
  1623. i__2 = myexp_(&scaloc);
  1624. buf *= pow_ri(&c_b19, &i__2);
  1625. i__2 = nbb;
  1626. for (jj = 1; jj <= i__2; ++jj) {
  1627. i__3 = nba;
  1628. for (ll = 1; ll <= i__3; ++ll) {
  1629. /* Computing MIN */
  1630. i__4 = myexp_(&scaloc);
  1631. r__1 = bignum, r__2 = swork[ll + jj *
  1632. swork_dim1] / pow_ri(&c_b19, &i__4);
  1633. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1634. }
  1635. }
  1636. i__2 = myexp_(&scaloc);
  1637. scamin /= pow_ri(&c_b19, &i__2);
  1638. i__2 = myexp_(&scaloc);
  1639. scaloc /= pow_ri(&c_b19, &i__2);
  1640. }
  1641. cnrm *= scaloc;
  1642. xnrm *= scaloc;
  1643. /* Simultaneously apply the robust update factor and the */
  1644. /* consistency scaling factor to C( I, L ) and C( K, L ). */
  1645. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1646. if (scal != 1.f) {
  1647. i__2 = l2 - 1;
  1648. for (ll = l1; ll <= i__2; ++ll) {
  1649. i__3 = k2 - k1;
  1650. sscal_(&i__3, &scal, &c__[k1 + ll * c_dim1], &
  1651. c__1);
  1652. }
  1653. }
  1654. scal = scamin / swork[i__ + l * swork_dim1] * scaloc;
  1655. if (scal != 1.f) {
  1656. i__2 = l2 - 1;
  1657. for (ll = l1; ll <= i__2; ++ll) {
  1658. i__3 = i2 - i1;
  1659. sscal_(&i__3, &scal, &c__[i1 + ll * c_dim1], &
  1660. c__1);
  1661. }
  1662. }
  1663. /* Record current scaling factor */
  1664. swork[k + l * swork_dim1] = scamin * scaloc;
  1665. swork[i__ + l * swork_dim1] = scamin * scaloc;
  1666. i__2 = i2 - i1;
  1667. i__3 = l2 - l1;
  1668. i__4 = k2 - k1;
  1669. sgemm_("N", "N", &i__2, &i__3, &i__4, &c_b31, &a[i1 + k1 *
  1670. a_dim1], lda, &c__[k1 + l1 * c_dim1], ldc, &
  1671. c_b32, &c__[i1 + l1 * c_dim1], ldc);
  1672. }
  1673. i__1 = l - 1;
  1674. for (j = 1; j <= i__1; ++j) {
  1675. /* C( K, J ) := C( K, J ) - SGN * C( K, L ) * B( J, L )**T */
  1676. j1 = iwork[pc + j];
  1677. j2 = iwork[pc + j + 1];
  1678. /* Compute scaling factor to survive the linear update */
  1679. /* simulating consistent scaling. */
  1680. i__2 = k2 - k1;
  1681. i__3 = j2 - j1;
  1682. cnrm = slange_("I", &i__2, &i__3, &c__[k1 + j1 * c_dim1],
  1683. ldc, wnrm);
  1684. /* Computing MIN */
  1685. r__1 = swork[k + j * swork_dim1], r__2 = swork[k + l *
  1686. swork_dim1];
  1687. scamin = f2cmin(r__1,r__2);
  1688. cnrm *= scamin / swork[k + j * swork_dim1];
  1689. xnrm *= scamin / swork[k + l * swork_dim1];
  1690. bnrm = swork[l + (bwrk + j) * swork_dim1];
  1691. scaloc = slarmm_(&bnrm, &xnrm, &cnrm);
  1692. if (scaloc * scamin == 0.f) {
  1693. /* Use second scaling factor to prevent flushing to zero. */
  1694. i__2 = myexp_(&scaloc);
  1695. buf *= pow_ri(&c_b19, &i__2);
  1696. i__2 = nbb;
  1697. for (jj = 1; jj <= i__2; ++jj) {
  1698. i__3 = nba;
  1699. for (ll = 1; ll <= i__3; ++ll) {
  1700. /* Computing MIN */
  1701. i__4 = myexp_(&scaloc);
  1702. r__1 = bignum, r__2 = swork[ll + jj *
  1703. swork_dim1] / pow_ri(&c_b19, &i__4);
  1704. swork[ll + jj * swork_dim1] = f2cmin(r__1,r__2);
  1705. }
  1706. }
  1707. i__2 = myexp_(&scaloc);
  1708. scamin /= pow_ri(&c_b19, &i__2);
  1709. i__2 = myexp_(&scaloc);
  1710. scaloc /= pow_ri(&c_b19, &i__2);
  1711. }
  1712. cnrm *= scaloc;
  1713. xnrm *= scaloc;
  1714. /* Simultaneously apply the robust update factor and the */
  1715. /* consistency scaling factor to C( K, J ) and C( K, L ). */
  1716. scal = scamin / swork[k + l * swork_dim1] * scaloc;
  1717. if (scal != 1.f) {
  1718. i__2 = l2 - 1;
  1719. for (jj = l1; jj <= i__2; ++jj) {
  1720. i__3 = k2 - k1;
  1721. sscal_(&i__3, &scal, &c__[k1 + jj * c_dim1], &
  1722. c__1);
  1723. }
  1724. }
  1725. scal = scamin / swork[k + j * swork_dim1] * scaloc;
  1726. if (scal != 1.f) {
  1727. i__2 = j2 - 1;
  1728. for (jj = j1; jj <= i__2; ++jj) {
  1729. i__3 = k2 - k1;
  1730. sscal_(&i__3, &scal, &c__[k1 + jj * c_dim1], &
  1731. c__1);
  1732. }
  1733. }
  1734. /* Record current scaling factor */
  1735. swork[k + l * swork_dim1] = scamin * scaloc;
  1736. swork[k + j * swork_dim1] = scamin * scaloc;
  1737. i__2 = k2 - k1;
  1738. i__3 = j2 - j1;
  1739. i__4 = l2 - l1;
  1740. r__1 = -sgn;
  1741. sgemm_("N", "T", &i__2, &i__3, &i__4, &r__1, &c__[k1 + l1
  1742. * c_dim1], ldc, &b[j1 + l1 * b_dim1], ldb, &c_b32,
  1743. &c__[k1 + j1 * c_dim1], ldc);
  1744. }
  1745. }
  1746. }
  1747. }
  1748. free(wnrm);
  1749. /* Reduce local scaling factors */
  1750. *scale = swork[swork_dim1 + 1];
  1751. i__1 = nba;
  1752. for (k = 1; k <= i__1; ++k) {
  1753. i__2 = nbb;
  1754. for (l = 1; l <= i__2; ++l) {
  1755. /* Computing MIN */
  1756. r__1 = *scale, r__2 = swork[k + l * swork_dim1];
  1757. *scale = f2cmin(r__1,r__2);
  1758. }
  1759. }
  1760. if (*scale == 0.f) {
  1761. /* The magnitude of the largest entry of the solution is larger */
  1762. /* than the product of BIGNUM**2 and cannot be represented in the */
  1763. /* form (1/SCALE)*X if SCALE is REAL. Set SCALE to zero and give up. */
  1764. iwork[1] = nba + nbb + 2;
  1765. swork[swork_dim1 + 1] = (real) f2cmax(nba,nbb);
  1766. swork[swork_dim1 + 2] = (real) ((nbb << 1) + nba);
  1767. return;
  1768. }
  1769. /* Realize consistent scaling */
  1770. i__1 = nba;
  1771. for (k = 1; k <= i__1; ++k) {
  1772. k1 = iwork[k];
  1773. k2 = iwork[k + 1];
  1774. i__2 = nbb;
  1775. for (l = 1; l <= i__2; ++l) {
  1776. l1 = iwork[pc + l];
  1777. l2 = iwork[pc + l + 1];
  1778. scal = *scale / swork[k + l * swork_dim1];
  1779. if (scal != 1.f) {
  1780. i__3 = l2 - 1;
  1781. for (ll = l1; ll <= i__3; ++ll) {
  1782. i__4 = k2 - k1;
  1783. sscal_(&i__4, &scal, &c__[k1 + ll * c_dim1], &c__1);
  1784. }
  1785. }
  1786. }
  1787. }
  1788. if (buf != 1.f && buf > 0.f) {
  1789. /* Decrease SCALE as much as possible. */
  1790. /* Computing MIN */
  1791. r__1 = *scale / smlnum, r__2 = 1.f / buf;
  1792. scaloc = f2cmin(r__1,r__2);
  1793. buf *= scaloc;
  1794. *scale /= scaloc;
  1795. }
  1796. if (buf != 1.f && buf > 0.f) {
  1797. /* In case of overly aggressive scaling during the computation, */
  1798. /* flushing of the global scale factor may be prevented by */
  1799. /* undoing some of the scaling. This step is to ensure that */
  1800. /* this routine flushes only scale factors that TRSYL also */
  1801. /* flushes and be usable as a drop-in replacement. */
  1802. /* How much can the normwise largest entry be upscaled? */
  1803. scal = c__[c_dim1 + 1];
  1804. i__1 = *m;
  1805. for (k = 1; k <= i__1; ++k) {
  1806. i__2 = *n;
  1807. for (l = 1; l <= i__2; ++l) {
  1808. /* Computing MAX */
  1809. r__2 = scal, r__3 = (r__1 = c__[k + l * c_dim1], abs(r__1));
  1810. scal = f2cmax(r__2,r__3);
  1811. }
  1812. }
  1813. /* Increase BUF as close to 1 as possible and apply scaling. */
  1814. /* Computing MIN */
  1815. r__1 = bignum / scal, r__2 = 1.f / buf;
  1816. scaloc = f2cmin(r__1,r__2);
  1817. buf *= scaloc;
  1818. slascl_("G", &c_n1, &c_n1, &c_b32, &scaloc, m, n, &c__[c_offset], ldc,
  1819. &iwork[1]);
  1820. }
  1821. /* Combine with buffer scaling factor. SCALE will be flushed if */
  1822. /* BUF is less than one here. */
  1823. *scale *= buf;
  1824. /* Restore workspace dimensions */
  1825. iwork[1] = nba + nbb + 2;
  1826. swork[swork_dim1 + 1] = (real) f2cmax(nba,nbb);
  1827. swork[swork_dim1 + 2] = (real) ((nbb << 1) + nba);
  1828. return;
  1829. /* End of STRSYL3 */
  1830. } /* strsyl3_ */