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 blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #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]);}
  172. #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]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  217. #define pow_si(B,E) spow_ui(*(B),*(E))
  218. #define pow_ri(B,E) spow_ui(*(B),*(E))
  219. #define pow_di(B,E) dpow_ui(*(B),*(E))
  220. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  221. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  222. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  223. #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++ = ' '; }
  224. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  225. #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]; }
  226. #define sig_die(s, kill) { exit(1); }
  227. #define s_stop(s, n) {exit(0);}
  228. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  229. #define z_abs(z) (cabs(Cd(z)))
  230. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  231. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  232. #define myexit_() break;
  233. #define mycycle() continue;
  234. #define myceiling(w) {ceil(w)}
  235. #define myhuge(w) {HUGE_VAL}
  236. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  237. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  238. /* procedure parameter types for -A and -C++ */
  239. #ifdef __cplusplus
  240. typedef logical (*L_fp)(...);
  241. #else
  242. typedef logical (*L_fp)();
  243. #endif
  244. static float spow_ui(float x, integer n) {
  245. float pow=1.0; unsigned long int u;
  246. if(n != 0) {
  247. if(n < 0) n = -n, x = 1/x;
  248. for(u = n; ; ) {
  249. if(u & 01) pow *= x;
  250. if(u >>= 1) x *= x;
  251. else break;
  252. }
  253. }
  254. return pow;
  255. }
  256. static double dpow_ui(double x, integer n) {
  257. double pow=1.0; unsigned long int u;
  258. if(n != 0) {
  259. if(n < 0) n = -n, x = 1/x;
  260. for(u = n; ; ) {
  261. if(u & 01) pow *= x;
  262. if(u >>= 1) x *= x;
  263. else break;
  264. }
  265. }
  266. return pow;
  267. }
  268. #ifdef _MSC_VER
  269. static _Fcomplex cpow_ui(complex x, integer n) {
  270. complex pow={1.0,0.0}; unsigned long int u;
  271. if(n != 0) {
  272. if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
  273. for(u = n; ; ) {
  274. if(u & 01) pow.r *= x.r, pow.i *= x.i;
  275. if(u >>= 1) x.r *= x.r, x.i *= x.i;
  276. else break;
  277. }
  278. }
  279. _Fcomplex p={pow.r, pow.i};
  280. return p;
  281. }
  282. #else
  283. static _Complex float cpow_ui(_Complex float x, integer n) {
  284. _Complex float pow=1.0; unsigned long int u;
  285. if(n != 0) {
  286. if(n < 0) n = -n, x = 1/x;
  287. for(u = n; ; ) {
  288. if(u & 01) pow *= x;
  289. if(u >>= 1) x *= x;
  290. else break;
  291. }
  292. }
  293. return pow;
  294. }
  295. #endif
  296. #ifdef _MSC_VER
  297. static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
  298. _Dcomplex pow={1.0,0.0}; unsigned long int u;
  299. if(n != 0) {
  300. if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
  301. for(u = n; ; ) {
  302. if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
  303. if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
  304. else break;
  305. }
  306. }
  307. _Dcomplex p = {pow._Val[0], pow._Val[1]};
  308. return p;
  309. }
  310. #else
  311. static _Complex double zpow_ui(_Complex double x, integer n) {
  312. _Complex double pow=1.0; unsigned long int u;
  313. if(n != 0) {
  314. if(n < 0) n = -n, x = 1/x;
  315. for(u = n; ; ) {
  316. if(u & 01) pow *= x;
  317. if(u >>= 1) x *= x;
  318. else break;
  319. }
  320. }
  321. return pow;
  322. }
  323. #endif
  324. static integer pow_ii(integer x, integer n) {
  325. integer pow; unsigned long int u;
  326. if (n <= 0) {
  327. if (n == 0 || x == 1) pow = 1;
  328. else if (x != -1) pow = x == 0 ? 1/x : 0;
  329. else n = -n;
  330. }
  331. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  332. u = n;
  333. for(pow = 1; ; ) {
  334. if(u & 01) pow *= x;
  335. if(u >>= 1) x *= x;
  336. else break;
  337. }
  338. }
  339. return pow;
  340. }
  341. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  342. {
  343. double m; integer i, mi;
  344. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  345. if (w[i-1]>m) mi=i ,m=w[i-1];
  346. return mi-s+1;
  347. }
  348. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  349. {
  350. float m; integer i, mi;
  351. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  352. if (w[i-1]>m) mi=i ,m=w[i-1];
  353. return mi-s+1;
  354. }
  355. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  356. integer n = *n_, incx = *incx_, incy = *incy_, i;
  357. #ifdef _MSC_VER
  358. _Fcomplex zdotc = {0.0, 0.0};
  359. if (incx == 1 && incy == 1) {
  360. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  361. zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
  362. zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
  363. }
  364. } else {
  365. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  366. zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
  367. zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
  368. }
  369. }
  370. pCf(z) = zdotc;
  371. }
  372. #else
  373. _Complex float zdotc = 0.0;
  374. if (incx == 1 && incy == 1) {
  375. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  376. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  377. }
  378. } else {
  379. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  380. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  381. }
  382. }
  383. pCf(z) = zdotc;
  384. }
  385. #endif
  386. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  387. integer n = *n_, incx = *incx_, incy = *incy_, i;
  388. #ifdef _MSC_VER
  389. _Dcomplex zdotc = {0.0, 0.0};
  390. if (incx == 1 && incy == 1) {
  391. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  392. zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
  393. zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
  394. }
  395. } else {
  396. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  397. zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
  398. zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
  399. }
  400. }
  401. pCd(z) = zdotc;
  402. }
  403. #else
  404. _Complex double zdotc = 0.0;
  405. if (incx == 1 && incy == 1) {
  406. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  407. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  408. }
  409. } else {
  410. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  411. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  412. }
  413. }
  414. pCd(z) = zdotc;
  415. }
  416. #endif
  417. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  418. integer n = *n_, incx = *incx_, incy = *incy_, i;
  419. #ifdef _MSC_VER
  420. _Fcomplex zdotc = {0.0, 0.0};
  421. if (incx == 1 && incy == 1) {
  422. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  423. zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
  424. zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
  425. }
  426. } else {
  427. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  428. zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
  429. zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
  430. }
  431. }
  432. pCf(z) = zdotc;
  433. }
  434. #else
  435. _Complex float zdotc = 0.0;
  436. if (incx == 1 && incy == 1) {
  437. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  438. zdotc += Cf(&x[i]) * Cf(&y[i]);
  439. }
  440. } else {
  441. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  442. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  443. }
  444. }
  445. pCf(z) = zdotc;
  446. }
  447. #endif
  448. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  449. integer n = *n_, incx = *incx_, incy = *incy_, i;
  450. #ifdef _MSC_VER
  451. _Dcomplex zdotc = {0.0, 0.0};
  452. if (incx == 1 && incy == 1) {
  453. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  454. zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
  455. zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
  456. }
  457. } else {
  458. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  459. zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
  460. zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
  461. }
  462. }
  463. pCd(z) = zdotc;
  464. }
  465. #else
  466. _Complex double zdotc = 0.0;
  467. if (incx == 1 && incy == 1) {
  468. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  469. zdotc += Cd(&x[i]) * Cd(&y[i]);
  470. }
  471. } else {
  472. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  473. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  474. }
  475. }
  476. pCd(z) = zdotc;
  477. }
  478. #endif
  479. /* -- translated by f2c (version 20000121).
  480. You must link the resulting object file with the libraries:
  481. -lf2c -lm (in that order)
  482. */
  483. /* Table of constant values */
  484. static doublecomplex c_b1 = {0.,0.};
  485. static doublecomplex c_b2 = {1.,0.};
  486. static integer c_n1 = -1;
  487. static integer c__1 = 1;
  488. static doublereal c_b74 = 0.;
  489. static integer c__0 = 0;
  490. static doublereal c_b87 = 1.;
  491. static logical c_false = FALSE_;
  492. /* > \brief <b> ZGESVDQ computes the singular value decomposition (SVD) with a QR-Preconditioned QR SVD Method
  493. for GE matrices</b> */
  494. /* =========== DOCUMENTATION =========== */
  495. /* Online html documentation available at */
  496. /* http://www.netlib.org/lapack/explore-html/ */
  497. /* > \htmlonly */
  498. /* > Download ZGESVDQ + dependencies */
  499. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zgesvdq
  500. .f"> */
  501. /* > [TGZ]</a> */
  502. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zgesvdq
  503. .f"> */
  504. /* > [ZIP]</a> */
  505. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zgesvdq
  506. .f"> */
  507. /* > [TXT]</a> */
  508. /* > \endhtmlonly */
  509. /* Definition: */
  510. /* =========== */
  511. /* SUBROUTINE ZGESVDQ( JOBA, JOBP, JOBR, JOBU, JOBV, M, N, A, LDA, */
  512. /* S, U, LDU, V, LDV, NUMRANK, IWORK, LIWORK, */
  513. /* CWORK, LCWORK, RWORK, LRWORK, INFO ) */
  514. /* IMPLICIT NONE */
  515. /* CHARACTER JOBA, JOBP, JOBR, JOBU, JOBV */
  516. /* INTEGER M, N, LDA, LDU, LDV, NUMRANK, LIWORK, LCWORK, LRWORK, */
  517. /* INFO */
  518. /* COMPLEX*16 A( LDA, * ), U( LDU, * ), V( LDV, * ), CWORK( * ) */
  519. /* DOUBLE PRECISION S( * ), RWORK( * ) */
  520. /* INTEGER IWORK( * ) */
  521. /* > \par Purpose: */
  522. /* ============= */
  523. /* > */
  524. /* > \verbatim */
  525. /* > */
  526. /* ZCGESVDQ computes the singular value decomposition (SVD) of a complex */
  527. /* > M-by-N matrix A, where M >= N. The SVD of A is written as */
  528. /* > [++] [xx] [x0] [xx] */
  529. /* > A = U * SIGMA * V^*, [++] = [xx] * [ox] * [xx] */
  530. /* > [++] [xx] */
  531. /* > where SIGMA is an N-by-N diagonal matrix, U is an M-by-N orthonormal */
  532. /* > matrix, and V is an N-by-N unitary matrix. The diagonal elements */
  533. /* > of SIGMA are the singular values of A. The columns of U and V are the */
  534. /* > left and the right singular vectors of A, respectively. */
  535. /* > \endverbatim */
  536. /* Arguments */
  537. /* ========= */
  538. /* > \param[in] JOBA */
  539. /* > \verbatim */
  540. /* > JOBA is CHARACTER*1 */
  541. /* > Specifies the level of accuracy in the computed SVD */
  542. /* > = 'A' The requested accuracy corresponds to having the backward */
  543. /* > error bounded by || delta A ||_F <= f(m,n) * EPS * || A ||_F, */
  544. /* > where EPS = DLAMCH('Epsilon'). This authorises ZGESVDQ to */
  545. /* > truncate the computed triangular factor in a rank revealing */
  546. /* > QR factorization whenever the truncated part is below the */
  547. /* > threshold of the order of EPS * ||A||_F. This is aggressive */
  548. /* > truncation level. */
  549. /* > = 'M' Similarly as with 'A', but the truncation is more gentle: it */
  550. /* > is allowed only when there is a drop on the diagonal of the */
  551. /* > triangular factor in the QR factorization. This is medium */
  552. /* > truncation level. */
  553. /* > = 'H' High accuracy requested. No numerical rank determination based */
  554. /* > on the rank revealing QR factorization is attempted. */
  555. /* > = 'E' Same as 'H', and in addition the condition number of column */
  556. /* > scaled A is estimated and returned in RWORK(1). */
  557. /* > N^(-1/4)*RWORK(1) <= ||pinv(A_scaled)||_2 <= N^(1/4)*RWORK(1) */
  558. /* > \endverbatim */
  559. /* > */
  560. /* > \param[in] JOBP */
  561. /* > \verbatim */
  562. /* > JOBP is CHARACTER*1 */
  563. /* > = 'P' The rows of A are ordered in decreasing order with respect to */
  564. /* > ||A(i,:)||_\infty. This enhances numerical accuracy at the cost */
  565. /* > of extra data movement. Recommended for numerical robustness. */
  566. /* > = 'N' No row pivoting. */
  567. /* > \endverbatim */
  568. /* > */
  569. /* > \param[in] JOBR */
  570. /* > \verbatim */
  571. /* > JOBR is CHARACTER*1 */
  572. /* > = 'T' After the initial pivoted QR factorization, ZGESVD is applied to */
  573. /* > the adjoint R**H of the computed triangular factor R. This involves */
  574. /* > some extra data movement (matrix transpositions). Useful for */
  575. /* > experiments, research and development. */
  576. /* > = 'N' The triangular factor R is given as input to CGESVD. This may be */
  577. /* > preferred as it involves less data movement. */
  578. /* > \endverbatim */
  579. /* > */
  580. /* > \param[in] JOBU */
  581. /* > \verbatim */
  582. /* > JOBU is CHARACTER*1 */
  583. /* > = 'A' All M left singular vectors are computed and returned in the */
  584. /* > matrix U. See the description of U. */
  585. /* > = 'S' or 'U' N = f2cmin(M,N) left singular vectors are computed and returned */
  586. /* > in the matrix U. See the description of U. */
  587. /* > = 'R' Numerical rank NUMRANK is determined and only NUMRANK left singular */
  588. /* > vectors are computed and returned in the matrix U. */
  589. /* > = 'F' The N left singular vectors are returned in factored form as the */
  590. /* > product of the Q factor from the initial QR factorization and the */
  591. /* > N left singular vectors of (R**H , 0)**H. If row pivoting is used, */
  592. /* > then the necessary information on the row pivoting is stored in */
  593. /* > IWORK(N+1:N+M-1). */
  594. /* > = 'N' The left singular vectors are not computed. */
  595. /* > \endverbatim */
  596. /* > */
  597. /* > \param[in] JOBV */
  598. /* > \verbatim */
  599. /* > JOBV is CHARACTER*1 */
  600. /* > = 'A', 'V' All N right singular vectors are computed and returned in */
  601. /* > the matrix V. */
  602. /* > = 'R' Numerical rank NUMRANK is determined and only NUMRANK right singular */
  603. /* > vectors are computed and returned in the matrix V. This option is */
  604. /* > allowed only if JOBU = 'R' or JOBU = 'N'; otherwise it is illegal. */
  605. /* > = 'N' The right singular vectors are not computed. */
  606. /* > \endverbatim */
  607. /* > */
  608. /* > \param[in] M */
  609. /* > \verbatim */
  610. /* > M is INTEGER */
  611. /* > The number of rows of the input matrix A. M >= 0. */
  612. /* > \endverbatim */
  613. /* > */
  614. /* > \param[in] N */
  615. /* > \verbatim */
  616. /* > N is INTEGER */
  617. /* > The number of columns of the input matrix A. M >= N >= 0. */
  618. /* > \endverbatim */
  619. /* > */
  620. /* > \param[in,out] A */
  621. /* > \verbatim */
  622. /* > A is COMPLEX*16 array of dimensions LDA x N */
  623. /* > On entry, the input matrix A. */
  624. /* > On exit, if JOBU .NE. 'N' or JOBV .NE. 'N', the lower triangle of A contains */
  625. /* > the Householder vectors as stored by ZGEQP3. If JOBU = 'F', these Householder */
  626. /* > vectors together with CWORK(1:N) can be used to restore the Q factors from */
  627. /* > the initial pivoted QR factorization of A. See the description of U. */
  628. /* > \endverbatim */
  629. /* > */
  630. /* > \param[in] LDA */
  631. /* > \verbatim */
  632. /* > LDA is INTEGER. */
  633. /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
  634. /* > \endverbatim */
  635. /* > */
  636. /* > \param[out] S */
  637. /* > \verbatim */
  638. /* > S is DOUBLE PRECISION array of dimension N. */
  639. /* > The singular values of A, ordered so that S(i) >= S(i+1). */
  640. /* > \endverbatim */
  641. /* > */
  642. /* > \param[out] U */
  643. /* > \verbatim */
  644. /* > U is COMPLEX*16 array, dimension */
  645. /* > LDU x M if JOBU = 'A'; see the description of LDU. In this case, */
  646. /* > on exit, U contains the M left singular vectors. */
  647. /* > LDU x N if JOBU = 'S', 'U', 'R' ; see the description of LDU. In this */
  648. /* > case, U contains the leading N or the leading NUMRANK left singular vectors. */
  649. /* > LDU x N if JOBU = 'F' ; see the description of LDU. In this case U */
  650. /* > contains N x N unitary matrix that can be used to form the left */
  651. /* > singular vectors. */
  652. /* > If JOBU = 'N', U is not referenced. */
  653. /* > \endverbatim */
  654. /* > */
  655. /* > \param[in] LDU */
  656. /* > \verbatim */
  657. /* > LDU is INTEGER. */
  658. /* > The leading dimension of the array U. */
  659. /* > If JOBU = 'A', 'S', 'U', 'R', LDU >= f2cmax(1,M). */
  660. /* > If JOBU = 'F', LDU >= f2cmax(1,N). */
  661. /* > Otherwise, LDU >= 1. */
  662. /* > \endverbatim */
  663. /* > */
  664. /* > \param[out] V */
  665. /* > \verbatim */
  666. /* > V is COMPLEX*16 array, dimension */
  667. /* > LDV x N if JOBV = 'A', 'V', 'R' or if JOBA = 'E' . */
  668. /* > If JOBV = 'A', or 'V', V contains the N-by-N unitary matrix V**H; */
  669. /* > If JOBV = 'R', V contains the first NUMRANK rows of V**H (the right */
  670. /* > singular vectors, stored rowwise, of the NUMRANK largest singular values). */
  671. /* > If JOBV = 'N' and JOBA = 'E', V is used as a workspace. */
  672. /* > If JOBV = 'N', and JOBA.NE.'E', V is not referenced. */
  673. /* > \endverbatim */
  674. /* > */
  675. /* > \param[in] LDV */
  676. /* > \verbatim */
  677. /* > LDV is INTEGER */
  678. /* > The leading dimension of the array V. */
  679. /* > If JOBV = 'A', 'V', 'R', or JOBA = 'E', LDV >= f2cmax(1,N). */
  680. /* > Otherwise, LDV >= 1. */
  681. /* > \endverbatim */
  682. /* > */
  683. /* > \param[out] NUMRANK */
  684. /* > \verbatim */
  685. /* > NUMRANK is INTEGER */
  686. /* > NUMRANK is the numerical rank first determined after the rank */
  687. /* > revealing QR factorization, following the strategy specified by the */
  688. /* > value of JOBA. If JOBV = 'R' and JOBU = 'R', only NUMRANK */
  689. /* > leading singular values and vectors are then requested in the call */
  690. /* > of CGESVD. The final value of NUMRANK might be further reduced if */
  691. /* > some singular values are computed as zeros. */
  692. /* > \endverbatim */
  693. /* > */
  694. /* > \param[out] IWORK */
  695. /* > \verbatim */
  696. /* > IWORK is INTEGER array, dimension (f2cmax(1, LIWORK)). */
  697. /* > On exit, IWORK(1:N) contains column pivoting permutation of the */
  698. /* > rank revealing QR factorization. */
  699. /* > If JOBP = 'P', IWORK(N+1:N+M-1) contains the indices of the sequence */
  700. /* > of row swaps used in row pivoting. These can be used to restore the */
  701. /* > left singular vectors in the case JOBU = 'F'. */
  702. /* > If LIWORK, LCWORK, or LRWORK = -1, then on exit, if INFO = 0, */
  703. /* > LIWORK(1) returns the minimal LIWORK. */
  704. /* > \endverbatim */
  705. /* > */
  706. /* > \param[in] LIWORK */
  707. /* > \verbatim */
  708. /* > LIWORK is INTEGER */
  709. /* > The dimension of the array IWORK. */
  710. /* > LIWORK >= N + M - 1, if JOBP = 'P'; */
  711. /* > LIWORK >= N if JOBP = 'N'. */
  712. /* > */
  713. /* > If LIWORK = -1, then a workspace query is assumed; the routine */
  714. /* > only calculates and returns the optimal and minimal sizes */
  715. /* > for the CWORK, IWORK, and RWORK arrays, and no error */
  716. /* > message related to LCWORK is issued by XERBLA. */
  717. /* > \endverbatim */
  718. /* > */
  719. /* > \param[out] CWORK */
  720. /* > \verbatim */
  721. /* > CWORK is COMPLEX*12 array, dimension (f2cmax(2, LCWORK)), used as a workspace. */
  722. /* > On exit, if, on entry, LCWORK.NE.-1, CWORK(1:N) contains parameters */
  723. /* > needed to recover the Q factor from the QR factorization computed by */
  724. /* > ZGEQP3. */
  725. /* > If LIWORK, LCWORK, or LRWORK = -1, then on exit, if INFO = 0, */
  726. /* > CWORK(1) returns the optimal LCWORK, and */
  727. /* > CWORK(2) returns the minimal LCWORK. */
  728. /* > \endverbatim */
  729. /* > */
  730. /* > \param[in,out] LCWORK */
  731. /* > \verbatim */
  732. /* > LCWORK is INTEGER */
  733. /* > The dimension of the array CWORK. It is determined as follows: */
  734. /* > Let LWQP3 = N+1, LWCON = 2*N, and let */
  735. /* > LWUNQ = { MAX( N, 1 ), if JOBU = 'R', 'S', or 'U' */
  736. /* > { MAX( M, 1 ), if JOBU = 'A' */
  737. /* > LWSVD = MAX( 3*N, 1 ) */
  738. /* > LWLQF = MAX( N/2, 1 ), LWSVD2 = MAX( 3*(N/2), 1 ), LWUNLQ = MAX( N, 1 ), */
  739. /* > LWQRF = MAX( N/2, 1 ), LWUNQ2 = MAX( N, 1 ) */
  740. /* > Then the minimal value of LCWORK is: */
  741. /* > = MAX( N + LWQP3, LWSVD ) if only the singular values are needed; */
  742. /* > = MAX( N + LWQP3, LWCON, LWSVD ) if only the singular values are needed, */
  743. /* > and a scaled condition estimate requested; */
  744. /* > */
  745. /* > = N + MAX( LWQP3, LWSVD, LWUNQ ) if the singular values and the left */
  746. /* > singular vectors are requested; */
  747. /* > = N + MAX( LWQP3, LWCON, LWSVD, LWUNQ ) if the singular values and the left */
  748. /* > singular vectors are requested, and also */
  749. /* > a scaled condition estimate requested; */
  750. /* > */
  751. /* > = N + MAX( LWQP3, LWSVD ) if the singular values and the right */
  752. /* > singular vectors are requested; */
  753. /* > = N + MAX( LWQP3, LWCON, LWSVD ) if the singular values and the right */
  754. /* > singular vectors are requested, and also */
  755. /* > a scaled condition etimate requested; */
  756. /* > */
  757. /* > = N + MAX( LWQP3, LWSVD, LWUNQ ) if the full SVD is requested with JOBV = 'R'; */
  758. /* > independent of JOBR; */
  759. /* > = N + MAX( LWQP3, LWCON, LWSVD, LWUNQ ) if the full SVD is requested, */
  760. /* > JOBV = 'R' and, also a scaled condition */
  761. /* > estimate requested; independent of JOBR; */
  762. /* > = MAX( N + MAX( LWQP3, LWSVD, LWUNQ ), */
  763. /* > N + MAX( LWQP3, N/2+LWLQF, N/2+LWSVD2, N/2+LWUNLQ, LWUNQ) ) if the */
  764. /* > full SVD is requested with JOBV = 'A' or 'V', and */
  765. /* > JOBR ='N' */
  766. /* > = MAX( N + MAX( LWQP3, LWCON, LWSVD, LWUNQ ), */
  767. /* > N + MAX( LWQP3, LWCON, N/2+LWLQF, N/2+LWSVD2, N/2+LWUNLQ, LWUNQ ) ) */
  768. /* > if the full SVD is requested with JOBV = 'A' or 'V', and */
  769. /* > JOBR ='N', and also a scaled condition number estimate */
  770. /* > requested. */
  771. /* > = MAX( N + MAX( LWQP3, LWSVD, LWUNQ ), */
  772. /* > N + MAX( LWQP3, N/2+LWQRF, N/2+LWSVD2, N/2+LWUNQ2, LWUNQ ) ) if the */
  773. /* > full SVD is requested with JOBV = 'A', 'V', and JOBR ='T' */
  774. /* > = MAX( N + MAX( LWQP3, LWCON, LWSVD, LWUNQ ), */
  775. /* > N + MAX( LWQP3, LWCON, N/2+LWQRF, N/2+LWSVD2, N/2+LWUNQ2, LWUNQ ) ) */
  776. /* > if the full SVD is requested with JOBV = 'A', 'V' and */
  777. /* > JOBR ='T', and also a scaled condition number estimate */
  778. /* > requested. */
  779. /* > Finally, LCWORK must be at least two: LCWORK = MAX( 2, LCWORK ). */
  780. /* > */
  781. /* > If LCWORK = -1, then a workspace query is assumed; the routine */
  782. /* > only calculates and returns the optimal and minimal sizes */
  783. /* > for the CWORK, IWORK, and RWORK arrays, and no error */
  784. /* > message related to LCWORK is issued by XERBLA. */
  785. /* > \endverbatim */
  786. /* > */
  787. /* > \param[out] RWORK */
  788. /* > \verbatim */
  789. /* > RWORK is DOUBLE PRECISION array, dimension (f2cmax(1, LRWORK)). */
  790. /* > On exit, */
  791. /* > 1. If JOBA = 'E', RWORK(1) contains an estimate of the condition */
  792. /* > number of column scaled A. If A = C * D where D is diagonal and C */
  793. /* > has unit columns in the Euclidean norm, then, assuming full column rank, */
  794. /* > N^(-1/4) * RWORK(1) <= ||pinv(C)||_2 <= N^(1/4) * RWORK(1). */
  795. /* > Otherwise, RWORK(1) = -1. */
  796. /* > 2. RWORK(2) contains the number of singular values computed as */
  797. /* > exact zeros in ZGESVD applied to the upper triangular or trapeziodal */
  798. /* > R (from the initial QR factorization). In case of early exit (no call to */
  799. /* > ZGESVD, such as in the case of zero matrix) RWORK(2) = -1. */
  800. /* > If LIWORK, LCWORK, or LRWORK = -1, then on exit, if INFO = 0, */
  801. /* > RWORK(1) returns the minimal LRWORK. */
  802. /* > \endverbatim */
  803. /* > */
  804. /* > \param[in] LRWORK */
  805. /* > \verbatim */
  806. /* > LRWORK is INTEGER. */
  807. /* > The dimension of the array RWORK. */
  808. /* > If JOBP ='P', then LRWORK >= MAX(2, M, 5*N); */
  809. /* > Otherwise, LRWORK >= MAX(2, 5*N). */
  810. /* > If LRWORK = -1, then a workspace query is assumed; the routine */
  811. /* > only calculates and returns the optimal and minimal sizes */
  812. /* > for the CWORK, IWORK, and RWORK arrays, and no error */
  813. /* > message related to LCWORK is issued by XERBLA. */
  814. /* > \endverbatim */
  815. /* > */
  816. /* > \param[out] INFO */
  817. /* > \verbatim */
  818. /* > INFO is INTEGER */
  819. /* > = 0: successful exit. */
  820. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  821. /* > > 0: if ZBDSQR did not converge, INFO specifies how many superdiagonals */
  822. /* > of an intermediate bidiagonal form B (computed in ZGESVD) did not */
  823. /* > converge to zero. */
  824. /* > \endverbatim */
  825. /* > \par Further Details: */
  826. /* ======================== */
  827. /* > */
  828. /* > \verbatim */
  829. /* > */
  830. /* > 1. The data movement (matrix transpose) is coded using simple nested */
  831. /* > DO-loops because BLAS and LAPACK do not provide corresponding subroutines. */
  832. /* > Those DO-loops are easily identified in this source code - by the CONTINUE */
  833. /* > statements labeled with 11**. In an optimized version of this code, the */
  834. /* > nested DO loops should be replaced with calls to an optimized subroutine. */
  835. /* > 2. This code scales A by 1/SQRT(M) if the largest ABS(A(i,j)) could cause */
  836. /* > column norm overflow. This is the minial precaution and it is left to the */
  837. /* > SVD routine (CGESVD) to do its own preemptive scaling if potential over- */
  838. /* > or underflows are detected. To avoid repeated scanning of the array A, */
  839. /* > an optimal implementation would do all necessary scaling before calling */
  840. /* > CGESVD and the scaling in CGESVD can be switched off. */
  841. /* > 3. Other comments related to code optimization are given in comments in the */
  842. /* > code, enlosed in [[double brackets]]. */
  843. /* > \endverbatim */
  844. /* > \par Bugs, examples and comments */
  845. /* =========================== */
  846. /* > \verbatim */
  847. /* > Please report all bugs and send interesting examples and/or comments to */
  848. /* > drmac@math.hr. Thank you. */
  849. /* > \endverbatim */
  850. /* > \par References */
  851. /* =============== */
  852. /* > \verbatim */
  853. /* > [1] Zlatko Drmac, Algorithm 977: A QR-Preconditioned QR SVD Method for */
  854. /* > Computing the SVD with High Accuracy. ACM Trans. Math. Softw. */
  855. /* > 44(1): 11:1-11:30 (2017) */
  856. /* > */
  857. /* > SIGMA library, xGESVDQ section updated February 2016. */
  858. /* > Developed and coded by Zlatko Drmac, Department of Mathematics */
  859. /* > University of Zagreb, Croatia, drmac@math.hr */
  860. /* > \endverbatim */
  861. /* > \par Contributors: */
  862. /* ================== */
  863. /* > */
  864. /* > \verbatim */
  865. /* > Developed and coded by Zlatko Drmac, Department of Mathematics */
  866. /* > University of Zagreb, Croatia, drmac@math.hr */
  867. /* > \endverbatim */
  868. /* Authors: */
  869. /* ======== */
  870. /* > \author Univ. of Tennessee */
  871. /* > \author Univ. of California Berkeley */
  872. /* > \author Univ. of Colorado Denver */
  873. /* > \author NAG Ltd. */
  874. /* > \date November 2018 */
  875. /* > \ingroup complex16GEsing */
  876. /* ===================================================================== */
  877. /* Subroutine */ void zgesvdq_(char *joba, char *jobp, char *jobr, char *jobu,
  878. char *jobv, integer *m, integer *n, doublecomplex *a, integer *lda,
  879. doublereal *s, doublecomplex *u, integer *ldu, doublecomplex *v,
  880. integer *ldv, integer *numrank, integer *iwork, integer *liwork,
  881. doublecomplex *cwork, integer *lcwork, doublereal *rwork, integer *
  882. lrwork, integer *info)
  883. {
  884. /* System generated locals */
  885. integer a_dim1, a_offset, u_dim1, u_offset, v_dim1, v_offset, i__1, i__2,
  886. i__3;
  887. doublereal d__1;
  888. doublecomplex z__1;
  889. /* Local variables */
  890. integer lwrk_zunmlq__, lwrk_zunmqr__, ierr;
  891. doublecomplex ctmp;
  892. integer lwrk_zgesvd2__;
  893. doublereal rtmp;
  894. integer lwrk_zunmqr2__, optratio;
  895. logical lsvc0, accla;
  896. integer lwqp3;
  897. logical acclh, acclm;
  898. integer p, q;
  899. logical conda;
  900. extern logical lsame_(char *, char *);
  901. logical lsvec;
  902. doublereal sfmin, epsln;
  903. integer lwcon;
  904. logical rsvec;
  905. integer lwlqf, lwqrf;
  906. logical wntua;
  907. integer n1, lwsvd;
  908. logical dntwu, dntwv, wntuf, wntva;
  909. integer lwunq;
  910. logical wntur, wntus, wntvr;
  911. extern /* Subroutine */ void zgeqp3_(integer *, integer *, doublecomplex *,
  912. integer *, integer *, doublecomplex *, doublecomplex *, integer *
  913. , doublereal *, integer *);
  914. extern doublereal dznrm2_(integer *, doublecomplex *, integer *);
  915. integer lwsvd2, lwunq2;
  916. extern doublereal dlamch_(char *);
  917. integer nr;
  918. extern /* Subroutine */ void dlascl_(char *, integer *, integer *,
  919. doublereal *, doublereal *, integer *, integer *, doublereal *,
  920. integer *, integer *);
  921. extern integer idamax_(integer *, doublereal *, integer *);
  922. doublereal sconda;
  923. extern /* Subroutine */ void dlaset_(char *, integer *, integer *,
  924. doublereal *, doublereal *, doublereal *, integer *);
  925. extern int xerbla_(char *, integer *, ftnlen);
  926. extern void zdscal_(integer *, doublereal
  927. *, doublecomplex *, integer *);
  928. extern doublereal zlange_(char *, integer *, integer *, doublecomplex *,
  929. integer *, doublereal *);
  930. extern /* Subroutine */ void zgelqf_(integer *, integer *, doublecomplex *,
  931. integer *, doublecomplex *, doublecomplex *, integer *, integer *
  932. ), zlascl_(char *, integer *, integer *, doublereal *, doublereal
  933. *, integer *, integer *, doublecomplex *, integer *, integer *);
  934. doublecomplex cdummy[1];
  935. extern /* Subroutine */ void zgeqrf_(integer *, integer *, doublecomplex *,
  936. integer *, doublecomplex *, doublecomplex *, integer *, integer *
  937. ), zgesvd_(char *, char *, integer *, integer *, doublecomplex *,
  938. integer *, doublereal *, doublecomplex *, integer *,
  939. doublecomplex *, integer *, doublecomplex *, integer *,
  940. doublereal *, integer *), zlacpy_(char *, integer
  941. *, integer *, doublecomplex *, integer *, doublecomplex *,
  942. integer *), zlaset_(char *, integer *, integer *,
  943. doublecomplex *, doublecomplex *, doublecomplex *, integer *);
  944. integer minwrk;
  945. logical rtrans;
  946. extern /* Subroutine */ void zlapmt_(logical *, integer *, integer *,
  947. doublecomplex *, integer *, integer *), zpocon_(char *, integer *,
  948. doublecomplex *, integer *, doublereal *, doublereal *,
  949. doublecomplex *, doublereal *, integer *);
  950. doublereal rdummy[1];
  951. logical lquery;
  952. integer lwunlq;
  953. extern /* Subroutine */ int zlaswp_(integer *, doublecomplex *, integer *,
  954. integer *, integer *, integer *, integer *);
  955. integer optwrk;
  956. logical rowprm;
  957. extern /* Subroutine */ void zunmlq_(char *, char *, integer *, integer *,
  958. integer *, doublecomplex *, integer *, doublecomplex *,
  959. doublecomplex *, integer *, doublecomplex *, integer *, integer *), zunmqr_(char *, char *, integer *, integer *,
  960. integer *, doublecomplex *, integer *, doublecomplex *,
  961. doublecomplex *, integer *, doublecomplex *, integer *, integer *);
  962. doublereal big;
  963. integer minwrk2;
  964. logical ascaled;
  965. integer optwrk2, lwrk_zgeqp3__, iminwrk, rminwrk, lwrk_zgelqf__,
  966. lwrk_zgeqrf__, lwrk_zgesvd__;
  967. /* ===================================================================== */
  968. /* Test the input arguments */
  969. /* Parameter adjustments */
  970. a_dim1 = *lda;
  971. a_offset = 1 + a_dim1 * 1;
  972. a -= a_offset;
  973. --s;
  974. u_dim1 = *ldu;
  975. u_offset = 1 + u_dim1 * 1;
  976. u -= u_offset;
  977. v_dim1 = *ldv;
  978. v_offset = 1 + v_dim1 * 1;
  979. v -= v_offset;
  980. --iwork;
  981. --cwork;
  982. --rwork;
  983. /* Function Body */
  984. wntus = lsame_(jobu, "S") || lsame_(jobu, "U");
  985. wntur = lsame_(jobu, "R");
  986. wntua = lsame_(jobu, "A");
  987. wntuf = lsame_(jobu, "F");
  988. lsvc0 = wntus || wntur || wntua;
  989. lsvec = lsvc0 || wntuf;
  990. dntwu = lsame_(jobu, "N");
  991. wntvr = lsame_(jobv, "R");
  992. wntva = lsame_(jobv, "A") || lsame_(jobv, "V");
  993. rsvec = wntvr || wntva;
  994. dntwv = lsame_(jobv, "N");
  995. accla = lsame_(joba, "A");
  996. acclm = lsame_(joba, "M");
  997. conda = lsame_(joba, "E");
  998. acclh = lsame_(joba, "H") || conda;
  999. rowprm = lsame_(jobp, "P");
  1000. rtrans = lsame_(jobr, "T");
  1001. if (rowprm) {
  1002. /* Computing MAX */
  1003. i__1 = 1, i__2 = *n + *m - 1;
  1004. iminwrk = f2cmax(i__1,i__2);
  1005. /* Computing MAX */
  1006. i__1 = f2cmax(2,*m), i__2 = *n * 5;
  1007. rminwrk = f2cmax(i__1,i__2);
  1008. } else {
  1009. iminwrk = f2cmax(1,*n);
  1010. /* Computing MAX */
  1011. i__1 = 2, i__2 = *n * 5;
  1012. rminwrk = f2cmax(i__1,i__2);
  1013. }
  1014. lquery = *liwork == -1 || *lcwork == -1 || *lrwork == -1;
  1015. *info = 0;
  1016. if (! (accla || acclm || acclh)) {
  1017. *info = -1;
  1018. } else if (! (rowprm || lsame_(jobp, "N"))) {
  1019. *info = -2;
  1020. } else if (! (rtrans || lsame_(jobr, "N"))) {
  1021. *info = -3;
  1022. } else if (! (lsvec || dntwu)) {
  1023. *info = -4;
  1024. } else if (wntur && wntva) {
  1025. *info = -5;
  1026. } else if (! (rsvec || dntwv)) {
  1027. *info = -5;
  1028. } else if (*m < 0) {
  1029. *info = -6;
  1030. } else if (*n < 0 || *n > *m) {
  1031. *info = -7;
  1032. } else if (*lda < f2cmax(1,*m)) {
  1033. *info = -9;
  1034. } else if (*ldu < 1 || lsvc0 && *ldu < *m || wntuf && *ldu < *n) {
  1035. *info = -12;
  1036. } else if (*ldv < 1 || rsvec && *ldv < *n || conda && *ldv < *n) {
  1037. *info = -14;
  1038. } else if (*liwork < iminwrk && ! lquery) {
  1039. *info = -17;
  1040. }
  1041. if (*info == 0) {
  1042. /* [[The expressions for computing the minimal and the optimal */
  1043. /* values of LCWORK are written with a lot of redundancy and */
  1044. /* can be simplified. However, this detailed form is easier for */
  1045. /* maintenance and modifications of the code.]] */
  1046. lwqp3 = *n + 1;
  1047. if (wntus || wntur) {
  1048. lwunq = f2cmax(*n,1);
  1049. } else if (wntua) {
  1050. lwunq = f2cmax(*m,1);
  1051. }
  1052. lwcon = *n << 1;
  1053. /* Computing MAX */
  1054. i__1 = *n * 3;
  1055. lwsvd = f2cmax(i__1,1);
  1056. if (lquery) {
  1057. zgeqp3_(m, n, &a[a_offset], lda, &iwork[1], cdummy, cdummy, &c_n1,
  1058. rdummy, &ierr);
  1059. lwrk_zgeqp3__ = (integer) cdummy[0].r;
  1060. if (wntus || wntur) {
  1061. zunmqr_("L", "N", m, n, n, &a[a_offset], lda, cdummy, &u[
  1062. u_offset], ldu, cdummy, &c_n1, &ierr);
  1063. lwrk_zunmqr__ = (integer) cdummy[0].r;
  1064. } else if (wntua) {
  1065. zunmqr_("L", "N", m, m, n, &a[a_offset], lda, cdummy, &u[
  1066. u_offset], ldu, cdummy, &c_n1, &ierr);
  1067. lwrk_zunmqr__ = (integer) cdummy[0].r;
  1068. } else {
  1069. lwrk_zunmqr__ = 0;
  1070. }
  1071. }
  1072. minwrk = 2;
  1073. optwrk = 2;
  1074. if (! (lsvec || rsvec)) {
  1075. /* only the singular values are requested */
  1076. if (conda) {
  1077. /* Computing MAX */
  1078. i__1 = *n + lwqp3, i__1 = f2cmax(i__1,lwcon);
  1079. minwrk = f2cmax(i__1,lwsvd);
  1080. } else {
  1081. /* Computing MAX */
  1082. i__1 = *n + lwqp3;
  1083. minwrk = f2cmax(i__1,lwsvd);
  1084. }
  1085. if (lquery) {
  1086. zgesvd_("N", "N", n, n, &a[a_offset], lda, &s[1], &u[u_offset]
  1087. , ldu, &v[v_offset], ldv, cdummy, &c_n1, rdummy, &
  1088. ierr);
  1089. lwrk_zgesvd__ = (integer) cdummy[0].r;
  1090. if (conda) {
  1091. /* Computing MAX */
  1092. i__1 = *n + lwrk_zgeqp3__, i__2 = *n + lwcon, i__1 = f2cmax(
  1093. i__1,i__2);
  1094. optwrk = f2cmax(i__1,lwrk_zgesvd__);
  1095. } else {
  1096. /* Computing MAX */
  1097. i__1 = *n + lwrk_zgeqp3__;
  1098. optwrk = f2cmax(i__1,lwrk_zgesvd__);
  1099. }
  1100. }
  1101. } else if (lsvec && ! rsvec) {
  1102. /* singular values and the left singular vectors are requested */
  1103. if (conda) {
  1104. /* Computing MAX */
  1105. i__1 = f2cmax(lwqp3,lwcon), i__1 = f2cmax(i__1,lwsvd);
  1106. minwrk = *n + f2cmax(i__1,lwunq);
  1107. } else {
  1108. /* Computing MAX */
  1109. i__1 = f2cmax(lwqp3,lwsvd);
  1110. minwrk = *n + f2cmax(i__1,lwunq);
  1111. }
  1112. if (lquery) {
  1113. if (rtrans) {
  1114. zgesvd_("N", "O", n, n, &a[a_offset], lda, &s[1], &u[
  1115. u_offset], ldu, &v[v_offset], ldv, cdummy, &c_n1,
  1116. rdummy, &ierr);
  1117. } else {
  1118. zgesvd_("O", "N", n, n, &a[a_offset], lda, &s[1], &u[
  1119. u_offset], ldu, &v[v_offset], ldv, cdummy, &c_n1,
  1120. rdummy, &ierr);
  1121. }
  1122. lwrk_zgesvd__ = (integer) cdummy[0].r;
  1123. if (conda) {
  1124. /* Computing MAX */
  1125. i__1 = f2cmax(lwrk_zgeqp3__,lwcon), i__1 = f2cmax(i__1,
  1126. lwrk_zgesvd__);
  1127. optwrk = *n + f2cmax(i__1,lwrk_zunmqr__);
  1128. } else {
  1129. /* Computing MAX */
  1130. i__1 = f2cmax(lwrk_zgeqp3__,lwrk_zgesvd__);
  1131. optwrk = *n + f2cmax(i__1,lwrk_zunmqr__);
  1132. }
  1133. }
  1134. } else if (rsvec && ! lsvec) {
  1135. /* singular values and the right singular vectors are requested */
  1136. if (conda) {
  1137. /* Computing MAX */
  1138. i__1 = f2cmax(lwqp3,lwcon);
  1139. minwrk = *n + f2cmax(i__1,lwsvd);
  1140. } else {
  1141. minwrk = *n + f2cmax(lwqp3,lwsvd);
  1142. }
  1143. if (lquery) {
  1144. if (rtrans) {
  1145. zgesvd_("O", "N", n, n, &a[a_offset], lda, &s[1], &u[
  1146. u_offset], ldu, &v[v_offset], ldv, cdummy, &c_n1,
  1147. rdummy, &ierr);
  1148. } else {
  1149. zgesvd_("N", "O", n, n, &a[a_offset], lda, &s[1], &u[
  1150. u_offset], ldu, &v[v_offset], ldv, cdummy, &c_n1,
  1151. rdummy, &ierr);
  1152. }
  1153. lwrk_zgesvd__ = (integer) cdummy[0].r;
  1154. if (conda) {
  1155. /* Computing MAX */
  1156. i__1 = f2cmax(lwrk_zgeqp3__,lwcon);
  1157. optwrk = *n + f2cmax(i__1,lwrk_zgesvd__);
  1158. } else {
  1159. optwrk = *n + f2cmax(lwrk_zgeqp3__,lwrk_zgesvd__);
  1160. }
  1161. }
  1162. } else {
  1163. /* full SVD is requested */
  1164. if (rtrans) {
  1165. /* Computing MAX */
  1166. i__1 = f2cmax(lwqp3,lwsvd);
  1167. minwrk = f2cmax(i__1,lwunq);
  1168. if (conda) {
  1169. minwrk = f2cmax(minwrk,lwcon);
  1170. }
  1171. minwrk += *n;
  1172. if (wntva) {
  1173. /* Computing MAX */
  1174. i__1 = *n / 2;
  1175. lwqrf = f2cmax(i__1,1);
  1176. /* Computing MAX */
  1177. i__1 = *n / 2 * 3;
  1178. lwsvd2 = f2cmax(i__1,1);
  1179. lwunq2 = f2cmax(*n,1);
  1180. /* Computing MAX */
  1181. i__1 = lwqp3, i__2 = *n / 2 + lwqrf, i__1 = f2cmax(i__1,i__2)
  1182. , i__2 = *n / 2 + lwsvd2, i__1 = f2cmax(i__1,i__2),
  1183. i__2 = *n / 2 + lwunq2, i__1 = f2cmax(i__1,i__2);
  1184. minwrk2 = f2cmax(i__1,lwunq);
  1185. if (conda) {
  1186. minwrk2 = f2cmax(minwrk2,lwcon);
  1187. }
  1188. minwrk2 = *n + minwrk2;
  1189. minwrk = f2cmax(minwrk,minwrk2);
  1190. }
  1191. } else {
  1192. /* Computing MAX */
  1193. i__1 = f2cmax(lwqp3,lwsvd);
  1194. minwrk = f2cmax(i__1,lwunq);
  1195. if (conda) {
  1196. minwrk = f2cmax(minwrk,lwcon);
  1197. }
  1198. minwrk += *n;
  1199. if (wntva) {
  1200. /* Computing MAX */
  1201. i__1 = *n / 2;
  1202. lwlqf = f2cmax(i__1,1);
  1203. /* Computing MAX */
  1204. i__1 = *n / 2 * 3;
  1205. lwsvd2 = f2cmax(i__1,1);
  1206. lwunlq = f2cmax(*n,1);
  1207. /* Computing MAX */
  1208. i__1 = lwqp3, i__2 = *n / 2 + lwlqf, i__1 = f2cmax(i__1,i__2)
  1209. , i__2 = *n / 2 + lwsvd2, i__1 = f2cmax(i__1,i__2),
  1210. i__2 = *n / 2 + lwunlq, i__1 = f2cmax(i__1,i__2);
  1211. minwrk2 = f2cmax(i__1,lwunq);
  1212. if (conda) {
  1213. minwrk2 = f2cmax(minwrk2,lwcon);
  1214. }
  1215. minwrk2 = *n + minwrk2;
  1216. minwrk = f2cmax(minwrk,minwrk2);
  1217. }
  1218. }
  1219. if (lquery) {
  1220. if (rtrans) {
  1221. zgesvd_("O", "A", n, n, &a[a_offset], lda, &s[1], &u[
  1222. u_offset], ldu, &v[v_offset], ldv, cdummy, &c_n1,
  1223. rdummy, &ierr);
  1224. lwrk_zgesvd__ = (integer) cdummy[0].r;
  1225. /* Computing MAX */
  1226. i__1 = f2cmax(lwrk_zgeqp3__,lwrk_zgesvd__);
  1227. optwrk = f2cmax(i__1,lwrk_zunmqr__);
  1228. if (conda) {
  1229. optwrk = f2cmax(optwrk,lwcon);
  1230. }
  1231. optwrk = *n + optwrk;
  1232. if (wntva) {
  1233. i__1 = *n / 2;
  1234. zgeqrf_(n, &i__1, &u[u_offset], ldu, cdummy, cdummy, &
  1235. c_n1, &ierr);
  1236. lwrk_zgeqrf__ = (integer) cdummy[0].r;
  1237. i__1 = *n / 2;
  1238. i__2 = *n / 2;
  1239. zgesvd_("S", "O", &i__1, &i__2, &v[v_offset], ldv, &s[
  1240. 1], &u[u_offset], ldu, &v[v_offset], ldv,
  1241. cdummy, &c_n1, rdummy, &ierr);
  1242. lwrk_zgesvd2__ = (integer) cdummy[0].r;
  1243. i__1 = *n / 2;
  1244. zunmqr_("R", "C", n, n, &i__1, &u[u_offset], ldu,
  1245. cdummy, &v[v_offset], ldv, cdummy, &c_n1, &
  1246. ierr);
  1247. lwrk_zunmqr2__ = (integer) cdummy[0].r;
  1248. /* Computing MAX */
  1249. i__1 = lwrk_zgeqp3__, i__2 = *n / 2 + lwrk_zgeqrf__,
  1250. i__1 = f2cmax(i__1,i__2), i__2 = *n / 2 +
  1251. lwrk_zgesvd2__, i__1 = f2cmax(i__1,i__2), i__2 =
  1252. *n / 2 + lwrk_zunmqr2__;
  1253. optwrk2 = f2cmax(i__1,i__2);
  1254. if (conda) {
  1255. optwrk2 = f2cmax(optwrk2,lwcon);
  1256. }
  1257. optwrk2 = *n + optwrk2;
  1258. optwrk = f2cmax(optwrk,optwrk2);
  1259. }
  1260. } else {
  1261. zgesvd_("S", "O", n, n, &a[a_offset], lda, &s[1], &u[
  1262. u_offset], ldu, &v[v_offset], ldv, cdummy, &c_n1,
  1263. rdummy, &ierr);
  1264. lwrk_zgesvd__ = (integer) cdummy[0].r;
  1265. /* Computing MAX */
  1266. i__1 = f2cmax(lwrk_zgeqp3__,lwrk_zgesvd__);
  1267. optwrk = f2cmax(i__1,lwrk_zunmqr__);
  1268. if (conda) {
  1269. optwrk = f2cmax(optwrk,lwcon);
  1270. }
  1271. optwrk = *n + optwrk;
  1272. if (wntva) {
  1273. i__1 = *n / 2;
  1274. zgelqf_(&i__1, n, &u[u_offset], ldu, cdummy, cdummy, &
  1275. c_n1, &ierr);
  1276. lwrk_zgelqf__ = (integer) cdummy[0].r;
  1277. i__1 = *n / 2;
  1278. i__2 = *n / 2;
  1279. zgesvd_("S", "O", &i__1, &i__2, &v[v_offset], ldv, &s[
  1280. 1], &u[u_offset], ldu, &v[v_offset], ldv,
  1281. cdummy, &c_n1, rdummy, &ierr);
  1282. lwrk_zgesvd2__ = (integer) cdummy[0].r;
  1283. i__1 = *n / 2;
  1284. zunmlq_("R", "N", n, n, &i__1, &u[u_offset], ldu,
  1285. cdummy, &v[v_offset], ldv, cdummy, &c_n1, &
  1286. ierr);
  1287. lwrk_zunmlq__ = (integer) cdummy[0].r;
  1288. /* Computing MAX */
  1289. i__1 = lwrk_zgeqp3__, i__2 = *n / 2 + lwrk_zgelqf__,
  1290. i__1 = f2cmax(i__1,i__2), i__2 = *n / 2 +
  1291. lwrk_zgesvd2__, i__1 = f2cmax(i__1,i__2), i__2 =
  1292. *n / 2 + lwrk_zunmlq__;
  1293. optwrk2 = f2cmax(i__1,i__2);
  1294. if (conda) {
  1295. optwrk2 = f2cmax(optwrk2,lwcon);
  1296. }
  1297. optwrk2 = *n + optwrk2;
  1298. optwrk = f2cmax(optwrk,optwrk2);
  1299. }
  1300. }
  1301. }
  1302. }
  1303. minwrk = f2cmax(2,minwrk);
  1304. optwrk = f2cmax(2,optwrk);
  1305. if (*lcwork < minwrk && ! lquery) {
  1306. *info = -19;
  1307. }
  1308. }
  1309. if (*info == 0 && *lrwork < rminwrk && ! lquery) {
  1310. *info = -21;
  1311. }
  1312. if (*info != 0) {
  1313. i__1 = -(*info);
  1314. xerbla_("ZGESVDQ", &i__1, (ftnlen)7);
  1315. return;
  1316. } else if (lquery) {
  1317. /* Return optimal workspace */
  1318. iwork[1] = iminwrk;
  1319. cwork[1].r = (doublereal) optwrk, cwork[1].i = 0.;
  1320. cwork[2].r = (doublereal) minwrk, cwork[2].i = 0.;
  1321. rwork[1] = (doublereal) rminwrk;
  1322. return;
  1323. }
  1324. /* Quick return if the matrix is void. */
  1325. if (*m == 0 || *n == 0) {
  1326. return;
  1327. }
  1328. big = dlamch_("O");
  1329. ascaled = FALSE_;
  1330. if (rowprm) {
  1331. /* ell-infinity norm - this enhances numerical robustness in */
  1332. /* the case of differently scaled rows. */
  1333. i__1 = *m;
  1334. for (p = 1; p <= i__1; ++p) {
  1335. /* RWORK(p) = ABS( A(p,IZAMAX(N,A(p,1),LDA)) ) */
  1336. /* [[ZLANGE will return NaN if an entry of the p-th row is Nan]] */
  1337. rwork[p] = zlange_("M", &c__1, n, &a[p + a_dim1], lda, rdummy);
  1338. if (rwork[p] != rwork[p] || rwork[p] * 0. != 0.) {
  1339. *info = -8;
  1340. i__2 = -(*info);
  1341. xerbla_("ZGESVDQ", &i__2, (ftnlen)7);
  1342. return;
  1343. }
  1344. /* L1904: */
  1345. }
  1346. i__1 = *m - 1;
  1347. for (p = 1; p <= i__1; ++p) {
  1348. i__2 = *m - p + 1;
  1349. q = idamax_(&i__2, &rwork[p], &c__1) + p - 1;
  1350. iwork[*n + p] = q;
  1351. if (p != q) {
  1352. rtmp = rwork[p];
  1353. rwork[p] = rwork[q];
  1354. rwork[q] = rtmp;
  1355. }
  1356. /* L1952: */
  1357. }
  1358. if (rwork[1] == 0.) {
  1359. /* Quick return: A is the M x N zero matrix. */
  1360. *numrank = 0;
  1361. dlaset_("G", n, &c__1, &c_b74, &c_b74, &s[1], n);
  1362. if (wntus) {
  1363. zlaset_("G", m, n, &c_b1, &c_b2, &u[u_offset], ldu)
  1364. ;
  1365. }
  1366. if (wntua) {
  1367. zlaset_("G", m, m, &c_b1, &c_b2, &u[u_offset], ldu)
  1368. ;
  1369. }
  1370. if (wntva) {
  1371. zlaset_("G", n, n, &c_b1, &c_b2, &v[v_offset], ldv)
  1372. ;
  1373. }
  1374. if (wntuf) {
  1375. zlaset_("G", n, &c__1, &c_b1, &c_b1, &cwork[1], n);
  1376. zlaset_("G", m, n, &c_b1, &c_b2, &u[u_offset], ldu)
  1377. ;
  1378. }
  1379. i__1 = *n;
  1380. for (p = 1; p <= i__1; ++p) {
  1381. iwork[p] = p;
  1382. /* L5001: */
  1383. }
  1384. if (rowprm) {
  1385. i__1 = *n + *m - 1;
  1386. for (p = *n + 1; p <= i__1; ++p) {
  1387. iwork[p] = p - *n;
  1388. /* L5002: */
  1389. }
  1390. }
  1391. if (conda) {
  1392. rwork[1] = -1.;
  1393. }
  1394. rwork[2] = -1.;
  1395. return;
  1396. }
  1397. if (rwork[1] > big / sqrt((doublereal) (*m))) {
  1398. /* matrix by 1/sqrt(M) if too large entry detected */
  1399. d__1 = sqrt((doublereal) (*m));
  1400. zlascl_("G", &c__0, &c__0, &d__1, &c_b87, m, n, &a[a_offset], lda,
  1401. &ierr);
  1402. ascaled = TRUE_;
  1403. }
  1404. i__1 = *m - 1;
  1405. zlaswp_(n, &a[a_offset], lda, &c__1, &i__1, &iwork[*n + 1], &c__1);
  1406. }
  1407. /* norms overflows during the QR factorization. The SVD procedure should */
  1408. /* have its own scaling to save the singular values from overflows and */
  1409. /* underflows. That depends on the SVD procedure. */
  1410. if (! rowprm) {
  1411. rtmp = zlange_("M", m, n, &a[a_offset], lda, &rwork[1]);
  1412. if (rtmp != rtmp || rtmp * 0. != 0.) {
  1413. *info = -8;
  1414. i__1 = -(*info);
  1415. xerbla_("ZGESVDQ", &i__1, (ftnlen)7);
  1416. return;
  1417. }
  1418. if (rtmp > big / sqrt((doublereal) (*m))) {
  1419. /* matrix by 1/sqrt(M) if too large entry detected */
  1420. d__1 = sqrt((doublereal) (*m));
  1421. zlascl_("G", &c__0, &c__0, &d__1, &c_b87, m, n, &a[a_offset], lda,
  1422. &ierr);
  1423. ascaled = TRUE_;
  1424. }
  1425. }
  1426. /* A * P = Q * [ R ] */
  1427. /* [ 0 ] */
  1428. i__1 = *n;
  1429. for (p = 1; p <= i__1; ++p) {
  1430. iwork[p] = 0;
  1431. /* L1963: */
  1432. }
  1433. i__1 = *lcwork - *n;
  1434. zgeqp3_(m, n, &a[a_offset], lda, &iwork[1], &cwork[1], &cwork[*n + 1], &
  1435. i__1, &rwork[1], &ierr);
  1436. /* If the user requested accuracy level allows truncation in the */
  1437. /* computed upper triangular factor, the matrix R is examined and, */
  1438. /* if possible, replaced with its leading upper trapezoidal part. */
  1439. epsln = dlamch_("E");
  1440. sfmin = dlamch_("S");
  1441. /* SMALL = SFMIN / EPSLN */
  1442. nr = *n;
  1443. if (accla) {
  1444. /* Standard absolute error bound suffices. All sigma_i with */
  1445. /* sigma_i < N*EPS*||A||_F are flushed to zero. This is an */
  1446. /* aggressive enforcement of lower numerical rank by introducing a */
  1447. /* backward error of the order of N*EPS*||A||_F. */
  1448. nr = 1;
  1449. rtmp = sqrt((doublereal) (*n)) * epsln;
  1450. i__1 = *n;
  1451. for (p = 2; p <= i__1; ++p) {
  1452. if (z_abs(&a[p + p * a_dim1]) < rtmp * z_abs(&a[a_dim1 + 1])) {
  1453. goto L3002;
  1454. }
  1455. ++nr;
  1456. /* L3001: */
  1457. }
  1458. L3002:
  1459. ;
  1460. } else if (acclm) {
  1461. /* Sudden drop on the diagonal of R is used as the criterion for being */
  1462. /* close-to-rank-deficient. The threshold is set to EPSLN=DLAMCH('E'). */
  1463. /* [[This can be made more flexible by replacing this hard-coded value */
  1464. /* with a user specified threshold.]] Also, the values that underflow */
  1465. /* will be truncated. */
  1466. nr = 1;
  1467. i__1 = *n;
  1468. for (p = 2; p <= i__1; ++p) {
  1469. if (z_abs(&a[p + p * a_dim1]) < epsln * z_abs(&a[p - 1 + (p - 1) *
  1470. a_dim1]) || z_abs(&a[p + p * a_dim1]) < sfmin) {
  1471. goto L3402;
  1472. }
  1473. ++nr;
  1474. /* L3401: */
  1475. }
  1476. L3402:
  1477. ;
  1478. } else {
  1479. /* obvious case of zero pivots. */
  1480. /* R(i,i)=0 => R(i:N,i:N)=0. */
  1481. nr = 1;
  1482. i__1 = *n;
  1483. for (p = 2; p <= i__1; ++p) {
  1484. if (z_abs(&a[p + p * a_dim1]) == 0.) {
  1485. goto L3502;
  1486. }
  1487. ++nr;
  1488. /* L3501: */
  1489. }
  1490. L3502:
  1491. if (conda) {
  1492. /* Estimate the scaled condition number of A. Use the fact that it is */
  1493. /* the same as the scaled condition number of R. */
  1494. zlacpy_("U", n, n, &a[a_offset], lda, &v[v_offset], ldv);
  1495. /* Only the leading NR x NR submatrix of the triangular factor */
  1496. /* is considered. Only if NR=N will this give a reliable error */
  1497. /* bound. However, even for NR < N, this can be used on an */
  1498. /* expert level and obtain useful information in the sense of */
  1499. /* perturbation theory. */
  1500. i__1 = nr;
  1501. for (p = 1; p <= i__1; ++p) {
  1502. rtmp = dznrm2_(&p, &v[p * v_dim1 + 1], &c__1);
  1503. d__1 = 1. / rtmp;
  1504. zdscal_(&p, &d__1, &v[p * v_dim1 + 1], &c__1);
  1505. /* L3053: */
  1506. }
  1507. if (! (lsvec || rsvec)) {
  1508. zpocon_("U", &nr, &v[v_offset], ldv, &c_b87, &rtmp, &cwork[1],
  1509. &rwork[1], &ierr);
  1510. } else {
  1511. zpocon_("U", &nr, &v[v_offset], ldv, &c_b87, &rtmp, &cwork[*n
  1512. + 1], &rwork[1], &ierr);
  1513. }
  1514. sconda = 1. / sqrt(rtmp);
  1515. /* For NR=N, SCONDA is an estimate of SQRT(||(R^* * R)^(-1)||_1), */
  1516. /* N^(-1/4) * SCONDA <= ||R^(-1)||_2 <= N^(1/4) * SCONDA */
  1517. /* See the reference [1] for more details. */
  1518. }
  1519. }
  1520. if (wntur) {
  1521. n1 = nr;
  1522. } else if (wntus || wntuf) {
  1523. n1 = *n;
  1524. } else if (wntua) {
  1525. n1 = *m;
  1526. }
  1527. if (! (rsvec || lsvec)) {
  1528. /* ....................................................................... */
  1529. /* ....................................................................... */
  1530. if (rtrans) {
  1531. /* the upper triangle of [A] to zero. */
  1532. i__1 = f2cmin(*n,nr);
  1533. for (p = 1; p <= i__1; ++p) {
  1534. i__2 = p + p * a_dim1;
  1535. d_cnjg(&z__1, &a[p + p * a_dim1]);
  1536. a[i__2].r = z__1.r, a[i__2].i = z__1.i;
  1537. i__2 = *n;
  1538. for (q = p + 1; q <= i__2; ++q) {
  1539. i__3 = q + p * a_dim1;
  1540. d_cnjg(&z__1, &a[p + q * a_dim1]);
  1541. a[i__3].r = z__1.r, a[i__3].i = z__1.i;
  1542. if (q <= nr) {
  1543. i__3 = p + q * a_dim1;
  1544. a[i__3].r = 0., a[i__3].i = 0.;
  1545. }
  1546. /* L1147: */
  1547. }
  1548. /* L1146: */
  1549. }
  1550. zgesvd_("N", "N", n, &nr, &a[a_offset], lda, &s[1], &u[u_offset],
  1551. ldu, &v[v_offset], ldv, &cwork[1], lcwork, &rwork[1],
  1552. info);
  1553. } else {
  1554. if (nr > 1) {
  1555. i__1 = nr - 1;
  1556. i__2 = nr - 1;
  1557. zlaset_("L", &i__1, &i__2, &c_b1, &c_b1, &a[a_dim1 + 2], lda);
  1558. }
  1559. zgesvd_("N", "N", &nr, n, &a[a_offset], lda, &s[1], &u[u_offset],
  1560. ldu, &v[v_offset], ldv, &cwork[1], lcwork, &rwork[1],
  1561. info);
  1562. }
  1563. } else if (lsvec && ! rsvec) {
  1564. /* ....................................................................... */
  1565. /* ......................................................................."""""""" */
  1566. if (rtrans) {
  1567. /* vectors of R */
  1568. i__1 = nr;
  1569. for (p = 1; p <= i__1; ++p) {
  1570. i__2 = *n;
  1571. for (q = p; q <= i__2; ++q) {
  1572. i__3 = q + p * u_dim1;
  1573. d_cnjg(&z__1, &a[p + q * a_dim1]);
  1574. u[i__3].r = z__1.r, u[i__3].i = z__1.i;
  1575. /* L1193: */
  1576. }
  1577. /* L1192: */
  1578. }
  1579. if (nr > 1) {
  1580. i__1 = nr - 1;
  1581. i__2 = nr - 1;
  1582. zlaset_("U", &i__1, &i__2, &c_b1, &c_b1, &u[(u_dim1 << 1) + 1]
  1583. , ldu);
  1584. }
  1585. /* vectors overwrite [U](1:NR,1:NR) as conjugate transposed. These */
  1586. /* will be pre-multiplied by Q to build the left singular vectors of A. */
  1587. i__1 = *lcwork - *n;
  1588. zgesvd_("N", "O", n, &nr, &u[u_offset], ldu, &s[1], &u[u_offset],
  1589. ldu, &u[u_offset], ldu, &cwork[*n + 1], &i__1, &rwork[1],
  1590. info);
  1591. i__1 = nr;
  1592. for (p = 1; p <= i__1; ++p) {
  1593. i__2 = p + p * u_dim1;
  1594. d_cnjg(&z__1, &u[p + p * u_dim1]);
  1595. u[i__2].r = z__1.r, u[i__2].i = z__1.i;
  1596. i__2 = nr;
  1597. for (q = p + 1; q <= i__2; ++q) {
  1598. d_cnjg(&z__1, &u[q + p * u_dim1]);
  1599. ctmp.r = z__1.r, ctmp.i = z__1.i;
  1600. i__3 = q + p * u_dim1;
  1601. d_cnjg(&z__1, &u[p + q * u_dim1]);
  1602. u[i__3].r = z__1.r, u[i__3].i = z__1.i;
  1603. i__3 = p + q * u_dim1;
  1604. u[i__3].r = ctmp.r, u[i__3].i = ctmp.i;
  1605. /* L1120: */
  1606. }
  1607. /* L1119: */
  1608. }
  1609. } else {
  1610. zlacpy_("U", &nr, n, &a[a_offset], lda, &u[u_offset], ldu);
  1611. if (nr > 1) {
  1612. i__1 = nr - 1;
  1613. i__2 = nr - 1;
  1614. zlaset_("L", &i__1, &i__2, &c_b1, &c_b1, &u[u_dim1 + 2], ldu);
  1615. }
  1616. /* vectors overwrite [U](1:NR,1:NR) */
  1617. i__1 = *lcwork - *n;
  1618. zgesvd_("O", "N", &nr, n, &u[u_offset], ldu, &s[1], &u[u_offset],
  1619. ldu, &v[v_offset], ldv, &cwork[*n + 1], &i__1, &rwork[1],
  1620. info);
  1621. /* R. These will be pre-multiplied by Q to build the left singular */
  1622. /* vectors of A. */
  1623. }
  1624. /* (M x NR) or (M x N) or (M x M). */
  1625. if (nr < *m && ! wntuf) {
  1626. i__1 = *m - nr;
  1627. zlaset_("A", &i__1, &nr, &c_b1, &c_b1, &u[nr + 1 + u_dim1], ldu);
  1628. if (nr < n1) {
  1629. i__1 = n1 - nr;
  1630. zlaset_("A", &nr, &i__1, &c_b1, &c_b1, &u[(nr + 1) * u_dim1 +
  1631. 1], ldu);
  1632. i__1 = *m - nr;
  1633. i__2 = n1 - nr;
  1634. zlaset_("A", &i__1, &i__2, &c_b1, &c_b2, &u[nr + 1 + (nr + 1)
  1635. * u_dim1], ldu);
  1636. }
  1637. }
  1638. /* The Q matrix from the first QRF is built into the left singular */
  1639. /* vectors matrix U. */
  1640. if (! wntuf) {
  1641. i__1 = *lcwork - *n;
  1642. zunmqr_("L", "N", m, &n1, n, &a[a_offset], lda, &cwork[1], &u[
  1643. u_offset], ldu, &cwork[*n + 1], &i__1, &ierr);
  1644. }
  1645. if (rowprm && ! wntuf) {
  1646. i__1 = *m - 1;
  1647. zlaswp_(&n1, &u[u_offset], ldu, &c__1, &i__1, &iwork[*n + 1], &
  1648. c_n1);
  1649. }
  1650. } else if (rsvec && ! lsvec) {
  1651. /* ....................................................................... */
  1652. /* ....................................................................... */
  1653. if (rtrans) {
  1654. i__1 = nr;
  1655. for (p = 1; p <= i__1; ++p) {
  1656. i__2 = *n;
  1657. for (q = p; q <= i__2; ++q) {
  1658. i__3 = q + p * v_dim1;
  1659. d_cnjg(&z__1, &a[p + q * a_dim1]);
  1660. v[i__3].r = z__1.r, v[i__3].i = z__1.i;
  1661. /* L1166: */
  1662. }
  1663. /* L1165: */
  1664. }
  1665. if (nr > 1) {
  1666. i__1 = nr - 1;
  1667. i__2 = nr - 1;
  1668. zlaset_("U", &i__1, &i__2, &c_b1, &c_b1, &v[(v_dim1 << 1) + 1]
  1669. , ldv);
  1670. }
  1671. /* vectors not computed */
  1672. if (wntvr || nr == *n) {
  1673. i__1 = *lcwork - *n;
  1674. zgesvd_("O", "N", n, &nr, &v[v_offset], ldv, &s[1], &u[
  1675. u_offset], ldu, &u[u_offset], ldu, &cwork[*n + 1], &
  1676. i__1, &rwork[1], info);
  1677. i__1 = nr;
  1678. for (p = 1; p <= i__1; ++p) {
  1679. i__2 = p + p * v_dim1;
  1680. d_cnjg(&z__1, &v[p + p * v_dim1]);
  1681. v[i__2].r = z__1.r, v[i__2].i = z__1.i;
  1682. i__2 = nr;
  1683. for (q = p + 1; q <= i__2; ++q) {
  1684. d_cnjg(&z__1, &v[q + p * v_dim1]);
  1685. ctmp.r = z__1.r, ctmp.i = z__1.i;
  1686. i__3 = q + p * v_dim1;
  1687. d_cnjg(&z__1, &v[p + q * v_dim1]);
  1688. v[i__3].r = z__1.r, v[i__3].i = z__1.i;
  1689. i__3 = p + q * v_dim1;
  1690. v[i__3].r = ctmp.r, v[i__3].i = ctmp.i;
  1691. /* L1122: */
  1692. }
  1693. /* L1121: */
  1694. }
  1695. if (nr < *n) {
  1696. i__1 = nr;
  1697. for (p = 1; p <= i__1; ++p) {
  1698. i__2 = *n;
  1699. for (q = nr + 1; q <= i__2; ++q) {
  1700. i__3 = p + q * v_dim1;
  1701. d_cnjg(&z__1, &v[q + p * v_dim1]);
  1702. v[i__3].r = z__1.r, v[i__3].i = z__1.i;
  1703. /* L1104: */
  1704. }
  1705. /* L1103: */
  1706. }
  1707. }
  1708. zlapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
  1709. } else {
  1710. /* [!] This is simple implementation that augments [V](1:N,1:NR) */
  1711. /* by padding a zero block. In the case NR << N, a more efficient */
  1712. /* way is to first use the QR factorization. For more details */
  1713. /* how to implement this, see the " FULL SVD " branch. */
  1714. i__1 = *n - nr;
  1715. zlaset_("G", n, &i__1, &c_b1, &c_b1, &v[(nr + 1) * v_dim1 + 1]
  1716. , ldv);
  1717. i__1 = *lcwork - *n;
  1718. zgesvd_("O", "N", n, n, &v[v_offset], ldv, &s[1], &u[u_offset]
  1719. , ldu, &u[u_offset], ldu, &cwork[*n + 1], &i__1, &
  1720. rwork[1], info);
  1721. i__1 = *n;
  1722. for (p = 1; p <= i__1; ++p) {
  1723. i__2 = p + p * v_dim1;
  1724. d_cnjg(&z__1, &v[p + p * v_dim1]);
  1725. v[i__2].r = z__1.r, v[i__2].i = z__1.i;
  1726. i__2 = *n;
  1727. for (q = p + 1; q <= i__2; ++q) {
  1728. d_cnjg(&z__1, &v[q + p * v_dim1]);
  1729. ctmp.r = z__1.r, ctmp.i = z__1.i;
  1730. i__3 = q + p * v_dim1;
  1731. d_cnjg(&z__1, &v[p + q * v_dim1]);
  1732. v[i__3].r = z__1.r, v[i__3].i = z__1.i;
  1733. i__3 = p + q * v_dim1;
  1734. v[i__3].r = ctmp.r, v[i__3].i = ctmp.i;
  1735. /* L1124: */
  1736. }
  1737. /* L1123: */
  1738. }
  1739. zlapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  1740. }
  1741. } else {
  1742. zlacpy_("U", &nr, n, &a[a_offset], lda, &v[v_offset], ldv);
  1743. if (nr > 1) {
  1744. i__1 = nr - 1;
  1745. i__2 = nr - 1;
  1746. zlaset_("L", &i__1, &i__2, &c_b1, &c_b1, &v[v_dim1 + 2], ldv);
  1747. }
  1748. /* vectors stored in U(1:NR,1:NR) */
  1749. if (wntvr || nr == *n) {
  1750. i__1 = *lcwork - *n;
  1751. zgesvd_("N", "O", &nr, n, &v[v_offset], ldv, &s[1], &u[
  1752. u_offset], ldu, &v[v_offset], ldv, &cwork[*n + 1], &
  1753. i__1, &rwork[1], info);
  1754. zlapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
  1755. } else {
  1756. /* [!] This is simple implementation that augments [V](1:NR,1:N) */
  1757. /* by padding a zero block. In the case NR << N, a more efficient */
  1758. /* way is to first use the LQ factorization. For more details */
  1759. /* how to implement this, see the " FULL SVD " branch. */
  1760. i__1 = *n - nr;
  1761. zlaset_("G", &i__1, n, &c_b1, &c_b1, &v[nr + 1 + v_dim1], ldv);
  1762. i__1 = *lcwork - *n;
  1763. zgesvd_("N", "O", n, n, &v[v_offset], ldv, &s[1], &u[u_offset]
  1764. , ldu, &v[v_offset], ldv, &cwork[*n + 1], &i__1, &
  1765. rwork[1], info);
  1766. zlapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  1767. }
  1768. /* vectors of A. */
  1769. }
  1770. } else {
  1771. /* ....................................................................... */
  1772. /* ....................................................................... */
  1773. if (rtrans) {
  1774. if (wntvr || nr == *n) {
  1775. /* vectors of R**H */
  1776. i__1 = nr;
  1777. for (p = 1; p <= i__1; ++p) {
  1778. i__2 = *n;
  1779. for (q = p; q <= i__2; ++q) {
  1780. i__3 = q + p * v_dim1;
  1781. d_cnjg(&z__1, &a[p + q * a_dim1]);
  1782. v[i__3].r = z__1.r, v[i__3].i = z__1.i;
  1783. /* L1169: */
  1784. }
  1785. /* L1168: */
  1786. }
  1787. if (nr > 1) {
  1788. i__1 = nr - 1;
  1789. i__2 = nr - 1;
  1790. zlaset_("U", &i__1, &i__2, &c_b1, &c_b1, &v[(v_dim1 << 1)
  1791. + 1], ldv);
  1792. }
  1793. /* singular vectors of R**H stored in [U](1:NR,1:NR) as conjugate */
  1794. /* transposed */
  1795. i__1 = *lcwork - *n;
  1796. zgesvd_("O", "A", n, &nr, &v[v_offset], ldv, &s[1], &v[
  1797. v_offset], ldv, &u[u_offset], ldu, &cwork[*n + 1], &
  1798. i__1, &rwork[1], info);
  1799. i__1 = nr;
  1800. for (p = 1; p <= i__1; ++p) {
  1801. i__2 = p + p * v_dim1;
  1802. d_cnjg(&z__1, &v[p + p * v_dim1]);
  1803. v[i__2].r = z__1.r, v[i__2].i = z__1.i;
  1804. i__2 = nr;
  1805. for (q = p + 1; q <= i__2; ++q) {
  1806. d_cnjg(&z__1, &v[q + p * v_dim1]);
  1807. ctmp.r = z__1.r, ctmp.i = z__1.i;
  1808. i__3 = q + p * v_dim1;
  1809. d_cnjg(&z__1, &v[p + q * v_dim1]);
  1810. v[i__3].r = z__1.r, v[i__3].i = z__1.i;
  1811. i__3 = p + q * v_dim1;
  1812. v[i__3].r = ctmp.r, v[i__3].i = ctmp.i;
  1813. /* L1116: */
  1814. }
  1815. /* L1115: */
  1816. }
  1817. if (nr < *n) {
  1818. i__1 = nr;
  1819. for (p = 1; p <= i__1; ++p) {
  1820. i__2 = *n;
  1821. for (q = nr + 1; q <= i__2; ++q) {
  1822. i__3 = p + q * v_dim1;
  1823. d_cnjg(&z__1, &v[q + p * v_dim1]);
  1824. v[i__3].r = z__1.r, v[i__3].i = z__1.i;
  1825. /* L1102: */
  1826. }
  1827. /* L1101: */
  1828. }
  1829. }
  1830. zlapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
  1831. i__1 = nr;
  1832. for (p = 1; p <= i__1; ++p) {
  1833. i__2 = p + p * u_dim1;
  1834. d_cnjg(&z__1, &u[p + p * u_dim1]);
  1835. u[i__2].r = z__1.r, u[i__2].i = z__1.i;
  1836. i__2 = nr;
  1837. for (q = p + 1; q <= i__2; ++q) {
  1838. d_cnjg(&z__1, &u[q + p * u_dim1]);
  1839. ctmp.r = z__1.r, ctmp.i = z__1.i;
  1840. i__3 = q + p * u_dim1;
  1841. d_cnjg(&z__1, &u[p + q * u_dim1]);
  1842. u[i__3].r = z__1.r, u[i__3].i = z__1.i;
  1843. i__3 = p + q * u_dim1;
  1844. u[i__3].r = ctmp.r, u[i__3].i = ctmp.i;
  1845. /* L1118: */
  1846. }
  1847. /* L1117: */
  1848. }
  1849. if (nr < *m && ! wntuf) {
  1850. i__1 = *m - nr;
  1851. zlaset_("A", &i__1, &nr, &c_b1, &c_b1, &u[nr + 1 + u_dim1]
  1852. , ldu);
  1853. if (nr < n1) {
  1854. i__1 = n1 - nr;
  1855. zlaset_("A", &nr, &i__1, &c_b1, &c_b1, &u[(nr + 1) *
  1856. u_dim1 + 1], ldu);
  1857. i__1 = *m - nr;
  1858. i__2 = n1 - nr;
  1859. zlaset_("A", &i__1, &i__2, &c_b1, &c_b2, &u[nr + 1 + (
  1860. nr + 1) * u_dim1], ldu);
  1861. }
  1862. }
  1863. } else {
  1864. /* vectors of R**H */
  1865. /* [[The optimal ratio N/NR for using QRF instead of padding */
  1866. /* with zeros. Here hard coded to 2; it must be at least */
  1867. /* two due to work space constraints.]] */
  1868. /* OPTRATIO = ILAENV(6, 'ZGESVD', 'S' // 'O', NR,N,0,0) */
  1869. /* OPTRATIO = MAX( OPTRATIO, 2 ) */
  1870. optratio = 2;
  1871. if (optratio * nr > *n) {
  1872. i__1 = nr;
  1873. for (p = 1; p <= i__1; ++p) {
  1874. i__2 = *n;
  1875. for (q = p; q <= i__2; ++q) {
  1876. i__3 = q + p * v_dim1;
  1877. d_cnjg(&z__1, &a[p + q * a_dim1]);
  1878. v[i__3].r = z__1.r, v[i__3].i = z__1.i;
  1879. /* L1199: */
  1880. }
  1881. /* L1198: */
  1882. }
  1883. if (nr > 1) {
  1884. i__1 = nr - 1;
  1885. i__2 = nr - 1;
  1886. zlaset_("U", &i__1, &i__2, &c_b1, &c_b1, &v[(v_dim1 <<
  1887. 1) + 1], ldv);
  1888. }
  1889. i__1 = *n - nr;
  1890. zlaset_("A", n, &i__1, &c_b1, &c_b1, &v[(nr + 1) * v_dim1
  1891. + 1], ldv);
  1892. i__1 = *lcwork - *n;
  1893. zgesvd_("O", "A", n, n, &v[v_offset], ldv, &s[1], &v[
  1894. v_offset], ldv, &u[u_offset], ldu, &cwork[*n + 1],
  1895. &i__1, &rwork[1], info);
  1896. i__1 = *n;
  1897. for (p = 1; p <= i__1; ++p) {
  1898. i__2 = p + p * v_dim1;
  1899. d_cnjg(&z__1, &v[p + p * v_dim1]);
  1900. v[i__2].r = z__1.r, v[i__2].i = z__1.i;
  1901. i__2 = *n;
  1902. for (q = p + 1; q <= i__2; ++q) {
  1903. d_cnjg(&z__1, &v[q + p * v_dim1]);
  1904. ctmp.r = z__1.r, ctmp.i = z__1.i;
  1905. i__3 = q + p * v_dim1;
  1906. d_cnjg(&z__1, &v[p + q * v_dim1]);
  1907. v[i__3].r = z__1.r, v[i__3].i = z__1.i;
  1908. i__3 = p + q * v_dim1;
  1909. v[i__3].r = ctmp.r, v[i__3].i = ctmp.i;
  1910. /* L1114: */
  1911. }
  1912. /* L1113: */
  1913. }
  1914. zlapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  1915. /* (M x N1), i.e. (M x N) or (M x M). */
  1916. i__1 = *n;
  1917. for (p = 1; p <= i__1; ++p) {
  1918. i__2 = p + p * u_dim1;
  1919. d_cnjg(&z__1, &u[p + p * u_dim1]);
  1920. u[i__2].r = z__1.r, u[i__2].i = z__1.i;
  1921. i__2 = *n;
  1922. for (q = p + 1; q <= i__2; ++q) {
  1923. d_cnjg(&z__1, &u[q + p * u_dim1]);
  1924. ctmp.r = z__1.r, ctmp.i = z__1.i;
  1925. i__3 = q + p * u_dim1;
  1926. d_cnjg(&z__1, &u[p + q * u_dim1]);
  1927. u[i__3].r = z__1.r, u[i__3].i = z__1.i;
  1928. i__3 = p + q * u_dim1;
  1929. u[i__3].r = ctmp.r, u[i__3].i = ctmp.i;
  1930. /* L1112: */
  1931. }
  1932. /* L1111: */
  1933. }
  1934. if (*n < *m && ! wntuf) {
  1935. i__1 = *m - *n;
  1936. zlaset_("A", &i__1, n, &c_b1, &c_b1, &u[*n + 1 +
  1937. u_dim1], ldu);
  1938. if (*n < n1) {
  1939. i__1 = n1 - *n;
  1940. zlaset_("A", n, &i__1, &c_b1, &c_b1, &u[(*n + 1) *
  1941. u_dim1 + 1], ldu);
  1942. i__1 = *m - *n;
  1943. i__2 = n1 - *n;
  1944. zlaset_("A", &i__1, &i__2, &c_b1, &c_b2, &u[*n +
  1945. 1 + (*n + 1) * u_dim1], ldu);
  1946. }
  1947. }
  1948. } else {
  1949. /* singular vectors of R */
  1950. i__1 = nr;
  1951. for (p = 1; p <= i__1; ++p) {
  1952. i__2 = *n;
  1953. for (q = p; q <= i__2; ++q) {
  1954. i__3 = q + (nr + p) * u_dim1;
  1955. d_cnjg(&z__1, &a[p + q * a_dim1]);
  1956. u[i__3].r = z__1.r, u[i__3].i = z__1.i;
  1957. /* L1197: */
  1958. }
  1959. /* L1196: */
  1960. }
  1961. if (nr > 1) {
  1962. i__1 = nr - 1;
  1963. i__2 = nr - 1;
  1964. zlaset_("U", &i__1, &i__2, &c_b1, &c_b1, &u[(nr + 2) *
  1965. u_dim1 + 1], ldu);
  1966. }
  1967. i__1 = *lcwork - *n - nr;
  1968. zgeqrf_(n, &nr, &u[(nr + 1) * u_dim1 + 1], ldu, &cwork[*n
  1969. + 1], &cwork[*n + nr + 1], &i__1, &ierr);
  1970. i__1 = nr;
  1971. for (p = 1; p <= i__1; ++p) {
  1972. i__2 = *n;
  1973. for (q = 1; q <= i__2; ++q) {
  1974. i__3 = q + p * v_dim1;
  1975. d_cnjg(&z__1, &u[p + (nr + q) * u_dim1]);
  1976. v[i__3].r = z__1.r, v[i__3].i = z__1.i;
  1977. /* L1144: */
  1978. }
  1979. /* L1143: */
  1980. }
  1981. i__1 = nr - 1;
  1982. i__2 = nr - 1;
  1983. zlaset_("U", &i__1, &i__2, &c_b1, &c_b1, &v[(v_dim1 << 1)
  1984. + 1], ldv);
  1985. i__1 = *lcwork - *n - nr;
  1986. zgesvd_("S", "O", &nr, &nr, &v[v_offset], ldv, &s[1], &u[
  1987. u_offset], ldu, &v[v_offset], ldv, &cwork[*n + nr
  1988. + 1], &i__1, &rwork[1], info);
  1989. i__1 = *n - nr;
  1990. zlaset_("A", &i__1, &nr, &c_b1, &c_b1, &v[nr + 1 + v_dim1]
  1991. , ldv);
  1992. i__1 = *n - nr;
  1993. zlaset_("A", &nr, &i__1, &c_b1, &c_b1, &v[(nr + 1) *
  1994. v_dim1 + 1], ldv);
  1995. i__1 = *n - nr;
  1996. i__2 = *n - nr;
  1997. zlaset_("A", &i__1, &i__2, &c_b1, &c_b2, &v[nr + 1 + (nr
  1998. + 1) * v_dim1], ldv);
  1999. i__1 = *lcwork - *n - nr;
  2000. zunmqr_("R", "C", n, n, &nr, &u[(nr + 1) * u_dim1 + 1],
  2001. ldu, &cwork[*n + 1], &v[v_offset], ldv, &cwork[*n
  2002. + nr + 1], &i__1, &ierr);
  2003. zlapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  2004. /* (M x NR) or (M x N) or (M x M). */
  2005. if (nr < *m && ! wntuf) {
  2006. i__1 = *m - nr;
  2007. zlaset_("A", &i__1, &nr, &c_b1, &c_b1, &u[nr + 1 +
  2008. u_dim1], ldu);
  2009. if (nr < n1) {
  2010. i__1 = n1 - nr;
  2011. zlaset_("A", &nr, &i__1, &c_b1, &c_b1, &u[(nr + 1)
  2012. * u_dim1 + 1], ldu);
  2013. i__1 = *m - nr;
  2014. i__2 = n1 - nr;
  2015. zlaset_("A", &i__1, &i__2, &c_b1, &c_b2, &u[nr +
  2016. 1 + (nr + 1) * u_dim1], ldu);
  2017. }
  2018. }
  2019. }
  2020. }
  2021. } else {
  2022. if (wntvr || nr == *n) {
  2023. zlacpy_("U", &nr, n, &a[a_offset], lda, &v[v_offset], ldv);
  2024. if (nr > 1) {
  2025. i__1 = nr - 1;
  2026. i__2 = nr - 1;
  2027. zlaset_("L", &i__1, &i__2, &c_b1, &c_b1, &v[v_dim1 + 2],
  2028. ldv);
  2029. }
  2030. /* singular vectors of R stored in [U](1:NR,1:NR) */
  2031. i__1 = *lcwork - *n;
  2032. zgesvd_("S", "O", &nr, n, &v[v_offset], ldv, &s[1], &u[
  2033. u_offset], ldu, &v[v_offset], ldv, &cwork[*n + 1], &
  2034. i__1, &rwork[1], info);
  2035. zlapmt_(&c_false, &nr, n, &v[v_offset], ldv, &iwork[1]);
  2036. /* (M x NR) or (M x N) or (M x M). */
  2037. if (nr < *m && ! wntuf) {
  2038. i__1 = *m - nr;
  2039. zlaset_("A", &i__1, &nr, &c_b1, &c_b1, &u[nr + 1 + u_dim1]
  2040. , ldu);
  2041. if (nr < n1) {
  2042. i__1 = n1 - nr;
  2043. zlaset_("A", &nr, &i__1, &c_b1, &c_b1, &u[(nr + 1) *
  2044. u_dim1 + 1], ldu);
  2045. i__1 = *m - nr;
  2046. i__2 = n1 - nr;
  2047. zlaset_("A", &i__1, &i__2, &c_b1, &c_b2, &u[nr + 1 + (
  2048. nr + 1) * u_dim1], ldu);
  2049. }
  2050. }
  2051. } else {
  2052. /* is then N1 (N or M) */
  2053. /* [[The optimal ratio N/NR for using LQ instead of padding */
  2054. /* with zeros. Here hard coded to 2; it must be at least */
  2055. /* two due to work space constraints.]] */
  2056. /* OPTRATIO = ILAENV(6, 'ZGESVD', 'S' // 'O', NR,N,0,0) */
  2057. /* OPTRATIO = MAX( OPTRATIO, 2 ) */
  2058. optratio = 2;
  2059. if (optratio * nr > *n) {
  2060. zlacpy_("U", &nr, n, &a[a_offset], lda, &v[v_offset], ldv);
  2061. if (nr > 1) {
  2062. i__1 = nr - 1;
  2063. i__2 = nr - 1;
  2064. zlaset_("L", &i__1, &i__2, &c_b1, &c_b1, &v[v_dim1 +
  2065. 2], ldv);
  2066. }
  2067. /* singular vectors of R stored in [U](1:NR,1:NR) */
  2068. i__1 = *n - nr;
  2069. zlaset_("A", &i__1, n, &c_b1, &c_b1, &v[nr + 1 + v_dim1],
  2070. ldv);
  2071. i__1 = *lcwork - *n;
  2072. zgesvd_("S", "O", n, n, &v[v_offset], ldv, &s[1], &u[
  2073. u_offset], ldu, &v[v_offset], ldv, &cwork[*n + 1],
  2074. &i__1, &rwork[1], info);
  2075. zlapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  2076. /* singular vectors of A. The leading N left singular vectors */
  2077. /* are in [U](1:N,1:N) */
  2078. /* (M x N1), i.e. (M x N) or (M x M). */
  2079. if (*n < *m && ! wntuf) {
  2080. i__1 = *m - *n;
  2081. zlaset_("A", &i__1, n, &c_b1, &c_b1, &u[*n + 1 +
  2082. u_dim1], ldu);
  2083. if (*n < n1) {
  2084. i__1 = n1 - *n;
  2085. zlaset_("A", n, &i__1, &c_b1, &c_b1, &u[(*n + 1) *
  2086. u_dim1 + 1], ldu);
  2087. i__1 = *m - *n;
  2088. i__2 = n1 - *n;
  2089. zlaset_("A", &i__1, &i__2, &c_b1, &c_b2, &u[*n +
  2090. 1 + (*n + 1) * u_dim1], ldu);
  2091. }
  2092. }
  2093. } else {
  2094. zlacpy_("U", &nr, n, &a[a_offset], lda, &u[nr + 1 +
  2095. u_dim1], ldu);
  2096. if (nr > 1) {
  2097. i__1 = nr - 1;
  2098. i__2 = nr - 1;
  2099. zlaset_("L", &i__1, &i__2, &c_b1, &c_b1, &u[nr + 2 +
  2100. u_dim1], ldu);
  2101. }
  2102. i__1 = *lcwork - *n - nr;
  2103. zgelqf_(&nr, n, &u[nr + 1 + u_dim1], ldu, &cwork[*n + 1],
  2104. &cwork[*n + nr + 1], &i__1, &ierr);
  2105. zlacpy_("L", &nr, &nr, &u[nr + 1 + u_dim1], ldu, &v[
  2106. v_offset], ldv);
  2107. if (nr > 1) {
  2108. i__1 = nr - 1;
  2109. i__2 = nr - 1;
  2110. zlaset_("U", &i__1, &i__2, &c_b1, &c_b1, &v[(v_dim1 <<
  2111. 1) + 1], ldv);
  2112. }
  2113. i__1 = *lcwork - *n - nr;
  2114. zgesvd_("S", "O", &nr, &nr, &v[v_offset], ldv, &s[1], &u[
  2115. u_offset], ldu, &v[v_offset], ldv, &cwork[*n + nr
  2116. + 1], &i__1, &rwork[1], info);
  2117. i__1 = *n - nr;
  2118. zlaset_("A", &i__1, &nr, &c_b1, &c_b1, &v[nr + 1 + v_dim1]
  2119. , ldv);
  2120. i__1 = *n - nr;
  2121. zlaset_("A", &nr, &i__1, &c_b1, &c_b1, &v[(nr + 1) *
  2122. v_dim1 + 1], ldv);
  2123. i__1 = *n - nr;
  2124. i__2 = *n - nr;
  2125. zlaset_("A", &i__1, &i__2, &c_b1, &c_b2, &v[nr + 1 + (nr
  2126. + 1) * v_dim1], ldv);
  2127. i__1 = *lcwork - *n - nr;
  2128. zunmlq_("R", "N", n, n, &nr, &u[nr + 1 + u_dim1], ldu, &
  2129. cwork[*n + 1], &v[v_offset], ldv, &cwork[*n + nr
  2130. + 1], &i__1, &ierr);
  2131. zlapmt_(&c_false, n, n, &v[v_offset], ldv, &iwork[1]);
  2132. /* (M x NR) or (M x N) or (M x M). */
  2133. if (nr < *m && ! wntuf) {
  2134. i__1 = *m - nr;
  2135. zlaset_("A", &i__1, &nr, &c_b1, &c_b1, &u[nr + 1 +
  2136. u_dim1], ldu);
  2137. if (nr < n1) {
  2138. i__1 = n1 - nr;
  2139. zlaset_("A", &nr, &i__1, &c_b1, &c_b1, &u[(nr + 1)
  2140. * u_dim1 + 1], ldu);
  2141. i__1 = *m - nr;
  2142. i__2 = n1 - nr;
  2143. zlaset_("A", &i__1, &i__2, &c_b1, &c_b2, &u[nr +
  2144. 1 + (nr + 1) * u_dim1], ldu);
  2145. }
  2146. }
  2147. }
  2148. }
  2149. }
  2150. /* The Q matrix from the first QRF is built into the left singular */
  2151. /* vectors matrix U. */
  2152. if (! wntuf) {
  2153. i__1 = *lcwork - *n;
  2154. zunmqr_("L", "N", m, &n1, n, &a[a_offset], lda, &cwork[1], &u[
  2155. u_offset], ldu, &cwork[*n + 1], &i__1, &ierr);
  2156. }
  2157. if (rowprm && ! wntuf) {
  2158. i__1 = *m - 1;
  2159. zlaswp_(&n1, &u[u_offset], ldu, &c__1, &i__1, &iwork[*n + 1], &
  2160. c_n1);
  2161. }
  2162. /* ... end of the "full SVD" branch */
  2163. }
  2164. /* Check whether some singular values are returned as zeros, e.g. */
  2165. /* due to underflow, and update the numerical rank. */
  2166. p = nr;
  2167. for (q = p; q >= 1; --q) {
  2168. if (s[q] > 0.) {
  2169. goto L4002;
  2170. }
  2171. --nr;
  2172. /* L4001: */
  2173. }
  2174. L4002:
  2175. /* singular values are set to zero. */
  2176. if (nr < *n) {
  2177. i__1 = *n - nr;
  2178. dlaset_("G", &i__1, &c__1, &c_b74, &c_b74, &s[nr + 1], n);
  2179. }
  2180. /* values. */
  2181. if (ascaled) {
  2182. d__1 = sqrt((doublereal) (*m));
  2183. dlascl_("G", &c__0, &c__0, &c_b87, &d__1, &nr, &c__1, &s[1], n, &ierr);
  2184. }
  2185. if (conda) {
  2186. rwork[1] = sconda;
  2187. }
  2188. rwork[2] = (doublereal) (p - nr);
  2189. /* exact zeros in ZGESVD() applied to the (possibly truncated) */
  2190. /* full row rank triangular (trapezoidal) factor of A. */
  2191. *numrank = nr;
  2192. return;
  2193. /* End of ZGESVDQ */
  2194. } /* zgesvdq_ */