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.

dgesvdq.c 70 kB

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