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.

clals0.c 31 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060
  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 real c_b5 = -1.f;
  381. static integer c__1 = 1;
  382. static real c_b13 = 1.f;
  383. static real c_b15 = 0.f;
  384. static integer c__0 = 0;
  385. /* > \brief \b CLALS0 applies back multiplying factors in solving the least squares problem using divide and c
  386. onquer SVD approach. Used by sgelsd. */
  387. /* =========== DOCUMENTATION =========== */
  388. /* Online html documentation available at */
  389. /* http://www.netlib.org/lapack/explore-html/ */
  390. /* > \htmlonly */
  391. /* > Download CLALS0 + dependencies */
  392. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clals0.
  393. f"> */
  394. /* > [TGZ]</a> */
  395. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clals0.
  396. f"> */
  397. /* > [ZIP]</a> */
  398. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clals0.
  399. f"> */
  400. /* > [TXT]</a> */
  401. /* > \endhtmlonly */
  402. /* Definition: */
  403. /* =========== */
  404. /* SUBROUTINE CLALS0( ICOMPQ, NL, NR, SQRE, NRHS, B, LDB, BX, LDBX, */
  405. /* PERM, GIVPTR, GIVCOL, LDGCOL, GIVNUM, LDGNUM, */
  406. /* POLES, DIFL, DIFR, Z, K, C, S, RWORK, INFO ) */
  407. /* INTEGER GIVPTR, ICOMPQ, INFO, K, LDB, LDBX, LDGCOL, */
  408. /* $ LDGNUM, NL, NR, NRHS, SQRE */
  409. /* REAL C, S */
  410. /* INTEGER GIVCOL( LDGCOL, * ), PERM( * ) */
  411. /* REAL DIFL( * ), DIFR( LDGNUM, * ), */
  412. /* $ GIVNUM( LDGNUM, * ), POLES( LDGNUM, * ), */
  413. /* $ RWORK( * ), Z( * ) */
  414. /* COMPLEX B( LDB, * ), BX( LDBX, * ) */
  415. /* > \par Purpose: */
  416. /* ============= */
  417. /* > */
  418. /* > \verbatim */
  419. /* > */
  420. /* > CLALS0 applies back the multiplying factors of either the left or the */
  421. /* > right singular vector matrix of a diagonal matrix appended by a row */
  422. /* > to the right hand side matrix B in solving the least squares problem */
  423. /* > using the divide-and-conquer SVD approach. */
  424. /* > */
  425. /* > For the left singular vector matrix, three types of orthogonal */
  426. /* > matrices are involved: */
  427. /* > */
  428. /* > (1L) Givens rotations: the number of such rotations is GIVPTR; the */
  429. /* > pairs of columns/rows they were applied to are stored in GIVCOL; */
  430. /* > and the C- and S-values of these rotations are stored in GIVNUM. */
  431. /* > */
  432. /* > (2L) Permutation. The (NL+1)-st row of B is to be moved to the first */
  433. /* > row, and for J=2:N, PERM(J)-th row of B is to be moved to the */
  434. /* > J-th row. */
  435. /* > */
  436. /* > (3L) The left singular vector matrix of the remaining matrix. */
  437. /* > */
  438. /* > For the right singular vector matrix, four types of orthogonal */
  439. /* > matrices are involved: */
  440. /* > */
  441. /* > (1R) The right singular vector matrix of the remaining matrix. */
  442. /* > */
  443. /* > (2R) If SQRE = 1, one extra Givens rotation to generate the right */
  444. /* > null space. */
  445. /* > */
  446. /* > (3R) The inverse transformation of (2L). */
  447. /* > */
  448. /* > (4R) The inverse transformation of (1L). */
  449. /* > \endverbatim */
  450. /* Arguments: */
  451. /* ========== */
  452. /* > \param[in] ICOMPQ */
  453. /* > \verbatim */
  454. /* > ICOMPQ is INTEGER */
  455. /* > Specifies whether singular vectors are to be computed in */
  456. /* > factored form: */
  457. /* > = 0: Left singular vector matrix. */
  458. /* > = 1: Right singular vector matrix. */
  459. /* > \endverbatim */
  460. /* > */
  461. /* > \param[in] NL */
  462. /* > \verbatim */
  463. /* > NL is INTEGER */
  464. /* > The row dimension of the upper block. NL >= 1. */
  465. /* > \endverbatim */
  466. /* > */
  467. /* > \param[in] NR */
  468. /* > \verbatim */
  469. /* > NR is INTEGER */
  470. /* > The row dimension of the lower block. NR >= 1. */
  471. /* > \endverbatim */
  472. /* > */
  473. /* > \param[in] SQRE */
  474. /* > \verbatim */
  475. /* > SQRE is INTEGER */
  476. /* > = 0: the lower block is an NR-by-NR square matrix. */
  477. /* > = 1: the lower block is an NR-by-(NR+1) rectangular matrix. */
  478. /* > */
  479. /* > The bidiagonal matrix has row dimension N = NL + NR + 1, */
  480. /* > and column dimension M = N + SQRE. */
  481. /* > \endverbatim */
  482. /* > */
  483. /* > \param[in] NRHS */
  484. /* > \verbatim */
  485. /* > NRHS is INTEGER */
  486. /* > The number of columns of B and BX. NRHS must be at least 1. */
  487. /* > \endverbatim */
  488. /* > */
  489. /* > \param[in,out] B */
  490. /* > \verbatim */
  491. /* > B is COMPLEX array, dimension ( LDB, NRHS ) */
  492. /* > On input, B contains the right hand sides of the least */
  493. /* > squares problem in rows 1 through M. On output, B contains */
  494. /* > the solution X in rows 1 through N. */
  495. /* > \endverbatim */
  496. /* > */
  497. /* > \param[in] LDB */
  498. /* > \verbatim */
  499. /* > LDB is INTEGER */
  500. /* > The leading dimension of B. LDB must be at least */
  501. /* > f2cmax(1,MAX( M, N ) ). */
  502. /* > \endverbatim */
  503. /* > */
  504. /* > \param[out] BX */
  505. /* > \verbatim */
  506. /* > BX is COMPLEX array, dimension ( LDBX, NRHS ) */
  507. /* > \endverbatim */
  508. /* > */
  509. /* > \param[in] LDBX */
  510. /* > \verbatim */
  511. /* > LDBX is INTEGER */
  512. /* > The leading dimension of BX. */
  513. /* > \endverbatim */
  514. /* > */
  515. /* > \param[in] PERM */
  516. /* > \verbatim */
  517. /* > PERM is INTEGER array, dimension ( N ) */
  518. /* > The permutations (from deflation and sorting) applied */
  519. /* > to the two blocks. */
  520. /* > \endverbatim */
  521. /* > */
  522. /* > \param[in] GIVPTR */
  523. /* > \verbatim */
  524. /* > GIVPTR is INTEGER */
  525. /* > The number of Givens rotations which took place in this */
  526. /* > subproblem. */
  527. /* > \endverbatim */
  528. /* > */
  529. /* > \param[in] GIVCOL */
  530. /* > \verbatim */
  531. /* > GIVCOL is INTEGER array, dimension ( LDGCOL, 2 ) */
  532. /* > Each pair of numbers indicates a pair of rows/columns */
  533. /* > involved in a Givens rotation. */
  534. /* > \endverbatim */
  535. /* > */
  536. /* > \param[in] LDGCOL */
  537. /* > \verbatim */
  538. /* > LDGCOL is INTEGER */
  539. /* > The leading dimension of GIVCOL, must be at least N. */
  540. /* > \endverbatim */
  541. /* > */
  542. /* > \param[in] GIVNUM */
  543. /* > \verbatim */
  544. /* > GIVNUM is REAL array, dimension ( LDGNUM, 2 ) */
  545. /* > Each number indicates the C or S value used in the */
  546. /* > corresponding Givens rotation. */
  547. /* > \endverbatim */
  548. /* > */
  549. /* > \param[in] LDGNUM */
  550. /* > \verbatim */
  551. /* > LDGNUM is INTEGER */
  552. /* > The leading dimension of arrays DIFR, POLES and */
  553. /* > GIVNUM, must be at least K. */
  554. /* > \endverbatim */
  555. /* > */
  556. /* > \param[in] POLES */
  557. /* > \verbatim */
  558. /* > POLES is REAL array, dimension ( LDGNUM, 2 ) */
  559. /* > On entry, POLES(1:K, 1) contains the new singular */
  560. /* > values obtained from solving the secular equation, and */
  561. /* > POLES(1:K, 2) is an array containing the poles in the secular */
  562. /* > equation. */
  563. /* > \endverbatim */
  564. /* > */
  565. /* > \param[in] DIFL */
  566. /* > \verbatim */
  567. /* > DIFL is REAL array, dimension ( K ). */
  568. /* > On entry, DIFL(I) is the distance between I-th updated */
  569. /* > (undeflated) singular value and the I-th (undeflated) old */
  570. /* > singular value. */
  571. /* > \endverbatim */
  572. /* > */
  573. /* > \param[in] DIFR */
  574. /* > \verbatim */
  575. /* > DIFR is REAL array, dimension ( LDGNUM, 2 ). */
  576. /* > On entry, DIFR(I, 1) contains the distances between I-th */
  577. /* > updated (undeflated) singular value and the I+1-th */
  578. /* > (undeflated) old singular value. And DIFR(I, 2) is the */
  579. /* > normalizing factor for the I-th right singular vector. */
  580. /* > \endverbatim */
  581. /* > */
  582. /* > \param[in] Z */
  583. /* > \verbatim */
  584. /* > Z is REAL array, dimension ( K ) */
  585. /* > Contain the components of the deflation-adjusted updating row */
  586. /* > vector. */
  587. /* > \endverbatim */
  588. /* > */
  589. /* > \param[in] K */
  590. /* > \verbatim */
  591. /* > K is INTEGER */
  592. /* > Contains the dimension of the non-deflated matrix, */
  593. /* > This is the order of the related secular equation. 1 <= K <=N. */
  594. /* > \endverbatim */
  595. /* > */
  596. /* > \param[in] C */
  597. /* > \verbatim */
  598. /* > C is REAL */
  599. /* > C contains garbage if SQRE =0 and the C-value of a Givens */
  600. /* > rotation related to the right null space if SQRE = 1. */
  601. /* > \endverbatim */
  602. /* > */
  603. /* > \param[in] S */
  604. /* > \verbatim */
  605. /* > S is REAL */
  606. /* > S contains garbage if SQRE =0 and the S-value of a Givens */
  607. /* > rotation related to the right null space if SQRE = 1. */
  608. /* > \endverbatim */
  609. /* > */
  610. /* > \param[out] RWORK */
  611. /* > \verbatim */
  612. /* > RWORK is REAL array, dimension */
  613. /* > ( K*(1+NRHS) + 2*NRHS ) */
  614. /* > \endverbatim */
  615. /* > */
  616. /* > \param[out] INFO */
  617. /* > \verbatim */
  618. /* > INFO is INTEGER */
  619. /* > = 0: successful exit. */
  620. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  621. /* > \endverbatim */
  622. /* Authors: */
  623. /* ======== */
  624. /* > \author Univ. of Tennessee */
  625. /* > \author Univ. of California Berkeley */
  626. /* > \author Univ. of Colorado Denver */
  627. /* > \author NAG Ltd. */
  628. /* > \date December 2016 */
  629. /* > \ingroup complexOTHERcomputational */
  630. /* > \par Contributors: */
  631. /* ================== */
  632. /* > */
  633. /* > Ming Gu and Ren-Cang Li, Computer Science Division, University of */
  634. /* > California at Berkeley, USA \n */
  635. /* > Osni Marques, LBNL/NERSC, USA \n */
  636. /* ===================================================================== */
  637. /* Subroutine */ int clals0_(integer *icompq, integer *nl, integer *nr,
  638. integer *sqre, integer *nrhs, complex *b, integer *ldb, complex *bx,
  639. integer *ldbx, integer *perm, integer *givptr, integer *givcol,
  640. integer *ldgcol, real *givnum, integer *ldgnum, real *poles, real *
  641. difl, real *difr, real *z__, integer *k, real *c__, real *s, real *
  642. rwork, integer *info)
  643. {
  644. /* System generated locals */
  645. integer givcol_dim1, givcol_offset, difr_dim1, difr_offset, givnum_dim1,
  646. givnum_offset, poles_dim1, poles_offset, b_dim1, b_offset,
  647. bx_dim1, bx_offset, i__1, i__2, i__3, i__4, i__5;
  648. real r__1;
  649. complex q__1;
  650. /* Local variables */
  651. integer jcol;
  652. real temp;
  653. integer jrow;
  654. extern real snrm2_(integer *, real *, integer *);
  655. integer i__, j, m, n;
  656. real diflj, difrj, dsigj;
  657. extern /* Subroutine */ int ccopy_(integer *, complex *, integer *,
  658. complex *, integer *), sgemv_(char *, integer *, integer *, real *
  659. , real *, integer *, real *, integer *, real *, real *, integer *), csrot_(integer *, complex *, integer *, complex *,
  660. integer *, real *, real *);
  661. extern real slamc3_(real *, real *);
  662. real dj;
  663. extern /* Subroutine */ int clascl_(char *, integer *, integer *, real *,
  664. real *, integer *, integer *, complex *, integer *, integer *), csscal_(integer *, real *, complex *, integer *),
  665. clacpy_(char *, integer *, integer *, complex *, integer *,
  666. complex *, integer *), xerbla_(char *, integer *, ftnlen);
  667. real dsigjp;
  668. integer nlp1;
  669. /* -- LAPACK computational routine (version 3.7.0) -- */
  670. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  671. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  672. /* December 2016 */
  673. /* ===================================================================== */
  674. /* Test the input parameters. */
  675. /* Parameter adjustments */
  676. b_dim1 = *ldb;
  677. b_offset = 1 + b_dim1 * 1;
  678. b -= b_offset;
  679. bx_dim1 = *ldbx;
  680. bx_offset = 1 + bx_dim1 * 1;
  681. bx -= bx_offset;
  682. --perm;
  683. givcol_dim1 = *ldgcol;
  684. givcol_offset = 1 + givcol_dim1 * 1;
  685. givcol -= givcol_offset;
  686. difr_dim1 = *ldgnum;
  687. difr_offset = 1 + difr_dim1 * 1;
  688. difr -= difr_offset;
  689. poles_dim1 = *ldgnum;
  690. poles_offset = 1 + poles_dim1 * 1;
  691. poles -= poles_offset;
  692. givnum_dim1 = *ldgnum;
  693. givnum_offset = 1 + givnum_dim1 * 1;
  694. givnum -= givnum_offset;
  695. --difl;
  696. --z__;
  697. --rwork;
  698. /* Function Body */
  699. *info = 0;
  700. n = *nl + *nr + 1;
  701. if (*icompq < 0 || *icompq > 1) {
  702. *info = -1;
  703. } else if (*nl < 1) {
  704. *info = -2;
  705. } else if (*nr < 1) {
  706. *info = -3;
  707. } else if (*sqre < 0 || *sqre > 1) {
  708. *info = -4;
  709. } else if (*nrhs < 1) {
  710. *info = -5;
  711. } else if (*ldb < n) {
  712. *info = -7;
  713. } else if (*ldbx < n) {
  714. *info = -9;
  715. } else if (*givptr < 0) {
  716. *info = -11;
  717. } else if (*ldgcol < n) {
  718. *info = -13;
  719. } else if (*ldgnum < n) {
  720. *info = -15;
  721. // } else if (*k < 1) {
  722. } else if (*k < 0) {
  723. *info = -20;
  724. }
  725. if (*info != 0) {
  726. i__1 = -(*info);
  727. xerbla_("CLALS0", &i__1, (ftnlen)6);
  728. return 0;
  729. }
  730. m = n + *sqre;
  731. nlp1 = *nl + 1;
  732. if (*icompq == 0) {
  733. /* Apply back orthogonal transformations from the left. */
  734. /* Step (1L): apply back the Givens rotations performed. */
  735. i__1 = *givptr;
  736. for (i__ = 1; i__ <= i__1; ++i__) {
  737. csrot_(nrhs, &b[givcol[i__ + (givcol_dim1 << 1)] + b_dim1], ldb, &
  738. b[givcol[i__ + givcol_dim1] + b_dim1], ldb, &givnum[i__ +
  739. (givnum_dim1 << 1)], &givnum[i__ + givnum_dim1]);
  740. /* L10: */
  741. }
  742. /* Step (2L): permute rows of B. */
  743. ccopy_(nrhs, &b[nlp1 + b_dim1], ldb, &bx[bx_dim1 + 1], ldbx);
  744. i__1 = n;
  745. for (i__ = 2; i__ <= i__1; ++i__) {
  746. ccopy_(nrhs, &b[perm[i__] + b_dim1], ldb, &bx[i__ + bx_dim1],
  747. ldbx);
  748. /* L20: */
  749. }
  750. /* Step (3L): apply the inverse of the left singular vector */
  751. /* matrix to BX. */
  752. if (*k == 1) {
  753. ccopy_(nrhs, &bx[bx_offset], ldbx, &b[b_offset], ldb);
  754. if (z__[1] < 0.f) {
  755. csscal_(nrhs, &c_b5, &b[b_offset], ldb);
  756. }
  757. } else {
  758. i__1 = *k;
  759. for (j = 1; j <= i__1; ++j) {
  760. diflj = difl[j];
  761. dj = poles[j + poles_dim1];
  762. dsigj = -poles[j + (poles_dim1 << 1)];
  763. if (j < *k) {
  764. difrj = -difr[j + difr_dim1];
  765. dsigjp = -poles[j + 1 + (poles_dim1 << 1)];
  766. }
  767. if (z__[j] == 0.f || poles[j + (poles_dim1 << 1)] == 0.f) {
  768. rwork[j] = 0.f;
  769. } else {
  770. rwork[j] = -poles[j + (poles_dim1 << 1)] * z__[j] / diflj
  771. / (poles[j + (poles_dim1 << 1)] + dj);
  772. }
  773. i__2 = j - 1;
  774. for (i__ = 1; i__ <= i__2; ++i__) {
  775. if (z__[i__] == 0.f || poles[i__ + (poles_dim1 << 1)] ==
  776. 0.f) {
  777. rwork[i__] = 0.f;
  778. } else {
  779. rwork[i__] = poles[i__ + (poles_dim1 << 1)] * z__[i__]
  780. / (slamc3_(&poles[i__ + (poles_dim1 << 1)], &
  781. dsigj) - diflj) / (poles[i__ + (poles_dim1 <<
  782. 1)] + dj);
  783. }
  784. /* L30: */
  785. }
  786. i__2 = *k;
  787. for (i__ = j + 1; i__ <= i__2; ++i__) {
  788. if (z__[i__] == 0.f || poles[i__ + (poles_dim1 << 1)] ==
  789. 0.f) {
  790. rwork[i__] = 0.f;
  791. } else {
  792. rwork[i__] = poles[i__ + (poles_dim1 << 1)] * z__[i__]
  793. / (slamc3_(&poles[i__ + (poles_dim1 << 1)], &
  794. dsigjp) + difrj) / (poles[i__ + (poles_dim1 <<
  795. 1)] + dj);
  796. }
  797. /* L40: */
  798. }
  799. rwork[1] = -1.f;
  800. temp = snrm2_(k, &rwork[1], &c__1);
  801. /* Since B and BX are complex, the following call to SGEMV */
  802. /* is performed in two steps (real and imaginary parts). */
  803. /* CALL SGEMV( 'T', K, NRHS, ONE, BX, LDBX, WORK, 1, ZERO, */
  804. /* $ B( J, 1 ), LDB ) */
  805. i__ = *k + (*nrhs << 1);
  806. i__2 = *nrhs;
  807. for (jcol = 1; jcol <= i__2; ++jcol) {
  808. i__3 = *k;
  809. for (jrow = 1; jrow <= i__3; ++jrow) {
  810. ++i__;
  811. i__4 = jrow + jcol * bx_dim1;
  812. rwork[i__] = bx[i__4].r;
  813. /* L50: */
  814. }
  815. /* L60: */
  816. }
  817. sgemv_("T", k, nrhs, &c_b13, &rwork[*k + 1 + (*nrhs << 1)], k,
  818. &rwork[1], &c__1, &c_b15, &rwork[*k + 1], &c__1);
  819. i__ = *k + (*nrhs << 1);
  820. i__2 = *nrhs;
  821. for (jcol = 1; jcol <= i__2; ++jcol) {
  822. i__3 = *k;
  823. for (jrow = 1; jrow <= i__3; ++jrow) {
  824. ++i__;
  825. rwork[i__] = r_imag(&bx[jrow + jcol * bx_dim1]);
  826. /* L70: */
  827. }
  828. /* L80: */
  829. }
  830. sgemv_("T", k, nrhs, &c_b13, &rwork[*k + 1 + (*nrhs << 1)], k,
  831. &rwork[1], &c__1, &c_b15, &rwork[*k + 1 + *nrhs], &
  832. c__1);
  833. i__2 = *nrhs;
  834. for (jcol = 1; jcol <= i__2; ++jcol) {
  835. i__3 = j + jcol * b_dim1;
  836. i__4 = jcol + *k;
  837. i__5 = jcol + *k + *nrhs;
  838. q__1.r = rwork[i__4], q__1.i = rwork[i__5];
  839. b[i__3].r = q__1.r, b[i__3].i = q__1.i;
  840. /* L90: */
  841. }
  842. clascl_("G", &c__0, &c__0, &temp, &c_b13, &c__1, nrhs, &b[j +
  843. b_dim1], ldb, info);
  844. /* L100: */
  845. }
  846. }
  847. /* Move the deflated rows of BX to B also. */
  848. if (*k < f2cmax(m,n)) {
  849. i__1 = n - *k;
  850. clacpy_("A", &i__1, nrhs, &bx[*k + 1 + bx_dim1], ldbx, &b[*k + 1
  851. + b_dim1], ldb);
  852. }
  853. } else {
  854. /* Apply back the right orthogonal transformations. */
  855. /* Step (1R): apply back the new right singular vector matrix */
  856. /* to B. */
  857. if (*k == 1) {
  858. ccopy_(nrhs, &b[b_offset], ldb, &bx[bx_offset], ldbx);
  859. } else {
  860. i__1 = *k;
  861. for (j = 1; j <= i__1; ++j) {
  862. dsigj = poles[j + (poles_dim1 << 1)];
  863. if (z__[j] == 0.f) {
  864. rwork[j] = 0.f;
  865. } else {
  866. rwork[j] = -z__[j] / difl[j] / (dsigj + poles[j +
  867. poles_dim1]) / difr[j + (difr_dim1 << 1)];
  868. }
  869. i__2 = j - 1;
  870. for (i__ = 1; i__ <= i__2; ++i__) {
  871. if (z__[j] == 0.f) {
  872. rwork[i__] = 0.f;
  873. } else {
  874. r__1 = -poles[i__ + 1 + (poles_dim1 << 1)];
  875. rwork[i__] = z__[j] / (slamc3_(&dsigj, &r__1) - difr[
  876. i__ + difr_dim1]) / (dsigj + poles[i__ +
  877. poles_dim1]) / difr[i__ + (difr_dim1 << 1)];
  878. }
  879. /* L110: */
  880. }
  881. i__2 = *k;
  882. for (i__ = j + 1; i__ <= i__2; ++i__) {
  883. if (z__[j] == 0.f) {
  884. rwork[i__] = 0.f;
  885. } else {
  886. r__1 = -poles[i__ + (poles_dim1 << 1)];
  887. rwork[i__] = z__[j] / (slamc3_(&dsigj, &r__1) - difl[
  888. i__]) / (dsigj + poles[i__ + poles_dim1]) /
  889. difr[i__ + (difr_dim1 << 1)];
  890. }
  891. /* L120: */
  892. }
  893. /* Since B and BX are complex, the following call to SGEMV */
  894. /* is performed in two steps (real and imaginary parts). */
  895. /* CALL SGEMV( 'T', K, NRHS, ONE, B, LDB, WORK, 1, ZERO, */
  896. /* $ BX( J, 1 ), LDBX ) */
  897. i__ = *k + (*nrhs << 1);
  898. i__2 = *nrhs;
  899. for (jcol = 1; jcol <= i__2; ++jcol) {
  900. i__3 = *k;
  901. for (jrow = 1; jrow <= i__3; ++jrow) {
  902. ++i__;
  903. i__4 = jrow + jcol * b_dim1;
  904. rwork[i__] = b[i__4].r;
  905. /* L130: */
  906. }
  907. /* L140: */
  908. }
  909. sgemv_("T", k, nrhs, &c_b13, &rwork[*k + 1 + (*nrhs << 1)], k,
  910. &rwork[1], &c__1, &c_b15, &rwork[*k + 1], &c__1);
  911. i__ = *k + (*nrhs << 1);
  912. i__2 = *nrhs;
  913. for (jcol = 1; jcol <= i__2; ++jcol) {
  914. i__3 = *k;
  915. for (jrow = 1; jrow <= i__3; ++jrow) {
  916. ++i__;
  917. rwork[i__] = r_imag(&b[jrow + jcol * b_dim1]);
  918. /* L150: */
  919. }
  920. /* L160: */
  921. }
  922. sgemv_("T", k, nrhs, &c_b13, &rwork[*k + 1 + (*nrhs << 1)], k,
  923. &rwork[1], &c__1, &c_b15, &rwork[*k + 1 + *nrhs], &
  924. c__1);
  925. i__2 = *nrhs;
  926. for (jcol = 1; jcol <= i__2; ++jcol) {
  927. i__3 = j + jcol * bx_dim1;
  928. i__4 = jcol + *k;
  929. i__5 = jcol + *k + *nrhs;
  930. q__1.r = rwork[i__4], q__1.i = rwork[i__5];
  931. bx[i__3].r = q__1.r, bx[i__3].i = q__1.i;
  932. /* L170: */
  933. }
  934. /* L180: */
  935. }
  936. }
  937. /* Step (2R): if SQRE = 1, apply back the rotation that is */
  938. /* related to the right null space of the subproblem. */
  939. if (*sqre == 1) {
  940. ccopy_(nrhs, &b[m + b_dim1], ldb, &bx[m + bx_dim1], ldbx);
  941. csrot_(nrhs, &bx[bx_dim1 + 1], ldbx, &bx[m + bx_dim1], ldbx, c__,
  942. s);
  943. }
  944. if (*k < f2cmax(m,n)) {
  945. i__1 = n - *k;
  946. clacpy_("A", &i__1, nrhs, &b[*k + 1 + b_dim1], ldb, &bx[*k + 1 +
  947. bx_dim1], ldbx);
  948. }
  949. /* Step (3R): permute rows of B. */
  950. ccopy_(nrhs, &bx[bx_dim1 + 1], ldbx, &b[nlp1 + b_dim1], ldb);
  951. if (*sqre == 1) {
  952. ccopy_(nrhs, &bx[m + bx_dim1], ldbx, &b[m + b_dim1], ldb);
  953. }
  954. i__1 = n;
  955. for (i__ = 2; i__ <= i__1; ++i__) {
  956. ccopy_(nrhs, &bx[i__ + bx_dim1], ldbx, &b[perm[i__] + b_dim1],
  957. ldb);
  958. /* L190: */
  959. }
  960. /* Step (4R): apply back the Givens rotations performed. */
  961. for (i__ = *givptr; i__ >= 1; --i__) {
  962. r__1 = -givnum[i__ + givnum_dim1];
  963. csrot_(nrhs, &b[givcol[i__ + (givcol_dim1 << 1)] + b_dim1], ldb, &
  964. b[givcol[i__ + givcol_dim1] + b_dim1], ldb, &givnum[i__ +
  965. (givnum_dim1 << 1)], &r__1);
  966. /* L200: */
  967. }
  968. }
  969. return 0;
  970. /* End of CLALS0 */
  971. } /* clals0_ */