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

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