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.

dlasd7.c 29 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033
  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__1 = 1;
  381. /* > \brief \b DLASD7 merges the two sets of singular values together into a single sorted set. Then it tries
  382. to deflate the size of the problem. Used by sbdsdc. */
  383. /* =========== DOCUMENTATION =========== */
  384. /* Online html documentation available at */
  385. /* http://www.netlib.org/lapack/explore-html/ */
  386. /* > \htmlonly */
  387. /* > Download DLASD7 + dependencies */
  388. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlasd7.
  389. f"> */
  390. /* > [TGZ]</a> */
  391. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlasd7.
  392. f"> */
  393. /* > [ZIP]</a> */
  394. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlasd7.
  395. f"> */
  396. /* > [TXT]</a> */
  397. /* > \endhtmlonly */
  398. /* Definition: */
  399. /* =========== */
  400. /* SUBROUTINE DLASD7( ICOMPQ, NL, NR, SQRE, K, D, Z, ZW, VF, VFW, VL, */
  401. /* VLW, ALPHA, BETA, DSIGMA, IDX, IDXP, IDXQ, */
  402. /* PERM, GIVPTR, GIVCOL, LDGCOL, GIVNUM, LDGNUM, */
  403. /* C, S, INFO ) */
  404. /* INTEGER GIVPTR, ICOMPQ, INFO, K, LDGCOL, LDGNUM, NL, */
  405. /* $ NR, SQRE */
  406. /* DOUBLE PRECISION ALPHA, BETA, C, S */
  407. /* INTEGER GIVCOL( LDGCOL, * ), IDX( * ), IDXP( * ), */
  408. /* $ IDXQ( * ), PERM( * ) */
  409. /* DOUBLE PRECISION D( * ), DSIGMA( * ), GIVNUM( LDGNUM, * ), */
  410. /* $ VF( * ), VFW( * ), VL( * ), VLW( * ), Z( * ), */
  411. /* $ ZW( * ) */
  412. /* > \par Purpose: */
  413. /* ============= */
  414. /* > */
  415. /* > \verbatim */
  416. /* > */
  417. /* > DLASD7 merges the two sets of singular values together into a single */
  418. /* > sorted set. Then it tries to deflate the size of the problem. There */
  419. /* > are two ways in which deflation can occur: when two or more singular */
  420. /* > values are close together or if there is a tiny entry in the Z */
  421. /* > vector. For each such occurrence the order of the related */
  422. /* > secular equation problem is reduced by one. */
  423. /* > */
  424. /* > DLASD7 is called from DLASD6. */
  425. /* > \endverbatim */
  426. /* Arguments: */
  427. /* ========== */
  428. /* > \param[in] ICOMPQ */
  429. /* > \verbatim */
  430. /* > ICOMPQ is INTEGER */
  431. /* > Specifies whether singular vectors are to be computed */
  432. /* > in compact form, as follows: */
  433. /* > = 0: Compute singular values only. */
  434. /* > = 1: Compute singular vectors of upper */
  435. /* > bidiagonal matrix in compact form. */
  436. /* > \endverbatim */
  437. /* > */
  438. /* > \param[in] NL */
  439. /* > \verbatim */
  440. /* > NL is INTEGER */
  441. /* > The row dimension of the upper block. NL >= 1. */
  442. /* > \endverbatim */
  443. /* > */
  444. /* > \param[in] NR */
  445. /* > \verbatim */
  446. /* > NR is INTEGER */
  447. /* > The row dimension of the lower block. NR >= 1. */
  448. /* > \endverbatim */
  449. /* > */
  450. /* > \param[in] SQRE */
  451. /* > \verbatim */
  452. /* > SQRE is INTEGER */
  453. /* > = 0: the lower block is an NR-by-NR square matrix. */
  454. /* > = 1: the lower block is an NR-by-(NR+1) rectangular matrix. */
  455. /* > */
  456. /* > The bidiagonal matrix has */
  457. /* > N = NL + NR + 1 rows and */
  458. /* > M = N + SQRE >= N columns. */
  459. /* > \endverbatim */
  460. /* > */
  461. /* > \param[out] K */
  462. /* > \verbatim */
  463. /* > K is INTEGER */
  464. /* > Contains the dimension of the non-deflated matrix, this is */
  465. /* > the order of the related secular equation. 1 <= K <=N. */
  466. /* > \endverbatim */
  467. /* > */
  468. /* > \param[in,out] D */
  469. /* > \verbatim */
  470. /* > D is DOUBLE PRECISION array, dimension ( N ) */
  471. /* > On entry D contains the singular values of the two submatrices */
  472. /* > to be combined. On exit D contains the trailing (N-K) updated */
  473. /* > singular values (those which were deflated) sorted into */
  474. /* > increasing order. */
  475. /* > \endverbatim */
  476. /* > */
  477. /* > \param[out] Z */
  478. /* > \verbatim */
  479. /* > Z is DOUBLE PRECISION array, dimension ( M ) */
  480. /* > On exit Z contains the updating row vector in the secular */
  481. /* > equation. */
  482. /* > \endverbatim */
  483. /* > */
  484. /* > \param[out] ZW */
  485. /* > \verbatim */
  486. /* > ZW is DOUBLE PRECISION array, dimension ( M ) */
  487. /* > Workspace for Z. */
  488. /* > \endverbatim */
  489. /* > */
  490. /* > \param[in,out] VF */
  491. /* > \verbatim */
  492. /* > VF is DOUBLE PRECISION array, dimension ( M ) */
  493. /* > On entry, VF(1:NL+1) contains the first components of all */
  494. /* > right singular vectors of the upper block; and VF(NL+2:M) */
  495. /* > contains the first components of all right singular vectors */
  496. /* > of the lower block. On exit, VF contains the first components */
  497. /* > of all right singular vectors of the bidiagonal matrix. */
  498. /* > \endverbatim */
  499. /* > */
  500. /* > \param[out] VFW */
  501. /* > \verbatim */
  502. /* > VFW is DOUBLE PRECISION array, dimension ( M ) */
  503. /* > Workspace for VF. */
  504. /* > \endverbatim */
  505. /* > */
  506. /* > \param[in,out] VL */
  507. /* > \verbatim */
  508. /* > VL is DOUBLE PRECISION array, dimension ( M ) */
  509. /* > On entry, VL(1:NL+1) contains the last components of all */
  510. /* > right singular vectors of the upper block; and VL(NL+2:M) */
  511. /* > contains the last components of all right singular vectors */
  512. /* > of the lower block. On exit, VL contains the last components */
  513. /* > of all right singular vectors of the bidiagonal matrix. */
  514. /* > \endverbatim */
  515. /* > */
  516. /* > \param[out] VLW */
  517. /* > \verbatim */
  518. /* > VLW is DOUBLE PRECISION array, dimension ( M ) */
  519. /* > Workspace for VL. */
  520. /* > \endverbatim */
  521. /* > */
  522. /* > \param[in] ALPHA */
  523. /* > \verbatim */
  524. /* > ALPHA is DOUBLE PRECISION */
  525. /* > Contains the diagonal element associated with the added row. */
  526. /* > \endverbatim */
  527. /* > */
  528. /* > \param[in] BETA */
  529. /* > \verbatim */
  530. /* > BETA is DOUBLE PRECISION */
  531. /* > Contains the off-diagonal element associated with the added */
  532. /* > row. */
  533. /* > \endverbatim */
  534. /* > */
  535. /* > \param[out] DSIGMA */
  536. /* > \verbatim */
  537. /* > DSIGMA is DOUBLE PRECISION array, dimension ( N ) */
  538. /* > Contains a copy of the diagonal elements (K-1 singular values */
  539. /* > and one zero) in the secular equation. */
  540. /* > \endverbatim */
  541. /* > */
  542. /* > \param[out] IDX */
  543. /* > \verbatim */
  544. /* > IDX is INTEGER array, dimension ( N ) */
  545. /* > This will contain the permutation used to sort the contents of */
  546. /* > D into ascending order. */
  547. /* > \endverbatim */
  548. /* > */
  549. /* > \param[out] IDXP */
  550. /* > \verbatim */
  551. /* > IDXP is INTEGER array, dimension ( N ) */
  552. /* > This will contain the permutation used to place deflated */
  553. /* > values of D at the end of the array. On output IDXP(2:K) */
  554. /* > points to the nondeflated D-values and IDXP(K+1:N) */
  555. /* > points to the deflated singular values. */
  556. /* > \endverbatim */
  557. /* > */
  558. /* > \param[in] IDXQ */
  559. /* > \verbatim */
  560. /* > IDXQ is INTEGER array, dimension ( N ) */
  561. /* > This contains the permutation which separately sorts the two */
  562. /* > sub-problems in D into ascending order. Note that entries in */
  563. /* > the first half of this permutation must first be moved one */
  564. /* > position backward; and entries in the second half */
  565. /* > must first have NL+1 added to their values. */
  566. /* > \endverbatim */
  567. /* > */
  568. /* > \param[out] PERM */
  569. /* > \verbatim */
  570. /* > PERM is INTEGER array, dimension ( N ) */
  571. /* > The permutations (from deflation and sorting) to be applied */
  572. /* > to each singular block. Not referenced if ICOMPQ = 0. */
  573. /* > \endverbatim */
  574. /* > */
  575. /* > \param[out] GIVPTR */
  576. /* > \verbatim */
  577. /* > GIVPTR is INTEGER */
  578. /* > The number of Givens rotations which took place in this */
  579. /* > subproblem. Not referenced if ICOMPQ = 0. */
  580. /* > \endverbatim */
  581. /* > */
  582. /* > \param[out] GIVCOL */
  583. /* > \verbatim */
  584. /* > GIVCOL is INTEGER array, dimension ( LDGCOL, 2 ) */
  585. /* > Each pair of numbers indicates a pair of columns to take place */
  586. /* > in a Givens rotation. Not referenced if ICOMPQ = 0. */
  587. /* > \endverbatim */
  588. /* > */
  589. /* > \param[in] LDGCOL */
  590. /* > \verbatim */
  591. /* > LDGCOL is INTEGER */
  592. /* > The leading dimension of GIVCOL, must be at least N. */
  593. /* > \endverbatim */
  594. /* > */
  595. /* > \param[out] GIVNUM */
  596. /* > \verbatim */
  597. /* > GIVNUM is DOUBLE PRECISION array, dimension ( LDGNUM, 2 ) */
  598. /* > Each number indicates the C or S value to be used in the */
  599. /* > corresponding Givens rotation. Not referenced if ICOMPQ = 0. */
  600. /* > \endverbatim */
  601. /* > */
  602. /* > \param[in] LDGNUM */
  603. /* > \verbatim */
  604. /* > LDGNUM is INTEGER */
  605. /* > The leading dimension of GIVNUM, must be at least N. */
  606. /* > \endverbatim */
  607. /* > */
  608. /* > \param[out] C */
  609. /* > \verbatim */
  610. /* > C is DOUBLE PRECISION */
  611. /* > C contains garbage if SQRE =0 and the C-value of a Givens */
  612. /* > rotation related to the right null space if SQRE = 1. */
  613. /* > \endverbatim */
  614. /* > */
  615. /* > \param[out] S */
  616. /* > \verbatim */
  617. /* > S is DOUBLE PRECISION */
  618. /* > S contains garbage if SQRE =0 and the S-value of a Givens */
  619. /* > rotation related to the right null space if SQRE = 1. */
  620. /* > \endverbatim */
  621. /* > */
  622. /* > \param[out] INFO */
  623. /* > \verbatim */
  624. /* > INFO is INTEGER */
  625. /* > = 0: successful exit. */
  626. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  627. /* > \endverbatim */
  628. /* Authors: */
  629. /* ======== */
  630. /* > \author Univ. of Tennessee */
  631. /* > \author Univ. of California Berkeley */
  632. /* > \author Univ. of Colorado Denver */
  633. /* > \author NAG Ltd. */
  634. /* > \date December 2016 */
  635. /* > \ingroup OTHERauxiliary */
  636. /* > \par Contributors: */
  637. /* ================== */
  638. /* > */
  639. /* > Ming Gu and Huan Ren, Computer Science Division, University of */
  640. /* > California at Berkeley, USA */
  641. /* > */
  642. /* ===================================================================== */
  643. /* Subroutine */ int dlasd7_(integer *icompq, integer *nl, integer *nr,
  644. integer *sqre, integer *k, doublereal *d__, doublereal *z__,
  645. doublereal *zw, doublereal *vf, doublereal *vfw, doublereal *vl,
  646. doublereal *vlw, doublereal *alpha, doublereal *beta, doublereal *
  647. dsigma, integer *idx, integer *idxp, integer *idxq, integer *perm,
  648. integer *givptr, integer *givcol, integer *ldgcol, doublereal *givnum,
  649. integer *ldgnum, doublereal *c__, doublereal *s, integer *info)
  650. {
  651. /* System generated locals */
  652. integer givcol_dim1, givcol_offset, givnum_dim1, givnum_offset, i__1;
  653. doublereal d__1, d__2;
  654. /* Local variables */
  655. integer idxi, idxj;
  656. extern /* Subroutine */ int drot_(integer *, doublereal *, integer *,
  657. doublereal *, integer *, doublereal *, doublereal *);
  658. integer i__, j, m, n, idxjp;
  659. extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
  660. doublereal *, integer *);
  661. integer jprev, k2;
  662. doublereal z1;
  663. extern doublereal dlapy2_(doublereal *, doublereal *), dlamch_(char *);
  664. integer jp;
  665. extern /* Subroutine */ int dlamrg_(integer *, integer *, doublereal *,
  666. integer *, integer *, integer *), xerbla_(char *, integer *, ftnlen);
  667. doublereal hlftol, eps, tau, tol;
  668. integer nlp1, nlp2;
  669. /* -- LAPACK auxiliary routine (version 3.7.0) -- */
  670. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  671. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  672. /* December 2016 */
  673. /* ===================================================================== */
  674. /* Test the input parameters. */
  675. /* Parameter adjustments */
  676. --d__;
  677. --z__;
  678. --zw;
  679. --vf;
  680. --vfw;
  681. --vl;
  682. --vlw;
  683. --dsigma;
  684. --idx;
  685. --idxp;
  686. --idxq;
  687. --perm;
  688. givcol_dim1 = *ldgcol;
  689. givcol_offset = 1 + givcol_dim1 * 1;
  690. givcol -= givcol_offset;
  691. givnum_dim1 = *ldgnum;
  692. givnum_offset = 1 + givnum_dim1 * 1;
  693. givnum -= givnum_offset;
  694. /* Function Body */
  695. *info = 0;
  696. n = *nl + *nr + 1;
  697. m = n + *sqre;
  698. if (*icompq < 0 || *icompq > 1) {
  699. *info = -1;
  700. } else if (*nl < 1) {
  701. *info = -2;
  702. } else if (*nr < 1) {
  703. *info = -3;
  704. } else if (*sqre < 0 || *sqre > 1) {
  705. *info = -4;
  706. } else if (*ldgcol < n) {
  707. *info = -22;
  708. } else if (*ldgnum < n) {
  709. *info = -24;
  710. }
  711. if (*info != 0) {
  712. i__1 = -(*info);
  713. xerbla_("DLASD7", &i__1, (ftnlen)6);
  714. return 0;
  715. }
  716. nlp1 = *nl + 1;
  717. nlp2 = *nl + 2;
  718. if (*icompq == 1) {
  719. *givptr = 0;
  720. }
  721. /* Generate the first part of the vector Z and move the singular */
  722. /* values in the first part of D one position backward. */
  723. z1 = *alpha * vl[nlp1];
  724. vl[nlp1] = 0.;
  725. tau = vf[nlp1];
  726. for (i__ = *nl; i__ >= 1; --i__) {
  727. z__[i__ + 1] = *alpha * vl[i__];
  728. vl[i__] = 0.;
  729. vf[i__ + 1] = vf[i__];
  730. d__[i__ + 1] = d__[i__];
  731. idxq[i__ + 1] = idxq[i__] + 1;
  732. /* L10: */
  733. }
  734. vf[1] = tau;
  735. /* Generate the second part of the vector Z. */
  736. i__1 = m;
  737. for (i__ = nlp2; i__ <= i__1; ++i__) {
  738. z__[i__] = *beta * vf[i__];
  739. vf[i__] = 0.;
  740. /* L20: */
  741. }
  742. /* Sort the singular values into increasing order */
  743. i__1 = n;
  744. for (i__ = nlp2; i__ <= i__1; ++i__) {
  745. idxq[i__] += nlp1;
  746. /* L30: */
  747. }
  748. /* DSIGMA, IDXC, IDXC, and ZW are used as storage space. */
  749. i__1 = n;
  750. for (i__ = 2; i__ <= i__1; ++i__) {
  751. dsigma[i__] = d__[idxq[i__]];
  752. zw[i__] = z__[idxq[i__]];
  753. vfw[i__] = vf[idxq[i__]];
  754. vlw[i__] = vl[idxq[i__]];
  755. /* L40: */
  756. }
  757. dlamrg_(nl, nr, &dsigma[2], &c__1, &c__1, &idx[2]);
  758. i__1 = n;
  759. for (i__ = 2; i__ <= i__1; ++i__) {
  760. idxi = idx[i__] + 1;
  761. d__[i__] = dsigma[idxi];
  762. z__[i__] = zw[idxi];
  763. vf[i__] = vfw[idxi];
  764. vl[i__] = vlw[idxi];
  765. /* L50: */
  766. }
  767. /* Calculate the allowable deflation tolerance */
  768. eps = dlamch_("Epsilon");
  769. /* Computing MAX */
  770. d__1 = abs(*alpha), d__2 = abs(*beta);
  771. tol = f2cmax(d__1,d__2);
  772. /* Computing MAX */
  773. d__2 = (d__1 = d__[n], abs(d__1));
  774. tol = eps * 64. * f2cmax(d__2,tol);
  775. /* There are 2 kinds of deflation -- first a value in the z-vector */
  776. /* is small, second two (or more) singular values are very close */
  777. /* together (their difference is small). */
  778. /* If the value in the z-vector is small, we simply permute the */
  779. /* array so that the corresponding singular value is moved to the */
  780. /* end. */
  781. /* If two values in the D-vector are close, we perform a two-sided */
  782. /* rotation designed to make one of the corresponding z-vector */
  783. /* entries zero, and then permute the array so that the deflated */
  784. /* singular value is moved to the end. */
  785. /* If there are multiple singular values then the problem deflates. */
  786. /* Here the number of equal singular values are found. As each equal */
  787. /* singular value is found, an elementary reflector is computed to */
  788. /* rotate the corresponding singular subspace so that the */
  789. /* corresponding components of Z are zero in this new basis. */
  790. *k = 1;
  791. k2 = n + 1;
  792. i__1 = n;
  793. for (j = 2; j <= i__1; ++j) {
  794. if ((d__1 = z__[j], abs(d__1)) <= tol) {
  795. /* Deflate due to small z component. */
  796. --k2;
  797. idxp[k2] = j;
  798. if (j == n) {
  799. goto L100;
  800. }
  801. } else {
  802. jprev = j;
  803. goto L70;
  804. }
  805. /* L60: */
  806. }
  807. L70:
  808. j = jprev;
  809. L80:
  810. ++j;
  811. if (j > n) {
  812. goto L90;
  813. }
  814. if ((d__1 = z__[j], abs(d__1)) <= tol) {
  815. /* Deflate due to small z component. */
  816. --k2;
  817. idxp[k2] = j;
  818. } else {
  819. /* Check if singular values are close enough to allow deflation. */
  820. if ((d__1 = d__[j] - d__[jprev], abs(d__1)) <= tol) {
  821. /* Deflation is possible. */
  822. *s = z__[jprev];
  823. *c__ = z__[j];
  824. /* Find sqrt(a**2+b**2) without overflow or */
  825. /* destructive underflow. */
  826. tau = dlapy2_(c__, s);
  827. z__[j] = tau;
  828. z__[jprev] = 0.;
  829. *c__ /= tau;
  830. *s = -(*s) / tau;
  831. /* Record the appropriate Givens rotation */
  832. if (*icompq == 1) {
  833. ++(*givptr);
  834. idxjp = idxq[idx[jprev] + 1];
  835. idxj = idxq[idx[j] + 1];
  836. if (idxjp <= nlp1) {
  837. --idxjp;
  838. }
  839. if (idxj <= nlp1) {
  840. --idxj;
  841. }
  842. givcol[*givptr + (givcol_dim1 << 1)] = idxjp;
  843. givcol[*givptr + givcol_dim1] = idxj;
  844. givnum[*givptr + (givnum_dim1 << 1)] = *c__;
  845. givnum[*givptr + givnum_dim1] = *s;
  846. }
  847. drot_(&c__1, &vf[jprev], &c__1, &vf[j], &c__1, c__, s);
  848. drot_(&c__1, &vl[jprev], &c__1, &vl[j], &c__1, c__, s);
  849. --k2;
  850. idxp[k2] = jprev;
  851. jprev = j;
  852. } else {
  853. ++(*k);
  854. zw[*k] = z__[jprev];
  855. dsigma[*k] = d__[jprev];
  856. idxp[*k] = jprev;
  857. jprev = j;
  858. }
  859. }
  860. goto L80;
  861. L90:
  862. /* Record the last singular value. */
  863. ++(*k);
  864. zw[*k] = z__[jprev];
  865. dsigma[*k] = d__[jprev];
  866. idxp[*k] = jprev;
  867. L100:
  868. /* Sort the singular values into DSIGMA. The singular values which */
  869. /* were not deflated go into the first K slots of DSIGMA, except */
  870. /* that DSIGMA(1) is treated separately. */
  871. i__1 = n;
  872. for (j = 2; j <= i__1; ++j) {
  873. jp = idxp[j];
  874. dsigma[j] = d__[jp];
  875. vfw[j] = vf[jp];
  876. vlw[j] = vl[jp];
  877. /* L110: */
  878. }
  879. if (*icompq == 1) {
  880. i__1 = n;
  881. for (j = 2; j <= i__1; ++j) {
  882. jp = idxp[j];
  883. perm[j] = idxq[idx[jp] + 1];
  884. if (perm[j] <= nlp1) {
  885. --perm[j];
  886. }
  887. /* L120: */
  888. }
  889. }
  890. /* The deflated singular values go back into the last N - K slots of */
  891. /* D. */
  892. i__1 = n - *k;
  893. dcopy_(&i__1, &dsigma[*k + 1], &c__1, &d__[*k + 1], &c__1);
  894. /* Determine DSIGMA(1), DSIGMA(2), Z(1), VF(1), VL(1), VF(M), and */
  895. /* VL(M). */
  896. dsigma[1] = 0.;
  897. hlftol = tol / 2.;
  898. if (abs(dsigma[2]) <= hlftol) {
  899. dsigma[2] = hlftol;
  900. }
  901. if (m > n) {
  902. z__[1] = dlapy2_(&z1, &z__[m]);
  903. if (z__[1] <= tol) {
  904. *c__ = 1.;
  905. *s = 0.;
  906. z__[1] = tol;
  907. } else {
  908. *c__ = z1 / z__[1];
  909. *s = -z__[m] / z__[1];
  910. }
  911. drot_(&c__1, &vf[m], &c__1, &vf[1], &c__1, c__, s);
  912. drot_(&c__1, &vl[m], &c__1, &vl[1], &c__1, c__, s);
  913. } else {
  914. if (abs(z1) <= tol) {
  915. z__[1] = tol;
  916. } else {
  917. z__[1] = z1;
  918. }
  919. }
  920. /* Restore Z, VF, and VL. */
  921. i__1 = *k - 1;
  922. dcopy_(&i__1, &zw[2], &c__1, &z__[2], &c__1);
  923. i__1 = n - 1;
  924. dcopy_(&i__1, &vfw[2], &c__1, &vf[2], &c__1);
  925. i__1 = n - 1;
  926. dcopy_(&i__1, &vlw[2], &c__1, &vl[2], &c__1);
  927. return 0;
  928. /* End of DLASD7 */
  929. } /* dlasd7_ */