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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  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. typedef int integer;
  18. typedef unsigned int uinteger;
  19. typedef char *address;
  20. typedef short int shortint;
  21. typedef float real;
  22. typedef double doublereal;
  23. typedef struct { real r, i; } complex;
  24. typedef struct { doublereal r, i; } doublecomplex;
  25. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  26. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  27. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  28. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  29. #define pCf(z) (*_pCf(z))
  30. #define pCd(z) (*_pCd(z))
  31. typedef int logical;
  32. typedef short int shortlogical;
  33. typedef char logical1;
  34. typedef char integer1;
  35. #define TRUE_ (1)
  36. #define FALSE_ (0)
  37. /* Extern is for use with -E */
  38. #ifndef Extern
  39. #define Extern extern
  40. #endif
  41. /* I/O stuff */
  42. typedef int flag;
  43. typedef int ftnlen;
  44. typedef int ftnint;
  45. /*external read, write*/
  46. typedef struct
  47. { flag cierr;
  48. ftnint ciunit;
  49. flag ciend;
  50. char *cifmt;
  51. ftnint cirec;
  52. } cilist;
  53. /*internal read, write*/
  54. typedef struct
  55. { flag icierr;
  56. char *iciunit;
  57. flag iciend;
  58. char *icifmt;
  59. ftnint icirlen;
  60. ftnint icirnum;
  61. } icilist;
  62. /*open*/
  63. typedef struct
  64. { flag oerr;
  65. ftnint ounit;
  66. char *ofnm;
  67. ftnlen ofnmlen;
  68. char *osta;
  69. char *oacc;
  70. char *ofm;
  71. ftnint orl;
  72. char *oblnk;
  73. } olist;
  74. /*close*/
  75. typedef struct
  76. { flag cerr;
  77. ftnint cunit;
  78. char *csta;
  79. } cllist;
  80. /*rewind, backspace, endfile*/
  81. typedef struct
  82. { flag aerr;
  83. ftnint aunit;
  84. } alist;
  85. /* inquire */
  86. typedef struct
  87. { flag inerr;
  88. ftnint inunit;
  89. char *infile;
  90. ftnlen infilen;
  91. ftnint *inex; /*parameters in standard's order*/
  92. ftnint *inopen;
  93. ftnint *innum;
  94. ftnint *innamed;
  95. char *inname;
  96. ftnlen innamlen;
  97. char *inacc;
  98. ftnlen inacclen;
  99. char *inseq;
  100. ftnlen inseqlen;
  101. char *indir;
  102. ftnlen indirlen;
  103. char *infmt;
  104. ftnlen infmtlen;
  105. char *inform;
  106. ftnint informlen;
  107. char *inunf;
  108. ftnlen inunflen;
  109. ftnint *inrecl;
  110. ftnint *innrec;
  111. char *inblank;
  112. ftnlen inblanklen;
  113. } inlist;
  114. #define VOID void
  115. union Multitype { /* for multiple entry points */
  116. integer1 g;
  117. shortint h;
  118. integer i;
  119. /* longint j; */
  120. real r;
  121. doublereal d;
  122. complex c;
  123. doublecomplex z;
  124. };
  125. typedef union Multitype Multitype;
  126. struct Vardesc { /* for Namelist */
  127. char *name;
  128. char *addr;
  129. ftnlen *dims;
  130. int type;
  131. };
  132. typedef struct Vardesc Vardesc;
  133. struct Namelist {
  134. char *name;
  135. Vardesc **vars;
  136. int nvars;
  137. };
  138. typedef struct Namelist Namelist;
  139. #define abs(x) ((x) >= 0 ? (x) : -(x))
  140. #define dabs(x) (fabs(x))
  141. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  142. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  143. #define dmin(a,b) (f2cmin(a,b))
  144. #define dmax(a,b) (f2cmax(a,b))
  145. #define bit_test(a,b) ((a) >> (b) & 1)
  146. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  147. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  148. #define abort_() { sig_die("Fortran abort routine called", 1); }
  149. #define c_abs(z) (cabsf(Cf(z)))
  150. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  151. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  152. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  153. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  154. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  155. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  156. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  157. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  158. #define d_abs(x) (fabs(*(x)))
  159. #define d_acos(x) (acos(*(x)))
  160. #define d_asin(x) (asin(*(x)))
  161. #define d_atan(x) (atan(*(x)))
  162. #define d_atn2(x, y) (atan2(*(x),*(y)))
  163. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  164. #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
  165. #define d_cos(x) (cos(*(x)))
  166. #define d_cosh(x) (cosh(*(x)))
  167. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  168. #define d_exp(x) (exp(*(x)))
  169. #define d_imag(z) (cimag(Cd(z)))
  170. #define r_imag(z) (cimag(Cf(z)))
  171. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  172. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  173. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  174. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  175. #define d_log(x) (log(*(x)))
  176. #define d_mod(x, y) (fmod(*(x), *(y)))
  177. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  178. #define d_nint(x) u_nint(*(x))
  179. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  180. #define d_sign(a,b) u_sign(*(a),*(b))
  181. #define r_sign(a,b) u_sign(*(a),*(b))
  182. #define d_sin(x) (sin(*(x)))
  183. #define d_sinh(x) (sinh(*(x)))
  184. #define d_sqrt(x) (sqrt(*(x)))
  185. #define d_tan(x) (tan(*(x)))
  186. #define d_tanh(x) (tanh(*(x)))
  187. #define i_abs(x) abs(*(x))
  188. #define i_dnnt(x) ((integer)u_nint(*(x)))
  189. #define i_len(s, n) (n)
  190. #define i_nint(x) ((integer)u_nint(*(x)))
  191. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  192. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  193. #define pow_si(B,E) spow_ui(*(B),*(E))
  194. #define pow_ri(B,E) spow_ui(*(B),*(E))
  195. #define pow_di(B,E) dpow_ui(*(B),*(E))
  196. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  197. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  198. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  199. #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++ = ' '; }
  200. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  201. #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]; }
  202. #define sig_die(s, kill) { exit(1); }
  203. #define s_stop(s, n) {exit(0);}
  204. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  205. #define z_abs(z) (cabs(Cd(z)))
  206. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  207. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  208. #define myexit_() break;
  209. #define mycycle() continue;
  210. #define myceiling(w) {ceil(w)}
  211. #define myhuge(w) {HUGE_VAL}
  212. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  213. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  214. /* procedure parameter types for -A and -C++ */
  215. #define F2C_proc_par_types 1
  216. #ifdef __cplusplus
  217. typedef logical (*L_fp)(...);
  218. #else
  219. typedef logical (*L_fp)();
  220. #endif
  221. static float spow_ui(float x, integer n) {
  222. float pow=1.0; unsigned long int u;
  223. if(n != 0) {
  224. if(n < 0) n = -n, x = 1/x;
  225. for(u = n; ; ) {
  226. if(u & 01) pow *= x;
  227. if(u >>= 1) x *= x;
  228. else break;
  229. }
  230. }
  231. return pow;
  232. }
  233. static double dpow_ui(double x, integer n) {
  234. double pow=1.0; unsigned long int u;
  235. if(n != 0) {
  236. if(n < 0) n = -n, x = 1/x;
  237. for(u = n; ; ) {
  238. if(u & 01) pow *= x;
  239. if(u >>= 1) x *= x;
  240. else break;
  241. }
  242. }
  243. return pow;
  244. }
  245. static _Complex float cpow_ui(_Complex float x, integer n) {
  246. _Complex float pow=1.0; unsigned long int u;
  247. if(n != 0) {
  248. if(n < 0) n = -n, x = 1/x;
  249. for(u = n; ; ) {
  250. if(u & 01) pow *= x;
  251. if(u >>= 1) x *= x;
  252. else break;
  253. }
  254. }
  255. return pow;
  256. }
  257. static _Complex double zpow_ui(_Complex double x, integer n) {
  258. _Complex double pow=1.0; unsigned long int u;
  259. if(n != 0) {
  260. if(n < 0) n = -n, x = 1/x;
  261. for(u = n; ; ) {
  262. if(u & 01) pow *= x;
  263. if(u >>= 1) x *= x;
  264. else break;
  265. }
  266. }
  267. return pow;
  268. }
  269. static integer pow_ii(integer x, integer n) {
  270. integer pow; unsigned long int u;
  271. if (n <= 0) {
  272. if (n == 0 || x == 1) pow = 1;
  273. else if (x != -1) pow = x == 0 ? 1/x : 0;
  274. else n = -n;
  275. }
  276. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  277. u = n;
  278. for(pow = 1; ; ) {
  279. if(u & 01) pow *= x;
  280. if(u >>= 1) x *= x;
  281. else break;
  282. }
  283. }
  284. return pow;
  285. }
  286. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  287. {
  288. double m; integer i, mi;
  289. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  290. if (w[i-1]>m) mi=i ,m=w[i-1];
  291. return mi-s+1;
  292. }
  293. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  294. {
  295. float m; integer i, mi;
  296. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  297. if (w[i-1]>m) mi=i ,m=w[i-1];
  298. return mi-s+1;
  299. }
  300. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  301. integer n = *n_, incx = *incx_, incy = *incy_, i;
  302. _Complex float zdotc = 0.0;
  303. if (incx == 1 && incy == 1) {
  304. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  305. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  306. }
  307. } else {
  308. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  309. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  310. }
  311. }
  312. pCf(z) = zdotc;
  313. }
  314. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  315. integer n = *n_, incx = *incx_, incy = *incy_, i;
  316. _Complex double zdotc = 0.0;
  317. if (incx == 1 && incy == 1) {
  318. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  319. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  320. }
  321. } else {
  322. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  323. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  324. }
  325. }
  326. pCd(z) = zdotc;
  327. }
  328. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  329. integer n = *n_, incx = *incx_, incy = *incy_, i;
  330. _Complex float zdotc = 0.0;
  331. if (incx == 1 && incy == 1) {
  332. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  333. zdotc += Cf(&x[i]) * Cf(&y[i]);
  334. }
  335. } else {
  336. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  337. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  338. }
  339. }
  340. pCf(z) = zdotc;
  341. }
  342. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  343. integer n = *n_, incx = *incx_, incy = *incy_, i;
  344. _Complex double zdotc = 0.0;
  345. if (incx == 1 && incy == 1) {
  346. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  347. zdotc += Cd(&x[i]) * Cd(&y[i]);
  348. }
  349. } else {
  350. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  351. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  352. }
  353. }
  354. pCd(z) = zdotc;
  355. }
  356. #endif
  357. /* -- translated by f2c (version 20000121).
  358. You must link the resulting object file with the libraries:
  359. -lf2c -lm (in that order)
  360. */
  361. /* Table of constant values */
  362. static integer c__1 = 1;
  363. /* > \brief \b DLASD7 merges the two sets of singular values together into a single sorted set. Then it tries
  364. to deflate the size of the problem. Used by sbdsdc. */
  365. /* =========== DOCUMENTATION =========== */
  366. /* Online html documentation available at */
  367. /* http://www.netlib.org/lapack/explore-html/ */
  368. /* > \htmlonly */
  369. /* > Download DLASD7 + dependencies */
  370. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlasd7.
  371. f"> */
  372. /* > [TGZ]</a> */
  373. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlasd7.
  374. f"> */
  375. /* > [ZIP]</a> */
  376. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlasd7.
  377. f"> */
  378. /* > [TXT]</a> */
  379. /* > \endhtmlonly */
  380. /* Definition: */
  381. /* =========== */
  382. /* SUBROUTINE DLASD7( ICOMPQ, NL, NR, SQRE, K, D, Z, ZW, VF, VFW, VL, */
  383. /* VLW, ALPHA, BETA, DSIGMA, IDX, IDXP, IDXQ, */
  384. /* PERM, GIVPTR, GIVCOL, LDGCOL, GIVNUM, LDGNUM, */
  385. /* C, S, INFO ) */
  386. /* INTEGER GIVPTR, ICOMPQ, INFO, K, LDGCOL, LDGNUM, NL, */
  387. /* $ NR, SQRE */
  388. /* DOUBLE PRECISION ALPHA, BETA, C, S */
  389. /* INTEGER GIVCOL( LDGCOL, * ), IDX( * ), IDXP( * ), */
  390. /* $ IDXQ( * ), PERM( * ) */
  391. /* DOUBLE PRECISION D( * ), DSIGMA( * ), GIVNUM( LDGNUM, * ), */
  392. /* $ VF( * ), VFW( * ), VL( * ), VLW( * ), Z( * ), */
  393. /* $ ZW( * ) */
  394. /* > \par Purpose: */
  395. /* ============= */
  396. /* > */
  397. /* > \verbatim */
  398. /* > */
  399. /* > DLASD7 merges the two sets of singular values together into a single */
  400. /* > sorted set. Then it tries to deflate the size of the problem. There */
  401. /* > are two ways in which deflation can occur: when two or more singular */
  402. /* > values are close together or if there is a tiny entry in the Z */
  403. /* > vector. For each such occurrence the order of the related */
  404. /* > secular equation problem is reduced by one. */
  405. /* > */
  406. /* > DLASD7 is called from DLASD6. */
  407. /* > \endverbatim */
  408. /* Arguments: */
  409. /* ========== */
  410. /* > \param[in] ICOMPQ */
  411. /* > \verbatim */
  412. /* > ICOMPQ is INTEGER */
  413. /* > Specifies whether singular vectors are to be computed */
  414. /* > in compact form, as follows: */
  415. /* > = 0: Compute singular values only. */
  416. /* > = 1: Compute singular vectors of upper */
  417. /* > bidiagonal matrix in compact form. */
  418. /* > \endverbatim */
  419. /* > */
  420. /* > \param[in] NL */
  421. /* > \verbatim */
  422. /* > NL is INTEGER */
  423. /* > The row dimension of the upper block. NL >= 1. */
  424. /* > \endverbatim */
  425. /* > */
  426. /* > \param[in] NR */
  427. /* > \verbatim */
  428. /* > NR is INTEGER */
  429. /* > The row dimension of the lower block. NR >= 1. */
  430. /* > \endverbatim */
  431. /* > */
  432. /* > \param[in] SQRE */
  433. /* > \verbatim */
  434. /* > SQRE is INTEGER */
  435. /* > = 0: the lower block is an NR-by-NR square matrix. */
  436. /* > = 1: the lower block is an NR-by-(NR+1) rectangular matrix. */
  437. /* > */
  438. /* > The bidiagonal matrix has */
  439. /* > N = NL + NR + 1 rows and */
  440. /* > M = N + SQRE >= N columns. */
  441. /* > \endverbatim */
  442. /* > */
  443. /* > \param[out] K */
  444. /* > \verbatim */
  445. /* > K is INTEGER */
  446. /* > Contains the dimension of the non-deflated matrix, this is */
  447. /* > the order of the related secular equation. 1 <= K <=N. */
  448. /* > \endverbatim */
  449. /* > */
  450. /* > \param[in,out] D */
  451. /* > \verbatim */
  452. /* > D is DOUBLE PRECISION array, dimension ( N ) */
  453. /* > On entry D contains the singular values of the two submatrices */
  454. /* > to be combined. On exit D contains the trailing (N-K) updated */
  455. /* > singular values (those which were deflated) sorted into */
  456. /* > increasing order. */
  457. /* > \endverbatim */
  458. /* > */
  459. /* > \param[out] Z */
  460. /* > \verbatim */
  461. /* > Z is DOUBLE PRECISION array, dimension ( M ) */
  462. /* > On exit Z contains the updating row vector in the secular */
  463. /* > equation. */
  464. /* > \endverbatim */
  465. /* > */
  466. /* > \param[out] ZW */
  467. /* > \verbatim */
  468. /* > ZW is DOUBLE PRECISION array, dimension ( M ) */
  469. /* > Workspace for Z. */
  470. /* > \endverbatim */
  471. /* > */
  472. /* > \param[in,out] VF */
  473. /* > \verbatim */
  474. /* > VF is DOUBLE PRECISION array, dimension ( M ) */
  475. /* > On entry, VF(1:NL+1) contains the first components of all */
  476. /* > right singular vectors of the upper block; and VF(NL+2:M) */
  477. /* > contains the first components of all right singular vectors */
  478. /* > of the lower block. On exit, VF contains the first components */
  479. /* > of all right singular vectors of the bidiagonal matrix. */
  480. /* > \endverbatim */
  481. /* > */
  482. /* > \param[out] VFW */
  483. /* > \verbatim */
  484. /* > VFW is DOUBLE PRECISION array, dimension ( M ) */
  485. /* > Workspace for VF. */
  486. /* > \endverbatim */
  487. /* > */
  488. /* > \param[in,out] VL */
  489. /* > \verbatim */
  490. /* > VL is DOUBLE PRECISION array, dimension ( M ) */
  491. /* > On entry, VL(1:NL+1) contains the last components of all */
  492. /* > right singular vectors of the upper block; and VL(NL+2:M) */
  493. /* > contains the last components of all right singular vectors */
  494. /* > of the lower block. On exit, VL contains the last components */
  495. /* > of all right singular vectors of the bidiagonal matrix. */
  496. /* > \endverbatim */
  497. /* > */
  498. /* > \param[out] VLW */
  499. /* > \verbatim */
  500. /* > VLW is DOUBLE PRECISION array, dimension ( M ) */
  501. /* > Workspace for VL. */
  502. /* > \endverbatim */
  503. /* > */
  504. /* > \param[in] ALPHA */
  505. /* > \verbatim */
  506. /* > ALPHA is DOUBLE PRECISION */
  507. /* > Contains the diagonal element associated with the added row. */
  508. /* > \endverbatim */
  509. /* > */
  510. /* > \param[in] BETA */
  511. /* > \verbatim */
  512. /* > BETA is DOUBLE PRECISION */
  513. /* > Contains the off-diagonal element associated with the added */
  514. /* > row. */
  515. /* > \endverbatim */
  516. /* > */
  517. /* > \param[out] DSIGMA */
  518. /* > \verbatim */
  519. /* > DSIGMA is DOUBLE PRECISION array, dimension ( N ) */
  520. /* > Contains a copy of the diagonal elements (K-1 singular values */
  521. /* > and one zero) in the secular equation. */
  522. /* > \endverbatim */
  523. /* > */
  524. /* > \param[out] IDX */
  525. /* > \verbatim */
  526. /* > IDX is INTEGER array, dimension ( N ) */
  527. /* > This will contain the permutation used to sort the contents of */
  528. /* > D into ascending order. */
  529. /* > \endverbatim */
  530. /* > */
  531. /* > \param[out] IDXP */
  532. /* > \verbatim */
  533. /* > IDXP is INTEGER array, dimension ( N ) */
  534. /* > This will contain the permutation used to place deflated */
  535. /* > values of D at the end of the array. On output IDXP(2:K) */
  536. /* > points to the nondeflated D-values and IDXP(K+1:N) */
  537. /* > points to the deflated singular values. */
  538. /* > \endverbatim */
  539. /* > */
  540. /* > \param[in] IDXQ */
  541. /* > \verbatim */
  542. /* > IDXQ is INTEGER array, dimension ( N ) */
  543. /* > This contains the permutation which separately sorts the two */
  544. /* > sub-problems in D into ascending order. Note that entries in */
  545. /* > the first half of this permutation must first be moved one */
  546. /* > position backward; and entries in the second half */
  547. /* > must first have NL+1 added to their values. */
  548. /* > \endverbatim */
  549. /* > */
  550. /* > \param[out] PERM */
  551. /* > \verbatim */
  552. /* > PERM is INTEGER array, dimension ( N ) */
  553. /* > The permutations (from deflation and sorting) to be applied */
  554. /* > to each singular block. Not referenced if ICOMPQ = 0. */
  555. /* > \endverbatim */
  556. /* > */
  557. /* > \param[out] GIVPTR */
  558. /* > \verbatim */
  559. /* > GIVPTR is INTEGER */
  560. /* > The number of Givens rotations which took place in this */
  561. /* > subproblem. Not referenced if ICOMPQ = 0. */
  562. /* > \endverbatim */
  563. /* > */
  564. /* > \param[out] GIVCOL */
  565. /* > \verbatim */
  566. /* > GIVCOL is INTEGER array, dimension ( LDGCOL, 2 ) */
  567. /* > Each pair of numbers indicates a pair of columns to take place */
  568. /* > in a Givens rotation. Not referenced if ICOMPQ = 0. */
  569. /* > \endverbatim */
  570. /* > */
  571. /* > \param[in] LDGCOL */
  572. /* > \verbatim */
  573. /* > LDGCOL is INTEGER */
  574. /* > The leading dimension of GIVCOL, must be at least N. */
  575. /* > \endverbatim */
  576. /* > */
  577. /* > \param[out] GIVNUM */
  578. /* > \verbatim */
  579. /* > GIVNUM is DOUBLE PRECISION array, dimension ( LDGNUM, 2 ) */
  580. /* > Each number indicates the C or S value to be used in the */
  581. /* > corresponding Givens rotation. Not referenced if ICOMPQ = 0. */
  582. /* > \endverbatim */
  583. /* > */
  584. /* > \param[in] LDGNUM */
  585. /* > \verbatim */
  586. /* > LDGNUM is INTEGER */
  587. /* > The leading dimension of GIVNUM, must be at least N. */
  588. /* > \endverbatim */
  589. /* > */
  590. /* > \param[out] C */
  591. /* > \verbatim */
  592. /* > C is DOUBLE PRECISION */
  593. /* > C contains garbage if SQRE =0 and the C-value of a Givens */
  594. /* > rotation related to the right null space if SQRE = 1. */
  595. /* > \endverbatim */
  596. /* > */
  597. /* > \param[out] S */
  598. /* > \verbatim */
  599. /* > S is DOUBLE PRECISION */
  600. /* > S contains garbage if SQRE =0 and the S-value of a Givens */
  601. /* > rotation related to the right null space if SQRE = 1. */
  602. /* > \endverbatim */
  603. /* > */
  604. /* > \param[out] INFO */
  605. /* > \verbatim */
  606. /* > INFO is INTEGER */
  607. /* > = 0: successful exit. */
  608. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  609. /* > \endverbatim */
  610. /* Authors: */
  611. /* ======== */
  612. /* > \author Univ. of Tennessee */
  613. /* > \author Univ. of California Berkeley */
  614. /* > \author Univ. of Colorado Denver */
  615. /* > \author NAG Ltd. */
  616. /* > \date December 2016 */
  617. /* > \ingroup OTHERauxiliary */
  618. /* > \par Contributors: */
  619. /* ================== */
  620. /* > */
  621. /* > Ming Gu and Huan Ren, Computer Science Division, University of */
  622. /* > California at Berkeley, USA */
  623. /* > */
  624. /* ===================================================================== */
  625. /* Subroutine */ int dlasd7_(integer *icompq, integer *nl, integer *nr,
  626. integer *sqre, integer *k, doublereal *d__, doublereal *z__,
  627. doublereal *zw, doublereal *vf, doublereal *vfw, doublereal *vl,
  628. doublereal *vlw, doublereal *alpha, doublereal *beta, doublereal *
  629. dsigma, integer *idx, integer *idxp, integer *idxq, integer *perm,
  630. integer *givptr, integer *givcol, integer *ldgcol, doublereal *givnum,
  631. integer *ldgnum, doublereal *c__, doublereal *s, integer *info)
  632. {
  633. /* System generated locals */
  634. integer givcol_dim1, givcol_offset, givnum_dim1, givnum_offset, i__1;
  635. doublereal d__1, d__2;
  636. /* Local variables */
  637. integer idxi, idxj;
  638. extern /* Subroutine */ int drot_(integer *, doublereal *, integer *,
  639. doublereal *, integer *, doublereal *, doublereal *);
  640. integer i__, j, m, n, idxjp;
  641. extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
  642. doublereal *, integer *);
  643. integer jprev, k2;
  644. doublereal z1;
  645. extern doublereal dlapy2_(doublereal *, doublereal *), dlamch_(char *);
  646. integer jp;
  647. extern /* Subroutine */ int dlamrg_(integer *, integer *, doublereal *,
  648. integer *, integer *, integer *), xerbla_(char *, integer *, ftnlen);
  649. doublereal hlftol, eps, tau, tol;
  650. integer nlp1, nlp2;
  651. /* -- LAPACK auxiliary routine (version 3.7.0) -- */
  652. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  653. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  654. /* December 2016 */
  655. /* ===================================================================== */
  656. /* Test the input parameters. */
  657. /* Parameter adjustments */
  658. --d__;
  659. --z__;
  660. --zw;
  661. --vf;
  662. --vfw;
  663. --vl;
  664. --vlw;
  665. --dsigma;
  666. --idx;
  667. --idxp;
  668. --idxq;
  669. --perm;
  670. givcol_dim1 = *ldgcol;
  671. givcol_offset = 1 + givcol_dim1 * 1;
  672. givcol -= givcol_offset;
  673. givnum_dim1 = *ldgnum;
  674. givnum_offset = 1 + givnum_dim1 * 1;
  675. givnum -= givnum_offset;
  676. /* Function Body */
  677. *info = 0;
  678. n = *nl + *nr + 1;
  679. m = n + *sqre;
  680. if (*icompq < 0 || *icompq > 1) {
  681. *info = -1;
  682. } else if (*nl < 1) {
  683. *info = -2;
  684. } else if (*nr < 1) {
  685. *info = -3;
  686. } else if (*sqre < 0 || *sqre > 1) {
  687. *info = -4;
  688. } else if (*ldgcol < n) {
  689. *info = -22;
  690. } else if (*ldgnum < n) {
  691. *info = -24;
  692. }
  693. if (*info != 0) {
  694. i__1 = -(*info);
  695. xerbla_("DLASD7", &i__1, (ftnlen)6);
  696. return 0;
  697. }
  698. nlp1 = *nl + 1;
  699. nlp2 = *nl + 2;
  700. if (*icompq == 1) {
  701. *givptr = 0;
  702. }
  703. /* Generate the first part of the vector Z and move the singular */
  704. /* values in the first part of D one position backward. */
  705. z1 = *alpha * vl[nlp1];
  706. vl[nlp1] = 0.;
  707. tau = vf[nlp1];
  708. for (i__ = *nl; i__ >= 1; --i__) {
  709. z__[i__ + 1] = *alpha * vl[i__];
  710. vl[i__] = 0.;
  711. vf[i__ + 1] = vf[i__];
  712. d__[i__ + 1] = d__[i__];
  713. idxq[i__ + 1] = idxq[i__] + 1;
  714. /* L10: */
  715. }
  716. vf[1] = tau;
  717. /* Generate the second part of the vector Z. */
  718. i__1 = m;
  719. for (i__ = nlp2; i__ <= i__1; ++i__) {
  720. z__[i__] = *beta * vf[i__];
  721. vf[i__] = 0.;
  722. /* L20: */
  723. }
  724. /* Sort the singular values into increasing order */
  725. i__1 = n;
  726. for (i__ = nlp2; i__ <= i__1; ++i__) {
  727. idxq[i__] += nlp1;
  728. /* L30: */
  729. }
  730. /* DSIGMA, IDXC, IDXC, and ZW are used as storage space. */
  731. i__1 = n;
  732. for (i__ = 2; i__ <= i__1; ++i__) {
  733. dsigma[i__] = d__[idxq[i__]];
  734. zw[i__] = z__[idxq[i__]];
  735. vfw[i__] = vf[idxq[i__]];
  736. vlw[i__] = vl[idxq[i__]];
  737. /* L40: */
  738. }
  739. dlamrg_(nl, nr, &dsigma[2], &c__1, &c__1, &idx[2]);
  740. i__1 = n;
  741. for (i__ = 2; i__ <= i__1; ++i__) {
  742. idxi = idx[i__] + 1;
  743. d__[i__] = dsigma[idxi];
  744. z__[i__] = zw[idxi];
  745. vf[i__] = vfw[idxi];
  746. vl[i__] = vlw[idxi];
  747. /* L50: */
  748. }
  749. /* Calculate the allowable deflation tolerance */
  750. eps = dlamch_("Epsilon");
  751. /* Computing MAX */
  752. d__1 = abs(*alpha), d__2 = abs(*beta);
  753. tol = f2cmax(d__1,d__2);
  754. /* Computing MAX */
  755. d__2 = (d__1 = d__[n], abs(d__1));
  756. tol = eps * 64. * f2cmax(d__2,tol);
  757. /* There are 2 kinds of deflation -- first a value in the z-vector */
  758. /* is small, second two (or more) singular values are very close */
  759. /* together (their difference is small). */
  760. /* If the value in the z-vector is small, we simply permute the */
  761. /* array so that the corresponding singular value is moved to the */
  762. /* end. */
  763. /* If two values in the D-vector are close, we perform a two-sided */
  764. /* rotation designed to make one of the corresponding z-vector */
  765. /* entries zero, and then permute the array so that the deflated */
  766. /* singular value is moved to the end. */
  767. /* If there are multiple singular values then the problem deflates. */
  768. /* Here the number of equal singular values are found. As each equal */
  769. /* singular value is found, an elementary reflector is computed to */
  770. /* rotate the corresponding singular subspace so that the */
  771. /* corresponding components of Z are zero in this new basis. */
  772. *k = 1;
  773. k2 = n + 1;
  774. i__1 = n;
  775. for (j = 2; j <= i__1; ++j) {
  776. if ((d__1 = z__[j], abs(d__1)) <= tol) {
  777. /* Deflate due to small z component. */
  778. --k2;
  779. idxp[k2] = j;
  780. if (j == n) {
  781. goto L100;
  782. }
  783. } else {
  784. jprev = j;
  785. goto L70;
  786. }
  787. /* L60: */
  788. }
  789. L70:
  790. j = jprev;
  791. L80:
  792. ++j;
  793. if (j > n) {
  794. goto L90;
  795. }
  796. if ((d__1 = z__[j], abs(d__1)) <= tol) {
  797. /* Deflate due to small z component. */
  798. --k2;
  799. idxp[k2] = j;
  800. } else {
  801. /* Check if singular values are close enough to allow deflation. */
  802. if ((d__1 = d__[j] - d__[jprev], abs(d__1)) <= tol) {
  803. /* Deflation is possible. */
  804. *s = z__[jprev];
  805. *c__ = z__[j];
  806. /* Find sqrt(a**2+b**2) without overflow or */
  807. /* destructive underflow. */
  808. tau = dlapy2_(c__, s);
  809. z__[j] = tau;
  810. z__[jprev] = 0.;
  811. *c__ /= tau;
  812. *s = -(*s) / tau;
  813. /* Record the appropriate Givens rotation */
  814. if (*icompq == 1) {
  815. ++(*givptr);
  816. idxjp = idxq[idx[jprev] + 1];
  817. idxj = idxq[idx[j] + 1];
  818. if (idxjp <= nlp1) {
  819. --idxjp;
  820. }
  821. if (idxj <= nlp1) {
  822. --idxj;
  823. }
  824. givcol[*givptr + (givcol_dim1 << 1)] = idxjp;
  825. givcol[*givptr + givcol_dim1] = idxj;
  826. givnum[*givptr + (givnum_dim1 << 1)] = *c__;
  827. givnum[*givptr + givnum_dim1] = *s;
  828. }
  829. drot_(&c__1, &vf[jprev], &c__1, &vf[j], &c__1, c__, s);
  830. drot_(&c__1, &vl[jprev], &c__1, &vl[j], &c__1, c__, s);
  831. --k2;
  832. idxp[k2] = jprev;
  833. jprev = j;
  834. } else {
  835. ++(*k);
  836. zw[*k] = z__[jprev];
  837. dsigma[*k] = d__[jprev];
  838. idxp[*k] = jprev;
  839. jprev = j;
  840. }
  841. }
  842. goto L80;
  843. L90:
  844. /* Record the last singular value. */
  845. ++(*k);
  846. zw[*k] = z__[jprev];
  847. dsigma[*k] = d__[jprev];
  848. idxp[*k] = jprev;
  849. L100:
  850. /* Sort the singular values into DSIGMA. The singular values which */
  851. /* were not deflated go into the first K slots of DSIGMA, except */
  852. /* that DSIGMA(1) is treated separately. */
  853. i__1 = n;
  854. for (j = 2; j <= i__1; ++j) {
  855. jp = idxp[j];
  856. dsigma[j] = d__[jp];
  857. vfw[j] = vf[jp];
  858. vlw[j] = vl[jp];
  859. /* L110: */
  860. }
  861. if (*icompq == 1) {
  862. i__1 = n;
  863. for (j = 2; j <= i__1; ++j) {
  864. jp = idxp[j];
  865. perm[j] = idxq[idx[jp] + 1];
  866. if (perm[j] <= nlp1) {
  867. --perm[j];
  868. }
  869. /* L120: */
  870. }
  871. }
  872. /* The deflated singular values go back into the last N - K slots of */
  873. /* D. */
  874. i__1 = n - *k;
  875. dcopy_(&i__1, &dsigma[*k + 1], &c__1, &d__[*k + 1], &c__1);
  876. /* Determine DSIGMA(1), DSIGMA(2), Z(1), VF(1), VL(1), VF(M), and */
  877. /* VL(M). */
  878. dsigma[1] = 0.;
  879. hlftol = tol / 2.;
  880. if (abs(dsigma[2]) <= hlftol) {
  881. dsigma[2] = hlftol;
  882. }
  883. if (m > n) {
  884. z__[1] = dlapy2_(&z1, &z__[m]);
  885. if (z__[1] <= tol) {
  886. *c__ = 1.;
  887. *s = 0.;
  888. z__[1] = tol;
  889. } else {
  890. *c__ = z1 / z__[1];
  891. *s = -z__[m] / z__[1];
  892. }
  893. drot_(&c__1, &vf[m], &c__1, &vf[1], &c__1, c__, s);
  894. drot_(&c__1, &vl[m], &c__1, &vl[1], &c__1, c__, s);
  895. } else {
  896. if (abs(z1) <= tol) {
  897. z__[1] = tol;
  898. } else {
  899. z__[1] = z1;
  900. }
  901. }
  902. /* Restore Z, VF, and VL. */
  903. i__1 = *k - 1;
  904. dcopy_(&i__1, &zw[2], &c__1, &z__[2], &c__1);
  905. i__1 = n - 1;
  906. dcopy_(&i__1, &vfw[2], &c__1, &vf[2], &c__1);
  907. i__1 = n - 1;
  908. dcopy_(&i__1, &vlw[2], &c__1, &vl[2], &c__1);
  909. return 0;
  910. /* End of DLASD7 */
  911. } /* dlasd7_ */