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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325
  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 */ int 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 */ int 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 */ int 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 */ int cgeqrf_(integer *, integer *, complex *,
  929. integer *, complex *, complex *, integer *, integer *), csscal_(
  930. integer *, real *, complex *, integer *);
  931. extern real slamch_(char *);
  932. extern /* Subroutine */ int 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. xerbla_(char *, integer *, ftnlen), clapmt_(logical *, integer *,
  938. integer *, complex *, integer *, integer *), slascl_(char *,
  939. integer *, integer *, real *, real *, integer *, integer *, real *
  940. , integer *, integer *), cpocon_(char *, integer *,
  941. complex *, integer *, real *, real *, complex *, real *, integer *
  942. );
  943. extern integer isamax_(integer *, real *, integer *);
  944. extern /* Subroutine */ int claswp_(integer *, complex *, integer *,
  945. integer *, integer *, integer *, integer *), slaset_(char *,
  946. integer *, integer *, real *, real *, real *, integer *);
  947. complex cdummy[1];
  948. extern /* Subroutine */ int cunmlq_(char *, char *, integer *, integer *,
  949. integer *, complex *, integer *, complex *, complex *, integer *,
  950. complex *, integer *, integer *), cunmqr_(char *,
  951. char *, integer *, integer *, integer *, complex *, integer *,
  952. complex *, complex *, integer *, complex *, integer *, integer *);
  953. integer minwrk;
  954. logical rtrans;
  955. real rdummy[1];
  956. logical lquery;
  957. integer lwunlq, optwrk;
  958. logical rowprm;
  959. real big;
  960. integer minwrk2;
  961. logical ascaled;
  962. integer lwrk_cgeqp3__, optwrk2, lwrk_cgelqf__, iminwrk, lwrk_cgeqrf__,
  963. lwrk_cgesvd__, rminwrk, lwrk_cunmlq__;
  964. /* ===================================================================== */
  965. /* Test the input arguments */
  966. /* Parameter adjustments */
  967. a_dim1 = *lda;
  968. a_offset = 1 + a_dim1 * 1;
  969. a -= a_offset;
  970. --s;
  971. u_dim1 = *ldu;
  972. u_offset = 1 + u_dim1 * 1;
  973. u -= u_offset;
  974. v_dim1 = *ldv;
  975. v_offset = 1 + v_dim1 * 1;
  976. v -= v_offset;
  977. --iwork;
  978. --cwork;
  979. --rwork;
  980. /* Function Body */
  981. wntus = lsame_(jobu, "S") || lsame_(jobu, "U");
  982. wntur = lsame_(jobu, "R");
  983. wntua = lsame_(jobu, "A");
  984. wntuf = lsame_(jobu, "F");
  985. lsvc0 = wntus || wntur || wntua;
  986. lsvec = lsvc0 || wntuf;
  987. dntwu = lsame_(jobu, "N");
  988. wntvr = lsame_(jobv, "R");
  989. wntva = lsame_(jobv, "A") || lsame_(jobv, "V");
  990. rsvec = wntvr || wntva;
  991. dntwv = lsame_(jobv, "N");
  992. accla = lsame_(joba, "A");
  993. acclm = lsame_(joba, "M");
  994. conda = lsame_(joba, "E");
  995. acclh = lsame_(joba, "H") || conda;
  996. rowprm = lsame_(jobp, "P");
  997. rtrans = lsame_(jobr, "T");
  998. if (rowprm) {
  999. /* Computing MAX */
  1000. i__1 = 1, i__2 = *n + *m - 1;
  1001. iminwrk = f2cmax(i__1,i__2);
  1002. /* Computing MAX */
  1003. i__1 = f2cmax(2,*m), i__2 = *n * 5;
  1004. rminwrk = f2cmax(i__1,i__2);
  1005. } else {
  1006. iminwrk = f2cmax(1,*n);
  1007. /* Computing MAX */
  1008. i__1 = 2, i__2 = *n * 5;
  1009. rminwrk = f2cmax(i__1,i__2);
  1010. }
  1011. lquery = *liwork == -1 || *lcwork == -1 || *lrwork == -1;
  1012. *info = 0;
  1013. if (! (accla || acclm || acclh)) {
  1014. *info = -1;
  1015. } else if (! (rowprm || lsame_(jobp, "N"))) {
  1016. *info = -2;
  1017. } else if (! (rtrans || lsame_(jobr, "N"))) {
  1018. *info = -3;
  1019. } else if (! (lsvec || dntwu)) {
  1020. *info = -4;
  1021. } else if (wntur && wntva) {
  1022. *info = -5;
  1023. } else if (! (rsvec || dntwv)) {
  1024. *info = -5;
  1025. } else if (*m < 0) {
  1026. *info = -6;
  1027. } else if (*n < 0 || *n > *m) {
  1028. *info = -7;
  1029. } else if (*lda < f2cmax(1,*m)) {
  1030. *info = -9;
  1031. } else if (*ldu < 1 || lsvc0 && *ldu < *m || wntuf && *ldu < *n) {
  1032. *info = -12;
  1033. } else if (*ldv < 1 || rsvec && *ldv < *n || conda && *ldv < *n) {
  1034. *info = -14;
  1035. } else if (*liwork < iminwrk && ! lquery) {
  1036. *info = -17;
  1037. }
  1038. if (*info == 0) {
  1039. /* Compute workspace */
  1040. /* [[The expressions for computing the minimal and the optimal */
  1041. /* values of LCWORK are written with a lot of redundancy and */
  1042. /* can be simplified. However, this detailed form is easier for */
  1043. /* maintenance and modifications of the code.]] */
  1044. lwqp3 = *n + 1;
  1045. if (wntus || wntur) {
  1046. lwunq = f2cmax(*n,1);
  1047. } else if (wntua) {
  1048. lwunq = f2cmax(*m,1);
  1049. }
  1050. lwcon = *n << 1;
  1051. /* Computing MAX */
  1052. i__1 = *n * 3;
  1053. lwsvd = f2cmax(i__1,1);
  1054. if (lquery) {
  1055. cgeqp3_(m, n, &a[a_offset], lda, &iwork[1], cdummy, cdummy, &c_n1,
  1056. rdummy, &ierr);
  1057. lwrk_cgeqp3__ = (integer) cdummy[0].r;
  1058. if (wntus || wntur) {
  1059. cunmqr_("L", "N", m, n, n, &a[a_offset], lda, cdummy, &u[
  1060. u_offset], ldu, cdummy, &c_n1, &ierr);
  1061. lwrk_cunmqr__ = (integer) cdummy[0].r;
  1062. } else if (wntua) {
  1063. cunmqr_("L", "N", m, m, n, &a[a_offset], lda, cdummy, &u[
  1064. u_offset], ldu, cdummy, &c_n1, &ierr);
  1065. lwrk_cunmqr__ = (integer) cdummy[0].r;
  1066. } else {
  1067. lwrk_cunmqr__ = 0;
  1068. }
  1069. }
  1070. minwrk = 2;
  1071. optwrk = 2;
  1072. if (! (lsvec || rsvec)) {
  1073. /* only the singular values are requested */
  1074. if (conda) {
  1075. /* Computing MAX */
  1076. i__1 = *n + lwqp3, i__1 = f2cmax(i__1,lwcon);
  1077. minwrk = f2cmax(i__1,lwsvd);
  1078. } else {
  1079. /* Computing MAX */
  1080. i__1 = *n + lwqp3;
  1081. minwrk = f2cmax(i__1,lwsvd);
  1082. }
  1083. if (lquery) {
  1084. cgesvd_("N", "N", n, n, &a[a_offset], lda, &s[1], &u[u_offset]
  1085. , ldu, &v[v_offset], ldv, cdummy, &c_n1, rdummy, &
  1086. ierr);
  1087. lwrk_cgesvd__ = (integer) cdummy[0].r;
  1088. if (conda) {
  1089. /* Computing MAX */
  1090. i__1 = *n + lwrk_cgeqp3__, i__2 = *n + lwcon, i__1 = f2cmax(
  1091. i__1,i__2);
  1092. optwrk = f2cmax(i__1,lwrk_cgesvd__);
  1093. } else {
  1094. /* Computing MAX */
  1095. i__1 = *n + lwrk_cgeqp3__;
  1096. optwrk = f2cmax(i__1,lwrk_cgesvd__);
  1097. }
  1098. }
  1099. } else if (lsvec && ! rsvec) {
  1100. /* singular values and the left singular vectors are requested */
  1101. if (conda) {
  1102. /* Computing MAX */
  1103. i__1 = f2cmax(lwqp3,lwcon), i__1 = f2cmax(i__1,lwsvd);
  1104. minwrk = *n + f2cmax(i__1,lwunq);
  1105. } else {
  1106. /* Computing MAX */
  1107. i__1 = f2cmax(lwqp3,lwsvd);
  1108. minwrk = *n + f2cmax(i__1,lwunq);
  1109. }
  1110. if (lquery) {
  1111. if (rtrans) {
  1112. cgesvd_("N", "O", n, n, &a[a_offset], lda, &s[1], &u[
  1113. u_offset], ldu, &v[v_offset], ldv, cdummy, &c_n1,
  1114. rdummy, &ierr);
  1115. } else {
  1116. cgesvd_("O", "N", n, n, &a[a_offset], lda, &s[1], &u[
  1117. u_offset], ldu, &v[v_offset], ldv, cdummy, &c_n1,
  1118. rdummy, &ierr);
  1119. }
  1120. lwrk_cgesvd__ = (integer) cdummy[0].r;
  1121. if (conda) {
  1122. /* Computing MAX */
  1123. i__1 = f2cmax(lwrk_cgeqp3__,lwcon), i__1 = f2cmax(i__1,
  1124. lwrk_cgesvd__);
  1125. optwrk = *n + f2cmax(i__1,lwrk_cunmqr__);
  1126. } else {
  1127. /* Computing MAX */
  1128. i__1 = f2cmax(lwrk_cgeqp3__,lwrk_cgesvd__);
  1129. optwrk = *n + f2cmax(i__1,lwrk_cunmqr__);
  1130. }
  1131. }
  1132. } else if (rsvec && ! lsvec) {
  1133. /* singular values and the right singular vectors are requested */
  1134. if (conda) {
  1135. /* Computing MAX */
  1136. i__1 = f2cmax(lwqp3,lwcon);
  1137. minwrk = *n + f2cmax(i__1,lwsvd);
  1138. } else {
  1139. minwrk = *n + f2cmax(lwqp3,lwsvd);
  1140. }
  1141. if (lquery) {
  1142. if (rtrans) {
  1143. cgesvd_("O", "N", n, n, &a[a_offset], lda, &s[1], &u[
  1144. u_offset], ldu, &v[v_offset], ldv, cdummy, &c_n1,
  1145. rdummy, &ierr);
  1146. } else {
  1147. cgesvd_("N", "O", n, n, &a[a_offset], lda, &s[1], &u[
  1148. u_offset], ldu, &v[v_offset], ldv, cdummy, &c_n1,
  1149. rdummy, &ierr);
  1150. }
  1151. lwrk_cgesvd__ = (integer) cdummy[0].r;
  1152. if (conda) {
  1153. /* Computing MAX */
  1154. i__1 = f2cmax(lwrk_cgeqp3__,lwcon);
  1155. optwrk = *n + f2cmax(i__1,lwrk_cgesvd__);
  1156. } else {
  1157. optwrk = *n + f2cmax(lwrk_cgeqp3__,lwrk_cgesvd__);
  1158. }
  1159. }
  1160. } else {
  1161. /* full SVD is requested */
  1162. if (rtrans) {
  1163. /* Computing MAX */
  1164. i__1 = f2cmax(lwqp3,lwsvd);
  1165. minwrk = f2cmax(i__1,lwunq);
  1166. if (conda) {
  1167. minwrk = f2cmax(minwrk,lwcon);
  1168. }
  1169. minwrk += *n;
  1170. if (wntva) {
  1171. /* Computing MAX */
  1172. i__1 = *n / 2;
  1173. lwqrf = f2cmax(i__1,1);
  1174. /* Computing MAX */
  1175. i__1 = *n / 2 * 3;
  1176. lwsvd2 = f2cmax(i__1,1);
  1177. lwunq2 = f2cmax(*n,1);
  1178. /* Computing MAX */
  1179. i__1 = lwqp3, i__2 = *n / 2 + lwqrf, i__1 = f2cmax(i__1,i__2)
  1180. , i__2 = *n / 2 + lwsvd2, i__1 = f2cmax(i__1,i__2),
  1181. i__2 = *n / 2 + lwunq2, i__1 = f2cmax(i__1,i__2);
  1182. minwrk2 = f2cmax(i__1,lwunq);
  1183. if (conda) {
  1184. minwrk2 = f2cmax(minwrk2,lwcon);
  1185. }
  1186. minwrk2 = *n + minwrk2;
  1187. minwrk = f2cmax(minwrk,minwrk2);
  1188. }
  1189. } else {
  1190. /* Computing MAX */
  1191. i__1 = f2cmax(lwqp3,lwsvd);
  1192. minwrk = f2cmax(i__1,lwunq);
  1193. if (conda) {
  1194. minwrk = f2cmax(minwrk,lwcon);
  1195. }
  1196. minwrk += *n;
  1197. if (wntva) {
  1198. /* Computing MAX */
  1199. i__1 = *n / 2;
  1200. lwlqf = f2cmax(i__1,1);
  1201. /* Computing MAX */
  1202. i__1 = *n / 2 * 3;
  1203. lwsvd2 = f2cmax(i__1,1);
  1204. lwunlq = f2cmax(*n,1);
  1205. /* Computing MAX */
  1206. i__1 = lwqp3, i__2 = *n / 2 + lwlqf, i__1 = f2cmax(i__1,i__2)
  1207. , i__2 = *n / 2 + lwsvd2, i__1 = f2cmax(i__1,i__2),
  1208. i__2 = *n / 2 + lwunlq, i__1 = f2cmax(i__1,i__2);
  1209. minwrk2 = f2cmax(i__1,lwunq);
  1210. if (conda) {
  1211. minwrk2 = f2cmax(minwrk2,lwcon);
  1212. }
  1213. minwrk2 = *n + minwrk2;
  1214. minwrk = f2cmax(minwrk,minwrk2);
  1215. }
  1216. }
  1217. if (lquery) {
  1218. if (rtrans) {
  1219. cgesvd_("O", "A", n, n, &a[a_offset], lda, &s[1], &u[
  1220. u_offset], ldu, &v[v_offset], ldv, cdummy, &c_n1,
  1221. rdummy, &ierr);
  1222. lwrk_cgesvd__ = (integer) cdummy[0].r;
  1223. /* Computing MAX */
  1224. i__1 = f2cmax(lwrk_cgeqp3__,lwrk_cgesvd__);
  1225. optwrk = f2cmax(i__1,lwrk_cunmqr__);
  1226. if (conda) {
  1227. optwrk = f2cmax(optwrk,lwcon);
  1228. }
  1229. optwrk = *n + optwrk;
  1230. if (wntva) {
  1231. i__1 = *n / 2;
  1232. cgeqrf_(n, &i__1, &u[u_offset], ldu, cdummy, cdummy, &
  1233. c_n1, &ierr);
  1234. lwrk_cgeqrf__ = (integer) cdummy[0].r;
  1235. i__1 = *n / 2;
  1236. i__2 = *n / 2;
  1237. cgesvd_("S", "O", &i__1, &i__2, &v[v_offset], ldv, &s[
  1238. 1], &u[u_offset], ldu, &v[v_offset], ldv,
  1239. cdummy, &c_n1, rdummy, &ierr);
  1240. lwrk_cgesvd2__ = (integer) cdummy[0].r;
  1241. i__1 = *n / 2;
  1242. cunmqr_("R", "C", n, n, &i__1, &u[u_offset], ldu,
  1243. cdummy, &v[v_offset], ldv, cdummy, &c_n1, &
  1244. ierr);
  1245. lwrk_cunmqr2__ = (integer) cdummy[0].r;
  1246. /* Computing MAX */
  1247. i__1 = lwrk_cgeqp3__, i__2 = *n / 2 + lwrk_cgeqrf__,
  1248. i__1 = f2cmax(i__1,i__2), i__2 = *n / 2 +
  1249. lwrk_cgesvd2__, i__1 = f2cmax(i__1,i__2), i__2 =
  1250. *n / 2 + lwrk_cunmqr2__;
  1251. optwrk2 = f2cmax(i__1,i__2);
  1252. if (conda) {
  1253. optwrk2 = f2cmax(optwrk2,lwcon);
  1254. }
  1255. optwrk2 = *n + optwrk2;
  1256. optwrk = f2cmax(optwrk,optwrk2);
  1257. }
  1258. } else {
  1259. cgesvd_("S", "O", n, n, &a[a_offset], lda, &s[1], &u[
  1260. u_offset], ldu, &v[v_offset], ldv, cdummy, &c_n1,
  1261. rdummy, &ierr);
  1262. lwrk_cgesvd__ = (integer) cdummy[0].r;
  1263. /* Computing MAX */
  1264. i__1 = f2cmax(lwrk_cgeqp3__,lwrk_cgesvd__);
  1265. optwrk = f2cmax(i__1,lwrk_cunmqr__);
  1266. if (conda) {
  1267. optwrk = f2cmax(optwrk,lwcon);
  1268. }
  1269. optwrk = *n + optwrk;
  1270. if (wntva) {
  1271. i__1 = *n / 2;
  1272. cgelqf_(&i__1, n, &u[u_offset], ldu, cdummy, cdummy, &
  1273. c_n1, &ierr);
  1274. lwrk_cgelqf__ = (integer) cdummy[0].r;
  1275. i__1 = *n / 2;
  1276. i__2 = *n / 2;
  1277. cgesvd_("S", "O", &i__1, &i__2, &v[v_offset], ldv, &s[
  1278. 1], &u[u_offset], ldu, &v[v_offset], ldv,
  1279. cdummy, &c_n1, rdummy, &ierr);
  1280. lwrk_cgesvd2__ = (integer) cdummy[0].r;
  1281. i__1 = *n / 2;
  1282. cunmlq_("R", "N", n, n, &i__1, &u[u_offset], ldu,
  1283. cdummy, &v[v_offset], ldv, cdummy, &c_n1, &
  1284. ierr);
  1285. lwrk_cunmlq__ = (integer) cdummy[0].r;
  1286. /* Computing MAX */
  1287. i__1 = lwrk_cgeqp3__, i__2 = *n / 2 + lwrk_cgelqf__,
  1288. i__1 = f2cmax(i__1,i__2), i__2 = *n / 2 +
  1289. lwrk_cgesvd2__, i__1 = f2cmax(i__1,i__2), i__2 =
  1290. *n / 2 + lwrk_cunmlq__;
  1291. optwrk2 = f2cmax(i__1,i__2);
  1292. if (conda) {
  1293. optwrk2 = f2cmax(optwrk2,lwcon);
  1294. }
  1295. optwrk2 = *n + optwrk2;
  1296. optwrk = f2cmax(optwrk,optwrk2);
  1297. }
  1298. }
  1299. }
  1300. }
  1301. minwrk = f2cmax(2,minwrk);
  1302. optwrk = f2cmax(2,optwrk);
  1303. if (*lcwork < minwrk && ! lquery) {
  1304. *info = -19;
  1305. }
  1306. }
  1307. if (*info == 0 && *lrwork < rminwrk && ! lquery) {
  1308. *info = -21;
  1309. }
  1310. if (*info != 0) {
  1311. i__1 = -(*info);
  1312. xerbla_("CGESVDQ", &i__1, (ftnlen)7);
  1313. return 0;
  1314. } else if (lquery) {
  1315. /* Return optimal workspace */
  1316. iwork[1] = iminwrk;
  1317. cwork[1].r = (real) optwrk, cwork[1].i = 0.f;
  1318. cwork[2].r = (real) minwrk, cwork[2].i = 0.f;
  1319. rwork[1] = (real) rminwrk;
  1320. return 0;
  1321. }
  1322. /* Quick return if the matrix is void. */
  1323. if (*m == 0 || *n == 0) {
  1324. return 0;
  1325. }
  1326. big = slamch_("O");
  1327. ascaled = FALSE_;
  1328. if (rowprm) {
  1329. /* ell-infinity norm - this enhances numerical robustness in */
  1330. /* the case of differently scaled rows. */
  1331. i__1 = *m;
  1332. for (p = 1; p <= i__1; ++p) {
  1333. /* RWORK(p) = ABS( A(p,ICAMAX(N,A(p,1),LDA)) ) */
  1334. /* [[CLANGE will return NaN if an entry of the p-th row is Nan]] */
  1335. rwork[p] = clange_("M", &c__1, n, &a[p + a_dim1], lda, rdummy);
  1336. if (rwork[p] != rwork[p] || rwork[p] * 0.f != 0.f) {
  1337. *info = -8;
  1338. i__2 = -(*info);
  1339. xerbla_("CGESVDQ", &i__2, (ftnlen)7);
  1340. return 0;
  1341. }
  1342. /* L1904: */
  1343. }
  1344. i__1 = *m - 1;
  1345. for (p = 1; p <= i__1; ++p) {
  1346. i__2 = *m - p + 1;
  1347. q = isamax_(&i__2, &rwork[p], &c__1) + p - 1;
  1348. iwork[*n + p] = q;
  1349. if (p != q) {
  1350. rtmp = rwork[p];
  1351. rwork[p] = rwork[q];
  1352. rwork[q] = rtmp;
  1353. }
  1354. /* L1952: */
  1355. }
  1356. if (rwork[1] == 0.f) {
  1357. /* Quick return: A is the M x N zero matrix. */
  1358. *numrank = 0;
  1359. slaset_("G", n, &c__1, &c_b74, &c_b74, &s[1], n);
  1360. if (wntus) {
  1361. claset_("G", m, n, &c_b1, &c_b2, &u[u_offset], ldu)
  1362. ;
  1363. }
  1364. if (wntua) {
  1365. claset_("G", m, m, &c_b1, &c_b2, &u[u_offset], ldu)
  1366. ;
  1367. }
  1368. if (wntva) {
  1369. claset_("G", n, n, &c_b1, &c_b2, &v[v_offset], ldv)
  1370. ;
  1371. }
  1372. if (wntuf) {
  1373. claset_("G", n, &c__1, &c_b1, &c_b1, &cwork[1], n);
  1374. claset_("G", m, n, &c_b1, &c_b2, &u[u_offset], ldu)
  1375. ;
  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.f;
  1391. }
  1392. rwork[2] = -1.f;
  1393. return 0;
  1394. }
  1395. if (rwork[1] > big / sqrt((real) (*m))) {
  1396. /* matrix by 1/sqrt(M) if too large entry detected */
  1397. r__1 = sqrt((real) (*m));
  1398. clascl_("G", &c__0, &c__0, &r__1, &c_b87, m, n, &a[a_offset], lda,
  1399. &ierr);
  1400. ascaled = TRUE_;
  1401. }
  1402. i__1 = *m - 1;
  1403. claswp_(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 = clange_("M", m, n, &a[a_offset], lda, &rwork[1]);
  1410. if (rtmp != rtmp || rtmp * 0.f != 0.f) {
  1411. *info = -8;
  1412. i__1 = -(*info);
  1413. xerbla_("CGESVDQ", &i__1, (ftnlen)7);
  1414. return 0;
  1415. }
  1416. if (rtmp > big / sqrt((real) (*m))) {
  1417. /* matrix by 1/sqrt(M) if too large entry detected */
  1418. r__1 = sqrt((real) (*m));
  1419. clascl_("G", &c__0, &c__0, &r__1, &c_b87, 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 = *lcwork - *n;
  1432. cgeqp3_(m, n, &a[a_offset], lda, &iwork[1], &cwork[1], &cwork[*n + 1], &
  1433. i__1, &rwork[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 = slamch_("E");
  1438. sfmin = slamch_("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((real) (*n)) * epsln;
  1448. i__1 = *n;
  1449. for (p = 2; p <= i__1; ++p) {
  1450. if (c_abs(&a[p + p * a_dim1]) < rtmp * c_abs(&a[a_dim1 + 1])) {
  1451. goto L3002;
  1452. }
  1453. ++nr;
  1454. /* L3001: */
  1455. }
  1456. L3002:
  1457. ;
  1458. } else if (acclm) {
  1459. /* Sudden drop on the diagonal of R is used as the criterion for being */
  1460. /* close-to-rank-deficient. The threshold is set to EPSLN=SLAMCH('E'). */
  1461. /* [[This can be made more flexible by replacing this hard-coded value */
  1462. /* with a user specified threshold.]] Also, the values that underflow */
  1463. /* will be truncated. */
  1464. nr = 1;
  1465. i__1 = *n;
  1466. for (p = 2; p <= i__1; ++p) {
  1467. if (c_abs(&a[p + p * a_dim1]) < epsln * c_abs(&a[p - 1 + (p - 1) *
  1468. a_dim1]) || c_abs(&a[p + p * a_dim1]) < sfmin) {
  1469. goto L3402;
  1470. }
  1471. ++nr;
  1472. /* L3401: */
  1473. }
  1474. L3402:
  1475. ;
  1476. } else {
  1477. /* obvious case of zero pivots. */
  1478. /* R(i,i)=0 => R(i:N,i:N)=0. */
  1479. nr = 1;
  1480. i__1 = *n;
  1481. for (p = 2; p <= i__1; ++p) {
  1482. if (c_abs(&a[p + p * a_dim1]) == 0.f) {
  1483. goto L3502;
  1484. }
  1485. ++nr;
  1486. /* L3501: */
  1487. }
  1488. L3502:
  1489. if (conda) {
  1490. /* Estimate the scaled condition number of A. Use the fact that it is */
  1491. /* the same as the scaled condition number of R. */
  1492. clacpy_("U", n, n, &a[a_offset], lda, &v[v_offset], ldv);
  1493. /* Only the leading NR x NR submatrix of the triangular factor */
  1494. /* is considered. Only if NR=N will this give a reliable error */
  1495. /* bound. However, even for NR < N, this can be used on an */
  1496. /* expert level and obtain useful information in the sense of */
  1497. /* perturbation theory. */
  1498. i__1 = nr;
  1499. for (p = 1; p <= i__1; ++p) {
  1500. rtmp = scnrm2_(&p, &v[p * v_dim1 + 1], &c__1);
  1501. r__1 = 1.f / rtmp;
  1502. csscal_(&p, &r__1, &v[p * v_dim1 + 1], &c__1);
  1503. /* L3053: */
  1504. }
  1505. if (! (lsvec || rsvec)) {
  1506. cpocon_("U", &nr, &v[v_offset], ldv, &c_b87, &rtmp, &cwork[1],
  1507. &rwork[1], &ierr);
  1508. } else {
  1509. cpocon_("U", &nr, &v[v_offset], ldv, &c_b87, &rtmp, &cwork[*n
  1510. + 1], &rwork[1], &ierr);
  1511. }
  1512. sconda = 1.f / sqrt(rtmp);
  1513. /* For NR=N, SCONDA is an estimate of SQRT(||(R^* * R)^(-1)||_1), */
  1514. /* N^(-1/4) * SCONDA <= ||R^(-1)||_2 <= N^(1/4) * SCONDA */
  1515. /* See the reference [1] for more details. */
  1516. }
  1517. }
  1518. if (wntur) {
  1519. n1 = nr;
  1520. } else if (wntus || wntuf) {
  1521. n1 = *n;
  1522. } else if (wntua) {
  1523. n1 = *m;
  1524. }
  1525. if (! (rsvec || lsvec)) {
  1526. /* ....................................................................... */
  1527. /* ....................................................................... */
  1528. if (rtrans) {
  1529. /* the upper triangle of [A] to zero. */
  1530. i__1 = f2cmin(*n,nr);
  1531. for (p = 1; p <= i__1; ++p) {
  1532. i__2 = p + p * a_dim1;
  1533. r_cnjg(&q__1, &a[p + p * a_dim1]);
  1534. a[i__2].r = q__1.r, a[i__2].i = q__1.i;
  1535. i__2 = *n;
  1536. for (q = p + 1; q <= i__2; ++q) {
  1537. i__3 = q + p * a_dim1;
  1538. r_cnjg(&q__1, &a[p + q * a_dim1]);
  1539. a[i__3].r = q__1.r, a[i__3].i = q__1.i;
  1540. if (q <= nr) {
  1541. i__3 = p + q * a_dim1;
  1542. a[i__3].r = 0.f, a[i__3].i = 0.f;
  1543. }
  1544. /* L1147: */
  1545. }
  1546. /* L1146: */
  1547. }
  1548. cgesvd_("N", "N", n, &nr, &a[a_offset], lda, &s[1], &u[u_offset],
  1549. ldu, &v[v_offset], ldv, &cwork[1], lcwork, &rwork[1],
  1550. info);
  1551. } else {
  1552. if (nr > 1) {
  1553. i__1 = nr - 1;
  1554. i__2 = nr - 1;
  1555. claset_("L", &i__1, &i__2, &c_b1, &c_b1, &a[a_dim1 + 2], lda);
  1556. }
  1557. cgesvd_("N", "N", &nr, n, &a[a_offset], lda, &s[1], &u[u_offset],
  1558. ldu, &v[v_offset], ldv, &cwork[1], lcwork, &rwork[1],
  1559. info);
  1560. }
  1561. } else if (lsvec && ! rsvec) {
  1562. /* ....................................................................... */
  1563. /* ......................................................................."""""""" */
  1564. if (rtrans) {
  1565. /* vectors of R */
  1566. i__1 = nr;
  1567. for (p = 1; p <= i__1; ++p) {
  1568. i__2 = *n;
  1569. for (q = p; q <= i__2; ++q) {
  1570. i__3 = q + p * u_dim1;
  1571. r_cnjg(&q__1, &a[p + q * a_dim1]);
  1572. u[i__3].r = q__1.r, u[i__3].i = q__1.i;
  1573. /* L1193: */
  1574. }
  1575. /* L1192: */
  1576. }
  1577. if (nr > 1) {
  1578. i__1 = nr - 1;
  1579. i__2 = nr - 1;
  1580. claset_("U", &i__1, &i__2, &c_b1, &c_b1, &u[(u_dim1 << 1) + 1]
  1581. , ldu);
  1582. }
  1583. /* vectors overwrite [U](1:NR,1:NR) as conjugate transposed. These */
  1584. /* will be pre-multiplied by Q to build the left singular vectors of A. */
  1585. i__1 = *lcwork - *n;
  1586. cgesvd_("N", "O", n, &nr, &u[u_offset], ldu, &s[1], &u[u_offset],
  1587. ldu, &u[u_offset], ldu, &cwork[*n + 1], &i__1, &rwork[1],
  1588. info);
  1589. i__1 = nr;
  1590. for (p = 1; p <= i__1; ++p) {
  1591. i__2 = p + p * u_dim1;
  1592. r_cnjg(&q__1, &u[p + p * u_dim1]);
  1593. u[i__2].r = q__1.r, u[i__2].i = q__1.i;
  1594. i__2 = nr;
  1595. for (q = p + 1; q <= i__2; ++q) {
  1596. r_cnjg(&q__1, &u[q + p * u_dim1]);
  1597. ctmp.r = q__1.r, ctmp.i = q__1.i;
  1598. i__3 = q + p * u_dim1;
  1599. r_cnjg(&q__1, &u[p + q * u_dim1]);
  1600. u[i__3].r = q__1.r, u[i__3].i = q__1.i;
  1601. i__3 = p + q * u_dim1;
  1602. u[i__3].r = ctmp.r, u[i__3].i = ctmp.i;
  1603. /* L1120: */
  1604. }
  1605. /* L1119: */
  1606. }
  1607. } else {
  1608. clacpy_("U", &nr, n, &a[a_offset], lda, &u[u_offset], ldu);
  1609. if (nr > 1) {
  1610. i__1 = nr - 1;
  1611. i__2 = nr - 1;
  1612. claset_("L", &i__1, &i__2, &c_b1, &c_b1, &u[u_dim1 + 2], ldu);
  1613. }
  1614. /* vectors overwrite [U](1:NR,1:NR) */
  1615. i__1 = *lcwork - *n;
  1616. cgesvd_("O", "N", &nr, n, &u[u_offset], ldu, &s[1], &u[u_offset],
  1617. ldu, &v[v_offset], ldv, &cwork[*n + 1], &i__1, &rwork[1],
  1618. info);
  1619. /* R. These will be pre-multiplied by Q to build the left singular */
  1620. /* vectors of A. */
  1621. }
  1622. /* (M x NR) or (M x N) or (M x M). */
  1623. if (nr < *m && ! wntuf) {
  1624. i__1 = *m - nr;
  1625. claset_("A", &i__1, &nr, &c_b1, &c_b1, &u[nr + 1 + u_dim1], ldu);
  1626. if (nr < n1) {
  1627. i__1 = n1 - nr;
  1628. claset_("A", &nr, &i__1, &c_b1, &c_b1, &u[(nr + 1) * u_dim1 +
  1629. 1], ldu);
  1630. i__1 = *m - nr;
  1631. i__2 = n1 - nr;
  1632. claset_("A", &i__1, &i__2, &c_b1, &c_b2, &u[nr + 1 + (nr + 1)
  1633. * u_dim1], ldu);
  1634. }
  1635. }
  1636. /* The Q matrix from the first QRF is built into the left singular */
  1637. /* vectors matrix U. */
  1638. if (! wntuf) {
  1639. i__1 = *lcwork - *n;
  1640. cunmqr_("L", "N", m, &n1, n, &a[a_offset], lda, &cwork[1], &u[
  1641. u_offset], ldu, &cwork[*n + 1], &i__1, &ierr);
  1642. }
  1643. if (rowprm && ! wntuf) {
  1644. i__1 = *m - 1;
  1645. claswp_(&n1, &u[u_offset], ldu, &c__1, &i__1, &iwork[*n + 1], &
  1646. c_n1);
  1647. }
  1648. } else if (rsvec && ! lsvec) {
  1649. /* ....................................................................... */
  1650. /* ....................................................................... */
  1651. if (rtrans) {
  1652. i__1 = nr;
  1653. for (p = 1; p <= i__1; ++p) {
  1654. i__2 = *n;
  1655. for (q = p; q <= i__2; ++q) {
  1656. i__3 = q + p * v_dim1;
  1657. r_cnjg(&q__1, &a[p + q * a_dim1]);
  1658. v[i__3].r = q__1.r, v[i__3].i = q__1.i;
  1659. /* L1166: */
  1660. }
  1661. /* L1165: */
  1662. }
  1663. if (nr > 1) {
  1664. i__1 = nr - 1;
  1665. i__2 = nr - 1;
  1666. claset_("U", &i__1, &i__2, &c_b1, &c_b1, &v[(v_dim1 << 1) + 1]
  1667. , ldv);
  1668. }
  1669. /* vectors not computed */
  1670. if (wntvr || nr == *n) {
  1671. i__1 = *lcwork - *n;
  1672. cgesvd_("O", "N", n, &nr, &v[v_offset], ldv, &s[1], &u[
  1673. u_offset], ldu, &u[u_offset], ldu, &cwork[*n + 1], &
  1674. i__1, &rwork[1], info);
  1675. i__1 = nr;
  1676. for (p = 1; p <= i__1; ++p) {
  1677. i__2 = p + p * v_dim1;
  1678. r_cnjg(&q__1, &v[p + p * v_dim1]);
  1679. v[i__2].r = q__1.r, v[i__2].i = q__1.i;
  1680. i__2 = nr;
  1681. for (q = p + 1; q <= i__2; ++q) {
  1682. r_cnjg(&q__1, &v[q + p * v_dim1]);
  1683. ctmp.r = q__1.r, ctmp.i = q__1.i;
  1684. i__3 = q + p * v_dim1;
  1685. r_cnjg(&q__1, &v[p + q * v_dim1]);
  1686. v[i__3].r = q__1.r, v[i__3].i = q__1.i;
  1687. i__3 = p + q * v_dim1;
  1688. v[i__3].r = ctmp.r, v[i__3].i = ctmp.i;
  1689. /* L1122: */
  1690. }
  1691. /* L1121: */
  1692. }
  1693. if (nr < *n) {
  1694. i__1 = nr;
  1695. for (p = 1; p <= i__1; ++p) {
  1696. i__2 = *n;
  1697. for (q = nr + 1; q <= i__2; ++q) {
  1698. i__3 = p + q * v_dim1;
  1699. r_cnjg(&q__1, &v[q + p * v_dim1]);
  1700. v[i__3].r = q__1.r, v[i__3].i = q__1.i;
  1701. /* L1104: */
  1702. }
  1703. /* L1103: */
  1704. }
  1705. }
  1706. clapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
  1707. } else {
  1708. /* [!] This is simple implementation that augments [V](1:N,1:NR) */
  1709. /* by padding a zero block. In the case NR << N, a more efficient */
  1710. /* way is to first use the QR factorization. For more details */
  1711. /* how to implement this, see the " FULL SVD " branch. */
  1712. i__1 = *n - nr;
  1713. claset_("G", n, &i__1, &c_b1, &c_b1, &v[(nr + 1) * v_dim1 + 1]
  1714. , ldv);
  1715. i__1 = *lcwork - *n;
  1716. cgesvd_("O", "N", n, n, &v[v_offset], ldv, &s[1], &u[u_offset]
  1717. , ldu, &u[u_offset], ldu, &cwork[*n + 1], &i__1, &
  1718. rwork[1], info);
  1719. i__1 = *n;
  1720. for (p = 1; p <= i__1; ++p) {
  1721. i__2 = p + p * v_dim1;
  1722. r_cnjg(&q__1, &v[p + p * v_dim1]);
  1723. v[i__2].r = q__1.r, v[i__2].i = q__1.i;
  1724. i__2 = *n;
  1725. for (q = p + 1; q <= i__2; ++q) {
  1726. r_cnjg(&q__1, &v[q + p * v_dim1]);
  1727. ctmp.r = q__1.r, ctmp.i = q__1.i;
  1728. i__3 = q + p * v_dim1;
  1729. r_cnjg(&q__1, &v[p + q * v_dim1]);
  1730. v[i__3].r = q__1.r, v[i__3].i = q__1.i;
  1731. i__3 = p + q * v_dim1;
  1732. v[i__3].r = ctmp.r, v[i__3].i = ctmp.i;
  1733. /* L1124: */
  1734. }
  1735. /* L1123: */
  1736. }
  1737. clapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  1738. }
  1739. } else {
  1740. clacpy_("U", &nr, n, &a[a_offset], lda, &v[v_offset], ldv);
  1741. if (nr > 1) {
  1742. i__1 = nr - 1;
  1743. i__2 = nr - 1;
  1744. claset_("L", &i__1, &i__2, &c_b1, &c_b1, &v[v_dim1 + 2], ldv);
  1745. }
  1746. /* vectors stored in U(1:NR,1:NR) */
  1747. if (wntvr || nr == *n) {
  1748. i__1 = *lcwork - *n;
  1749. cgesvd_("N", "O", &nr, n, &v[v_offset], ldv, &s[1], &u[
  1750. u_offset], ldu, &v[v_offset], ldv, &cwork[*n + 1], &
  1751. i__1, &rwork[1], info);
  1752. clapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
  1753. } else {
  1754. /* [!] This is simple implementation that augments [V](1:NR,1:N) */
  1755. /* by padding a zero block. In the case NR << N, a more efficient */
  1756. /* way is to first use the LQ factorization. For more details */
  1757. /* how to implement this, see the " FULL SVD " branch. */
  1758. i__1 = *n - nr;
  1759. claset_("G", &i__1, n, &c_b1, &c_b1, &v[nr + 1 + v_dim1], ldv);
  1760. i__1 = *lcwork - *n;
  1761. cgesvd_("N", "O", n, n, &v[v_offset], ldv, &s[1], &u[u_offset]
  1762. , ldu, &v[v_offset], ldv, &cwork[*n + 1], &i__1, &
  1763. rwork[1], info);
  1764. clapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  1765. }
  1766. /* vectors of A. */
  1767. }
  1768. } else {
  1769. /* ....................................................................... */
  1770. /* ....................................................................... */
  1771. if (rtrans) {
  1772. if (wntvr || nr == *n) {
  1773. /* vectors of R**H */
  1774. i__1 = nr;
  1775. for (p = 1; p <= i__1; ++p) {
  1776. i__2 = *n;
  1777. for (q = p; q <= i__2; ++q) {
  1778. i__3 = q + p * v_dim1;
  1779. r_cnjg(&q__1, &a[p + q * a_dim1]);
  1780. v[i__3].r = q__1.r, v[i__3].i = q__1.i;
  1781. /* L1169: */
  1782. }
  1783. /* L1168: */
  1784. }
  1785. if (nr > 1) {
  1786. i__1 = nr - 1;
  1787. i__2 = nr - 1;
  1788. claset_("U", &i__1, &i__2, &c_b1, &c_b1, &v[(v_dim1 << 1)
  1789. + 1], ldv);
  1790. }
  1791. /* singular vectors of R**H stored in [U](1:NR,1:NR) as conjugate */
  1792. /* transposed */
  1793. i__1 = *lcwork - *n;
  1794. cgesvd_("O", "A", n, &nr, &v[v_offset], ldv, &s[1], &v[
  1795. v_offset], ldv, &u[u_offset], ldu, &cwork[*n + 1], &
  1796. i__1, &rwork[1], info);
  1797. i__1 = nr;
  1798. for (p = 1; p <= i__1; ++p) {
  1799. i__2 = p + p * v_dim1;
  1800. r_cnjg(&q__1, &v[p + p * v_dim1]);
  1801. v[i__2].r = q__1.r, v[i__2].i = q__1.i;
  1802. i__2 = nr;
  1803. for (q = p + 1; q <= i__2; ++q) {
  1804. r_cnjg(&q__1, &v[q + p * v_dim1]);
  1805. ctmp.r = q__1.r, ctmp.i = q__1.i;
  1806. i__3 = q + p * v_dim1;
  1807. r_cnjg(&q__1, &v[p + q * v_dim1]);
  1808. v[i__3].r = q__1.r, v[i__3].i = q__1.i;
  1809. i__3 = p + q * v_dim1;
  1810. v[i__3].r = ctmp.r, v[i__3].i = ctmp.i;
  1811. /* L1116: */
  1812. }
  1813. /* L1115: */
  1814. }
  1815. if (nr < *n) {
  1816. i__1 = nr;
  1817. for (p = 1; p <= i__1; ++p) {
  1818. i__2 = *n;
  1819. for (q = nr + 1; q <= i__2; ++q) {
  1820. i__3 = p + q * v_dim1;
  1821. r_cnjg(&q__1, &v[q + p * v_dim1]);
  1822. v[i__3].r = q__1.r, v[i__3].i = q__1.i;
  1823. /* L1102: */
  1824. }
  1825. /* L1101: */
  1826. }
  1827. }
  1828. clapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
  1829. i__1 = nr;
  1830. for (p = 1; p <= i__1; ++p) {
  1831. i__2 = p + p * u_dim1;
  1832. r_cnjg(&q__1, &u[p + p * u_dim1]);
  1833. u[i__2].r = q__1.r, u[i__2].i = q__1.i;
  1834. i__2 = nr;
  1835. for (q = p + 1; q <= i__2; ++q) {
  1836. r_cnjg(&q__1, &u[q + p * u_dim1]);
  1837. ctmp.r = q__1.r, ctmp.i = q__1.i;
  1838. i__3 = q + p * u_dim1;
  1839. r_cnjg(&q__1, &u[p + q * u_dim1]);
  1840. u[i__3].r = q__1.r, u[i__3].i = q__1.i;
  1841. i__3 = p + q * u_dim1;
  1842. u[i__3].r = ctmp.r, u[i__3].i = ctmp.i;
  1843. /* L1118: */
  1844. }
  1845. /* L1117: */
  1846. }
  1847. if (nr < *m && ! wntuf) {
  1848. i__1 = *m - nr;
  1849. claset_("A", &i__1, &nr, &c_b1, &c_b1, &u[nr + 1 + u_dim1]
  1850. , ldu);
  1851. if (nr < n1) {
  1852. i__1 = n1 - nr;
  1853. claset_("A", &nr, &i__1, &c_b1, &c_b1, &u[(nr + 1) *
  1854. u_dim1 + 1], ldu);
  1855. i__1 = *m - nr;
  1856. i__2 = n1 - nr;
  1857. claset_("A", &i__1, &i__2, &c_b1, &c_b2, &u[nr + 1 + (
  1858. nr + 1) * u_dim1], ldu);
  1859. }
  1860. }
  1861. } else {
  1862. /* vectors of R**H */
  1863. /* [[The optimal ratio N/NR for using QRF instead of padding */
  1864. /* with zeros. Here hard coded to 2; it must be at least */
  1865. /* two due to work space constraints.]] */
  1866. /* OPTRATIO = ILAENV(6, 'CGESVD', 'S' // 'O', NR,N,0,0) */
  1867. /* OPTRATIO = MAX( OPTRATIO, 2 ) */
  1868. optratio = 2;
  1869. if (optratio * nr > *n) {
  1870. i__1 = nr;
  1871. for (p = 1; p <= i__1; ++p) {
  1872. i__2 = *n;
  1873. for (q = p; q <= i__2; ++q) {
  1874. i__3 = q + p * v_dim1;
  1875. r_cnjg(&q__1, &a[p + q * a_dim1]);
  1876. v[i__3].r = q__1.r, v[i__3].i = q__1.i;
  1877. /* L1199: */
  1878. }
  1879. /* L1198: */
  1880. }
  1881. if (nr > 1) {
  1882. i__1 = nr - 1;
  1883. i__2 = nr - 1;
  1884. claset_("U", &i__1, &i__2, &c_b1, &c_b1, &v[(v_dim1 <<
  1885. 1) + 1], ldv);
  1886. }
  1887. i__1 = *n - nr;
  1888. claset_("A", n, &i__1, &c_b1, &c_b1, &v[(nr + 1) * v_dim1
  1889. + 1], ldv);
  1890. i__1 = *lcwork - *n;
  1891. cgesvd_("O", "A", n, n, &v[v_offset], ldv, &s[1], &v[
  1892. v_offset], ldv, &u[u_offset], ldu, &cwork[*n + 1],
  1893. &i__1, &rwork[1], info);
  1894. i__1 = *n;
  1895. for (p = 1; p <= i__1; ++p) {
  1896. i__2 = p + p * v_dim1;
  1897. r_cnjg(&q__1, &v[p + p * v_dim1]);
  1898. v[i__2].r = q__1.r, v[i__2].i = q__1.i;
  1899. i__2 = *n;
  1900. for (q = p + 1; q <= i__2; ++q) {
  1901. r_cnjg(&q__1, &v[q + p * v_dim1]);
  1902. ctmp.r = q__1.r, ctmp.i = q__1.i;
  1903. i__3 = q + p * v_dim1;
  1904. r_cnjg(&q__1, &v[p + q * v_dim1]);
  1905. v[i__3].r = q__1.r, v[i__3].i = q__1.i;
  1906. i__3 = p + q * v_dim1;
  1907. v[i__3].r = ctmp.r, v[i__3].i = ctmp.i;
  1908. /* L1114: */
  1909. }
  1910. /* L1113: */
  1911. }
  1912. clapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  1913. /* (M x N1), i.e. (M x N) or (M x M). */
  1914. i__1 = *n;
  1915. for (p = 1; p <= i__1; ++p) {
  1916. i__2 = p + p * u_dim1;
  1917. r_cnjg(&q__1, &u[p + p * u_dim1]);
  1918. u[i__2].r = q__1.r, u[i__2].i = q__1.i;
  1919. i__2 = *n;
  1920. for (q = p + 1; q <= i__2; ++q) {
  1921. r_cnjg(&q__1, &u[q + p * u_dim1]);
  1922. ctmp.r = q__1.r, ctmp.i = q__1.i;
  1923. i__3 = q + p * u_dim1;
  1924. r_cnjg(&q__1, &u[p + q * u_dim1]);
  1925. u[i__3].r = q__1.r, u[i__3].i = q__1.i;
  1926. i__3 = p + q * u_dim1;
  1927. u[i__3].r = ctmp.r, u[i__3].i = ctmp.i;
  1928. /* L1112: */
  1929. }
  1930. /* L1111: */
  1931. }
  1932. if (*n < *m && ! wntuf) {
  1933. i__1 = *m - *n;
  1934. claset_("A", &i__1, n, &c_b1, &c_b1, &u[*n + 1 +
  1935. u_dim1], ldu);
  1936. if (*n < n1) {
  1937. i__1 = n1 - *n;
  1938. claset_("A", n, &i__1, &c_b1, &c_b1, &u[(*n + 1) *
  1939. u_dim1 + 1], ldu);
  1940. i__1 = *m - *n;
  1941. i__2 = n1 - *n;
  1942. claset_("A", &i__1, &i__2, &c_b1, &c_b2, &u[*n +
  1943. 1 + (*n + 1) * u_dim1], ldu);
  1944. }
  1945. }
  1946. } else {
  1947. /* singular vectors of R */
  1948. i__1 = nr;
  1949. for (p = 1; p <= i__1; ++p) {
  1950. i__2 = *n;
  1951. for (q = p; q <= i__2; ++q) {
  1952. i__3 = q + (nr + p) * u_dim1;
  1953. r_cnjg(&q__1, &a[p + q * a_dim1]);
  1954. u[i__3].r = q__1.r, u[i__3].i = q__1.i;
  1955. /* L1197: */
  1956. }
  1957. /* L1196: */
  1958. }
  1959. if (nr > 1) {
  1960. i__1 = nr - 1;
  1961. i__2 = nr - 1;
  1962. claset_("U", &i__1, &i__2, &c_b1, &c_b1, &u[(nr + 2) *
  1963. u_dim1 + 1], ldu);
  1964. }
  1965. i__1 = *lcwork - *n - nr;
  1966. cgeqrf_(n, &nr, &u[(nr + 1) * u_dim1 + 1], ldu, &cwork[*n
  1967. + 1], &cwork[*n + nr + 1], &i__1, &ierr);
  1968. i__1 = nr;
  1969. for (p = 1; p <= i__1; ++p) {
  1970. i__2 = *n;
  1971. for (q = 1; q <= i__2; ++q) {
  1972. i__3 = q + p * v_dim1;
  1973. r_cnjg(&q__1, &u[p + (nr + q) * u_dim1]);
  1974. v[i__3].r = q__1.r, v[i__3].i = q__1.i;
  1975. /* L1144: */
  1976. }
  1977. /* L1143: */
  1978. }
  1979. i__1 = nr - 1;
  1980. i__2 = nr - 1;
  1981. claset_("U", &i__1, &i__2, &c_b1, &c_b1, &v[(v_dim1 << 1)
  1982. + 1], ldv);
  1983. i__1 = *lcwork - *n - nr;
  1984. cgesvd_("S", "O", &nr, &nr, &v[v_offset], ldv, &s[1], &u[
  1985. u_offset], ldu, &v[v_offset], ldv, &cwork[*n + nr
  1986. + 1], &i__1, &rwork[1], info);
  1987. i__1 = *n - nr;
  1988. claset_("A", &i__1, &nr, &c_b1, &c_b1, &v[nr + 1 + v_dim1]
  1989. , ldv);
  1990. i__1 = *n - nr;
  1991. claset_("A", &nr, &i__1, &c_b1, &c_b1, &v[(nr + 1) *
  1992. v_dim1 + 1], ldv);
  1993. i__1 = *n - nr;
  1994. i__2 = *n - nr;
  1995. claset_("A", &i__1, &i__2, &c_b1, &c_b2, &v[nr + 1 + (nr
  1996. + 1) * v_dim1], ldv);
  1997. i__1 = *lcwork - *n - nr;
  1998. cunmqr_("R", "C", n, n, &nr, &u[(nr + 1) * u_dim1 + 1],
  1999. ldu, &cwork[*n + 1], &v[v_offset], ldv, &cwork[*n
  2000. + nr + 1], &i__1, &ierr);
  2001. clapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  2002. /* (M x NR) or (M x N) or (M x M). */
  2003. if (nr < *m && ! wntuf) {
  2004. i__1 = *m - nr;
  2005. claset_("A", &i__1, &nr, &c_b1, &c_b1, &u[nr + 1 +
  2006. u_dim1], ldu);
  2007. if (nr < n1) {
  2008. i__1 = n1 - nr;
  2009. claset_("A", &nr, &i__1, &c_b1, &c_b1, &u[(nr + 1)
  2010. * u_dim1 + 1], ldu);
  2011. i__1 = *m - nr;
  2012. i__2 = n1 - nr;
  2013. claset_("A", &i__1, &i__2, &c_b1, &c_b2, &u[nr +
  2014. 1 + (nr + 1) * u_dim1], ldu);
  2015. }
  2016. }
  2017. }
  2018. }
  2019. } else {
  2020. if (wntvr || nr == *n) {
  2021. clacpy_("U", &nr, n, &a[a_offset], lda, &v[v_offset], ldv);
  2022. if (nr > 1) {
  2023. i__1 = nr - 1;
  2024. i__2 = nr - 1;
  2025. claset_("L", &i__1, &i__2, &c_b1, &c_b1, &v[v_dim1 + 2],
  2026. ldv);
  2027. }
  2028. /* singular vectors of R stored in [U](1:NR,1:NR) */
  2029. i__1 = *lcwork - *n;
  2030. cgesvd_("S", "O", &nr, n, &v[v_offset], ldv, &s[1], &u[
  2031. u_offset], ldu, &v[v_offset], ldv, &cwork[*n + 1], &
  2032. i__1, &rwork[1], info);
  2033. clapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
  2034. /* (M x NR) or (M x N) or (M x M). */
  2035. if (nr < *m && ! wntuf) {
  2036. i__1 = *m - nr;
  2037. claset_("A", &i__1, &nr, &c_b1, &c_b1, &u[nr + 1 + u_dim1]
  2038. , ldu);
  2039. if (nr < n1) {
  2040. i__1 = n1 - nr;
  2041. claset_("A", &nr, &i__1, &c_b1, &c_b1, &u[(nr + 1) *
  2042. u_dim1 + 1], ldu);
  2043. i__1 = *m - nr;
  2044. i__2 = n1 - nr;
  2045. claset_("A", &i__1, &i__2, &c_b1, &c_b2, &u[nr + 1 + (
  2046. nr + 1) * u_dim1], ldu);
  2047. }
  2048. }
  2049. } else {
  2050. /* is then N1 (N or M) */
  2051. /* [[The optimal ratio N/NR for using LQ instead of padding */
  2052. /* with zeros. Here hard coded to 2; it must be at least */
  2053. /* two due to work space constraints.]] */
  2054. /* OPTRATIO = ILAENV(6, 'CGESVD', 'S' // 'O', NR,N,0,0) */
  2055. /* OPTRATIO = MAX( OPTRATIO, 2 ) */
  2056. optratio = 2;
  2057. if (optratio * nr > *n) {
  2058. clacpy_("U", &nr, n, &a[a_offset], lda, &v[v_offset], ldv);
  2059. if (nr > 1) {
  2060. i__1 = nr - 1;
  2061. i__2 = nr - 1;
  2062. claset_("L", &i__1, &i__2, &c_b1, &c_b1, &v[v_dim1 +
  2063. 2], ldv);
  2064. }
  2065. /* singular vectors of R stored in [U](1:NR,1:NR) */
  2066. i__1 = *n - nr;
  2067. claset_("A", &i__1, n, &c_b1, &c_b1, &v[nr + 1 + v_dim1],
  2068. ldv);
  2069. i__1 = *lcwork - *n;
  2070. cgesvd_("S", "O", n, n, &v[v_offset], ldv, &s[1], &u[
  2071. u_offset], ldu, &v[v_offset], ldv, &cwork[*n + 1],
  2072. &i__1, &rwork[1], info);
  2073. clapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  2074. /* singular vectors of A. The leading N left singular vectors */
  2075. /* are in [U](1:N,1:N) */
  2076. /* (M x N1), i.e. (M x N) or (M x M). */
  2077. if (*n < *m && ! wntuf) {
  2078. i__1 = *m - *n;
  2079. claset_("A", &i__1, n, &c_b1, &c_b1, &u[*n + 1 +
  2080. u_dim1], ldu);
  2081. if (*n < n1) {
  2082. i__1 = n1 - *n;
  2083. claset_("A", n, &i__1, &c_b1, &c_b1, &u[(*n + 1) *
  2084. u_dim1 + 1], ldu);
  2085. i__1 = *m - *n;
  2086. i__2 = n1 - *n;
  2087. claset_("A", &i__1, &i__2, &c_b1, &c_b2, &u[*n +
  2088. 1 + (*n + 1) * u_dim1], ldu);
  2089. }
  2090. }
  2091. } else {
  2092. clacpy_("U", &nr, n, &a[a_offset], lda, &u[nr + 1 +
  2093. u_dim1], ldu);
  2094. if (nr > 1) {
  2095. i__1 = nr - 1;
  2096. i__2 = nr - 1;
  2097. claset_("L", &i__1, &i__2, &c_b1, &c_b1, &u[nr + 2 +
  2098. u_dim1], ldu);
  2099. }
  2100. i__1 = *lcwork - *n - nr;
  2101. cgelqf_(&nr, n, &u[nr + 1 + u_dim1], ldu, &cwork[*n + 1],
  2102. &cwork[*n + nr + 1], &i__1, &ierr);
  2103. clacpy_("L", &nr, &nr, &u[nr + 1 + u_dim1], ldu, &v[
  2104. v_offset], ldv);
  2105. if (nr > 1) {
  2106. i__1 = nr - 1;
  2107. i__2 = nr - 1;
  2108. claset_("U", &i__1, &i__2, &c_b1, &c_b1, &v[(v_dim1 <<
  2109. 1) + 1], ldv);
  2110. }
  2111. i__1 = *lcwork - *n - nr;
  2112. cgesvd_("S", "O", &nr, &nr, &v[v_offset], ldv, &s[1], &u[
  2113. u_offset], ldu, &v[v_offset], ldv, &cwork[*n + nr
  2114. + 1], &i__1, &rwork[1], info);
  2115. i__1 = *n - nr;
  2116. claset_("A", &i__1, &nr, &c_b1, &c_b1, &v[nr + 1 + v_dim1]
  2117. , ldv);
  2118. i__1 = *n - nr;
  2119. claset_("A", &nr, &i__1, &c_b1, &c_b1, &v[(nr + 1) *
  2120. v_dim1 + 1], ldv);
  2121. i__1 = *n - nr;
  2122. i__2 = *n - nr;
  2123. claset_("A", &i__1, &i__2, &c_b1, &c_b2, &v[nr + 1 + (nr
  2124. + 1) * v_dim1], ldv);
  2125. i__1 = *lcwork - *n - nr;
  2126. cunmlq_("R", "N", n, n, &nr, &u[nr + 1 + u_dim1], ldu, &
  2127. cwork[*n + 1], &v[v_offset], ldv, &cwork[*n + nr
  2128. + 1], &i__1, &ierr);
  2129. clapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  2130. /* (M x NR) or (M x N) or (M x M). */
  2131. if (nr < *m && ! wntuf) {
  2132. i__1 = *m - nr;
  2133. claset_("A", &i__1, &nr, &c_b1, &c_b1, &u[nr + 1 +
  2134. u_dim1], ldu);
  2135. if (nr < n1) {
  2136. i__1 = n1 - nr;
  2137. claset_("A", &nr, &i__1, &c_b1, &c_b1, &u[(nr + 1)
  2138. * u_dim1 + 1], ldu);
  2139. i__1 = *m - nr;
  2140. i__2 = n1 - nr;
  2141. claset_("A", &i__1, &i__2, &c_b1, &c_b2, &u[nr +
  2142. 1 + (nr + 1) * u_dim1], ldu);
  2143. }
  2144. }
  2145. }
  2146. }
  2147. }
  2148. /* The Q matrix from the first QRF is built into the left singular */
  2149. /* vectors matrix U. */
  2150. if (! wntuf) {
  2151. i__1 = *lcwork - *n;
  2152. cunmqr_("L", "N", m, &n1, n, &a[a_offset], lda, &cwork[1], &u[
  2153. u_offset], ldu, &cwork[*n + 1], &i__1, &ierr);
  2154. }
  2155. if (rowprm && ! wntuf) {
  2156. i__1 = *m - 1;
  2157. claswp_(&n1, &u[u_offset], ldu, &c__1, &i__1, &iwork[*n + 1], &
  2158. c_n1);
  2159. }
  2160. /* ... end of the "full SVD" branch */
  2161. }
  2162. /* Check whether some singular values are returned as zeros, e.g. */
  2163. /* due to underflow, and update the numerical rank. */
  2164. p = nr;
  2165. for (q = p; q >= 1; --q) {
  2166. if (s[q] > 0.f) {
  2167. goto L4002;
  2168. }
  2169. --nr;
  2170. /* L4001: */
  2171. }
  2172. L4002:
  2173. /* singular values are set to zero. */
  2174. if (nr < *n) {
  2175. i__1 = *n - nr;
  2176. slaset_("G", &i__1, &c__1, &c_b74, &c_b74, &s[nr + 1], n);
  2177. }
  2178. /* values. */
  2179. if (ascaled) {
  2180. r__1 = sqrt((real) (*m));
  2181. slascl_("G", &c__0, &c__0, &c_b87, &r__1, &nr, &c__1, &s[1], n, &ierr);
  2182. }
  2183. if (conda) {
  2184. rwork[1] = sconda;
  2185. }
  2186. rwork[2] = (real) (p - nr);
  2187. /* exact zeros in CGESVD() applied to the (possibly truncated) */
  2188. /* full row rank triangular (trapezoidal) factor of A. */
  2189. *numrank = nr;
  2190. return 0;
  2191. /* End of CGESVDQ */
  2192. } /* cgesvdq_ */