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.

dbdsvdx.c 40 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370
  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 doublereal c_b10 = 1.;
  381. static doublereal c_b14 = -.125;
  382. static integer c__1 = 1;
  383. static doublereal c_b19 = 0.;
  384. static integer c__2 = 2;
  385. /* > \brief \b DBDSVDX */
  386. /* =========== DOCUMENTATION =========== */
  387. /* Online html documentation available at */
  388. /* http://www.netlib.org/lapack/explore-html/ */
  389. /* > \htmlonly */
  390. /* > Download DBDSVDX + dependencies */
  391. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dbdsvdx
  392. .f"> */
  393. /* > [TGZ]</a> */
  394. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dbdsvdx
  395. .f"> */
  396. /* > [ZIP]</a> */
  397. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dbdsvdx
  398. .f"> */
  399. /* > [TXT]</a> */
  400. /* > \endhtmlonly */
  401. /* Definition: */
  402. /* =========== */
  403. /* SUBROUTINE DBDSVDX( UPLO, JOBZ, RANGE, N, D, E, VL, VU, IL, IU, */
  404. /* $ NS, S, Z, LDZ, WORK, IWORK, INFO ) */
  405. /* CHARACTER JOBZ, RANGE, UPLO */
  406. /* INTEGER IL, INFO, IU, LDZ, N, NS */
  407. /* DOUBLE PRECISION VL, VU */
  408. /* INTEGER IWORK( * ) */
  409. /* DOUBLE PRECISION D( * ), E( * ), S( * ), WORK( * ), */
  410. /* Z( LDZ, * ) */
  411. /* > \par Purpose: */
  412. /* ============= */
  413. /* > */
  414. /* > \verbatim */
  415. /* > */
  416. /* > DBDSVDX computes the singular value decomposition (SVD) of a real */
  417. /* > N-by-N (upper or lower) bidiagonal matrix B, B = U * S * VT, */
  418. /* > where S is a diagonal matrix with non-negative diagonal elements */
  419. /* > (the singular values of B), and U and VT are orthogonal matrices */
  420. /* > of left and right singular vectors, respectively. */
  421. /* > */
  422. /* > Given an upper bidiagonal B with diagonal D = [ d_1 d_2 ... d_N ] */
  423. /* > and superdiagonal E = [ e_1 e_2 ... e_N-1 ], DBDSVDX computes the */
  424. /* > singular value decompositon of B through the eigenvalues and */
  425. /* > eigenvectors of the N*2-by-N*2 tridiagonal matrix */
  426. /* > */
  427. /* > | 0 d_1 | */
  428. /* > | d_1 0 e_1 | */
  429. /* > TGK = | e_1 0 d_2 | */
  430. /* > | d_2 . . | */
  431. /* > | . . . | */
  432. /* > */
  433. /* > If (s,u,v) is a singular triplet of B with ||u|| = ||v|| = 1, then */
  434. /* > (+/-s,q), ||q|| = 1, are eigenpairs of TGK, with q = P * ( u' +/-v' ) / */
  435. /* > sqrt(2) = ( v_1 u_1 v_2 u_2 ... v_n u_n ) / sqrt(2), and */
  436. /* > P = [ e_{n+1} e_{1} e_{n+2} e_{2} ... ]. */
  437. /* > */
  438. /* > Given a TGK matrix, one can either a) compute -s,-v and change signs */
  439. /* > so that the singular values (and corresponding vectors) are already in */
  440. /* > descending order (as in DGESVD/DGESDD) or b) compute s,v and reorder */
  441. /* > the values (and corresponding vectors). DBDSVDX implements a) by */
  442. /* > calling DSTEVX (bisection plus inverse iteration, to be replaced */
  443. /* > with a version of the Multiple Relative Robust Representation */
  444. /* > algorithm. (See P. Willems and B. Lang, A framework for the MR^3 */
  445. /* > algorithm: theory and implementation, SIAM J. Sci. Comput., */
  446. /* > 35:740-766, 2013.) */
  447. /* > \endverbatim */
  448. /* Arguments: */
  449. /* ========== */
  450. /* > \param[in] UPLO */
  451. /* > \verbatim */
  452. /* > UPLO is CHARACTER*1 */
  453. /* > = 'U': B is upper bidiagonal; */
  454. /* > = 'L': B is lower bidiagonal. */
  455. /* > \endverbatim */
  456. /* > */
  457. /* > \param[in] JOBZ */
  458. /* > \verbatim */
  459. /* > JOBZ is CHARACTER*1 */
  460. /* > = 'N': Compute singular values only; */
  461. /* > = 'V': Compute singular values and singular vectors. */
  462. /* > \endverbatim */
  463. /* > */
  464. /* > \param[in] RANGE */
  465. /* > \verbatim */
  466. /* > RANGE is CHARACTER*1 */
  467. /* > = 'A': all singular values will be found. */
  468. /* > = 'V': all singular values in the half-open interval [VL,VU) */
  469. /* > will be found. */
  470. /* > = 'I': the IL-th through IU-th singular values will be found. */
  471. /* > \endverbatim */
  472. /* > */
  473. /* > \param[in] N */
  474. /* > \verbatim */
  475. /* > N is INTEGER */
  476. /* > The order of the bidiagonal matrix. N >= 0. */
  477. /* > \endverbatim */
  478. /* > */
  479. /* > \param[in] D */
  480. /* > \verbatim */
  481. /* > D is DOUBLE PRECISION array, dimension (N) */
  482. /* > The n diagonal elements of the bidiagonal matrix B. */
  483. /* > \endverbatim */
  484. /* > */
  485. /* > \param[in] E */
  486. /* > \verbatim */
  487. /* > E is DOUBLE PRECISION array, dimension (f2cmax(1,N-1)) */
  488. /* > The (n-1) superdiagonal elements of the bidiagonal matrix */
  489. /* > B in elements 1 to N-1. */
  490. /* > \endverbatim */
  491. /* > */
  492. /* > \param[in] VL */
  493. /* > \verbatim */
  494. /* > VL is DOUBLE PRECISION */
  495. /* > If RANGE='V', the lower bound of the interval to */
  496. /* > be searched for singular values. VU > VL. */
  497. /* > Not referenced if RANGE = 'A' or 'I'. */
  498. /* > \endverbatim */
  499. /* > */
  500. /* > \param[in] VU */
  501. /* > \verbatim */
  502. /* > VU is DOUBLE PRECISION */
  503. /* > If RANGE='V', the upper bound of the interval to */
  504. /* > be searched for singular values. VU > VL. */
  505. /* > Not referenced if RANGE = 'A' or 'I'. */
  506. /* > \endverbatim */
  507. /* > */
  508. /* > \param[in] IL */
  509. /* > \verbatim */
  510. /* > IL is INTEGER */
  511. /* > If RANGE='I', the index of the */
  512. /* > smallest singular value to be returned. */
  513. /* > 1 <= IL <= IU <= f2cmin(M,N), if f2cmin(M,N) > 0. */
  514. /* > Not referenced if RANGE = 'A' or 'V'. */
  515. /* > \endverbatim */
  516. /* > */
  517. /* > \param[in] IU */
  518. /* > \verbatim */
  519. /* > IU is INTEGER */
  520. /* > If RANGE='I', the index of the */
  521. /* > largest singular value to be returned. */
  522. /* > 1 <= IL <= IU <= f2cmin(M,N), if f2cmin(M,N) > 0. */
  523. /* > Not referenced if RANGE = 'A' or 'V'. */
  524. /* > \endverbatim */
  525. /* > */
  526. /* > \param[out] NS */
  527. /* > \verbatim */
  528. /* > NS is INTEGER */
  529. /* > The total number of singular values found. 0 <= NS <= N. */
  530. /* > If RANGE = 'A', NS = N, and if RANGE = 'I', NS = IU-IL+1. */
  531. /* > \endverbatim */
  532. /* > */
  533. /* > \param[out] S */
  534. /* > \verbatim */
  535. /* > S is DOUBLE PRECISION array, dimension (N) */
  536. /* > The first NS elements contain the selected singular values in */
  537. /* > ascending order. */
  538. /* > \endverbatim */
  539. /* > */
  540. /* > \param[out] Z */
  541. /* > \verbatim */
  542. /* > Z is DOUBLE PRECISION array, dimension (2*N,K) */
  543. /* > If JOBZ = 'V', then if INFO = 0 the first NS columns of Z */
  544. /* > contain the singular vectors of the matrix B corresponding to */
  545. /* > the selected singular values, with U in rows 1 to N and V */
  546. /* > in rows N+1 to N*2, i.e. */
  547. /* > Z = [ U ] */
  548. /* > [ V ] */
  549. /* > If JOBZ = 'N', then Z is not referenced. */
  550. /* > Note: The user must ensure that at least K = NS+1 columns are */
  551. /* > supplied in the array Z; if RANGE = 'V', the exact value of */
  552. /* > NS is not known in advance and an upper bound must be used. */
  553. /* > \endverbatim */
  554. /* > */
  555. /* > \param[in] LDZ */
  556. /* > \verbatim */
  557. /* > LDZ is INTEGER */
  558. /* > The leading dimension of the array Z. LDZ >= 1, and if */
  559. /* > JOBZ = 'V', LDZ >= f2cmax(2,N*2). */
  560. /* > \endverbatim */
  561. /* > */
  562. /* > \param[out] WORK */
  563. /* > \verbatim */
  564. /* > WORK is DOUBLE PRECISION array, dimension (14*N) */
  565. /* > \endverbatim */
  566. /* > */
  567. /* > \param[out] IWORK */
  568. /* > \verbatim */
  569. /* > IWORK is INTEGER array, dimension (12*N) */
  570. /* > If JOBZ = 'V', then if INFO = 0, the first NS elements of */
  571. /* > IWORK are zero. If INFO > 0, then IWORK contains the indices */
  572. /* > of the eigenvectors that failed to converge in DSTEVX. */
  573. /* > \endverbatim */
  574. /* > */
  575. /* > \param[out] INFO */
  576. /* > \verbatim */
  577. /* > INFO is INTEGER */
  578. /* > = 0: successful exit */
  579. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  580. /* > > 0: if INFO = i, then i eigenvectors failed to converge */
  581. /* > in DSTEVX. The indices of the eigenvectors */
  582. /* > (as returned by DSTEVX) are stored in the */
  583. /* > array IWORK. */
  584. /* > if INFO = N*2 + 1, an internal error occurred. */
  585. /* > \endverbatim */
  586. /* Authors: */
  587. /* ======== */
  588. /* > \author Univ. of Tennessee */
  589. /* > \author Univ. of California Berkeley */
  590. /* > \author Univ. of Colorado Denver */
  591. /* > \author NAG Ltd. */
  592. /* > \date June 2016 */
  593. /* > \ingroup doubleOTHEReigen */
  594. /* ===================================================================== */
  595. /* Subroutine */ int dbdsvdx_(char *uplo, char *jobz, char *range, integer *n,
  596. doublereal *d__, doublereal *e, doublereal *vl, doublereal *vu,
  597. integer *il, integer *iu, integer *ns, doublereal *s, doublereal *z__,
  598. integer *ldz, doublereal *work, integer *iwork, integer *info)
  599. {
  600. /* System generated locals */
  601. integer z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5;
  602. doublereal d__1, d__2, d__3, d__4;
  603. /* Local variables */
  604. doublereal emin;
  605. extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *,
  606. integer *);
  607. integer ntgk;
  608. doublereal smin, smax, nrmu, nrmv;
  609. extern doublereal dnrm2_(integer *, doublereal *, integer *);
  610. logical sveq0;
  611. integer i__, idbeg, j, k;
  612. doublereal sqrt2;
  613. integer idend;
  614. extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
  615. integer *);
  616. integer isbeg;
  617. extern logical lsame_(char *, char *);
  618. integer idtgk, ietgk, iltgk, itemp;
  619. extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
  620. doublereal *, integer *);
  621. integer icolz;
  622. logical allsv;
  623. integer idptr;
  624. logical indsv;
  625. integer ieptr, iutgk;
  626. extern /* Subroutine */ int daxpy_(integer *, doublereal *, doublereal *,
  627. integer *, doublereal *, integer *);
  628. doublereal vltgk;
  629. logical lower;
  630. extern /* Subroutine */ int dswap_(integer *, doublereal *, integer *,
  631. doublereal *, integer *);
  632. doublereal zjtji;
  633. logical split, valsv;
  634. integer isplt;
  635. doublereal ortol, vutgk;
  636. logical wantz;
  637. char rngvx[1];
  638. integer irowu, irowv, irowz;
  639. extern doublereal dlamch_(char *);
  640. integer iifail;
  641. doublereal mu;
  642. extern integer idamax_(integer *, doublereal *, integer *);
  643. extern /* Subroutine */ int dlaset_(char *, integer *, integer *,
  644. doublereal *, doublereal *, doublereal *, integer *),
  645. xerbla_(char *, integer *, ftnlen);
  646. doublereal abstol, thresh;
  647. integer iiwork;
  648. extern /* Subroutine */ int dstevx_(char *, char *, integer *, doublereal
  649. *, doublereal *, doublereal *, doublereal *, integer *, integer *,
  650. doublereal *, integer *, doublereal *, doublereal *, integer *,
  651. doublereal *, integer *, integer *, integer *),
  652. mecago_();
  653. doublereal eps;
  654. integer nsl;
  655. doublereal tol, ulp;
  656. integer nru, nrv;
  657. /* -- LAPACK driver routine (version 3.8.0) -- */
  658. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  659. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  660. /* November 2017 */
  661. /* ===================================================================== */
  662. /* Test the input parameters. */
  663. /* Parameter adjustments */
  664. --d__;
  665. --e;
  666. --s;
  667. z_dim1 = *ldz;
  668. z_offset = 1 + z_dim1 * 1;
  669. z__ -= z_offset;
  670. --work;
  671. --iwork;
  672. /* Function Body */
  673. allsv = lsame_(range, "A");
  674. valsv = lsame_(range, "V");
  675. indsv = lsame_(range, "I");
  676. wantz = lsame_(jobz, "V");
  677. lower = lsame_(uplo, "L");
  678. *info = 0;
  679. if (! lsame_(uplo, "U") && ! lower) {
  680. *info = -1;
  681. } else if (! (wantz || lsame_(jobz, "N"))) {
  682. *info = -2;
  683. } else if (! (allsv || valsv || indsv)) {
  684. *info = -3;
  685. } else if (*n < 0) {
  686. *info = -4;
  687. } else if (*n > 0) {
  688. if (valsv) {
  689. if (*vl < 0.) {
  690. *info = -7;
  691. } else if (*vu <= *vl) {
  692. *info = -8;
  693. }
  694. } else if (indsv) {
  695. if (*il < 1 || *il > f2cmax(1,*n)) {
  696. *info = -9;
  697. } else if (*iu < f2cmin(*n,*il) || *iu > *n) {
  698. *info = -10;
  699. }
  700. }
  701. }
  702. if (*info == 0) {
  703. if (*ldz < 1 || wantz && *ldz < *n << 1) {
  704. *info = -14;
  705. }
  706. }
  707. if (*info != 0) {
  708. i__1 = -(*info);
  709. xerbla_("DBDSVDX", &i__1, (ftnlen)7);
  710. return 0;
  711. }
  712. /* Quick return if possible (N.LE.1) */
  713. *ns = 0;
  714. if (*n == 0) {
  715. return 0;
  716. }
  717. if (*n == 1) {
  718. if (allsv || indsv) {
  719. *ns = 1;
  720. s[1] = abs(d__[1]);
  721. } else {
  722. if (*vl < abs(d__[1]) && *vu >= abs(d__[1])) {
  723. *ns = 1;
  724. s[1] = abs(d__[1]);
  725. }
  726. }
  727. if (wantz) {
  728. z__[z_dim1 + 1] = d_sign(&c_b10, &d__[1]);
  729. z__[z_dim1 + 2] = 1.;
  730. }
  731. return 0;
  732. }
  733. abstol = dlamch_("Safe Minimum") * 2;
  734. ulp = dlamch_("Precision");
  735. eps = dlamch_("Epsilon");
  736. sqrt2 = sqrt(2.);
  737. ortol = sqrt(ulp);
  738. /* Criterion for splitting is taken from DBDSQR when singular */
  739. /* values are computed to relative accuracy TOL. (See J. Demmel and */
  740. /* W. Kahan, Accurate singular values of bidiagonal matrices, SIAM */
  741. /* J. Sci. and Stat. Comput., 11:873–912, 1990.) */
  742. /* Computing MAX */
  743. /* Computing MIN */
  744. d__3 = 100., d__4 = pow_dd(&eps, &c_b14);
  745. d__1 = 10., d__2 = f2cmin(d__3,d__4);
  746. tol = f2cmax(d__1,d__2) * eps;
  747. /* Compute approximate maximum, minimum singular values. */
  748. i__ = idamax_(n, &d__[1], &c__1);
  749. smax = (d__1 = d__[i__], abs(d__1));
  750. i__1 = *n - 1;
  751. i__ = idamax_(&i__1, &e[1], &c__1);
  752. /* Computing MAX */
  753. d__2 = smax, d__3 = (d__1 = e[i__], abs(d__1));
  754. smax = f2cmax(d__2,d__3);
  755. /* Compute threshold for neglecting D's and E's. */
  756. smin = abs(d__[1]);
  757. if (smin != 0.) {
  758. mu = smin;
  759. i__1 = *n;
  760. for (i__ = 2; i__ <= i__1; ++i__) {
  761. mu = (d__2 = d__[i__], abs(d__2)) * (mu / (mu + (d__1 = e[i__ - 1]
  762. , abs(d__1))));
  763. smin = f2cmin(smin,mu);
  764. if (smin == 0.) {
  765. myexit_();
  766. }
  767. }
  768. }
  769. smin /= sqrt((doublereal) (*n));
  770. thresh = tol * smin;
  771. /* Check for zeros in D and E (splits), i.e. submatrices. */
  772. i__1 = *n - 1;
  773. for (i__ = 1; i__ <= i__1; ++i__) {
  774. if ((d__1 = d__[i__], abs(d__1)) <= thresh) {
  775. d__[i__] = 0.;
  776. }
  777. if ((d__1 = e[i__], abs(d__1)) <= thresh) {
  778. e[i__] = 0.;
  779. }
  780. }
  781. if ((d__1 = d__[*n], abs(d__1)) <= thresh) {
  782. d__[*n] = 0.;
  783. }
  784. /* Pointers for arrays used by DSTEVX. */
  785. idtgk = 1;
  786. ietgk = idtgk + (*n << 1);
  787. itemp = ietgk + (*n << 1);
  788. iifail = 1;
  789. iiwork = iifail + (*n << 1);
  790. /* Set RNGVX, which corresponds to RANGE for DSTEVX in TGK mode. */
  791. /* VL,VU or IL,IU are redefined to conform to implementation a) */
  792. /* described in the leading comments. */
  793. iltgk = 0;
  794. iutgk = 0;
  795. vltgk = 0.;
  796. vutgk = 0.;
  797. if (allsv) {
  798. /* All singular values will be found. We aim at -s (see */
  799. /* leading comments) with RNGVX = 'I'. IL and IU are set */
  800. /* later (as ILTGK and IUTGK) according to the dimension */
  801. /* of the active submatrix. */
  802. *(unsigned char *)rngvx = 'I';
  803. if (wantz) {
  804. i__1 = *n << 1;
  805. i__2 = *n + 1;
  806. dlaset_("F", &i__1, &i__2, &c_b19, &c_b19, &z__[z_offset], ldz);
  807. }
  808. } else if (valsv) {
  809. /* Find singular values in a half-open interval. We aim */
  810. /* at -s (see leading comments) and we swap VL and VU */
  811. /* (as VUTGK and VLTGK), changing their signs. */
  812. *(unsigned char *)rngvx = 'V';
  813. vltgk = -(*vu);
  814. vutgk = -(*vl);
  815. i__1 = idtgk + (*n << 1) - 1;
  816. for (i__ = idtgk; i__ <= i__1; ++i__) {
  817. work[i__] = 0.;
  818. }
  819. /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
  820. dcopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
  821. i__1 = *n - 1;
  822. dcopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
  823. i__1 = *n << 1;
  824. dstevx_("N", "V", &i__1, &work[idtgk], &work[ietgk], &vltgk, &vutgk, &
  825. iltgk, &iltgk, &abstol, ns, &s[1], &z__[z_offset], ldz, &work[
  826. itemp], &iwork[iiwork], &iwork[iifail], info);
  827. if (*ns == 0) {
  828. return 0;
  829. } else {
  830. if (wantz) {
  831. i__1 = *n << 1;
  832. dlaset_("F", &i__1, ns, &c_b19, &c_b19, &z__[z_offset], ldz);
  833. }
  834. }
  835. } else if (indsv) {
  836. /* Find the IL-th through the IU-th singular values. We aim */
  837. /* at -s (see leading comments) and indices are mapped into */
  838. /* values, therefore mimicking DSTEBZ, where */
  839. /* GL = GL - FUDGE*TNORM*ULP*N - FUDGE*TWO*PIVMIN */
  840. /* GU = GU + FUDGE*TNORM*ULP*N + FUDGE*PIVMIN */
  841. iltgk = *il;
  842. iutgk = *iu;
  843. *(unsigned char *)rngvx = 'V';
  844. i__1 = idtgk + (*n << 1) - 1;
  845. for (i__ = idtgk; i__ <= i__1; ++i__) {
  846. work[i__] = 0.;
  847. }
  848. /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
  849. dcopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
  850. i__1 = *n - 1;
  851. dcopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
  852. i__1 = *n << 1;
  853. dstevx_("N", "I", &i__1, &work[idtgk], &work[ietgk], &vltgk, &vltgk, &
  854. iltgk, &iltgk, &abstol, ns, &s[1], &z__[z_offset], ldz, &work[
  855. itemp], &iwork[iiwork], &iwork[iifail], info);
  856. vltgk = s[1] - smax * 2. * ulp * *n;
  857. i__1 = idtgk + (*n << 1) - 1;
  858. for (i__ = idtgk; i__ <= i__1; ++i__) {
  859. work[i__] = 0.;
  860. }
  861. /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
  862. dcopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
  863. i__1 = *n - 1;
  864. dcopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
  865. i__1 = *n << 1;
  866. dstevx_("N", "I", &i__1, &work[idtgk], &work[ietgk], &vutgk, &vutgk, &
  867. iutgk, &iutgk, &abstol, ns, &s[1], &z__[z_offset], ldz, &work[
  868. itemp], &iwork[iiwork], &iwork[iifail], info);
  869. vutgk = s[1] + smax * 2. * ulp * *n;
  870. vutgk = f2cmin(vutgk,0.);
  871. /* If VLTGK=VUTGK, DSTEVX returns an error message, */
  872. /* so if needed we change VUTGK slightly. */
  873. if (vltgk == vutgk) {
  874. vltgk -= tol;
  875. }
  876. if (wantz) {
  877. i__1 = *n << 1;
  878. i__2 = *iu - *il + 1;
  879. dlaset_("F", &i__1, &i__2, &c_b19, &c_b19, &z__[z_offset], ldz);
  880. }
  881. }
  882. /* Initialize variables and pointers for S, Z, and WORK. */
  883. /* NRU, NRV: number of rows in U and V for the active submatrix */
  884. /* IDBEG, ISBEG: offsets for the entries of D and S */
  885. /* IROWZ, ICOLZ: offsets for the rows and columns of Z */
  886. /* IROWU, IROWV: offsets for the rows of U and V */
  887. *ns = 0;
  888. nru = 0;
  889. nrv = 0;
  890. idbeg = 1;
  891. isbeg = 1;
  892. irowz = 1;
  893. icolz = 1;
  894. irowu = 2;
  895. irowv = 1;
  896. split = FALSE_;
  897. sveq0 = FALSE_;
  898. /* Form the tridiagonal TGK matrix. */
  899. i__1 = *n;
  900. for (i__ = 1; i__ <= i__1; ++i__) {
  901. s[i__] = 0.;
  902. }
  903. /* S( 1:N ) = ZERO */
  904. work[ietgk + (*n << 1) - 1] = 0.;
  905. i__1 = idtgk + (*n << 1) - 1;
  906. for (i__ = idtgk; i__ <= i__1; ++i__) {
  907. work[i__] = 0.;
  908. }
  909. /* WORK( IDTGK:IDTGK+2*N-1 ) = ZERO */
  910. dcopy_(n, &d__[1], &c__1, &work[ietgk], &c__2);
  911. i__1 = *n - 1;
  912. dcopy_(&i__1, &e[1], &c__1, &work[ietgk + 1], &c__2);
  913. /* Check for splits in two levels, outer level */
  914. /* in E and inner level in D. */
  915. i__1 = *n << 1;
  916. for (ieptr = 2; ieptr <= i__1; ieptr += 2) {
  917. if (work[ietgk + ieptr - 1] == 0.) {
  918. /* Split in E (this piece of B is square) or bottom */
  919. /* of the (input bidiagonal) matrix. */
  920. isplt = idbeg;
  921. idend = ieptr - 1;
  922. i__2 = idend;
  923. for (idptr = idbeg; idptr <= i__2; idptr += 2) {
  924. if (work[ietgk + idptr - 1] == 0.) {
  925. /* Split in D (rectangular submatrix). Set the number */
  926. /* of rows in U and V (NRU and NRV) accordingly. */
  927. if (idptr == idbeg) {
  928. /* D=0 at the top. */
  929. sveq0 = TRUE_;
  930. if (idbeg == idend) {
  931. nru = 1;
  932. nrv = 1;
  933. }
  934. } else if (idptr == idend) {
  935. /* D=0 at the bottom. */
  936. sveq0 = TRUE_;
  937. nru = (idend - isplt) / 2 + 1;
  938. nrv = nru;
  939. if (isplt != idbeg) {
  940. ++nru;
  941. }
  942. } else {
  943. if (isplt == idbeg) {
  944. /* Split: top rectangular submatrix. */
  945. nru = (idptr - idbeg) / 2;
  946. nrv = nru + 1;
  947. } else {
  948. /* Split: middle square submatrix. */
  949. nru = (idptr - isplt) / 2 + 1;
  950. nrv = nru;
  951. }
  952. }
  953. } else if (idptr == idend) {
  954. /* Last entry of D in the active submatrix. */
  955. if (isplt == idbeg) {
  956. /* No split (trivial case). */
  957. nru = (idend - idbeg) / 2 + 1;
  958. nrv = nru;
  959. } else {
  960. /* Split: bottom rectangular submatrix. */
  961. nrv = (idend - isplt) / 2 + 1;
  962. nru = nrv + 1;
  963. }
  964. }
  965. ntgk = nru + nrv;
  966. if (ntgk > 0) {
  967. /* Compute eigenvalues/vectors of the active */
  968. /* submatrix according to RANGE: */
  969. /* if RANGE='A' (ALLSV) then RNGVX = 'I' */
  970. /* if RANGE='V' (VALSV) then RNGVX = 'V' */
  971. /* if RANGE='I' (INDSV) then RNGVX = 'V' */
  972. iltgk = 1;
  973. iutgk = ntgk / 2;
  974. if (allsv || vutgk == 0.) {
  975. if (sveq0 || smin < eps || ntgk % 2 > 0) {
  976. /* Special case: eigenvalue equal to zero or very */
  977. /* small, additional eigenvector is needed. */
  978. ++iutgk;
  979. }
  980. }
  981. /* Workspace needed by DSTEVX: */
  982. /* WORK( ITEMP: ): 2*5*NTGK */
  983. /* IWORK( 1: ): 2*6*NTGK */
  984. dstevx_(jobz, rngvx, &ntgk, &work[idtgk + isplt - 1], &
  985. work[ietgk + isplt - 1], &vltgk, &vutgk, &iltgk, &
  986. iutgk, &abstol, &nsl, &s[isbeg], &z__[irowz +
  987. icolz * z_dim1], ldz, &work[itemp], &iwork[iiwork]
  988. , &iwork[iifail], info);
  989. if (*info != 0) {
  990. /* Exit with the error code from DSTEVX. */
  991. return 0;
  992. }
  993. emin = (d__1 = s[isbeg], abs(d__1));
  994. i__3 = isbeg + nsl - 1;
  995. for (i__ = isbeg; i__ <= i__3; ++i__) {
  996. if ((d__1 = s[i__], abs(d__1)) > emin) {
  997. emin = s[i__];
  998. }
  999. }
  1000. /* EMIN = ABS( MAXVAL( S( ISBEG:ISBEG+NSL-1 ) ) ) */
  1001. if (nsl > 0 && wantz) {
  1002. /* Normalize u=Z([2,4,...],:) and v=Z([1,3,...],:), */
  1003. /* changing the sign of v as discussed in the leading */
  1004. /* comments. The norms of u and v may be (slightly) */
  1005. /* different from 1/sqrt(2) if the corresponding */
  1006. /* eigenvalues are very small or too close. We check */
  1007. /* those norms and, if needed, reorthogonalize the */
  1008. /* vectors. */
  1009. if (nsl > 1 && vutgk == 0. && ntgk % 2 == 0 && emin ==
  1010. 0. && ! split) {
  1011. /* D=0 at the top or bottom of the active submatrix: */
  1012. /* one eigenvalue is equal to zero; concatenate the */
  1013. /* eigenvectors corresponding to the two smallest */
  1014. /* eigenvalues. */
  1015. i__3 = irowz + ntgk - 1;
  1016. for (i__ = irowz; i__ <= i__3; ++i__) {
  1017. z__[i__ + (icolz + nsl - 2) * z_dim1] += z__[
  1018. i__ + (icolz + nsl - 1) * z_dim1];
  1019. z__[i__ + (icolz + nsl - 1) * z_dim1] = 0.;
  1020. }
  1021. /* Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-2 ) = */
  1022. /* $ Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-2 ) + */
  1023. /* $ Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-1 ) */
  1024. /* Z( IROWZ:IROWZ+NTGK-1,ICOLZ+NSL-1 ) = */
  1025. /* $ ZERO */
  1026. /* IF( IUTGK*2.GT.NTGK ) THEN */
  1027. /* Eigenvalue equal to zero or very small. */
  1028. /* NSL = NSL - 1 */
  1029. /* END IF */
  1030. }
  1031. /* Computing MIN */
  1032. i__4 = nsl - 1, i__5 = nru - 1;
  1033. i__3 = f2cmin(i__4,i__5);
  1034. for (i__ = 0; i__ <= i__3; ++i__) {
  1035. nrmu = dnrm2_(&nru, &z__[irowu + (icolz + i__) *
  1036. z_dim1], &c__2);
  1037. if (nrmu == 0.) {
  1038. *info = (*n << 1) + 1;
  1039. return 0;
  1040. }
  1041. d__1 = 1. / nrmu;
  1042. dscal_(&nru, &d__1, &z__[irowu + (icolz + i__) *
  1043. z_dim1], &c__2);
  1044. if (nrmu != 1. && (d__1 = nrmu - ortol, abs(d__1))
  1045. * sqrt2 > 1.) {
  1046. i__4 = i__ - 1;
  1047. for (j = 0; j <= i__4; ++j) {
  1048. zjtji = -ddot_(&nru, &z__[irowu + (icolz
  1049. + j) * z_dim1], &c__2, &z__[irowu
  1050. + (icolz + i__) * z_dim1], &c__2);
  1051. daxpy_(&nru, &zjtji, &z__[irowu + (icolz
  1052. + j) * z_dim1], &c__2, &z__[irowu
  1053. + (icolz + i__) * z_dim1], &c__2);
  1054. }
  1055. nrmu = dnrm2_(&nru, &z__[irowu + (icolz + i__)
  1056. * z_dim1], &c__2);
  1057. d__1 = 1. / nrmu;
  1058. dscal_(&nru, &d__1, &z__[irowu + (icolz + i__)
  1059. * z_dim1], &c__2);
  1060. }
  1061. }
  1062. /* Computing MIN */
  1063. i__4 = nsl - 1, i__5 = nrv - 1;
  1064. i__3 = f2cmin(i__4,i__5);
  1065. for (i__ = 0; i__ <= i__3; ++i__) {
  1066. nrmv = dnrm2_(&nrv, &z__[irowv + (icolz + i__) *
  1067. z_dim1], &c__2);
  1068. if (nrmv == 0.) {
  1069. *info = (*n << 1) + 1;
  1070. return 0;
  1071. }
  1072. d__1 = -1. / nrmv;
  1073. dscal_(&nrv, &d__1, &z__[irowv + (icolz + i__) *
  1074. z_dim1], &c__2);
  1075. if (nrmv != 1. && (d__1 = nrmv - ortol, abs(d__1))
  1076. * sqrt2 > 1.) {
  1077. i__4 = i__ - 1;
  1078. for (j = 0; j <= i__4; ++j) {
  1079. zjtji = -ddot_(&nrv, &z__[irowv + (icolz
  1080. + j) * z_dim1], &c__2, &z__[irowv
  1081. + (icolz + i__) * z_dim1], &c__2);
  1082. daxpy_(&nru, &zjtji, &z__[irowv + (icolz
  1083. + j) * z_dim1], &c__2, &z__[irowv
  1084. + (icolz + i__) * z_dim1], &c__2);
  1085. }
  1086. nrmv = dnrm2_(&nrv, &z__[irowv + (icolz + i__)
  1087. * z_dim1], &c__2);
  1088. d__1 = 1. / nrmv;
  1089. dscal_(&nrv, &d__1, &z__[irowv + (icolz + i__)
  1090. * z_dim1], &c__2);
  1091. }
  1092. }
  1093. if (vutgk == 0. && idptr < idend && ntgk % 2 > 0) {
  1094. /* D=0 in the middle of the active submatrix (one */
  1095. /* eigenvalue is equal to zero): save the corresponding */
  1096. /* eigenvector for later use (when bottom of the */
  1097. /* active submatrix is reached). */
  1098. split = TRUE_;
  1099. i__3 = irowz + ntgk - 1;
  1100. for (i__ = irowz; i__ <= i__3; ++i__) {
  1101. z__[i__ + (*n + 1) * z_dim1] = z__[i__ + (*ns
  1102. + nsl) * z_dim1];
  1103. z__[i__ + (*ns + nsl) * z_dim1] = 0.;
  1104. }
  1105. /* Z( IROWZ:IROWZ+NTGK-1,N+1 ) = */
  1106. /* $ Z( IROWZ:IROWZ+NTGK-1,NS+NSL ) */
  1107. /* Z( IROWZ:IROWZ+NTGK-1,NS+NSL ) = */
  1108. /* $ ZERO */
  1109. }
  1110. }
  1111. /* ** WANTZ **! */
  1112. nsl = f2cmin(nsl,nru);
  1113. sveq0 = FALSE_;
  1114. /* Absolute values of the eigenvalues of TGK. */
  1115. i__3 = nsl - 1;
  1116. for (i__ = 0; i__ <= i__3; ++i__) {
  1117. s[isbeg + i__] = (d__1 = s[isbeg + i__], abs(d__1));
  1118. }
  1119. /* Update pointers for TGK, S and Z. */
  1120. isbeg += nsl;
  1121. irowz += ntgk;
  1122. icolz += nsl;
  1123. irowu = irowz;
  1124. irowv = irowz + 1;
  1125. isplt = idptr + 1;
  1126. *ns += nsl;
  1127. nru = 0;
  1128. nrv = 0;
  1129. }
  1130. /* ** NTGK.GT.0 **! */
  1131. if (irowz < *n << 1 && wantz) {
  1132. i__3 = irowz - 1;
  1133. for (i__ = 1; i__ <= i__3; ++i__) {
  1134. z__[i__ + icolz * z_dim1] = 0.;
  1135. }
  1136. /* Z( 1:IROWZ-1, ICOLZ ) = ZERO */
  1137. }
  1138. }
  1139. /* ** IDPTR loop **! */
  1140. if (split && wantz) {
  1141. /* Bring back eigenvector corresponding */
  1142. /* to eigenvalue equal to zero. */
  1143. i__2 = idend - ntgk + 1;
  1144. for (i__ = idbeg; i__ <= i__2; ++i__) {
  1145. z__[i__ + (isbeg - 1) * z_dim1] += z__[i__ + (*n + 1) *
  1146. z_dim1];
  1147. z__[i__ + (*n + 1) * z_dim1] = 0.;
  1148. }
  1149. /* Z( IDBEG:IDEND-NTGK+1,ISBEG-1 ) = */
  1150. /* $ Z( IDBEG:IDEND-NTGK+1,ISBEG-1 ) + */
  1151. /* $ Z( IDBEG:IDEND-NTGK+1,N+1 ) */
  1152. /* Z( IDBEG:IDEND-NTGK+1,N+1 ) = 0 */
  1153. }
  1154. --irowv;
  1155. ++irowu;
  1156. idbeg = ieptr + 1;
  1157. sveq0 = FALSE_;
  1158. split = FALSE_;
  1159. }
  1160. /* ** Check for split in E **! */
  1161. }
  1162. /* Sort the singular values into decreasing order (insertion sort on */
  1163. /* singular values, but only one transposition per singular vector) */
  1164. /* ** IEPTR loop **! */
  1165. i__1 = *ns - 1;
  1166. for (i__ = 1; i__ <= i__1; ++i__) {
  1167. k = 1;
  1168. smin = s[1];
  1169. i__2 = *ns + 1 - i__;
  1170. for (j = 2; j <= i__2; ++j) {
  1171. if (s[j] <= smin) {
  1172. k = j;
  1173. smin = s[j];
  1174. }
  1175. }
  1176. if (k != *ns + 1 - i__) {
  1177. s[k] = s[*ns + 1 - i__];
  1178. s[*ns + 1 - i__] = smin;
  1179. if (wantz) {
  1180. i__2 = *n << 1;
  1181. dswap_(&i__2, &z__[k * z_dim1 + 1], &c__1, &z__[(*ns + 1 -
  1182. i__) * z_dim1 + 1], &c__1);
  1183. }
  1184. }
  1185. }
  1186. /* If RANGE=I, check for singular values/vectors to be discarded. */
  1187. if (indsv) {
  1188. k = *iu - *il + 1;
  1189. if (k < *ns) {
  1190. i__1 = *ns;
  1191. for (i__ = k + 1; i__ <= i__1; ++i__) {
  1192. s[i__] = 0.;
  1193. }
  1194. /* S( K+1:NS ) = ZERO */
  1195. if (wantz) {
  1196. i__1 = *n << 1;
  1197. for (i__ = 1; i__ <= i__1; ++i__) {
  1198. i__2 = *ns;
  1199. for (j = k + 1; j <= i__2; ++j) {
  1200. z__[i__ + j * z_dim1] = 0.;
  1201. }
  1202. }
  1203. /* Z( 1:N*2,K+1:NS ) = ZERO */
  1204. }
  1205. *ns = k;
  1206. }
  1207. }
  1208. /* Reorder Z: U = Z( 1:N,1:NS ), V = Z( N+1:N*2,1:NS ). */
  1209. /* If B is a lower diagonal, swap U and V. */
  1210. if (wantz) {
  1211. i__1 = *ns;
  1212. for (i__ = 1; i__ <= i__1; ++i__) {
  1213. i__2 = *n << 1;
  1214. dcopy_(&i__2, &z__[i__ * z_dim1 + 1], &c__1, &work[1], &c__1);
  1215. if (lower) {
  1216. dcopy_(n, &work[2], &c__2, &z__[*n + 1 + i__ * z_dim1], &c__1)
  1217. ;
  1218. dcopy_(n, &work[1], &c__2, &z__[i__ * z_dim1 + 1], &c__1);
  1219. } else {
  1220. dcopy_(n, &work[2], &c__2, &z__[i__ * z_dim1 + 1], &c__1);
  1221. dcopy_(n, &work[1], &c__2, &z__[*n + 1 + i__ * z_dim1], &c__1)
  1222. ;
  1223. }
  1224. }
  1225. }
  1226. return 0;
  1227. /* End of DBDSVDX */
  1228. } /* dbdsvdx_ */