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.

dbdsdc.c 30 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990
  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__9 = 9;
  381. static integer c__0 = 0;
  382. static doublereal c_b15 = 1.;
  383. static integer c__1 = 1;
  384. static doublereal c_b29 = 0.;
  385. /* > \brief \b DBDSDC */
  386. /* =========== DOCUMENTATION =========== */
  387. /* Online html documentation available at */
  388. /* http://www.netlib.org/lapack/explore-html/ */
  389. /* > \htmlonly */
  390. /* > Download DBDSDC + dependencies */
  391. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dbdsdc.
  392. f"> */
  393. /* > [TGZ]</a> */
  394. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dbdsdc.
  395. f"> */
  396. /* > [ZIP]</a> */
  397. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dbdsdc.
  398. f"> */
  399. /* > [TXT]</a> */
  400. /* > \endhtmlonly */
  401. /* Definition: */
  402. /* =========== */
  403. /* SUBROUTINE DBDSDC( UPLO, COMPQ, N, D, E, U, LDU, VT, LDVT, Q, IQ, */
  404. /* WORK, IWORK, INFO ) */
  405. /* CHARACTER COMPQ, UPLO */
  406. /* INTEGER INFO, LDU, LDVT, N */
  407. /* INTEGER IQ( * ), IWORK( * ) */
  408. /* DOUBLE PRECISION D( * ), E( * ), Q( * ), U( LDU, * ), */
  409. /* $ VT( LDVT, * ), WORK( * ) */
  410. /* > \par Purpose: */
  411. /* ============= */
  412. /* > */
  413. /* > \verbatim */
  414. /* > */
  415. /* > DBDSDC computes the singular value decomposition (SVD) of a real */
  416. /* > N-by-N (upper or lower) bidiagonal matrix B: B = U * S * VT, */
  417. /* > using a divide and conquer method, where S is a diagonal matrix */
  418. /* > with non-negative diagonal elements (the singular values of B), and */
  419. /* > U and VT are orthogonal matrices of left and right singular vectors, */
  420. /* > respectively. DBDSDC can be used to compute all singular values, */
  421. /* > and optionally, singular vectors or singular vectors in compact form. */
  422. /* > */
  423. /* > This code makes very mild assumptions about floating point */
  424. /* > arithmetic. It will work on machines with a guard digit in */
  425. /* > add/subtract, or on those binary machines without guard digits */
  426. /* > which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or Cray-2. */
  427. /* > It could conceivably fail on hexadecimal or decimal machines */
  428. /* > without guard digits, but we know of none. See DLASD3 for details. */
  429. /* > */
  430. /* > The code currently calls DLASDQ if singular values only are desired. */
  431. /* > However, it can be slightly modified to compute singular values */
  432. /* > using the divide and conquer method. */
  433. /* > \endverbatim */
  434. /* Arguments: */
  435. /* ========== */
  436. /* > \param[in] UPLO */
  437. /* > \verbatim */
  438. /* > UPLO is CHARACTER*1 */
  439. /* > = 'U': B is upper bidiagonal. */
  440. /* > = 'L': B is lower bidiagonal. */
  441. /* > \endverbatim */
  442. /* > */
  443. /* > \param[in] COMPQ */
  444. /* > \verbatim */
  445. /* > COMPQ is CHARACTER*1 */
  446. /* > Specifies whether singular vectors are to be computed */
  447. /* > as follows: */
  448. /* > = 'N': Compute singular values only; */
  449. /* > = 'P': Compute singular values and compute singular */
  450. /* > vectors in compact form; */
  451. /* > = 'I': Compute singular values and singular vectors. */
  452. /* > \endverbatim */
  453. /* > */
  454. /* > \param[in] N */
  455. /* > \verbatim */
  456. /* > N is INTEGER */
  457. /* > The order of the matrix B. N >= 0. */
  458. /* > \endverbatim */
  459. /* > */
  460. /* > \param[in,out] D */
  461. /* > \verbatim */
  462. /* > D is DOUBLE PRECISION array, dimension (N) */
  463. /* > On entry, the n diagonal elements of the bidiagonal matrix B. */
  464. /* > On exit, if INFO=0, the singular values of B. */
  465. /* > \endverbatim */
  466. /* > */
  467. /* > \param[in,out] E */
  468. /* > \verbatim */
  469. /* > E is DOUBLE PRECISION array, dimension (N-1) */
  470. /* > On entry, the elements of E contain the offdiagonal */
  471. /* > elements of the bidiagonal matrix whose SVD is desired. */
  472. /* > On exit, E has been destroyed. */
  473. /* > \endverbatim */
  474. /* > */
  475. /* > \param[out] U */
  476. /* > \verbatim */
  477. /* > U is DOUBLE PRECISION array, dimension (LDU,N) */
  478. /* > If COMPQ = 'I', then: */
  479. /* > On exit, if INFO = 0, U contains the left singular vectors */
  480. /* > of the bidiagonal matrix. */
  481. /* > For other values of COMPQ, U is not referenced. */
  482. /* > \endverbatim */
  483. /* > */
  484. /* > \param[in] LDU */
  485. /* > \verbatim */
  486. /* > LDU is INTEGER */
  487. /* > The leading dimension of the array U. LDU >= 1. */
  488. /* > If singular vectors are desired, then LDU >= f2cmax( 1, N ). */
  489. /* > \endverbatim */
  490. /* > */
  491. /* > \param[out] VT */
  492. /* > \verbatim */
  493. /* > VT is DOUBLE PRECISION array, dimension (LDVT,N) */
  494. /* > If COMPQ = 'I', then: */
  495. /* > On exit, if INFO = 0, VT**T contains the right singular */
  496. /* > vectors of the bidiagonal matrix. */
  497. /* > For other values of COMPQ, VT is not referenced. */
  498. /* > \endverbatim */
  499. /* > */
  500. /* > \param[in] LDVT */
  501. /* > \verbatim */
  502. /* > LDVT is INTEGER */
  503. /* > The leading dimension of the array VT. LDVT >= 1. */
  504. /* > If singular vectors are desired, then LDVT >= f2cmax( 1, N ). */
  505. /* > \endverbatim */
  506. /* > */
  507. /* > \param[out] Q */
  508. /* > \verbatim */
  509. /* > Q is DOUBLE PRECISION array, dimension (LDQ) */
  510. /* > If COMPQ = 'P', then: */
  511. /* > On exit, if INFO = 0, Q and IQ contain the left */
  512. /* > and right singular vectors in a compact form, */
  513. /* > requiring O(N log N) space instead of 2*N**2. */
  514. /* > In particular, Q contains all the DOUBLE PRECISION data in */
  515. /* > LDQ >= N*(11 + 2*SMLSIZ + 8*INT(LOG_2(N/(SMLSIZ+1)))) */
  516. /* > words of memory, where SMLSIZ is returned by ILAENV and */
  517. /* > is equal to the maximum size of the subproblems at the */
  518. /* > bottom of the computation tree (usually about 25). */
  519. /* > For other values of COMPQ, Q is not referenced. */
  520. /* > \endverbatim */
  521. /* > */
  522. /* > \param[out] IQ */
  523. /* > \verbatim */
  524. /* > IQ is INTEGER array, dimension (LDIQ) */
  525. /* > If COMPQ = 'P', then: */
  526. /* > On exit, if INFO = 0, Q and IQ contain the left */
  527. /* > and right singular vectors in a compact form, */
  528. /* > requiring O(N log N) space instead of 2*N**2. */
  529. /* > In particular, IQ contains all INTEGER data in */
  530. /* > LDIQ >= N*(3 + 3*INT(LOG_2(N/(SMLSIZ+1)))) */
  531. /* > words of memory, where SMLSIZ is returned by ILAENV and */
  532. /* > is equal to the maximum size of the subproblems at the */
  533. /* > bottom of the computation tree (usually about 25). */
  534. /* > For other values of COMPQ, IQ is not referenced. */
  535. /* > \endverbatim */
  536. /* > */
  537. /* > \param[out] WORK */
  538. /* > \verbatim */
  539. /* > WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */
  540. /* > If COMPQ = 'N' then LWORK >= (4 * N). */
  541. /* > If COMPQ = 'P' then LWORK >= (6 * N). */
  542. /* > If COMPQ = 'I' then LWORK >= (3 * N**2 + 4 * N). */
  543. /* > \endverbatim */
  544. /* > */
  545. /* > \param[out] IWORK */
  546. /* > \verbatim */
  547. /* > IWORK is INTEGER array, dimension (8*N) */
  548. /* > \endverbatim */
  549. /* > */
  550. /* > \param[out] INFO */
  551. /* > \verbatim */
  552. /* > INFO is INTEGER */
  553. /* > = 0: successful exit. */
  554. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  555. /* > > 0: The algorithm failed to compute a singular value. */
  556. /* > The update process of divide and conquer failed. */
  557. /* > \endverbatim */
  558. /* Authors: */
  559. /* ======== */
  560. /* > \author Univ. of Tennessee */
  561. /* > \author Univ. of California Berkeley */
  562. /* > \author Univ. of Colorado Denver */
  563. /* > \author NAG Ltd. */
  564. /* > \date June 2016 */
  565. /* > \ingroup auxOTHERcomputational */
  566. /* > \par Contributors: */
  567. /* ================== */
  568. /* > */
  569. /* > Ming Gu and Huan Ren, Computer Science Division, University of */
  570. /* > California at Berkeley, USA */
  571. /* > */
  572. /* ===================================================================== */
  573. /* Subroutine */ int dbdsdc_(char *uplo, char *compq, integer *n, doublereal *
  574. d__, doublereal *e, doublereal *u, integer *ldu, doublereal *vt,
  575. integer *ldvt, doublereal *q, integer *iq, doublereal *work, integer *
  576. iwork, integer *info)
  577. {
  578. /* System generated locals */
  579. integer u_dim1, u_offset, vt_dim1, vt_offset, i__1, i__2;
  580. doublereal d__1;
  581. /* Local variables */
  582. integer difl, difr, ierr, perm, mlvl, sqre, i__, j, k;
  583. doublereal p, r__;
  584. integer z__;
  585. extern logical lsame_(char *, char *);
  586. extern /* Subroutine */ int dlasr_(char *, char *, char *, integer *,
  587. integer *, doublereal *, doublereal *, doublereal *, integer *), dcopy_(integer *, doublereal *, integer *
  588. , doublereal *, integer *), dswap_(integer *, doublereal *,
  589. integer *, doublereal *, integer *);
  590. integer poles, iuplo, nsize, start;
  591. extern /* Subroutine */ int dlasd0_(integer *, integer *, doublereal *,
  592. doublereal *, doublereal *, integer *, doublereal *, integer *,
  593. integer *, integer *, doublereal *, integer *);
  594. integer ic, ii, kk;
  595. doublereal cs;
  596. extern doublereal dlamch_(char *);
  597. extern /* Subroutine */ int dlasda_(integer *, integer *, integer *,
  598. integer *, doublereal *, doublereal *, doublereal *, integer *,
  599. doublereal *, integer *, doublereal *, doublereal *, doublereal *,
  600. doublereal *, integer *, integer *, integer *, integer *,
  601. doublereal *, doublereal *, doublereal *, doublereal *, integer *,
  602. integer *);
  603. integer is, iu;
  604. doublereal sn;
  605. extern /* Subroutine */ int dlascl_(char *, integer *, integer *,
  606. doublereal *, doublereal *, integer *, integer *, doublereal *,
  607. integer *, integer *), dlasdq_(char *, integer *, integer
  608. *, integer *, integer *, integer *, doublereal *, doublereal *,
  609. doublereal *, integer *, doublereal *, integer *, doublereal *,
  610. integer *, doublereal *, integer *), dlaset_(char *,
  611. integer *, integer *, doublereal *, doublereal *, doublereal *,
  612. integer *), dlartg_(doublereal *, doublereal *,
  613. doublereal *, doublereal *, doublereal *);
  614. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  615. integer *, integer *, ftnlen, ftnlen);
  616. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  617. integer givcol;
  618. extern doublereal dlanst_(char *, integer *, doublereal *, doublereal *);
  619. integer icompq;
  620. doublereal orgnrm;
  621. integer givnum, givptr, nm1, qstart, smlsiz, wstart, smlszp;
  622. doublereal eps;
  623. integer ivt;
  624. /* -- LAPACK computational routine (version 3.7.1) -- */
  625. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  626. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  627. /* June 2016 */
  628. /* ===================================================================== */
  629. /* Changed dimension statement in comment describing E from (N) to */
  630. /* (N-1). Sven, 17 Feb 05. */
  631. /* ===================================================================== */
  632. /* Test the input parameters. */
  633. /* Parameter adjustments */
  634. --d__;
  635. --e;
  636. u_dim1 = *ldu;
  637. u_offset = 1 + u_dim1 * 1;
  638. u -= u_offset;
  639. vt_dim1 = *ldvt;
  640. vt_offset = 1 + vt_dim1 * 1;
  641. vt -= vt_offset;
  642. --q;
  643. --iq;
  644. --work;
  645. --iwork;
  646. /* Function Body */
  647. *info = 0;
  648. iuplo = 0;
  649. if (lsame_(uplo, "U")) {
  650. iuplo = 1;
  651. }
  652. if (lsame_(uplo, "L")) {
  653. iuplo = 2;
  654. }
  655. if (lsame_(compq, "N")) {
  656. icompq = 0;
  657. } else if (lsame_(compq, "P")) {
  658. icompq = 1;
  659. } else if (lsame_(compq, "I")) {
  660. icompq = 2;
  661. } else {
  662. icompq = -1;
  663. }
  664. if (iuplo == 0) {
  665. *info = -1;
  666. } else if (icompq < 0) {
  667. *info = -2;
  668. } else if (*n < 0) {
  669. *info = -3;
  670. } else if (*ldu < 1 || icompq == 2 && *ldu < *n) {
  671. *info = -7;
  672. } else if (*ldvt < 1 || icompq == 2 && *ldvt < *n) {
  673. *info = -9;
  674. }
  675. if (*info != 0) {
  676. i__1 = -(*info);
  677. xerbla_("DBDSDC", &i__1, (ftnlen)6);
  678. return 0;
  679. }
  680. /* Quick return if possible */
  681. if (*n == 0) {
  682. return 0;
  683. }
  684. smlsiz = ilaenv_(&c__9, "DBDSDC", " ", &c__0, &c__0, &c__0, &c__0, (
  685. ftnlen)6, (ftnlen)1);
  686. if (*n == 1) {
  687. if (icompq == 1) {
  688. q[1] = d_sign(&c_b15, &d__[1]);
  689. q[smlsiz * *n + 1] = 1.;
  690. } else if (icompq == 2) {
  691. u[u_dim1 + 1] = d_sign(&c_b15, &d__[1]);
  692. vt[vt_dim1 + 1] = 1.;
  693. }
  694. d__[1] = abs(d__[1]);
  695. return 0;
  696. }
  697. nm1 = *n - 1;
  698. /* If matrix lower bidiagonal, rotate to be upper bidiagonal */
  699. /* by applying Givens rotations on the left */
  700. wstart = 1;
  701. qstart = 3;
  702. if (icompq == 1) {
  703. dcopy_(n, &d__[1], &c__1, &q[1], &c__1);
  704. i__1 = *n - 1;
  705. dcopy_(&i__1, &e[1], &c__1, &q[*n + 1], &c__1);
  706. }
  707. if (iuplo == 2) {
  708. qstart = 5;
  709. if (icompq == 2) {
  710. wstart = (*n << 1) - 1;
  711. }
  712. i__1 = *n - 1;
  713. for (i__ = 1; i__ <= i__1; ++i__) {
  714. dlartg_(&d__[i__], &e[i__], &cs, &sn, &r__);
  715. d__[i__] = r__;
  716. e[i__] = sn * d__[i__ + 1];
  717. d__[i__ + 1] = cs * d__[i__ + 1];
  718. if (icompq == 1) {
  719. q[i__ + (*n << 1)] = cs;
  720. q[i__ + *n * 3] = sn;
  721. } else if (icompq == 2) {
  722. work[i__] = cs;
  723. work[nm1 + i__] = -sn;
  724. }
  725. /* L10: */
  726. }
  727. }
  728. /* If ICOMPQ = 0, use DLASDQ to compute the singular values. */
  729. if (icompq == 0) {
  730. /* Ignore WSTART, instead using WORK( 1 ), since the two vectors */
  731. /* for CS and -SN above are added only if ICOMPQ == 2, */
  732. /* and adding them exceeds documented WORK size of 4*n. */
  733. dlasdq_("U", &c__0, n, &c__0, &c__0, &c__0, &d__[1], &e[1], &vt[
  734. vt_offset], ldvt, &u[u_offset], ldu, &u[u_offset], ldu, &work[
  735. 1], info);
  736. goto L40;
  737. }
  738. /* If N is smaller than the minimum divide size SMLSIZ, then solve */
  739. /* the problem with another solver. */
  740. if (*n <= smlsiz) {
  741. if (icompq == 2) {
  742. dlaset_("A", n, n, &c_b29, &c_b15, &u[u_offset], ldu);
  743. dlaset_("A", n, n, &c_b29, &c_b15, &vt[vt_offset], ldvt);
  744. dlasdq_("U", &c__0, n, n, n, &c__0, &d__[1], &e[1], &vt[vt_offset]
  745. , ldvt, &u[u_offset], ldu, &u[u_offset], ldu, &work[
  746. wstart], info);
  747. } else if (icompq == 1) {
  748. iu = 1;
  749. ivt = iu + *n;
  750. dlaset_("A", n, n, &c_b29, &c_b15, &q[iu + (qstart - 1) * *n], n);
  751. dlaset_("A", n, n, &c_b29, &c_b15, &q[ivt + (qstart - 1) * *n], n);
  752. dlasdq_("U", &c__0, n, n, n, &c__0, &d__[1], &e[1], &q[ivt + (
  753. qstart - 1) * *n], n, &q[iu + (qstart - 1) * *n], n, &q[
  754. iu + (qstart - 1) * *n], n, &work[wstart], info);
  755. }
  756. goto L40;
  757. }
  758. if (icompq == 2) {
  759. dlaset_("A", n, n, &c_b29, &c_b15, &u[u_offset], ldu);
  760. dlaset_("A", n, n, &c_b29, &c_b15, &vt[vt_offset], ldvt);
  761. }
  762. /* Scale. */
  763. orgnrm = dlanst_("M", n, &d__[1], &e[1]);
  764. if (orgnrm == 0.) {
  765. return 0;
  766. }
  767. dlascl_("G", &c__0, &c__0, &orgnrm, &c_b15, n, &c__1, &d__[1], n, &ierr);
  768. dlascl_("G", &c__0, &c__0, &orgnrm, &c_b15, &nm1, &c__1, &e[1], &nm1, &
  769. ierr);
  770. eps = dlamch_("Epsilon") * .9;
  771. mlvl = (integer) (log((doublereal) (*n) / (doublereal) (smlsiz + 1)) /
  772. log(2.)) + 1;
  773. smlszp = smlsiz + 1;
  774. if (icompq == 1) {
  775. iu = 1;
  776. ivt = smlsiz + 1;
  777. difl = ivt + smlszp;
  778. difr = difl + mlvl;
  779. z__ = difr + (mlvl << 1);
  780. ic = z__ + mlvl;
  781. is = ic + 1;
  782. poles = is + 1;
  783. givnum = poles + (mlvl << 1);
  784. k = 1;
  785. givptr = 2;
  786. perm = 3;
  787. givcol = perm + mlvl;
  788. }
  789. i__1 = *n;
  790. for (i__ = 1; i__ <= i__1; ++i__) {
  791. if ((d__1 = d__[i__], abs(d__1)) < eps) {
  792. d__[i__] = d_sign(&eps, &d__[i__]);
  793. }
  794. /* L20: */
  795. }
  796. start = 1;
  797. sqre = 0;
  798. i__1 = nm1;
  799. for (i__ = 1; i__ <= i__1; ++i__) {
  800. if ((d__1 = e[i__], abs(d__1)) < eps || i__ == nm1) {
  801. /* Subproblem found. First determine its size and then */
  802. /* apply divide and conquer on it. */
  803. if (i__ < nm1) {
  804. /* A subproblem with E(I) small for I < NM1. */
  805. nsize = i__ - start + 1;
  806. } else if ((d__1 = e[i__], abs(d__1)) >= eps) {
  807. /* A subproblem with E(NM1) not too small but I = NM1. */
  808. nsize = *n - start + 1;
  809. } else {
  810. /* A subproblem with E(NM1) small. This implies an */
  811. /* 1-by-1 subproblem at D(N). Solve this 1-by-1 problem */
  812. /* first. */
  813. nsize = i__ - start + 1;
  814. if (icompq == 2) {
  815. u[*n + *n * u_dim1] = d_sign(&c_b15, &d__[*n]);
  816. vt[*n + *n * vt_dim1] = 1.;
  817. } else if (icompq == 1) {
  818. q[*n + (qstart - 1) * *n] = d_sign(&c_b15, &d__[*n]);
  819. q[*n + (smlsiz + qstart - 1) * *n] = 1.;
  820. }
  821. d__[*n] = (d__1 = d__[*n], abs(d__1));
  822. }
  823. if (icompq == 2) {
  824. dlasd0_(&nsize, &sqre, &d__[start], &e[start], &u[start +
  825. start * u_dim1], ldu, &vt[start + start * vt_dim1],
  826. ldvt, &smlsiz, &iwork[1], &work[wstart], info);
  827. } else {
  828. dlasda_(&icompq, &smlsiz, &nsize, &sqre, &d__[start], &e[
  829. start], &q[start + (iu + qstart - 2) * *n], n, &q[
  830. start + (ivt + qstart - 2) * *n], &iq[start + k * *n],
  831. &q[start + (difl + qstart - 2) * *n], &q[start + (
  832. difr + qstart - 2) * *n], &q[start + (z__ + qstart -
  833. 2) * *n], &q[start + (poles + qstart - 2) * *n], &iq[
  834. start + givptr * *n], &iq[start + givcol * *n], n, &
  835. iq[start + perm * *n], &q[start + (givnum + qstart -
  836. 2) * *n], &q[start + (ic + qstart - 2) * *n], &q[
  837. start + (is + qstart - 2) * *n], &work[wstart], &
  838. iwork[1], info);
  839. }
  840. if (*info != 0) {
  841. return 0;
  842. }
  843. start = i__ + 1;
  844. }
  845. /* L30: */
  846. }
  847. /* Unscale */
  848. dlascl_("G", &c__0, &c__0, &c_b15, &orgnrm, n, &c__1, &d__[1], n, &ierr);
  849. L40:
  850. /* Use Selection Sort to minimize swaps of singular vectors */
  851. i__1 = *n;
  852. for (ii = 2; ii <= i__1; ++ii) {
  853. i__ = ii - 1;
  854. kk = i__;
  855. p = d__[i__];
  856. i__2 = *n;
  857. for (j = ii; j <= i__2; ++j) {
  858. if (d__[j] > p) {
  859. kk = j;
  860. p = d__[j];
  861. }
  862. /* L50: */
  863. }
  864. if (kk != i__) {
  865. d__[kk] = d__[i__];
  866. d__[i__] = p;
  867. if (icompq == 1) {
  868. iq[i__] = kk;
  869. } else if (icompq == 2) {
  870. dswap_(n, &u[i__ * u_dim1 + 1], &c__1, &u[kk * u_dim1 + 1], &
  871. c__1);
  872. dswap_(n, &vt[i__ + vt_dim1], ldvt, &vt[kk + vt_dim1], ldvt);
  873. }
  874. } else if (icompq == 1) {
  875. iq[i__] = i__;
  876. }
  877. /* L60: */
  878. }
  879. /* If ICOMPQ = 1, use IQ(N,1) as the indicator for UPLO */
  880. if (icompq == 1) {
  881. if (iuplo == 1) {
  882. iq[*n] = 1;
  883. } else {
  884. iq[*n] = 0;
  885. }
  886. }
  887. /* If B is lower bidiagonal, update U by those Givens rotations */
  888. /* which rotated B to be upper bidiagonal */
  889. if (iuplo == 2 && icompq == 2) {
  890. dlasr_("L", "V", "B", n, n, &work[1], &work[*n], &u[u_offset], ldu);
  891. }
  892. return 0;
  893. /* End of DBDSDC */
  894. } /* dbdsdc_ */