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.

clalsd.c 35 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203
  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 complex c_b1 = {0.f,0.f};
  363. static integer c__1 = 1;
  364. static integer c__0 = 0;
  365. static real c_b10 = 1.f;
  366. static real c_b35 = 0.f;
  367. /* > \brief \b CLALSD uses the singular value decomposition of A to solve the least squares problem. */
  368. /* =========== DOCUMENTATION =========== */
  369. /* Online html documentation available at */
  370. /* http://www.netlib.org/lapack/explore-html/ */
  371. /* > \htmlonly */
  372. /* > Download CLALSD + dependencies */
  373. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clalsd.
  374. f"> */
  375. /* > [TGZ]</a> */
  376. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clalsd.
  377. f"> */
  378. /* > [ZIP]</a> */
  379. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clalsd.
  380. f"> */
  381. /* > [TXT]</a> */
  382. /* > \endhtmlonly */
  383. /* Definition: */
  384. /* =========== */
  385. /* SUBROUTINE CLALSD( UPLO, SMLSIZ, N, NRHS, D, E, B, LDB, RCOND, */
  386. /* RANK, WORK, RWORK, IWORK, INFO ) */
  387. /* CHARACTER UPLO */
  388. /* INTEGER INFO, LDB, N, NRHS, RANK, SMLSIZ */
  389. /* REAL RCOND */
  390. /* INTEGER IWORK( * ) */
  391. /* REAL D( * ), E( * ), RWORK( * ) */
  392. /* COMPLEX B( LDB, * ), WORK( * ) */
  393. /* > \par Purpose: */
  394. /* ============= */
  395. /* > */
  396. /* > \verbatim */
  397. /* > */
  398. /* > CLALSD uses the singular value decomposition of A to solve the least */
  399. /* > squares problem of finding X to minimize the Euclidean norm of each */
  400. /* > column of A*X-B, where A is N-by-N upper bidiagonal, and X and B */
  401. /* > are N-by-NRHS. The solution X overwrites B. */
  402. /* > */
  403. /* > The singular values of A smaller than RCOND times the largest */
  404. /* > singular value are treated as zero in solving the least squares */
  405. /* > problem; in this case a minimum norm solution is returned. */
  406. /* > The actual singular values are returned in D in ascending order. */
  407. /* > */
  408. /* > This code makes very mild assumptions about floating point */
  409. /* > arithmetic. It will work on machines with a guard digit in */
  410. /* > add/subtract, or on those binary machines without guard digits */
  411. /* > which subtract like the Cray XMP, Cray YMP, Cray C 90, or Cray 2. */
  412. /* > It could conceivably fail on hexadecimal or decimal machines */
  413. /* > without guard digits, but we know of none. */
  414. /* > \endverbatim */
  415. /* Arguments: */
  416. /* ========== */
  417. /* > \param[in] UPLO */
  418. /* > \verbatim */
  419. /* > UPLO is CHARACTER*1 */
  420. /* > = 'U': D and E define an upper bidiagonal matrix. */
  421. /* > = 'L': D and E define a lower bidiagonal matrix. */
  422. /* > \endverbatim */
  423. /* > */
  424. /* > \param[in] SMLSIZ */
  425. /* > \verbatim */
  426. /* > SMLSIZ is INTEGER */
  427. /* > The maximum size of the subproblems at the bottom of the */
  428. /* > computation tree. */
  429. /* > \endverbatim */
  430. /* > */
  431. /* > \param[in] N */
  432. /* > \verbatim */
  433. /* > N is INTEGER */
  434. /* > The dimension of the bidiagonal matrix. N >= 0. */
  435. /* > \endverbatim */
  436. /* > */
  437. /* > \param[in] NRHS */
  438. /* > \verbatim */
  439. /* > NRHS is INTEGER */
  440. /* > The number of columns of B. NRHS must be at least 1. */
  441. /* > \endverbatim */
  442. /* > */
  443. /* > \param[in,out] D */
  444. /* > \verbatim */
  445. /* > D is REAL array, dimension (N) */
  446. /* > On entry D contains the main diagonal of the bidiagonal */
  447. /* > matrix. On exit, if INFO = 0, D contains its singular values. */
  448. /* > \endverbatim */
  449. /* > */
  450. /* > \param[in,out] E */
  451. /* > \verbatim */
  452. /* > E is REAL array, dimension (N-1) */
  453. /* > Contains the super-diagonal entries of the bidiagonal matrix. */
  454. /* > On exit, E has been destroyed. */
  455. /* > \endverbatim */
  456. /* > */
  457. /* > \param[in,out] B */
  458. /* > \verbatim */
  459. /* > B is COMPLEX array, dimension (LDB,NRHS) */
  460. /* > On input, B contains the right hand sides of the least */
  461. /* > squares problem. On output, B contains the solution X. */
  462. /* > \endverbatim */
  463. /* > */
  464. /* > \param[in] LDB */
  465. /* > \verbatim */
  466. /* > LDB is INTEGER */
  467. /* > The leading dimension of B in the calling subprogram. */
  468. /* > LDB must be at least f2cmax(1,N). */
  469. /* > \endverbatim */
  470. /* > */
  471. /* > \param[in] RCOND */
  472. /* > \verbatim */
  473. /* > RCOND is REAL */
  474. /* > The singular values of A less than or equal to RCOND times */
  475. /* > the largest singular value are treated as zero in solving */
  476. /* > the least squares problem. If RCOND is negative, */
  477. /* > machine precision is used instead. */
  478. /* > For example, if diag(S)*X=B were the least squares problem, */
  479. /* > where diag(S) is a diagonal matrix of singular values, the */
  480. /* > solution would be X(i) = B(i) / S(i) if S(i) is greater than */
  481. /* > RCOND*f2cmax(S), and X(i) = 0 if S(i) is less than or equal to */
  482. /* > RCOND*f2cmax(S). */
  483. /* > \endverbatim */
  484. /* > */
  485. /* > \param[out] RANK */
  486. /* > \verbatim */
  487. /* > RANK is INTEGER */
  488. /* > The number of singular values of A greater than RCOND times */
  489. /* > the largest singular value. */
  490. /* > \endverbatim */
  491. /* > */
  492. /* > \param[out] WORK */
  493. /* > \verbatim */
  494. /* > WORK is COMPLEX array, dimension (N * NRHS). */
  495. /* > \endverbatim */
  496. /* > */
  497. /* > \param[out] RWORK */
  498. /* > \verbatim */
  499. /* > RWORK is REAL array, dimension at least */
  500. /* > (9*N + 2*N*SMLSIZ + 8*N*NLVL + 3*SMLSIZ*NRHS + */
  501. /* > MAX( (SMLSIZ+1)**2, N*(1+NRHS) + 2*NRHS ), */
  502. /* > where */
  503. /* > NLVL = MAX( 0, INT( LOG_2( MIN( M,N )/(SMLSIZ+1) ) ) + 1 ) */
  504. /* > \endverbatim */
  505. /* > */
  506. /* > \param[out] IWORK */
  507. /* > \verbatim */
  508. /* > IWORK is INTEGER array, dimension (3*N*NLVL + 11*N). */
  509. /* > \endverbatim */
  510. /* > */
  511. /* > \param[out] INFO */
  512. /* > \verbatim */
  513. /* > INFO is INTEGER */
  514. /* > = 0: successful exit. */
  515. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  516. /* > > 0: The algorithm failed to compute a singular value while */
  517. /* > working on the submatrix lying in rows and columns */
  518. /* > INFO/(N+1) through MOD(INFO,N+1). */
  519. /* > \endverbatim */
  520. /* Authors: */
  521. /* ======== */
  522. /* > \author Univ. of Tennessee */
  523. /* > \author Univ. of California Berkeley */
  524. /* > \author Univ. of Colorado Denver */
  525. /* > \author NAG Ltd. */
  526. /* > \date December 2016 */
  527. /* > \ingroup complexOTHERcomputational */
  528. /* > \par Contributors: */
  529. /* ================== */
  530. /* > */
  531. /* > Ming Gu and Ren-Cang Li, Computer Science Division, University of */
  532. /* > California at Berkeley, USA \n */
  533. /* > Osni Marques, LBNL/NERSC, USA \n */
  534. /* ===================================================================== */
  535. /* Subroutine */ int clalsd_(char *uplo, integer *smlsiz, integer *n, integer
  536. *nrhs, real *d__, real *e, complex *b, integer *ldb, real *rcond,
  537. integer *rank, complex *work, real *rwork, integer *iwork, integer *
  538. info)
  539. {
  540. /* System generated locals */
  541. integer b_dim1, b_offset, i__1, i__2, i__3, i__4, i__5, i__6;
  542. real r__1;
  543. complex q__1;
  544. /* Local variables */
  545. integer difl, difr;
  546. real rcnd;
  547. integer jcol, irwb, perm, nsub, nlvl, sqre, bxst, jrow, irwu, c__, i__, j,
  548. k;
  549. real r__;
  550. integer s, u, jimag, z__, jreal;
  551. extern /* Subroutine */ int sgemm_(char *, char *, integer *, integer *,
  552. integer *, real *, real *, integer *, real *, integer *, real *,
  553. real *, integer *);
  554. integer irwib;
  555. extern /* Subroutine */ int ccopy_(integer *, complex *, integer *,
  556. complex *, integer *);
  557. integer poles, sizei, irwrb, nsize;
  558. extern /* Subroutine */ int csrot_(integer *, complex *, integer *,
  559. complex *, integer *, real *, real *);
  560. integer irwvt, icmpq1, icmpq2;
  561. real cs;
  562. integer bx;
  563. extern /* Subroutine */ int clalsa_(integer *, integer *, integer *,
  564. integer *, complex *, integer *, complex *, integer *, real *,
  565. integer *, real *, integer *, real *, real *, real *, real *,
  566. integer *, integer *, integer *, integer *, real *, real *, real *
  567. , real *, integer *, integer *);
  568. real sn;
  569. extern /* Subroutine */ int clascl_(char *, integer *, integer *, real *,
  570. real *, integer *, integer *, complex *, integer *, integer *);
  571. integer st;
  572. extern real slamch_(char *);
  573. extern /* Subroutine */ int slasda_(integer *, integer *, integer *,
  574. integer *, real *, real *, real *, integer *, real *, integer *,
  575. real *, real *, real *, real *, integer *, integer *, integer *,
  576. integer *, real *, real *, real *, real *, integer *, integer *);
  577. integer vt;
  578. extern /* Subroutine */ int clacpy_(char *, integer *, integer *, complex
  579. *, integer *, complex *, integer *), claset_(char *,
  580. integer *, integer *, complex *, complex *, complex *, integer *), xerbla_(char *, integer *, ftnlen), slascl_(char *,
  581. integer *, integer *, real *, real *, integer *, integer *, real *
  582. , integer *, integer *);
  583. extern integer isamax_(integer *, real *, integer *);
  584. integer givcol;
  585. extern /* Subroutine */ int slasdq_(char *, integer *, integer *, integer
  586. *, integer *, integer *, real *, real *, real *, integer *, real *
  587. , integer *, real *, integer *, real *, integer *),
  588. slaset_(char *, integer *, integer *, real *, real *, real *,
  589. integer *), slartg_(real *, real *, real *, real *, real *
  590. );
  591. real orgnrm;
  592. integer givnum;
  593. extern real slanst_(char *, integer *, real *, real *);
  594. extern /* Subroutine */ int slasrt_(char *, integer *, real *, integer *);
  595. integer givptr, nm1, nrwork, irwwrk, smlszp, st1;
  596. real eps;
  597. integer iwk;
  598. real tol;
  599. /* -- LAPACK computational routine (version 3.7.0) -- */
  600. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  601. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  602. /* December 2016 */
  603. /* ===================================================================== */
  604. /* Test the input parameters. */
  605. /* Parameter adjustments */
  606. --d__;
  607. --e;
  608. b_dim1 = *ldb;
  609. b_offset = 1 + b_dim1 * 1;
  610. b -= b_offset;
  611. --work;
  612. --rwork;
  613. --iwork;
  614. /* Function Body */
  615. *info = 0;
  616. if (*n < 0) {
  617. *info = -3;
  618. } else if (*nrhs < 1) {
  619. *info = -4;
  620. } else if (*ldb < 1 || *ldb < *n) {
  621. *info = -8;
  622. }
  623. if (*info != 0) {
  624. i__1 = -(*info);
  625. xerbla_("CLALSD", &i__1, (ftnlen)6);
  626. return 0;
  627. }
  628. eps = slamch_("Epsilon");
  629. /* Set up the tolerance. */
  630. if (*rcond <= 0.f || *rcond >= 1.f) {
  631. rcnd = eps;
  632. } else {
  633. rcnd = *rcond;
  634. }
  635. *rank = 0;
  636. /* Quick return if possible. */
  637. if (*n == 0) {
  638. return 0;
  639. } else if (*n == 1) {
  640. if (d__[1] == 0.f) {
  641. claset_("A", &c__1, nrhs, &c_b1, &c_b1, &b[b_offset], ldb);
  642. } else {
  643. *rank = 1;
  644. clascl_("G", &c__0, &c__0, &d__[1], &c_b10, &c__1, nrhs, &b[
  645. b_offset], ldb, info);
  646. d__[1] = abs(d__[1]);
  647. }
  648. return 0;
  649. }
  650. /* Rotate the matrix if it is lower bidiagonal. */
  651. if (*(unsigned char *)uplo == 'L') {
  652. i__1 = *n - 1;
  653. for (i__ = 1; i__ <= i__1; ++i__) {
  654. slartg_(&d__[i__], &e[i__], &cs, &sn, &r__);
  655. d__[i__] = r__;
  656. e[i__] = sn * d__[i__ + 1];
  657. d__[i__ + 1] = cs * d__[i__ + 1];
  658. if (*nrhs == 1) {
  659. csrot_(&c__1, &b[i__ + b_dim1], &c__1, &b[i__ + 1 + b_dim1], &
  660. c__1, &cs, &sn);
  661. } else {
  662. rwork[(i__ << 1) - 1] = cs;
  663. rwork[i__ * 2] = sn;
  664. }
  665. /* L10: */
  666. }
  667. if (*nrhs > 1) {
  668. i__1 = *nrhs;
  669. for (i__ = 1; i__ <= i__1; ++i__) {
  670. i__2 = *n - 1;
  671. for (j = 1; j <= i__2; ++j) {
  672. cs = rwork[(j << 1) - 1];
  673. sn = rwork[j * 2];
  674. csrot_(&c__1, &b[j + i__ * b_dim1], &c__1, &b[j + 1 + i__
  675. * b_dim1], &c__1, &cs, &sn);
  676. /* L20: */
  677. }
  678. /* L30: */
  679. }
  680. }
  681. }
  682. /* Scale. */
  683. nm1 = *n - 1;
  684. orgnrm = slanst_("M", n, &d__[1], &e[1]);
  685. if (orgnrm == 0.f) {
  686. claset_("A", n, nrhs, &c_b1, &c_b1, &b[b_offset], ldb);
  687. return 0;
  688. }
  689. slascl_("G", &c__0, &c__0, &orgnrm, &c_b10, n, &c__1, &d__[1], n, info);
  690. slascl_("G", &c__0, &c__0, &orgnrm, &c_b10, &nm1, &c__1, &e[1], &nm1,
  691. info);
  692. /* If N is smaller than the minimum divide size SMLSIZ, then solve */
  693. /* the problem with another solver. */
  694. if (*n <= *smlsiz) {
  695. irwu = 1;
  696. irwvt = irwu + *n * *n;
  697. irwwrk = irwvt + *n * *n;
  698. irwrb = irwwrk;
  699. irwib = irwrb + *n * *nrhs;
  700. irwb = irwib + *n * *nrhs;
  701. slaset_("A", n, n, &c_b35, &c_b10, &rwork[irwu], n);
  702. slaset_("A", n, n, &c_b35, &c_b10, &rwork[irwvt], n);
  703. slasdq_("U", &c__0, n, n, n, &c__0, &d__[1], &e[1], &rwork[irwvt], n,
  704. &rwork[irwu], n, &rwork[irwwrk], &c__1, &rwork[irwwrk], info);
  705. if (*info != 0) {
  706. return 0;
  707. }
  708. /* In the real version, B is passed to SLASDQ and multiplied */
  709. /* internally by Q**H. Here B is complex and that product is */
  710. /* computed below in two steps (real and imaginary parts). */
  711. j = irwb - 1;
  712. i__1 = *nrhs;
  713. for (jcol = 1; jcol <= i__1; ++jcol) {
  714. i__2 = *n;
  715. for (jrow = 1; jrow <= i__2; ++jrow) {
  716. ++j;
  717. i__3 = jrow + jcol * b_dim1;
  718. rwork[j] = b[i__3].r;
  719. /* L40: */
  720. }
  721. /* L50: */
  722. }
  723. sgemm_("T", "N", n, nrhs, n, &c_b10, &rwork[irwu], n, &rwork[irwb], n,
  724. &c_b35, &rwork[irwrb], n);
  725. j = irwb - 1;
  726. i__1 = *nrhs;
  727. for (jcol = 1; jcol <= i__1; ++jcol) {
  728. i__2 = *n;
  729. for (jrow = 1; jrow <= i__2; ++jrow) {
  730. ++j;
  731. rwork[j] = r_imag(&b[jrow + jcol * b_dim1]);
  732. /* L60: */
  733. }
  734. /* L70: */
  735. }
  736. sgemm_("T", "N", n, nrhs, n, &c_b10, &rwork[irwu], n, &rwork[irwb], n,
  737. &c_b35, &rwork[irwib], n);
  738. jreal = irwrb - 1;
  739. jimag = irwib - 1;
  740. i__1 = *nrhs;
  741. for (jcol = 1; jcol <= i__1; ++jcol) {
  742. i__2 = *n;
  743. for (jrow = 1; jrow <= i__2; ++jrow) {
  744. ++jreal;
  745. ++jimag;
  746. i__3 = jrow + jcol * b_dim1;
  747. i__4 = jreal;
  748. i__5 = jimag;
  749. q__1.r = rwork[i__4], q__1.i = rwork[i__5];
  750. b[i__3].r = q__1.r, b[i__3].i = q__1.i;
  751. /* L80: */
  752. }
  753. /* L90: */
  754. }
  755. tol = rcnd * (r__1 = d__[isamax_(n, &d__[1], &c__1)], abs(r__1));
  756. i__1 = *n;
  757. for (i__ = 1; i__ <= i__1; ++i__) {
  758. if (d__[i__] <= tol) {
  759. claset_("A", &c__1, nrhs, &c_b1, &c_b1, &b[i__ + b_dim1], ldb);
  760. } else {
  761. clascl_("G", &c__0, &c__0, &d__[i__], &c_b10, &c__1, nrhs, &b[
  762. i__ + b_dim1], ldb, info);
  763. ++(*rank);
  764. }
  765. /* L100: */
  766. }
  767. /* Since B is complex, the following call to SGEMM is performed */
  768. /* in two steps (real and imaginary parts). That is for V * B */
  769. /* (in the real version of the code V**H is stored in WORK). */
  770. /* CALL SGEMM( 'T', 'N', N, NRHS, N, ONE, WORK, N, B, LDB, ZERO, */
  771. /* $ WORK( NWORK ), N ) */
  772. j = irwb - 1;
  773. i__1 = *nrhs;
  774. for (jcol = 1; jcol <= i__1; ++jcol) {
  775. i__2 = *n;
  776. for (jrow = 1; jrow <= i__2; ++jrow) {
  777. ++j;
  778. i__3 = jrow + jcol * b_dim1;
  779. rwork[j] = b[i__3].r;
  780. /* L110: */
  781. }
  782. /* L120: */
  783. }
  784. sgemm_("T", "N", n, nrhs, n, &c_b10, &rwork[irwvt], n, &rwork[irwb],
  785. n, &c_b35, &rwork[irwrb], n);
  786. j = irwb - 1;
  787. i__1 = *nrhs;
  788. for (jcol = 1; jcol <= i__1; ++jcol) {
  789. i__2 = *n;
  790. for (jrow = 1; jrow <= i__2; ++jrow) {
  791. ++j;
  792. rwork[j] = r_imag(&b[jrow + jcol * b_dim1]);
  793. /* L130: */
  794. }
  795. /* L140: */
  796. }
  797. sgemm_("T", "N", n, nrhs, n, &c_b10, &rwork[irwvt], n, &rwork[irwb],
  798. n, &c_b35, &rwork[irwib], n);
  799. jreal = irwrb - 1;
  800. jimag = irwib - 1;
  801. i__1 = *nrhs;
  802. for (jcol = 1; jcol <= i__1; ++jcol) {
  803. i__2 = *n;
  804. for (jrow = 1; jrow <= i__2; ++jrow) {
  805. ++jreal;
  806. ++jimag;
  807. i__3 = jrow + jcol * b_dim1;
  808. i__4 = jreal;
  809. i__5 = jimag;
  810. q__1.r = rwork[i__4], q__1.i = rwork[i__5];
  811. b[i__3].r = q__1.r, b[i__3].i = q__1.i;
  812. /* L150: */
  813. }
  814. /* L160: */
  815. }
  816. /* Unscale. */
  817. slascl_("G", &c__0, &c__0, &c_b10, &orgnrm, n, &c__1, &d__[1], n,
  818. info);
  819. slasrt_("D", n, &d__[1], info);
  820. clascl_("G", &c__0, &c__0, &orgnrm, &c_b10, n, nrhs, &b[b_offset],
  821. ldb, info);
  822. return 0;
  823. }
  824. /* Book-keeping and setting up some constants. */
  825. nlvl = (integer) (log((real) (*n) / (real) (*smlsiz + 1)) / log(2.f)) + 1;
  826. smlszp = *smlsiz + 1;
  827. u = 1;
  828. vt = *smlsiz * *n + 1;
  829. difl = vt + smlszp * *n;
  830. difr = difl + nlvl * *n;
  831. z__ = difr + (nlvl * *n << 1);
  832. c__ = z__ + nlvl * *n;
  833. s = c__ + *n;
  834. poles = s + *n;
  835. givnum = poles + (nlvl << 1) * *n;
  836. nrwork = givnum + (nlvl << 1) * *n;
  837. bx = 1;
  838. irwrb = nrwork;
  839. irwib = irwrb + *smlsiz * *nrhs;
  840. irwb = irwib + *smlsiz * *nrhs;
  841. sizei = *n + 1;
  842. k = sizei + *n;
  843. givptr = k + *n;
  844. perm = givptr + *n;
  845. givcol = perm + nlvl * *n;
  846. iwk = givcol + (nlvl * *n << 1);
  847. st = 1;
  848. sqre = 0;
  849. icmpq1 = 1;
  850. icmpq2 = 0;
  851. nsub = 0;
  852. i__1 = *n;
  853. for (i__ = 1; i__ <= i__1; ++i__) {
  854. if ((r__1 = d__[i__], abs(r__1)) < eps) {
  855. d__[i__] = r_sign(&eps, &d__[i__]);
  856. }
  857. /* L170: */
  858. }
  859. i__1 = nm1;
  860. for (i__ = 1; i__ <= i__1; ++i__) {
  861. if ((r__1 = e[i__], abs(r__1)) < eps || i__ == nm1) {
  862. ++nsub;
  863. iwork[nsub] = st;
  864. /* Subproblem found. First determine its size and then */
  865. /* apply divide and conquer on it. */
  866. if (i__ < nm1) {
  867. /* A subproblem with E(I) small for I < NM1. */
  868. nsize = i__ - st + 1;
  869. iwork[sizei + nsub - 1] = nsize;
  870. } else if ((r__1 = e[i__], abs(r__1)) >= eps) {
  871. /* A subproblem with E(NM1) not too small but I = NM1. */
  872. nsize = *n - st + 1;
  873. iwork[sizei + nsub - 1] = nsize;
  874. } else {
  875. /* A subproblem with E(NM1) small. This implies an */
  876. /* 1-by-1 subproblem at D(N), which is not solved */
  877. /* explicitly. */
  878. nsize = i__ - st + 1;
  879. iwork[sizei + nsub - 1] = nsize;
  880. ++nsub;
  881. iwork[nsub] = *n;
  882. iwork[sizei + nsub - 1] = 1;
  883. ccopy_(nrhs, &b[*n + b_dim1], ldb, &work[bx + nm1], n);
  884. }
  885. st1 = st - 1;
  886. if (nsize == 1) {
  887. /* This is a 1-by-1 subproblem and is not solved */
  888. /* explicitly. */
  889. ccopy_(nrhs, &b[st + b_dim1], ldb, &work[bx + st1], n);
  890. } else if (nsize <= *smlsiz) {
  891. /* This is a small subproblem and is solved by SLASDQ. */
  892. slaset_("A", &nsize, &nsize, &c_b35, &c_b10, &rwork[vt + st1],
  893. n);
  894. slaset_("A", &nsize, &nsize, &c_b35, &c_b10, &rwork[u + st1],
  895. n);
  896. slasdq_("U", &c__0, &nsize, &nsize, &nsize, &c__0, &d__[st], &
  897. e[st], &rwork[vt + st1], n, &rwork[u + st1], n, &
  898. rwork[nrwork], &c__1, &rwork[nrwork], info)
  899. ;
  900. if (*info != 0) {
  901. return 0;
  902. }
  903. /* In the real version, B is passed to SLASDQ and multiplied */
  904. /* internally by Q**H. Here B is complex and that product is */
  905. /* computed below in two steps (real and imaginary parts). */
  906. j = irwb - 1;
  907. i__2 = *nrhs;
  908. for (jcol = 1; jcol <= i__2; ++jcol) {
  909. i__3 = st + nsize - 1;
  910. for (jrow = st; jrow <= i__3; ++jrow) {
  911. ++j;
  912. i__4 = jrow + jcol * b_dim1;
  913. rwork[j] = b[i__4].r;
  914. /* L180: */
  915. }
  916. /* L190: */
  917. }
  918. sgemm_("T", "N", &nsize, nrhs, &nsize, &c_b10, &rwork[u + st1]
  919. , n, &rwork[irwb], &nsize, &c_b35, &rwork[irwrb], &
  920. nsize);
  921. j = irwb - 1;
  922. i__2 = *nrhs;
  923. for (jcol = 1; jcol <= i__2; ++jcol) {
  924. i__3 = st + nsize - 1;
  925. for (jrow = st; jrow <= i__3; ++jrow) {
  926. ++j;
  927. rwork[j] = r_imag(&b[jrow + jcol * b_dim1]);
  928. /* L200: */
  929. }
  930. /* L210: */
  931. }
  932. sgemm_("T", "N", &nsize, nrhs, &nsize, &c_b10, &rwork[u + st1]
  933. , n, &rwork[irwb], &nsize, &c_b35, &rwork[irwib], &
  934. nsize);
  935. jreal = irwrb - 1;
  936. jimag = irwib - 1;
  937. i__2 = *nrhs;
  938. for (jcol = 1; jcol <= i__2; ++jcol) {
  939. i__3 = st + nsize - 1;
  940. for (jrow = st; jrow <= i__3; ++jrow) {
  941. ++jreal;
  942. ++jimag;
  943. i__4 = jrow + jcol * b_dim1;
  944. i__5 = jreal;
  945. i__6 = jimag;
  946. q__1.r = rwork[i__5], q__1.i = rwork[i__6];
  947. b[i__4].r = q__1.r, b[i__4].i = q__1.i;
  948. /* L220: */
  949. }
  950. /* L230: */
  951. }
  952. clacpy_("A", &nsize, nrhs, &b[st + b_dim1], ldb, &work[bx +
  953. st1], n);
  954. } else {
  955. /* A large problem. Solve it using divide and conquer. */
  956. slasda_(&icmpq1, smlsiz, &nsize, &sqre, &d__[st], &e[st], &
  957. rwork[u + st1], n, &rwork[vt + st1], &iwork[k + st1],
  958. &rwork[difl + st1], &rwork[difr + st1], &rwork[z__ +
  959. st1], &rwork[poles + st1], &iwork[givptr + st1], &
  960. iwork[givcol + st1], n, &iwork[perm + st1], &rwork[
  961. givnum + st1], &rwork[c__ + st1], &rwork[s + st1], &
  962. rwork[nrwork], &iwork[iwk], info);
  963. if (*info != 0) {
  964. return 0;
  965. }
  966. bxst = bx + st1;
  967. clalsa_(&icmpq2, smlsiz, &nsize, nrhs, &b[st + b_dim1], ldb, &
  968. work[bxst], n, &rwork[u + st1], n, &rwork[vt + st1], &
  969. iwork[k + st1], &rwork[difl + st1], &rwork[difr + st1]
  970. , &rwork[z__ + st1], &rwork[poles + st1], &iwork[
  971. givptr + st1], &iwork[givcol + st1], n, &iwork[perm +
  972. st1], &rwork[givnum + st1], &rwork[c__ + st1], &rwork[
  973. s + st1], &rwork[nrwork], &iwork[iwk], info);
  974. if (*info != 0) {
  975. return 0;
  976. }
  977. }
  978. st = i__ + 1;
  979. }
  980. /* L240: */
  981. }
  982. /* Apply the singular values and treat the tiny ones as zero. */
  983. tol = rcnd * (r__1 = d__[isamax_(n, &d__[1], &c__1)], abs(r__1));
  984. i__1 = *n;
  985. for (i__ = 1; i__ <= i__1; ++i__) {
  986. /* Some of the elements in D can be negative because 1-by-1 */
  987. /* subproblems were not solved explicitly. */
  988. if ((r__1 = d__[i__], abs(r__1)) <= tol) {
  989. claset_("A", &c__1, nrhs, &c_b1, &c_b1, &work[bx + i__ - 1], n);
  990. } else {
  991. ++(*rank);
  992. clascl_("G", &c__0, &c__0, &d__[i__], &c_b10, &c__1, nrhs, &work[
  993. bx + i__ - 1], n, info);
  994. }
  995. d__[i__] = (r__1 = d__[i__], abs(r__1));
  996. /* L250: */
  997. }
  998. /* Now apply back the right singular vectors. */
  999. icmpq2 = 1;
  1000. i__1 = nsub;
  1001. for (i__ = 1; i__ <= i__1; ++i__) {
  1002. st = iwork[i__];
  1003. st1 = st - 1;
  1004. nsize = iwork[sizei + i__ - 1];
  1005. bxst = bx + st1;
  1006. if (nsize == 1) {
  1007. ccopy_(nrhs, &work[bxst], n, &b[st + b_dim1], ldb);
  1008. } else if (nsize <= *smlsiz) {
  1009. /* Since B and BX are complex, the following call to SGEMM */
  1010. /* is performed in two steps (real and imaginary parts). */
  1011. /* CALL SGEMM( 'T', 'N', NSIZE, NRHS, NSIZE, ONE, */
  1012. /* $ RWORK( VT+ST1 ), N, RWORK( BXST ), N, ZERO, */
  1013. /* $ B( ST, 1 ), LDB ) */
  1014. j = bxst - *n - 1;
  1015. jreal = irwb - 1;
  1016. i__2 = *nrhs;
  1017. for (jcol = 1; jcol <= i__2; ++jcol) {
  1018. j += *n;
  1019. i__3 = nsize;
  1020. for (jrow = 1; jrow <= i__3; ++jrow) {
  1021. ++jreal;
  1022. i__4 = j + jrow;
  1023. rwork[jreal] = work[i__4].r;
  1024. /* L260: */
  1025. }
  1026. /* L270: */
  1027. }
  1028. sgemm_("T", "N", &nsize, nrhs, &nsize, &c_b10, &rwork[vt + st1],
  1029. n, &rwork[irwb], &nsize, &c_b35, &rwork[irwrb], &nsize);
  1030. j = bxst - *n - 1;
  1031. jimag = irwb - 1;
  1032. i__2 = *nrhs;
  1033. for (jcol = 1; jcol <= i__2; ++jcol) {
  1034. j += *n;
  1035. i__3 = nsize;
  1036. for (jrow = 1; jrow <= i__3; ++jrow) {
  1037. ++jimag;
  1038. rwork[jimag] = r_imag(&work[j + jrow]);
  1039. /* L280: */
  1040. }
  1041. /* L290: */
  1042. }
  1043. sgemm_("T", "N", &nsize, nrhs, &nsize, &c_b10, &rwork[vt + st1],
  1044. n, &rwork[irwb], &nsize, &c_b35, &rwork[irwib], &nsize);
  1045. jreal = irwrb - 1;
  1046. jimag = irwib - 1;
  1047. i__2 = *nrhs;
  1048. for (jcol = 1; jcol <= i__2; ++jcol) {
  1049. i__3 = st + nsize - 1;
  1050. for (jrow = st; jrow <= i__3; ++jrow) {
  1051. ++jreal;
  1052. ++jimag;
  1053. i__4 = jrow + jcol * b_dim1;
  1054. i__5 = jreal;
  1055. i__6 = jimag;
  1056. q__1.r = rwork[i__5], q__1.i = rwork[i__6];
  1057. b[i__4].r = q__1.r, b[i__4].i = q__1.i;
  1058. /* L300: */
  1059. }
  1060. /* L310: */
  1061. }
  1062. } else {
  1063. clalsa_(&icmpq2, smlsiz, &nsize, nrhs, &work[bxst], n, &b[st +
  1064. b_dim1], ldb, &rwork[u + st1], n, &rwork[vt + st1], &
  1065. iwork[k + st1], &rwork[difl + st1], &rwork[difr + st1], &
  1066. rwork[z__ + st1], &rwork[poles + st1], &iwork[givptr +
  1067. st1], &iwork[givcol + st1], n, &iwork[perm + st1], &rwork[
  1068. givnum + st1], &rwork[c__ + st1], &rwork[s + st1], &rwork[
  1069. nrwork], &iwork[iwk], info);
  1070. if (*info != 0) {
  1071. return 0;
  1072. }
  1073. }
  1074. /* L320: */
  1075. }
  1076. /* Unscale and sort the singular values. */
  1077. slascl_("G", &c__0, &c__0, &c_b10, &orgnrm, n, &c__1, &d__[1], n, info);
  1078. slasrt_("D", n, &d__[1], info);
  1079. clascl_("G", &c__0, &c__0, &orgnrm, &c_b10, n, nrhs, &b[b_offset], ldb,
  1080. info);
  1081. return 0;
  1082. /* End of CLALSD */
  1083. } /* clalsd_ */