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

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