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.

dlasda.c 31 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992
  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__0 = 0;
  381. static doublereal c_b11 = 0.;
  382. static doublereal c_b12 = 1.;
  383. static integer c__1 = 1;
  384. static integer c__2 = 2;
  385. /* > \brief \b DLASDA computes the singular value decomposition (SVD) of a real upper bidiagonal matrix with d
  386. iagonal d and off-diagonal e. Used by sbdsdc. */
  387. /* =========== DOCUMENTATION =========== */
  388. /* Online html documentation available at */
  389. /* http://www.netlib.org/lapack/explore-html/ */
  390. /* > \htmlonly */
  391. /* > Download DLASDA + dependencies */
  392. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlasda.
  393. f"> */
  394. /* > [TGZ]</a> */
  395. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlasda.
  396. f"> */
  397. /* > [ZIP]</a> */
  398. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlasda.
  399. f"> */
  400. /* > [TXT]</a> */
  401. /* > \endhtmlonly */
  402. /* Definition: */
  403. /* =========== */
  404. /* SUBROUTINE DLASDA( ICOMPQ, SMLSIZ, N, SQRE, D, E, U, LDU, VT, K, */
  405. /* DIFL, DIFR, Z, POLES, GIVPTR, GIVCOL, LDGCOL, */
  406. /* PERM, GIVNUM, C, S, WORK, IWORK, INFO ) */
  407. /* INTEGER ICOMPQ, INFO, LDGCOL, LDU, N, SMLSIZ, SQRE */
  408. /* INTEGER GIVCOL( LDGCOL, * ), GIVPTR( * ), IWORK( * ), */
  409. /* $ K( * ), PERM( LDGCOL, * ) */
  410. /* DOUBLE PRECISION C( * ), D( * ), DIFL( LDU, * ), DIFR( LDU, * ), */
  411. /* $ E( * ), GIVNUM( LDU, * ), POLES( LDU, * ), */
  412. /* $ S( * ), U( LDU, * ), VT( LDU, * ), WORK( * ), */
  413. /* $ Z( LDU, * ) */
  414. /* > \par Purpose: */
  415. /* ============= */
  416. /* > */
  417. /* > \verbatim */
  418. /* > */
  419. /* > Using a divide and conquer approach, DLASDA computes the singular */
  420. /* > value decomposition (SVD) of a real upper bidiagonal N-by-M matrix */
  421. /* > B with diagonal D and offdiagonal E, where M = N + SQRE. The */
  422. /* > algorithm computes the singular values in the SVD B = U * S * VT. */
  423. /* > The orthogonal matrices U and VT are optionally computed in */
  424. /* > compact form. */
  425. /* > */
  426. /* > A related subroutine, DLASD0, computes the singular values and */
  427. /* > the singular vectors in explicit form. */
  428. /* > \endverbatim */
  429. /* Arguments: */
  430. /* ========== */
  431. /* > \param[in] ICOMPQ */
  432. /* > \verbatim */
  433. /* > ICOMPQ is INTEGER */
  434. /* > Specifies whether singular vectors are to be computed */
  435. /* > in compact form, as follows */
  436. /* > = 0: Compute singular values only. */
  437. /* > = 1: Compute singular vectors of upper bidiagonal */
  438. /* > matrix in compact form. */
  439. /* > \endverbatim */
  440. /* > */
  441. /* > \param[in] SMLSIZ */
  442. /* > \verbatim */
  443. /* > SMLSIZ is INTEGER */
  444. /* > The maximum size of the subproblems at the bottom of the */
  445. /* > computation tree. */
  446. /* > \endverbatim */
  447. /* > */
  448. /* > \param[in] N */
  449. /* > \verbatim */
  450. /* > N is INTEGER */
  451. /* > The row dimension of the upper bidiagonal matrix. This is */
  452. /* > also the dimension of the main diagonal array D. */
  453. /* > \endverbatim */
  454. /* > */
  455. /* > \param[in] SQRE */
  456. /* > \verbatim */
  457. /* > SQRE is INTEGER */
  458. /* > Specifies the column dimension of the bidiagonal matrix. */
  459. /* > = 0: The bidiagonal matrix has column dimension M = N; */
  460. /* > = 1: The bidiagonal matrix has column dimension M = N + 1. */
  461. /* > \endverbatim */
  462. /* > */
  463. /* > \param[in,out] D */
  464. /* > \verbatim */
  465. /* > D is DOUBLE PRECISION array, dimension ( N ) */
  466. /* > On entry D contains the main diagonal of the bidiagonal */
  467. /* > matrix. On exit D, if INFO = 0, contains its singular values. */
  468. /* > \endverbatim */
  469. /* > */
  470. /* > \param[in] E */
  471. /* > \verbatim */
  472. /* > E is DOUBLE PRECISION array, dimension ( M-1 ) */
  473. /* > Contains the subdiagonal entries of the bidiagonal matrix. */
  474. /* > On exit, E has been destroyed. */
  475. /* > \endverbatim */
  476. /* > */
  477. /* > \param[out] U */
  478. /* > \verbatim */
  479. /* > U is DOUBLE PRECISION array, */
  480. /* > dimension ( LDU, SMLSIZ ) if ICOMPQ = 1, and not referenced */
  481. /* > if ICOMPQ = 0. If ICOMPQ = 1, on exit, U contains the left */
  482. /* > singular vector matrices of all subproblems at the bottom */
  483. /* > level. */
  484. /* > \endverbatim */
  485. /* > */
  486. /* > \param[in] LDU */
  487. /* > \verbatim */
  488. /* > LDU is INTEGER, LDU = > N. */
  489. /* > The leading dimension of arrays U, VT, DIFL, DIFR, POLES, */
  490. /* > GIVNUM, and Z. */
  491. /* > \endverbatim */
  492. /* > */
  493. /* > \param[out] VT */
  494. /* > \verbatim */
  495. /* > VT is DOUBLE PRECISION array, */
  496. /* > dimension ( LDU, SMLSIZ+1 ) if ICOMPQ = 1, and not referenced */
  497. /* > if ICOMPQ = 0. If ICOMPQ = 1, on exit, VT**T contains the right */
  498. /* > singular vector matrices of all subproblems at the bottom */
  499. /* > level. */
  500. /* > \endverbatim */
  501. /* > */
  502. /* > \param[out] K */
  503. /* > \verbatim */
  504. /* > K is INTEGER array, */
  505. /* > dimension ( N ) if ICOMPQ = 1 and dimension 1 if ICOMPQ = 0. */
  506. /* > If ICOMPQ = 1, on exit, K(I) is the dimension of the I-th */
  507. /* > secular equation on the computation tree. */
  508. /* > \endverbatim */
  509. /* > */
  510. /* > \param[out] DIFL */
  511. /* > \verbatim */
  512. /* > DIFL is DOUBLE PRECISION array, dimension ( LDU, NLVL ), */
  513. /* > where NLVL = floor(log_2 (N/SMLSIZ))). */
  514. /* > \endverbatim */
  515. /* > */
  516. /* > \param[out] DIFR */
  517. /* > \verbatim */
  518. /* > DIFR is DOUBLE PRECISION array, */
  519. /* > dimension ( LDU, 2 * NLVL ) if ICOMPQ = 1 and */
  520. /* > dimension ( N ) if ICOMPQ = 0. */
  521. /* > If ICOMPQ = 1, on exit, DIFL(1:N, I) and DIFR(1:N, 2 * I - 1) */
  522. /* > record distances between singular values on the I-th */
  523. /* > level and singular values on the (I -1)-th level, and */
  524. /* > DIFR(1:N, 2 * I ) contains the normalizing factors for */
  525. /* > the right singular vector matrix. See DLASD8 for details. */
  526. /* > \endverbatim */
  527. /* > */
  528. /* > \param[out] Z */
  529. /* > \verbatim */
  530. /* > Z is DOUBLE PRECISION array, */
  531. /* > dimension ( LDU, NLVL ) if ICOMPQ = 1 and */
  532. /* > dimension ( N ) if ICOMPQ = 0. */
  533. /* > The first K elements of Z(1, I) contain the components of */
  534. /* > the deflation-adjusted updating row vector for subproblems */
  535. /* > on the I-th level. */
  536. /* > \endverbatim */
  537. /* > */
  538. /* > \param[out] POLES */
  539. /* > \verbatim */
  540. /* > POLES is DOUBLE PRECISION array, */
  541. /* > dimension ( LDU, 2 * NLVL ) if ICOMPQ = 1, and not referenced */
  542. /* > if ICOMPQ = 0. If ICOMPQ = 1, on exit, POLES(1, 2*I - 1) and */
  543. /* > POLES(1, 2*I) contain the new and old singular values */
  544. /* > involved in the secular equations on the I-th level. */
  545. /* > \endverbatim */
  546. /* > */
  547. /* > \param[out] GIVPTR */
  548. /* > \verbatim */
  549. /* > GIVPTR is INTEGER array, */
  550. /* > dimension ( N ) if ICOMPQ = 1, and not referenced if */
  551. /* > ICOMPQ = 0. If ICOMPQ = 1, on exit, GIVPTR( I ) records */
  552. /* > the number of Givens rotations performed on the I-th */
  553. /* > problem on the computation tree. */
  554. /* > \endverbatim */
  555. /* > */
  556. /* > \param[out] GIVCOL */
  557. /* > \verbatim */
  558. /* > GIVCOL is INTEGER array, */
  559. /* > dimension ( LDGCOL, 2 * NLVL ) if ICOMPQ = 1, and not */
  560. /* > referenced if ICOMPQ = 0. If ICOMPQ = 1, on exit, for each I, */
  561. /* > GIVCOL(1, 2 *I - 1) and GIVCOL(1, 2 *I) record the locations */
  562. /* > of Givens rotations performed on the I-th level on the */
  563. /* > computation tree. */
  564. /* > \endverbatim */
  565. /* > */
  566. /* > \param[in] LDGCOL */
  567. /* > \verbatim */
  568. /* > LDGCOL is INTEGER, LDGCOL = > N. */
  569. /* > The leading dimension of arrays GIVCOL and PERM. */
  570. /* > \endverbatim */
  571. /* > */
  572. /* > \param[out] PERM */
  573. /* > \verbatim */
  574. /* > PERM is INTEGER array, */
  575. /* > dimension ( LDGCOL, NLVL ) if ICOMPQ = 1, and not referenced */
  576. /* > if ICOMPQ = 0. If ICOMPQ = 1, on exit, PERM(1, I) records */
  577. /* > permutations done on the I-th level of the computation tree. */
  578. /* > \endverbatim */
  579. /* > */
  580. /* > \param[out] GIVNUM */
  581. /* > \verbatim */
  582. /* > GIVNUM is DOUBLE PRECISION array, */
  583. /* > dimension ( LDU, 2 * NLVL ) if ICOMPQ = 1, and not */
  584. /* > referenced if ICOMPQ = 0. If ICOMPQ = 1, on exit, for each I, */
  585. /* > GIVNUM(1, 2 *I - 1) and GIVNUM(1, 2 *I) record the C- and S- */
  586. /* > values of Givens rotations performed on the I-th level on */
  587. /* > the computation tree. */
  588. /* > \endverbatim */
  589. /* > */
  590. /* > \param[out] C */
  591. /* > \verbatim */
  592. /* > C is DOUBLE PRECISION array, */
  593. /* > dimension ( N ) if ICOMPQ = 1, and dimension 1 if ICOMPQ = 0. */
  594. /* > If ICOMPQ = 1 and the I-th subproblem is not square, on exit, */
  595. /* > C( I ) contains the C-value of a Givens rotation related to */
  596. /* > the right null space of the I-th subproblem. */
  597. /* > \endverbatim */
  598. /* > */
  599. /* > \param[out] S */
  600. /* > \verbatim */
  601. /* > S is DOUBLE PRECISION array, dimension ( N ) if */
  602. /* > ICOMPQ = 1, and dimension 1 if ICOMPQ = 0. If ICOMPQ = 1 */
  603. /* > and the I-th subproblem is not square, on exit, S( I ) */
  604. /* > contains the S-value of a Givens rotation related to */
  605. /* > the right null space of the I-th subproblem. */
  606. /* > \endverbatim */
  607. /* > */
  608. /* > \param[out] WORK */
  609. /* > \verbatim */
  610. /* > WORK is DOUBLE PRECISION array, dimension */
  611. /* > (6 * N + (SMLSIZ + 1)*(SMLSIZ + 1)). */
  612. /* > \endverbatim */
  613. /* > */
  614. /* > \param[out] IWORK */
  615. /* > \verbatim */
  616. /* > IWORK is INTEGER array, dimension (7*N) */
  617. /* > \endverbatim */
  618. /* > */
  619. /* > \param[out] INFO */
  620. /* > \verbatim */
  621. /* > INFO is INTEGER */
  622. /* > = 0: successful exit. */
  623. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  624. /* > > 0: if INFO = 1, a singular value did not converge */
  625. /* > \endverbatim */
  626. /* Authors: */
  627. /* ======== */
  628. /* > \author Univ. of Tennessee */
  629. /* > \author Univ. of California Berkeley */
  630. /* > \author Univ. of Colorado Denver */
  631. /* > \author NAG Ltd. */
  632. /* > \date June 2017 */
  633. /* > \ingroup OTHERauxiliary */
  634. /* > \par Contributors: */
  635. /* ================== */
  636. /* > */
  637. /* > Ming Gu and Huan Ren, Computer Science Division, University of */
  638. /* > California at Berkeley, USA */
  639. /* > */
  640. /* ===================================================================== */
  641. /* Subroutine */ int dlasda_(integer *icompq, integer *smlsiz, integer *n,
  642. integer *sqre, doublereal *d__, doublereal *e, doublereal *u, integer
  643. *ldu, doublereal *vt, integer *k, doublereal *difl, doublereal *difr,
  644. doublereal *z__, doublereal *poles, integer *givptr, integer *givcol,
  645. integer *ldgcol, integer *perm, doublereal *givnum, doublereal *c__,
  646. doublereal *s, doublereal *work, integer *iwork, integer *info)
  647. {
  648. /* System generated locals */
  649. integer givcol_dim1, givcol_offset, perm_dim1, perm_offset, difl_dim1,
  650. difl_offset, difr_dim1, difr_offset, givnum_dim1, givnum_offset,
  651. poles_dim1, poles_offset, u_dim1, u_offset, vt_dim1, vt_offset,
  652. z_dim1, z_offset, i__1, i__2;
  653. /* Local variables */
  654. doublereal beta;
  655. integer idxq, nlvl, i__, j, m;
  656. doublereal alpha;
  657. integer inode, ndiml, ndimr, idxqi, itemp;
  658. extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
  659. doublereal *, integer *);
  660. integer sqrei, i1;
  661. extern /* Subroutine */ int dlasd6_(integer *, integer *, integer *,
  662. integer *, doublereal *, doublereal *, doublereal *, doublereal *,
  663. doublereal *, integer *, integer *, integer *, integer *,
  664. integer *, doublereal *, integer *, doublereal *, doublereal *,
  665. doublereal *, doublereal *, integer *, doublereal *, doublereal *,
  666. doublereal *, integer *, integer *);
  667. integer ic, nwork1, lf, nd, nwork2, ll, nl, vf, nr, vl;
  668. extern /* Subroutine */ int dlasdq_(char *, integer *, integer *, integer
  669. *, integer *, integer *, doublereal *, doublereal *, doublereal *,
  670. integer *, doublereal *, integer *, doublereal *, integer *,
  671. doublereal *, integer *), dlasdt_(integer *, integer *,
  672. integer *, integer *, integer *, integer *, integer *), dlaset_(
  673. char *, integer *, integer *, doublereal *, doublereal *,
  674. doublereal *, integer *), xerbla_(char *, integer *, ftnlen);
  675. integer im1, smlszp, ncc, nlf, nrf, vfi, iwk, vli, lvl, nru, ndb1, nlp1,
  676. lvl2, nrp1;
  677. /* -- LAPACK auxiliary routine (version 3.7.1) -- */
  678. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  679. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  680. /* June 2017 */
  681. /* ===================================================================== */
  682. /* Test the input parameters. */
  683. /* Parameter adjustments */
  684. --d__;
  685. --e;
  686. givnum_dim1 = *ldu;
  687. givnum_offset = 1 + givnum_dim1 * 1;
  688. givnum -= givnum_offset;
  689. poles_dim1 = *ldu;
  690. poles_offset = 1 + poles_dim1 * 1;
  691. poles -= poles_offset;
  692. z_dim1 = *ldu;
  693. z_offset = 1 + z_dim1 * 1;
  694. z__ -= z_offset;
  695. difr_dim1 = *ldu;
  696. difr_offset = 1 + difr_dim1 * 1;
  697. difr -= difr_offset;
  698. difl_dim1 = *ldu;
  699. difl_offset = 1 + difl_dim1 * 1;
  700. difl -= difl_offset;
  701. vt_dim1 = *ldu;
  702. vt_offset = 1 + vt_dim1 * 1;
  703. vt -= vt_offset;
  704. u_dim1 = *ldu;
  705. u_offset = 1 + u_dim1 * 1;
  706. u -= u_offset;
  707. --k;
  708. --givptr;
  709. perm_dim1 = *ldgcol;
  710. perm_offset = 1 + perm_dim1 * 1;
  711. perm -= perm_offset;
  712. givcol_dim1 = *ldgcol;
  713. givcol_offset = 1 + givcol_dim1 * 1;
  714. givcol -= givcol_offset;
  715. --c__;
  716. --s;
  717. --work;
  718. --iwork;
  719. /* Function Body */
  720. *info = 0;
  721. if (*icompq < 0 || *icompq > 1) {
  722. *info = -1;
  723. } else if (*smlsiz < 3) {
  724. *info = -2;
  725. } else if (*n < 0) {
  726. *info = -3;
  727. } else if (*sqre < 0 || *sqre > 1) {
  728. *info = -4;
  729. } else if (*ldu < *n + *sqre) {
  730. *info = -8;
  731. } else if (*ldgcol < *n) {
  732. *info = -17;
  733. }
  734. if (*info != 0) {
  735. i__1 = -(*info);
  736. xerbla_("DLASDA", &i__1, (ftnlen)6);
  737. return 0;
  738. }
  739. m = *n + *sqre;
  740. /* If the input matrix is too small, call DLASDQ to find the SVD. */
  741. if (*n <= *smlsiz) {
  742. if (*icompq == 0) {
  743. dlasdq_("U", sqre, n, &c__0, &c__0, &c__0, &d__[1], &e[1], &vt[
  744. vt_offset], ldu, &u[u_offset], ldu, &u[u_offset], ldu, &
  745. work[1], info);
  746. } else {
  747. dlasdq_("U", sqre, n, &m, n, &c__0, &d__[1], &e[1], &vt[vt_offset]
  748. , ldu, &u[u_offset], ldu, &u[u_offset], ldu, &work[1],
  749. info);
  750. }
  751. return 0;
  752. }
  753. /* Book-keeping and set up the computation tree. */
  754. inode = 1;
  755. ndiml = inode + *n;
  756. ndimr = ndiml + *n;
  757. idxq = ndimr + *n;
  758. iwk = idxq + *n;
  759. ncc = 0;
  760. nru = 0;
  761. smlszp = *smlsiz + 1;
  762. vf = 1;
  763. vl = vf + m;
  764. nwork1 = vl + m;
  765. nwork2 = nwork1 + smlszp * smlszp;
  766. dlasdt_(n, &nlvl, &nd, &iwork[inode], &iwork[ndiml], &iwork[ndimr],
  767. smlsiz);
  768. /* for the nodes on bottom level of the tree, solve */
  769. /* their subproblems by DLASDQ. */
  770. ndb1 = (nd + 1) / 2;
  771. i__1 = nd;
  772. for (i__ = ndb1; i__ <= i__1; ++i__) {
  773. /* IC : center row of each node */
  774. /* NL : number of rows of left subproblem */
  775. /* NR : number of rows of right subproblem */
  776. /* NLF: starting row of the left subproblem */
  777. /* NRF: starting row of the right subproblem */
  778. i1 = i__ - 1;
  779. ic = iwork[inode + i1];
  780. nl = iwork[ndiml + i1];
  781. nlp1 = nl + 1;
  782. nr = iwork[ndimr + i1];
  783. nlf = ic - nl;
  784. nrf = ic + 1;
  785. idxqi = idxq + nlf - 2;
  786. vfi = vf + nlf - 1;
  787. vli = vl + nlf - 1;
  788. sqrei = 1;
  789. if (*icompq == 0) {
  790. dlaset_("A", &nlp1, &nlp1, &c_b11, &c_b12, &work[nwork1], &smlszp);
  791. dlasdq_("U", &sqrei, &nl, &nlp1, &nru, &ncc, &d__[nlf], &e[nlf], &
  792. work[nwork1], &smlszp, &work[nwork2], &nl, &work[nwork2],
  793. &nl, &work[nwork2], info);
  794. itemp = nwork1 + nl * smlszp;
  795. dcopy_(&nlp1, &work[nwork1], &c__1, &work[vfi], &c__1);
  796. dcopy_(&nlp1, &work[itemp], &c__1, &work[vli], &c__1);
  797. } else {
  798. dlaset_("A", &nl, &nl, &c_b11, &c_b12, &u[nlf + u_dim1], ldu);
  799. dlaset_("A", &nlp1, &nlp1, &c_b11, &c_b12, &vt[nlf + vt_dim1],
  800. ldu);
  801. dlasdq_("U", &sqrei, &nl, &nlp1, &nl, &ncc, &d__[nlf], &e[nlf], &
  802. vt[nlf + vt_dim1], ldu, &u[nlf + u_dim1], ldu, &u[nlf +
  803. u_dim1], ldu, &work[nwork1], info);
  804. dcopy_(&nlp1, &vt[nlf + vt_dim1], &c__1, &work[vfi], &c__1);
  805. dcopy_(&nlp1, &vt[nlf + nlp1 * vt_dim1], &c__1, &work[vli], &c__1)
  806. ;
  807. }
  808. if (*info != 0) {
  809. return 0;
  810. }
  811. i__2 = nl;
  812. for (j = 1; j <= i__2; ++j) {
  813. iwork[idxqi + j] = j;
  814. /* L10: */
  815. }
  816. if (i__ == nd && *sqre == 0) {
  817. sqrei = 0;
  818. } else {
  819. sqrei = 1;
  820. }
  821. idxqi += nlp1;
  822. vfi += nlp1;
  823. vli += nlp1;
  824. nrp1 = nr + sqrei;
  825. if (*icompq == 0) {
  826. dlaset_("A", &nrp1, &nrp1, &c_b11, &c_b12, &work[nwork1], &smlszp);
  827. dlasdq_("U", &sqrei, &nr, &nrp1, &nru, &ncc, &d__[nrf], &e[nrf], &
  828. work[nwork1], &smlszp, &work[nwork2], &nr, &work[nwork2],
  829. &nr, &work[nwork2], info);
  830. itemp = nwork1 + (nrp1 - 1) * smlszp;
  831. dcopy_(&nrp1, &work[nwork1], &c__1, &work[vfi], &c__1);
  832. dcopy_(&nrp1, &work[itemp], &c__1, &work[vli], &c__1);
  833. } else {
  834. dlaset_("A", &nr, &nr, &c_b11, &c_b12, &u[nrf + u_dim1], ldu);
  835. dlaset_("A", &nrp1, &nrp1, &c_b11, &c_b12, &vt[nrf + vt_dim1],
  836. ldu);
  837. dlasdq_("U", &sqrei, &nr, &nrp1, &nr, &ncc, &d__[nrf], &e[nrf], &
  838. vt[nrf + vt_dim1], ldu, &u[nrf + u_dim1], ldu, &u[nrf +
  839. u_dim1], ldu, &work[nwork1], info);
  840. dcopy_(&nrp1, &vt[nrf + vt_dim1], &c__1, &work[vfi], &c__1);
  841. dcopy_(&nrp1, &vt[nrf + nrp1 * vt_dim1], &c__1, &work[vli], &c__1)
  842. ;
  843. }
  844. if (*info != 0) {
  845. return 0;
  846. }
  847. i__2 = nr;
  848. for (j = 1; j <= i__2; ++j) {
  849. iwork[idxqi + j] = j;
  850. /* L20: */
  851. }
  852. /* L30: */
  853. }
  854. /* Now conquer each subproblem bottom-up. */
  855. j = pow_ii(&c__2, &nlvl);
  856. for (lvl = nlvl; lvl >= 1; --lvl) {
  857. lvl2 = (lvl << 1) - 1;
  858. /* Find the first node LF and last node LL on */
  859. /* the current level LVL. */
  860. if (lvl == 1) {
  861. lf = 1;
  862. ll = 1;
  863. } else {
  864. i__1 = lvl - 1;
  865. lf = pow_ii(&c__2, &i__1);
  866. ll = (lf << 1) - 1;
  867. }
  868. i__1 = ll;
  869. for (i__ = lf; i__ <= i__1; ++i__) {
  870. im1 = i__ - 1;
  871. ic = iwork[inode + im1];
  872. nl = iwork[ndiml + im1];
  873. nr = iwork[ndimr + im1];
  874. nlf = ic - nl;
  875. nrf = ic + 1;
  876. if (i__ == ll) {
  877. sqrei = *sqre;
  878. } else {
  879. sqrei = 1;
  880. }
  881. vfi = vf + nlf - 1;
  882. vli = vl + nlf - 1;
  883. idxqi = idxq + nlf - 1;
  884. alpha = d__[ic];
  885. beta = e[ic];
  886. if (*icompq == 0) {
  887. dlasd6_(icompq, &nl, &nr, &sqrei, &d__[nlf], &work[vfi], &
  888. work[vli], &alpha, &beta, &iwork[idxqi], &perm[
  889. perm_offset], &givptr[1], &givcol[givcol_offset],
  890. ldgcol, &givnum[givnum_offset], ldu, &poles[
  891. poles_offset], &difl[difl_offset], &difr[difr_offset],
  892. &z__[z_offset], &k[1], &c__[1], &s[1], &work[nwork1],
  893. &iwork[iwk], info);
  894. } else {
  895. --j;
  896. dlasd6_(icompq, &nl, &nr, &sqrei, &d__[nlf], &work[vfi], &
  897. work[vli], &alpha, &beta, &iwork[idxqi], &perm[nlf +
  898. lvl * perm_dim1], &givptr[j], &givcol[nlf + lvl2 *
  899. givcol_dim1], ldgcol, &givnum[nlf + lvl2 *
  900. givnum_dim1], ldu, &poles[nlf + lvl2 * poles_dim1], &
  901. difl[nlf + lvl * difl_dim1], &difr[nlf + lvl2 *
  902. difr_dim1], &z__[nlf + lvl * z_dim1], &k[j], &c__[j],
  903. &s[j], &work[nwork1], &iwork[iwk], info);
  904. }
  905. if (*info != 0) {
  906. return 0;
  907. }
  908. /* L40: */
  909. }
  910. /* L50: */
  911. }
  912. return 0;
  913. /* End of DLASDA */
  914. } /* dlasda_ */