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.

sgesvj.c 70 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334
  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 int logical;
  52. typedef short int shortlogical;
  53. typedef char logical1;
  54. typedef char integer1;
  55. #define TRUE_ (1)
  56. #define FALSE_ (0)
  57. /* Extern is for use with -E */
  58. #ifndef Extern
  59. #define Extern extern
  60. #endif
  61. /* I/O stuff */
  62. typedef int flag;
  63. typedef int ftnlen;
  64. typedef int ftnint;
  65. /*external read, write*/
  66. typedef struct
  67. { flag cierr;
  68. ftnint ciunit;
  69. flag ciend;
  70. char *cifmt;
  71. ftnint cirec;
  72. } cilist;
  73. /*internal read, write*/
  74. typedef struct
  75. { flag icierr;
  76. char *iciunit;
  77. flag iciend;
  78. char *icifmt;
  79. ftnint icirlen;
  80. ftnint icirnum;
  81. } icilist;
  82. /*open*/
  83. typedef struct
  84. { flag oerr;
  85. ftnint ounit;
  86. char *ofnm;
  87. ftnlen ofnmlen;
  88. char *osta;
  89. char *oacc;
  90. char *ofm;
  91. ftnint orl;
  92. char *oblnk;
  93. } olist;
  94. /*close*/
  95. typedef struct
  96. { flag cerr;
  97. ftnint cunit;
  98. char *csta;
  99. } cllist;
  100. /*rewind, backspace, endfile*/
  101. typedef struct
  102. { flag aerr;
  103. ftnint aunit;
  104. } alist;
  105. /* inquire */
  106. typedef struct
  107. { flag inerr;
  108. ftnint inunit;
  109. char *infile;
  110. ftnlen infilen;
  111. ftnint *inex; /*parameters in standard's order*/
  112. ftnint *inopen;
  113. ftnint *innum;
  114. ftnint *innamed;
  115. char *inname;
  116. ftnlen innamlen;
  117. char *inacc;
  118. ftnlen inacclen;
  119. char *inseq;
  120. ftnlen inseqlen;
  121. char *indir;
  122. ftnlen indirlen;
  123. char *infmt;
  124. ftnlen infmtlen;
  125. char *inform;
  126. ftnint informlen;
  127. char *inunf;
  128. ftnlen inunflen;
  129. ftnint *inrecl;
  130. ftnint *innrec;
  131. char *inblank;
  132. ftnlen inblanklen;
  133. } inlist;
  134. #define VOID void
  135. union Multitype { /* for multiple entry points */
  136. integer1 g;
  137. shortint h;
  138. integer i;
  139. /* longint j; */
  140. real r;
  141. doublereal d;
  142. complex c;
  143. doublecomplex z;
  144. };
  145. typedef union Multitype Multitype;
  146. struct Vardesc { /* for Namelist */
  147. char *name;
  148. char *addr;
  149. ftnlen *dims;
  150. int type;
  151. };
  152. typedef struct Vardesc Vardesc;
  153. struct Namelist {
  154. char *name;
  155. Vardesc **vars;
  156. int nvars;
  157. };
  158. typedef struct Namelist Namelist;
  159. #define abs(x) ((x) >= 0 ? (x) : -(x))
  160. #define dabs(x) (fabs(x))
  161. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  162. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  163. #define dmin(a,b) (f2cmin(a,b))
  164. #define dmax(a,b) (f2cmax(a,b))
  165. #define bit_test(a,b) ((a) >> (b) & 1)
  166. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  167. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  168. #define abort_() { sig_die("Fortran abort routine called", 1); }
  169. #define c_abs(z) (cabsf(Cf(z)))
  170. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  171. #ifdef _MSC_VER
  172. #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]);}
  173. #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]);}
  174. #else
  175. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  176. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  177. #endif
  178. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  179. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  180. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  181. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  182. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  183. #define d_abs(x) (fabs(*(x)))
  184. #define d_acos(x) (acos(*(x)))
  185. #define d_asin(x) (asin(*(x)))
  186. #define d_atan(x) (atan(*(x)))
  187. #define d_atn2(x, y) (atan2(*(x),*(y)))
  188. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  189. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  190. #define d_cos(x) (cos(*(x)))
  191. #define d_cosh(x) (cosh(*(x)))
  192. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  193. #define d_exp(x) (exp(*(x)))
  194. #define d_imag(z) (cimag(Cd(z)))
  195. #define r_imag(z) (cimagf(Cf(z)))
  196. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  198. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  200. #define d_log(x) (log(*(x)))
  201. #define d_mod(x, y) (fmod(*(x), *(y)))
  202. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  203. #define d_nint(x) u_nint(*(x))
  204. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  205. #define d_sign(a,b) u_sign(*(a),*(b))
  206. #define r_sign(a,b) u_sign(*(a),*(b))
  207. #define d_sin(x) (sin(*(x)))
  208. #define d_sinh(x) (sinh(*(x)))
  209. #define d_sqrt(x) (sqrt(*(x)))
  210. #define d_tan(x) (tan(*(x)))
  211. #define d_tanh(x) (tanh(*(x)))
  212. #define i_abs(x) abs(*(x))
  213. #define i_dnnt(x) ((integer)u_nint(*(x)))
  214. #define i_len(s, n) (n)
  215. #define i_nint(x) ((integer)u_nint(*(x)))
  216. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  217. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  218. #define pow_si(B,E) spow_ui(*(B),*(E))
  219. #define pow_ri(B,E) spow_ui(*(B),*(E))
  220. #define pow_di(B,E) dpow_ui(*(B),*(E))
  221. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  222. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  223. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  224. #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++ = ' '; }
  225. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  226. #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]; }
  227. #define sig_die(s, kill) { exit(1); }
  228. #define s_stop(s, n) {exit(0);}
  229. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  230. #define z_abs(z) (cabs(Cd(z)))
  231. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  232. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  233. #define myexit_() break;
  234. #define mycycle() continue;
  235. #define myceiling(w) {ceil(w)}
  236. #define myhuge(w) {HUGE_VAL}
  237. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  238. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  239. /* procedure parameter types for -A and -C++ */
  240. #define F2C_proc_par_types 1
  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 real c_b17 = 0.f;
  487. static real c_b18 = 1.f;
  488. static integer c__1 = 1;
  489. static integer c__0 = 0;
  490. static integer c__2 = 2;
  491. /* > \brief \b SGESVJ */
  492. /* =========== DOCUMENTATION =========== */
  493. /* Online html documentation available at */
  494. /* http://www.netlib.org/lapack/explore-html/ */
  495. /* > \htmlonly */
  496. /* > Download SGESVJ + dependencies */
  497. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgesvj.
  498. f"> */
  499. /* > [TGZ]</a> */
  500. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgesvj.
  501. f"> */
  502. /* > [ZIP]</a> */
  503. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgesvj.
  504. f"> */
  505. /* > [TXT]</a> */
  506. /* > \endhtmlonly */
  507. /* Definition: */
  508. /* =========== */
  509. /* SUBROUTINE SGESVJ( JOBA, JOBU, JOBV, M, N, A, LDA, SVA, MV, V, */
  510. /* LDV, WORK, LWORK, INFO ) */
  511. /* INTEGER INFO, LDA, LDV, LWORK, M, MV, N */
  512. /* CHARACTER*1 JOBA, JOBU, JOBV */
  513. /* REAL A( LDA, * ), SVA( N ), V( LDV, * ), */
  514. /* $ WORK( LWORK ) */
  515. /* > \par Purpose: */
  516. /* ============= */
  517. /* > */
  518. /* > \verbatim */
  519. /* > */
  520. /* > SGESVJ computes the singular value decomposition (SVD) of a real */
  521. /* > M-by-N matrix A, where M >= N. The SVD of A is written as */
  522. /* > [++] [xx] [x0] [xx] */
  523. /* > A = U * SIGMA * V^t, [++] = [xx] * [ox] * [xx] */
  524. /* > [++] [xx] */
  525. /* > where SIGMA is an N-by-N diagonal matrix, U is an M-by-N orthonormal */
  526. /* > matrix, and V is an N-by-N orthogonal matrix. The diagonal elements */
  527. /* > of SIGMA are the singular values of A. The columns of U and V are the */
  528. /* > left and the right singular vectors of A, respectively. */
  529. /* > SGESVJ can sometimes compute tiny singular values and their singular vectors much */
  530. /* > more accurately than other SVD routines, see below under Further Details. */
  531. /* > \endverbatim */
  532. /* Arguments: */
  533. /* ========== */
  534. /* > \param[in] JOBA */
  535. /* > \verbatim */
  536. /* > JOBA is CHARACTER*1 */
  537. /* > Specifies the structure of A. */
  538. /* > = 'L': The input matrix A is lower triangular; */
  539. /* > = 'U': The input matrix A is upper triangular; */
  540. /* > = 'G': The input matrix A is general M-by-N matrix, M >= N. */
  541. /* > \endverbatim */
  542. /* > */
  543. /* > \param[in] JOBU */
  544. /* > \verbatim */
  545. /* > JOBU is CHARACTER*1 */
  546. /* > Specifies whether to compute the left singular vectors */
  547. /* > (columns of U): */
  548. /* > = 'U': The left singular vectors corresponding to the nonzero */
  549. /* > singular values are computed and returned in the leading */
  550. /* > columns of A. See more details in the description of A. */
  551. /* > The default numerical orthogonality threshold is set to */
  552. /* > approximately TOL=CTOL*EPS, CTOL=SQRT(M), EPS=SLAMCH('E'). */
  553. /* > = 'C': Analogous to JOBU='U', except that user can control the */
  554. /* > level of numerical orthogonality of the computed left */
  555. /* > singular vectors. TOL can be set to TOL = CTOL*EPS, where */
  556. /* > CTOL is given on input in the array WORK. */
  557. /* > No CTOL smaller than ONE is allowed. CTOL greater */
  558. /* > than 1 / EPS is meaningless. The option 'C' */
  559. /* > can be used if M*EPS is satisfactory orthogonality */
  560. /* > of the computed left singular vectors, so CTOL=M could */
  561. /* > save few sweeps of Jacobi rotations. */
  562. /* > See the descriptions of A and WORK(1). */
  563. /* > = 'N': The matrix U is not computed. However, see the */
  564. /* > description of A. */
  565. /* > \endverbatim */
  566. /* > */
  567. /* > \param[in] JOBV */
  568. /* > \verbatim */
  569. /* > JOBV is CHARACTER*1 */
  570. /* > Specifies whether to compute the right singular vectors, that */
  571. /* > is, the matrix V: */
  572. /* > = 'V': the matrix V is computed and returned in the array V */
  573. /* > = 'A': the Jacobi rotations are applied to the MV-by-N */
  574. /* > array V. In other words, the right singular vector */
  575. /* > matrix V is not computed explicitly; instead it is */
  576. /* > applied to an MV-by-N matrix initially stored in the */
  577. /* > first MV rows of V. */
  578. /* > = 'N': the matrix V is not computed and the array V is not */
  579. /* > referenced */
  580. /* > \endverbatim */
  581. /* > */
  582. /* > \param[in] M */
  583. /* > \verbatim */
  584. /* > M is INTEGER */
  585. /* > The number of rows of the input matrix A. 1/SLAMCH('E') > M >= 0. */
  586. /* > \endverbatim */
  587. /* > */
  588. /* > \param[in] N */
  589. /* > \verbatim */
  590. /* > N is INTEGER */
  591. /* > The number of columns of the input matrix A. */
  592. /* > M >= N >= 0. */
  593. /* > \endverbatim */
  594. /* > */
  595. /* > \param[in,out] A */
  596. /* > \verbatim */
  597. /* > A is REAL array, dimension (LDA,N) */
  598. /* > On entry, the M-by-N matrix A. */
  599. /* > On exit, */
  600. /* > If JOBU = 'U' .OR. JOBU = 'C': */
  601. /* > If INFO = 0: */
  602. /* > RANKA orthonormal columns of U are returned in the */
  603. /* > leading RANKA columns of the array A. Here RANKA <= N */
  604. /* > is the number of computed singular values of A that are */
  605. /* > above the underflow threshold SLAMCH('S'). The singular */
  606. /* > vectors corresponding to underflowed or zero singular */
  607. /* > values are not computed. The value of RANKA is returned */
  608. /* > in the array WORK as RANKA=NINT(WORK(2)). Also see the */
  609. /* > descriptions of SVA and WORK. The computed columns of U */
  610. /* > are mutually numerically orthogonal up to approximately */
  611. /* > TOL=SQRT(M)*EPS (default); or TOL=CTOL*EPS (JOBU = 'C'), */
  612. /* > see the description of JOBU. */
  613. /* > If INFO > 0, */
  614. /* > the procedure SGESVJ did not converge in the given number */
  615. /* > of iterations (sweeps). In that case, the computed */
  616. /* > columns of U may not be orthogonal up to TOL. The output */
  617. /* > U (stored in A), SIGMA (given by the computed singular */
  618. /* > values in SVA(1:N)) and V is still a decomposition of the */
  619. /* > input matrix A in the sense that the residual */
  620. /* > ||A-SCALE*U*SIGMA*V^T||_2 / ||A||_2 is small. */
  621. /* > If JOBU = 'N': */
  622. /* > If INFO = 0: */
  623. /* > Note that the left singular vectors are 'for free' in the */
  624. /* > one-sided Jacobi SVD algorithm. However, if only the */
  625. /* > singular values are needed, the level of numerical */
  626. /* > orthogonality of U is not an issue and iterations are */
  627. /* > stopped when the columns of the iterated matrix are */
  628. /* > numerically orthogonal up to approximately M*EPS. Thus, */
  629. /* > on exit, A contains the columns of U scaled with the */
  630. /* > corresponding singular values. */
  631. /* > If INFO > 0: */
  632. /* > the procedure SGESVJ did not converge in the given number */
  633. /* > of iterations (sweeps). */
  634. /* > \endverbatim */
  635. /* > */
  636. /* > \param[in] LDA */
  637. /* > \verbatim */
  638. /* > LDA is INTEGER */
  639. /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
  640. /* > \endverbatim */
  641. /* > */
  642. /* > \param[out] SVA */
  643. /* > \verbatim */
  644. /* > SVA is REAL array, dimension (N) */
  645. /* > On exit, */
  646. /* > If INFO = 0 : */
  647. /* > depending on the value SCALE = WORK(1), we have: */
  648. /* > If SCALE = ONE: */
  649. /* > SVA(1:N) contains the computed singular values of A. */
  650. /* > During the computation SVA contains the Euclidean column */
  651. /* > norms of the iterated matrices in the array A. */
  652. /* > If SCALE .NE. ONE: */
  653. /* > The singular values of A are SCALE*SVA(1:N), and this */
  654. /* > factored representation is due to the fact that some of the */
  655. /* > singular values of A might underflow or overflow. */
  656. /* > */
  657. /* > If INFO > 0 : */
  658. /* > the procedure SGESVJ did not converge in the given number of */
  659. /* > iterations (sweeps) and SCALE*SVA(1:N) may not be accurate. */
  660. /* > \endverbatim */
  661. /* > */
  662. /* > \param[in] MV */
  663. /* > \verbatim */
  664. /* > MV is INTEGER */
  665. /* > If JOBV = 'A', then the product of Jacobi rotations in SGESVJ */
  666. /* > is applied to the first MV rows of V. See the description of JOBV. */
  667. /* > \endverbatim */
  668. /* > */
  669. /* > \param[in,out] V */
  670. /* > \verbatim */
  671. /* > V is REAL array, dimension (LDV,N) */
  672. /* > If JOBV = 'V', then V contains on exit the N-by-N matrix of */
  673. /* > the right singular vectors; */
  674. /* > If JOBV = 'A', then V contains the product of the computed right */
  675. /* > singular vector matrix and the initial matrix in */
  676. /* > the array V. */
  677. /* > If JOBV = 'N', then V is not referenced. */
  678. /* > \endverbatim */
  679. /* > */
  680. /* > \param[in] LDV */
  681. /* > \verbatim */
  682. /* > LDV is INTEGER */
  683. /* > The leading dimension of the array V, LDV >= 1. */
  684. /* > If JOBV = 'V', then LDV >= f2cmax(1,N). */
  685. /* > If JOBV = 'A', then LDV >= f2cmax(1,MV) . */
  686. /* > \endverbatim */
  687. /* > */
  688. /* > \param[in,out] WORK */
  689. /* > \verbatim */
  690. /* > WORK is REAL array, dimension (LWORK) */
  691. /* > On entry, */
  692. /* > If JOBU = 'C' : */
  693. /* > WORK(1) = CTOL, where CTOL defines the threshold for convergence. */
  694. /* > The process stops if all columns of A are mutually */
  695. /* > orthogonal up to CTOL*EPS, EPS=SLAMCH('E'). */
  696. /* > It is required that CTOL >= ONE, i.e. it is not */
  697. /* > allowed to force the routine to obtain orthogonality */
  698. /* > below EPSILON. */
  699. /* > On exit, */
  700. /* > WORK(1) = SCALE is the scaling factor such that SCALE*SVA(1:N) */
  701. /* > are the computed singular vcalues of A. */
  702. /* > (See description of SVA().) */
  703. /* > WORK(2) = NINT(WORK(2)) is the number of the computed nonzero */
  704. /* > singular values. */
  705. /* > WORK(3) = NINT(WORK(3)) is the number of the computed singular */
  706. /* > values that are larger than the underflow threshold. */
  707. /* > WORK(4) = NINT(WORK(4)) is the number of sweeps of Jacobi */
  708. /* > rotations needed for numerical convergence. */
  709. /* > WORK(5) = max_{i.NE.j} |COS(A(:,i),A(:,j))| in the last sweep. */
  710. /* > This is useful information in cases when SGESVJ did */
  711. /* > not converge, as it can be used to estimate whether */
  712. /* > the output is still useful and for post festum analysis. */
  713. /* > WORK(6) = the largest absolute value over all sines of the */
  714. /* > Jacobi rotation angles in the last sweep. It can be */
  715. /* > useful for a post festum analysis. */
  716. /* > \endverbatim */
  717. /* > */
  718. /* > \param[in] LWORK */
  719. /* > \verbatim */
  720. /* > LWORK is INTEGER */
  721. /* > length of WORK, WORK >= MAX(6,M+N) */
  722. /* > \endverbatim */
  723. /* > */
  724. /* > \param[out] INFO */
  725. /* > \verbatim */
  726. /* > INFO is INTEGER */
  727. /* > = 0: successful exit. */
  728. /* > < 0: if INFO = -i, then the i-th argument had an illegal value */
  729. /* > > 0: SGESVJ did not converge in the maximal allowed number (30) */
  730. /* > of sweeps. The output may still be useful. See the */
  731. /* > description of WORK. */
  732. /* > \endverbatim */
  733. /* Authors: */
  734. /* ======== */
  735. /* > \author Univ. of Tennessee */
  736. /* > \author Univ. of California Berkeley */
  737. /* > \author Univ. of Colorado Denver */
  738. /* > \author NAG Ltd. */
  739. /* > \date June 2017 */
  740. /* > \ingroup realGEcomputational */
  741. /* > \par Further Details: */
  742. /* ===================== */
  743. /* > */
  744. /* > The orthogonal N-by-N matrix V is obtained as a product of Jacobi plane */
  745. /* > rotations. The rotations are implemented as fast scaled rotations of */
  746. /* > Anda and Park [1]. In the case of underflow of the Jacobi angle, a */
  747. /* > modified Jacobi transformation of Drmac [4] is used. Pivot strategy uses */
  748. /* > column interchanges of de Rijk [2]. The relative accuracy of the computed */
  749. /* > singular values and the accuracy of the computed singular vectors (in */
  750. /* > angle metric) is as guaranteed by the theory of Demmel and Veselic [3]. */
  751. /* > The condition number that determines the accuracy in the full rank case */
  752. /* > is essentially min_{D=diag} kappa(A*D), where kappa(.) is the */
  753. /* > spectral condition number. The best performance of this Jacobi SVD */
  754. /* > procedure is achieved if used in an accelerated version of Drmac and */
  755. /* > Veselic [5,6], and it is the kernel routine in the SIGMA library [7]. */
  756. /* > Some tunning parameters (marked with [TP]) are available for the */
  757. /* > implementer. \n */
  758. /* > The computational range for the nonzero singular values is the machine */
  759. /* > number interval ( UNDERFLOW , OVERFLOW ). In extreme cases, even */
  760. /* > denormalized singular values can be computed with the corresponding */
  761. /* > gradual loss of accurate digits. */
  762. /* > */
  763. /* > \par Contributors: */
  764. /* ================== */
  765. /* > */
  766. /* > Zlatko Drmac (Zagreb, Croatia) and Kresimir Veselic (Hagen, Germany) */
  767. /* > */
  768. /* > \par References: */
  769. /* ================ */
  770. /* > */
  771. /* > [1] A. A. Anda and H. Park: Fast plane rotations with dynamic scaling. \n */
  772. /* > SIAM J. matrix Anal. Appl., Vol. 15 (1994), pp. 162-174. \n\n */
  773. /* > [2] P. P. M. De Rijk: A one-sided Jacobi algorithm for computing the */
  774. /* > singular value decomposition on a vector computer. \n */
  775. /* > SIAM J. Sci. Stat. Comp., Vol. 10 (1998), pp. 359-371. \n\n */
  776. /* > [3] J. Demmel and K. Veselic: Jacobi method is more accurate than QR. \n */
  777. /* > [4] Z. Drmac: Implementation of Jacobi rotations for accurate singular */
  778. /* > value computation in floating point arithmetic. \n */
  779. /* > SIAM J. Sci. Comp., Vol. 18 (1997), pp. 1200-1222. \n\n */
  780. /* > [5] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm I. \n */
  781. /* > SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1322-1342. \n */
  782. /* > LAPACK Working note 169. \n\n */
  783. /* > [6] Z. Drmac and K. Veselic: New fast and accurate Jacobi SVD algorithm II. \n */
  784. /* > SIAM J. Matrix Anal. Appl. Vol. 35, No. 2 (2008), pp. 1343-1362. \n */
  785. /* > LAPACK Working note 170. \n\n */
  786. /* > [7] Z. Drmac: SIGMA - mathematical software library for accurate SVD, PSV, */
  787. /* > QSVD, (H,K)-SVD computations.\n */
  788. /* > Department of Mathematics, University of Zagreb, 2008. */
  789. /* > */
  790. /* > \par Bugs, Examples and Comments: */
  791. /* ================================= */
  792. /* > */
  793. /* > Please report all bugs and send interesting test examples and comments to */
  794. /* > drmac@math.hr. Thank you. */
  795. /* ===================================================================== */
  796. /* Subroutine */ void sgesvj_(char *joba, char *jobu, char *jobv, integer *m,
  797. integer *n, real *a, integer *lda, real *sva, integer *mv, real *v,
  798. integer *ldv, real *work, integer *lwork, integer *info)
  799. {
  800. /* System generated locals */
  801. integer a_dim1, a_offset, v_dim1, v_offset, i__1, i__2, i__3, i__4, i__5;
  802. real r__1, r__2;
  803. /* Local variables */
  804. real aapp, aapq, aaqq, ctol;
  805. integer ierr;
  806. real bigtheta;
  807. extern real sdot_(integer *, real *, integer *, real *, integer *);
  808. integer pskipped;
  809. real aapp0, temp1;
  810. extern real snrm2_(integer *, real *, integer *);
  811. integer i__, p, q;
  812. real t, large, apoaq, aqoap;
  813. extern logical lsame_(char *, char *);
  814. real theta;
  815. extern /* Subroutine */ void sscal_(integer *, real *, real *, integer *);
  816. real small, sfmin;
  817. logical lsvec;
  818. real fastr[5], epsln;
  819. logical applv, rsvec, uctol, lower, upper;
  820. extern /* Subroutine */ void scopy_(integer *, real *, integer *, real *,
  821. integer *);
  822. logical rotok;
  823. integer n2;
  824. extern /* Subroutine */ void sswap_(integer *, real *, integer *, real *,
  825. integer *);
  826. integer n4;
  827. extern /* Subroutine */ void saxpy_(integer *, real *, real *, integer *,
  828. real *, integer *), srotm_(integer *, real *, integer *, real *,
  829. integer *, real *);
  830. real rootsfmin;
  831. extern /* Subroutine */ void sgsvj0_(char *, integer *, integer *, real *,
  832. integer *, real *, real *, integer *, real *, integer *, real *,
  833. real *, real *, integer *, real *, integer *, integer *),
  834. sgsvj1_(char *, integer *, integer *, integer *, real *, integer *
  835. , real *, real *, integer *, real *, integer *, real *, real *,
  836. real *, integer *, real *, integer *, integer *);
  837. integer n34;
  838. real cs, sn;
  839. extern real slamch_(char *);
  840. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  841. integer ijblsk, swband;
  842. extern /* Subroutine */ void slascl_(char *, integer *, integer *, real *,
  843. real *, integer *, integer *, real *, integer *, integer *);
  844. extern integer isamax_(integer *, real *, integer *);
  845. integer blskip;
  846. real mxaapq;
  847. extern /* Subroutine */ void slaset_(char *, integer *, integer *, real *,
  848. real *, real *, integer *);
  849. real thsign;
  850. extern /* Subroutine */ void slassq_(integer *, real *, integer *, real *,
  851. real *);
  852. real mxsinj;
  853. integer ir1, emptsw, notrot, iswrot, jbc;
  854. real big;
  855. integer kbl, lkahead, igl, ibr, jgl, nbl;
  856. real skl;
  857. logical goscale;
  858. real tol;
  859. integer mvl;
  860. logical noscale;
  861. real rootbig, rooteps;
  862. integer rowskip;
  863. real roottol;
  864. /* -- LAPACK computational routine (version 3.7.1) -- */
  865. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  866. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  867. /* June 2017 */
  868. /* ===================================================================== */
  869. /* from BLAS */
  870. /* from LAPACK */
  871. /* from BLAS */
  872. /* from LAPACK */
  873. /* Test the input arguments */
  874. /* Parameter adjustments */
  875. --sva;
  876. a_dim1 = *lda;
  877. a_offset = 1 + a_dim1 * 1;
  878. a -= a_offset;
  879. v_dim1 = *ldv;
  880. v_offset = 1 + v_dim1 * 1;
  881. v -= v_offset;
  882. --work;
  883. /* Function Body */
  884. lsvec = lsame_(jobu, "U");
  885. uctol = lsame_(jobu, "C");
  886. rsvec = lsame_(jobv, "V");
  887. applv = lsame_(jobv, "A");
  888. upper = lsame_(joba, "U");
  889. lower = lsame_(joba, "L");
  890. if (! (upper || lower || lsame_(joba, "G"))) {
  891. *info = -1;
  892. } else if (! (lsvec || uctol || lsame_(jobu, "N")))
  893. {
  894. *info = -2;
  895. } else if (! (rsvec || applv || lsame_(jobv, "N")))
  896. {
  897. *info = -3;
  898. } else if (*m < 0) {
  899. *info = -4;
  900. } else if (*n < 0 || *n > *m) {
  901. *info = -5;
  902. } else if (*lda < *m) {
  903. *info = -7;
  904. } else if (*mv < 0) {
  905. *info = -9;
  906. } else if (rsvec && *ldv < *n || applv && *ldv < *mv) {
  907. *info = -11;
  908. } else if (uctol && work[1] <= 1.f) {
  909. *info = -12;
  910. } else /* if(complicated condition) */ {
  911. /* Computing MAX */
  912. i__1 = *m + *n;
  913. if (*lwork < f2cmax(i__1,6)) {
  914. *info = -13;
  915. } else {
  916. *info = 0;
  917. }
  918. }
  919. /* #:( */
  920. if (*info != 0) {
  921. i__1 = -(*info);
  922. xerbla_("SGESVJ", &i__1, (ftnlen)6);
  923. return;
  924. }
  925. /* #:) Quick return for void matrix */
  926. if (*m == 0 || *n == 0) {
  927. return;
  928. }
  929. /* Set numerical parameters */
  930. /* The stopping criterion for Jacobi rotations is */
  931. /* max_{i<>j}|A(:,i)^T * A(:,j)|/(||A(:,i)||*||A(:,j)||) < CTOL*EPS */
  932. /* where EPS is the round-off and CTOL is defined as follows: */
  933. if (uctol) {
  934. /* ... user controlled */
  935. ctol = work[1];
  936. } else {
  937. /* ... default */
  938. if (lsvec || rsvec || applv) {
  939. ctol = sqrt((real) (*m));
  940. } else {
  941. ctol = (real) (*m);
  942. }
  943. }
  944. /* ... and the machine dependent parameters are */
  945. /* [!] (Make sure that SLAMCH() works properly on the target machine.) */
  946. epsln = slamch_("Epsilon");
  947. rooteps = sqrt(epsln);
  948. sfmin = slamch_("SafeMinimum");
  949. rootsfmin = sqrt(sfmin);
  950. small = sfmin / epsln;
  951. big = slamch_("Overflow");
  952. /* BIG = ONE / SFMIN */
  953. rootbig = 1.f / rootsfmin;
  954. large = big / sqrt((real) (*m * *n));
  955. bigtheta = 1.f / rooteps;
  956. tol = ctol * epsln;
  957. roottol = sqrt(tol);
  958. if ((real) (*m) * epsln >= 1.f) {
  959. *info = -4;
  960. i__1 = -(*info);
  961. xerbla_("SGESVJ", &i__1, (ftnlen)6);
  962. return;
  963. }
  964. /* Initialize the right singular vector matrix. */
  965. if (rsvec) {
  966. mvl = *n;
  967. slaset_("A", &mvl, n, &c_b17, &c_b18, &v[v_offset], ldv);
  968. } else if (applv) {
  969. mvl = *mv;
  970. }
  971. rsvec = rsvec || applv;
  972. /* Initialize SVA( 1:N ) = ( ||A e_i||_2, i = 1:N ) */
  973. /* (!) If necessary, scale A to protect the largest singular value */
  974. /* from overflow. It is possible that saving the largest singular */
  975. /* value destroys the information about the small ones. */
  976. /* This initial scaling is almost minimal in the sense that the */
  977. /* goal is to make sure that no column norm overflows, and that */
  978. /* SQRT(N)*max_i SVA(i) does not overflow. If INFinite entries */
  979. /* in A are detected, the procedure returns with INFO=-6. */
  980. skl = 1.f / sqrt((real) (*m) * (real) (*n));
  981. noscale = TRUE_;
  982. goscale = TRUE_;
  983. if (lower) {
  984. /* the input matrix is M-by-N lower triangular (trapezoidal) */
  985. i__1 = *n;
  986. for (p = 1; p <= i__1; ++p) {
  987. aapp = 0.f;
  988. aaqq = 1.f;
  989. i__2 = *m - p + 1;
  990. slassq_(&i__2, &a[p + p * a_dim1], &c__1, &aapp, &aaqq);
  991. if (aapp > big) {
  992. *info = -6;
  993. i__2 = -(*info);
  994. xerbla_("SGESVJ", &i__2, (ftnlen)6);
  995. return;
  996. }
  997. aaqq = sqrt(aaqq);
  998. if (aapp < big / aaqq && noscale) {
  999. sva[p] = aapp * aaqq;
  1000. } else {
  1001. noscale = FALSE_;
  1002. sva[p] = aapp * (aaqq * skl);
  1003. if (goscale) {
  1004. goscale = FALSE_;
  1005. i__2 = p - 1;
  1006. for (q = 1; q <= i__2; ++q) {
  1007. sva[q] *= skl;
  1008. /* L1873: */
  1009. }
  1010. }
  1011. }
  1012. /* L1874: */
  1013. }
  1014. } else if (upper) {
  1015. /* the input matrix is M-by-N upper triangular (trapezoidal) */
  1016. i__1 = *n;
  1017. for (p = 1; p <= i__1; ++p) {
  1018. aapp = 0.f;
  1019. aaqq = 1.f;
  1020. slassq_(&p, &a[p * a_dim1 + 1], &c__1, &aapp, &aaqq);
  1021. if (aapp > big) {
  1022. *info = -6;
  1023. i__2 = -(*info);
  1024. xerbla_("SGESVJ", &i__2, (ftnlen)6);
  1025. return;
  1026. }
  1027. aaqq = sqrt(aaqq);
  1028. if (aapp < big / aaqq && noscale) {
  1029. sva[p] = aapp * aaqq;
  1030. } else {
  1031. noscale = FALSE_;
  1032. sva[p] = aapp * (aaqq * skl);
  1033. if (goscale) {
  1034. goscale = FALSE_;
  1035. i__2 = p - 1;
  1036. for (q = 1; q <= i__2; ++q) {
  1037. sva[q] *= skl;
  1038. /* L2873: */
  1039. }
  1040. }
  1041. }
  1042. /* L2874: */
  1043. }
  1044. } else {
  1045. /* the input matrix is M-by-N general dense */
  1046. i__1 = *n;
  1047. for (p = 1; p <= i__1; ++p) {
  1048. aapp = 0.f;
  1049. aaqq = 1.f;
  1050. slassq_(m, &a[p * a_dim1 + 1], &c__1, &aapp, &aaqq);
  1051. if (aapp > big) {
  1052. *info = -6;
  1053. i__2 = -(*info);
  1054. xerbla_("SGESVJ", &i__2, (ftnlen)6);
  1055. return;
  1056. }
  1057. aaqq = sqrt(aaqq);
  1058. if (aapp < big / aaqq && noscale) {
  1059. sva[p] = aapp * aaqq;
  1060. } else {
  1061. noscale = FALSE_;
  1062. sva[p] = aapp * (aaqq * skl);
  1063. if (goscale) {
  1064. goscale = FALSE_;
  1065. i__2 = p - 1;
  1066. for (q = 1; q <= i__2; ++q) {
  1067. sva[q] *= skl;
  1068. /* L3873: */
  1069. }
  1070. }
  1071. }
  1072. /* L3874: */
  1073. }
  1074. }
  1075. if (noscale) {
  1076. skl = 1.f;
  1077. }
  1078. /* Move the smaller part of the spectrum from the underflow threshold */
  1079. /* (!) Start by determining the position of the nonzero entries of the */
  1080. /* array SVA() relative to ( SFMIN, BIG ). */
  1081. aapp = 0.f;
  1082. aaqq = big;
  1083. i__1 = *n;
  1084. for (p = 1; p <= i__1; ++p) {
  1085. if (sva[p] != 0.f) {
  1086. /* Computing MIN */
  1087. r__1 = aaqq, r__2 = sva[p];
  1088. aaqq = f2cmin(r__1,r__2);
  1089. }
  1090. /* Computing MAX */
  1091. r__1 = aapp, r__2 = sva[p];
  1092. aapp = f2cmax(r__1,r__2);
  1093. /* L4781: */
  1094. }
  1095. /* #:) Quick return for zero matrix */
  1096. if (aapp == 0.f) {
  1097. if (lsvec) {
  1098. slaset_("G", m, n, &c_b17, &c_b18, &a[a_offset], lda);
  1099. }
  1100. work[1] = 1.f;
  1101. work[2] = 0.f;
  1102. work[3] = 0.f;
  1103. work[4] = 0.f;
  1104. work[5] = 0.f;
  1105. work[6] = 0.f;
  1106. return;
  1107. }
  1108. /* #:) Quick return for one-column matrix */
  1109. if (*n == 1) {
  1110. if (lsvec) {
  1111. slascl_("G", &c__0, &c__0, &sva[1], &skl, m, &c__1, &a[a_dim1 + 1]
  1112. , lda, &ierr);
  1113. }
  1114. work[1] = 1.f / skl;
  1115. if (sva[1] >= sfmin) {
  1116. work[2] = 1.f;
  1117. } else {
  1118. work[2] = 0.f;
  1119. }
  1120. work[3] = 0.f;
  1121. work[4] = 0.f;
  1122. work[5] = 0.f;
  1123. work[6] = 0.f;
  1124. return;
  1125. }
  1126. /* Protect small singular values from underflow, and try to */
  1127. /* avoid underflows/overflows in computing Jacobi rotations. */
  1128. sn = sqrt(sfmin / epsln);
  1129. temp1 = sqrt(big / (real) (*n));
  1130. if (aapp <= sn || aaqq >= temp1 || sn <= aaqq && aapp <= temp1) {
  1131. /* Computing MIN */
  1132. r__1 = big, r__2 = temp1 / aapp;
  1133. temp1 = f2cmin(r__1,r__2);
  1134. /* AAQQ = AAQQ*TEMP1 */
  1135. /* AAPP = AAPP*TEMP1 */
  1136. } else if (aaqq <= sn && aapp <= temp1) {
  1137. /* Computing MIN */
  1138. r__1 = sn / aaqq, r__2 = big / (aapp * sqrt((real) (*n)));
  1139. temp1 = f2cmin(r__1,r__2);
  1140. /* AAQQ = AAQQ*TEMP1 */
  1141. /* AAPP = AAPP*TEMP1 */
  1142. } else if (aaqq >= sn && aapp >= temp1) {
  1143. /* Computing MAX */
  1144. r__1 = sn / aaqq, r__2 = temp1 / aapp;
  1145. temp1 = f2cmax(r__1,r__2);
  1146. /* AAQQ = AAQQ*TEMP1 */
  1147. /* AAPP = AAPP*TEMP1 */
  1148. } else if (aaqq <= sn && aapp >= temp1) {
  1149. /* Computing MIN */
  1150. r__1 = sn / aaqq, r__2 = big / (sqrt((real) (*n)) * aapp);
  1151. temp1 = f2cmin(r__1,r__2);
  1152. /* AAQQ = AAQQ*TEMP1 */
  1153. /* AAPP = AAPP*TEMP1 */
  1154. } else {
  1155. temp1 = 1.f;
  1156. }
  1157. /* Scale, if necessary */
  1158. if (temp1 != 1.f) {
  1159. slascl_("G", &c__0, &c__0, &c_b18, &temp1, n, &c__1, &sva[1], n, &
  1160. ierr);
  1161. }
  1162. skl = temp1 * skl;
  1163. if (skl != 1.f) {
  1164. slascl_(joba, &c__0, &c__0, &c_b18, &skl, m, n, &a[a_offset], lda, &
  1165. ierr);
  1166. skl = 1.f / skl;
  1167. }
  1168. /* Row-cyclic Jacobi SVD algorithm with column pivoting */
  1169. emptsw = *n * (*n - 1) / 2;
  1170. notrot = 0;
  1171. fastr[0] = 0.f;
  1172. /* A is represented in factored form A = A * diag(WORK), where diag(WORK) */
  1173. /* is initialized to identity. WORK is updated during fast scaled */
  1174. /* rotations. */
  1175. i__1 = *n;
  1176. for (q = 1; q <= i__1; ++q) {
  1177. work[q] = 1.f;
  1178. /* L1868: */
  1179. }
  1180. swband = 3;
  1181. /* [TP] SWBAND is a tuning parameter [TP]. It is meaningful and effective */
  1182. /* if SGESVJ is used as a computational routine in the preconditioned */
  1183. /* Jacobi SVD algorithm SGESVJ. For sweeps i=1:SWBAND the procedure */
  1184. /* works on pivots inside a band-like region around the diagonal. */
  1185. /* The boundaries are determined dynamically, based on the number of */
  1186. /* pivots above a threshold. */
  1187. kbl = f2cmin(8,*n);
  1188. /* [TP] KBL is a tuning parameter that defines the tile size in the */
  1189. /* tiling of the p-q loops of pivot pairs. In general, an optimal */
  1190. /* value of KBL depends on the matrix dimensions and on the */
  1191. /* parameters of the computer's memory. */
  1192. nbl = *n / kbl;
  1193. if (nbl * kbl != *n) {
  1194. ++nbl;
  1195. }
  1196. /* Computing 2nd power */
  1197. i__1 = kbl;
  1198. blskip = i__1 * i__1;
  1199. /* [TP] BLKSKIP is a tuning parameter that depends on SWBAND and KBL. */
  1200. rowskip = f2cmin(5,kbl);
  1201. /* [TP] ROWSKIP is a tuning parameter. */
  1202. lkahead = 1;
  1203. /* [TP] LKAHEAD is a tuning parameter. */
  1204. /* Quasi block transformations, using the lower (upper) triangular */
  1205. /* structure of the input matrix. The quasi-block-cycling usually */
  1206. /* invokes cubic convergence. Big part of this cycle is done inside */
  1207. /* canonical subspaces of dimensions less than M. */
  1208. /* Computing MAX */
  1209. i__1 = 64, i__2 = kbl << 2;
  1210. if ((lower || upper) && *n > f2cmax(i__1,i__2)) {
  1211. /* [TP] The number of partition levels and the actual partition are */
  1212. /* tuning parameters. */
  1213. n4 = *n / 4;
  1214. n2 = *n / 2;
  1215. n34 = n4 * 3;
  1216. if (applv) {
  1217. q = 0;
  1218. } else {
  1219. q = 1;
  1220. }
  1221. if (lower) {
  1222. /* This works very well on lower triangular matrices, in particular */
  1223. /* in the framework of the preconditioned Jacobi SVD (xGEJSV). */
  1224. /* The idea is simple: */
  1225. /* [+ 0 0 0] Note that Jacobi transformations of [0 0] */
  1226. /* [+ + 0 0] [0 0] */
  1227. /* [+ + x 0] actually work on [x 0] [x 0] */
  1228. /* [+ + x x] [x x]. [x x] */
  1229. i__1 = *m - n34;
  1230. i__2 = *n - n34;
  1231. i__3 = *lwork - *n;
  1232. sgsvj0_(jobv, &i__1, &i__2, &a[n34 + 1 + (n34 + 1) * a_dim1], lda,
  1233. &work[n34 + 1], &sva[n34 + 1], &mvl, &v[n34 * q + 1 + (
  1234. n34 + 1) * v_dim1], ldv, &epsln, &sfmin, &tol, &c__2, &
  1235. work[*n + 1], &i__3, &ierr);
  1236. i__1 = *m - n2;
  1237. i__2 = n34 - n2;
  1238. i__3 = *lwork - *n;
  1239. sgsvj0_(jobv, &i__1, &i__2, &a[n2 + 1 + (n2 + 1) * a_dim1], lda, &
  1240. work[n2 + 1], &sva[n2 + 1], &mvl, &v[n2 * q + 1 + (n2 + 1)
  1241. * v_dim1], ldv, &epsln, &sfmin, &tol, &c__2, &work[*n +
  1242. 1], &i__3, &ierr);
  1243. i__1 = *m - n2;
  1244. i__2 = *n - n2;
  1245. i__3 = *lwork - *n;
  1246. sgsvj1_(jobv, &i__1, &i__2, &n4, &a[n2 + 1 + (n2 + 1) * a_dim1],
  1247. lda, &work[n2 + 1], &sva[n2 + 1], &mvl, &v[n2 * q + 1 + (
  1248. n2 + 1) * v_dim1], ldv, &epsln, &sfmin, &tol, &c__1, &
  1249. work[*n + 1], &i__3, &ierr);
  1250. i__1 = *m - n4;
  1251. i__2 = n2 - n4;
  1252. i__3 = *lwork - *n;
  1253. sgsvj0_(jobv, &i__1, &i__2, &a[n4 + 1 + (n4 + 1) * a_dim1], lda, &
  1254. work[n4 + 1], &sva[n4 + 1], &mvl, &v[n4 * q + 1 + (n4 + 1)
  1255. * v_dim1], ldv, &epsln, &sfmin, &tol, &c__1, &work[*n +
  1256. 1], &i__3, &ierr);
  1257. i__1 = *lwork - *n;
  1258. sgsvj0_(jobv, m, &n4, &a[a_offset], lda, &work[1], &sva[1], &mvl,
  1259. &v[v_offset], ldv, &epsln, &sfmin, &tol, &c__1, &work[*n
  1260. + 1], &i__1, &ierr);
  1261. i__1 = *lwork - *n;
  1262. sgsvj1_(jobv, m, &n2, &n4, &a[a_offset], lda, &work[1], &sva[1], &
  1263. mvl, &v[v_offset], ldv, &epsln, &sfmin, &tol, &c__1, &
  1264. work[*n + 1], &i__1, &ierr);
  1265. } else if (upper) {
  1266. i__1 = *lwork - *n;
  1267. sgsvj0_(jobv, &n4, &n4, &a[a_offset], lda, &work[1], &sva[1], &
  1268. mvl, &v[v_offset], ldv, &epsln, &sfmin, &tol, &c__2, &
  1269. work[*n + 1], &i__1, &ierr);
  1270. i__1 = *lwork - *n;
  1271. sgsvj0_(jobv, &n2, &n4, &a[(n4 + 1) * a_dim1 + 1], lda, &work[n4
  1272. + 1], &sva[n4 + 1], &mvl, &v[n4 * q + 1 + (n4 + 1) *
  1273. v_dim1], ldv, &epsln, &sfmin, &tol, &c__1, &work[*n + 1],
  1274. &i__1, &ierr);
  1275. i__1 = *lwork - *n;
  1276. sgsvj1_(jobv, &n2, &n2, &n4, &a[a_offset], lda, &work[1], &sva[1],
  1277. &mvl, &v[v_offset], ldv, &epsln, &sfmin, &tol, &c__1, &
  1278. work[*n + 1], &i__1, &ierr);
  1279. i__1 = n2 + n4;
  1280. i__2 = *lwork - *n;
  1281. sgsvj0_(jobv, &i__1, &n4, &a[(n2 + 1) * a_dim1 + 1], lda, &work[
  1282. n2 + 1], &sva[n2 + 1], &mvl, &v[n2 * q + 1 + (n2 + 1) *
  1283. v_dim1], ldv, &epsln, &sfmin, &tol, &c__1, &work[*n + 1],
  1284. &i__2, &ierr);
  1285. }
  1286. }
  1287. for (i__ = 1; i__ <= 30; ++i__) {
  1288. mxaapq = 0.f;
  1289. mxsinj = 0.f;
  1290. iswrot = 0;
  1291. notrot = 0;
  1292. pskipped = 0;
  1293. /* Each sweep is unrolled using KBL-by-KBL tiles over the pivot pairs */
  1294. /* 1 <= p < q <= N. This is the first step toward a blocked implementation */
  1295. /* of the rotations. New implementation, based on block transformations, */
  1296. /* is under development. */
  1297. i__1 = nbl;
  1298. for (ibr = 1; ibr <= i__1; ++ibr) {
  1299. igl = (ibr - 1) * kbl + 1;
  1300. /* Computing MIN */
  1301. i__3 = lkahead, i__4 = nbl - ibr;
  1302. i__2 = f2cmin(i__3,i__4);
  1303. for (ir1 = 0; ir1 <= i__2; ++ir1) {
  1304. igl += ir1 * kbl;
  1305. /* Computing MIN */
  1306. i__4 = igl + kbl - 1, i__5 = *n - 1;
  1307. i__3 = f2cmin(i__4,i__5);
  1308. for (p = igl; p <= i__3; ++p) {
  1309. i__4 = *n - p + 1;
  1310. q = isamax_(&i__4, &sva[p], &c__1) + p - 1;
  1311. if (p != q) {
  1312. sswap_(m, &a[p * a_dim1 + 1], &c__1, &a[q * a_dim1 +
  1313. 1], &c__1);
  1314. if (rsvec) {
  1315. sswap_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q *
  1316. v_dim1 + 1], &c__1);
  1317. }
  1318. temp1 = sva[p];
  1319. sva[p] = sva[q];
  1320. sva[q] = temp1;
  1321. temp1 = work[p];
  1322. work[p] = work[q];
  1323. work[q] = temp1;
  1324. }
  1325. if (ir1 == 0) {
  1326. /* Column norms are periodically updated by explicit */
  1327. /* norm computation. */
  1328. /* Caveat: */
  1329. /* Unfortunately, some BLAS implementations compute SNRM2(M,A(1,p),1) */
  1330. /* as SQRT(SDOT(M,A(1,p),1,A(1,p),1)), which may cause the result to */
  1331. /* overflow for ||A(:,p)||_2 > SQRT(overflow_threshold), and to */
  1332. /* underflow for ||A(:,p)||_2 < SQRT(underflow_threshold). */
  1333. /* Hence, SNRM2 cannot be trusted, not even in the case when */
  1334. /* the true norm is far from the under(over)flow boundaries. */
  1335. /* If properly implemented SNRM2 is available, the IF-THEN-ELSE */
  1336. /* below should read "AAPP = SNRM2( M, A(1,p), 1 ) * WORK(p)". */
  1337. if (sva[p] < rootbig && sva[p] > rootsfmin) {
  1338. sva[p] = snrm2_(m, &a[p * a_dim1 + 1], &c__1) *
  1339. work[p];
  1340. } else {
  1341. temp1 = 0.f;
  1342. aapp = 1.f;
  1343. slassq_(m, &a[p * a_dim1 + 1], &c__1, &temp1, &
  1344. aapp);
  1345. sva[p] = temp1 * sqrt(aapp) * work[p];
  1346. }
  1347. aapp = sva[p];
  1348. } else {
  1349. aapp = sva[p];
  1350. }
  1351. if (aapp > 0.f) {
  1352. pskipped = 0;
  1353. /* Computing MIN */
  1354. i__5 = igl + kbl - 1;
  1355. i__4 = f2cmin(i__5,*n);
  1356. for (q = p + 1; q <= i__4; ++q) {
  1357. aaqq = sva[q];
  1358. if (aaqq > 0.f) {
  1359. aapp0 = aapp;
  1360. if (aaqq >= 1.f) {
  1361. rotok = small * aapp <= aaqq;
  1362. if (aapp < big / aaqq) {
  1363. aapq = sdot_(m, &a[p * a_dim1 + 1], &
  1364. c__1, &a[q * a_dim1 + 1], &
  1365. c__1) * work[p] * work[q] /
  1366. aaqq / aapp;
  1367. } else {
  1368. scopy_(m, &a[p * a_dim1 + 1], &c__1, &
  1369. work[*n + 1], &c__1);
  1370. slascl_("G", &c__0, &c__0, &aapp, &
  1371. work[p], m, &c__1, &work[*n +
  1372. 1], lda, &ierr);
  1373. aapq = sdot_(m, &work[*n + 1], &c__1,
  1374. &a[q * a_dim1 + 1], &c__1) *
  1375. work[q] / aaqq;
  1376. }
  1377. } else {
  1378. rotok = aapp <= aaqq / small;
  1379. if (aapp > small / aaqq) {
  1380. aapq = sdot_(m, &a[p * a_dim1 + 1], &
  1381. c__1, &a[q * a_dim1 + 1], &
  1382. c__1) * work[p] * work[q] /
  1383. aaqq / aapp;
  1384. } else {
  1385. scopy_(m, &a[q * a_dim1 + 1], &c__1, &
  1386. work[*n + 1], &c__1);
  1387. slascl_("G", &c__0, &c__0, &aaqq, &
  1388. work[q], m, &c__1, &work[*n +
  1389. 1], lda, &ierr);
  1390. aapq = sdot_(m, &work[*n + 1], &c__1,
  1391. &a[p * a_dim1 + 1], &c__1) *
  1392. work[p] / aapp;
  1393. }
  1394. }
  1395. /* Computing MAX */
  1396. r__1 = mxaapq, r__2 = abs(aapq);
  1397. mxaapq = f2cmax(r__1,r__2);
  1398. /* TO rotate or NOT to rotate, THAT is the question ... */
  1399. if (abs(aapq) > tol) {
  1400. /* [RTD] ROTATED = ROTATED + ONE */
  1401. if (ir1 == 0) {
  1402. notrot = 0;
  1403. pskipped = 0;
  1404. ++iswrot;
  1405. }
  1406. if (rotok) {
  1407. aqoap = aaqq / aapp;
  1408. apoaq = aapp / aaqq;
  1409. theta = (r__1 = aqoap - apoaq, abs(
  1410. r__1)) * -.5f / aapq;
  1411. if (abs(theta) > bigtheta) {
  1412. t = .5f / theta;
  1413. fastr[2] = t * work[p] / work[q];
  1414. fastr[3] = -t * work[q] / work[p];
  1415. srotm_(m, &a[p * a_dim1 + 1], &
  1416. c__1, &a[q * a_dim1 + 1],
  1417. &c__1, fastr);
  1418. if (rsvec) {
  1419. srotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q *
  1420. v_dim1 + 1], &c__1, fastr);
  1421. }
  1422. /* Computing MAX */
  1423. r__1 = 0.f, r__2 = t * apoaq *
  1424. aapq + 1.f;
  1425. sva[q] = aaqq * sqrt((f2cmax(r__1,
  1426. r__2)));
  1427. /* Computing MAX */
  1428. r__1 = 0.f, r__2 = 1.f - t *
  1429. aqoap * aapq;
  1430. aapp *= sqrt((f2cmax(r__1,r__2)));
  1431. /* Computing MAX */
  1432. r__1 = mxsinj, r__2 = abs(t);
  1433. mxsinj = f2cmax(r__1,r__2);
  1434. } else {
  1435. thsign = -r_sign(&c_b18, &aapq);
  1436. t = 1.f / (theta + thsign * sqrt(
  1437. theta * theta + 1.f));
  1438. cs = sqrt(1.f / (t * t + 1.f));
  1439. sn = t * cs;
  1440. /* Computing MAX */
  1441. r__1 = mxsinj, r__2 = abs(sn);
  1442. mxsinj = f2cmax(r__1,r__2);
  1443. /* Computing MAX */
  1444. r__1 = 0.f, r__2 = t * apoaq *
  1445. aapq + 1.f;
  1446. sva[q] = aaqq * sqrt((f2cmax(r__1,
  1447. r__2)));
  1448. /* Computing MAX */
  1449. r__1 = 0.f, r__2 = 1.f - t *
  1450. aqoap * aapq;
  1451. aapp *= sqrt((f2cmax(r__1,r__2)));
  1452. apoaq = work[p] / work[q];
  1453. aqoap = work[q] / work[p];
  1454. if (work[p] >= 1.f) {
  1455. if (work[q] >= 1.f) {
  1456. fastr[2] = t * apoaq;
  1457. fastr[3] = -t * aqoap;
  1458. work[p] *= cs;
  1459. work[q] *= cs;
  1460. srotm_(m, &a[p * a_dim1 + 1], &c__1, &a[q *
  1461. a_dim1 + 1], &c__1, fastr);
  1462. if (rsvec) {
  1463. srotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[
  1464. q * v_dim1 + 1], &c__1, fastr);
  1465. }
  1466. } else {
  1467. r__1 = -t * aqoap;
  1468. saxpy_(m, &r__1, &a[q * a_dim1 + 1], &c__1, &a[
  1469. p * a_dim1 + 1], &c__1);
  1470. r__1 = cs * sn * apoaq;
  1471. saxpy_(m, &r__1, &a[p * a_dim1 + 1], &c__1, &a[
  1472. q * a_dim1 + 1], &c__1);
  1473. work[p] *= cs;
  1474. work[q] /= cs;
  1475. if (rsvec) {
  1476. r__1 = -t * aqoap;
  1477. saxpy_(&mvl, &r__1, &v[q * v_dim1 + 1], &
  1478. c__1, &v[p * v_dim1 + 1], &c__1);
  1479. r__1 = cs * sn * apoaq;
  1480. saxpy_(&mvl, &r__1, &v[p * v_dim1 + 1], &
  1481. c__1, &v[q * v_dim1 + 1], &c__1);
  1482. }
  1483. }
  1484. } else {
  1485. if (work[q] >= 1.f) {
  1486. r__1 = t * apoaq;
  1487. saxpy_(m, &r__1, &a[p * a_dim1 + 1], &c__1, &a[
  1488. q * a_dim1 + 1], &c__1);
  1489. r__1 = -cs * sn * aqoap;
  1490. saxpy_(m, &r__1, &a[q * a_dim1 + 1], &c__1, &a[
  1491. p * a_dim1 + 1], &c__1);
  1492. work[p] /= cs;
  1493. work[q] *= cs;
  1494. if (rsvec) {
  1495. r__1 = t * apoaq;
  1496. saxpy_(&mvl, &r__1, &v[p * v_dim1 + 1], &
  1497. c__1, &v[q * v_dim1 + 1], &c__1);
  1498. r__1 = -cs * sn * aqoap;
  1499. saxpy_(&mvl, &r__1, &v[q * v_dim1 + 1], &
  1500. c__1, &v[p * v_dim1 + 1], &c__1);
  1501. }
  1502. } else {
  1503. if (work[p] >= work[q]) {
  1504. r__1 = -t * aqoap;
  1505. saxpy_(m, &r__1, &a[q * a_dim1 + 1], &c__1,
  1506. &a[p * a_dim1 + 1], &c__1);
  1507. r__1 = cs * sn * apoaq;
  1508. saxpy_(m, &r__1, &a[p * a_dim1 + 1], &c__1,
  1509. &a[q * a_dim1 + 1], &c__1);
  1510. work[p] *= cs;
  1511. work[q] /= cs;
  1512. if (rsvec) {
  1513. r__1 = -t * aqoap;
  1514. saxpy_(&mvl, &r__1, &v[q * v_dim1 + 1],
  1515. &c__1, &v[p * v_dim1 + 1], &
  1516. c__1);
  1517. r__1 = cs * sn * apoaq;
  1518. saxpy_(&mvl, &r__1, &v[p * v_dim1 + 1],
  1519. &c__1, &v[q * v_dim1 + 1], &
  1520. c__1);
  1521. }
  1522. } else {
  1523. r__1 = t * apoaq;
  1524. saxpy_(m, &r__1, &a[p * a_dim1 + 1], &c__1,
  1525. &a[q * a_dim1 + 1], &c__1);
  1526. r__1 = -cs * sn * aqoap;
  1527. saxpy_(m, &r__1, &a[q * a_dim1 + 1], &c__1,
  1528. &a[p * a_dim1 + 1], &c__1);
  1529. work[p] /= cs;
  1530. work[q] *= cs;
  1531. if (rsvec) {
  1532. r__1 = t * apoaq;
  1533. saxpy_(&mvl, &r__1, &v[p * v_dim1 + 1],
  1534. &c__1, &v[q * v_dim1 + 1], &
  1535. c__1);
  1536. r__1 = -cs * sn * aqoap;
  1537. saxpy_(&mvl, &r__1, &v[q * v_dim1 + 1],
  1538. &c__1, &v[p * v_dim1 + 1], &
  1539. c__1);
  1540. }
  1541. }
  1542. }
  1543. }
  1544. }
  1545. } else {
  1546. scopy_(m, &a[p * a_dim1 + 1], &c__1, &
  1547. work[*n + 1], &c__1);
  1548. slascl_("G", &c__0, &c__0, &aapp, &
  1549. c_b18, m, &c__1, &work[*n + 1]
  1550. , lda, &ierr);
  1551. slascl_("G", &c__0, &c__0, &aaqq, &
  1552. c_b18, m, &c__1, &a[q *
  1553. a_dim1 + 1], lda, &ierr);
  1554. temp1 = -aapq * work[p] / work[q];
  1555. saxpy_(m, &temp1, &work[*n + 1], &
  1556. c__1, &a[q * a_dim1 + 1], &
  1557. c__1);
  1558. slascl_("G", &c__0, &c__0, &c_b18, &
  1559. aaqq, m, &c__1, &a[q * a_dim1
  1560. + 1], lda, &ierr);
  1561. /* Computing MAX */
  1562. r__1 = 0.f, r__2 = 1.f - aapq * aapq;
  1563. sva[q] = aaqq * sqrt((f2cmax(r__1,r__2)))
  1564. ;
  1565. mxsinj = f2cmax(mxsinj,sfmin);
  1566. }
  1567. /* END IF ROTOK THEN ... ELSE */
  1568. /* In the case of cancellation in updating SVA(q), SVA(p) */
  1569. /* recompute SVA(q), SVA(p). */
  1570. /* Computing 2nd power */
  1571. r__1 = sva[q] / aaqq;
  1572. if (r__1 * r__1 <= rooteps) {
  1573. if (aaqq < rootbig && aaqq >
  1574. rootsfmin) {
  1575. sva[q] = snrm2_(m, &a[q * a_dim1
  1576. + 1], &c__1) * work[q];
  1577. } else {
  1578. t = 0.f;
  1579. aaqq = 1.f;
  1580. slassq_(m, &a[q * a_dim1 + 1], &
  1581. c__1, &t, &aaqq);
  1582. sva[q] = t * sqrt(aaqq) * work[q];
  1583. }
  1584. }
  1585. if (aapp / aapp0 <= rooteps) {
  1586. if (aapp < rootbig && aapp >
  1587. rootsfmin) {
  1588. aapp = snrm2_(m, &a[p * a_dim1 +
  1589. 1], &c__1) * work[p];
  1590. } else {
  1591. t = 0.f;
  1592. aapp = 1.f;
  1593. slassq_(m, &a[p * a_dim1 + 1], &
  1594. c__1, &t, &aapp);
  1595. aapp = t * sqrt(aapp) * work[p];
  1596. }
  1597. sva[p] = aapp;
  1598. }
  1599. } else {
  1600. /* A(:,p) and A(:,q) already numerically orthogonal */
  1601. if (ir1 == 0) {
  1602. ++notrot;
  1603. }
  1604. /* [RTD] SKIPPED = SKIPPED + 1 */
  1605. ++pskipped;
  1606. }
  1607. } else {
  1608. /* A(:,q) is zero column */
  1609. if (ir1 == 0) {
  1610. ++notrot;
  1611. }
  1612. ++pskipped;
  1613. }
  1614. if (i__ <= swband && pskipped > rowskip) {
  1615. if (ir1 == 0) {
  1616. aapp = -aapp;
  1617. }
  1618. notrot = 0;
  1619. goto L2103;
  1620. }
  1621. /* L2002: */
  1622. }
  1623. /* END q-LOOP */
  1624. L2103:
  1625. /* bailed out of q-loop */
  1626. sva[p] = aapp;
  1627. } else {
  1628. sva[p] = aapp;
  1629. if (ir1 == 0 && aapp == 0.f) {
  1630. /* Computing MIN */
  1631. i__4 = igl + kbl - 1;
  1632. notrot = notrot + f2cmin(i__4,*n) - p;
  1633. }
  1634. }
  1635. /* L2001: */
  1636. }
  1637. /* end of the p-loop */
  1638. /* end of doing the block ( ibr, ibr ) */
  1639. /* L1002: */
  1640. }
  1641. /* end of ir1-loop */
  1642. /* ... go to the off diagonal blocks */
  1643. igl = (ibr - 1) * kbl + 1;
  1644. i__2 = nbl;
  1645. for (jbc = ibr + 1; jbc <= i__2; ++jbc) {
  1646. jgl = (jbc - 1) * kbl + 1;
  1647. /* doing the block at ( ibr, jbc ) */
  1648. ijblsk = 0;
  1649. /* Computing MIN */
  1650. i__4 = igl + kbl - 1;
  1651. i__3 = f2cmin(i__4,*n);
  1652. for (p = igl; p <= i__3; ++p) {
  1653. aapp = sva[p];
  1654. if (aapp > 0.f) {
  1655. pskipped = 0;
  1656. /* Computing MIN */
  1657. i__5 = jgl + kbl - 1;
  1658. i__4 = f2cmin(i__5,*n);
  1659. for (q = jgl; q <= i__4; ++q) {
  1660. aaqq = sva[q];
  1661. if (aaqq > 0.f) {
  1662. aapp0 = aapp;
  1663. /* Safe Gram matrix computation */
  1664. if (aaqq >= 1.f) {
  1665. if (aapp >= aaqq) {
  1666. rotok = small * aapp <= aaqq;
  1667. } else {
  1668. rotok = small * aaqq <= aapp;
  1669. }
  1670. if (aapp < big / aaqq) {
  1671. aapq = sdot_(m, &a[p * a_dim1 + 1], &
  1672. c__1, &a[q * a_dim1 + 1], &
  1673. c__1) * work[p] * work[q] /
  1674. aaqq / aapp;
  1675. } else {
  1676. scopy_(m, &a[p * a_dim1 + 1], &c__1, &
  1677. work[*n + 1], &c__1);
  1678. slascl_("G", &c__0, &c__0, &aapp, &
  1679. work[p], m, &c__1, &work[*n +
  1680. 1], lda, &ierr);
  1681. aapq = sdot_(m, &work[*n + 1], &c__1,
  1682. &a[q * a_dim1 + 1], &c__1) *
  1683. work[q] / aaqq;
  1684. }
  1685. } else {
  1686. if (aapp >= aaqq) {
  1687. rotok = aapp <= aaqq / small;
  1688. } else {
  1689. rotok = aaqq <= aapp / small;
  1690. }
  1691. if (aapp > small / aaqq) {
  1692. aapq = sdot_(m, &a[p * a_dim1 + 1], &
  1693. c__1, &a[q * a_dim1 + 1], &
  1694. c__1) * work[p] * work[q] /
  1695. aaqq / aapp;
  1696. } else {
  1697. scopy_(m, &a[q * a_dim1 + 1], &c__1, &
  1698. work[*n + 1], &c__1);
  1699. slascl_("G", &c__0, &c__0, &aaqq, &
  1700. work[q], m, &c__1, &work[*n +
  1701. 1], lda, &ierr);
  1702. aapq = sdot_(m, &work[*n + 1], &c__1,
  1703. &a[p * a_dim1 + 1], &c__1) *
  1704. work[p] / aapp;
  1705. }
  1706. }
  1707. /* Computing MAX */
  1708. r__1 = mxaapq, r__2 = abs(aapq);
  1709. mxaapq = f2cmax(r__1,r__2);
  1710. /* TO rotate or NOT to rotate, THAT is the question ... */
  1711. if (abs(aapq) > tol) {
  1712. notrot = 0;
  1713. /* [RTD] ROTATED = ROTATED + 1 */
  1714. pskipped = 0;
  1715. ++iswrot;
  1716. if (rotok) {
  1717. aqoap = aaqq / aapp;
  1718. apoaq = aapp / aaqq;
  1719. theta = (r__1 = aqoap - apoaq, abs(
  1720. r__1)) * -.5f / aapq;
  1721. if (aaqq > aapp0) {
  1722. theta = -theta;
  1723. }
  1724. if (abs(theta) > bigtheta) {
  1725. t = .5f / theta;
  1726. fastr[2] = t * work[p] / work[q];
  1727. fastr[3] = -t * work[q] / work[p];
  1728. srotm_(m, &a[p * a_dim1 + 1], &
  1729. c__1, &a[q * a_dim1 + 1],
  1730. &c__1, fastr);
  1731. if (rsvec) {
  1732. srotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q *
  1733. v_dim1 + 1], &c__1, fastr);
  1734. }
  1735. /* Computing MAX */
  1736. r__1 = 0.f, r__2 = t * apoaq *
  1737. aapq + 1.f;
  1738. sva[q] = aaqq * sqrt((f2cmax(r__1,
  1739. r__2)));
  1740. /* Computing MAX */
  1741. r__1 = 0.f, r__2 = 1.f - t *
  1742. aqoap * aapq;
  1743. aapp *= sqrt((f2cmax(r__1,r__2)));
  1744. /* Computing MAX */
  1745. r__1 = mxsinj, r__2 = abs(t);
  1746. mxsinj = f2cmax(r__1,r__2);
  1747. } else {
  1748. thsign = -r_sign(&c_b18, &aapq);
  1749. if (aaqq > aapp0) {
  1750. thsign = -thsign;
  1751. }
  1752. t = 1.f / (theta + thsign * sqrt(
  1753. theta * theta + 1.f));
  1754. cs = sqrt(1.f / (t * t + 1.f));
  1755. sn = t * cs;
  1756. /* Computing MAX */
  1757. r__1 = mxsinj, r__2 = abs(sn);
  1758. mxsinj = f2cmax(r__1,r__2);
  1759. /* Computing MAX */
  1760. r__1 = 0.f, r__2 = t * apoaq *
  1761. aapq + 1.f;
  1762. sva[q] = aaqq * sqrt((f2cmax(r__1,
  1763. r__2)));
  1764. /* Computing MAX */
  1765. r__1 = 0.f, r__2 = 1.f - t *
  1766. aqoap * aapq;
  1767. aapp *= sqrt((f2cmax(r__1,r__2)));
  1768. apoaq = work[p] / work[q];
  1769. aqoap = work[q] / work[p];
  1770. if (work[p] >= 1.f) {
  1771. if (work[q] >= 1.f) {
  1772. fastr[2] = t * apoaq;
  1773. fastr[3] = -t * aqoap;
  1774. work[p] *= cs;
  1775. work[q] *= cs;
  1776. srotm_(m, &a[p * a_dim1 + 1], &c__1, &a[q *
  1777. a_dim1 + 1], &c__1, fastr);
  1778. if (rsvec) {
  1779. srotm_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[
  1780. q * v_dim1 + 1], &c__1, fastr);
  1781. }
  1782. } else {
  1783. r__1 = -t * aqoap;
  1784. saxpy_(m, &r__1, &a[q * a_dim1 + 1], &c__1, &a[
  1785. p * a_dim1 + 1], &c__1);
  1786. r__1 = cs * sn * apoaq;
  1787. saxpy_(m, &r__1, &a[p * a_dim1 + 1], &c__1, &a[
  1788. q * a_dim1 + 1], &c__1);
  1789. if (rsvec) {
  1790. r__1 = -t * aqoap;
  1791. saxpy_(&mvl, &r__1, &v[q * v_dim1 + 1], &
  1792. c__1, &v[p * v_dim1 + 1], &c__1);
  1793. r__1 = cs * sn * apoaq;
  1794. saxpy_(&mvl, &r__1, &v[p * v_dim1 + 1], &
  1795. c__1, &v[q * v_dim1 + 1], &c__1);
  1796. }
  1797. work[p] *= cs;
  1798. work[q] /= cs;
  1799. }
  1800. } else {
  1801. if (work[q] >= 1.f) {
  1802. r__1 = t * apoaq;
  1803. saxpy_(m, &r__1, &a[p * a_dim1 + 1], &c__1, &a[
  1804. q * a_dim1 + 1], &c__1);
  1805. r__1 = -cs * sn * aqoap;
  1806. saxpy_(m, &r__1, &a[q * a_dim1 + 1], &c__1, &a[
  1807. p * a_dim1 + 1], &c__1);
  1808. if (rsvec) {
  1809. r__1 = t * apoaq;
  1810. saxpy_(&mvl, &r__1, &v[p * v_dim1 + 1], &
  1811. c__1, &v[q * v_dim1 + 1], &c__1);
  1812. r__1 = -cs * sn * aqoap;
  1813. saxpy_(&mvl, &r__1, &v[q * v_dim1 + 1], &
  1814. c__1, &v[p * v_dim1 + 1], &c__1);
  1815. }
  1816. work[p] /= cs;
  1817. work[q] *= cs;
  1818. } else {
  1819. if (work[p] >= work[q]) {
  1820. r__1 = -t * aqoap;
  1821. saxpy_(m, &r__1, &a[q * a_dim1 + 1], &c__1,
  1822. &a[p * a_dim1 + 1], &c__1);
  1823. r__1 = cs * sn * apoaq;
  1824. saxpy_(m, &r__1, &a[p * a_dim1 + 1], &c__1,
  1825. &a[q * a_dim1 + 1], &c__1);
  1826. work[p] *= cs;
  1827. work[q] /= cs;
  1828. if (rsvec) {
  1829. r__1 = -t * aqoap;
  1830. saxpy_(&mvl, &r__1, &v[q * v_dim1 + 1],
  1831. &c__1, &v[p * v_dim1 + 1], &
  1832. c__1);
  1833. r__1 = cs * sn * apoaq;
  1834. saxpy_(&mvl, &r__1, &v[p * v_dim1 + 1],
  1835. &c__1, &v[q * v_dim1 + 1], &
  1836. c__1);
  1837. }
  1838. } else {
  1839. r__1 = t * apoaq;
  1840. saxpy_(m, &r__1, &a[p * a_dim1 + 1], &c__1,
  1841. &a[q * a_dim1 + 1], &c__1);
  1842. r__1 = -cs * sn * aqoap;
  1843. saxpy_(m, &r__1, &a[q * a_dim1 + 1], &c__1,
  1844. &a[p * a_dim1 + 1], &c__1);
  1845. work[p] /= cs;
  1846. work[q] *= cs;
  1847. if (rsvec) {
  1848. r__1 = t * apoaq;
  1849. saxpy_(&mvl, &r__1, &v[p * v_dim1 + 1],
  1850. &c__1, &v[q * v_dim1 + 1], &
  1851. c__1);
  1852. r__1 = -cs * sn * aqoap;
  1853. saxpy_(&mvl, &r__1, &v[q * v_dim1 + 1],
  1854. &c__1, &v[p * v_dim1 + 1], &
  1855. c__1);
  1856. }
  1857. }
  1858. }
  1859. }
  1860. }
  1861. } else {
  1862. if (aapp > aaqq) {
  1863. scopy_(m, &a[p * a_dim1 + 1], &
  1864. c__1, &work[*n + 1], &
  1865. c__1);
  1866. slascl_("G", &c__0, &c__0, &aapp,
  1867. &c_b18, m, &c__1, &work[*
  1868. n + 1], lda, &ierr);
  1869. slascl_("G", &c__0, &c__0, &aaqq,
  1870. &c_b18, m, &c__1, &a[q *
  1871. a_dim1 + 1], lda, &ierr);
  1872. temp1 = -aapq * work[p] / work[q];
  1873. saxpy_(m, &temp1, &work[*n + 1], &
  1874. c__1, &a[q * a_dim1 + 1],
  1875. &c__1);
  1876. slascl_("G", &c__0, &c__0, &c_b18,
  1877. &aaqq, m, &c__1, &a[q *
  1878. a_dim1 + 1], lda, &ierr);
  1879. /* Computing MAX */
  1880. r__1 = 0.f, r__2 = 1.f - aapq *
  1881. aapq;
  1882. sva[q] = aaqq * sqrt((f2cmax(r__1,
  1883. r__2)));
  1884. mxsinj = f2cmax(mxsinj,sfmin);
  1885. } else {
  1886. scopy_(m, &a[q * a_dim1 + 1], &
  1887. c__1, &work[*n + 1], &
  1888. c__1);
  1889. slascl_("G", &c__0, &c__0, &aaqq,
  1890. &c_b18, m, &c__1, &work[*
  1891. n + 1], lda, &ierr);
  1892. slascl_("G", &c__0, &c__0, &aapp,
  1893. &c_b18, m, &c__1, &a[p *
  1894. a_dim1 + 1], lda, &ierr);
  1895. temp1 = -aapq * work[q] / work[p];
  1896. saxpy_(m, &temp1, &work[*n + 1], &
  1897. c__1, &a[p * a_dim1 + 1],
  1898. &c__1);
  1899. slascl_("G", &c__0, &c__0, &c_b18,
  1900. &aapp, m, &c__1, &a[p *
  1901. a_dim1 + 1], lda, &ierr);
  1902. /* Computing MAX */
  1903. r__1 = 0.f, r__2 = 1.f - aapq *
  1904. aapq;
  1905. sva[p] = aapp * sqrt((f2cmax(r__1,
  1906. r__2)));
  1907. mxsinj = f2cmax(mxsinj,sfmin);
  1908. }
  1909. }
  1910. /* END IF ROTOK THEN ... ELSE */
  1911. /* In the case of cancellation in updating SVA(q) */
  1912. /* Computing 2nd power */
  1913. r__1 = sva[q] / aaqq;
  1914. if (r__1 * r__1 <= rooteps) {
  1915. if (aaqq < rootbig && aaqq >
  1916. rootsfmin) {
  1917. sva[q] = snrm2_(m, &a[q * a_dim1
  1918. + 1], &c__1) * work[q];
  1919. } else {
  1920. t = 0.f;
  1921. aaqq = 1.f;
  1922. slassq_(m, &a[q * a_dim1 + 1], &
  1923. c__1, &t, &aaqq);
  1924. sva[q] = t * sqrt(aaqq) * work[q];
  1925. }
  1926. }
  1927. /* Computing 2nd power */
  1928. r__1 = aapp / aapp0;
  1929. if (r__1 * r__1 <= rooteps) {
  1930. if (aapp < rootbig && aapp >
  1931. rootsfmin) {
  1932. aapp = snrm2_(m, &a[p * a_dim1 +
  1933. 1], &c__1) * work[p];
  1934. } else {
  1935. t = 0.f;
  1936. aapp = 1.f;
  1937. slassq_(m, &a[p * a_dim1 + 1], &
  1938. c__1, &t, &aapp);
  1939. aapp = t * sqrt(aapp) * work[p];
  1940. }
  1941. sva[p] = aapp;
  1942. }
  1943. /* end of OK rotation */
  1944. } else {
  1945. ++notrot;
  1946. /* [RTD] SKIPPED = SKIPPED + 1 */
  1947. ++pskipped;
  1948. ++ijblsk;
  1949. }
  1950. } else {
  1951. ++notrot;
  1952. ++pskipped;
  1953. ++ijblsk;
  1954. }
  1955. if (i__ <= swband && ijblsk >= blskip) {
  1956. sva[p] = aapp;
  1957. notrot = 0;
  1958. goto L2011;
  1959. }
  1960. if (i__ <= swband && pskipped > rowskip) {
  1961. aapp = -aapp;
  1962. notrot = 0;
  1963. goto L2203;
  1964. }
  1965. /* L2200: */
  1966. }
  1967. /* end of the q-loop */
  1968. L2203:
  1969. sva[p] = aapp;
  1970. } else {
  1971. if (aapp == 0.f) {
  1972. /* Computing MIN */
  1973. i__4 = jgl + kbl - 1;
  1974. notrot = notrot + f2cmin(i__4,*n) - jgl + 1;
  1975. }
  1976. if (aapp < 0.f) {
  1977. notrot = 0;
  1978. }
  1979. }
  1980. /* L2100: */
  1981. }
  1982. /* end of the p-loop */
  1983. /* L2010: */
  1984. }
  1985. /* end of the jbc-loop */
  1986. L2011:
  1987. /* 2011 bailed out of the jbc-loop */
  1988. /* Computing MIN */
  1989. i__3 = igl + kbl - 1;
  1990. i__2 = f2cmin(i__3,*n);
  1991. for (p = igl; p <= i__2; ++p) {
  1992. sva[p] = (r__1 = sva[p], abs(r__1));
  1993. /* L2012: */
  1994. }
  1995. /* ** */
  1996. /* L2000: */
  1997. }
  1998. /* 2000 :: end of the ibr-loop */
  1999. if (sva[*n] < rootbig && sva[*n] > rootsfmin) {
  2000. sva[*n] = snrm2_(m, &a[*n * a_dim1 + 1], &c__1) * work[*n];
  2001. } else {
  2002. t = 0.f;
  2003. aapp = 1.f;
  2004. slassq_(m, &a[*n * a_dim1 + 1], &c__1, &t, &aapp);
  2005. sva[*n] = t * sqrt(aapp) * work[*n];
  2006. }
  2007. /* Additional steering devices */
  2008. if (i__ < swband && (mxaapq <= roottol || iswrot <= *n)) {
  2009. swband = i__;
  2010. }
  2011. if (i__ > swband + 1 && mxaapq < sqrt((real) (*n)) * tol && (real) (*
  2012. n) * mxaapq * mxsinj < tol) {
  2013. goto L1994;
  2014. }
  2015. if (notrot >= emptsw) {
  2016. goto L1994;
  2017. }
  2018. /* L1993: */
  2019. }
  2020. /* end i=1:NSWEEP loop */
  2021. /* #:( Reaching this point means that the procedure has not converged. */
  2022. *info = 29;
  2023. goto L1995;
  2024. L1994:
  2025. /* #:) Reaching this point means numerical convergence after the i-th */
  2026. /* sweep. */
  2027. *info = 0;
  2028. /* #:) INFO = 0 confirms successful iterations. */
  2029. L1995:
  2030. /* Sort the singular values and find how many are above */
  2031. /* the underflow threshold. */
  2032. n2 = 0;
  2033. n4 = 0;
  2034. i__1 = *n - 1;
  2035. for (p = 1; p <= i__1; ++p) {
  2036. i__2 = *n - p + 1;
  2037. q = isamax_(&i__2, &sva[p], &c__1) + p - 1;
  2038. if (p != q) {
  2039. temp1 = sva[p];
  2040. sva[p] = sva[q];
  2041. sva[q] = temp1;
  2042. temp1 = work[p];
  2043. work[p] = work[q];
  2044. work[q] = temp1;
  2045. sswap_(m, &a[p * a_dim1 + 1], &c__1, &a[q * a_dim1 + 1], &c__1);
  2046. if (rsvec) {
  2047. sswap_(&mvl, &v[p * v_dim1 + 1], &c__1, &v[q * v_dim1 + 1], &
  2048. c__1);
  2049. }
  2050. }
  2051. if (sva[p] != 0.f) {
  2052. ++n4;
  2053. if (sva[p] * skl > sfmin) {
  2054. ++n2;
  2055. }
  2056. }
  2057. /* L5991: */
  2058. }
  2059. if (sva[*n] != 0.f) {
  2060. ++n4;
  2061. if (sva[*n] * skl > sfmin) {
  2062. ++n2;
  2063. }
  2064. }
  2065. /* Normalize the left singular vectors. */
  2066. if (lsvec || uctol) {
  2067. i__1 = n2;
  2068. for (p = 1; p <= i__1; ++p) {
  2069. r__1 = work[p] / sva[p];
  2070. sscal_(m, &r__1, &a[p * a_dim1 + 1], &c__1);
  2071. /* L1998: */
  2072. }
  2073. }
  2074. /* Scale the product of Jacobi rotations (assemble the fast rotations). */
  2075. if (rsvec) {
  2076. if (applv) {
  2077. i__1 = *n;
  2078. for (p = 1; p <= i__1; ++p) {
  2079. sscal_(&mvl, &work[p], &v[p * v_dim1 + 1], &c__1);
  2080. /* L2398: */
  2081. }
  2082. } else {
  2083. i__1 = *n;
  2084. for (p = 1; p <= i__1; ++p) {
  2085. temp1 = 1.f / snrm2_(&mvl, &v[p * v_dim1 + 1], &c__1);
  2086. sscal_(&mvl, &temp1, &v[p * v_dim1 + 1], &c__1);
  2087. /* L2399: */
  2088. }
  2089. }
  2090. }
  2091. /* Undo scaling, if necessary (and possible). */
  2092. if (skl > 1.f && sva[1] < big / skl || skl < 1.f && sva[f2cmax(n2,1)] >
  2093. sfmin / skl) {
  2094. i__1 = *n;
  2095. for (p = 1; p <= i__1; ++p) {
  2096. sva[p] = skl * sva[p];
  2097. /* L2400: */
  2098. }
  2099. skl = 1.f;
  2100. }
  2101. work[1] = skl;
  2102. /* The singular values of A are SKL*SVA(1:N). If SKL.NE.ONE */
  2103. /* then some of the singular values may overflow or underflow and */
  2104. /* the spectrum is given in this factored representation. */
  2105. work[2] = (real) n4;
  2106. /* N4 is the number of computed nonzero singular values of A. */
  2107. work[3] = (real) n2;
  2108. /* N2 is the number of singular values of A greater than SFMIN. */
  2109. /* If N2<N, SVA(N2:N) contains ZEROS and/or denormalized numbers */
  2110. /* that may carry some information. */
  2111. work[4] = (real) i__;
  2112. /* i is the index of the last sweep before declaring convergence. */
  2113. work[5] = mxaapq;
  2114. /* MXAAPQ is the largest absolute value of scaled pivots in the */
  2115. /* last sweep */
  2116. work[6] = mxsinj;
  2117. /* MXSINJ is the largest absolute value of the sines of Jacobi angles */
  2118. /* in the last sweep */
  2119. return;
  2120. } /* sgesvj_ */