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.

sgesvdq.c 72 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <complex.h>
  6. #ifdef complex
  7. #undef complex
  8. #endif
  9. #ifdef I
  10. #undef I
  11. #endif
  12. #if defined(_WIN64)
  13. typedef long long BLASLONG;
  14. typedef unsigned long long BLASULONG;
  15. #else
  16. typedef long BLASLONG;
  17. typedef unsigned long BLASULONG;
  18. #endif
  19. #ifdef LAPACK_ILP64
  20. typedef BLASLONG blasint;
  21. #if defined(_WIN64)
  22. #define blasabs(x) llabs(x)
  23. #else
  24. #define blasabs(x) labs(x)
  25. #endif
  26. #else
  27. typedef int blasint;
  28. #define blasabs(x) abs(x)
  29. #endif
  30. typedef blasint integer;
  31. typedef unsigned int uinteger;
  32. typedef char *address;
  33. typedef short int shortint;
  34. typedef float real;
  35. typedef double doublereal;
  36. typedef struct { real r, i; } complex;
  37. typedef struct { doublereal r, i; } doublecomplex;
  38. #ifdef _MSC_VER
  39. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  40. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  41. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  42. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  43. #else
  44. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  47. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  48. #endif
  49. #define pCf(z) (*_pCf(z))
  50. #define pCd(z) (*_pCd(z))
  51. typedef blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  172. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  217. #define pow_si(B,E) spow_ui(*(B),*(E))
  218. #define pow_ri(B,E) spow_ui(*(B),*(E))
  219. #define pow_di(B,E) dpow_ui(*(B),*(E))
  220. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  221. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  222. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  223. #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
  224. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  225. #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
  226. #define sig_die(s, kill) { exit(1); }
  227. #define s_stop(s, n) {exit(0);}
  228. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  229. #define z_abs(z) (cabs(Cd(z)))
  230. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  231. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  232. #define myexit_() break;
  233. #define mycycle() continue;
  234. #define myceiling(w) {ceil(w)}
  235. #define myhuge(w) {HUGE_VAL}
  236. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  237. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  238. /* procedure parameter types for -A and -C++ */
  239. #ifdef __cplusplus
  240. typedef logical (*L_fp)(...);
  241. #else
  242. typedef logical (*L_fp)();
  243. #endif
  244. static float spow_ui(float x, integer n) {
  245. float pow=1.0; unsigned long int u;
  246. if(n != 0) {
  247. if(n < 0) n = -n, x = 1/x;
  248. for(u = n; ; ) {
  249. if(u & 01) pow *= x;
  250. if(u >>= 1) x *= x;
  251. else break;
  252. }
  253. }
  254. return pow;
  255. }
  256. static double dpow_ui(double x, integer n) {
  257. double pow=1.0; unsigned long int u;
  258. if(n != 0) {
  259. if(n < 0) n = -n, x = 1/x;
  260. for(u = n; ; ) {
  261. if(u & 01) pow *= x;
  262. if(u >>= 1) x *= x;
  263. else break;
  264. }
  265. }
  266. return pow;
  267. }
  268. #ifdef _MSC_VER
  269. static _Fcomplex cpow_ui(complex x, integer n) {
  270. complex pow={1.0,0.0}; unsigned long int u;
  271. if(n != 0) {
  272. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  273. for(u = n; ; ) {
  274. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  275. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  276. else break;
  277. }
  278. }
  279. _Fcomplex p={pow.r, pow.i};
  280. return p;
  281. }
  282. #else
  283. static _Complex float cpow_ui(_Complex float x, integer n) {
  284. _Complex float pow=1.0; unsigned long int u;
  285. if(n != 0) {
  286. if(n < 0) n = -n, x = 1/x;
  287. for(u = n; ; ) {
  288. if(u & 01) pow *= x;
  289. if(u >>= 1) x *= x;
  290. else break;
  291. }
  292. }
  293. return pow;
  294. }
  295. #endif
  296. #ifdef _MSC_VER
  297. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  298. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  299. if(n != 0) {
  300. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  301. for(u = n; ; ) {
  302. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  303. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  304. else break;
  305. }
  306. }
  307. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  308. return p;
  309. }
  310. #else
  311. static _Complex double zpow_ui(_Complex double x, integer n) {
  312. _Complex double pow=1.0; unsigned long int u;
  313. if(n != 0) {
  314. if(n < 0) n = -n, x = 1/x;
  315. for(u = n; ; ) {
  316. if(u & 01) pow *= x;
  317. if(u >>= 1) x *= x;
  318. else break;
  319. }
  320. }
  321. return pow;
  322. }
  323. #endif
  324. static integer pow_ii(integer x, integer n) {
  325. integer pow; unsigned long int u;
  326. if (n <= 0) {
  327. if (n == 0 || x == 1) pow = 1;
  328. else if (x != -1) pow = x == 0 ? 1/x : 0;
  329. else n = -n;
  330. }
  331. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  332. u = n;
  333. for(pow = 1; ; ) {
  334. if(u & 01) pow *= x;
  335. if(u >>= 1) x *= x;
  336. else break;
  337. }
  338. }
  339. return pow;
  340. }
  341. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  342. {
  343. double m; integer i, mi;
  344. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  345. if (w[i-1]>m) mi=i ,m=w[i-1];
  346. return mi-s+1;
  347. }
  348. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  349. {
  350. float m; integer i, mi;
  351. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  352. if (w[i-1]>m) mi=i ,m=w[i-1];
  353. return mi-s+1;
  354. }
  355. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  356. integer n = *n_, incx = *incx_, incy = *incy_, i;
  357. #ifdef _MSC_VER
  358. _Fcomplex zdotc = {0.0, 0.0};
  359. if (incx == 1 && incy == 1) {
  360. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  361. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  362. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  363. }
  364. } else {
  365. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  366. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  367. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  368. }
  369. }
  370. pCf(z) = zdotc;
  371. }
  372. #else
  373. _Complex float zdotc = 0.0;
  374. if (incx == 1 && incy == 1) {
  375. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  376. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  377. }
  378. } else {
  379. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  380. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  381. }
  382. }
  383. pCf(z) = zdotc;
  384. }
  385. #endif
  386. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  387. integer n = *n_, incx = *incx_, incy = *incy_, i;
  388. #ifdef _MSC_VER
  389. _Dcomplex zdotc = {0.0, 0.0};
  390. if (incx == 1 && incy == 1) {
  391. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  392. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  393. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  394. }
  395. } else {
  396. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  397. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  398. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  399. }
  400. }
  401. pCd(z) = zdotc;
  402. }
  403. #else
  404. _Complex double zdotc = 0.0;
  405. if (incx == 1 && incy == 1) {
  406. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  407. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  408. }
  409. } else {
  410. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  411. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  412. }
  413. }
  414. pCd(z) = zdotc;
  415. }
  416. #endif
  417. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  418. integer n = *n_, incx = *incx_, incy = *incy_, i;
  419. #ifdef _MSC_VER
  420. _Fcomplex zdotc = {0.0, 0.0};
  421. if (incx == 1 && incy == 1) {
  422. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  423. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  424. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  425. }
  426. } else {
  427. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  428. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  429. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  430. }
  431. }
  432. pCf(z) = zdotc;
  433. }
  434. #else
  435. _Complex float zdotc = 0.0;
  436. if (incx == 1 && incy == 1) {
  437. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  438. zdotc += Cf(&x[i]) * Cf(&y[i]);
  439. }
  440. } else {
  441. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  442. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  443. }
  444. }
  445. pCf(z) = zdotc;
  446. }
  447. #endif
  448. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  449. integer n = *n_, incx = *incx_, incy = *incy_, i;
  450. #ifdef _MSC_VER
  451. _Dcomplex zdotc = {0.0, 0.0};
  452. if (incx == 1 && incy == 1) {
  453. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  454. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  455. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  456. }
  457. } else {
  458. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  459. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  460. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  461. }
  462. }
  463. pCd(z) = zdotc;
  464. }
  465. #else
  466. _Complex double zdotc = 0.0;
  467. if (incx == 1 && incy == 1) {
  468. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  469. zdotc += Cd(&x[i]) * Cd(&y[i]);
  470. }
  471. } else {
  472. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  473. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  474. }
  475. }
  476. pCd(z) = zdotc;
  477. }
  478. #endif
  479. /* -- translated by f2c (version 20000121).
  480. You must link the resulting object file with the libraries:
  481. -lf2c -lm (in that order)
  482. */
  483. /* Table of constant values */
  484. static integer c_n1 = -1;
  485. static integer c__1 = 1;
  486. static real c_b72 = 0.f;
  487. static real c_b76 = 1.f;
  488. static integer c__0 = 0;
  489. static logical c_false = FALSE_;
  490. /* > \brief <b> SGESVDQ computes the singular value decomposition (SVD) with a QR-Preconditioned QR SVD Method
  491. for GE matrices</b> */
  492. /* =========== DOCUMENTATION =========== */
  493. /* Online html documentation available at */
  494. /* http://www.netlib.org/lapack/explore-html/ */
  495. /* > \htmlonly */
  496. /* > Download SGESVDQ + dependencies */
  497. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgesvdq
  498. .f"> */
  499. /* > [TGZ]</a> */
  500. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgesvdq
  501. .f"> */
  502. /* > [ZIP]</a> */
  503. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgesvdq
  504. .f"> */
  505. /* > [TXT]</a> */
  506. /* > \endhtmlonly */
  507. /* Definition: */
  508. /* =========== */
  509. /* SUBROUTINE SGESVDQ( JOBA, JOBP, JOBR, JOBU, JOBV, M, N, A, LDA, */
  510. /* S, U, LDU, V, LDV, NUMRANK, IWORK, LIWORK, */
  511. /* WORK, LWORK, RWORK, LRWORK, INFO ) */
  512. /* IMPLICIT NONE */
  513. /* CHARACTER JOBA, JOBP, JOBR, JOBU, JOBV */
  514. /* INTEGER M, N, LDA, LDU, LDV, NUMRANK, LIWORK, LWORK, LRWORK, */
  515. /* INFO */
  516. /* REAL A( LDA, * ), U( LDU, * ), V( LDV, * ), WORK( * ) */
  517. /* REAL S( * ), RWORK( * ) */
  518. /* INTEGER IWORK( * ) */
  519. /* > \par Purpose: */
  520. /* ============= */
  521. /* > */
  522. /* > \verbatim */
  523. /* > */
  524. /* > SGESVDQ computes the singular value decomposition (SVD) of a real */
  525. /* > M-by-N matrix A, where M >= N. The SVD of A is written as */
  526. /* > [++] [xx] [x0] [xx] */
  527. /* > A = U * SIGMA * V^*, [++] = [xx] * [ox] * [xx] */
  528. /* > [++] [xx] */
  529. /* > where SIGMA is an N-by-N diagonal matrix, U is an M-by-N orthonormal */
  530. /* > matrix, and V is an N-by-N orthogonal matrix. The diagonal elements */
  531. /* > of SIGMA are the singular values of A. The columns of U and V are the */
  532. /* > left and the right singular vectors of A, respectively. */
  533. /* > \endverbatim */
  534. /* Arguments: */
  535. /* ========== */
  536. /* > \param[in] JOBA */
  537. /* > \verbatim */
  538. /* > JOBA is CHARACTER*1 */
  539. /* > Specifies the level of accuracy in the computed SVD */
  540. /* > = 'A' The requested accuracy corresponds to having the backward */
  541. /* > error bounded by || delta A ||_F <= f(m,n) * EPS * || A ||_F, */
  542. /* > where EPS = SLAMCH('Epsilon'). This authorises CGESVDQ to */
  543. /* > truncate the computed triangular factor in a rank revealing */
  544. /* > QR factorization whenever the truncated part is below the */
  545. /* > threshold of the order of EPS * ||A||_F. This is aggressive */
  546. /* > truncation level. */
  547. /* > = 'M' Similarly as with 'A', but the truncation is more gentle: it */
  548. /* > is allowed only when there is a drop on the diagonal of the */
  549. /* > triangular factor in the QR factorization. This is medium */
  550. /* > truncation level. */
  551. /* > = 'H' High accuracy requested. No numerical rank determination based */
  552. /* > on the rank revealing QR factorization is attempted. */
  553. /* > = 'E' Same as 'H', and in addition the condition number of column */
  554. /* > scaled A is estimated and returned in RWORK(1). */
  555. /* > N^(-1/4)*RWORK(1) <= ||pinv(A_scaled)||_2 <= N^(1/4)*RWORK(1) */
  556. /* > \endverbatim */
  557. /* > */
  558. /* > \param[in] JOBP */
  559. /* > \verbatim */
  560. /* > JOBP is CHARACTER*1 */
  561. /* > = 'P' The rows of A are ordered in decreasing order with respect to */
  562. /* > ||A(i,:)||_\infty. This enhances numerical accuracy at the cost */
  563. /* > of extra data movement. Recommended for numerical robustness. */
  564. /* > = 'N' No row pivoting. */
  565. /* > \endverbatim */
  566. /* > */
  567. /* > \param[in] JOBR */
  568. /* > \verbatim */
  569. /* > JOBR is CHARACTER*1 */
  570. /* > = 'T' After the initial pivoted QR factorization, SGESVD is applied to */
  571. /* > the transposed R**T of the computed triangular factor R. This involves */
  572. /* > some extra data movement (matrix transpositions). Useful for */
  573. /* > experiments, research and development. */
  574. /* > = 'N' The triangular factor R is given as input to SGESVD. This may be */
  575. /* > preferred as it involves less data movement. */
  576. /* > \endverbatim */
  577. /* > */
  578. /* > \param[in] JOBU */
  579. /* > \verbatim */
  580. /* > JOBU is CHARACTER*1 */
  581. /* > = 'A' All M left singular vectors are computed and returned in the */
  582. /* > matrix U. See the description of U. */
  583. /* > = 'S' or 'U' N = f2cmin(M,N) left singular vectors are computed and returned */
  584. /* > in the matrix U. See the description of U. */
  585. /* > = 'R' Numerical rank NUMRANK is determined and only NUMRANK left singular */
  586. /* > vectors are computed and returned in the matrix U. */
  587. /* > = 'F' The N left singular vectors are returned in factored form as the */
  588. /* > product of the Q factor from the initial QR factorization and the */
  589. /* > N left singular vectors of (R**T , 0)**T. If row pivoting is used, */
  590. /* > then the necessary information on the row pivoting is stored in */
  591. /* > IWORK(N+1:N+M-1). */
  592. /* > = 'N' The left singular vectors are not computed. */
  593. /* > \endverbatim */
  594. /* > */
  595. /* > \param[in] JOBV */
  596. /* > \verbatim */
  597. /* > JOBV is CHARACTER*1 */
  598. /* > = 'A', 'V' All N right singular vectors are computed and returned in */
  599. /* > the matrix V. */
  600. /* > = 'R' Numerical rank NUMRANK is determined and only NUMRANK right singular */
  601. /* > vectors are computed and returned in the matrix V. This option is */
  602. /* > allowed only if JOBU = 'R' or JOBU = 'N'; otherwise it is illegal. */
  603. /* > = 'N' The right singular vectors are not computed. */
  604. /* > \endverbatim */
  605. /* > */
  606. /* > \param[in] M */
  607. /* > \verbatim */
  608. /* > M is INTEGER */
  609. /* > The number of rows of the input matrix A. M >= 0. */
  610. /* > \endverbatim */
  611. /* > */
  612. /* > \param[in] N */
  613. /* > \verbatim */
  614. /* > N is INTEGER */
  615. /* > The number of columns of the input matrix A. M >= N >= 0. */
  616. /* > \endverbatim */
  617. /* > */
  618. /* > \param[in,out] A */
  619. /* > \verbatim */
  620. /* > A is REAL array of dimensions LDA x N */
  621. /* > On entry, the input matrix A. */
  622. /* > On exit, if JOBU .NE. 'N' or JOBV .NE. 'N', the lower triangle of A contains */
  623. /* > the Householder vectors as stored by SGEQP3. If JOBU = 'F', these Householder */
  624. /* > vectors together with WORK(1:N) can be used to restore the Q factors from */
  625. /* > the initial pivoted QR factorization of A. See the description of U. */
  626. /* > \endverbatim */
  627. /* > */
  628. /* > \param[in] LDA */
  629. /* > \verbatim */
  630. /* > LDA is INTEGER. */
  631. /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
  632. /* > \endverbatim */
  633. /* > */
  634. /* > \param[out] S */
  635. /* > \verbatim */
  636. /* > S is REAL array of dimension N. */
  637. /* > The singular values of A, ordered so that S(i) >= S(i+1). */
  638. /* > \endverbatim */
  639. /* > */
  640. /* > \param[out] U */
  641. /* > \verbatim */
  642. /* > U is REAL array, dimension */
  643. /* > LDU x M if JOBU = 'A'; see the description of LDU. In this case, */
  644. /* > on exit, U contains the M left singular vectors. */
  645. /* > LDU x N if JOBU = 'S', 'U', 'R' ; see the description of LDU. In this */
  646. /* > case, U contains the leading N or the leading NUMRANK left singular vectors. */
  647. /* > LDU x N if JOBU = 'F' ; see the description of LDU. In this case U */
  648. /* > contains N x N orthogonal matrix that can be used to form the left */
  649. /* > singular vectors. */
  650. /* > If JOBU = 'N', U is not referenced. */
  651. /* > \endverbatim */
  652. /* > */
  653. /* > \param[in] LDU */
  654. /* > \verbatim */
  655. /* > LDU is INTEGER. */
  656. /* > The leading dimension of the array U. */
  657. /* > If JOBU = 'A', 'S', 'U', 'R', LDU >= f2cmax(1,M). */
  658. /* > If JOBU = 'F', LDU >= f2cmax(1,N). */
  659. /* > Otherwise, LDU >= 1. */
  660. /* > \endverbatim */
  661. /* > */
  662. /* > \param[out] V */
  663. /* > \verbatim */
  664. /* > V is REAL array, dimension */
  665. /* > LDV x N if JOBV = 'A', 'V', 'R' or if JOBA = 'E' . */
  666. /* > If JOBV = 'A', or 'V', V contains the N-by-N orthogonal matrix V**T; */
  667. /* > If JOBV = 'R', V contains the first NUMRANK rows of V**T (the right */
  668. /* > singular vectors, stored rowwise, of the NUMRANK largest singular values). */
  669. /* > If JOBV = 'N' and JOBA = 'E', V is used as a workspace. */
  670. /* > If JOBV = 'N', and JOBA.NE.'E', V is not referenced. */
  671. /* > \endverbatim */
  672. /* > */
  673. /* > \param[in] LDV */
  674. /* > \verbatim */
  675. /* > LDV is INTEGER */
  676. /* > The leading dimension of the array V. */
  677. /* > If JOBV = 'A', 'V', 'R', or JOBA = 'E', LDV >= f2cmax(1,N). */
  678. /* > Otherwise, LDV >= 1. */
  679. /* > \endverbatim */
  680. /* > */
  681. /* > \param[out] NUMRANK */
  682. /* > \verbatim */
  683. /* > NUMRANK is INTEGER */
  684. /* > NUMRANK is the numerical rank first determined after the rank */
  685. /* > revealing QR factorization, following the strategy specified by the */
  686. /* > value of JOBA. If JOBV = 'R' and JOBU = 'R', only NUMRANK */
  687. /* > leading singular values and vectors are then requested in the call */
  688. /* > of SGESVD. The final value of NUMRANK might be further reduced if */
  689. /* > some singular values are computed as zeros. */
  690. /* > \endverbatim */
  691. /* > */
  692. /* > \param[out] IWORK */
  693. /* > \verbatim */
  694. /* > IWORK is INTEGER array, dimension (f2cmax(1, LIWORK)). */
  695. /* > On exit, IWORK(1:N) contains column pivoting permutation of the */
  696. /* > rank revealing QR factorization. */
  697. /* > If JOBP = 'P', IWORK(N+1:N+M-1) contains the indices of the sequence */
  698. /* > of row swaps used in row pivoting. These can be used to restore the */
  699. /* > left singular vectors in the case JOBU = 'F'. */
  700. /* > */
  701. /* > If LIWORK, LWORK, or LRWORK = -1, then on exit, if INFO = 0, */
  702. /* > LIWORK(1) returns the minimal LIWORK. */
  703. /* > \endverbatim */
  704. /* > */
  705. /* > \param[in] LIWORK */
  706. /* > \verbatim */
  707. /* > LIWORK is INTEGER */
  708. /* > The dimension of the array IWORK. */
  709. /* > LIWORK >= N + M - 1, if JOBP = 'P' and JOBA .NE. 'E'; */
  710. /* > LIWORK >= N if JOBP = 'N' and JOBA .NE. 'E'; */
  711. /* > LIWORK >= N + M - 1 + N, if JOBP = 'P' and JOBA = 'E'; */
  712. /* > LIWORK >= N + N if JOBP = 'N' and JOBA = 'E'. */
  713. /* > If LIWORK = -1, then a workspace query is assumed; the routine */
  714. /* > only calculates and returns the optimal and minimal sizes */
  715. /* > for the WORK, IWORK, and RWORK arrays, and no error */
  716. /* > message related to LWORK is issued by XERBLA. */
  717. /* > \endverbatim */
  718. /* > */
  719. /* > \param[out] WORK */
  720. /* > \verbatim */
  721. /* > WORK is REAL array, dimension (f2cmax(2, LWORK)), used as a workspace. */
  722. /* > On exit, if, on entry, LWORK.NE.-1, WORK(1:N) contains parameters */
  723. /* > needed to recover the Q factor from the QR factorization computed by */
  724. /* > SGEQP3. */
  725. /* > */
  726. /* > If LIWORK, LWORK, or LRWORK = -1, then on exit, if INFO = 0, */
  727. /* > WORK(1) returns the optimal LWORK, and */
  728. /* > WORK(2) returns the minimal LWORK. */
  729. /* > \endverbatim */
  730. /* > */
  731. /* > \param[in,out] LWORK */
  732. /* > \verbatim */
  733. /* > LWORK is INTEGER */
  734. /* > The dimension of the array WORK. It is determined as follows: */
  735. /* > Let LWQP3 = 3*N+1, LWCON = 3*N, and let */
  736. /* > LWORQ = { MAX( N, 1 ), if JOBU = 'R', 'S', or 'U' */
  737. /* > { MAX( M, 1 ), if JOBU = 'A' */
  738. /* > LWSVD = MAX( 5*N, 1 ) */
  739. /* > LWLQF = MAX( N/2, 1 ), LWSVD2 = MAX( 5*(N/2), 1 ), LWORLQ = MAX( N, 1 ), */
  740. /* > LWQRF = MAX( N/2, 1 ), LWORQ2 = MAX( N, 1 ) */
  741. /* > Then the minimal value of LWORK is: */
  742. /* > = MAX( N + LWQP3, LWSVD ) if only the singular values are needed; */
  743. /* > = MAX( N + LWQP3, LWCON, LWSVD ) if only the singular values are needed, */
  744. /* > and a scaled condition estimate requested; */
  745. /* > */
  746. /* > = N + MAX( LWQP3, LWSVD, LWORQ ) if the singular values and the left */
  747. /* > singular vectors are requested; */
  748. /* > = N + MAX( LWQP3, LWCON, LWSVD, LWORQ ) if the singular values and the left */
  749. /* > singular vectors are requested, and also */
  750. /* > a scaled condition estimate requested; */
  751. /* > */
  752. /* > = N + MAX( LWQP3, LWSVD ) if the singular values and the right */
  753. /* > singular vectors are requested; */
  754. /* > = N + MAX( LWQP3, LWCON, LWSVD ) if the singular values and the right */
  755. /* > singular vectors are requested, and also */
  756. /* > a scaled condition etimate requested; */
  757. /* > */
  758. /* > = N + MAX( LWQP3, LWSVD, LWORQ ) if the full SVD is requested with JOBV = 'R'; */
  759. /* > independent of JOBR; */
  760. /* > = N + MAX( LWQP3, LWCON, LWSVD, LWORQ ) if the full SVD is requested, */
  761. /* > JOBV = 'R' and, also a scaled condition */
  762. /* > estimate requested; independent of JOBR; */
  763. /* > = MAX( N + MAX( LWQP3, LWSVD, LWORQ ), */
  764. /* > N + MAX( LWQP3, N/2+LWLQF, N/2+LWSVD2, N/2+LWORLQ, LWORQ) ) if the */
  765. /* > full SVD is requested with JOBV = 'A' or 'V', and */
  766. /* > JOBR ='N' */
  767. /* > = MAX( N + MAX( LWQP3, LWCON, LWSVD, LWORQ ), */
  768. /* > N + MAX( LWQP3, LWCON, N/2+LWLQF, N/2+LWSVD2, N/2+LWORLQ, LWORQ ) ) */
  769. /* > if the full SVD is requested with JOBV = 'A' or 'V', and */
  770. /* > JOBR ='N', and also a scaled condition number estimate */
  771. /* > requested. */
  772. /* > = MAX( N + MAX( LWQP3, LWSVD, LWORQ ), */
  773. /* > N + MAX( LWQP3, N/2+LWQRF, N/2+LWSVD2, N/2+LWORQ2, LWORQ ) ) if the */
  774. /* > full SVD is requested with JOBV = 'A', 'V', and JOBR ='T' */
  775. /* > = MAX( N + MAX( LWQP3, LWCON, LWSVD, LWORQ ), */
  776. /* > N + MAX( LWQP3, LWCON, N/2+LWQRF, N/2+LWSVD2, N/2+LWORQ2, LWORQ ) ) */
  777. /* > if the full SVD is requested with JOBV = 'A' or 'V', and */
  778. /* > JOBR ='T', and also a scaled condition number estimate */
  779. /* > requested. */
  780. /* > Finally, LWORK must be at least two: LWORK = MAX( 2, LWORK ). */
  781. /* > */
  782. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  783. /* > only calculates and returns the optimal and minimal sizes */
  784. /* > for the WORK, IWORK, and RWORK arrays, and no error */
  785. /* > message related to LWORK is issued by XERBLA. */
  786. /* > \endverbatim */
  787. /* > */
  788. /* > \param[out] RWORK */
  789. /* > \verbatim */
  790. /* > RWORK is REAL array, dimension (f2cmax(1, LRWORK)). */
  791. /* > On exit, */
  792. /* > 1. If JOBA = 'E', RWORK(1) contains an estimate of the condition */
  793. /* > number of column scaled A. If A = C * D where D is diagonal and C */
  794. /* > has unit columns in the Euclidean norm, then, assuming full column rank, */
  795. /* > N^(-1/4) * RWORK(1) <= ||pinv(C)||_2 <= N^(1/4) * RWORK(1). */
  796. /* > Otherwise, RWORK(1) = -1. */
  797. /* > 2. RWORK(2) contains the number of singular values computed as */
  798. /* > exact zeros in SGESVD applied to the upper triangular or trapeziodal */
  799. /* > R (from the initial QR factorization). In case of early exit (no call to */
  800. /* > SGESVD, such as in the case of zero matrix) RWORK(2) = -1. */
  801. /* > */
  802. /* > If LIWORK, LWORK, or LRWORK = -1, then on exit, if INFO = 0, */
  803. /* > RWORK(1) returns the minimal LRWORK. */
  804. /* > \endverbatim */
  805. /* > */
  806. /* > \param[in] LRWORK */
  807. /* > \verbatim */
  808. /* > LRWORK is INTEGER. */
  809. /* > The dimension of the array RWORK. */
  810. /* > If JOBP ='P', then LRWORK >= MAX(2, M). */
  811. /* > Otherwise, LRWORK >= 2 */
  812. /* > If LRWORK = -1, then a workspace query is assumed; the routine */
  813. /* > only calculates and returns the optimal and minimal sizes */
  814. /* > for the WORK, IWORK, and RWORK arrays, and no error */
  815. /* > message related to LWORK is issued by XERBLA. */
  816. /* > \endverbatim */
  817. /* > */
  818. /* > \param[out] INFO */
  819. /* > \verbatim */
  820. /* > INFO is INTEGER */
  821. /* > = 0: successful exit. */
  822. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  823. /* > > 0: if SBDSQR did not converge, INFO specifies how many superdiagonals */
  824. /* > of an intermediate bidiagonal form B (computed in SGESVD) did not */
  825. /* > converge to zero. */
  826. /* > \endverbatim */
  827. /* > \par Further Details: */
  828. /* ======================== */
  829. /* > */
  830. /* > \verbatim */
  831. /* > */
  832. /* > 1. The data movement (matrix transpose) is coded using simple nested */
  833. /* > DO-loops because BLAS and LAPACK do not provide corresponding subroutines. */
  834. /* > Those DO-loops are easily identified in this source code - by the CONTINUE */
  835. /* > statements labeled with 11**. In an optimized version of this code, the */
  836. /* > nested DO loops should be replaced with calls to an optimized subroutine. */
  837. /* > 2. This code scales A by 1/SQRT(M) if the largest ABS(A(i,j)) could cause */
  838. /* > column norm overflow. This is the minial precaution and it is left to the */
  839. /* > SVD routine (CGESVD) to do its own preemptive scaling if potential over- */
  840. /* > or underflows are detected. To avoid repeated scanning of the array A, */
  841. /* > an optimal implementation would do all necessary scaling before calling */
  842. /* > CGESVD and the scaling in CGESVD can be switched off. */
  843. /* > 3. Other comments related to code optimization are given in comments in the */
  844. /* > code, enlosed in [[double brackets]]. */
  845. /* > \endverbatim */
  846. /* > \par Bugs, examples and comments */
  847. /* =========================== */
  848. /* > \verbatim */
  849. /* > Please report all bugs and send interesting examples and/or comments to */
  850. /* > drmac@math.hr. Thank you. */
  851. /* > \endverbatim */
  852. /* > \par References */
  853. /* =============== */
  854. /* > \verbatim */
  855. /* > [1] Zlatko Drmac, Algorithm 977: A QR-Preconditioned QR SVD Method for */
  856. /* > Computing the SVD with High Accuracy. ACM Trans. Math. Softw. */
  857. /* > 44(1): 11:1-11:30 (2017) */
  858. /* > */
  859. /* > SIGMA library, xGESVDQ section updated February 2016. */
  860. /* > Developed and coded by Zlatko Drmac, Department of Mathematics */
  861. /* > University of Zagreb, Croatia, drmac@math.hr */
  862. /* > \endverbatim */
  863. /* > \par Contributors: */
  864. /* ================== */
  865. /* > */
  866. /* > \verbatim */
  867. /* > Developed and coded by Zlatko Drmac, Department of Mathematics */
  868. /* > University of Zagreb, Croatia, drmac@math.hr */
  869. /* > \endverbatim */
  870. /* Authors: */
  871. /* ======== */
  872. /* > \author Univ. of Tennessee */
  873. /* > \author Univ. of California Berkeley */
  874. /* > \author Univ. of Colorado Denver */
  875. /* > \author NAG Ltd. */
  876. /* > \date November 2018 */
  877. /* > \ingroup realGEsing */
  878. /* ===================================================================== */
  879. /* Subroutine */ void sgesvdq_(char *joba, char *jobp, char *jobr, char *jobu,
  880. char *jobv, integer *m, integer *n, real *a, integer *lda, real *s,
  881. real *u, integer *ldu, real *v, integer *ldv, integer *numrank,
  882. integer *iwork, integer *liwork, real *work, integer *lwork, real *
  883. rwork, integer *lrwork, integer *info)
  884. {
  885. /* System generated locals */
  886. integer a_dim1, a_offset, u_dim1, u_offset, v_dim1, v_offset, i__1, i__2;
  887. real r__1, r__2, r__3;
  888. /* Local variables */
  889. integer lwrk_sormlq__, lwrk_sormqr__, ierr, lwrk_sgesvd2__;
  890. real rtmp;
  891. integer lwrk_sormqr2__, optratio;
  892. logical lsvc0;
  893. extern real snrm2_(integer *, real *, integer *);
  894. logical accla;
  895. integer lwqp3;
  896. logical acclh, acclm;
  897. integer p, q;
  898. logical conda;
  899. extern logical lsame_(char *, char *);
  900. extern /* Subroutine */ void sscal_(integer *, real *, real *, integer *);
  901. integer iwoff;
  902. logical lsvec;
  903. real sfmin, epsln;
  904. integer lwcon;
  905. logical rsvec;
  906. integer lwlqf, lwqrf, n1, lwsvd;
  907. logical dntwu, dntwv, wntua;
  908. integer lworq;
  909. logical wntuf, wntva, wntur, wntus, wntvr;
  910. extern /* Subroutine */ void sgeqp3_(integer *, integer *, real *, integer
  911. *, integer *, real *, real *, integer *, integer *);
  912. integer lwsvd2, lworq2, nr;
  913. real sconda;
  914. extern real slamch_(char *), slange_(char *, integer *, integer *,
  915. real *, integer *, real *);
  916. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  917. extern void sgelqf_(
  918. integer *, integer *, real *, integer *, real *, real *, integer *
  919. , integer *), slascl_(char *, integer *, integer *, real *, real *
  920. , integer *, integer *, real *, integer *, integer *);
  921. extern integer isamax_(integer *, real *, integer *);
  922. extern /* Subroutine */ void sgeqrf_(integer *, integer *, real *, integer
  923. *, real *, real *, integer *, integer *), sgesvd_(char *, char *,
  924. integer *, integer *, real *, integer *, real *, real *, integer *
  925. , real *, integer *, real *, integer *, integer *)
  926. , slacpy_(char *, integer *, integer *, real *, integer *, real *,
  927. integer *), slaset_(char *, integer *, integer *, real *,
  928. real *, real *, integer *), slapmt_(logical *, integer *,
  929. integer *, real *, integer *, integer *), spocon_(char *,
  930. integer *, real *, integer *, real *, real *, real *, integer *,
  931. integer *);
  932. integer minwrk;
  933. logical rtrans;
  934. extern /* Subroutine */ int slaswp_(integer *, real *, integer *, integer
  935. *, integer *, integer *, integer *);
  936. real rdummy[1];
  937. extern /* Subroutine */ void sormlq_(char *, char *, integer *, integer *,
  938. integer *, real *, integer *, real *, real *, integer *, real *,
  939. integer *, integer *);
  940. logical lquery;
  941. integer lwunlq;
  942. extern /* Subroutine */ void sormqr_(char *, char *, integer *, integer *,
  943. integer *, real *, integer *, real *, real *, integer *, real *,
  944. integer *, integer *);
  945. integer optwrk;
  946. logical rowprm;
  947. real big;
  948. integer minwrk2;
  949. logical ascaled;
  950. integer optwrk2, lwrk_sgeqp3__, iminwrk, rminwrk, lwrk_sgelqf__,
  951. lwrk_sgeqrf__, lwrk_sgesvd__;
  952. /* ===================================================================== */
  953. /* Test the input arguments */
  954. /* Parameter adjustments */
  955. a_dim1 = *lda;
  956. a_offset = 1 + a_dim1 * 1;
  957. a -= a_offset;
  958. --s;
  959. u_dim1 = *ldu;
  960. u_offset = 1 + u_dim1 * 1;
  961. u -= u_offset;
  962. v_dim1 = *ldv;
  963. v_offset = 1 + v_dim1 * 1;
  964. v -= v_offset;
  965. --iwork;
  966. --work;
  967. --rwork;
  968. /* Function Body */
  969. wntus = lsame_(jobu, "S") || lsame_(jobu, "U");
  970. wntur = lsame_(jobu, "R");
  971. wntua = lsame_(jobu, "A");
  972. wntuf = lsame_(jobu, "F");
  973. lsvc0 = wntus || wntur || wntua;
  974. lsvec = lsvc0 || wntuf;
  975. dntwu = lsame_(jobu, "N");
  976. wntvr = lsame_(jobv, "R");
  977. wntva = lsame_(jobv, "A") || lsame_(jobv, "V");
  978. rsvec = wntvr || wntva;
  979. dntwv = lsame_(jobv, "N");
  980. accla = lsame_(joba, "A");
  981. acclm = lsame_(joba, "M");
  982. conda = lsame_(joba, "E");
  983. acclh = lsame_(joba, "H") || conda;
  984. rowprm = lsame_(jobp, "P");
  985. rtrans = lsame_(jobr, "T");
  986. if (rowprm) {
  987. if (conda) {
  988. /* Computing MAX */
  989. i__1 = 1, i__2 = *n + *m - 1 + *n;
  990. iminwrk = f2cmax(i__1,i__2);
  991. } else {
  992. /* Computing MAX */
  993. i__1 = 1, i__2 = *n + *m - 1;
  994. iminwrk = f2cmax(i__1,i__2);
  995. }
  996. rminwrk = f2cmax(2,*m);
  997. } else {
  998. if (conda) {
  999. /* Computing MAX */
  1000. i__1 = 1, i__2 = *n + *n;
  1001. iminwrk = f2cmax(i__1,i__2);
  1002. } else {
  1003. iminwrk = f2cmax(1,*n);
  1004. }
  1005. rminwrk = 2;
  1006. }
  1007. lquery = *liwork == -1 || *lwork == -1 || *lrwork == -1;
  1008. *info = 0;
  1009. if (! (accla || acclm || acclh)) {
  1010. *info = -1;
  1011. } else if (! (rowprm || lsame_(jobp, "N"))) {
  1012. *info = -2;
  1013. } else if (! (rtrans || lsame_(jobr, "N"))) {
  1014. *info = -3;
  1015. } else if (! (lsvec || dntwu)) {
  1016. *info = -4;
  1017. } else if (wntur && wntva) {
  1018. *info = -5;
  1019. } else if (! (rsvec || dntwv)) {
  1020. *info = -5;
  1021. } else if (*m < 0) {
  1022. *info = -6;
  1023. } else if (*n < 0 || *n > *m) {
  1024. *info = -7;
  1025. } else if (*lda < f2cmax(1,*m)) {
  1026. *info = -9;
  1027. } else if (*ldu < 1 || lsvc0 && *ldu < *m || wntuf && *ldu < *n) {
  1028. *info = -12;
  1029. } else if (*ldv < 1 || rsvec && *ldv < *n || conda && *ldv < *n) {
  1030. *info = -14;
  1031. } else if (*liwork < iminwrk && ! lquery) {
  1032. *info = -17;
  1033. }
  1034. if (*info == 0) {
  1035. /* [[The expressions for computing the minimal and the optimal */
  1036. /* values of LWORK are written with a lot of redundancy and */
  1037. /* can be simplified. However, this detailed form is easier for */
  1038. /* maintenance and modifications of the code.]] */
  1039. lwqp3 = *n * 3 + 1;
  1040. if (wntus || wntur) {
  1041. lworq = f2cmax(*n,1);
  1042. } else if (wntua) {
  1043. lworq = f2cmax(*m,1);
  1044. }
  1045. lwcon = *n * 3;
  1046. /* Computing MAX */
  1047. i__1 = *n * 5;
  1048. lwsvd = f2cmax(i__1,1);
  1049. if (lquery) {
  1050. sgeqp3_(m, n, &a[a_offset], lda, &iwork[1], rdummy, rdummy, &c_n1,
  1051. &ierr);
  1052. lwrk_sgeqp3__ = (integer) rdummy[0];
  1053. if (wntus || wntur) {
  1054. sormqr_("L", "N", m, n, n, &a[a_offset], lda, rdummy, &u[
  1055. u_offset], ldu, rdummy, &c_n1, &ierr);
  1056. lwrk_sormqr__ = (integer) rdummy[0];
  1057. } else if (wntua) {
  1058. sormqr_("L", "N", m, m, n, &a[a_offset], lda, rdummy, &u[
  1059. u_offset], ldu, rdummy, &c_n1, &ierr);
  1060. lwrk_sormqr__ = (integer) rdummy[0];
  1061. } else {
  1062. lwrk_sormqr__ = 0;
  1063. }
  1064. }
  1065. minwrk = 2;
  1066. optwrk = 2;
  1067. if (! (lsvec || rsvec)) {
  1068. /* only the singular values are requested */
  1069. if (conda) {
  1070. /* Computing MAX */
  1071. i__1 = *n + lwqp3, i__1 = f2cmax(i__1,lwcon);
  1072. minwrk = f2cmax(i__1,lwsvd);
  1073. } else {
  1074. /* Computing MAX */
  1075. i__1 = *n + lwqp3;
  1076. minwrk = f2cmax(i__1,lwsvd);
  1077. }
  1078. if (lquery) {
  1079. sgesvd_("N", "N", n, n, &a[a_offset], lda, &s[1], &u[u_offset]
  1080. , ldu, &v[v_offset], ldv, rdummy, &c_n1, &ierr);
  1081. lwrk_sgesvd__ = (integer) rdummy[0];
  1082. if (conda) {
  1083. /* Computing MAX */
  1084. i__1 = *n + lwrk_sgeqp3__, i__2 = *n + lwcon, i__1 = f2cmax(
  1085. i__1,i__2);
  1086. optwrk = f2cmax(i__1,lwrk_sgesvd__);
  1087. } else {
  1088. /* Computing MAX */
  1089. i__1 = *n + lwrk_sgeqp3__;
  1090. optwrk = f2cmax(i__1,lwrk_sgesvd__);
  1091. }
  1092. }
  1093. } else if (lsvec && ! rsvec) {
  1094. /* singular values and the left singular vectors are requested */
  1095. if (conda) {
  1096. /* Computing MAX */
  1097. i__1 = f2cmax(lwqp3,lwcon), i__1 = f2cmax(i__1,lwsvd);
  1098. minwrk = *n + f2cmax(i__1,lworq);
  1099. } else {
  1100. /* Computing MAX */
  1101. i__1 = f2cmax(lwqp3,lwsvd);
  1102. minwrk = *n + f2cmax(i__1,lworq);
  1103. }
  1104. if (lquery) {
  1105. if (rtrans) {
  1106. sgesvd_("N", "O", n, n, &a[a_offset], lda, &s[1], &u[
  1107. u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
  1108. &ierr);
  1109. } else {
  1110. sgesvd_("O", "N", n, n, &a[a_offset], lda, &s[1], &u[
  1111. u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
  1112. &ierr);
  1113. }
  1114. lwrk_sgesvd__ = (integer) rdummy[0];
  1115. if (conda) {
  1116. /* Computing MAX */
  1117. i__1 = f2cmax(lwrk_sgeqp3__,lwcon), i__1 = f2cmax(i__1,
  1118. lwrk_sgesvd__);
  1119. optwrk = *n + f2cmax(i__1,lwrk_sormqr__);
  1120. } else {
  1121. /* Computing MAX */
  1122. i__1 = f2cmax(lwrk_sgeqp3__,lwrk_sgesvd__);
  1123. optwrk = *n + f2cmax(i__1,lwrk_sormqr__);
  1124. }
  1125. }
  1126. } else if (rsvec && ! lsvec) {
  1127. /* singular values and the right singular vectors are requested */
  1128. if (conda) {
  1129. /* Computing MAX */
  1130. i__1 = f2cmax(lwqp3,lwcon);
  1131. minwrk = *n + f2cmax(i__1,lwsvd);
  1132. } else {
  1133. minwrk = *n + f2cmax(lwqp3,lwsvd);
  1134. }
  1135. if (lquery) {
  1136. if (rtrans) {
  1137. sgesvd_("O", "N", n, n, &a[a_offset], lda, &s[1], &u[
  1138. u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
  1139. &ierr);
  1140. } else {
  1141. sgesvd_("N", "O", n, n, &a[a_offset], lda, &s[1], &u[
  1142. u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
  1143. &ierr);
  1144. }
  1145. lwrk_sgesvd__ = (integer) rdummy[0];
  1146. if (conda) {
  1147. /* Computing MAX */
  1148. i__1 = f2cmax(lwrk_sgeqp3__,lwcon);
  1149. optwrk = *n + f2cmax(i__1,lwrk_sgesvd__);
  1150. } else {
  1151. optwrk = *n + f2cmax(lwrk_sgeqp3__,lwrk_sgesvd__);
  1152. }
  1153. }
  1154. } else {
  1155. /* full SVD is requested */
  1156. if (rtrans) {
  1157. /* Computing MAX */
  1158. i__1 = f2cmax(lwqp3,lwsvd);
  1159. minwrk = f2cmax(i__1,lworq);
  1160. if (conda) {
  1161. minwrk = f2cmax(minwrk,lwcon);
  1162. }
  1163. minwrk += *n;
  1164. if (wntva) {
  1165. /* Computing MAX */
  1166. i__1 = *n / 2;
  1167. lwqrf = f2cmax(i__1,1);
  1168. /* Computing MAX */
  1169. i__1 = *n / 2 * 5;
  1170. lwsvd2 = f2cmax(i__1,1);
  1171. lworq2 = f2cmax(*n,1);
  1172. /* Computing MAX */
  1173. i__1 = lwqp3, i__2 = *n / 2 + lwqrf, i__1 = f2cmax(i__1,i__2)
  1174. , i__2 = *n / 2 + lwsvd2, i__1 = f2cmax(i__1,i__2),
  1175. i__2 = *n / 2 + lworq2, i__1 = f2cmax(i__1,i__2);
  1176. minwrk2 = f2cmax(i__1,lworq);
  1177. if (conda) {
  1178. minwrk2 = f2cmax(minwrk2,lwcon);
  1179. }
  1180. minwrk2 = *n + minwrk2;
  1181. minwrk = f2cmax(minwrk,minwrk2);
  1182. }
  1183. } else {
  1184. /* Computing MAX */
  1185. i__1 = f2cmax(lwqp3,lwsvd);
  1186. minwrk = f2cmax(i__1,lworq);
  1187. if (conda) {
  1188. minwrk = f2cmax(minwrk,lwcon);
  1189. }
  1190. minwrk += *n;
  1191. if (wntva) {
  1192. /* Computing MAX */
  1193. i__1 = *n / 2;
  1194. lwlqf = f2cmax(i__1,1);
  1195. /* Computing MAX */
  1196. i__1 = *n / 2 * 5;
  1197. lwsvd2 = f2cmax(i__1,1);
  1198. lwunlq = f2cmax(*n,1);
  1199. /* Computing MAX */
  1200. i__1 = lwqp3, i__2 = *n / 2 + lwlqf, i__1 = f2cmax(i__1,i__2)
  1201. , i__2 = *n / 2 + lwsvd2, i__1 = f2cmax(i__1,i__2),
  1202. i__2 = *n / 2 + lwunlq, i__1 = f2cmax(i__1,i__2);
  1203. minwrk2 = f2cmax(i__1,lworq);
  1204. if (conda) {
  1205. minwrk2 = f2cmax(minwrk2,lwcon);
  1206. }
  1207. minwrk2 = *n + minwrk2;
  1208. minwrk = f2cmax(minwrk,minwrk2);
  1209. }
  1210. }
  1211. if (lquery) {
  1212. if (rtrans) {
  1213. sgesvd_("O", "A", n, n, &a[a_offset], lda, &s[1], &u[
  1214. u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
  1215. &ierr);
  1216. lwrk_sgesvd__ = (integer) rdummy[0];
  1217. /* Computing MAX */
  1218. i__1 = f2cmax(lwrk_sgeqp3__,lwrk_sgesvd__);
  1219. optwrk = f2cmax(i__1,lwrk_sormqr__);
  1220. if (conda) {
  1221. optwrk = f2cmax(optwrk,lwcon);
  1222. }
  1223. optwrk = *n + optwrk;
  1224. if (wntva) {
  1225. i__1 = *n / 2;
  1226. sgeqrf_(n, &i__1, &u[u_offset], ldu, rdummy, rdummy, &
  1227. c_n1, &ierr);
  1228. lwrk_sgeqrf__ = (integer) rdummy[0];
  1229. i__1 = *n / 2;
  1230. i__2 = *n / 2;
  1231. sgesvd_("S", "O", &i__1, &i__2, &v[v_offset], ldv, &s[
  1232. 1], &u[u_offset], ldu, &v[v_offset], ldv,
  1233. rdummy, &c_n1, &ierr);
  1234. lwrk_sgesvd2__ = (integer) rdummy[0];
  1235. i__1 = *n / 2;
  1236. sormqr_("R", "C", n, n, &i__1, &u[u_offset], ldu,
  1237. rdummy, &v[v_offset], ldv, rdummy, &c_n1, &
  1238. ierr);
  1239. lwrk_sormqr2__ = (integer) rdummy[0];
  1240. /* Computing MAX */
  1241. i__1 = lwrk_sgeqp3__, i__2 = *n / 2 + lwrk_sgeqrf__,
  1242. i__1 = f2cmax(i__1,i__2), i__2 = *n / 2 +
  1243. lwrk_sgesvd2__, i__1 = f2cmax(i__1,i__2), i__2 =
  1244. *n / 2 + lwrk_sormqr2__;
  1245. optwrk2 = f2cmax(i__1,i__2);
  1246. if (conda) {
  1247. optwrk2 = f2cmax(optwrk2,lwcon);
  1248. }
  1249. optwrk2 = *n + optwrk2;
  1250. optwrk = f2cmax(optwrk,optwrk2);
  1251. }
  1252. } else {
  1253. sgesvd_("S", "O", n, n, &a[a_offset], lda, &s[1], &u[
  1254. u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
  1255. &ierr);
  1256. lwrk_sgesvd__ = (integer) rdummy[0];
  1257. /* Computing MAX */
  1258. i__1 = f2cmax(lwrk_sgeqp3__,lwrk_sgesvd__);
  1259. optwrk = f2cmax(i__1,lwrk_sormqr__);
  1260. if (conda) {
  1261. optwrk = f2cmax(optwrk,lwcon);
  1262. }
  1263. optwrk = *n + optwrk;
  1264. if (wntva) {
  1265. i__1 = *n / 2;
  1266. sgelqf_(&i__1, n, &u[u_offset], ldu, rdummy, rdummy, &
  1267. c_n1, &ierr);
  1268. lwrk_sgelqf__ = (integer) rdummy[0];
  1269. i__1 = *n / 2;
  1270. i__2 = *n / 2;
  1271. sgesvd_("S", "O", &i__1, &i__2, &v[v_offset], ldv, &s[
  1272. 1], &u[u_offset], ldu, &v[v_offset], ldv,
  1273. rdummy, &c_n1, &ierr);
  1274. lwrk_sgesvd2__ = (integer) rdummy[0];
  1275. i__1 = *n / 2;
  1276. sormlq_("R", "N", n, n, &i__1, &u[u_offset], ldu,
  1277. rdummy, &v[v_offset], ldv, rdummy, &c_n1, &
  1278. ierr);
  1279. lwrk_sormlq__ = (integer) rdummy[0];
  1280. /* Computing MAX */
  1281. i__1 = lwrk_sgeqp3__, i__2 = *n / 2 + lwrk_sgelqf__,
  1282. i__1 = f2cmax(i__1,i__2), i__2 = *n / 2 +
  1283. lwrk_sgesvd2__, i__1 = f2cmax(i__1,i__2), i__2 =
  1284. *n / 2 + lwrk_sormlq__;
  1285. optwrk2 = f2cmax(i__1,i__2);
  1286. if (conda) {
  1287. optwrk2 = f2cmax(optwrk2,lwcon);
  1288. }
  1289. optwrk2 = *n + optwrk2;
  1290. optwrk = f2cmax(optwrk,optwrk2);
  1291. }
  1292. }
  1293. }
  1294. }
  1295. minwrk = f2cmax(2,minwrk);
  1296. optwrk = f2cmax(2,optwrk);
  1297. if (*lwork < minwrk && ! lquery) {
  1298. *info = -19;
  1299. }
  1300. }
  1301. if (*info == 0 && *lrwork < rminwrk && ! lquery) {
  1302. *info = -21;
  1303. }
  1304. if (*info != 0) {
  1305. i__1 = -(*info);
  1306. xerbla_("SGESVDQ", &i__1, (ftnlen)7);
  1307. return;
  1308. } else if (lquery) {
  1309. /* Return optimal workspace */
  1310. iwork[1] = iminwrk;
  1311. work[1] = (real) optwrk;
  1312. work[2] = (real) minwrk;
  1313. rwork[1] = (real) rminwrk;
  1314. return;
  1315. }
  1316. /* Quick return if the matrix is void. */
  1317. if (*m == 0 || *n == 0) {
  1318. return;
  1319. }
  1320. big = slamch_("O");
  1321. ascaled = FALSE_;
  1322. iwoff = 1;
  1323. if (rowprm) {
  1324. iwoff = *m;
  1325. /* ell-infinity norm - this enhances numerical robustness in */
  1326. /* the case of differently scaled rows. */
  1327. i__1 = *m;
  1328. for (p = 1; p <= i__1; ++p) {
  1329. /* RWORK(p) = ABS( A(p,ICAMAX(N,A(p,1),LDA)) ) */
  1330. /* [[SLANGE will return NaN if an entry of the p-th row is Nan]] */
  1331. rwork[p] = slange_("M", &c__1, n, &a[p + a_dim1], lda, rdummy);
  1332. if (rwork[p] != rwork[p] || rwork[p] * 0.f != 0.f) {
  1333. *info = -8;
  1334. i__2 = -(*info);
  1335. xerbla_("SGESVDQ", &i__2, (ftnlen)7);
  1336. return;
  1337. }
  1338. /* L1904: */
  1339. }
  1340. i__1 = *m - 1;
  1341. for (p = 1; p <= i__1; ++p) {
  1342. i__2 = *m - p + 1;
  1343. q = isamax_(&i__2, &rwork[p], &c__1) + p - 1;
  1344. iwork[*n + p] = q;
  1345. if (p != q) {
  1346. rtmp = rwork[p];
  1347. rwork[p] = rwork[q];
  1348. rwork[q] = rtmp;
  1349. }
  1350. /* L1952: */
  1351. }
  1352. if (rwork[1] == 0.f) {
  1353. /* Quick return: A is the M x N zero matrix. */
  1354. *numrank = 0;
  1355. slaset_("G", n, &c__1, &c_b72, &c_b72, &s[1], n);
  1356. if (wntus) {
  1357. slaset_("G", m, n, &c_b72, &c_b76, &u[u_offset], ldu);
  1358. }
  1359. if (wntua) {
  1360. slaset_("G", m, m, &c_b72, &c_b76, &u[u_offset], ldu);
  1361. }
  1362. if (wntva) {
  1363. slaset_("G", n, n, &c_b72, &c_b76, &v[v_offset], ldv);
  1364. }
  1365. if (wntuf) {
  1366. slaset_("G", n, &c__1, &c_b72, &c_b72, &work[1], n)
  1367. ;
  1368. slaset_("G", m, n, &c_b72, &c_b76, &u[u_offset], ldu);
  1369. }
  1370. i__1 = *n;
  1371. for (p = 1; p <= i__1; ++p) {
  1372. iwork[p] = p;
  1373. /* L5001: */
  1374. }
  1375. if (rowprm) {
  1376. i__1 = *n + *m - 1;
  1377. for (p = *n + 1; p <= i__1; ++p) {
  1378. iwork[p] = p - *n;
  1379. /* L5002: */
  1380. }
  1381. }
  1382. if (conda) {
  1383. rwork[1] = -1.f;
  1384. }
  1385. rwork[2] = -1.f;
  1386. return;
  1387. }
  1388. if (rwork[1] > big / sqrt((real) (*m))) {
  1389. /* matrix by 1/sqrt(M) if too large entry detected */
  1390. r__1 = sqrt((real) (*m));
  1391. slascl_("G", &c__0, &c__0, &r__1, &c_b76, m, n, &a[a_offset], lda,
  1392. &ierr);
  1393. ascaled = TRUE_;
  1394. }
  1395. i__1 = *m - 1;
  1396. slaswp_(n, &a[a_offset], lda, &c__1, &i__1, &iwork[*n + 1], &c__1);
  1397. }
  1398. /* norms overflows during the QR factorization. The SVD procedure should */
  1399. /* have its own scaling to save the singular values from overflows and */
  1400. /* underflows. That depends on the SVD procedure. */
  1401. if (! rowprm) {
  1402. rtmp = slange_("M", m, n, &a[a_offset], lda, rdummy);
  1403. if (rtmp != rtmp || rtmp * 0.f != 0.f) {
  1404. *info = -8;
  1405. i__1 = -(*info);
  1406. xerbla_("SGESVDQ", &i__1, (ftnlen)7);
  1407. return;
  1408. }
  1409. if (rtmp > big / sqrt((real) (*m))) {
  1410. /* matrix by 1/sqrt(M) if too large entry detected */
  1411. r__1 = sqrt((real) (*m));
  1412. slascl_("G", &c__0, &c__0, &r__1, &c_b76, m, n, &a[a_offset], lda,
  1413. &ierr);
  1414. ascaled = TRUE_;
  1415. }
  1416. }
  1417. /* A * P = Q * [ R ] */
  1418. /* [ 0 ] */
  1419. i__1 = *n;
  1420. for (p = 1; p <= i__1; ++p) {
  1421. iwork[p] = 0;
  1422. /* L1963: */
  1423. }
  1424. i__1 = *lwork - *n;
  1425. sgeqp3_(m, n, &a[a_offset], lda, &iwork[1], &work[1], &work[*n + 1], &
  1426. i__1, &ierr);
  1427. /* If the user requested accuracy level allows truncation in the */
  1428. /* computed upper triangular factor, the matrix R is examined and, */
  1429. /* if possible, replaced with its leading upper trapezoidal part. */
  1430. epsln = slamch_("E");
  1431. sfmin = slamch_("S");
  1432. /* SMALL = SFMIN / EPSLN */
  1433. nr = *n;
  1434. if (accla) {
  1435. /* Standard absolute error bound suffices. All sigma_i with */
  1436. /* sigma_i < N*EPS*||A||_F are flushed to zero. This is an */
  1437. /* aggressive enforcement of lower numerical rank by introducing a */
  1438. /* backward error of the order of N*EPS*||A||_F. */
  1439. nr = 1;
  1440. rtmp = sqrt((real) (*n)) * epsln;
  1441. i__1 = *n;
  1442. for (p = 2; p <= i__1; ++p) {
  1443. if ((r__2 = a[p + p * a_dim1], abs(r__2)) < rtmp * (r__1 = a[
  1444. a_dim1 + 1], abs(r__1))) {
  1445. goto L3002;
  1446. }
  1447. ++nr;
  1448. /* L3001: */
  1449. }
  1450. L3002:
  1451. ;
  1452. } else if (acclm) {
  1453. /* Sudden drop on the diagonal of R is used as the criterion for being */
  1454. /* close-to-rank-deficient. The threshold is set to EPSLN=SLAMCH('E'). */
  1455. /* [[This can be made more flexible by replacing this hard-coded value */
  1456. /* with a user specified threshold.]] Also, the values that underflow */
  1457. /* will be truncated. */
  1458. nr = 1;
  1459. i__1 = *n;
  1460. for (p = 2; p <= i__1; ++p) {
  1461. if ((r__2 = a[p + p * a_dim1], abs(r__2)) < epsln * (r__1 = a[p -
  1462. 1 + (p - 1) * a_dim1], abs(r__1)) || (r__3 = a[p + p *
  1463. a_dim1], abs(r__3)) < sfmin) {
  1464. goto L3402;
  1465. }
  1466. ++nr;
  1467. /* L3401: */
  1468. }
  1469. L3402:
  1470. ;
  1471. } else {
  1472. /* obvious case of zero pivots. */
  1473. /* R(i,i)=0 => R(i:N,i:N)=0. */
  1474. nr = 1;
  1475. i__1 = *n;
  1476. for (p = 2; p <= i__1; ++p) {
  1477. if ((r__1 = a[p + p * a_dim1], abs(r__1)) == 0.f) {
  1478. goto L3502;
  1479. }
  1480. ++nr;
  1481. /* L3501: */
  1482. }
  1483. L3502:
  1484. if (conda) {
  1485. /* Estimate the scaled condition number of A. Use the fact that it is */
  1486. /* the same as the scaled condition number of R. */
  1487. slacpy_("U", n, n, &a[a_offset], lda, &v[v_offset], ldv);
  1488. /* Only the leading NR x NR submatrix of the triangular factor */
  1489. /* is considered. Only if NR=N will this give a reliable error */
  1490. /* bound. However, even for NR < N, this can be used on an */
  1491. /* expert level and obtain useful information in the sense of */
  1492. /* perturbation theory. */
  1493. i__1 = nr;
  1494. for (p = 1; p <= i__1; ++p) {
  1495. rtmp = snrm2_(&p, &v[p * v_dim1 + 1], &c__1);
  1496. r__1 = 1.f / rtmp;
  1497. sscal_(&p, &r__1, &v[p * v_dim1 + 1], &c__1);
  1498. /* L3053: */
  1499. }
  1500. if (! (lsvec || rsvec)) {
  1501. spocon_("U", &nr, &v[v_offset], ldv, &c_b76, &rtmp, &work[1],
  1502. &iwork[*n + iwoff], &ierr);
  1503. } else {
  1504. spocon_("U", &nr, &v[v_offset], ldv, &c_b76, &rtmp, &work[*n
  1505. + 1], &iwork[*n + iwoff], &ierr);
  1506. }
  1507. sconda = 1.f / sqrt(rtmp);
  1508. /* For NR=N, SCONDA is an estimate of SQRT(||(R^* * R)^(-1)||_1), */
  1509. /* N^(-1/4) * SCONDA <= ||R^(-1)||_2 <= N^(1/4) * SCONDA */
  1510. /* See the reference [1] for more details. */
  1511. }
  1512. }
  1513. if (wntur) {
  1514. n1 = nr;
  1515. } else if (wntus || wntuf) {
  1516. n1 = *n;
  1517. } else if (wntua) {
  1518. n1 = *m;
  1519. }
  1520. if (! (rsvec || lsvec)) {
  1521. /* ....................................................................... */
  1522. /* ....................................................................... */
  1523. if (rtrans) {
  1524. /* the upper triangle of [A] to zero. */
  1525. i__1 = f2cmin(*n,nr);
  1526. for (p = 1; p <= i__1; ++p) {
  1527. i__2 = *n;
  1528. for (q = p + 1; q <= i__2; ++q) {
  1529. a[q + p * a_dim1] = a[p + q * a_dim1];
  1530. if (q <= nr) {
  1531. a[p + q * a_dim1] = 0.f;
  1532. }
  1533. /* L1147: */
  1534. }
  1535. /* L1146: */
  1536. }
  1537. sgesvd_("N", "N", n, &nr, &a[a_offset], lda, &s[1], &u[u_offset],
  1538. ldu, &v[v_offset], ldv, &work[1], lwork, info);
  1539. } else {
  1540. if (nr > 1) {
  1541. i__1 = nr - 1;
  1542. i__2 = nr - 1;
  1543. slaset_("L", &i__1, &i__2, &c_b72, &c_b72, &a[a_dim1 + 2],
  1544. lda);
  1545. }
  1546. sgesvd_("N", "N", &nr, n, &a[a_offset], lda, &s[1], &u[u_offset],
  1547. ldu, &v[v_offset], ldv, &work[1], lwork, info);
  1548. }
  1549. } else if (lsvec && ! rsvec) {
  1550. /* ....................................................................... */
  1551. /* ......................................................................."""""""" */
  1552. if (rtrans) {
  1553. /* vectors of R */
  1554. i__1 = nr;
  1555. for (p = 1; p <= i__1; ++p) {
  1556. i__2 = *n;
  1557. for (q = p; q <= i__2; ++q) {
  1558. u[q + p * u_dim1] = a[p + q * a_dim1];
  1559. /* L1193: */
  1560. }
  1561. /* L1192: */
  1562. }
  1563. if (nr > 1) {
  1564. i__1 = nr - 1;
  1565. i__2 = nr - 1;
  1566. slaset_("U", &i__1, &i__2, &c_b72, &c_b72, &u[(u_dim1 << 1) +
  1567. 1], ldu);
  1568. }
  1569. /* vectors overwrite [U](1:NR,1:NR) as transposed. These */
  1570. /* will be pre-multiplied by Q to build the left singular vectors of A. */
  1571. i__1 = *lwork - *n;
  1572. sgesvd_("N", "O", n, &nr, &u[u_offset], ldu, &s[1], &u[u_offset],
  1573. ldu, &u[u_offset], ldu, &work[*n + 1], &i__1, info);
  1574. i__1 = nr;
  1575. for (p = 1; p <= i__1; ++p) {
  1576. i__2 = nr;
  1577. for (q = p + 1; q <= i__2; ++q) {
  1578. rtmp = u[q + p * u_dim1];
  1579. u[q + p * u_dim1] = u[p + q * u_dim1];
  1580. u[p + q * u_dim1] = rtmp;
  1581. /* L1120: */
  1582. }
  1583. /* L1119: */
  1584. }
  1585. } else {
  1586. slacpy_("U", &nr, n, &a[a_offset], lda, &u[u_offset], ldu);
  1587. if (nr > 1) {
  1588. i__1 = nr - 1;
  1589. i__2 = nr - 1;
  1590. slaset_("L", &i__1, &i__2, &c_b72, &c_b72, &u[u_dim1 + 2],
  1591. ldu);
  1592. }
  1593. /* vectors overwrite [U](1:NR,1:NR) */
  1594. i__1 = *lwork - *n;
  1595. sgesvd_("O", "N", &nr, n, &u[u_offset], ldu, &s[1], &u[u_offset],
  1596. ldu, &v[v_offset], ldv, &work[*n + 1], &i__1, info);
  1597. /* R. These will be pre-multiplied by Q to build the left singular */
  1598. /* vectors of A. */
  1599. }
  1600. /* (M x NR) or (M x N) or (M x M). */
  1601. if (nr < *m && ! wntuf) {
  1602. i__1 = *m - nr;
  1603. slaset_("A", &i__1, &nr, &c_b72, &c_b72, &u[nr + 1 + u_dim1], ldu);
  1604. if (nr < n1) {
  1605. i__1 = n1 - nr;
  1606. slaset_("A", &nr, &i__1, &c_b72, &c_b72, &u[(nr + 1) * u_dim1
  1607. + 1], ldu);
  1608. i__1 = *m - nr;
  1609. i__2 = n1 - nr;
  1610. slaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[nr + 1 + (nr +
  1611. 1) * u_dim1], ldu);
  1612. }
  1613. }
  1614. /* The Q matrix from the first QRF is built into the left singular */
  1615. /* vectors matrix U. */
  1616. if (! wntuf) {
  1617. i__1 = *lwork - *n;
  1618. sormqr_("L", "N", m, &n1, n, &a[a_offset], lda, &work[1], &u[
  1619. u_offset], ldu, &work[*n + 1], &i__1, &ierr);
  1620. }
  1621. if (rowprm && ! wntuf) {
  1622. i__1 = *m - 1;
  1623. slaswp_(&n1, &u[u_offset], ldu, &c__1, &i__1, &iwork[*n + 1], &
  1624. c_n1);
  1625. }
  1626. } else if (rsvec && ! lsvec) {
  1627. /* ....................................................................... */
  1628. /* ....................................................................... */
  1629. if (rtrans) {
  1630. i__1 = nr;
  1631. for (p = 1; p <= i__1; ++p) {
  1632. i__2 = *n;
  1633. for (q = p; q <= i__2; ++q) {
  1634. v[q + p * v_dim1] = a[p + q * a_dim1];
  1635. /* L1166: */
  1636. }
  1637. /* L1165: */
  1638. }
  1639. if (nr > 1) {
  1640. i__1 = nr - 1;
  1641. i__2 = nr - 1;
  1642. slaset_("U", &i__1, &i__2, &c_b72, &c_b72, &v[(v_dim1 << 1) +
  1643. 1], ldv);
  1644. }
  1645. /* vectors not computed */
  1646. if (wntvr || nr == *n) {
  1647. i__1 = *lwork - *n;
  1648. sgesvd_("O", "N", n, &nr, &v[v_offset], ldv, &s[1], &u[
  1649. u_offset], ldu, &u[u_offset], ldu, &work[*n + 1], &
  1650. i__1, info);
  1651. i__1 = nr;
  1652. for (p = 1; p <= i__1; ++p) {
  1653. i__2 = nr;
  1654. for (q = p + 1; q <= i__2; ++q) {
  1655. rtmp = v[q + p * v_dim1];
  1656. v[q + p * v_dim1] = v[p + q * v_dim1];
  1657. v[p + q * v_dim1] = rtmp;
  1658. /* L1122: */
  1659. }
  1660. /* L1121: */
  1661. }
  1662. if (nr < *n) {
  1663. i__1 = nr;
  1664. for (p = 1; p <= i__1; ++p) {
  1665. i__2 = *n;
  1666. for (q = nr + 1; q <= i__2; ++q) {
  1667. v[p + q * v_dim1] = v[q + p * v_dim1];
  1668. /* L1104: */
  1669. }
  1670. /* L1103: */
  1671. }
  1672. }
  1673. slapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
  1674. } else {
  1675. /* [!] This is simple implementation that augments [V](1:N,1:NR) */
  1676. /* by padding a zero block. In the case NR << N, a more efficient */
  1677. /* way is to first use the QR factorization. For more details */
  1678. /* how to implement this, see the " FULL SVD " branch. */
  1679. i__1 = *n - nr;
  1680. slaset_("G", n, &i__1, &c_b72, &c_b72, &v[(nr + 1) * v_dim1 +
  1681. 1], ldv);
  1682. i__1 = *lwork - *n;
  1683. sgesvd_("O", "N", n, n, &v[v_offset], ldv, &s[1], &u[u_offset]
  1684. , ldu, &u[u_offset], ldu, &work[*n + 1], &i__1, info);
  1685. i__1 = *n;
  1686. for (p = 1; p <= i__1; ++p) {
  1687. i__2 = *n;
  1688. for (q = p + 1; q <= i__2; ++q) {
  1689. rtmp = v[q + p * v_dim1];
  1690. v[q + p * v_dim1] = v[p + q * v_dim1];
  1691. v[p + q * v_dim1] = rtmp;
  1692. /* L1124: */
  1693. }
  1694. /* L1123: */
  1695. }
  1696. slapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  1697. }
  1698. } else {
  1699. slacpy_("U", &nr, n, &a[a_offset], lda, &v[v_offset], ldv);
  1700. if (nr > 1) {
  1701. i__1 = nr - 1;
  1702. i__2 = nr - 1;
  1703. slaset_("L", &i__1, &i__2, &c_b72, &c_b72, &v[v_dim1 + 2],
  1704. ldv);
  1705. }
  1706. /* vectors stored in U(1:NR,1:NR) */
  1707. if (wntvr || nr == *n) {
  1708. i__1 = *lwork - *n;
  1709. sgesvd_("N", "O", &nr, n, &v[v_offset], ldv, &s[1], &u[
  1710. u_offset], ldu, &v[v_offset], ldv, &work[*n + 1], &
  1711. i__1, info);
  1712. slapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
  1713. } else {
  1714. /* [!] This is simple implementation that augments [V](1:NR,1:N) */
  1715. /* by padding a zero block. In the case NR << N, a more efficient */
  1716. /* way is to first use the LQ factorization. For more details */
  1717. /* how to implement this, see the " FULL SVD " branch. */
  1718. i__1 = *n - nr;
  1719. slaset_("G", &i__1, n, &c_b72, &c_b72, &v[nr + 1 + v_dim1],
  1720. ldv);
  1721. i__1 = *lwork - *n;
  1722. sgesvd_("N", "O", n, n, &v[v_offset], ldv, &s[1], &u[u_offset]
  1723. , ldu, &v[v_offset], ldv, &work[*n + 1], &i__1, info);
  1724. slapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  1725. }
  1726. /* vectors of A. */
  1727. }
  1728. } else {
  1729. /* ....................................................................... */
  1730. /* ....................................................................... */
  1731. if (rtrans) {
  1732. if (wntvr || nr == *n) {
  1733. /* vectors of R**T */
  1734. i__1 = nr;
  1735. for (p = 1; p <= i__1; ++p) {
  1736. i__2 = *n;
  1737. for (q = p; q <= i__2; ++q) {
  1738. v[q + p * v_dim1] = a[p + q * a_dim1];
  1739. /* L1169: */
  1740. }
  1741. /* L1168: */
  1742. }
  1743. if (nr > 1) {
  1744. i__1 = nr - 1;
  1745. i__2 = nr - 1;
  1746. slaset_("U", &i__1, &i__2, &c_b72, &c_b72, &v[(v_dim1 <<
  1747. 1) + 1], ldv);
  1748. }
  1749. /* singular vectors of R**T stored in [U](1:NR,1:NR) as transposed */
  1750. i__1 = *lwork - *n;
  1751. sgesvd_("O", "A", n, &nr, &v[v_offset], ldv, &s[1], &v[
  1752. v_offset], ldv, &u[u_offset], ldu, &work[*n + 1], &
  1753. i__1, info);
  1754. i__1 = nr;
  1755. for (p = 1; p <= i__1; ++p) {
  1756. i__2 = nr;
  1757. for (q = p + 1; q <= i__2; ++q) {
  1758. rtmp = v[q + p * v_dim1];
  1759. v[q + p * v_dim1] = v[p + q * v_dim1];
  1760. v[p + q * v_dim1] = rtmp;
  1761. /* L1116: */
  1762. }
  1763. /* L1115: */
  1764. }
  1765. if (nr < *n) {
  1766. i__1 = nr;
  1767. for (p = 1; p <= i__1; ++p) {
  1768. i__2 = *n;
  1769. for (q = nr + 1; q <= i__2; ++q) {
  1770. v[p + q * v_dim1] = v[q + p * v_dim1];
  1771. /* L1102: */
  1772. }
  1773. /* L1101: */
  1774. }
  1775. }
  1776. slapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
  1777. i__1 = nr;
  1778. for (p = 1; p <= i__1; ++p) {
  1779. i__2 = nr;
  1780. for (q = p + 1; q <= i__2; ++q) {
  1781. rtmp = u[q + p * u_dim1];
  1782. u[q + p * u_dim1] = u[p + q * u_dim1];
  1783. u[p + q * u_dim1] = rtmp;
  1784. /* L1118: */
  1785. }
  1786. /* L1117: */
  1787. }
  1788. if (nr < *m && ! wntuf) {
  1789. i__1 = *m - nr;
  1790. slaset_("A", &i__1, &nr, &c_b72, &c_b72, &u[nr + 1 +
  1791. u_dim1], ldu);
  1792. if (nr < n1) {
  1793. i__1 = n1 - nr;
  1794. slaset_("A", &nr, &i__1, &c_b72, &c_b72, &u[(nr + 1) *
  1795. u_dim1 + 1], ldu);
  1796. i__1 = *m - nr;
  1797. i__2 = n1 - nr;
  1798. slaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[nr + 1
  1799. + (nr + 1) * u_dim1], ldu);
  1800. }
  1801. }
  1802. } else {
  1803. /* vectors of R**T */
  1804. /* [[The optimal ratio N/NR for using QRF instead of padding */
  1805. /* with zeros. Here hard coded to 2; it must be at least */
  1806. /* two due to work space constraints.]] */
  1807. /* OPTRATIO = ILAENV(6, 'SGESVD', 'S' // 'O', NR,N,0,0) */
  1808. /* OPTRATIO = MAX( OPTRATIO, 2 ) */
  1809. optratio = 2;
  1810. if (optratio * nr > *n) {
  1811. i__1 = nr;
  1812. for (p = 1; p <= i__1; ++p) {
  1813. i__2 = *n;
  1814. for (q = p; q <= i__2; ++q) {
  1815. v[q + p * v_dim1] = a[p + q * a_dim1];
  1816. /* L1199: */
  1817. }
  1818. /* L1198: */
  1819. }
  1820. if (nr > 1) {
  1821. i__1 = nr - 1;
  1822. i__2 = nr - 1;
  1823. slaset_("U", &i__1, &i__2, &c_b72, &c_b72, &v[(v_dim1
  1824. << 1) + 1], ldv);
  1825. }
  1826. i__1 = *n - nr;
  1827. slaset_("A", n, &i__1, &c_b72, &c_b72, &v[(nr + 1) *
  1828. v_dim1 + 1], ldv);
  1829. i__1 = *lwork - *n;
  1830. sgesvd_("O", "A", n, n, &v[v_offset], ldv, &s[1], &v[
  1831. v_offset], ldv, &u[u_offset], ldu, &work[*n + 1],
  1832. &i__1, info);
  1833. i__1 = *n;
  1834. for (p = 1; p <= i__1; ++p) {
  1835. i__2 = *n;
  1836. for (q = p + 1; q <= i__2; ++q) {
  1837. rtmp = v[q + p * v_dim1];
  1838. v[q + p * v_dim1] = v[p + q * v_dim1];
  1839. v[p + q * v_dim1] = rtmp;
  1840. /* L1114: */
  1841. }
  1842. /* L1113: */
  1843. }
  1844. slapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  1845. /* (M x N1), i.e. (M x N) or (M x M). */
  1846. i__1 = *n;
  1847. for (p = 1; p <= i__1; ++p) {
  1848. i__2 = *n;
  1849. for (q = p + 1; q <= i__2; ++q) {
  1850. rtmp = u[q + p * u_dim1];
  1851. u[q + p * u_dim1] = u[p + q * u_dim1];
  1852. u[p + q * u_dim1] = rtmp;
  1853. /* L1112: */
  1854. }
  1855. /* L1111: */
  1856. }
  1857. if (*n < *m && ! wntuf) {
  1858. i__1 = *m - *n;
  1859. slaset_("A", &i__1, n, &c_b72, &c_b72, &u[*n + 1 +
  1860. u_dim1], ldu);
  1861. if (*n < n1) {
  1862. i__1 = n1 - *n;
  1863. slaset_("A", n, &i__1, &c_b72, &c_b72, &u[(*n + 1)
  1864. * u_dim1 + 1], ldu);
  1865. i__1 = *m - *n;
  1866. i__2 = n1 - *n;
  1867. slaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[*n
  1868. + 1 + (*n + 1) * u_dim1], ldu);
  1869. }
  1870. }
  1871. } else {
  1872. /* singular vectors of R */
  1873. i__1 = nr;
  1874. for (p = 1; p <= i__1; ++p) {
  1875. i__2 = *n;
  1876. for (q = p; q <= i__2; ++q) {
  1877. u[q + (nr + p) * u_dim1] = a[p + q * a_dim1];
  1878. /* L1197: */
  1879. }
  1880. /* L1196: */
  1881. }
  1882. if (nr > 1) {
  1883. i__1 = nr - 1;
  1884. i__2 = nr - 1;
  1885. slaset_("U", &i__1, &i__2, &c_b72, &c_b72, &u[(nr + 2)
  1886. * u_dim1 + 1], ldu);
  1887. }
  1888. i__1 = *lwork - *n - nr;
  1889. sgeqrf_(n, &nr, &u[(nr + 1) * u_dim1 + 1], ldu, &work[*n
  1890. + 1], &work[*n + nr + 1], &i__1, &ierr);
  1891. i__1 = nr;
  1892. for (p = 1; p <= i__1; ++p) {
  1893. i__2 = *n;
  1894. for (q = 1; q <= i__2; ++q) {
  1895. v[q + p * v_dim1] = u[p + (nr + q) * u_dim1];
  1896. /* L1144: */
  1897. }
  1898. /* L1143: */
  1899. }
  1900. i__1 = nr - 1;
  1901. i__2 = nr - 1;
  1902. slaset_("U", &i__1, &i__2, &c_b72, &c_b72, &v[(v_dim1 <<
  1903. 1) + 1], ldv);
  1904. i__1 = *lwork - *n - nr;
  1905. sgesvd_("S", "O", &nr, &nr, &v[v_offset], ldv, &s[1], &u[
  1906. u_offset], ldu, &v[v_offset], ldv, &work[*n + nr
  1907. + 1], &i__1, info);
  1908. i__1 = *n - nr;
  1909. slaset_("A", &i__1, &nr, &c_b72, &c_b72, &v[nr + 1 +
  1910. v_dim1], ldv);
  1911. i__1 = *n - nr;
  1912. slaset_("A", &nr, &i__1, &c_b72, &c_b72, &v[(nr + 1) *
  1913. v_dim1 + 1], ldv);
  1914. i__1 = *n - nr;
  1915. i__2 = *n - nr;
  1916. slaset_("A", &i__1, &i__2, &c_b72, &c_b76, &v[nr + 1 + (
  1917. nr + 1) * v_dim1], ldv);
  1918. i__1 = *lwork - *n - nr;
  1919. sormqr_("R", "C", n, n, &nr, &u[(nr + 1) * u_dim1 + 1],
  1920. ldu, &work[*n + 1], &v[v_offset], ldv, &work[*n +
  1921. nr + 1], &i__1, &ierr);
  1922. slapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  1923. /* (M x NR) or (M x N) or (M x M). */
  1924. if (nr < *m && ! wntuf) {
  1925. i__1 = *m - nr;
  1926. slaset_("A", &i__1, &nr, &c_b72, &c_b72, &u[nr + 1 +
  1927. u_dim1], ldu);
  1928. if (nr < n1) {
  1929. i__1 = n1 - nr;
  1930. slaset_("A", &nr, &i__1, &c_b72, &c_b72, &u[(nr +
  1931. 1) * u_dim1 + 1], ldu);
  1932. i__1 = *m - nr;
  1933. i__2 = n1 - nr;
  1934. slaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[nr
  1935. + 1 + (nr + 1) * u_dim1], ldu);
  1936. }
  1937. }
  1938. }
  1939. }
  1940. } else {
  1941. if (wntvr || nr == *n) {
  1942. slacpy_("U", &nr, n, &a[a_offset], lda, &v[v_offset], ldv);
  1943. if (nr > 1) {
  1944. i__1 = nr - 1;
  1945. i__2 = nr - 1;
  1946. slaset_("L", &i__1, &i__2, &c_b72, &c_b72, &v[v_dim1 + 2],
  1947. ldv);
  1948. }
  1949. /* singular vectors of R stored in [U](1:NR,1:NR) */
  1950. i__1 = *lwork - *n;
  1951. sgesvd_("S", "O", &nr, n, &v[v_offset], ldv, &s[1], &u[
  1952. u_offset], ldu, &v[v_offset], ldv, &work[*n + 1], &
  1953. i__1, info);
  1954. slapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
  1955. /* (M x NR) or (M x N) or (M x M). */
  1956. if (nr < *m && ! wntuf) {
  1957. i__1 = *m - nr;
  1958. slaset_("A", &i__1, &nr, &c_b72, &c_b72, &u[nr + 1 +
  1959. u_dim1], ldu);
  1960. if (nr < n1) {
  1961. i__1 = n1 - nr;
  1962. slaset_("A", &nr, &i__1, &c_b72, &c_b72, &u[(nr + 1) *
  1963. u_dim1 + 1], ldu);
  1964. i__1 = *m - nr;
  1965. i__2 = n1 - nr;
  1966. slaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[nr + 1
  1967. + (nr + 1) * u_dim1], ldu);
  1968. }
  1969. }
  1970. } else {
  1971. /* is then N1 (N or M) */
  1972. /* [[The optimal ratio N/NR for using LQ instead of padding */
  1973. /* with zeros. Here hard coded to 2; it must be at least */
  1974. /* two due to work space constraints.]] */
  1975. /* OPTRATIO = ILAENV(6, 'SGESVD', 'S' // 'O', NR,N,0,0) */
  1976. /* OPTRATIO = MAX( OPTRATIO, 2 ) */
  1977. optratio = 2;
  1978. if (optratio * nr > *n) {
  1979. slacpy_("U", &nr, n, &a[a_offset], lda, &v[v_offset], ldv);
  1980. if (nr > 1) {
  1981. i__1 = nr - 1;
  1982. i__2 = nr - 1;
  1983. slaset_("L", &i__1, &i__2, &c_b72, &c_b72, &v[v_dim1
  1984. + 2], ldv);
  1985. }
  1986. /* singular vectors of R stored in [U](1:NR,1:NR) */
  1987. i__1 = *n - nr;
  1988. slaset_("A", &i__1, n, &c_b72, &c_b72, &v[nr + 1 + v_dim1]
  1989. , ldv);
  1990. i__1 = *lwork - *n;
  1991. sgesvd_("S", "O", n, n, &v[v_offset], ldv, &s[1], &u[
  1992. u_offset], ldu, &v[v_offset], ldv, &work[*n + 1],
  1993. &i__1, info);
  1994. slapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  1995. /* singular vectors of A. The leading N left singular vectors */
  1996. /* are in [U](1:N,1:N) */
  1997. /* (M x N1), i.e. (M x N) or (M x M). */
  1998. if (*n < *m && ! wntuf) {
  1999. i__1 = *m - *n;
  2000. slaset_("A", &i__1, n, &c_b72, &c_b72, &u[*n + 1 +
  2001. u_dim1], ldu);
  2002. if (*n < n1) {
  2003. i__1 = n1 - *n;
  2004. slaset_("A", n, &i__1, &c_b72, &c_b72, &u[(*n + 1)
  2005. * u_dim1 + 1], ldu);
  2006. i__1 = *m - *n;
  2007. i__2 = n1 - *n;
  2008. slaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[*n
  2009. + 1 + (*n + 1) * u_dim1], ldu);
  2010. }
  2011. }
  2012. } else {
  2013. slacpy_("U", &nr, n, &a[a_offset], lda, &u[nr + 1 +
  2014. u_dim1], ldu);
  2015. if (nr > 1) {
  2016. i__1 = nr - 1;
  2017. i__2 = nr - 1;
  2018. slaset_("L", &i__1, &i__2, &c_b72, &c_b72, &u[nr + 2
  2019. + u_dim1], ldu);
  2020. }
  2021. i__1 = *lwork - *n - nr;
  2022. sgelqf_(&nr, n, &u[nr + 1 + u_dim1], ldu, &work[*n + 1], &
  2023. work[*n + nr + 1], &i__1, &ierr);
  2024. slacpy_("L", &nr, &nr, &u[nr + 1 + u_dim1], ldu, &v[
  2025. v_offset], ldv);
  2026. if (nr > 1) {
  2027. i__1 = nr - 1;
  2028. i__2 = nr - 1;
  2029. slaset_("U", &i__1, &i__2, &c_b72, &c_b72, &v[(v_dim1
  2030. << 1) + 1], ldv);
  2031. }
  2032. i__1 = *lwork - *n - nr;
  2033. sgesvd_("S", "O", &nr, &nr, &v[v_offset], ldv, &s[1], &u[
  2034. u_offset], ldu, &v[v_offset], ldv, &work[*n + nr
  2035. + 1], &i__1, info);
  2036. i__1 = *n - nr;
  2037. slaset_("A", &i__1, &nr, &c_b72, &c_b72, &v[nr + 1 +
  2038. v_dim1], ldv);
  2039. i__1 = *n - nr;
  2040. slaset_("A", &nr, &i__1, &c_b72, &c_b72, &v[(nr + 1) *
  2041. v_dim1 + 1], ldv);
  2042. i__1 = *n - nr;
  2043. i__2 = *n - nr;
  2044. slaset_("A", &i__1, &i__2, &c_b72, &c_b76, &v[nr + 1 + (
  2045. nr + 1) * v_dim1], ldv);
  2046. i__1 = *lwork - *n - nr;
  2047. sormlq_("R", "N", n, n, &nr, &u[nr + 1 + u_dim1], ldu, &
  2048. work[*n + 1], &v[v_offset], ldv, &work[*n + nr +
  2049. 1], &i__1, &ierr);
  2050. slapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  2051. /* (M x NR) or (M x N) or (M x M). */
  2052. if (nr < *m && ! wntuf) {
  2053. i__1 = *m - nr;
  2054. slaset_("A", &i__1, &nr, &c_b72, &c_b72, &u[nr + 1 +
  2055. u_dim1], ldu);
  2056. if (nr < n1) {
  2057. i__1 = n1 - nr;
  2058. slaset_("A", &nr, &i__1, &c_b72, &c_b72, &u[(nr +
  2059. 1) * u_dim1 + 1], ldu);
  2060. i__1 = *m - nr;
  2061. i__2 = n1 - nr;
  2062. slaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[nr
  2063. + 1 + (nr + 1) * u_dim1], ldu);
  2064. }
  2065. }
  2066. }
  2067. }
  2068. }
  2069. /* The Q matrix from the first QRF is built into the left singular */
  2070. /* vectors matrix U. */
  2071. if (! wntuf) {
  2072. i__1 = *lwork - *n;
  2073. sormqr_("L", "N", m, &n1, n, &a[a_offset], lda, &work[1], &u[
  2074. u_offset], ldu, &work[*n + 1], &i__1, &ierr);
  2075. }
  2076. if (rowprm && ! wntuf) {
  2077. i__1 = *m - 1;
  2078. slaswp_(&n1, &u[u_offset], ldu, &c__1, &i__1, &iwork[*n + 1], &
  2079. c_n1);
  2080. }
  2081. /* ... end of the "full SVD" branch */
  2082. }
  2083. /* Check whether some singular values are returned as zeros, e.g. */
  2084. /* due to underflow, and update the numerical rank. */
  2085. p = nr;
  2086. for (q = p; q >= 1; --q) {
  2087. if (s[q] > 0.f) {
  2088. goto L4002;
  2089. }
  2090. --nr;
  2091. /* L4001: */
  2092. }
  2093. L4002:
  2094. /* singular values are set to zero. */
  2095. if (nr < *n) {
  2096. i__1 = *n - nr;
  2097. slaset_("G", &i__1, &c__1, &c_b72, &c_b72, &s[nr + 1], n);
  2098. }
  2099. /* values. */
  2100. if (ascaled) {
  2101. r__1 = sqrt((real) (*m));
  2102. slascl_("G", &c__0, &c__0, &c_b76, &r__1, &nr, &c__1, &s[1], n, &ierr);
  2103. }
  2104. if (conda) {
  2105. rwork[1] = sconda;
  2106. }
  2107. rwork[2] = (real) (p - nr);
  2108. /* exact zeros in SGESVD() applied to the (possibly truncated) */
  2109. /* full row rank triangular (trapezoidal) factor of A. */
  2110. *numrank = nr;
  2111. return;
  2112. /* End of SGESVDQ */
  2113. } /* sgesvdq_ */