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.

sgelsd.c 33 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049
  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <complex.h>
  6. #ifdef complex
  7. #undef complex
  8. #endif
  9. #ifdef I
  10. #undef I
  11. #endif
  12. #if defined(_WIN64)
  13. typedef long long BLASLONG;
  14. typedef unsigned long long BLASULONG;
  15. #else
  16. typedef long BLASLONG;
  17. typedef unsigned long BLASULONG;
  18. #endif
  19. #ifdef LAPACK_ILP64
  20. typedef BLASLONG blasint;
  21. #if defined(_WIN64)
  22. #define blasabs(x) llabs(x)
  23. #else
  24. #define blasabs(x) labs(x)
  25. #endif
  26. #else
  27. typedef int blasint;
  28. #define blasabs(x) abs(x)
  29. #endif
  30. typedef blasint integer;
  31. typedef unsigned int uinteger;
  32. typedef char *address;
  33. typedef short int shortint;
  34. typedef float real;
  35. typedef double doublereal;
  36. typedef struct { real r, i; } complex;
  37. typedef struct { doublereal r, i; } doublecomplex;
  38. #ifdef _MSC_VER
  39. static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
  40. static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
  41. static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
  42. static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
  43. #else
  44. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  46. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  47. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  48. #endif
  49. #define pCf(z) (*_pCf(z))
  50. #define pCd(z) (*_pCd(z))
  51. typedef blasint logical;
  52. typedef char logical1;
  53. typedef char integer1;
  54. #define TRUE_ (1)
  55. #define FALSE_ (0)
  56. /* Extern is for use with -E */
  57. #ifndef Extern
  58. #define Extern extern
  59. #endif
  60. /* I/O stuff */
  61. typedef int flag;
  62. typedef int ftnlen;
  63. typedef int ftnint;
  64. /*external read, write*/
  65. typedef struct
  66. { flag cierr;
  67. ftnint ciunit;
  68. flag ciend;
  69. char *cifmt;
  70. ftnint cirec;
  71. } cilist;
  72. /*internal read, write*/
  73. typedef struct
  74. { flag icierr;
  75. char *iciunit;
  76. flag iciend;
  77. char *icifmt;
  78. ftnint icirlen;
  79. ftnint icirnum;
  80. } icilist;
  81. /*open*/
  82. typedef struct
  83. { flag oerr;
  84. ftnint ounit;
  85. char *ofnm;
  86. ftnlen ofnmlen;
  87. char *osta;
  88. char *oacc;
  89. char *ofm;
  90. ftnint orl;
  91. char *oblnk;
  92. } olist;
  93. /*close*/
  94. typedef struct
  95. { flag cerr;
  96. ftnint cunit;
  97. char *csta;
  98. } cllist;
  99. /*rewind, backspace, endfile*/
  100. typedef struct
  101. { flag aerr;
  102. ftnint aunit;
  103. } alist;
  104. /* inquire */
  105. typedef struct
  106. { flag inerr;
  107. ftnint inunit;
  108. char *infile;
  109. ftnlen infilen;
  110. ftnint *inex; /*parameters in standard's order*/
  111. ftnint *inopen;
  112. ftnint *innum;
  113. ftnint *innamed;
  114. char *inname;
  115. ftnlen innamlen;
  116. char *inacc;
  117. ftnlen inacclen;
  118. char *inseq;
  119. ftnlen inseqlen;
  120. char *indir;
  121. ftnlen indirlen;
  122. char *infmt;
  123. ftnlen infmtlen;
  124. char *inform;
  125. ftnint informlen;
  126. char *inunf;
  127. ftnlen inunflen;
  128. ftnint *inrecl;
  129. ftnint *innrec;
  130. char *inblank;
  131. ftnlen inblanklen;
  132. } inlist;
  133. #define VOID void
  134. union Multitype { /* for multiple entry points */
  135. integer1 g;
  136. shortint h;
  137. integer i;
  138. /* longint j; */
  139. real r;
  140. doublereal d;
  141. complex c;
  142. doublecomplex z;
  143. };
  144. typedef union Multitype Multitype;
  145. struct Vardesc { /* for Namelist */
  146. char *name;
  147. char *addr;
  148. ftnlen *dims;
  149. int type;
  150. };
  151. typedef struct Vardesc Vardesc;
  152. struct Namelist {
  153. char *name;
  154. Vardesc **vars;
  155. int nvars;
  156. };
  157. typedef struct Namelist Namelist;
  158. #define abs(x) ((x) >= 0 ? (x) : -(x))
  159. #define dabs(x) (fabs(x))
  160. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  161. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  162. #define dmin(a,b) (f2cmin(a,b))
  163. #define dmax(a,b) (f2cmax(a,b))
  164. #define bit_test(a,b) ((a) >> (b) & 1)
  165. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  166. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  167. #define abort_() { sig_die("Fortran abort routine called", 1); }
  168. #define c_abs(z) (cabsf(Cf(z)))
  169. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  170. #ifdef _MSC_VER
  171. #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
  172. #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
  173. #else
  174. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  175. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  176. #endif
  177. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  178. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  179. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  180. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  181. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  182. #define d_abs(x) (fabs(*(x)))
  183. #define d_acos(x) (acos(*(x)))
  184. #define d_asin(x) (asin(*(x)))
  185. #define d_atan(x) (atan(*(x)))
  186. #define d_atn2(x, y) (atan2(*(x),*(y)))
  187. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  188. #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
  189. #define d_cos(x) (cos(*(x)))
  190. #define d_cosh(x) (cosh(*(x)))
  191. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  192. #define d_exp(x) (exp(*(x)))
  193. #define d_imag(z) (cimag(Cd(z)))
  194. #define r_imag(z) (cimagf(Cf(z)))
  195. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  196. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  197. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  198. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  199. #define d_log(x) (log(*(x)))
  200. #define d_mod(x, y) (fmod(*(x), *(y)))
  201. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  202. #define d_nint(x) u_nint(*(x))
  203. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  204. #define d_sign(a,b) u_sign(*(a),*(b))
  205. #define r_sign(a,b) u_sign(*(a),*(b))
  206. #define d_sin(x) (sin(*(x)))
  207. #define d_sinh(x) (sinh(*(x)))
  208. #define d_sqrt(x) (sqrt(*(x)))
  209. #define d_tan(x) (tan(*(x)))
  210. #define d_tanh(x) (tanh(*(x)))
  211. #define i_abs(x) abs(*(x))
  212. #define i_dnnt(x) ((integer)u_nint(*(x)))
  213. #define i_len(s, n) (n)
  214. #define i_nint(x) ((integer)u_nint(*(x)))
  215. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  216. #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++ = ' '; }
  217. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  218. #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]; }
  219. #define sig_die(s, kill) { exit(1); }
  220. #define s_stop(s, n) {exit(0);}
  221. #define z_abs(z) (cabs(Cd(z)))
  222. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  223. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  224. #define myexit_() break;
  225. #define mycycle() continue;
  226. #define myceiling(w) {ceil(w)}
  227. #define myhuge(w) {HUGE_VAL}
  228. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  229. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  230. /* -- translated by f2c (version 20000121).
  231. You must link the resulting object file with the libraries:
  232. -lf2c -lm (in that order)
  233. */
  234. /* Table of constant values */
  235. static integer c__9 = 9;
  236. static integer c__0 = 0;
  237. static integer c__6 = 6;
  238. static integer c_n1 = -1;
  239. static integer c__1 = 1;
  240. static real c_b81 = 0.f;
  241. /* > \brief <b> SGELSD computes the minimum-norm solution to a linear least squares problem for GE matrices</b
  242. > */
  243. /* =========== DOCUMENTATION =========== */
  244. /* Online html documentation available at */
  245. /* http://www.netlib.org/lapack/explore-html/ */
  246. /* > \htmlonly */
  247. /* > Download SGELSD + dependencies */
  248. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgelsd.
  249. f"> */
  250. /* > [TGZ]</a> */
  251. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgelsd.
  252. f"> */
  253. /* > [ZIP]</a> */
  254. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgelsd.
  255. f"> */
  256. /* > [TXT]</a> */
  257. /* > \endhtmlonly */
  258. /* Definition: */
  259. /* =========== */
  260. /* SUBROUTINE SGELSD( M, N, NRHS, A, LDA, B, LDB, S, RCOND, */
  261. /* RANK, WORK, LWORK, IWORK, INFO ) */
  262. /* INTEGER INFO, LDA, LDB, LWORK, M, N, NRHS, RANK */
  263. /* REAL RCOND */
  264. /* INTEGER IWORK( * ) */
  265. /* REAL A( LDA, * ), B( LDB, * ), S( * ), WORK( * ) */
  266. /* > \par Purpose: */
  267. /* ============= */
  268. /* > */
  269. /* > \verbatim */
  270. /* > */
  271. /* > SGELSD computes the minimum-norm solution to a real linear least */
  272. /* > squares problem: */
  273. /* > minimize 2-norm(| b - A*x |) */
  274. /* > using the singular value decomposition (SVD) of A. A is an M-by-N */
  275. /* > matrix which may be rank-deficient. */
  276. /* > */
  277. /* > Several right hand side vectors b and solution vectors x can be */
  278. /* > handled in a single call; they are stored as the columns of the */
  279. /* > M-by-NRHS right hand side matrix B and the N-by-NRHS solution */
  280. /* > matrix X. */
  281. /* > */
  282. /* > The problem is solved in three steps: */
  283. /* > (1) Reduce the coefficient matrix A to bidiagonal form with */
  284. /* > Householder transformations, reducing the original problem */
  285. /* > into a "bidiagonal least squares problem" (BLS) */
  286. /* > (2) Solve the BLS using a divide and conquer approach. */
  287. /* > (3) Apply back all the Householder transformations to solve */
  288. /* > the original least squares problem. */
  289. /* > */
  290. /* > The effective rank of A is determined by treating as zero those */
  291. /* > singular values which are less than RCOND times the largest singular */
  292. /* > value. */
  293. /* > */
  294. /* > The divide and conquer algorithm makes very mild assumptions about */
  295. /* > floating point arithmetic. It will work on machines with a guard */
  296. /* > digit in add/subtract, or on those binary machines without guard */
  297. /* > digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or */
  298. /* > Cray-2. It could conceivably fail on hexadecimal or decimal machines */
  299. /* > without guard digits, but we know of none. */
  300. /* > \endverbatim */
  301. /* Arguments: */
  302. /* ========== */
  303. /* > \param[in] M */
  304. /* > \verbatim */
  305. /* > M is INTEGER */
  306. /* > The number of rows of A. M >= 0. */
  307. /* > \endverbatim */
  308. /* > */
  309. /* > \param[in] N */
  310. /* > \verbatim */
  311. /* > N is INTEGER */
  312. /* > The number of columns of A. N >= 0. */
  313. /* > \endverbatim */
  314. /* > */
  315. /* > \param[in] NRHS */
  316. /* > \verbatim */
  317. /* > NRHS is INTEGER */
  318. /* > The number of right hand sides, i.e., the number of columns */
  319. /* > of the matrices B and X. NRHS >= 0. */
  320. /* > \endverbatim */
  321. /* > */
  322. /* > \param[in,out] A */
  323. /* > \verbatim */
  324. /* > A is REAL array, dimension (LDA,N) */
  325. /* > On entry, the M-by-N matrix A. */
  326. /* > On exit, A has been destroyed. */
  327. /* > \endverbatim */
  328. /* > */
  329. /* > \param[in] LDA */
  330. /* > \verbatim */
  331. /* > LDA is INTEGER */
  332. /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
  333. /* > \endverbatim */
  334. /* > */
  335. /* > \param[in,out] B */
  336. /* > \verbatim */
  337. /* > B is REAL array, dimension (LDB,NRHS) */
  338. /* > On entry, the M-by-NRHS right hand side matrix B. */
  339. /* > On exit, B is overwritten by the N-by-NRHS solution */
  340. /* > matrix X. If m >= n and RANK = n, the residual */
  341. /* > sum-of-squares for the solution in the i-th column is given */
  342. /* > by the sum of squares of elements n+1:m in that column. */
  343. /* > \endverbatim */
  344. /* > */
  345. /* > \param[in] LDB */
  346. /* > \verbatim */
  347. /* > LDB is INTEGER */
  348. /* > The leading dimension of the array B. LDB >= f2cmax(1,f2cmax(M,N)). */
  349. /* > \endverbatim */
  350. /* > */
  351. /* > \param[out] S */
  352. /* > \verbatim */
  353. /* > S is REAL array, dimension (f2cmin(M,N)) */
  354. /* > The singular values of A in decreasing order. */
  355. /* > The condition number of A in the 2-norm = S(1)/S(f2cmin(m,n)). */
  356. /* > \endverbatim */
  357. /* > */
  358. /* > \param[in] RCOND */
  359. /* > \verbatim */
  360. /* > RCOND is REAL */
  361. /* > RCOND is used to determine the effective rank of A. */
  362. /* > Singular values S(i) <= RCOND*S(1) are treated as zero. */
  363. /* > If RCOND < 0, machine precision is used instead. */
  364. /* > \endverbatim */
  365. /* > */
  366. /* > \param[out] RANK */
  367. /* > \verbatim */
  368. /* > RANK is INTEGER */
  369. /* > The effective rank of A, i.e., the number of singular values */
  370. /* > which are greater than RCOND*S(1). */
  371. /* > \endverbatim */
  372. /* > */
  373. /* > \param[out] WORK */
  374. /* > \verbatim */
  375. /* > WORK is REAL array, dimension (MAX(1,LWORK)) */
  376. /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
  377. /* > \endverbatim */
  378. /* > */
  379. /* > \param[in] LWORK */
  380. /* > \verbatim */
  381. /* > LWORK is INTEGER */
  382. /* > The dimension of the array WORK. LWORK must be at least 1. */
  383. /* > The exact minimum amount of workspace needed depends on M, */
  384. /* > N and NRHS. As long as LWORK is at least */
  385. /* > 12*N + 2*N*SMLSIZ + 8*N*NLVL + N*NRHS + (SMLSIZ+1)**2, */
  386. /* > if M is greater than or equal to N or */
  387. /* > 12*M + 2*M*SMLSIZ + 8*M*NLVL + M*NRHS + (SMLSIZ+1)**2, */
  388. /* > if M is less than N, the code will execute correctly. */
  389. /* > SMLSIZ is returned by ILAENV and is equal to the maximum */
  390. /* > size of the subproblems at the bottom of the computation */
  391. /* > tree (usually about 25), and */
  392. /* > NLVL = MAX( 0, INT( LOG_2( MIN( M,N )/(SMLSIZ+1) ) ) + 1 ) */
  393. /* > For good performance, LWORK should generally be larger. */
  394. /* > */
  395. /* > If LWORK = -1, then a workspace query is assumed; the routine */
  396. /* > only calculates the optimal size of the array WORK and the */
  397. /* > minimum size of the array IWORK, and returns these values as */
  398. /* > the first entries of the WORK and IWORK arrays, and no error */
  399. /* > message related to LWORK is issued by XERBLA. */
  400. /* > \endverbatim */
  401. /* > */
  402. /* > \param[out] IWORK */
  403. /* > \verbatim */
  404. /* > IWORK is INTEGER array, dimension (MAX(1,LIWORK)) */
  405. /* > LIWORK >= f2cmax(1, 3*MINMN*NLVL + 11*MINMN), */
  406. /* > where MINMN = MIN( M,N ). */
  407. /* > On exit, if INFO = 0, IWORK(1) returns the minimum LIWORK. */
  408. /* > \endverbatim */
  409. /* > */
  410. /* > \param[out] INFO */
  411. /* > \verbatim */
  412. /* > INFO is INTEGER */
  413. /* > = 0: successful exit */
  414. /* > < 0: if INFO = -i, the i-th argument had an illegal value. */
  415. /* > > 0: the algorithm for computing the SVD failed to converge; */
  416. /* > if INFO = i, i off-diagonal elements of an intermediate */
  417. /* > bidiagonal form did not converge to zero. */
  418. /* > \endverbatim */
  419. /* Authors: */
  420. /* ======== */
  421. /* > \author Univ. of Tennessee */
  422. /* > \author Univ. of California Berkeley */
  423. /* > \author Univ. of Colorado Denver */
  424. /* > \author NAG Ltd. */
  425. /* > \date June 2017 */
  426. /* > \ingroup realGEsolve */
  427. /* > \par Contributors: */
  428. /* ================== */
  429. /* > */
  430. /* > Ming Gu and Ren-Cang Li, Computer Science Division, University of */
  431. /* > California at Berkeley, USA \n */
  432. /* > Osni Marques, LBNL/NERSC, USA \n */
  433. /* ===================================================================== */
  434. /* Subroutine */ void sgelsd_(integer *m, integer *n, integer *nrhs, real *a,
  435. integer *lda, real *b, integer *ldb, real *s, real *rcond, integer *
  436. rank, real *work, integer *lwork, integer *iwork, integer *info)
  437. {
  438. /* System generated locals */
  439. integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2, i__3, i__4;
  440. /* Local variables */
  441. real anrm, bnrm;
  442. integer itau, nlvl, iascl, ibscl;
  443. real sfmin;
  444. integer minmn, maxmn, itaup, itauq, mnthr, nwork, ie, il;
  445. extern /* Subroutine */ void slabad_(real *, real *);
  446. integer mm;
  447. extern /* Subroutine */ void sgebrd_(integer *, integer *, real *, integer
  448. *, real *, real *, real *, real *, real *, integer *, integer *);
  449. extern real slamch_(char *), slange_(char *, integer *, integer *,
  450. real *, integer *, real *);
  451. extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
  452. extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
  453. integer *, integer *, ftnlen, ftnlen);
  454. real bignum;
  455. extern /* Subroutine */ void sgelqf_(integer *, integer *, real *, integer
  456. *, real *, real *, integer *, integer *), slalsd_(char *, integer
  457. *, integer *, integer *, real *, real *, real *, integer *, real *
  458. , integer *, real *, integer *, integer *), slascl_(char *
  459. , integer *, integer *, real *, real *, integer *, integer *,
  460. real *, integer *, integer *);
  461. integer wlalsd;
  462. extern /* Subroutine */ void sgeqrf_(integer *, integer *, real *, integer
  463. *, real *, real *, integer *, integer *), slacpy_(char *, integer
  464. *, integer *, real *, integer *, real *, integer *),
  465. slaset_(char *, integer *, integer *, real *, real *, real *,
  466. integer *);
  467. integer ldwork;
  468. extern /* Subroutine */ void sormbr_(char *, char *, char *, integer *,
  469. integer *, integer *, real *, integer *, real *, real *, integer *
  470. , real *, integer *, integer *);
  471. integer liwork, minwrk, maxwrk;
  472. real smlnum;
  473. extern /* Subroutine */ void sormlq_(char *, char *, integer *, integer *,
  474. integer *, real *, integer *, real *, real *, integer *, real *,
  475. integer *, integer *);
  476. logical lquery;
  477. integer smlsiz;
  478. extern /* Subroutine */ void sormqr_(char *, char *, integer *, integer *,
  479. integer *, real *, integer *, real *, real *, integer *, real *,
  480. integer *, integer *);
  481. real eps;
  482. /* -- LAPACK driver routine (version 3.7.1) -- */
  483. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  484. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  485. /* June 2017 */
  486. /* ===================================================================== */
  487. /* Test the input arguments. */
  488. /* Parameter adjustments */
  489. a_dim1 = *lda;
  490. a_offset = 1 + a_dim1;
  491. a -= a_offset;
  492. b_dim1 = *ldb;
  493. b_offset = 1 + b_dim1;
  494. b -= b_offset;
  495. --s;
  496. --work;
  497. --iwork;
  498. fprintf(stdout,"start of SGELSD\n");
  499. /* Function Body */
  500. *info = 0;
  501. minmn = f2cmin(*m,*n);
  502. maxmn = f2cmax(*m,*n);
  503. lquery = *lwork == -1;
  504. if (*m < 0) {
  505. *info = -1;
  506. } else if (*n < 0) {
  507. *info = -2;
  508. } else if (*nrhs < 0) {
  509. *info = -3;
  510. } else if (*lda < f2cmax(1,*m)) {
  511. *info = -5;
  512. } else if (*ldb < f2cmax(1,maxmn)) {
  513. *info = -7;
  514. }
  515. /* Compute workspace. */
  516. /* (Note: Comments in the code beginning "Workspace:" describe the */
  517. /* minimal amount of workspace needed at that point in the code, */
  518. /* as well as the preferred amount for good performance. */
  519. /* NB refers to the optimal block size for the immediately */
  520. /* following subroutine, as returned by ILAENV.) */
  521. if (*info == 0) {
  522. minwrk = 1;
  523. maxwrk = 1;
  524. liwork = 1;
  525. if (minmn > 0) {
  526. smlsiz = ilaenv_(&c__9, "SGELSD", " ", &c__0, &c__0, &c__0, &c__0,
  527. (ftnlen)6, (ftnlen)1);
  528. mnthr = ilaenv_(&c__6, "SGELSD", " ", m, n, nrhs, &c_n1, (ftnlen)
  529. 6, (ftnlen)1);
  530. /* Computing MAX */
  531. i__1 = (integer) (logf((real) minmn / (real) (smlsiz + 1)) / logf(
  532. 2.f)) + 1;
  533. nlvl = f2cmax(i__1,0);
  534. liwork = minmn * 3 * nlvl + minmn * 11;
  535. mm = *m;
  536. if (*m >= *n && *m >= mnthr) {
  537. /* Path 1a - overdetermined, with many more rows than */
  538. /* columns. */
  539. mm = *n;
  540. /* Computing MAX */
  541. i__1 = maxwrk, i__2 = *n + *n * ilaenv_(&c__1, "SGEQRF",
  542. " ", m, n, &c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
  543. maxwrk = f2cmax(i__1,i__2);
  544. /* Computing MAX */
  545. i__1 = maxwrk, i__2 = *n + *nrhs * ilaenv_(&c__1, "SORMQR",
  546. "LT", m, nrhs, n, &c_n1, (ftnlen)6, (ftnlen)2);
  547. maxwrk = f2cmax(i__1,i__2);
  548. }
  549. if (*m >= *n) {
  550. /* Path 1 - overdetermined or exactly determined. */
  551. /* Computing MAX */
  552. i__1 = maxwrk, i__2 = *n * 3 + (mm + *n) * ilaenv_(&c__1,
  553. "SGEBRD", " ", &mm, n, &c_n1, &c_n1, (ftnlen)6, (
  554. ftnlen)1);
  555. maxwrk = f2cmax(i__1,i__2);
  556. /* Computing MAX */
  557. i__1 = maxwrk, i__2 = *n * 3 + *nrhs * ilaenv_(&c__1, "SORMBR"
  558. , "QLT", &mm, nrhs, n, &c_n1, (ftnlen)6, (ftnlen)3);
  559. maxwrk = f2cmax(i__1,i__2);
  560. /* Computing MAX */
  561. i__1 = maxwrk, i__2 = *n * 3 + (*n - 1) * ilaenv_(&c__1,
  562. "SORMBR", "PLN", n, nrhs, n, &c_n1, (ftnlen)6, (
  563. ftnlen)3);
  564. maxwrk = f2cmax(i__1,i__2);
  565. /* Computing 2nd power */
  566. i__1 = smlsiz + 1;
  567. wlalsd = *n * 9 + (*n << 1) * smlsiz + (*n << 3) * nlvl + *n *
  568. *nrhs + i__1 * i__1;
  569. /* Computing MAX */
  570. i__1 = maxwrk, i__2 = *n * 3 + wlalsd;
  571. maxwrk = f2cmax(i__1,i__2);
  572. /* Computing MAX */
  573. i__1 = *n * 3 + mm, i__2 = *n * 3 + *nrhs, i__1 = f2cmax(i__1,
  574. i__2), i__2 = *n * 3 + wlalsd;
  575. minwrk = f2cmax(i__1,i__2);
  576. }
  577. if (*n > *m) {
  578. /* Computing 2nd power */
  579. i__1 = smlsiz + 1;
  580. wlalsd = *m * 9 + (*m << 1) * smlsiz + (*m << 3) * nlvl + *m *
  581. *nrhs + i__1 * i__1;
  582. if (*n >= mnthr) {
  583. /* Path 2a - underdetermined, with many more columns */
  584. /* than rows. */
  585. maxwrk = *m + *m * ilaenv_(&c__1, "SGELQF", " ", m, n, &
  586. c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
  587. /* Computing MAX */
  588. i__1 = maxwrk, i__2 = *m * *m + (*m << 2) + (*m << 1) *
  589. ilaenv_(&c__1, "SGEBRD", " ", m, m, &c_n1, &c_n1,
  590. (ftnlen)6, (ftnlen)1);
  591. maxwrk = f2cmax(i__1,i__2);
  592. /* Computing MAX */
  593. i__1 = maxwrk, i__2 = *m * *m + (*m << 2) + *nrhs *
  594. ilaenv_(&c__1, "SORMBR", "QLT", m, nrhs, m, &c_n1,
  595. (ftnlen)6, (ftnlen)3);
  596. maxwrk = f2cmax(i__1,i__2);
  597. /* Computing MAX */
  598. i__1 = maxwrk, i__2 = *m * *m + (*m << 2) + (*m - 1) *
  599. ilaenv_(&c__1, "SORMBR", "PLN", m, nrhs, m, &c_n1,
  600. (ftnlen)6, (ftnlen)3);
  601. maxwrk = f2cmax(i__1,i__2);
  602. if (*nrhs > 1) {
  603. /* Computing MAX */
  604. i__1 = maxwrk, i__2 = *m * *m + *m + *m * *nrhs;
  605. maxwrk = f2cmax(i__1,i__2);
  606. } else {
  607. /* Computing MAX */
  608. i__1 = maxwrk, i__2 = *m * *m + (*m << 1);
  609. maxwrk = f2cmax(i__1,i__2);
  610. }
  611. /* Computing MAX */
  612. i__1 = maxwrk, i__2 = *m + *nrhs * ilaenv_(&c__1, "SORMLQ"
  613. , "LT", n, nrhs, m, &c_n1, (ftnlen)6, (ftnlen)2);
  614. maxwrk = f2cmax(i__1,i__2);
  615. /* Computing MAX */
  616. i__1 = maxwrk, i__2 = *m * *m + (*m << 2) + wlalsd;
  617. maxwrk = f2cmax(i__1,i__2);
  618. /* XXX: Ensure the Path 2a case below is triggered. The workspace */
  619. /* calculation should use queries for all routines eventually. */
  620. /* Computing MAX */
  621. /* Computing MAX */
  622. i__3 = *m, i__4 = (*m << 1) - 4, i__3 = f2cmax(i__3,i__4),
  623. i__3 = f2cmax(i__3,*nrhs), i__4 = *n - *m * 3;
  624. i__1 = maxwrk, i__2 = (*m << 2) + *m * *m + f2cmax(i__3,i__4)
  625. ;
  626. maxwrk = f2cmax(i__1,i__2);
  627. } else {
  628. /* Path 2 - remaining underdetermined cases. */
  629. maxwrk = *m * 3 + (*n + *m) * ilaenv_(&c__1, "SGEBRD",
  630. " ", m, n, &c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
  631. /* Computing MAX */
  632. i__1 = maxwrk, i__2 = *m * 3 + *nrhs * ilaenv_(&c__1,
  633. "SORMBR", "QLT", m, nrhs, n, &c_n1, (ftnlen)6, (
  634. ftnlen)3);
  635. maxwrk = f2cmax(i__1,i__2);
  636. /* Computing MAX */
  637. i__1 = maxwrk, i__2 = *m * 3 + *m * ilaenv_(&c__1, "SORM"
  638. "BR", "PLN", n, nrhs, m, &c_n1, (ftnlen)6, (ftnlen)
  639. 3);
  640. maxwrk = f2cmax(i__1,i__2);
  641. /* Computing MAX */
  642. i__1 = maxwrk, i__2 = *m * 3 + wlalsd;
  643. maxwrk = f2cmax(i__1,i__2);
  644. }
  645. /* Computing MAX */
  646. i__1 = *m * 3 + *nrhs, i__2 = *m * 3 + *m, i__1 = f2cmax(i__1,
  647. i__2), i__2 = *m * 3 + wlalsd;
  648. minwrk = f2cmax(i__1,i__2);
  649. }
  650. }
  651. minwrk = f2cmin(minwrk,maxwrk);
  652. work[1] = (real) maxwrk;
  653. iwork[1] = liwork;
  654. if (*lwork < minwrk && ! lquery) {
  655. *info = -12;
  656. }
  657. }
  658. if (*info != 0) {
  659. i__1 = -(*info);
  660. xerbla_("SGELSD", &i__1, (ftnlen)6);
  661. return;
  662. } else if (lquery) {
  663. return;
  664. }
  665. /* Quick return if possible. */
  666. if (*m == 0 || *n == 0) {
  667. fprintf(stdout,"SGELSD quickreturn rank=0\n");
  668. *rank = 0;
  669. return;
  670. }
  671. /* Get machine parameters. */
  672. eps = slamch_("P");
  673. sfmin = slamch_("S");
  674. smlnum = sfmin / eps;
  675. bignum = 1.f / smlnum;
  676. // FILE *bla=fopen("/tmp/bla","w");
  677. //fprintf(bla,"SGELSD eps=%g sfmin=%g smlnum=%g bignum=%g\n",eps,sfmin,smlnum,bignum);
  678. //fclose(bla);
  679. slabad_(&smlnum, &bignum);
  680. /* Scale A if f2cmax entry outside range [SMLNUM,BIGNUM]. */
  681. anrm = slange_("M", m, n, &a[a_offset], lda, &work[1]);
  682. iascl = 0;
  683. if (anrm > 0.f && anrm < smlnum) {
  684. /* Scale matrix norm up to SMLNUM. */
  685. fprintf(stdout,"scaling A up to SML\n");
  686. slascl_("G", &c__0, &c__0, &anrm, &smlnum, m, n, &a[a_offset], lda,
  687. info);
  688. iascl = 1;
  689. } else if (anrm > bignum) {
  690. /* Scale matrix norm down to BIGNUM. */
  691. fprintf(stdout,"scaling A down to BIG\n");
  692. slascl_("G", &c__0, &c__0, &anrm, &bignum, m, n, &a[a_offset], lda,
  693. info);
  694. iascl = 2;
  695. } else if (anrm == 0.f) {
  696. /* Matrix all zero. Return zero solution. */
  697. fprintf(stdout,"A is zero soln\n");
  698. i__1 = f2cmax(*m,*n);
  699. slaset_("F", &i__1, nrhs, &c_b81, &c_b81, &b[b_offset], ldb);
  700. slaset_("F", &minmn, &c__1, &c_b81, &c_b81, &s[1], &c__1);
  701. *rank = 0;
  702. goto L10;
  703. }
  704. /* Scale B if f2cmax entry outside range [SMLNUM,BIGNUM]. */
  705. bnrm = slange_("M", m, nrhs, &b[b_offset], ldb, &work[1]);
  706. ibscl = 0;
  707. if (bnrm > 0.f && bnrm < smlnum) {
  708. /* Scale matrix norm up to SMLNUM. */
  709. fprintf(stdout,"scaling B up to SML\n");
  710. slascl_("G", &c__0, &c__0, &bnrm, &smlnum, m, nrhs, &b[b_offset], ldb,
  711. info);
  712. ibscl = 1;
  713. } else if (bnrm > bignum) {
  714. /* Scale matrix norm down to BIGNUM. */
  715. fprintf(stdout,"scaling B down to BIG\n");
  716. slascl_("G", &c__0, &c__0, &bnrm, &bignum, m, nrhs, &b[b_offset], ldb,
  717. info);
  718. ibscl = 2;
  719. }
  720. /* If M < N make sure certain entries of B are zero. */
  721. if (*m < *n) {
  722. i__1 = *n - *m;
  723. fprintf(stdout,"zeroing parts of B \n");
  724. slaset_("F", &i__1, nrhs, &c_b81, &c_b81, &b[*m + 1 + b_dim1], ldb);
  725. }
  726. /* Overdetermined case. */
  727. if (*m >= *n) {
  728. fprintf(stdout,"overdetermined, path 1 \n");
  729. /* Path 1 - overdetermined or exactly determined. */
  730. mm = *m;
  731. if (*m >= mnthr) {
  732. /* Path 1a - overdetermined, with many more rows than columns. */
  733. fprintf(stdout,"overdetermined, path 1a \n");
  734. mm = *n;
  735. itau = 1;
  736. nwork = itau + *n;
  737. /* Compute A=Q*R. */
  738. /* (Workspace: need 2*N, prefer N+N*NB) */
  739. i__1 = *lwork - nwork + 1;
  740. sgeqrf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &i__1,
  741. info);
  742. /* Multiply B by transpose(Q). */
  743. /* (Workspace: need N+NRHS, prefer N+NRHS*NB) */
  744. i__1 = *lwork - nwork + 1;
  745. sormqr_("L", "T", m, nrhs, n, &a[a_offset], lda, &work[itau], &b[
  746. b_offset], ldb, &work[nwork], &i__1, info);
  747. /* Zero out below R. */
  748. if (*n > 1) {
  749. i__1 = *n - 1;
  750. i__2 = *n - 1;
  751. slaset_("L", &i__1, &i__2, &c_b81, &c_b81, &a[a_dim1 + 2],
  752. lda);
  753. }
  754. }
  755. ie = 1;
  756. itauq = ie + *n;
  757. itaup = itauq + *n;
  758. nwork = itaup + *n;
  759. /* Bidiagonalize R in A. */
  760. /* (Workspace: need 3*N+MM, prefer 3*N+(MM+N)*NB) */
  761. i__1 = *lwork - nwork + 1;
  762. sgebrd_(&mm, n, &a[a_offset], lda, &s[1], &work[ie], &work[itauq], &
  763. work[itaup], &work[nwork], &i__1, info);
  764. /* Multiply B by transpose of left bidiagonalizing vectors of R. */
  765. /* (Workspace: need 3*N+NRHS, prefer 3*N+NRHS*NB) */
  766. i__1 = *lwork - nwork + 1;
  767. sormbr_("Q", "L", "T", &mm, nrhs, n, &a[a_offset], lda, &work[itauq],
  768. &b[b_offset], ldb, &work[nwork], &i__1, info);
  769. /* Solve the bidiagonal least squares problem. */
  770. slalsd_("U", &smlsiz, n, nrhs, &s[1], &work[ie], &b[b_offset], ldb,
  771. rcond, rank, &work[nwork], &iwork[1], info);
  772. if (*info != 0) {
  773. fprintf(stdout,"info !=0 nach slalsd\n");
  774. goto L10;
  775. }
  776. /* Multiply B by right bidiagonalizing vectors of R. */
  777. i__1 = *lwork - nwork + 1;
  778. sormbr_("P", "L", "N", n, nrhs, n, &a[a_offset], lda, &work[itaup], &
  779. b[b_offset], ldb, &work[nwork], &i__1, info);
  780. } else /* if(complicated condition) */ {
  781. fprintf(stdout,"not overdetermined \n");
  782. /* Computing MAX */
  783. i__1 = *m, i__2 = (*m << 1) - 4, i__1 = f2cmax(i__1,i__2), i__1 = f2cmax(
  784. i__1,*nrhs), i__2 = *n - *m * 3, i__1 = f2cmax(i__1,i__2);
  785. if (*n >= mnthr && *lwork >= (*m << 2) + *m * *m + f2cmax(i__1,wlalsd)) {
  786. /* Path 2a - underdetermined, with many more columns than rows */
  787. /* and sufficient workspace for an efficient algorithm. */
  788. fprintf(stdout,"not overdetermined, path 2a\n");
  789. ldwork = *m;
  790. /* Computing MAX */
  791. /* Computing MAX */
  792. i__3 = *m, i__4 = (*m << 1) - 4, i__3 = f2cmax(i__3,i__4), i__3 =
  793. f2cmax(i__3,*nrhs), i__4 = *n - *m * 3;
  794. i__1 = (*m << 2) + *m * *lda + f2cmax(i__3,i__4), i__2 = *m * *lda +
  795. *m + *m * *nrhs, i__1 = f2cmax(i__1,i__2), i__2 = (*m << 2)
  796. + *m * *lda + wlalsd;
  797. if (*lwork >= f2cmax(i__1,i__2)) {
  798. ldwork = *lda;
  799. }
  800. itau = 1;
  801. nwork = *m + 1;
  802. /* Compute A=L*Q. */
  803. /* (Workspace: need 2*M, prefer M+M*NB) */
  804. i__1 = *lwork - nwork + 1;
  805. sgelqf_(m, n, &a[a_offset], lda, &work[itau], &work[nwork], &i__1,
  806. info);
  807. il = nwork;
  808. /* Copy L to WORK(IL), zeroing out above its diagonal. */
  809. slacpy_("L", m, m, &a[a_offset], lda, &work[il], &ldwork);
  810. i__1 = *m - 1;
  811. i__2 = *m - 1;
  812. slaset_("U", &i__1, &i__2, &c_b81, &c_b81, &work[il + ldwork], &
  813. ldwork);
  814. ie = il + ldwork * *m;
  815. itauq = ie + *m;
  816. itaup = itauq + *m;
  817. nwork = itaup + *m;
  818. /* Bidiagonalize L in WORK(IL). */
  819. /* (Workspace: need M*M+5*M, prefer M*M+4*M+2*M*NB) */
  820. i__1 = *lwork - nwork + 1;
  821. sgebrd_(m, m, &work[il], &ldwork, &s[1], &work[ie], &work[itauq],
  822. &work[itaup], &work[nwork], &i__1, info);
  823. /* Multiply B by transpose of left bidiagonalizing vectors of L. */
  824. /* (Workspace: need M*M+4*M+NRHS, prefer M*M+4*M+NRHS*NB) */
  825. i__1 = *lwork - nwork + 1;
  826. sormbr_("Q", "L", "T", m, nrhs, m, &work[il], &ldwork, &work[
  827. itauq], &b[b_offset], ldb, &work[nwork], &i__1, info);
  828. /* Solve the bidiagonal least squares problem. */
  829. slalsd_("U", &smlsiz, m, nrhs, &s[1], &work[ie], &b[b_offset],
  830. ldb, rcond, rank, &work[nwork], &iwork[1], info);
  831. if (*info != 0) {
  832. goto L10;
  833. }
  834. /* Multiply B by right bidiagonalizing vectors of L. */
  835. i__1 = *lwork - nwork + 1;
  836. sormbr_("P", "L", "N", m, nrhs, m, &work[il], &ldwork, &work[
  837. itaup], &b[b_offset], ldb, &work[nwork], &i__1, info);
  838. /* Zero out below first M rows of B. */
  839. i__1 = *n - *m;
  840. slaset_("F", &i__1, nrhs, &c_b81, &c_b81, &b[*m + 1 + b_dim1],
  841. ldb);
  842. nwork = itau + *m;
  843. /* Multiply transpose(Q) by B. */
  844. /* (Workspace: need M+NRHS, prefer M+NRHS*NB) */
  845. i__1 = *lwork - nwork + 1;
  846. sormlq_("L", "T", n, nrhs, m, &a[a_offset], lda, &work[itau], &b[
  847. b_offset], ldb, &work[nwork], &i__1, info);
  848. } else {
  849. /* Path 2 - remaining underdetermined cases. */
  850. fprintf(stdout,"other underdetermined, path 2");
  851. ie = 1;
  852. itauq = ie + *m;
  853. itaup = itauq + *m;
  854. nwork = itaup + *m;
  855. /* Bidiagonalize A. */
  856. /* (Workspace: need 3*M+N, prefer 3*M+(M+N)*NB) */
  857. i__1 = *lwork - nwork + 1;
  858. sgebrd_(m, n, &a[a_offset], lda, &s[1], &work[ie], &work[itauq], &
  859. work[itaup], &work[nwork], &i__1, info);
  860. /* Multiply B by transpose of left bidiagonalizing vectors. */
  861. /* (Workspace: need 3*M+NRHS, prefer 3*M+NRHS*NB) */
  862. i__1 = *lwork - nwork + 1;
  863. sormbr_("Q", "L", "T", m, nrhs, n, &a[a_offset], lda, &work[itauq]
  864. , &b[b_offset], ldb, &work[nwork], &i__1, info);
  865. /* Solve the bidiagonal least squares problem. */
  866. slalsd_("L", &smlsiz, m, nrhs, &s[1], &work[ie], &b[b_offset],
  867. ldb, rcond, rank, &work[nwork], &iwork[1], info);
  868. if (*info != 0) {
  869. goto L10;
  870. }
  871. /* Multiply B by right bidiagonalizing vectors of A. */
  872. i__1 = *lwork - nwork + 1;
  873. sormbr_("P", "L", "N", n, nrhs, m, &a[a_offset], lda, &work[itaup]
  874. , &b[b_offset], ldb, &work[nwork], &i__1, info);
  875. }
  876. }
  877. /* Undo scaling. */
  878. if (iascl == 1) {
  879. fprintf(stdout," unscaling a1\n");
  880. slascl_("G", &c__0, &c__0, &anrm, &smlnum, n, nrhs, &b[b_offset], ldb,
  881. info);
  882. slascl_("G", &c__0, &c__0, &smlnum, &anrm, &minmn, &c__1, &s[1], &
  883. minmn, info);
  884. } else if (iascl == 2) {
  885. fprintf(stdout," unscaling a2\n");
  886. slascl_("G", &c__0, &c__0, &anrm, &bignum, n, nrhs, &b[b_offset], ldb,
  887. info);
  888. slascl_("G", &c__0, &c__0, &bignum, &anrm, &minmn, &c__1, &s[1], &
  889. minmn, info);
  890. }
  891. if (ibscl == 1) {
  892. fprintf(stdout," unscaling b1\n");
  893. slascl_("G", &c__0, &c__0, &smlnum, &bnrm, n, nrhs, &b[b_offset], ldb,
  894. info);
  895. } else if (ibscl == 2) {
  896. fprintf(stdout," unscaling b2\n");
  897. slascl_("G", &c__0, &c__0, &bignum, &bnrm, n, nrhs, &b[b_offset], ldb,
  898. info);
  899. }
  900. L10:
  901. work[1] = (real) maxwrk;
  902. iwork[1] = liwork;
  903. fprintf(stdout, "end of SGELSD\n");
  904. return;
  905. /* End of SGELSD */
  906. } /* sgelsd_ */