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.

dbdsqr.c 42 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521
  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 doublereal c_b15 = -.125;
  485. static integer c__1 = 1;
  486. static doublereal c_b49 = 1.;
  487. static doublereal c_b72 = -1.;
  488. /* > \brief \b DBDSQR */
  489. /* =========== DOCUMENTATION =========== */
  490. /* Online html documentation available at */
  491. /* http://www.netlib.org/lapack/explore-html/ */
  492. /* > \htmlonly */
  493. /* > Download DBDSQR + dependencies */
  494. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dbdsqr.
  495. f"> */
  496. /* > [TGZ]</a> */
  497. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dbdsqr.
  498. f"> */
  499. /* > [ZIP]</a> */
  500. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dbdsqr.
  501. f"> */
  502. /* > [TXT]</a> */
  503. /* > \endhtmlonly */
  504. /* Definition: */
  505. /* =========== */
  506. /* SUBROUTINE DBDSQR( UPLO, N, NCVT, NRU, NCC, D, E, VT, LDVT, U, */
  507. /* LDU, C, LDC, WORK, INFO ) */
  508. /* CHARACTER UPLO */
  509. /* INTEGER INFO, LDC, LDU, LDVT, N, NCC, NCVT, NRU */
  510. /* DOUBLE PRECISION C( LDC, * ), D( * ), E( * ), U( LDU, * ), */
  511. /* $ VT( LDVT, * ), WORK( * ) */
  512. /* > \par Purpose: */
  513. /* ============= */
  514. /* > */
  515. /* > \verbatim */
  516. /* > */
  517. /* > DBDSQR computes the singular values and, optionally, the right and/or */
  518. /* > left singular vectors from the singular value decomposition (SVD) of */
  519. /* > a real N-by-N (upper or lower) bidiagonal matrix B using the implicit */
  520. /* > zero-shift QR algorithm. The SVD of B has the form */
  521. /* > */
  522. /* > B = Q * S * P**T */
  523. /* > */
  524. /* > where S is the diagonal matrix of singular values, Q is an orthogonal */
  525. /* > matrix of left singular vectors, and P is an orthogonal matrix of */
  526. /* > right singular vectors. If left singular vectors are requested, this */
  527. /* > subroutine actually returns U*Q instead of Q, and, if right singular */
  528. /* > vectors are requested, this subroutine returns P**T*VT instead of */
  529. /* > P**T, for given real input matrices U and VT. When U and VT are the */
  530. /* > orthogonal matrices that reduce a general matrix A to bidiagonal */
  531. /* > form: A = U*B*VT, as computed by DGEBRD, then */
  532. /* > */
  533. /* > A = (U*Q) * S * (P**T*VT) */
  534. /* > */
  535. /* > is the SVD of A. Optionally, the subroutine may also compute Q**T*C */
  536. /* > for a given real input matrix C. */
  537. /* > */
  538. /* > See "Computing Small Singular Values of Bidiagonal Matrices With */
  539. /* > Guaranteed High Relative Accuracy," by J. Demmel and W. Kahan, */
  540. /* > LAPACK Working Note #3 (or SIAM J. Sci. Statist. Comput. vol. 11, */
  541. /* > no. 5, pp. 873-912, Sept 1990) and */
  542. /* > "Accurate singular values and differential qd algorithms," by */
  543. /* > B. Parlett and V. Fernando, Technical Report CPAM-554, Mathematics */
  544. /* > Department, University of California at Berkeley, July 1992 */
  545. /* > for a detailed description of the algorithm. */
  546. /* > \endverbatim */
  547. /* Arguments: */
  548. /* ========== */
  549. /* > \param[in] UPLO */
  550. /* > \verbatim */
  551. /* > UPLO is CHARACTER*1 */
  552. /* > = 'U': B is upper bidiagonal; */
  553. /* > = 'L': B is lower bidiagonal. */
  554. /* > \endverbatim */
  555. /* > */
  556. /* > \param[in] N */
  557. /* > \verbatim */
  558. /* > N is INTEGER */
  559. /* > The order of the matrix B. N >= 0. */
  560. /* > \endverbatim */
  561. /* > */
  562. /* > \param[in] NCVT */
  563. /* > \verbatim */
  564. /* > NCVT is INTEGER */
  565. /* > The number of columns of the matrix VT. NCVT >= 0. */
  566. /* > \endverbatim */
  567. /* > */
  568. /* > \param[in] NRU */
  569. /* > \verbatim */
  570. /* > NRU is INTEGER */
  571. /* > The number of rows of the matrix U. NRU >= 0. */
  572. /* > \endverbatim */
  573. /* > */
  574. /* > \param[in] NCC */
  575. /* > \verbatim */
  576. /* > NCC is INTEGER */
  577. /* > The number of columns of the matrix C. NCC >= 0. */
  578. /* > \endverbatim */
  579. /* > */
  580. /* > \param[in,out] D */
  581. /* > \verbatim */
  582. /* > D is DOUBLE PRECISION array, dimension (N) */
  583. /* > On entry, the n diagonal elements of the bidiagonal matrix B. */
  584. /* > On exit, if INFO=0, the singular values of B in decreasing */
  585. /* > order. */
  586. /* > \endverbatim */
  587. /* > */
  588. /* > \param[in,out] E */
  589. /* > \verbatim */
  590. /* > E is DOUBLE PRECISION array, dimension (N-1) */
  591. /* > On entry, the N-1 offdiagonal elements of the bidiagonal */
  592. /* > matrix B. */
  593. /* > On exit, if INFO = 0, E is destroyed; if INFO > 0, D and E */
  594. /* > will contain the diagonal and superdiagonal elements of a */
  595. /* > bidiagonal matrix orthogonally equivalent to the one given */
  596. /* > as input. */
  597. /* > \endverbatim */
  598. /* > */
  599. /* > \param[in,out] VT */
  600. /* > \verbatim */
  601. /* > VT is DOUBLE PRECISION array, dimension (LDVT, NCVT) */
  602. /* > On entry, an N-by-NCVT matrix VT. */
  603. /* > On exit, VT is overwritten by P**T * VT. */
  604. /* > Not referenced if NCVT = 0. */
  605. /* > \endverbatim */
  606. /* > */
  607. /* > \param[in] LDVT */
  608. /* > \verbatim */
  609. /* > LDVT is INTEGER */
  610. /* > The leading dimension of the array VT. */
  611. /* > LDVT >= f2cmax(1,N) if NCVT > 0; LDVT >= 1 if NCVT = 0. */
  612. /* > \endverbatim */
  613. /* > */
  614. /* > \param[in,out] U */
  615. /* > \verbatim */
  616. /* > U is DOUBLE PRECISION array, dimension (LDU, N) */
  617. /* > On entry, an NRU-by-N matrix U. */
  618. /* > On exit, U is overwritten by U * Q. */
  619. /* > Not referenced if NRU = 0. */
  620. /* > \endverbatim */
  621. /* > */
  622. /* > \param[in] LDU */
  623. /* > \verbatim */
  624. /* > LDU is INTEGER */
  625. /* > The leading dimension of the array U. LDU >= f2cmax(1,NRU). */
  626. /* > \endverbatim */
  627. /* > */
  628. /* > \param[in,out] C */
  629. /* > \verbatim */
  630. /* > C is DOUBLE PRECISION array, dimension (LDC, NCC) */
  631. /* > On entry, an N-by-NCC matrix C. */
  632. /* > On exit, C is overwritten by Q**T * C. */
  633. /* > Not referenced if NCC = 0. */
  634. /* > \endverbatim */
  635. /* > */
  636. /* > \param[in] LDC */
  637. /* > \verbatim */
  638. /* > LDC is INTEGER */
  639. /* > The leading dimension of the array C. */
  640. /* > LDC >= f2cmax(1,N) if NCC > 0; LDC >=1 if NCC = 0. */
  641. /* > \endverbatim */
  642. /* > */
  643. /* > \param[out] WORK */
  644. /* > \verbatim */
  645. /* > WORK is DOUBLE PRECISION array, dimension (4*(N-1)) */
  646. /* > \endverbatim */
  647. /* > */
  648. /* > \param[out] INFO */
  649. /* > \verbatim */
  650. /* > INFO is INTEGER */
  651. /* > = 0: successful exit */
  652. /* > < 0: If INFO = -i, the i-th argument had an illegal value */
  653. /* > > 0: */
  654. /* > if NCVT = NRU = NCC = 0, */
  655. /* > = 1, a split was marked by a positive value in E */
  656. /* > = 2, current block of Z not diagonalized after 30*N */
  657. /* > iterations (in inner while loop) */
  658. /* > = 3, termination criterion of outer while loop not met */
  659. /* > (program created more than N unreduced blocks) */
  660. /* > else NCVT = NRU = NCC = 0, */
  661. /* > the algorithm did not converge; D and E contain the */
  662. /* > elements of a bidiagonal matrix which is orthogonally */
  663. /* > similar to the input matrix B; if INFO = i, i */
  664. /* > elements of E have not converged to zero. */
  665. /* > \endverbatim */
  666. /* > \par Internal Parameters: */
  667. /* ========================= */
  668. /* > */
  669. /* > \verbatim */
  670. /* > TOLMUL DOUBLE PRECISION, default = f2cmax(10,f2cmin(100,EPS**(-1/8))) */
  671. /* > TOLMUL controls the convergence criterion of the QR loop. */
  672. /* > If it is positive, TOLMUL*EPS is the desired relative */
  673. /* > precision in the computed singular values. */
  674. /* > If it is negative, abs(TOLMUL*EPS*sigma_max) is the */
  675. /* > desired absolute accuracy in the computed singular */
  676. /* > values (corresponds to relative accuracy */
  677. /* > abs(TOLMUL*EPS) in the largest singular value. */
  678. /* > abs(TOLMUL) should be between 1 and 1/EPS, and preferably */
  679. /* > between 10 (for fast convergence) and .1/EPS */
  680. /* > (for there to be some accuracy in the results). */
  681. /* > Default is to lose at either one eighth or 2 of the */
  682. /* > available decimal digits in each computed singular value */
  683. /* > (whichever is smaller). */
  684. /* > */
  685. /* > MAXITR INTEGER, default = 6 */
  686. /* > MAXITR controls the maximum number of passes of the */
  687. /* > algorithm through its inner loop. The algorithms stops */
  688. /* > (and so fails to converge) if the number of passes */
  689. /* > through the inner loop exceeds MAXITR*N**2. */
  690. /* > */
  691. /* > \endverbatim */
  692. /* > \par Note: */
  693. /* =========== */
  694. /* > */
  695. /* > \verbatim */
  696. /* > Bug report from Cezary Dendek. */
  697. /* > On March 23rd 2017, the INTEGER variable MAXIT = MAXITR*N**2 is */
  698. /* > removed since it can overflow pretty easily (for N larger or equal */
  699. /* > than 18,919). We instead use MAXITDIVN = MAXITR*N. */
  700. /* > \endverbatim */
  701. /* Authors: */
  702. /* ======== */
  703. /* > \author Univ. of Tennessee */
  704. /* > \author Univ. of California Berkeley */
  705. /* > \author Univ. of Colorado Denver */
  706. /* > \author NAG Ltd. */
  707. /* > \date June 2017 */
  708. /* > \ingroup auxOTHERcomputational */
  709. /* ===================================================================== */
  710. /* Subroutine */ void dbdsqr_(char *uplo, integer *n, integer *ncvt, integer *
  711. nru, integer *ncc, doublereal *d__, doublereal *e, doublereal *vt,
  712. integer *ldvt, doublereal *u, integer *ldu, doublereal *c__, integer *
  713. ldc, doublereal *work, integer *info)
  714. {
  715. /* System generated locals */
  716. integer c_dim1, c_offset, u_dim1, u_offset, vt_dim1, vt_offset, i__1,
  717. i__2;
  718. doublereal d__1, d__2, d__3, d__4;
  719. /* Local variables */
  720. doublereal abse;
  721. integer idir;
  722. doublereal abss;
  723. integer oldm;
  724. doublereal cosl;
  725. integer isub, iter;
  726. doublereal unfl, sinl, cosr, smin, smax, sinr;
  727. extern /* Subroutine */ void drot_(integer *, doublereal *, integer *,
  728. doublereal *, integer *, doublereal *, doublereal *);
  729. integer iterdivn;
  730. extern /* Subroutine */ void dlas2_(doublereal *, doublereal *, doublereal
  731. *, doublereal *, doublereal *);
  732. doublereal f, g, h__;
  733. integer i__, j, m;
  734. doublereal r__;
  735. extern /* Subroutine */ void dscal_(integer *, doublereal *, doublereal *,
  736. integer *);
  737. extern logical lsame_(char *, char *);
  738. doublereal oldcs;
  739. extern /* Subroutine */ void dlasr_(char *, char *, char *, integer *,
  740. integer *, doublereal *, doublereal *, doublereal *, integer *);
  741. integer oldll;
  742. doublereal shift, sigmn, oldsn;
  743. extern /* Subroutine */ void dswap_(integer *, doublereal *, integer *,
  744. doublereal *, integer *);
  745. doublereal sminl, sigmx;
  746. logical lower;
  747. integer maxitdivn;
  748. extern /* Subroutine */ void dlasq1_(integer *, doublereal *, doublereal *,
  749. doublereal *, integer *), dlasv2_(doublereal *, doublereal *,
  750. doublereal *, doublereal *, doublereal *, doublereal *,
  751. doublereal *, doublereal *, doublereal *);
  752. doublereal cs;
  753. integer ll;
  754. extern doublereal dlamch_(char *);
  755. doublereal sn, mu;
  756. extern /* Subroutine */ void dlartg_(doublereal *, doublereal *,
  757. doublereal *, doublereal *, doublereal *);
  758. extern int xerbla_(char *, integer *, ftnlen);
  759. doublereal sminoa, thresh;
  760. logical rotate;
  761. integer nm1;
  762. doublereal tolmul;
  763. integer nm12, nm13, lll;
  764. doublereal eps, sll, tol;
  765. /* -- LAPACK computational routine (version 3.7.1) -- */
  766. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  767. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  768. /* June 2017 */
  769. /* ===================================================================== */
  770. /* Test the input parameters. */
  771. /* Parameter adjustments */
  772. --d__;
  773. --e;
  774. vt_dim1 = *ldvt;
  775. vt_offset = 1 + vt_dim1 * 1;
  776. vt -= vt_offset;
  777. u_dim1 = *ldu;
  778. u_offset = 1 + u_dim1 * 1;
  779. u -= u_offset;
  780. c_dim1 = *ldc;
  781. c_offset = 1 + c_dim1 * 1;
  782. c__ -= c_offset;
  783. --work;
  784. /* Function Body */
  785. *info = 0;
  786. lower = lsame_(uplo, "L");
  787. if (! lsame_(uplo, "U") && ! lower) {
  788. *info = -1;
  789. } else if (*n < 0) {
  790. *info = -2;
  791. } else if (*ncvt < 0) {
  792. *info = -3;
  793. } else if (*nru < 0) {
  794. *info = -4;
  795. } else if (*ncc < 0) {
  796. *info = -5;
  797. } else if (*ncvt == 0 && *ldvt < 1 || *ncvt > 0 && *ldvt < f2cmax(1,*n)) {
  798. *info = -9;
  799. } else if (*ldu < f2cmax(1,*nru)) {
  800. *info = -11;
  801. } else if (*ncc == 0 && *ldc < 1 || *ncc > 0 && *ldc < f2cmax(1,*n)) {
  802. *info = -13;
  803. }
  804. if (*info != 0) {
  805. i__1 = -(*info);
  806. xerbla_("DBDSQR", &i__1, (ftnlen)6);
  807. return;
  808. }
  809. if (*n == 0) {
  810. return;
  811. }
  812. if (*n == 1) {
  813. goto L160;
  814. }
  815. /* ROTATE is true if any singular vectors desired, false otherwise */
  816. rotate = *ncvt > 0 || *nru > 0 || *ncc > 0;
  817. /* If no singular vectors desired, use qd algorithm */
  818. if (! rotate) {
  819. dlasq1_(n, &d__[1], &e[1], &work[1], info);
  820. /* If INFO equals 2, dqds didn't finish, try to finish */
  821. if (*info != 2) {
  822. return;
  823. }
  824. *info = 0;
  825. }
  826. nm1 = *n - 1;
  827. nm12 = nm1 + nm1;
  828. nm13 = nm12 + nm1;
  829. idir = 0;
  830. /* Get machine constants */
  831. eps = dlamch_("Epsilon");
  832. unfl = dlamch_("Safe minimum");
  833. /* If matrix lower bidiagonal, rotate to be upper bidiagonal */
  834. /* by applying Givens rotations on the left */
  835. if (lower) {
  836. i__1 = *n - 1;
  837. for (i__ = 1; i__ <= i__1; ++i__) {
  838. dlartg_(&d__[i__], &e[i__], &cs, &sn, &r__);
  839. d__[i__] = r__;
  840. e[i__] = sn * d__[i__ + 1];
  841. d__[i__ + 1] = cs * d__[i__ + 1];
  842. work[i__] = cs;
  843. work[nm1 + i__] = sn;
  844. /* L10: */
  845. }
  846. /* Update singular vectors if desired */
  847. if (*nru > 0) {
  848. dlasr_("R", "V", "F", nru, n, &work[1], &work[*n], &u[u_offset],
  849. ldu);
  850. }
  851. if (*ncc > 0) {
  852. dlasr_("L", "V", "F", n, ncc, &work[1], &work[*n], &c__[c_offset],
  853. ldc);
  854. }
  855. }
  856. /* Compute singular values to relative accuracy TOL */
  857. /* (By setting TOL to be negative, algorithm will compute */
  858. /* singular values to absolute accuracy ABS(TOL)*norm(input matrix)) */
  859. /* Computing MAX */
  860. /* Computing MIN */
  861. d__3 = 100., d__4 = pow_dd(&eps, &c_b15);
  862. d__1 = 10., d__2 = f2cmin(d__3,d__4);
  863. tolmul = f2cmax(d__1,d__2);
  864. tol = tolmul * eps;
  865. /* Compute approximate maximum, minimum singular values */
  866. smax = 0.;
  867. i__1 = *n;
  868. for (i__ = 1; i__ <= i__1; ++i__) {
  869. /* Computing MAX */
  870. d__2 = smax, d__3 = (d__1 = d__[i__], abs(d__1));
  871. smax = f2cmax(d__2,d__3);
  872. /* L20: */
  873. }
  874. i__1 = *n - 1;
  875. for (i__ = 1; i__ <= i__1; ++i__) {
  876. /* Computing MAX */
  877. d__2 = smax, d__3 = (d__1 = e[i__], abs(d__1));
  878. smax = f2cmax(d__2,d__3);
  879. /* L30: */
  880. }
  881. sminl = 0.;
  882. if (tol >= 0.) {
  883. /* Relative accuracy desired */
  884. sminoa = abs(d__[1]);
  885. if (sminoa == 0.) {
  886. goto L50;
  887. }
  888. mu = sminoa;
  889. i__1 = *n;
  890. for (i__ = 2; i__ <= i__1; ++i__) {
  891. mu = (d__2 = d__[i__], abs(d__2)) * (mu / (mu + (d__1 = e[i__ - 1]
  892. , abs(d__1))));
  893. sminoa = f2cmin(sminoa,mu);
  894. if (sminoa == 0.) {
  895. goto L50;
  896. }
  897. /* L40: */
  898. }
  899. L50:
  900. sminoa /= sqrt((doublereal) (*n));
  901. /* Computing MAX */
  902. d__1 = tol * sminoa, d__2 = *n * (*n * unfl) * 6;
  903. thresh = f2cmax(d__1,d__2);
  904. } else {
  905. /* Absolute accuracy desired */
  906. /* Computing MAX */
  907. d__1 = abs(tol) * smax, d__2 = *n * (*n * unfl) * 6;
  908. thresh = f2cmax(d__1,d__2);
  909. }
  910. /* Prepare for main iteration loop for the singular values */
  911. /* (MAXIT is the maximum number of passes through the inner */
  912. /* loop permitted before nonconvergence signalled.) */
  913. maxitdivn = *n * 6;
  914. iterdivn = 0;
  915. iter = -1;
  916. oldll = -1;
  917. oldm = -1;
  918. /* M points to last element of unconverged part of matrix */
  919. m = *n;
  920. /* Begin main iteration loop */
  921. L60:
  922. /* Check for convergence or exceeding iteration count */
  923. if (m <= 1) {
  924. goto L160;
  925. }
  926. if (iter >= *n) {
  927. iter -= *n;
  928. ++iterdivn;
  929. if (iterdivn >= maxitdivn) {
  930. goto L200;
  931. }
  932. }
  933. /* Find diagonal block of matrix to work on */
  934. if (tol < 0. && (d__1 = d__[m], abs(d__1)) <= thresh) {
  935. d__[m] = 0.;
  936. }
  937. smax = (d__1 = d__[m], abs(d__1));
  938. smin = smax;
  939. i__1 = m - 1;
  940. for (lll = 1; lll <= i__1; ++lll) {
  941. ll = m - lll;
  942. abss = (d__1 = d__[ll], abs(d__1));
  943. abse = (d__1 = e[ll], abs(d__1));
  944. if (tol < 0. && abss <= thresh) {
  945. d__[ll] = 0.;
  946. }
  947. if (abse <= thresh) {
  948. goto L80;
  949. }
  950. smin = f2cmin(smin,abss);
  951. /* Computing MAX */
  952. d__1 = f2cmax(smax,abss);
  953. smax = f2cmax(d__1,abse);
  954. /* L70: */
  955. }
  956. ll = 0;
  957. goto L90;
  958. L80:
  959. e[ll] = 0.;
  960. /* Matrix splits since E(LL) = 0 */
  961. if (ll == m - 1) {
  962. /* Convergence of bottom singular value, return to top of loop */
  963. --m;
  964. goto L60;
  965. }
  966. L90:
  967. ++ll;
  968. /* E(LL) through E(M-1) are nonzero, E(LL-1) is zero */
  969. if (ll == m - 1) {
  970. /* 2 by 2 block, handle separately */
  971. dlasv2_(&d__[m - 1], &e[m - 1], &d__[m], &sigmn, &sigmx, &sinr, &cosr,
  972. &sinl, &cosl);
  973. d__[m - 1] = sigmx;
  974. e[m - 1] = 0.;
  975. d__[m] = sigmn;
  976. /* Compute singular vectors, if desired */
  977. if (*ncvt > 0) {
  978. drot_(ncvt, &vt[m - 1 + vt_dim1], ldvt, &vt[m + vt_dim1], ldvt, &
  979. cosr, &sinr);
  980. }
  981. if (*nru > 0) {
  982. drot_(nru, &u[(m - 1) * u_dim1 + 1], &c__1, &u[m * u_dim1 + 1], &
  983. c__1, &cosl, &sinl);
  984. }
  985. if (*ncc > 0) {
  986. drot_(ncc, &c__[m - 1 + c_dim1], ldc, &c__[m + c_dim1], ldc, &
  987. cosl, &sinl);
  988. }
  989. m += -2;
  990. goto L60;
  991. }
  992. /* If working on new submatrix, choose shift direction */
  993. /* (from larger end diagonal element towards smaller) */
  994. if (ll > oldm || m < oldll) {
  995. if ((d__1 = d__[ll], abs(d__1)) >= (d__2 = d__[m], abs(d__2))) {
  996. /* Chase bulge from top (big end) to bottom (small end) */
  997. idir = 1;
  998. } else {
  999. /* Chase bulge from bottom (big end) to top (small end) */
  1000. idir = 2;
  1001. }
  1002. }
  1003. /* Apply convergence tests */
  1004. if (idir == 1) {
  1005. /* Run convergence test in forward direction */
  1006. /* First apply standard test to bottom of matrix */
  1007. if ((d__2 = e[m - 1], abs(d__2)) <= abs(tol) * (d__1 = d__[m], abs(
  1008. d__1)) || tol < 0. && (d__3 = e[m - 1], abs(d__3)) <= thresh)
  1009. {
  1010. e[m - 1] = 0.;
  1011. goto L60;
  1012. }
  1013. if (tol >= 0.) {
  1014. /* If relative accuracy desired, */
  1015. /* apply convergence criterion forward */
  1016. mu = (d__1 = d__[ll], abs(d__1));
  1017. sminl = mu;
  1018. i__1 = m - 1;
  1019. for (lll = ll; lll <= i__1; ++lll) {
  1020. if ((d__1 = e[lll], abs(d__1)) <= tol * mu) {
  1021. e[lll] = 0.;
  1022. goto L60;
  1023. }
  1024. mu = (d__2 = d__[lll + 1], abs(d__2)) * (mu / (mu + (d__1 = e[
  1025. lll], abs(d__1))));
  1026. sminl = f2cmin(sminl,mu);
  1027. /* L100: */
  1028. }
  1029. }
  1030. } else {
  1031. /* Run convergence test in backward direction */
  1032. /* First apply standard test to top of matrix */
  1033. if ((d__2 = e[ll], abs(d__2)) <= abs(tol) * (d__1 = d__[ll], abs(d__1)
  1034. ) || tol < 0. && (d__3 = e[ll], abs(d__3)) <= thresh) {
  1035. e[ll] = 0.;
  1036. goto L60;
  1037. }
  1038. if (tol >= 0.) {
  1039. /* If relative accuracy desired, */
  1040. /* apply convergence criterion backward */
  1041. mu = (d__1 = d__[m], abs(d__1));
  1042. sminl = mu;
  1043. i__1 = ll;
  1044. for (lll = m - 1; lll >= i__1; --lll) {
  1045. if ((d__1 = e[lll], abs(d__1)) <= tol * mu) {
  1046. e[lll] = 0.;
  1047. goto L60;
  1048. }
  1049. mu = (d__2 = d__[lll], abs(d__2)) * (mu / (mu + (d__1 = e[lll]
  1050. , abs(d__1))));
  1051. sminl = f2cmin(sminl,mu);
  1052. /* L110: */
  1053. }
  1054. }
  1055. }
  1056. oldll = ll;
  1057. oldm = m;
  1058. /* Compute shift. First, test if shifting would ruin relative */
  1059. /* accuracy, and if so set the shift to zero. */
  1060. /* Computing MAX */
  1061. d__1 = eps, d__2 = tol * .01;
  1062. if (tol >= 0. && *n * tol * (sminl / smax) <= f2cmax(d__1,d__2)) {
  1063. /* Use a zero shift to avoid loss of relative accuracy */
  1064. shift = 0.;
  1065. } else {
  1066. /* Compute the shift from 2-by-2 block at end of matrix */
  1067. if (idir == 1) {
  1068. sll = (d__1 = d__[ll], abs(d__1));
  1069. dlas2_(&d__[m - 1], &e[m - 1], &d__[m], &shift, &r__);
  1070. } else {
  1071. sll = (d__1 = d__[m], abs(d__1));
  1072. dlas2_(&d__[ll], &e[ll], &d__[ll + 1], &shift, &r__);
  1073. }
  1074. /* Test if shift negligible, and if so set to zero */
  1075. if (sll > 0.) {
  1076. /* Computing 2nd power */
  1077. d__1 = shift / sll;
  1078. if (d__1 * d__1 < eps) {
  1079. shift = 0.;
  1080. }
  1081. }
  1082. }
  1083. /* Increment iteration count */
  1084. iter = iter + m - ll;
  1085. /* If SHIFT = 0, do simplified QR iteration */
  1086. if (shift == 0.) {
  1087. if (idir == 1) {
  1088. /* Chase bulge from top to bottom */
  1089. /* Save cosines and sines for later singular vector updates */
  1090. cs = 1.;
  1091. oldcs = 1.;
  1092. i__1 = m - 1;
  1093. for (i__ = ll; i__ <= i__1; ++i__) {
  1094. d__1 = d__[i__] * cs;
  1095. dlartg_(&d__1, &e[i__], &cs, &sn, &r__);
  1096. if (i__ > ll) {
  1097. e[i__ - 1] = oldsn * r__;
  1098. }
  1099. d__1 = oldcs * r__;
  1100. d__2 = d__[i__ + 1] * sn;
  1101. dlartg_(&d__1, &d__2, &oldcs, &oldsn, &d__[i__]);
  1102. work[i__ - ll + 1] = cs;
  1103. work[i__ - ll + 1 + nm1] = sn;
  1104. work[i__ - ll + 1 + nm12] = oldcs;
  1105. work[i__ - ll + 1 + nm13] = oldsn;
  1106. /* L120: */
  1107. }
  1108. h__ = d__[m] * cs;
  1109. d__[m] = h__ * oldcs;
  1110. e[m - 1] = h__ * oldsn;
  1111. /* Update singular vectors */
  1112. if (*ncvt > 0) {
  1113. i__1 = m - ll + 1;
  1114. dlasr_("L", "V", "F", &i__1, ncvt, &work[1], &work[*n], &vt[
  1115. ll + vt_dim1], ldvt);
  1116. }
  1117. if (*nru > 0) {
  1118. i__1 = m - ll + 1;
  1119. dlasr_("R", "V", "F", nru, &i__1, &work[nm12 + 1], &work[nm13
  1120. + 1], &u[ll * u_dim1 + 1], ldu);
  1121. }
  1122. if (*ncc > 0) {
  1123. i__1 = m - ll + 1;
  1124. dlasr_("L", "V", "F", &i__1, ncc, &work[nm12 + 1], &work[nm13
  1125. + 1], &c__[ll + c_dim1], ldc);
  1126. }
  1127. /* Test convergence */
  1128. if ((d__1 = e[m - 1], abs(d__1)) <= thresh) {
  1129. e[m - 1] = 0.;
  1130. }
  1131. } else {
  1132. /* Chase bulge from bottom to top */
  1133. /* Save cosines and sines for later singular vector updates */
  1134. cs = 1.;
  1135. oldcs = 1.;
  1136. i__1 = ll + 1;
  1137. for (i__ = m; i__ >= i__1; --i__) {
  1138. d__1 = d__[i__] * cs;
  1139. dlartg_(&d__1, &e[i__ - 1], &cs, &sn, &r__);
  1140. if (i__ < m) {
  1141. e[i__] = oldsn * r__;
  1142. }
  1143. d__1 = oldcs * r__;
  1144. d__2 = d__[i__ - 1] * sn;
  1145. dlartg_(&d__1, &d__2, &oldcs, &oldsn, &d__[i__]);
  1146. work[i__ - ll] = cs;
  1147. work[i__ - ll + nm1] = -sn;
  1148. work[i__ - ll + nm12] = oldcs;
  1149. work[i__ - ll + nm13] = -oldsn;
  1150. /* L130: */
  1151. }
  1152. h__ = d__[ll] * cs;
  1153. d__[ll] = h__ * oldcs;
  1154. e[ll] = h__ * oldsn;
  1155. /* Update singular vectors */
  1156. if (*ncvt > 0) {
  1157. i__1 = m - ll + 1;
  1158. dlasr_("L", "V", "B", &i__1, ncvt, &work[nm12 + 1], &work[
  1159. nm13 + 1], &vt[ll + vt_dim1], ldvt);
  1160. }
  1161. if (*nru > 0) {
  1162. i__1 = m - ll + 1;
  1163. dlasr_("R", "V", "B", nru, &i__1, &work[1], &work[*n], &u[ll *
  1164. u_dim1 + 1], ldu);
  1165. }
  1166. if (*ncc > 0) {
  1167. i__1 = m - ll + 1;
  1168. dlasr_("L", "V", "B", &i__1, ncc, &work[1], &work[*n], &c__[
  1169. ll + c_dim1], ldc);
  1170. }
  1171. /* Test convergence */
  1172. if ((d__1 = e[ll], abs(d__1)) <= thresh) {
  1173. e[ll] = 0.;
  1174. }
  1175. }
  1176. } else {
  1177. /* Use nonzero shift */
  1178. if (idir == 1) {
  1179. /* Chase bulge from top to bottom */
  1180. /* Save cosines and sines for later singular vector updates */
  1181. f = ((d__1 = d__[ll], abs(d__1)) - shift) * (d_sign(&c_b49, &d__[
  1182. ll]) + shift / d__[ll]);
  1183. g = e[ll];
  1184. i__1 = m - 1;
  1185. for (i__ = ll; i__ <= i__1; ++i__) {
  1186. dlartg_(&f, &g, &cosr, &sinr, &r__);
  1187. if (i__ > ll) {
  1188. e[i__ - 1] = r__;
  1189. }
  1190. f = cosr * d__[i__] + sinr * e[i__];
  1191. e[i__] = cosr * e[i__] - sinr * d__[i__];
  1192. g = sinr * d__[i__ + 1];
  1193. d__[i__ + 1] = cosr * d__[i__ + 1];
  1194. dlartg_(&f, &g, &cosl, &sinl, &r__);
  1195. d__[i__] = r__;
  1196. f = cosl * e[i__] + sinl * d__[i__ + 1];
  1197. d__[i__ + 1] = cosl * d__[i__ + 1] - sinl * e[i__];
  1198. if (i__ < m - 1) {
  1199. g = sinl * e[i__ + 1];
  1200. e[i__ + 1] = cosl * e[i__ + 1];
  1201. }
  1202. work[i__ - ll + 1] = cosr;
  1203. work[i__ - ll + 1 + nm1] = sinr;
  1204. work[i__ - ll + 1 + nm12] = cosl;
  1205. work[i__ - ll + 1 + nm13] = sinl;
  1206. /* L140: */
  1207. }
  1208. e[m - 1] = f;
  1209. /* Update singular vectors */
  1210. if (*ncvt > 0) {
  1211. i__1 = m - ll + 1;
  1212. dlasr_("L", "V", "F", &i__1, ncvt, &work[1], &work[*n], &vt[
  1213. ll + vt_dim1], ldvt);
  1214. }
  1215. if (*nru > 0) {
  1216. i__1 = m - ll + 1;
  1217. dlasr_("R", "V", "F", nru, &i__1, &work[nm12 + 1], &work[nm13
  1218. + 1], &u[ll * u_dim1 + 1], ldu);
  1219. }
  1220. if (*ncc > 0) {
  1221. i__1 = m - ll + 1;
  1222. dlasr_("L", "V", "F", &i__1, ncc, &work[nm12 + 1], &work[nm13
  1223. + 1], &c__[ll + c_dim1], ldc);
  1224. }
  1225. /* Test convergence */
  1226. if ((d__1 = e[m - 1], abs(d__1)) <= thresh) {
  1227. e[m - 1] = 0.;
  1228. }
  1229. } else {
  1230. /* Chase bulge from bottom to top */
  1231. /* Save cosines and sines for later singular vector updates */
  1232. f = ((d__1 = d__[m], abs(d__1)) - shift) * (d_sign(&c_b49, &d__[m]
  1233. ) + shift / d__[m]);
  1234. g = e[m - 1];
  1235. i__1 = ll + 1;
  1236. for (i__ = m; i__ >= i__1; --i__) {
  1237. dlartg_(&f, &g, &cosr, &sinr, &r__);
  1238. if (i__ < m) {
  1239. e[i__] = r__;
  1240. }
  1241. f = cosr * d__[i__] + sinr * e[i__ - 1];
  1242. e[i__ - 1] = cosr * e[i__ - 1] - sinr * d__[i__];
  1243. g = sinr * d__[i__ - 1];
  1244. d__[i__ - 1] = cosr * d__[i__ - 1];
  1245. dlartg_(&f, &g, &cosl, &sinl, &r__);
  1246. d__[i__] = r__;
  1247. f = cosl * e[i__ - 1] + sinl * d__[i__ - 1];
  1248. d__[i__ - 1] = cosl * d__[i__ - 1] - sinl * e[i__ - 1];
  1249. if (i__ > ll + 1) {
  1250. g = sinl * e[i__ - 2];
  1251. e[i__ - 2] = cosl * e[i__ - 2];
  1252. }
  1253. work[i__ - ll] = cosr;
  1254. work[i__ - ll + nm1] = -sinr;
  1255. work[i__ - ll + nm12] = cosl;
  1256. work[i__ - ll + nm13] = -sinl;
  1257. /* L150: */
  1258. }
  1259. e[ll] = f;
  1260. /* Test convergence */
  1261. if ((d__1 = e[ll], abs(d__1)) <= thresh) {
  1262. e[ll] = 0.;
  1263. }
  1264. /* Update singular vectors if desired */
  1265. if (*ncvt > 0) {
  1266. i__1 = m - ll + 1;
  1267. dlasr_("L", "V", "B", &i__1, ncvt, &work[nm12 + 1], &work[
  1268. nm13 + 1], &vt[ll + vt_dim1], ldvt);
  1269. }
  1270. if (*nru > 0) {
  1271. i__1 = m - ll + 1;
  1272. dlasr_("R", "V", "B", nru, &i__1, &work[1], &work[*n], &u[ll *
  1273. u_dim1 + 1], ldu);
  1274. }
  1275. if (*ncc > 0) {
  1276. i__1 = m - ll + 1;
  1277. dlasr_("L", "V", "B", &i__1, ncc, &work[1], &work[*n], &c__[
  1278. ll + c_dim1], ldc);
  1279. }
  1280. }
  1281. }
  1282. /* QR iteration finished, go back and check convergence */
  1283. goto L60;
  1284. /* All singular values converged, so make them positive */
  1285. L160:
  1286. i__1 = *n;
  1287. for (i__ = 1; i__ <= i__1; ++i__) {
  1288. if (d__[i__] < 0.) {
  1289. d__[i__] = -d__[i__];
  1290. /* Change sign of singular vectors, if desired */
  1291. if (*ncvt > 0) {
  1292. dscal_(ncvt, &c_b72, &vt[i__ + vt_dim1], ldvt);
  1293. }
  1294. }
  1295. /* L170: */
  1296. }
  1297. /* Sort the singular values into decreasing order (insertion sort on */
  1298. /* singular values, but only one transposition per singular vector) */
  1299. i__1 = *n - 1;
  1300. for (i__ = 1; i__ <= i__1; ++i__) {
  1301. /* Scan for smallest D(I) */
  1302. isub = 1;
  1303. smin = d__[1];
  1304. i__2 = *n + 1 - i__;
  1305. for (j = 2; j <= i__2; ++j) {
  1306. if (d__[j] <= smin) {
  1307. isub = j;
  1308. smin = d__[j];
  1309. }
  1310. /* L180: */
  1311. }
  1312. if (isub != *n + 1 - i__) {
  1313. /* Swap singular values and vectors */
  1314. d__[isub] = d__[*n + 1 - i__];
  1315. d__[*n + 1 - i__] = smin;
  1316. if (*ncvt > 0) {
  1317. dswap_(ncvt, &vt[isub + vt_dim1], ldvt, &vt[*n + 1 - i__ +
  1318. vt_dim1], ldvt);
  1319. }
  1320. if (*nru > 0) {
  1321. dswap_(nru, &u[isub * u_dim1 + 1], &c__1, &u[(*n + 1 - i__) *
  1322. u_dim1 + 1], &c__1);
  1323. }
  1324. if (*ncc > 0) {
  1325. dswap_(ncc, &c__[isub + c_dim1], ldc, &c__[*n + 1 - i__ +
  1326. c_dim1], ldc);
  1327. }
  1328. }
  1329. /* L190: */
  1330. }
  1331. goto L220;
  1332. /* Maximum number of iterations exceeded, failure to converge */
  1333. L200:
  1334. *info = 0;
  1335. i__1 = *n - 1;
  1336. for (i__ = 1; i__ <= i__1; ++i__) {
  1337. if (e[i__] != 0.) {
  1338. ++(*info);
  1339. }
  1340. /* L210: */
  1341. }
  1342. L220:
  1343. return;
  1344. /* End of DBDSQR */
  1345. } /* dbdsqr_ */