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.

cgesvdq.c 76 kB

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