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.

dgesvdq.c 73 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255
  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 integer c_n1 = -1;
  487. static integer c__1 = 1;
  488. static doublereal c_b72 = 0.;
  489. static doublereal c_b76 = 1.;
  490. static integer c__0 = 0;
  491. static logical c_false = FALSE_;
  492. /* > \brief <b> DGESVDQ computes the singular value decomposition (SVD) with a QR-Preconditioned QR SVD Method
  493. for GE matrices</b> */
  494. /* =========== DOCUMENTATION =========== */
  495. /* Online html documentation available at */
  496. /* http://www.netlib.org/lapack/explore-html/ */
  497. /* > \htmlonly */
  498. /* > Download DGESVDQ + dependencies */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgesvdq
  500. .f"> */
  501. /* > [TGZ]</a> */
  502. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgesvdq
  503. .f"> */
  504. /* > [ZIP]</a> */
  505. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgesvdq
  506. .f"> */
  507. /* > [TXT]</a> */
  508. /* > \endhtmlonly */
  509. /* Definition: */
  510. /* =========== */
  511. /* SUBROUTINE DGESVDQ( JOBA, JOBP, JOBR, JOBU, JOBV, M, N, A, LDA, */
  512. /* S, U, LDU, V, LDV, NUMRANK, IWORK, LIWORK, */
  513. /* WORK, LWORK, RWORK, LRWORK, INFO ) */
  514. /* IMPLICIT NONE */
  515. /* CHARACTER JOBA, JOBP, JOBR, JOBU, JOBV */
  516. /* INTEGER M, N, LDA, LDU, LDV, NUMRANK, LIWORK, LWORK, LRWORK, */
  517. /* INFO */
  518. /* DOUBLE PRECISION A( LDA, * ), U( LDU, * ), V( LDV, * ), WORK( * ) */
  519. /* DOUBLE PRECISION S( * ), RWORK( * ) */
  520. /* INTEGER IWORK( * ) */
  521. /* > \par Purpose: */
  522. /* ============= */
  523. /* > */
  524. /* > \verbatim */
  525. /* > */
  526. /* > DGESVDQ computes the singular value decomposition (SVD) of a real */
  527. /* > M-by-N matrix A, where M >= N. The SVD of A is written as */
  528. /* > [++] [xx] [x0] [xx] */
  529. /* > A = U * SIGMA * V^*, [++] = [xx] * [ox] * [xx] */
  530. /* > [++] [xx] */
  531. /* > where SIGMA is an N-by-N diagonal matrix, U is an M-by-N orthonormal */
  532. /* > matrix, and V is an N-by-N orthogonal matrix. The diagonal elements */
  533. /* > of SIGMA are the singular values of A. The columns of U and V are the */
  534. /* > left and the right singular vectors of A, respectively. */
  535. /* > \endverbatim */
  536. /* Arguments: */
  537. /* ========== */
  538. /* > \param[in] JOBA */
  539. /* > \verbatim */
  540. /* > JOBA is CHARACTER*1 */
  541. /* > Specifies the level of accuracy in the computed SVD */
  542. /* > = 'A' The requested accuracy corresponds to having the backward */
  543. /* > error bounded by || delta A ||_F <= f(m,n) * EPS * || A ||_F, */
  544. /* > where EPS = DLAMCH('Epsilon'). This authorises DGESVDQ to */
  545. /* > truncate the computed triangular factor in a rank revealing */
  546. /* > QR factorization whenever the truncated part is below the */
  547. /* > threshold of the order of EPS * ||A||_F. This is aggressive */
  548. /* > truncation level. */
  549. /* > = 'M' Similarly as with 'A', but the truncation is more gentle: it */
  550. /* > is allowed only when there is a drop on the diagonal of the */
  551. /* > triangular factor in the QR factorization. This is medium */
  552. /* > truncation level. */
  553. /* > = 'H' High accuracy requested. No numerical rank determination based */
  554. /* > on the rank revealing QR factorization is attempted. */
  555. /* > = 'E' Same as 'H', and in addition the condition number of column */
  556. /* > scaled A is estimated and returned in RWORK(1). */
  557. /* > N^(-1/4)*RWORK(1) <= ||pinv(A_scaled)||_2 <= N^(1/4)*RWORK(1) */
  558. /* > \endverbatim */
  559. /* > */
  560. /* > \param[in] JOBP */
  561. /* > \verbatim */
  562. /* > JOBP is CHARACTER*1 */
  563. /* > = 'P' The rows of A are ordered in decreasing order with respect to */
  564. /* > ||A(i,:)||_\infty. This enhances numerical accuracy at the cost */
  565. /* > of extra data movement. Recommended for numerical robustness. */
  566. /* > = 'N' No row pivoting. */
  567. /* > \endverbatim */
  568. /* > */
  569. /* > \param[in] JOBR */
  570. /* > \verbatim */
  571. /* > JOBR is CHARACTER*1 */
  572. /* > = 'T' After the initial pivoted QR factorization, DGESVD is applied to */
  573. /* > the transposed R**T of the computed triangular factor R. This involves */
  574. /* > some extra data movement (matrix transpositions). Useful for */
  575. /* > experiments, research and development. */
  576. /* > = 'N' The triangular factor R is given as input to DGESVD. This may be */
  577. /* > preferred as it involves less data movement. */
  578. /* > \endverbatim */
  579. /* > */
  580. /* > \param[in] JOBU */
  581. /* > \verbatim */
  582. /* > JOBU is CHARACTER*1 */
  583. /* > = 'A' All M left singular vectors are computed and returned in the */
  584. /* > matrix U. See the description of U. */
  585. /* > = 'S' or 'U' N = f2cmin(M,N) left singular vectors are computed and returned */
  586. /* > in the matrix U. See the description of U. */
  587. /* > = 'R' Numerical rank NUMRANK is determined and only NUMRANK left singular */
  588. /* > vectors are computed and returned in the matrix U. */
  589. /* > = 'F' The N left singular vectors are returned in factored form as the */
  590. /* > product of the Q factor from the initial QR factorization and the */
  591. /* > N left singular vectors of (R**T , 0)**T. If row pivoting is used, */
  592. /* > then the necessary information on the row pivoting is stored in */
  593. /* > IWORK(N+1:N+M-1). */
  594. /* > = 'N' The left singular vectors are not computed. */
  595. /* > \endverbatim */
  596. /* > */
  597. /* > \param[in] JOBV */
  598. /* > \verbatim */
  599. /* > JOBV is CHARACTER*1 */
  600. /* > = 'A', 'V' All N right singular vectors are computed and returned in */
  601. /* > the matrix V. */
  602. /* > = 'R' Numerical rank NUMRANK is determined and only NUMRANK right singular */
  603. /* > vectors are computed and returned in the matrix V. This option is */
  604. /* > allowed only if JOBU = 'R' or JOBU = 'N'; otherwise it is illegal. */
  605. /* > = 'N' The right singular vectors are not computed. */
  606. /* > \endverbatim */
  607. /* > */
  608. /* > \param[in] M */
  609. /* > \verbatim */
  610. /* > M is INTEGER */
  611. /* > The number of rows of the input matrix A. M >= 0. */
  612. /* > \endverbatim */
  613. /* > */
  614. /* > \param[in] N */
  615. /* > \verbatim */
  616. /* > N is INTEGER */
  617. /* > The number of columns of the input matrix A. M >= N >= 0. */
  618. /* > \endverbatim */
  619. /* > */
  620. /* > \param[in,out] A */
  621. /* > \verbatim */
  622. /* > A is DOUBLE PRECISION array of dimensions LDA x N */
  623. /* > On entry, the input matrix A. */
  624. /* > On exit, if JOBU .NE. 'N' or JOBV .NE. 'N', the lower triangle of A contains */
  625. /* > the Householder vectors as stored by DGEQP3. If JOBU = 'F', these Householder */
  626. /* > vectors together with WORK(1:N) can be used to restore the Q factors from */
  627. /* > the initial pivoted QR factorization of A. See the description of U. */
  628. /* > \endverbatim */
  629. /* > */
  630. /* > \param[in] LDA */
  631. /* > \verbatim */
  632. /* > LDA is INTEGER. */
  633. /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
  634. /* > \endverbatim */
  635. /* > */
  636. /* > \param[out] S */
  637. /* > \verbatim */
  638. /* > S is DOUBLE PRECISION array of dimension N. */
  639. /* > The singular values of A, ordered so that S(i) >= S(i+1). */
  640. /* > \endverbatim */
  641. /* > */
  642. /* > \param[out] U */
  643. /* > \verbatim */
  644. /* > U is DOUBLE PRECISION array, dimension */
  645. /* > LDU x M if JOBU = 'A'; see the description of LDU. In this case, */
  646. /* > on exit, U contains the M left singular vectors. */
  647. /* > LDU x N if JOBU = 'S', 'U', 'R' ; see the description of LDU. In this */
  648. /* > case, U contains the leading N or the leading NUMRANK left singular vectors. */
  649. /* > LDU x N if JOBU = 'F' ; see the description of LDU. In this case U */
  650. /* > contains N x N orthogonal matrix that can be used to form the left */
  651. /* > singular vectors. */
  652. /* > If JOBU = 'N', U is not referenced. */
  653. /* > \endverbatim */
  654. /* > */
  655. /* > \param[in] LDU */
  656. /* > \verbatim */
  657. /* > LDU is INTEGER. */
  658. /* > The leading dimension of the array U. */
  659. /* > If JOBU = 'A', 'S', 'U', 'R', LDU >= f2cmax(1,M). */
  660. /* > If JOBU = 'F', LDU >= f2cmax(1,N). */
  661. /* > Otherwise, LDU >= 1. */
  662. /* > \endverbatim */
  663. /* > */
  664. /* > \param[out] V */
  665. /* > \verbatim */
  666. /* > V is DOUBLE PRECISION array, dimension */
  667. /* > LDV x N if JOBV = 'A', 'V', 'R' or if JOBA = 'E' . */
  668. /* > If JOBV = 'A', or 'V', V contains the N-by-N orthogonal matrix V**T; */
  669. /* > If JOBV = 'R', V contains the first NUMRANK rows of V**T (the right */
  670. /* > singular vectors, stored rowwise, of the NUMRANK largest singular values). */
  671. /* > If JOBV = 'N' and JOBA = 'E', V is used as a workspace. */
  672. /* > If JOBV = 'N', and JOBA.NE.'E', V is not referenced. */
  673. /* > \endverbatim */
  674. /* > */
  675. /* > \param[in] LDV */
  676. /* > \verbatim */
  677. /* > LDV is INTEGER */
  678. /* > The leading dimension of the array V. */
  679. /* > If JOBV = 'A', 'V', 'R', or JOBA = 'E', LDV >= f2cmax(1,N). */
  680. /* > Otherwise, LDV >= 1. */
  681. /* > \endverbatim */
  682. /* > */
  683. /* > \param[out] NUMRANK */
  684. /* > \verbatim */
  685. /* > NUMRANK is INTEGER */
  686. /* > NUMRANK is the numerical rank first determined after the rank */
  687. /* > revealing QR factorization, following the strategy specified by the */
  688. /* > value of JOBA. If JOBV = 'R' and JOBU = 'R', only NUMRANK */
  689. /* > leading singular values and vectors are then requested in the call */
  690. /* > of DGESVD. The final value of NUMRANK might be further reduced if */
  691. /* > some singular values are computed as zeros. */
  692. /* > \endverbatim */
  693. /* > */
  694. /* > \param[out] IWORK */
  695. /* > \verbatim */
  696. /* > IWORK is INTEGER array, dimension (f2cmax(1, LIWORK)). */
  697. /* > On exit, IWORK(1:N) contains column pivoting permutation of the */
  698. /* > rank revealing QR factorization. */
  699. /* > If JOBP = 'P', IWORK(N+1:N+M-1) contains the indices of the sequence */
  700. /* > of row swaps used in row pivoting. These can be used to restore the */
  701. /* > left singular vectors in the case JOBU = 'F'. */
  702. /* > */
  703. /* > If LIWORK, LWORK, or LRWORK = -1, then on exit, if INFO = 0, */
  704. /* > LIWORK(1) returns the minimal LIWORK. */
  705. /* > \endverbatim */
  706. /* > */
  707. /* > \param[in] LIWORK */
  708. /* > \verbatim */
  709. /* > LIWORK is INTEGER */
  710. /* > The dimension of the array IWORK. */
  711. /* > LIWORK >= N + M - 1, if JOBP = 'P' and JOBA .NE. 'E'; */
  712. /* > LIWORK >= N if JOBP = 'N' and JOBA .NE. 'E'; */
  713. /* > LIWORK >= N + M - 1 + N, if JOBP = 'P' and JOBA = 'E'; */
  714. /* > LIWORK >= N + N if JOBP = 'N' and JOBA = 'E'. */
  715. /* > If LIWORK = -1, then a workspace query is assumed; the routine */
  716. /* > only calculates and returns the optimal and minimal sizes */
  717. /* > for the WORK, IWORK, and RWORK arrays, and no error */
  718. /* > message related to LWORK is issued by XERBLA. */
  719. /* > \endverbatim */
  720. /* > */
  721. /* > \param[out] WORK */
  722. /* > \verbatim */
  723. /* > WORK is DOUBLE PRECISION array, dimension (f2cmax(2, LWORK)), used as a workspace. */
  724. /* > On exit, if, on entry, LWORK.NE.-1, WORK(1:N) contains parameters */
  725. /* > needed to recover the Q factor from the QR factorization computed by */
  726. /* > DGEQP3. */
  727. /* > */
  728. /* > If LIWORK, LWORK, or LRWORK = -1, then on exit, if INFO = 0, */
  729. /* > WORK(1) returns the optimal LWORK, and */
  730. /* > WORK(2) returns the minimal LWORK. */
  731. /* > \endverbatim */
  732. /* > */
  733. /* > \param[in,out] LWORK */
  734. /* > \verbatim */
  735. /* > LWORK is INTEGER */
  736. /* > The dimension of the array WORK. It is determined as follows: */
  737. /* > Let LWQP3 = 3*N+1, LWCON = 3*N, and let */
  738. /* > LWORQ = { MAX( N, 1 ), if JOBU = 'R', 'S', or 'U' */
  739. /* > { MAX( M, 1 ), if JOBU = 'A' */
  740. /* > LWSVD = MAX( 5*N, 1 ) */
  741. /* > LWLQF = MAX( N/2, 1 ), LWSVD2 = MAX( 5*(N/2), 1 ), LWORLQ = MAX( N, 1 ), */
  742. /* > LWQRF = MAX( N/2, 1 ), LWORQ2 = MAX( N, 1 ) */
  743. /* > Then the minimal value of LWORK is: */
  744. /* > = MAX( N + LWQP3, LWSVD ) if only the singular values are needed; */
  745. /* > = MAX( N + LWQP3, LWCON, LWSVD ) if only the singular values are needed, */
  746. /* > and a scaled condition estimate requested; */
  747. /* > */
  748. /* > = N + MAX( LWQP3, LWSVD, LWORQ ) if the singular values and the left */
  749. /* > singular vectors are requested; */
  750. /* > = N + MAX( LWQP3, LWCON, LWSVD, LWORQ ) if the singular values and the left */
  751. /* > singular vectors are requested, and also */
  752. /* > a scaled condition estimate requested; */
  753. /* > */
  754. /* > = N + MAX( LWQP3, LWSVD ) if the singular values and the right */
  755. /* > singular vectors are requested; */
  756. /* > = N + MAX( LWQP3, LWCON, LWSVD ) if the singular values and the right */
  757. /* > singular vectors are requested, and also */
  758. /* > a scaled condition etimate requested; */
  759. /* > */
  760. /* > = N + MAX( LWQP3, LWSVD, LWORQ ) if the full SVD is requested with JOBV = 'R'; */
  761. /* > independent of JOBR; */
  762. /* > = N + MAX( LWQP3, LWCON, LWSVD, LWORQ ) if the full SVD is requested, */
  763. /* > JOBV = 'R' and, also a scaled condition */
  764. /* > estimate requested; independent of JOBR; */
  765. /* > = MAX( N + MAX( LWQP3, LWSVD, LWORQ ), */
  766. /* > N + MAX( LWQP3, N/2+LWLQF, N/2+LWSVD2, N/2+LWORLQ, LWORQ) ) if the */
  767. /* > full SVD is requested with JOBV = 'A' or 'V', and */
  768. /* > JOBR ='N' */
  769. /* > = MAX( N + MAX( LWQP3, LWCON, LWSVD, LWORQ ), */
  770. /* > N + MAX( LWQP3, LWCON, N/2+LWLQF, N/2+LWSVD2, N/2+LWORLQ, LWORQ ) ) */
  771. /* > if the full SVD is requested with JOBV = 'A' or 'V', and */
  772. /* > JOBR ='N', and also a scaled condition number estimate */
  773. /* > requested. */
  774. /* > = MAX( N + MAX( LWQP3, LWSVD, LWORQ ), */
  775. /* > N + MAX( LWQP3, N/2+LWQRF, N/2+LWSVD2, N/2+LWORQ2, LWORQ ) ) if the */
  776. /* > full SVD is requested with JOBV = 'A', 'V', and JOBR ='T' */
  777. /* > = MAX( N + MAX( LWQP3, LWCON, LWSVD, LWORQ ), */
  778. /* > N + MAX( LWQP3, LWCON, N/2+LWQRF, N/2+LWSVD2, N/2+LWORQ2, LWORQ ) ) */
  779. /* > if the full SVD is requested with JOBV = 'A' or 'V', and */
  780. /* > JOBR ='T', and also a scaled condition number estimate */
  781. /* > requested. */
  782. /* > Finally, LWORK must be at least two: LWORK = MAX( 2, LWORK ). */
  783. /* > */
  784. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  785. /* > only calculates and returns the optimal and minimal sizes */
  786. /* > for the WORK, IWORK, and RWORK arrays, and no error */
  787. /* > message related to LWORK is issued by XERBLA. */
  788. /* > \endverbatim */
  789. /* > */
  790. /* > \param[out] RWORK */
  791. /* > \verbatim */
  792. /* > RWORK is DOUBLE PRECISION array, dimension (f2cmax(1, LRWORK)). */
  793. /* > On exit, */
  794. /* > 1. If JOBA = 'E', RWORK(1) contains an estimate of the condition */
  795. /* > number of column scaled A. If A = C * D where D is diagonal and C */
  796. /* > has unit columns in the Euclidean norm, then, assuming full column rank, */
  797. /* > N^(-1/4) * RWORK(1) <= ||pinv(C)||_2 <= N^(1/4) * RWORK(1). */
  798. /* > Otherwise, RWORK(1) = -1. */
  799. /* > 2. RWORK(2) contains the number of singular values computed as */
  800. /* > exact zeros in DGESVD applied to the upper triangular or trapeziodal */
  801. /* > R (from the initial QR factorization). In case of early exit (no call to */
  802. /* > DGESVD, such as in the case of zero matrix) RWORK(2) = -1. */
  803. /* > */
  804. /* > If LIWORK, LWORK, or LRWORK = -1, then on exit, if INFO = 0, */
  805. /* > RWORK(1) returns the minimal LRWORK. */
  806. /* > \endverbatim */
  807. /* > */
  808. /* > \param[in] LRWORK */
  809. /* > \verbatim */
  810. /* > LRWORK is INTEGER. */
  811. /* > The dimension of the array RWORK. */
  812. /* > If JOBP ='P', then LRWORK >= MAX(2, M). */
  813. /* > Otherwise, LRWORK >= 2 */
  814. /* > If LRWORK = -1, then a workspace query is assumed; the routine */
  815. /* > only calculates and returns the optimal and minimal sizes */
  816. /* > for the WORK, IWORK, and RWORK arrays, and no error */
  817. /* > message related to LWORK is issued by XERBLA. */
  818. /* > \endverbatim */
  819. /* > */
  820. /* > \param[out] INFO */
  821. /* > \verbatim */
  822. /* > INFO is INTEGER */
  823. /* > = 0: successful exit. */
  824. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  825. /* > > 0: if DBDSQR did not converge, INFO specifies how many superdiagonals */
  826. /* > of an intermediate bidiagonal form B (computed in DGESVD) did not */
  827. /* > converge to zero. */
  828. /* > \endverbatim */
  829. /* > \par Further Details: */
  830. /* ======================== */
  831. /* > */
  832. /* > \verbatim */
  833. /* > */
  834. /* > 1. The data movement (matrix transpose) is coded using simple nested */
  835. /* > DO-loops because BLAS and LAPACK do not provide corresponding subroutines. */
  836. /* > Those DO-loops are easily identified in this source code - by the CONTINUE */
  837. /* > statements labeled with 11**. In an optimized version of this code, the */
  838. /* > nested DO loops should be replaced with calls to an optimized subroutine. */
  839. /* > 2. This code scales A by 1/SQRT(M) if the largest ABS(A(i,j)) could cause */
  840. /* > column norm overflow. This is the minial precaution and it is left to the */
  841. /* > SVD routine (CGESVD) to do its own preemptive scaling if potential over- */
  842. /* > or underflows are detected. To avoid repeated scanning of the array A, */
  843. /* > an optimal implementation would do all necessary scaling before calling */
  844. /* > CGESVD and the scaling in CGESVD can be switched off. */
  845. /* > 3. Other comments related to code optimization are given in comments in the */
  846. /* > code, enlosed in [[double brackets]]. */
  847. /* > \endverbatim */
  848. /* > \par Bugs, examples and comments */
  849. /* =========================== */
  850. /* > \verbatim */
  851. /* > Please report all bugs and send interesting examples and/or comments to */
  852. /* > drmac@math.hr. Thank you. */
  853. /* > \endverbatim */
  854. /* > \par References */
  855. /* =============== */
  856. /* > \verbatim */
  857. /* > [1] Zlatko Drmac, Algorithm 977: A QR-Preconditioned QR SVD Method for */
  858. /* > Computing the SVD with High Accuracy. ACM Trans. Math. Softw. */
  859. /* > 44(1): 11:1-11:30 (2017) */
  860. /* > */
  861. /* > SIGMA library, xGESVDQ section updated February 2016. */
  862. /* > Developed and coded by Zlatko Drmac, Department of Mathematics */
  863. /* > University of Zagreb, Croatia, drmac@math.hr */
  864. /* > \endverbatim */
  865. /* > \par Contributors: */
  866. /* ================== */
  867. /* > */
  868. /* > \verbatim */
  869. /* > Developed and coded by Zlatko Drmac, Department of Mathematics */
  870. /* > University of Zagreb, Croatia, drmac@math.hr */
  871. /* > \endverbatim */
  872. /* Authors: */
  873. /* ======== */
  874. /* > \author Univ. of Tennessee */
  875. /* > \author Univ. of California Berkeley */
  876. /* > \author Univ. of Colorado Denver */
  877. /* > \author NAG Ltd. */
  878. /* > \date November 2018 */
  879. /* > \ingroup doubleGEsing */
  880. /* ===================================================================== */
  881. /* Subroutine */ void dgesvdq_(char *joba, char *jobp, char *jobr, char *jobu,
  882. char *jobv, integer *m, integer *n, doublereal *a, integer *lda,
  883. doublereal *s, doublereal *u, integer *ldu, doublereal *v, integer *
  884. ldv, integer *numrank, integer *iwork, integer *liwork, doublereal *
  885. work, integer *lwork, doublereal *rwork, integer *lrwork, integer *
  886. info)
  887. {
  888. /* System generated locals */
  889. integer a_dim1, a_offset, u_dim1, u_offset, v_dim1, v_offset, i__1, i__2;
  890. doublereal d__1, d__2, d__3;
  891. /* Local variables */
  892. integer lwrk_dormqr__, lwrk_dgesvd2__, ierr, lwrk_dormqr2__;
  893. doublereal rtmp;
  894. integer optratio;
  895. extern doublereal dnrm2_(integer *, doublereal *, integer *);
  896. logical lsvc0, accla;
  897. integer lwqp3;
  898. logical acclh, acclm;
  899. integer p, q;
  900. logical conda;
  901. extern /* Subroutine */ void dscal_(integer *, doublereal *, doublereal *,
  902. integer *);
  903. extern logical lsame_(char *, char *);
  904. integer iwoff;
  905. logical lsvec;
  906. doublereal sfmin, epsln;
  907. integer lwcon;
  908. logical rsvec;
  909. integer lwlqf, lwqrf, n1, lwsvd;
  910. logical dntwu, dntwv, wntua;
  911. integer lworq;
  912. logical wntuf, wntva, wntur, wntus, wntvr;
  913. extern /* Subroutine */ void dgeqp3_(integer *, integer *, doublereal *,
  914. integer *, integer *, doublereal *, doublereal *, integer *,
  915. integer *);
  916. integer lwsvd2, lworq2;
  917. extern doublereal dlamch_(char *), dlange_(char *, integer *,
  918. integer *, doublereal *, integer *, doublereal *);
  919. integer nr;
  920. extern /* Subroutine */ void dgelqf_(integer *, integer *, doublereal *,
  921. integer *, doublereal *, doublereal *, integer *, integer *),
  922. dlascl_(char *, integer *, integer *, doublereal *, doublereal *,
  923. integer *, integer *, doublereal *, integer *, integer *);
  924. extern integer idamax_(integer *, doublereal *, integer *);
  925. doublereal sconda;
  926. extern /* Subroutine */ void dgeqrf_(integer *, integer *, doublereal *,
  927. integer *, doublereal *, doublereal *, integer *, integer *),
  928. dgesvd_(char *, char *, integer *, integer *, doublereal *,
  929. integer *, doublereal *, doublereal *, integer *, doublereal *,
  930. integer *, doublereal *, integer *, integer *),
  931. dlacpy_(char *, integer *, integer *, doublereal *, integer *,
  932. doublereal *, integer *), dlaset_(char *, integer *,
  933. integer *, doublereal *, doublereal *, doublereal *, integer *);
  934. extern int xerbla_(char *, integer *, ftnlen);
  935. extern void dlapmt_(logical *,
  936. integer *, integer *, doublereal *, integer *, integer *),
  937. dpocon_(char *, integer *, doublereal *, integer *, doublereal *,
  938. doublereal *, doublereal *, integer *, integer *);
  939. extern int dlaswp_(integer *, doublereal *, integer *, integer *, integer *,
  940. integer *, integer *);
  941. extern void dormlq_(char *, char *, integer *, integer
  942. *, integer *, doublereal *, integer *, doublereal *, doublereal *,
  943. integer *, doublereal *, integer *, integer *),
  944. dormqr_(char *, char *, integer *, integer *, integer *,
  945. doublereal *, integer *, doublereal *, doublereal *, integer *,
  946. doublereal *, integer *, integer *);
  947. integer minwrk;
  948. logical rtrans;
  949. doublereal rdummy[1];
  950. integer lworlq;
  951. logical lquery;
  952. integer optwrk;
  953. logical rowprm;
  954. doublereal big;
  955. integer minwrk2;
  956. logical ascaled;
  957. integer lwrk_dgeqp3__, optwrk2, lwrk_dgelqf__, iminwrk, lwrk_dgeqrf__,
  958. rminwrk, lwrk_dgesvd__, lwrk_dormlq__;
  959. /* ===================================================================== */
  960. /* Test the input arguments */
  961. /* Parameter adjustments */
  962. a_dim1 = *lda;
  963. a_offset = 1 + a_dim1 * 1;
  964. a -= a_offset;
  965. --s;
  966. u_dim1 = *ldu;
  967. u_offset = 1 + u_dim1 * 1;
  968. u -= u_offset;
  969. v_dim1 = *ldv;
  970. v_offset = 1 + v_dim1 * 1;
  971. v -= v_offset;
  972. --iwork;
  973. --work;
  974. --rwork;
  975. /* Function Body */
  976. wntus = lsame_(jobu, "S") || lsame_(jobu, "U");
  977. wntur = lsame_(jobu, "R");
  978. wntua = lsame_(jobu, "A");
  979. wntuf = lsame_(jobu, "F");
  980. lsvc0 = wntus || wntur || wntua;
  981. lsvec = lsvc0 || wntuf;
  982. dntwu = lsame_(jobu, "N");
  983. wntvr = lsame_(jobv, "R");
  984. wntva = lsame_(jobv, "A") || lsame_(jobv, "V");
  985. rsvec = wntvr || wntva;
  986. dntwv = lsame_(jobv, "N");
  987. accla = lsame_(joba, "A");
  988. acclm = lsame_(joba, "M");
  989. conda = lsame_(joba, "E");
  990. acclh = lsame_(joba, "H") || conda;
  991. rowprm = lsame_(jobp, "P");
  992. rtrans = lsame_(jobr, "T");
  993. if (rowprm) {
  994. if (conda) {
  995. /* Computing MAX */
  996. i__1 = 1, i__2 = *n + *m - 1 + *n;
  997. iminwrk = f2cmax(i__1,i__2);
  998. } else {
  999. /* Computing MAX */
  1000. i__1 = 1, i__2 = *n + *m - 1;
  1001. iminwrk = f2cmax(i__1,i__2);
  1002. }
  1003. rminwrk = f2cmax(2,*m);
  1004. } else {
  1005. if (conda) {
  1006. /* Computing MAX */
  1007. i__1 = 1, i__2 = *n + *n;
  1008. iminwrk = f2cmax(i__1,i__2);
  1009. } else {
  1010. iminwrk = f2cmax(1,*n);
  1011. }
  1012. rminwrk = 2;
  1013. }
  1014. lquery = *liwork == -1 || *lwork == -1 || *lrwork == -1;
  1015. *info = 0;
  1016. if (! (accla || acclm || acclh)) {
  1017. *info = -1;
  1018. } else if (! (rowprm || lsame_(jobp, "N"))) {
  1019. *info = -2;
  1020. } else if (! (rtrans || lsame_(jobr, "N"))) {
  1021. *info = -3;
  1022. } else if (! (lsvec || dntwu)) {
  1023. *info = -4;
  1024. } else if (wntur && wntva) {
  1025. *info = -5;
  1026. } else if (! (rsvec || dntwv)) {
  1027. *info = -5;
  1028. } else if (*m < 0) {
  1029. *info = -6;
  1030. } else if (*n < 0 || *n > *m) {
  1031. *info = -7;
  1032. } else if (*lda < f2cmax(1,*m)) {
  1033. *info = -9;
  1034. } else if (*ldu < 1 || lsvc0 && *ldu < *m || wntuf && *ldu < *n) {
  1035. *info = -12;
  1036. } else if (*ldv < 1 || rsvec && *ldv < *n || conda && *ldv < *n) {
  1037. *info = -14;
  1038. } else if (*liwork < iminwrk && ! lquery) {
  1039. *info = -17;
  1040. }
  1041. if (*info == 0) {
  1042. /* [[The expressions for computing the minimal and the optimal */
  1043. /* values of LWORK are written with a lot of redundancy and */
  1044. /* can be simplified. However, this detailed form is easier for */
  1045. /* maintenance and modifications of the code.]] */
  1046. lwqp3 = *n * 3 + 1;
  1047. if (wntus || wntur) {
  1048. lworq = f2cmax(*n,1);
  1049. } else if (wntua) {
  1050. lworq = f2cmax(*m,1);
  1051. }
  1052. lwcon = *n * 3;
  1053. /* Computing MAX */
  1054. i__1 = *n * 5;
  1055. lwsvd = f2cmax(i__1,1);
  1056. if (lquery) {
  1057. dgeqp3_(m, n, &a[a_offset], lda, &iwork[1], rdummy, rdummy, &c_n1,
  1058. &ierr);
  1059. lwrk_dgeqp3__ = (integer) rdummy[0];
  1060. if (wntus || wntur) {
  1061. dormqr_("L", "N", m, n, n, &a[a_offset], lda, rdummy, &u[
  1062. u_offset], ldu, rdummy, &c_n1, &ierr);
  1063. lwrk_dormqr__ = (integer) rdummy[0];
  1064. } else if (wntua) {
  1065. dormqr_("L", "N", m, m, n, &a[a_offset], lda, rdummy, &u[
  1066. u_offset], ldu, rdummy, &c_n1, &ierr);
  1067. lwrk_dormqr__ = (integer) rdummy[0];
  1068. } else {
  1069. lwrk_dormqr__ = 0;
  1070. }
  1071. }
  1072. minwrk = 2;
  1073. optwrk = 2;
  1074. if (! (lsvec || rsvec)) {
  1075. /* only the singular values are requested */
  1076. if (conda) {
  1077. /* Computing MAX */
  1078. i__1 = *n + lwqp3, i__1 = f2cmax(i__1,lwcon);
  1079. minwrk = f2cmax(i__1,lwsvd);
  1080. } else {
  1081. /* Computing MAX */
  1082. i__1 = *n + lwqp3;
  1083. minwrk = f2cmax(i__1,lwsvd);
  1084. }
  1085. if (lquery) {
  1086. dgesvd_("N", "N", n, n, &a[a_offset], lda, &s[1], &u[u_offset]
  1087. , ldu, &v[v_offset], ldv, rdummy, &c_n1, &ierr);
  1088. lwrk_dgesvd__ = (integer) rdummy[0];
  1089. if (conda) {
  1090. /* Computing MAX */
  1091. i__1 = *n + lwrk_dgeqp3__, i__2 = *n + lwcon, i__1 = f2cmax(
  1092. i__1,i__2);
  1093. optwrk = f2cmax(i__1,lwrk_dgesvd__);
  1094. } else {
  1095. /* Computing MAX */
  1096. i__1 = *n + lwrk_dgeqp3__;
  1097. optwrk = f2cmax(i__1,lwrk_dgesvd__);
  1098. }
  1099. }
  1100. } else if (lsvec && ! rsvec) {
  1101. /* singular values and the left singular vectors are requested */
  1102. if (conda) {
  1103. /* Computing MAX */
  1104. i__1 = f2cmax(lwqp3,lwcon), i__1 = f2cmax(i__1,lwsvd);
  1105. minwrk = *n + f2cmax(i__1,lworq);
  1106. } else {
  1107. /* Computing MAX */
  1108. i__1 = f2cmax(lwqp3,lwsvd);
  1109. minwrk = *n + f2cmax(i__1,lworq);
  1110. }
  1111. if (lquery) {
  1112. if (rtrans) {
  1113. dgesvd_("N", "O", n, n, &a[a_offset], lda, &s[1], &u[
  1114. u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
  1115. &ierr);
  1116. } else {
  1117. dgesvd_("O", "N", n, n, &a[a_offset], lda, &s[1], &u[
  1118. u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
  1119. &ierr);
  1120. }
  1121. lwrk_dgesvd__ = (integer) rdummy[0];
  1122. if (conda) {
  1123. /* Computing MAX */
  1124. i__1 = f2cmax(lwrk_dgeqp3__,lwcon), i__1 = f2cmax(i__1,
  1125. lwrk_dgesvd__);
  1126. optwrk = *n + f2cmax(i__1,lwrk_dormqr__);
  1127. } else {
  1128. /* Computing MAX */
  1129. i__1 = f2cmax(lwrk_dgeqp3__,lwrk_dgesvd__);
  1130. optwrk = *n + f2cmax(i__1,lwrk_dormqr__);
  1131. }
  1132. }
  1133. } else if (rsvec && ! lsvec) {
  1134. /* singular values and the right singular vectors are requested */
  1135. if (conda) {
  1136. /* Computing MAX */
  1137. i__1 = f2cmax(lwqp3,lwcon);
  1138. minwrk = *n + f2cmax(i__1,lwsvd);
  1139. } else {
  1140. minwrk = *n + f2cmax(lwqp3,lwsvd);
  1141. }
  1142. if (lquery) {
  1143. if (rtrans) {
  1144. dgesvd_("O", "N", n, n, &a[a_offset], lda, &s[1], &u[
  1145. u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
  1146. &ierr);
  1147. } else {
  1148. dgesvd_("N", "O", n, n, &a[a_offset], lda, &s[1], &u[
  1149. u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
  1150. &ierr);
  1151. }
  1152. lwrk_dgesvd__ = (integer) rdummy[0];
  1153. if (conda) {
  1154. /* Computing MAX */
  1155. i__1 = f2cmax(lwrk_dgeqp3__,lwcon);
  1156. optwrk = *n + f2cmax(i__1,lwrk_dgesvd__);
  1157. } else {
  1158. optwrk = *n + f2cmax(lwrk_dgeqp3__,lwrk_dgesvd__);
  1159. }
  1160. }
  1161. } else {
  1162. /* full SVD is requested */
  1163. if (rtrans) {
  1164. /* Computing MAX */
  1165. i__1 = f2cmax(lwqp3,lwsvd);
  1166. minwrk = f2cmax(i__1,lworq);
  1167. if (conda) {
  1168. minwrk = f2cmax(minwrk,lwcon);
  1169. }
  1170. minwrk += *n;
  1171. if (wntva) {
  1172. /* Computing MAX */
  1173. i__1 = *n / 2;
  1174. lwqrf = f2cmax(i__1,1);
  1175. /* Computing MAX */
  1176. i__1 = *n / 2 * 5;
  1177. lwsvd2 = f2cmax(i__1,1);
  1178. lworq2 = f2cmax(*n,1);
  1179. /* Computing MAX */
  1180. i__1 = lwqp3, i__2 = *n / 2 + lwqrf, i__1 = f2cmax(i__1,i__2)
  1181. , i__2 = *n / 2 + lwsvd2, i__1 = f2cmax(i__1,i__2),
  1182. i__2 = *n / 2 + lworq2, i__1 = f2cmax(i__1,i__2);
  1183. minwrk2 = f2cmax(i__1,lworq);
  1184. if (conda) {
  1185. minwrk2 = f2cmax(minwrk2,lwcon);
  1186. }
  1187. minwrk2 = *n + minwrk2;
  1188. minwrk = f2cmax(minwrk,minwrk2);
  1189. }
  1190. } else {
  1191. /* Computing MAX */
  1192. i__1 = f2cmax(lwqp3,lwsvd);
  1193. minwrk = f2cmax(i__1,lworq);
  1194. if (conda) {
  1195. minwrk = f2cmax(minwrk,lwcon);
  1196. }
  1197. minwrk += *n;
  1198. if (wntva) {
  1199. /* Computing MAX */
  1200. i__1 = *n / 2;
  1201. lwlqf = f2cmax(i__1,1);
  1202. /* Computing MAX */
  1203. i__1 = *n / 2 * 5;
  1204. lwsvd2 = f2cmax(i__1,1);
  1205. lworlq = f2cmax(*n,1);
  1206. /* Computing MAX */
  1207. i__1 = lwqp3, i__2 = *n / 2 + lwlqf, i__1 = f2cmax(i__1,i__2)
  1208. , i__2 = *n / 2 + lwsvd2, i__1 = f2cmax(i__1,i__2),
  1209. i__2 = *n / 2 + lworlq, i__1 = f2cmax(i__1,i__2);
  1210. minwrk2 = f2cmax(i__1,lworq);
  1211. if (conda) {
  1212. minwrk2 = f2cmax(minwrk2,lwcon);
  1213. }
  1214. minwrk2 = *n + minwrk2;
  1215. minwrk = f2cmax(minwrk,minwrk2);
  1216. }
  1217. }
  1218. if (lquery) {
  1219. if (rtrans) {
  1220. dgesvd_("O", "A", n, n, &a[a_offset], lda, &s[1], &u[
  1221. u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
  1222. &ierr);
  1223. lwrk_dgesvd__ = (integer) rdummy[0];
  1224. /* Computing MAX */
  1225. i__1 = f2cmax(lwrk_dgeqp3__,lwrk_dgesvd__);
  1226. optwrk = f2cmax(i__1,lwrk_dormqr__);
  1227. if (conda) {
  1228. optwrk = f2cmax(optwrk,lwcon);
  1229. }
  1230. optwrk = *n + optwrk;
  1231. if (wntva) {
  1232. i__1 = *n / 2;
  1233. dgeqrf_(n, &i__1, &u[u_offset], ldu, rdummy, rdummy, &
  1234. c_n1, &ierr);
  1235. lwrk_dgeqrf__ = (integer) rdummy[0];
  1236. i__1 = *n / 2;
  1237. i__2 = *n / 2;
  1238. dgesvd_("S", "O", &i__1, &i__2, &v[v_offset], ldv, &s[
  1239. 1], &u[u_offset], ldu, &v[v_offset], ldv,
  1240. rdummy, &c_n1, &ierr);
  1241. lwrk_dgesvd2__ = (integer) rdummy[0];
  1242. i__1 = *n / 2;
  1243. dormqr_("R", "C", n, n, &i__1, &u[u_offset], ldu,
  1244. rdummy, &v[v_offset], ldv, rdummy, &c_n1, &
  1245. ierr);
  1246. lwrk_dormqr2__ = (integer) rdummy[0];
  1247. /* Computing MAX */
  1248. i__1 = lwrk_dgeqp3__, i__2 = *n / 2 + lwrk_dgeqrf__,
  1249. i__1 = f2cmax(i__1,i__2), i__2 = *n / 2 +
  1250. lwrk_dgesvd2__, i__1 = f2cmax(i__1,i__2), i__2 =
  1251. *n / 2 + lwrk_dormqr2__;
  1252. optwrk2 = f2cmax(i__1,i__2);
  1253. if (conda) {
  1254. optwrk2 = f2cmax(optwrk2,lwcon);
  1255. }
  1256. optwrk2 = *n + optwrk2;
  1257. optwrk = f2cmax(optwrk,optwrk2);
  1258. }
  1259. } else {
  1260. dgesvd_("S", "O", n, n, &a[a_offset], lda, &s[1], &u[
  1261. u_offset], ldu, &v[v_offset], ldv, rdummy, &c_n1,
  1262. &ierr);
  1263. lwrk_dgesvd__ = (integer) rdummy[0];
  1264. /* Computing MAX */
  1265. i__1 = f2cmax(lwrk_dgeqp3__,lwrk_dgesvd__);
  1266. optwrk = f2cmax(i__1,lwrk_dormqr__);
  1267. if (conda) {
  1268. optwrk = f2cmax(optwrk,lwcon);
  1269. }
  1270. optwrk = *n + optwrk;
  1271. if (wntva) {
  1272. i__1 = *n / 2;
  1273. dgelqf_(&i__1, n, &u[u_offset], ldu, rdummy, rdummy, &
  1274. c_n1, &ierr);
  1275. lwrk_dgelqf__ = (integer) rdummy[0];
  1276. i__1 = *n / 2;
  1277. i__2 = *n / 2;
  1278. dgesvd_("S", "O", &i__1, &i__2, &v[v_offset], ldv, &s[
  1279. 1], &u[u_offset], ldu, &v[v_offset], ldv,
  1280. rdummy, &c_n1, &ierr);
  1281. lwrk_dgesvd2__ = (integer) rdummy[0];
  1282. i__1 = *n / 2;
  1283. dormlq_("R", "N", n, n, &i__1, &u[u_offset], ldu,
  1284. rdummy, &v[v_offset], ldv, rdummy, &c_n1, &
  1285. ierr);
  1286. lwrk_dormlq__ = (integer) rdummy[0];
  1287. /* Computing MAX */
  1288. i__1 = lwrk_dgeqp3__, i__2 = *n / 2 + lwrk_dgelqf__,
  1289. i__1 = f2cmax(i__1,i__2), i__2 = *n / 2 +
  1290. lwrk_dgesvd2__, i__1 = f2cmax(i__1,i__2), i__2 =
  1291. *n / 2 + lwrk_dormlq__;
  1292. optwrk2 = f2cmax(i__1,i__2);
  1293. if (conda) {
  1294. optwrk2 = f2cmax(optwrk2,lwcon);
  1295. }
  1296. optwrk2 = *n + optwrk2;
  1297. optwrk = f2cmax(optwrk,optwrk2);
  1298. }
  1299. }
  1300. }
  1301. }
  1302. minwrk = f2cmax(2,minwrk);
  1303. optwrk = f2cmax(2,optwrk);
  1304. if (*lwork < minwrk && ! lquery) {
  1305. *info = -19;
  1306. }
  1307. }
  1308. if (*info == 0 && *lrwork < rminwrk && ! lquery) {
  1309. *info = -21;
  1310. }
  1311. if (*info != 0) {
  1312. i__1 = -(*info);
  1313. xerbla_("DGESVDQ", &i__1, (ftnlen)7);
  1314. return;
  1315. } else if (lquery) {
  1316. /* Return optimal workspace */
  1317. iwork[1] = iminwrk;
  1318. work[1] = (doublereal) optwrk;
  1319. work[2] = (doublereal) minwrk;
  1320. rwork[1] = (doublereal) rminwrk;
  1321. return;
  1322. }
  1323. /* Quick return if the matrix is void. */
  1324. if (*m == 0 || *n == 0) {
  1325. return;
  1326. }
  1327. big = dlamch_("O");
  1328. ascaled = FALSE_;
  1329. iwoff = 1;
  1330. if (rowprm) {
  1331. iwoff = *m;
  1332. /* ell-infinity norm - this enhances numerical robustness in */
  1333. /* the case of differently scaled rows. */
  1334. i__1 = *m;
  1335. for (p = 1; p <= i__1; ++p) {
  1336. /* RWORK(p) = ABS( A(p,ICAMAX(N,A(p,1),LDA)) ) */
  1337. /* [[DLANGE will return NaN if an entry of the p-th row is Nan]] */
  1338. rwork[p] = dlange_("M", &c__1, n, &a[p + a_dim1], lda, rdummy);
  1339. if (rwork[p] != rwork[p] || rwork[p] * 0. != 0.) {
  1340. *info = -8;
  1341. i__2 = -(*info);
  1342. xerbla_("DGESVDQ", &i__2, (ftnlen)7);
  1343. return;
  1344. }
  1345. /* L1904: */
  1346. }
  1347. i__1 = *m - 1;
  1348. for (p = 1; p <= i__1; ++p) {
  1349. i__2 = *m - p + 1;
  1350. q = idamax_(&i__2, &rwork[p], &c__1) + p - 1;
  1351. iwork[*n + p] = q;
  1352. if (p != q) {
  1353. rtmp = rwork[p];
  1354. rwork[p] = rwork[q];
  1355. rwork[q] = rtmp;
  1356. }
  1357. /* L1952: */
  1358. }
  1359. if (rwork[1] == 0.) {
  1360. /* Quick return: A is the M x N zero matrix. */
  1361. *numrank = 0;
  1362. dlaset_("G", n, &c__1, &c_b72, &c_b72, &s[1], n);
  1363. if (wntus) {
  1364. dlaset_("G", m, n, &c_b72, &c_b76, &u[u_offset], ldu);
  1365. }
  1366. if (wntua) {
  1367. dlaset_("G", m, m, &c_b72, &c_b76, &u[u_offset], ldu);
  1368. }
  1369. if (wntva) {
  1370. dlaset_("G", n, n, &c_b72, &c_b76, &v[v_offset], ldv);
  1371. }
  1372. if (wntuf) {
  1373. dlaset_("G", n, &c__1, &c_b72, &c_b72, &work[1], n)
  1374. ;
  1375. dlaset_("G", m, n, &c_b72, &c_b76, &u[u_offset], ldu);
  1376. }
  1377. i__1 = *n;
  1378. for (p = 1; p <= i__1; ++p) {
  1379. iwork[p] = p;
  1380. /* L5001: */
  1381. }
  1382. if (rowprm) {
  1383. i__1 = *n + *m - 1;
  1384. for (p = *n + 1; p <= i__1; ++p) {
  1385. iwork[p] = p - *n;
  1386. /* L5002: */
  1387. }
  1388. }
  1389. if (conda) {
  1390. rwork[1] = -1.;
  1391. }
  1392. rwork[2] = -1.;
  1393. return;
  1394. }
  1395. if (rwork[1] > big / sqrt((doublereal) (*m))) {
  1396. /* matrix by 1/sqrt(M) if too large entry detected */
  1397. d__1 = sqrt((doublereal) (*m));
  1398. dlascl_("G", &c__0, &c__0, &d__1, &c_b76, m, n, &a[a_offset], lda,
  1399. &ierr);
  1400. ascaled = TRUE_;
  1401. }
  1402. i__1 = *m - 1;
  1403. dlaswp_(n, &a[a_offset], lda, &c__1, &i__1, &iwork[*n + 1], &c__1);
  1404. }
  1405. /* norms overflows during the QR factorization. The SVD procedure should */
  1406. /* have its own scaling to save the singular values from overflows and */
  1407. /* underflows. That depends on the SVD procedure. */
  1408. if (! rowprm) {
  1409. rtmp = dlange_("M", m, n, &a[a_offset], lda, rdummy);
  1410. if (rtmp != rtmp || rtmp * 0. != 0.) {
  1411. *info = -8;
  1412. i__1 = -(*info);
  1413. xerbla_("DGESVDQ", &i__1, (ftnlen)7);
  1414. return;
  1415. }
  1416. if (rtmp > big / sqrt((doublereal) (*m))) {
  1417. /* matrix by 1/sqrt(M) if too large entry detected */
  1418. d__1 = sqrt((doublereal) (*m));
  1419. dlascl_("G", &c__0, &c__0, &d__1, &c_b76, m, n, &a[a_offset], lda,
  1420. &ierr);
  1421. ascaled = TRUE_;
  1422. }
  1423. }
  1424. /* A * P = Q * [ R ] */
  1425. /* [ 0 ] */
  1426. i__1 = *n;
  1427. for (p = 1; p <= i__1; ++p) {
  1428. iwork[p] = 0;
  1429. /* L1963: */
  1430. }
  1431. i__1 = *lwork - *n;
  1432. dgeqp3_(m, n, &a[a_offset], lda, &iwork[1], &work[1], &work[*n + 1], &
  1433. i__1, &ierr);
  1434. /* If the user requested accuracy level allows truncation in the */
  1435. /* computed upper triangular factor, the matrix R is examined and, */
  1436. /* if possible, replaced with its leading upper trapezoidal part. */
  1437. epsln = dlamch_("E");
  1438. sfmin = dlamch_("S");
  1439. /* SMALL = SFMIN / EPSLN */
  1440. nr = *n;
  1441. if (accla) {
  1442. /* Standard absolute error bound suffices. All sigma_i with */
  1443. /* sigma_i < N*EPS*||A||_F are flushed to zero. This is an */
  1444. /* aggressive enforcement of lower numerical rank by introducing a */
  1445. /* backward error of the order of N*EPS*||A||_F. */
  1446. nr = 1;
  1447. rtmp = sqrt((doublereal) (*n)) * epsln;
  1448. i__1 = *n;
  1449. for (p = 2; p <= i__1; ++p) {
  1450. if ((d__2 = a[p + p * a_dim1], abs(d__2)) < rtmp * (d__1 = a[
  1451. a_dim1 + 1], abs(d__1))) {
  1452. goto L3002;
  1453. }
  1454. ++nr;
  1455. /* L3001: */
  1456. }
  1457. L3002:
  1458. ;
  1459. } else if (acclm) {
  1460. /* Sudden drop on the diagonal of R is used as the criterion for being */
  1461. /* close-to-rank-deficient. The threshold is set to EPSLN=DLAMCH('E'). */
  1462. /* [[This can be made more flexible by replacing this hard-coded value */
  1463. /* with a user specified threshold.]] Also, the values that underflow */
  1464. /* will be truncated. */
  1465. nr = 1;
  1466. i__1 = *n;
  1467. for (p = 2; p <= i__1; ++p) {
  1468. if ((d__2 = a[p + p * a_dim1], abs(d__2)) < epsln * (d__1 = a[p -
  1469. 1 + (p - 1) * a_dim1], abs(d__1)) || (d__3 = a[p + p *
  1470. a_dim1], abs(d__3)) < sfmin) {
  1471. goto L3402;
  1472. }
  1473. ++nr;
  1474. /* L3401: */
  1475. }
  1476. L3402:
  1477. ;
  1478. } else {
  1479. /* obvious case of zero pivots. */
  1480. /* R(i,i)=0 => R(i:N,i:N)=0. */
  1481. nr = 1;
  1482. i__1 = *n;
  1483. for (p = 2; p <= i__1; ++p) {
  1484. if ((d__1 = a[p + p * a_dim1], abs(d__1)) == 0.) {
  1485. goto L3502;
  1486. }
  1487. ++nr;
  1488. /* L3501: */
  1489. }
  1490. L3502:
  1491. if (conda) {
  1492. /* Estimate the scaled condition number of A. Use the fact that it is */
  1493. /* the same as the scaled condition number of R. */
  1494. dlacpy_("U", n, n, &a[a_offset], lda, &v[v_offset], ldv);
  1495. /* Only the leading NR x NR submatrix of the triangular factor */
  1496. /* is considered. Only if NR=N will this give a reliable error */
  1497. /* bound. However, even for NR < N, this can be used on an */
  1498. /* expert level and obtain useful information in the sense of */
  1499. /* perturbation theory. */
  1500. i__1 = nr;
  1501. for (p = 1; p <= i__1; ++p) {
  1502. rtmp = dnrm2_(&p, &v[p * v_dim1 + 1], &c__1);
  1503. d__1 = 1. / rtmp;
  1504. dscal_(&p, &d__1, &v[p * v_dim1 + 1], &c__1);
  1505. /* L3053: */
  1506. }
  1507. if (! (lsvec || rsvec)) {
  1508. dpocon_("U", &nr, &v[v_offset], ldv, &c_b76, &rtmp, &work[1],
  1509. &iwork[*n + iwoff], &ierr);
  1510. } else {
  1511. dpocon_("U", &nr, &v[v_offset], ldv, &c_b76, &rtmp, &work[*n
  1512. + 1], &iwork[*n + iwoff], &ierr);
  1513. }
  1514. sconda = 1. / sqrt(rtmp);
  1515. /* For NR=N, SCONDA is an estimate of SQRT(||(R^* * R)^(-1)||_1), */
  1516. /* N^(-1/4) * SCONDA <= ||R^(-1)||_2 <= N^(1/4) * SCONDA */
  1517. /* See the reference [1] for more details. */
  1518. }
  1519. }
  1520. if (wntur) {
  1521. n1 = nr;
  1522. } else if (wntus || wntuf) {
  1523. n1 = *n;
  1524. } else if (wntua) {
  1525. n1 = *m;
  1526. }
  1527. if (! (rsvec || lsvec)) {
  1528. /* ....................................................................... */
  1529. /* ....................................................................... */
  1530. if (rtrans) {
  1531. /* the upper triangle of [A] to zero. */
  1532. i__1 = f2cmin(*n,nr);
  1533. for (p = 1; p <= i__1; ++p) {
  1534. i__2 = *n;
  1535. for (q = p + 1; q <= i__2; ++q) {
  1536. a[q + p * a_dim1] = a[p + q * a_dim1];
  1537. if (q <= nr) {
  1538. a[p + q * a_dim1] = 0.;
  1539. }
  1540. /* L1147: */
  1541. }
  1542. /* L1146: */
  1543. }
  1544. dgesvd_("N", "N", n, &nr, &a[a_offset], lda, &s[1], &u[u_offset],
  1545. ldu, &v[v_offset], ldv, &work[1], lwork, info);
  1546. } else {
  1547. if (nr > 1) {
  1548. i__1 = nr - 1;
  1549. i__2 = nr - 1;
  1550. dlaset_("L", &i__1, &i__2, &c_b72, &c_b72, &a[a_dim1 + 2],
  1551. lda);
  1552. }
  1553. dgesvd_("N", "N", &nr, n, &a[a_offset], lda, &s[1], &u[u_offset],
  1554. ldu, &v[v_offset], ldv, &work[1], lwork, info);
  1555. }
  1556. } else if (lsvec && ! rsvec) {
  1557. /* ....................................................................... */
  1558. /* ......................................................................."""""""" */
  1559. if (rtrans) {
  1560. /* vectors of R */
  1561. i__1 = nr;
  1562. for (p = 1; p <= i__1; ++p) {
  1563. i__2 = *n;
  1564. for (q = p; q <= i__2; ++q) {
  1565. u[q + p * u_dim1] = a[p + q * a_dim1];
  1566. /* L1193: */
  1567. }
  1568. /* L1192: */
  1569. }
  1570. if (nr > 1) {
  1571. i__1 = nr - 1;
  1572. i__2 = nr - 1;
  1573. dlaset_("U", &i__1, &i__2, &c_b72, &c_b72, &u[(u_dim1 << 1) +
  1574. 1], ldu);
  1575. }
  1576. /* vectors overwrite [U](1:NR,1:NR) as transposed. These */
  1577. /* will be pre-multiplied by Q to build the left singular vectors of A. */
  1578. i__1 = *lwork - *n;
  1579. dgesvd_("N", "O", n, &nr, &u[u_offset], ldu, &s[1], &u[u_offset],
  1580. ldu, &u[u_offset], ldu, &work[*n + 1], &i__1, info);
  1581. i__1 = nr;
  1582. for (p = 1; p <= i__1; ++p) {
  1583. i__2 = nr;
  1584. for (q = p + 1; q <= i__2; ++q) {
  1585. rtmp = u[q + p * u_dim1];
  1586. u[q + p * u_dim1] = u[p + q * u_dim1];
  1587. u[p + q * u_dim1] = rtmp;
  1588. /* L1120: */
  1589. }
  1590. /* L1119: */
  1591. }
  1592. } else {
  1593. dlacpy_("U", &nr, n, &a[a_offset], lda, &u[u_offset], ldu);
  1594. if (nr > 1) {
  1595. i__1 = nr - 1;
  1596. i__2 = nr - 1;
  1597. dlaset_("L", &i__1, &i__2, &c_b72, &c_b72, &u[u_dim1 + 2],
  1598. ldu);
  1599. }
  1600. /* vectors overwrite [U](1:NR,1:NR) */
  1601. i__1 = *lwork - *n;
  1602. dgesvd_("O", "N", &nr, n, &u[u_offset], ldu, &s[1], &u[u_offset],
  1603. ldu, &v[v_offset], ldv, &work[*n + 1], &i__1, info);
  1604. /* R. These will be pre-multiplied by Q to build the left singular */
  1605. /* vectors of A. */
  1606. }
  1607. /* (M x NR) or (M x N) or (M x M). */
  1608. if (nr < *m && ! wntuf) {
  1609. i__1 = *m - nr;
  1610. dlaset_("A", &i__1, &nr, &c_b72, &c_b72, &u[nr + 1 + u_dim1], ldu);
  1611. if (nr < n1) {
  1612. i__1 = n1 - nr;
  1613. dlaset_("A", &nr, &i__1, &c_b72, &c_b72, &u[(nr + 1) * u_dim1
  1614. + 1], ldu);
  1615. i__1 = *m - nr;
  1616. i__2 = n1 - nr;
  1617. dlaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[nr + 1 + (nr +
  1618. 1) * u_dim1], ldu);
  1619. }
  1620. }
  1621. /* The Q matrix from the first QRF is built into the left singular */
  1622. /* vectors matrix U. */
  1623. if (! wntuf) {
  1624. i__1 = *lwork - *n;
  1625. dormqr_("L", "N", m, &n1, n, &a[a_offset], lda, &work[1], &u[
  1626. u_offset], ldu, &work[*n + 1], &i__1, &ierr);
  1627. }
  1628. if (rowprm && ! wntuf) {
  1629. i__1 = *m - 1;
  1630. dlaswp_(&n1, &u[u_offset], ldu, &c__1, &i__1, &iwork[*n + 1], &
  1631. c_n1);
  1632. }
  1633. } else if (rsvec && ! lsvec) {
  1634. /* ....................................................................... */
  1635. /* ....................................................................... */
  1636. if (rtrans) {
  1637. i__1 = nr;
  1638. for (p = 1; p <= i__1; ++p) {
  1639. i__2 = *n;
  1640. for (q = p; q <= i__2; ++q) {
  1641. v[q + p * v_dim1] = a[p + q * a_dim1];
  1642. /* L1166: */
  1643. }
  1644. /* L1165: */
  1645. }
  1646. if (nr > 1) {
  1647. i__1 = nr - 1;
  1648. i__2 = nr - 1;
  1649. dlaset_("U", &i__1, &i__2, &c_b72, &c_b72, &v[(v_dim1 << 1) +
  1650. 1], ldv);
  1651. }
  1652. /* vectors not computed */
  1653. if (wntvr || nr == *n) {
  1654. i__1 = *lwork - *n;
  1655. dgesvd_("O", "N", n, &nr, &v[v_offset], ldv, &s[1], &u[
  1656. u_offset], ldu, &u[u_offset], ldu, &work[*n + 1], &
  1657. i__1, info);
  1658. i__1 = nr;
  1659. for (p = 1; p <= i__1; ++p) {
  1660. i__2 = nr;
  1661. for (q = p + 1; q <= i__2; ++q) {
  1662. rtmp = v[q + p * v_dim1];
  1663. v[q + p * v_dim1] = v[p + q * v_dim1];
  1664. v[p + q * v_dim1] = rtmp;
  1665. /* L1122: */
  1666. }
  1667. /* L1121: */
  1668. }
  1669. if (nr < *n) {
  1670. i__1 = nr;
  1671. for (p = 1; p <= i__1; ++p) {
  1672. i__2 = *n;
  1673. for (q = nr + 1; q <= i__2; ++q) {
  1674. v[p + q * v_dim1] = v[q + p * v_dim1];
  1675. /* L1104: */
  1676. }
  1677. /* L1103: */
  1678. }
  1679. }
  1680. dlapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
  1681. } else {
  1682. /* [!] This is simple implementation that augments [V](1:N,1:NR) */
  1683. /* by padding a zero block. In the case NR << N, a more efficient */
  1684. /* way is to first use the QR factorization. For more details */
  1685. /* how to implement this, see the " FULL SVD " branch. */
  1686. i__1 = *n - nr;
  1687. dlaset_("G", n, &i__1, &c_b72, &c_b72, &v[(nr + 1) * v_dim1 +
  1688. 1], ldv);
  1689. i__1 = *lwork - *n;
  1690. dgesvd_("O", "N", n, n, &v[v_offset], ldv, &s[1], &u[u_offset]
  1691. , ldu, &u[u_offset], ldu, &work[*n + 1], &i__1, info);
  1692. i__1 = *n;
  1693. for (p = 1; p <= i__1; ++p) {
  1694. i__2 = *n;
  1695. for (q = p + 1; q <= i__2; ++q) {
  1696. rtmp = v[q + p * v_dim1];
  1697. v[q + p * v_dim1] = v[p + q * v_dim1];
  1698. v[p + q * v_dim1] = rtmp;
  1699. /* L1124: */
  1700. }
  1701. /* L1123: */
  1702. }
  1703. dlapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  1704. }
  1705. } else {
  1706. dlacpy_("U", &nr, n, &a[a_offset], lda, &v[v_offset], ldv);
  1707. if (nr > 1) {
  1708. i__1 = nr - 1;
  1709. i__2 = nr - 1;
  1710. dlaset_("L", &i__1, &i__2, &c_b72, &c_b72, &v[v_dim1 + 2],
  1711. ldv);
  1712. }
  1713. /* vectors stored in U(1:NR,1:NR) */
  1714. if (wntvr || nr == *n) {
  1715. i__1 = *lwork - *n;
  1716. dgesvd_("N", "O", &nr, n, &v[v_offset], ldv, &s[1], &u[
  1717. u_offset], ldu, &v[v_offset], ldv, &work[*n + 1], &
  1718. i__1, info);
  1719. dlapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
  1720. } else {
  1721. /* [!] This is simple implementation that augments [V](1:NR,1:N) */
  1722. /* by padding a zero block. In the case NR << N, a more efficient */
  1723. /* way is to first use the LQ factorization. For more details */
  1724. /* how to implement this, see the " FULL SVD " branch. */
  1725. i__1 = *n - nr;
  1726. dlaset_("G", &i__1, n, &c_b72, &c_b72, &v[nr + 1 + v_dim1],
  1727. ldv);
  1728. i__1 = *lwork - *n;
  1729. dgesvd_("N", "O", n, n, &v[v_offset], ldv, &s[1], &u[u_offset]
  1730. , ldu, &v[v_offset], ldv, &work[*n + 1], &i__1, info);
  1731. dlapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  1732. }
  1733. /* vectors of A. */
  1734. }
  1735. } else {
  1736. /* ....................................................................... */
  1737. /* ....................................................................... */
  1738. if (rtrans) {
  1739. if (wntvr || nr == *n) {
  1740. /* vectors of R**T */
  1741. i__1 = nr;
  1742. for (p = 1; p <= i__1; ++p) {
  1743. i__2 = *n;
  1744. for (q = p; q <= i__2; ++q) {
  1745. v[q + p * v_dim1] = a[p + q * a_dim1];
  1746. /* L1169: */
  1747. }
  1748. /* L1168: */
  1749. }
  1750. if (nr > 1) {
  1751. i__1 = nr - 1;
  1752. i__2 = nr - 1;
  1753. dlaset_("U", &i__1, &i__2, &c_b72, &c_b72, &v[(v_dim1 <<
  1754. 1) + 1], ldv);
  1755. }
  1756. /* singular vectors of R**T stored in [U](1:NR,1:NR) as transposed */
  1757. i__1 = *lwork - *n;
  1758. dgesvd_("O", "A", n, &nr, &v[v_offset], ldv, &s[1], &v[
  1759. v_offset], ldv, &u[u_offset], ldu, &work[*n + 1], &
  1760. i__1, info);
  1761. i__1 = nr;
  1762. for (p = 1; p <= i__1; ++p) {
  1763. i__2 = nr;
  1764. for (q = p + 1; q <= i__2; ++q) {
  1765. rtmp = v[q + p * v_dim1];
  1766. v[q + p * v_dim1] = v[p + q * v_dim1];
  1767. v[p + q * v_dim1] = rtmp;
  1768. /* L1116: */
  1769. }
  1770. /* L1115: */
  1771. }
  1772. if (nr < *n) {
  1773. i__1 = nr;
  1774. for (p = 1; p <= i__1; ++p) {
  1775. i__2 = *n;
  1776. for (q = nr + 1; q <= i__2; ++q) {
  1777. v[p + q * v_dim1] = v[q + p * v_dim1];
  1778. /* L1102: */
  1779. }
  1780. /* L1101: */
  1781. }
  1782. }
  1783. dlapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
  1784. i__1 = nr;
  1785. for (p = 1; p <= i__1; ++p) {
  1786. i__2 = nr;
  1787. for (q = p + 1; q <= i__2; ++q) {
  1788. rtmp = u[q + p * u_dim1];
  1789. u[q + p * u_dim1] = u[p + q * u_dim1];
  1790. u[p + q * u_dim1] = rtmp;
  1791. /* L1118: */
  1792. }
  1793. /* L1117: */
  1794. }
  1795. if (nr < *m && ! wntuf) {
  1796. i__1 = *m - nr;
  1797. dlaset_("A", &i__1, &nr, &c_b72, &c_b72, &u[nr + 1 +
  1798. u_dim1], ldu);
  1799. if (nr < n1) {
  1800. i__1 = n1 - nr;
  1801. dlaset_("A", &nr, &i__1, &c_b72, &c_b72, &u[(nr + 1) *
  1802. u_dim1 + 1], ldu);
  1803. i__1 = *m - nr;
  1804. i__2 = n1 - nr;
  1805. dlaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[nr + 1
  1806. + (nr + 1) * u_dim1], ldu);
  1807. }
  1808. }
  1809. } else {
  1810. /* vectors of R**T */
  1811. /* [[The optimal ratio N/NR for using QRF instead of padding */
  1812. /* with zeros. Here hard coded to 2; it must be at least */
  1813. /* two due to work space constraints.]] */
  1814. /* OPTRATIO = ILAENV(6, 'DGESVD', 'S' // 'O', NR,N,0,0) */
  1815. /* OPTRATIO = MAX( OPTRATIO, 2 ) */
  1816. optratio = 2;
  1817. if (optratio * nr > *n) {
  1818. i__1 = nr;
  1819. for (p = 1; p <= i__1; ++p) {
  1820. i__2 = *n;
  1821. for (q = p; q <= i__2; ++q) {
  1822. v[q + p * v_dim1] = a[p + q * a_dim1];
  1823. /* L1199: */
  1824. }
  1825. /* L1198: */
  1826. }
  1827. if (nr > 1) {
  1828. i__1 = nr - 1;
  1829. i__2 = nr - 1;
  1830. dlaset_("U", &i__1, &i__2, &c_b72, &c_b72, &v[(v_dim1
  1831. << 1) + 1], ldv);
  1832. }
  1833. i__1 = *n - nr;
  1834. dlaset_("A", n, &i__1, &c_b72, &c_b72, &v[(nr + 1) *
  1835. v_dim1 + 1], ldv);
  1836. i__1 = *lwork - *n;
  1837. dgesvd_("O", "A", n, n, &v[v_offset], ldv, &s[1], &v[
  1838. v_offset], ldv, &u[u_offset], ldu, &work[*n + 1],
  1839. &i__1, info);
  1840. i__1 = *n;
  1841. for (p = 1; p <= i__1; ++p) {
  1842. i__2 = *n;
  1843. for (q = p + 1; q <= i__2; ++q) {
  1844. rtmp = v[q + p * v_dim1];
  1845. v[q + p * v_dim1] = v[p + q * v_dim1];
  1846. v[p + q * v_dim1] = rtmp;
  1847. /* L1114: */
  1848. }
  1849. /* L1113: */
  1850. }
  1851. dlapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  1852. /* (M x N1), i.e. (M x N) or (M x M). */
  1853. i__1 = *n;
  1854. for (p = 1; p <= i__1; ++p) {
  1855. i__2 = *n;
  1856. for (q = p + 1; q <= i__2; ++q) {
  1857. rtmp = u[q + p * u_dim1];
  1858. u[q + p * u_dim1] = u[p + q * u_dim1];
  1859. u[p + q * u_dim1] = rtmp;
  1860. /* L1112: */
  1861. }
  1862. /* L1111: */
  1863. }
  1864. if (*n < *m && ! wntuf) {
  1865. i__1 = *m - *n;
  1866. dlaset_("A", &i__1, n, &c_b72, &c_b72, &u[*n + 1 +
  1867. u_dim1], ldu);
  1868. if (*n < n1) {
  1869. i__1 = n1 - *n;
  1870. dlaset_("A", n, &i__1, &c_b72, &c_b72, &u[(*n + 1)
  1871. * u_dim1 + 1], ldu);
  1872. i__1 = *m - *n;
  1873. i__2 = n1 - *n;
  1874. dlaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[*n
  1875. + 1 + (*n + 1) * u_dim1], ldu);
  1876. }
  1877. }
  1878. } else {
  1879. /* singular vectors of R */
  1880. i__1 = nr;
  1881. for (p = 1; p <= i__1; ++p) {
  1882. i__2 = *n;
  1883. for (q = p; q <= i__2; ++q) {
  1884. u[q + (nr + p) * u_dim1] = a[p + q * a_dim1];
  1885. /* L1197: */
  1886. }
  1887. /* L1196: */
  1888. }
  1889. if (nr > 1) {
  1890. i__1 = nr - 1;
  1891. i__2 = nr - 1;
  1892. dlaset_("U", &i__1, &i__2, &c_b72, &c_b72, &u[(nr + 2)
  1893. * u_dim1 + 1], ldu);
  1894. }
  1895. i__1 = *lwork - *n - nr;
  1896. dgeqrf_(n, &nr, &u[(nr + 1) * u_dim1 + 1], ldu, &work[*n
  1897. + 1], &work[*n + nr + 1], &i__1, &ierr);
  1898. i__1 = nr;
  1899. for (p = 1; p <= i__1; ++p) {
  1900. i__2 = *n;
  1901. for (q = 1; q <= i__2; ++q) {
  1902. v[q + p * v_dim1] = u[p + (nr + q) * u_dim1];
  1903. /* L1144: */
  1904. }
  1905. /* L1143: */
  1906. }
  1907. i__1 = nr - 1;
  1908. i__2 = nr - 1;
  1909. dlaset_("U", &i__1, &i__2, &c_b72, &c_b72, &v[(v_dim1 <<
  1910. 1) + 1], ldv);
  1911. i__1 = *lwork - *n - nr;
  1912. dgesvd_("S", "O", &nr, &nr, &v[v_offset], ldv, &s[1], &u[
  1913. u_offset], ldu, &v[v_offset], ldv, &work[*n + nr
  1914. + 1], &i__1, info);
  1915. i__1 = *n - nr;
  1916. dlaset_("A", &i__1, &nr, &c_b72, &c_b72, &v[nr + 1 +
  1917. v_dim1], ldv);
  1918. i__1 = *n - nr;
  1919. dlaset_("A", &nr, &i__1, &c_b72, &c_b72, &v[(nr + 1) *
  1920. v_dim1 + 1], ldv);
  1921. i__1 = *n - nr;
  1922. i__2 = *n - nr;
  1923. dlaset_("A", &i__1, &i__2, &c_b72, &c_b76, &v[nr + 1 + (
  1924. nr + 1) * v_dim1], ldv);
  1925. i__1 = *lwork - *n - nr;
  1926. dormqr_("R", "C", n, n, &nr, &u[(nr + 1) * u_dim1 + 1],
  1927. ldu, &work[*n + 1], &v[v_offset], ldv, &work[*n +
  1928. nr + 1], &i__1, &ierr);
  1929. dlapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  1930. /* (M x NR) or (M x N) or (M x M). */
  1931. if (nr < *m && ! wntuf) {
  1932. i__1 = *m - nr;
  1933. dlaset_("A", &i__1, &nr, &c_b72, &c_b72, &u[nr + 1 +
  1934. u_dim1], ldu);
  1935. if (nr < n1) {
  1936. i__1 = n1 - nr;
  1937. dlaset_("A", &nr, &i__1, &c_b72, &c_b72, &u[(nr +
  1938. 1) * u_dim1 + 1], ldu);
  1939. i__1 = *m - nr;
  1940. i__2 = n1 - nr;
  1941. dlaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[nr
  1942. + 1 + (nr + 1) * u_dim1], ldu);
  1943. }
  1944. }
  1945. }
  1946. }
  1947. } else {
  1948. if (wntvr || nr == *n) {
  1949. dlacpy_("U", &nr, n, &a[a_offset], lda, &v[v_offset], ldv);
  1950. if (nr > 1) {
  1951. i__1 = nr - 1;
  1952. i__2 = nr - 1;
  1953. dlaset_("L", &i__1, &i__2, &c_b72, &c_b72, &v[v_dim1 + 2],
  1954. ldv);
  1955. }
  1956. /* singular vectors of R stored in [U](1:NR,1:NR) */
  1957. i__1 = *lwork - *n;
  1958. dgesvd_("S", "O", &nr, n, &v[v_offset], ldv, &s[1], &u[
  1959. u_offset], ldu, &v[v_offset], ldv, &work[*n + 1], &
  1960. i__1, info);
  1961. dlapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
  1962. /* (M x NR) or (M x N) or (M x M). */
  1963. if (nr < *m && ! wntuf) {
  1964. i__1 = *m - nr;
  1965. dlaset_("A", &i__1, &nr, &c_b72, &c_b72, &u[nr + 1 +
  1966. u_dim1], ldu);
  1967. if (nr < n1) {
  1968. i__1 = n1 - nr;
  1969. dlaset_("A", &nr, &i__1, &c_b72, &c_b72, &u[(nr + 1) *
  1970. u_dim1 + 1], ldu);
  1971. i__1 = *m - nr;
  1972. i__2 = n1 - nr;
  1973. dlaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[nr + 1
  1974. + (nr + 1) * u_dim1], ldu);
  1975. }
  1976. }
  1977. } else {
  1978. /* is then N1 (N or M) */
  1979. /* [[The optimal ratio N/NR for using LQ instead of padding */
  1980. /* with zeros. Here hard coded to 2; it must be at least */
  1981. /* two due to work space constraints.]] */
  1982. /* OPTRATIO = ILAENV(6, 'DGESVD', 'S' // 'O', NR,N,0,0) */
  1983. /* OPTRATIO = MAX( OPTRATIO, 2 ) */
  1984. optratio = 2;
  1985. if (optratio * nr > *n) {
  1986. dlacpy_("U", &nr, n, &a[a_offset], lda, &v[v_offset], ldv);
  1987. if (nr > 1) {
  1988. i__1 = nr - 1;
  1989. i__2 = nr - 1;
  1990. dlaset_("L", &i__1, &i__2, &c_b72, &c_b72, &v[v_dim1
  1991. + 2], ldv);
  1992. }
  1993. /* singular vectors of R stored in [U](1:NR,1:NR) */
  1994. i__1 = *n - nr;
  1995. dlaset_("A", &i__1, n, &c_b72, &c_b72, &v[nr + 1 + v_dim1]
  1996. , ldv);
  1997. i__1 = *lwork - *n;
  1998. dgesvd_("S", "O", n, n, &v[v_offset], ldv, &s[1], &u[
  1999. u_offset], ldu, &v[v_offset], ldv, &work[*n + 1],
  2000. &i__1, info);
  2001. dlapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  2002. /* singular vectors of A. The leading N left singular vectors */
  2003. /* are in [U](1:N,1:N) */
  2004. /* (M x N1), i.e. (M x N) or (M x M). */
  2005. if (*n < *m && ! wntuf) {
  2006. i__1 = *m - *n;
  2007. dlaset_("A", &i__1, n, &c_b72, &c_b72, &u[*n + 1 +
  2008. u_dim1], ldu);
  2009. if (*n < n1) {
  2010. i__1 = n1 - *n;
  2011. dlaset_("A", n, &i__1, &c_b72, &c_b72, &u[(*n + 1)
  2012. * u_dim1 + 1], ldu);
  2013. i__1 = *m - *n;
  2014. i__2 = n1 - *n;
  2015. dlaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[*n
  2016. + 1 + (*n + 1) * u_dim1], ldu);
  2017. }
  2018. }
  2019. } else {
  2020. dlacpy_("U", &nr, n, &a[a_offset], lda, &u[nr + 1 +
  2021. u_dim1], ldu);
  2022. if (nr > 1) {
  2023. i__1 = nr - 1;
  2024. i__2 = nr - 1;
  2025. dlaset_("L", &i__1, &i__2, &c_b72, &c_b72, &u[nr + 2
  2026. + u_dim1], ldu);
  2027. }
  2028. i__1 = *lwork - *n - nr;
  2029. dgelqf_(&nr, n, &u[nr + 1 + u_dim1], ldu, &work[*n + 1], &
  2030. work[*n + nr + 1], &i__1, &ierr);
  2031. dlacpy_("L", &nr, &nr, &u[nr + 1 + u_dim1], ldu, &v[
  2032. v_offset], ldv);
  2033. if (nr > 1) {
  2034. i__1 = nr - 1;
  2035. i__2 = nr - 1;
  2036. dlaset_("U", &i__1, &i__2, &c_b72, &c_b72, &v[(v_dim1
  2037. << 1) + 1], ldv);
  2038. }
  2039. i__1 = *lwork - *n - nr;
  2040. dgesvd_("S", "O", &nr, &nr, &v[v_offset], ldv, &s[1], &u[
  2041. u_offset], ldu, &v[v_offset], ldv, &work[*n + nr
  2042. + 1], &i__1, info);
  2043. i__1 = *n - nr;
  2044. dlaset_("A", &i__1, &nr, &c_b72, &c_b72, &v[nr + 1 +
  2045. v_dim1], ldv);
  2046. i__1 = *n - nr;
  2047. dlaset_("A", &nr, &i__1, &c_b72, &c_b72, &v[(nr + 1) *
  2048. v_dim1 + 1], ldv);
  2049. i__1 = *n - nr;
  2050. i__2 = *n - nr;
  2051. dlaset_("A", &i__1, &i__2, &c_b72, &c_b76, &v[nr + 1 + (
  2052. nr + 1) * v_dim1], ldv);
  2053. i__1 = *lwork - *n - nr;
  2054. dormlq_("R", "N", n, n, &nr, &u[nr + 1 + u_dim1], ldu, &
  2055. work[*n + 1], &v[v_offset], ldv, &work[*n + nr +
  2056. 1], &i__1, &ierr);
  2057. dlapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  2058. /* (M x NR) or (M x N) or (M x M). */
  2059. if (nr < *m && ! wntuf) {
  2060. i__1 = *m - nr;
  2061. dlaset_("A", &i__1, &nr, &c_b72, &c_b72, &u[nr + 1 +
  2062. u_dim1], ldu);
  2063. if (nr < n1) {
  2064. i__1 = n1 - nr;
  2065. dlaset_("A", &nr, &i__1, &c_b72, &c_b72, &u[(nr +
  2066. 1) * u_dim1 + 1], ldu);
  2067. i__1 = *m - nr;
  2068. i__2 = n1 - nr;
  2069. dlaset_("A", &i__1, &i__2, &c_b72, &c_b76, &u[nr
  2070. + 1 + (nr + 1) * u_dim1], ldu);
  2071. }
  2072. }
  2073. }
  2074. }
  2075. }
  2076. /* The Q matrix from the first QRF is built into the left singular */
  2077. /* vectors matrix U. */
  2078. if (! wntuf) {
  2079. i__1 = *lwork - *n;
  2080. dormqr_("L", "N", m, &n1, n, &a[a_offset], lda, &work[1], &u[
  2081. u_offset], ldu, &work[*n + 1], &i__1, &ierr);
  2082. }
  2083. if (rowprm && ! wntuf) {
  2084. i__1 = *m - 1;
  2085. dlaswp_(&n1, &u[u_offset], ldu, &c__1, &i__1, &iwork[*n + 1], &
  2086. c_n1);
  2087. }
  2088. /* ... end of the "full SVD" branch */
  2089. }
  2090. /* Check whether some singular values are returned as zeros, e.g. */
  2091. /* due to underflow, and update the numerical rank. */
  2092. p = nr;
  2093. for (q = p; q >= 1; --q) {
  2094. if (s[q] > 0.) {
  2095. goto L4002;
  2096. }
  2097. --nr;
  2098. /* L4001: */
  2099. }
  2100. L4002:
  2101. /* singular values are set to zero. */
  2102. if (nr < *n) {
  2103. i__1 = *n - nr;
  2104. dlaset_("G", &i__1, &c__1, &c_b72, &c_b72, &s[nr + 1], n);
  2105. }
  2106. /* values. */
  2107. if (ascaled) {
  2108. d__1 = sqrt((doublereal) (*m));
  2109. dlascl_("G", &c__0, &c__0, &c_b76, &d__1, &nr, &c__1, &s[1], n, &ierr);
  2110. }
  2111. if (conda) {
  2112. rwork[1] = sconda;
  2113. }
  2114. rwork[2] = (doublereal) (p - nr);
  2115. /* exact zeros in DGESVD() applied to the (possibly truncated) */
  2116. /* full row rank triangular (trapezoidal) factor of A. */
  2117. *numrank = nr;
  2118. return;
  2119. /* End of DGESVDQ */
  2120. } /* dgesvdq_ */