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.

zgesvdq.c 76 kB

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