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.

slasd2.c 32 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  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. static real c_b30 = 0.f;
  382. /* > \brief \b SLASD2 merges the two sets of singular values together into a single sorted set. Used by sbdsdc
  383. . */
  384. /* =========== DOCUMENTATION =========== */
  385. /* Online html documentation available at */
  386. /* http://www.netlib.org/lapack/explore-html/ */
  387. /* > \htmlonly */
  388. /* > Download SLASD2 + dependencies */
  389. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slasd2.
  390. f"> */
  391. /* > [TGZ]</a> */
  392. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slasd2.
  393. f"> */
  394. /* > [ZIP]</a> */
  395. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slasd2.
  396. f"> */
  397. /* > [TXT]</a> */
  398. /* > \endhtmlonly */
  399. /* Definition: */
  400. /* =========== */
  401. /* SUBROUTINE SLASD2( NL, NR, SQRE, K, D, Z, ALPHA, BETA, U, LDU, VT, */
  402. /* LDVT, DSIGMA, U2, LDU2, VT2, LDVT2, IDXP, IDX, */
  403. /* IDXC, IDXQ, COLTYP, INFO ) */
  404. /* INTEGER INFO, K, LDU, LDU2, LDVT, LDVT2, NL, NR, SQRE */
  405. /* REAL ALPHA, BETA */
  406. /* INTEGER COLTYP( * ), IDX( * ), IDXC( * ), IDXP( * ), */
  407. /* $ IDXQ( * ) */
  408. /* REAL D( * ), DSIGMA( * ), U( LDU, * ), */
  409. /* $ U2( LDU2, * ), VT( LDVT, * ), VT2( LDVT2, * ), */
  410. /* $ Z( * ) */
  411. /* > \par Purpose: */
  412. /* ============= */
  413. /* > */
  414. /* > \verbatim */
  415. /* > */
  416. /* > SLASD2 merges the two sets of singular values together into a single */
  417. /* > sorted set. Then it tries to deflate the size of the problem. */
  418. /* > There are two ways in which deflation can occur: when two or more */
  419. /* > singular values are close together or if there is a tiny entry in the */
  420. /* > Z vector. For each such occurrence the order of the related secular */
  421. /* > equation problem is reduced by one. */
  422. /* > */
  423. /* > SLASD2 is called from SLASD1. */
  424. /* > \endverbatim */
  425. /* Arguments: */
  426. /* ========== */
  427. /* > \param[in] NL */
  428. /* > \verbatim */
  429. /* > NL is INTEGER */
  430. /* > The row dimension of the upper block. NL >= 1. */
  431. /* > \endverbatim */
  432. /* > */
  433. /* > \param[in] NR */
  434. /* > \verbatim */
  435. /* > NR is INTEGER */
  436. /* > The row dimension of the lower block. NR >= 1. */
  437. /* > \endverbatim */
  438. /* > */
  439. /* > \param[in] SQRE */
  440. /* > \verbatim */
  441. /* > SQRE is INTEGER */
  442. /* > = 0: the lower block is an NR-by-NR square matrix. */
  443. /* > = 1: the lower block is an NR-by-(NR+1) rectangular matrix. */
  444. /* > */
  445. /* > The bidiagonal matrix has N = NL + NR + 1 rows and */
  446. /* > M = N + SQRE >= N columns. */
  447. /* > \endverbatim */
  448. /* > */
  449. /* > \param[out] K */
  450. /* > \verbatim */
  451. /* > K is INTEGER */
  452. /* > Contains the dimension of the non-deflated matrix, */
  453. /* > This is the order of the related secular equation. 1 <= K <=N. */
  454. /* > \endverbatim */
  455. /* > */
  456. /* > \param[in,out] D */
  457. /* > \verbatim */
  458. /* > D is REAL array, dimension (N) */
  459. /* > On entry D contains the singular values of the two submatrices */
  460. /* > to be combined. On exit D contains the trailing (N-K) updated */
  461. /* > singular values (those which were deflated) sorted into */
  462. /* > increasing order. */
  463. /* > \endverbatim */
  464. /* > */
  465. /* > \param[out] Z */
  466. /* > \verbatim */
  467. /* > Z is REAL array, dimension (N) */
  468. /* > On exit Z contains the updating row vector in the secular */
  469. /* > equation. */
  470. /* > \endverbatim */
  471. /* > */
  472. /* > \param[in] ALPHA */
  473. /* > \verbatim */
  474. /* > ALPHA is REAL */
  475. /* > Contains the diagonal element associated with the added row. */
  476. /* > \endverbatim */
  477. /* > */
  478. /* > \param[in] BETA */
  479. /* > \verbatim */
  480. /* > BETA is REAL */
  481. /* > Contains the off-diagonal element associated with the added */
  482. /* > row. */
  483. /* > \endverbatim */
  484. /* > */
  485. /* > \param[in,out] U */
  486. /* > \verbatim */
  487. /* > U is REAL array, dimension (LDU,N) */
  488. /* > On entry U contains the left singular vectors of two */
  489. /* > submatrices in the two square blocks with corners at (1,1), */
  490. /* > (NL, NL), and (NL+2, NL+2), (N,N). */
  491. /* > On exit U contains the trailing (N-K) updated left singular */
  492. /* > vectors (those which were deflated) in its last N-K columns. */
  493. /* > \endverbatim */
  494. /* > */
  495. /* > \param[in] LDU */
  496. /* > \verbatim */
  497. /* > LDU is INTEGER */
  498. /* > The leading dimension of the array U. LDU >= N. */
  499. /* > \endverbatim */
  500. /* > */
  501. /* > \param[in,out] VT */
  502. /* > \verbatim */
  503. /* > VT is REAL array, dimension (LDVT,M) */
  504. /* > On entry VT**T contains the right singular vectors of two */
  505. /* > submatrices in the two square blocks with corners at (1,1), */
  506. /* > (NL+1, NL+1), and (NL+2, NL+2), (M,M). */
  507. /* > On exit VT**T contains the trailing (N-K) updated right singular */
  508. /* > vectors (those which were deflated) in its last N-K columns. */
  509. /* > In case SQRE =1, the last row of VT spans the right null */
  510. /* > space. */
  511. /* > \endverbatim */
  512. /* > */
  513. /* > \param[in] LDVT */
  514. /* > \verbatim */
  515. /* > LDVT is INTEGER */
  516. /* > The leading dimension of the array VT. LDVT >= M. */
  517. /* > \endverbatim */
  518. /* > */
  519. /* > \param[out] DSIGMA */
  520. /* > \verbatim */
  521. /* > DSIGMA is REAL array, dimension (N) */
  522. /* > Contains a copy of the diagonal elements (K-1 singular values */
  523. /* > and one zero) in the secular equation. */
  524. /* > \endverbatim */
  525. /* > */
  526. /* > \param[out] U2 */
  527. /* > \verbatim */
  528. /* > U2 is REAL array, dimension (LDU2,N) */
  529. /* > Contains a copy of the first K-1 left singular vectors which */
  530. /* > will be used by SLASD3 in a matrix multiply (SGEMM) to solve */
  531. /* > for the new left singular vectors. U2 is arranged into four */
  532. /* > blocks. The first block contains a column with 1 at NL+1 and */
  533. /* > zero everywhere else; the second block contains non-zero */
  534. /* > entries only at and above NL; the third contains non-zero */
  535. /* > entries only below NL+1; and the fourth is dense. */
  536. /* > \endverbatim */
  537. /* > */
  538. /* > \param[in] LDU2 */
  539. /* > \verbatim */
  540. /* > LDU2 is INTEGER */
  541. /* > The leading dimension of the array U2. LDU2 >= N. */
  542. /* > \endverbatim */
  543. /* > */
  544. /* > \param[out] VT2 */
  545. /* > \verbatim */
  546. /* > VT2 is REAL array, dimension (LDVT2,N) */
  547. /* > VT2**T contains a copy of the first K right singular vectors */
  548. /* > which will be used by SLASD3 in a matrix multiply (SGEMM) to */
  549. /* > solve for the new right singular vectors. VT2 is arranged into */
  550. /* > three blocks. The first block contains a row that corresponds */
  551. /* > to the special 0 diagonal element in SIGMA; the second block */
  552. /* > contains non-zeros only at and before NL +1; the third block */
  553. /* > contains non-zeros only at and after NL +2. */
  554. /* > \endverbatim */
  555. /* > */
  556. /* > \param[in] LDVT2 */
  557. /* > \verbatim */
  558. /* > LDVT2 is INTEGER */
  559. /* > The leading dimension of the array VT2. LDVT2 >= M. */
  560. /* > \endverbatim */
  561. /* > */
  562. /* > \param[out] IDXP */
  563. /* > \verbatim */
  564. /* > IDXP is INTEGER array, dimension (N) */
  565. /* > This will contain the permutation used to place deflated */
  566. /* > values of D at the end of the array. On output IDXP(2:K) */
  567. /* > points to the nondeflated D-values and IDXP(K+1:N) */
  568. /* > points to the deflated singular values. */
  569. /* > \endverbatim */
  570. /* > */
  571. /* > \param[out] IDX */
  572. /* > \verbatim */
  573. /* > IDX is INTEGER array, dimension (N) */
  574. /* > This will contain the permutation used to sort the contents of */
  575. /* > D into ascending order. */
  576. /* > \endverbatim */
  577. /* > */
  578. /* > \param[out] IDXC */
  579. /* > \verbatim */
  580. /* > IDXC is INTEGER array, dimension (N) */
  581. /* > This will contain the permutation used to arrange the columns */
  582. /* > of the deflated U matrix into three groups: the first group */
  583. /* > contains non-zero entries only at and above NL, the second */
  584. /* > contains non-zero entries only below NL+2, and the third is */
  585. /* > dense. */
  586. /* > \endverbatim */
  587. /* > */
  588. /* > \param[in,out] IDXQ */
  589. /* > \verbatim */
  590. /* > IDXQ is INTEGER array, dimension (N) */
  591. /* > This contains the permutation which separately sorts the two */
  592. /* > sub-problems in D into ascending order. Note that entries in */
  593. /* > the first hlaf of this permutation must first be moved one */
  594. /* > position backward; and entries in the second half */
  595. /* > must first have NL+1 added to their values. */
  596. /* > \endverbatim */
  597. /* > */
  598. /* > \param[out] COLTYP */
  599. /* > \verbatim */
  600. /* > COLTYP is INTEGER array, dimension (N) */
  601. /* > As workspace, this will contain a label which will indicate */
  602. /* > which of the following types a column in the U2 matrix or a */
  603. /* > row in the VT2 matrix is: */
  604. /* > 1 : non-zero in the upper half only */
  605. /* > 2 : non-zero in the lower half only */
  606. /* > 3 : dense */
  607. /* > 4 : deflated */
  608. /* > */
  609. /* > On exit, it is an array of dimension 4, with COLTYP(I) being */
  610. /* > the dimension of the I-th type columns. */
  611. /* > \endverbatim */
  612. /* > */
  613. /* > \param[out] INFO */
  614. /* > \verbatim */
  615. /* > INFO is INTEGER */
  616. /* > = 0: successful exit. */
  617. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  618. /* > \endverbatim */
  619. /* Authors: */
  620. /* ======== */
  621. /* > \author Univ. of Tennessee */
  622. /* > \author Univ. of California Berkeley */
  623. /* > \author Univ. of Colorado Denver */
  624. /* > \author NAG Ltd. */
  625. /* > \date December 2016 */
  626. /* > \ingroup OTHERauxiliary */
  627. /* > \par Contributors: */
  628. /* ================== */
  629. /* > */
  630. /* > Ming Gu and Huan Ren, Computer Science Division, University of */
  631. /* > California at Berkeley, USA */
  632. /* > */
  633. /* ===================================================================== */
  634. /* Subroutine */ int slasd2_(integer *nl, integer *nr, integer *sqre, integer
  635. *k, real *d__, real *z__, real *alpha, real *beta, real *u, integer *
  636. ldu, real *vt, integer *ldvt, real *dsigma, real *u2, integer *ldu2,
  637. real *vt2, integer *ldvt2, integer *idxp, integer *idx, integer *idxc,
  638. integer *idxq, integer *coltyp, integer *info)
  639. {
  640. /* System generated locals */
  641. integer u_dim1, u_offset, u2_dim1, u2_offset, vt_dim1, vt_offset,
  642. vt2_dim1, vt2_offset, i__1;
  643. real r__1, r__2;
  644. /* Local variables */
  645. integer idxi, idxj, ctot[4];
  646. extern /* Subroutine */ int srot_(integer *, real *, integer *, real *,
  647. integer *, real *, real *);
  648. real c__;
  649. integer i__, j, m, n;
  650. real s;
  651. integer idxjp, jprev, k2;
  652. extern /* Subroutine */ int scopy_(integer *, real *, integer *, real *,
  653. integer *);
  654. real z1;
  655. extern real slapy2_(real *, real *);
  656. integer ct, jp;
  657. extern real slamch_(char *);
  658. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen), slamrg_(
  659. integer *, integer *, real *, integer *, integer *, integer *);
  660. real hlftol;
  661. extern /* Subroutine */ int slacpy_(char *, integer *, integer *, real *,
  662. integer *, real *, integer *), slaset_(char *, integer *,
  663. integer *, real *, real *, real *, integer *);
  664. real eps, tau, tol;
  665. integer psm[4], nlp1, nlp2;
  666. /* -- LAPACK auxiliary routine (version 3.7.0) -- */
  667. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  668. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  669. /* December 2016 */
  670. /* ===================================================================== */
  671. /* Test the input parameters. */
  672. /* Parameter adjustments */
  673. --d__;
  674. --z__;
  675. u_dim1 = *ldu;
  676. u_offset = 1 + u_dim1 * 1;
  677. u -= u_offset;
  678. vt_dim1 = *ldvt;
  679. vt_offset = 1 + vt_dim1 * 1;
  680. vt -= vt_offset;
  681. --dsigma;
  682. u2_dim1 = *ldu2;
  683. u2_offset = 1 + u2_dim1 * 1;
  684. u2 -= u2_offset;
  685. vt2_dim1 = *ldvt2;
  686. vt2_offset = 1 + vt2_dim1 * 1;
  687. vt2 -= vt2_offset;
  688. --idxp;
  689. --idx;
  690. --idxc;
  691. --idxq;
  692. --coltyp;
  693. /* Function Body */
  694. *info = 0;
  695. if (*nl < 1) {
  696. *info = -1;
  697. } else if (*nr < 1) {
  698. *info = -2;
  699. } else if (*sqre != 1 && *sqre != 0) {
  700. *info = -3;
  701. }
  702. n = *nl + *nr + 1;
  703. m = n + *sqre;
  704. if (*ldu < n) {
  705. *info = -10;
  706. } else if (*ldvt < m) {
  707. *info = -12;
  708. } else if (*ldu2 < n) {
  709. *info = -15;
  710. } else if (*ldvt2 < m) {
  711. *info = -17;
  712. }
  713. if (*info != 0) {
  714. i__1 = -(*info);
  715. xerbla_("SLASD2", &i__1, (ftnlen)6);
  716. return 0;
  717. }
  718. nlp1 = *nl + 1;
  719. nlp2 = *nl + 2;
  720. /* Generate the first part of the vector Z; and move the singular */
  721. /* values in the first part of D one position backward. */
  722. z1 = *alpha * vt[nlp1 + nlp1 * vt_dim1];
  723. z__[1] = z1;
  724. for (i__ = *nl; i__ >= 1; --i__) {
  725. z__[i__ + 1] = *alpha * vt[i__ + nlp1 * vt_dim1];
  726. d__[i__ + 1] = d__[i__];
  727. idxq[i__ + 1] = idxq[i__] + 1;
  728. /* L10: */
  729. }
  730. /* Generate the second part of the vector Z. */
  731. i__1 = m;
  732. for (i__ = nlp2; i__ <= i__1; ++i__) {
  733. z__[i__] = *beta * vt[i__ + nlp2 * vt_dim1];
  734. /* L20: */
  735. }
  736. /* Initialize some reference arrays. */
  737. i__1 = nlp1;
  738. for (i__ = 2; i__ <= i__1; ++i__) {
  739. coltyp[i__] = 1;
  740. /* L30: */
  741. }
  742. i__1 = n;
  743. for (i__ = nlp2; i__ <= i__1; ++i__) {
  744. coltyp[i__] = 2;
  745. /* L40: */
  746. }
  747. /* Sort the singular values into increasing order */
  748. i__1 = n;
  749. for (i__ = nlp2; i__ <= i__1; ++i__) {
  750. idxq[i__] += nlp1;
  751. /* L50: */
  752. }
  753. /* DSIGMA, IDXC, IDXC, and the first column of U2 */
  754. /* are used as storage space. */
  755. i__1 = n;
  756. for (i__ = 2; i__ <= i__1; ++i__) {
  757. dsigma[i__] = d__[idxq[i__]];
  758. u2[i__ + u2_dim1] = z__[idxq[i__]];
  759. idxc[i__] = coltyp[idxq[i__]];
  760. /* L60: */
  761. }
  762. slamrg_(nl, nr, &dsigma[2], &c__1, &c__1, &idx[2]);
  763. i__1 = n;
  764. for (i__ = 2; i__ <= i__1; ++i__) {
  765. idxi = idx[i__] + 1;
  766. d__[i__] = dsigma[idxi];
  767. z__[i__] = u2[idxi + u2_dim1];
  768. coltyp[i__] = idxc[idxi];
  769. /* L70: */
  770. }
  771. /* Calculate the allowable deflation tolerance */
  772. eps = slamch_("Epsilon");
  773. /* Computing MAX */
  774. r__1 = abs(*alpha), r__2 = abs(*beta);
  775. tol = f2cmax(r__1,r__2);
  776. /* Computing MAX */
  777. r__2 = (r__1 = d__[n], abs(r__1));
  778. tol = eps * 8.f * f2cmax(r__2,tol);
  779. /* There are 2 kinds of deflation -- first a value in the z-vector */
  780. /* is small, second two (or more) singular values are very close */
  781. /* together (their difference is small). */
  782. /* If the value in the z-vector is small, we simply permute the */
  783. /* array so that the corresponding singular value is moved to the */
  784. /* end. */
  785. /* If two values in the D-vector are close, we perform a two-sided */
  786. /* rotation designed to make one of the corresponding z-vector */
  787. /* entries zero, and then permute the array so that the deflated */
  788. /* singular value is moved to the end. */
  789. /* If there are multiple singular values then the problem deflates. */
  790. /* Here the number of equal singular values are found. As each equal */
  791. /* singular value is found, an elementary reflector is computed to */
  792. /* rotate the corresponding singular subspace so that the */
  793. /* corresponding components of Z are zero in this new basis. */
  794. *k = 1;
  795. k2 = n + 1;
  796. i__1 = n;
  797. for (j = 2; j <= i__1; ++j) {
  798. if ((r__1 = z__[j], abs(r__1)) <= tol) {
  799. /* Deflate due to small z component. */
  800. --k2;
  801. idxp[k2] = j;
  802. coltyp[j] = 4;
  803. if (j == n) {
  804. goto L120;
  805. }
  806. } else {
  807. jprev = j;
  808. goto L90;
  809. }
  810. /* L80: */
  811. }
  812. L90:
  813. j = jprev;
  814. L100:
  815. ++j;
  816. if (j > n) {
  817. goto L110;
  818. }
  819. if ((r__1 = z__[j], abs(r__1)) <= tol) {
  820. /* Deflate due to small z component. */
  821. --k2;
  822. idxp[k2] = j;
  823. coltyp[j] = 4;
  824. } else {
  825. /* Check if singular values are close enough to allow deflation. */
  826. if ((r__1 = d__[j] - d__[jprev], abs(r__1)) <= tol) {
  827. /* Deflation is possible. */
  828. s = z__[jprev];
  829. c__ = z__[j];
  830. /* Find sqrt(a**2+b**2) without overflow or */
  831. /* destructive underflow. */
  832. tau = slapy2_(&c__, &s);
  833. c__ /= tau;
  834. s = -s / tau;
  835. z__[j] = tau;
  836. z__[jprev] = 0.f;
  837. /* Apply back the Givens rotation to the left and right */
  838. /* singular vector matrices. */
  839. idxjp = idxq[idx[jprev] + 1];
  840. idxj = idxq[idx[j] + 1];
  841. if (idxjp <= nlp1) {
  842. --idxjp;
  843. }
  844. if (idxj <= nlp1) {
  845. --idxj;
  846. }
  847. srot_(&n, &u[idxjp * u_dim1 + 1], &c__1, &u[idxj * u_dim1 + 1], &
  848. c__1, &c__, &s);
  849. srot_(&m, &vt[idxjp + vt_dim1], ldvt, &vt[idxj + vt_dim1], ldvt, &
  850. c__, &s);
  851. if (coltyp[j] != coltyp[jprev]) {
  852. coltyp[j] = 3;
  853. }
  854. coltyp[jprev] = 4;
  855. --k2;
  856. idxp[k2] = jprev;
  857. jprev = j;
  858. } else {
  859. ++(*k);
  860. u2[*k + u2_dim1] = z__[jprev];
  861. dsigma[*k] = d__[jprev];
  862. idxp[*k] = jprev;
  863. jprev = j;
  864. }
  865. }
  866. goto L100;
  867. L110:
  868. /* Record the last singular value. */
  869. ++(*k);
  870. u2[*k + u2_dim1] = z__[jprev];
  871. dsigma[*k] = d__[jprev];
  872. idxp[*k] = jprev;
  873. L120:
  874. /* Count up the total number of the various types of columns, then */
  875. /* form a permutation which positions the four column types into */
  876. /* four groups of uniform structure (although one or more of these */
  877. /* groups may be empty). */
  878. for (j = 1; j <= 4; ++j) {
  879. ctot[j - 1] = 0;
  880. /* L130: */
  881. }
  882. i__1 = n;
  883. for (j = 2; j <= i__1; ++j) {
  884. ct = coltyp[j];
  885. ++ctot[ct - 1];
  886. /* L140: */
  887. }
  888. /* PSM(*) = Position in SubMatrix (of types 1 through 4) */
  889. psm[0] = 2;
  890. psm[1] = ctot[0] + 2;
  891. psm[2] = psm[1] + ctot[1];
  892. psm[3] = psm[2] + ctot[2];
  893. /* Fill out the IDXC array so that the permutation which it induces */
  894. /* will place all type-1 columns first, all type-2 columns next, */
  895. /* then all type-3's, and finally all type-4's, starting from the */
  896. /* second column. This applies similarly to the rows of VT. */
  897. i__1 = n;
  898. for (j = 2; j <= i__1; ++j) {
  899. jp = idxp[j];
  900. ct = coltyp[jp];
  901. idxc[psm[ct - 1]] = j;
  902. ++psm[ct - 1];
  903. /* L150: */
  904. }
  905. /* Sort the singular values and corresponding singular vectors into */
  906. /* DSIGMA, U2, and VT2 respectively. The singular values/vectors */
  907. /* which were not deflated go into the first K slots of DSIGMA, U2, */
  908. /* and VT2 respectively, while those which were deflated go into the */
  909. /* last N - K slots, except that the first column/row will be treated */
  910. /* separately. */
  911. i__1 = n;
  912. for (j = 2; j <= i__1; ++j) {
  913. jp = idxp[j];
  914. dsigma[j] = d__[jp];
  915. idxj = idxq[idx[idxp[idxc[j]]] + 1];
  916. if (idxj <= nlp1) {
  917. --idxj;
  918. }
  919. scopy_(&n, &u[idxj * u_dim1 + 1], &c__1, &u2[j * u2_dim1 + 1], &c__1);
  920. scopy_(&m, &vt[idxj + vt_dim1], ldvt, &vt2[j + vt2_dim1], ldvt2);
  921. /* L160: */
  922. }
  923. /* Determine DSIGMA(1), DSIGMA(2) and Z(1) */
  924. dsigma[1] = 0.f;
  925. hlftol = tol / 2.f;
  926. if (abs(dsigma[2]) <= hlftol) {
  927. dsigma[2] = hlftol;
  928. }
  929. if (m > n) {
  930. z__[1] = slapy2_(&z1, &z__[m]);
  931. if (z__[1] <= tol) {
  932. c__ = 1.f;
  933. s = 0.f;
  934. z__[1] = tol;
  935. } else {
  936. c__ = z1 / z__[1];
  937. s = z__[m] / z__[1];
  938. }
  939. } else {
  940. if (abs(z1) <= tol) {
  941. z__[1] = tol;
  942. } else {
  943. z__[1] = z1;
  944. }
  945. }
  946. /* Move the rest of the updating row to Z. */
  947. i__1 = *k - 1;
  948. scopy_(&i__1, &u2[u2_dim1 + 2], &c__1, &z__[2], &c__1);
  949. /* Determine the first column of U2, the first row of VT2 and the */
  950. /* last row of VT. */
  951. slaset_("A", &n, &c__1, &c_b30, &c_b30, &u2[u2_offset], ldu2);
  952. u2[nlp1 + u2_dim1] = 1.f;
  953. if (m > n) {
  954. i__1 = nlp1;
  955. for (i__ = 1; i__ <= i__1; ++i__) {
  956. vt[m + i__ * vt_dim1] = -s * vt[nlp1 + i__ * vt_dim1];
  957. vt2[i__ * vt2_dim1 + 1] = c__ * vt[nlp1 + i__ * vt_dim1];
  958. /* L170: */
  959. }
  960. i__1 = m;
  961. for (i__ = nlp2; i__ <= i__1; ++i__) {
  962. vt2[i__ * vt2_dim1 + 1] = s * vt[m + i__ * vt_dim1];
  963. vt[m + i__ * vt_dim1] = c__ * vt[m + i__ * vt_dim1];
  964. /* L180: */
  965. }
  966. } else {
  967. scopy_(&m, &vt[nlp1 + vt_dim1], ldvt, &vt2[vt2_dim1 + 1], ldvt2);
  968. }
  969. if (m > n) {
  970. scopy_(&m, &vt[m + vt_dim1], ldvt, &vt2[m + vt2_dim1], ldvt2);
  971. }
  972. /* The deflated singular values and their corresponding vectors go */
  973. /* into the back of D, U, and V respectively. */
  974. if (n > *k) {
  975. i__1 = n - *k;
  976. scopy_(&i__1, &dsigma[*k + 1], &c__1, &d__[*k + 1], &c__1);
  977. i__1 = n - *k;
  978. slacpy_("A", &n, &i__1, &u2[(*k + 1) * u2_dim1 + 1], ldu2, &u[(*k + 1)
  979. * u_dim1 + 1], ldu);
  980. i__1 = n - *k;
  981. slacpy_("A", &i__1, &m, &vt2[*k + 1 + vt2_dim1], ldvt2, &vt[*k + 1 +
  982. vt_dim1], ldvt);
  983. }
  984. /* Copy CTOT into COLTYP for referencing in SLASD3. */
  985. for (j = 1; j <= 4; ++j) {
  986. coltyp[j] = ctot[j - 1];
  987. /* L190: */
  988. }
  989. return 0;
  990. /* End of SLASD2 */
  991. } /* slasd2_ */