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.

sgesvx.c 30 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  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. /* > \brief <b> SGESVX computes the solution to system of linear equations A * X = B for GE matrices</b> */
  235. /* =========== DOCUMENTATION =========== */
  236. /* Online html documentation available at */
  237. /* http://www.netlib.org/lapack/explore-html/ */
  238. /* > \htmlonly */
  239. /* > Download SGESVX + dependencies */
  240. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sgesvx.
  241. f"> */
  242. /* > [TGZ]</a> */
  243. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sgesvx.
  244. f"> */
  245. /* > [ZIP]</a> */
  246. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sgesvx.
  247. f"> */
  248. /* > [TXT]</a> */
  249. /* > \endhtmlonly */
  250. /* Definition: */
  251. /* =========== */
  252. /* SUBROUTINE SGESVX( FACT, TRANS, N, NRHS, A, LDA, AF, LDAF, IPIV, */
  253. /* EQUED, R, C, B, LDB, X, LDX, RCOND, FERR, BERR, */
  254. /* WORK, IWORK, INFO ) */
  255. /* CHARACTER EQUED, FACT, TRANS */
  256. /* INTEGER INFO, LDA, LDAF, LDB, LDX, N, NRHS */
  257. /* REAL RCOND */
  258. /* INTEGER IPIV( * ), IWORK( * ) */
  259. /* REAL A( LDA, * ), AF( LDAF, * ), B( LDB, * ), */
  260. /* $ BERR( * ), C( * ), FERR( * ), R( * ), */
  261. /* $ WORK( * ), X( LDX, * ) */
  262. /* > \par Purpose: */
  263. /* ============= */
  264. /* > */
  265. /* > \verbatim */
  266. /* > */
  267. /* > SGESVX uses the LU factorization to compute the solution to a real */
  268. /* > system of linear equations */
  269. /* > A * X = B, */
  270. /* > where A is an N-by-N matrix and X and B are N-by-NRHS matrices. */
  271. /* > */
  272. /* > Error bounds on the solution and a condition estimate are also */
  273. /* > provided. */
  274. /* > \endverbatim */
  275. /* > \par Description: */
  276. /* ================= */
  277. /* > */
  278. /* > \verbatim */
  279. /* > */
  280. /* > The following steps are performed: */
  281. /* > */
  282. /* > 1. If FACT = 'E', real scaling factors are computed to equilibrate */
  283. /* > the system: */
  284. /* > TRANS = 'N': diag(R)*A*diag(C) *inv(diag(C))*X = diag(R)*B */
  285. /* > TRANS = 'T': (diag(R)*A*diag(C))**T *inv(diag(R))*X = diag(C)*B */
  286. /* > TRANS = 'C': (diag(R)*A*diag(C))**H *inv(diag(R))*X = diag(C)*B */
  287. /* > Whether or not the system will be equilibrated depends on the */
  288. /* > scaling of the matrix A, but if equilibration is used, A is */
  289. /* > overwritten by diag(R)*A*diag(C) and B by diag(R)*B (if TRANS='N') */
  290. /* > or diag(C)*B (if TRANS = 'T' or 'C'). */
  291. /* > */
  292. /* > 2. If FACT = 'N' or 'E', the LU decomposition is used to factor the */
  293. /* > matrix A (after equilibration if FACT = 'E') as */
  294. /* > A = P * L * U, */
  295. /* > where P is a permutation matrix, L is a unit lower triangular */
  296. /* > matrix, and U is upper triangular. */
  297. /* > */
  298. /* > 3. If some U(i,i)=0, so that U is exactly singular, then the routine */
  299. /* > returns with INFO = i. Otherwise, the factored form of A is used */
  300. /* > to estimate the condition number of the matrix A. If the */
  301. /* > reciprocal of the condition number is less than machine precision, */
  302. /* > INFO = N+1 is returned as a warning, but the routine still goes on */
  303. /* > to solve for X and compute error bounds as described below. */
  304. /* > */
  305. /* > 4. The system of equations is solved for X using the factored form */
  306. /* > of A. */
  307. /* > */
  308. /* > 5. Iterative refinement is applied to improve the computed solution */
  309. /* > matrix and calculate error bounds and backward error estimates */
  310. /* > for it. */
  311. /* > */
  312. /* > 6. If equilibration was used, the matrix X is premultiplied by */
  313. /* > diag(C) (if TRANS = 'N') or diag(R) (if TRANS = 'T' or 'C') so */
  314. /* > that it solves the original system before equilibration. */
  315. /* > \endverbatim */
  316. /* Arguments: */
  317. /* ========== */
  318. /* > \param[in] FACT */
  319. /* > \verbatim */
  320. /* > FACT is CHARACTER*1 */
  321. /* > Specifies whether or not the factored form of the matrix A is */
  322. /* > supplied on entry, and if not, whether the matrix A should be */
  323. /* > equilibrated before it is factored. */
  324. /* > = 'F': On entry, AF and IPIV contain the factored form of A. */
  325. /* > If EQUED is not 'N', the matrix A has been */
  326. /* > equilibrated with scaling factors given by R and C. */
  327. /* > A, AF, and IPIV are not modified. */
  328. /* > = 'N': The matrix A will be copied to AF and factored. */
  329. /* > = 'E': The matrix A will be equilibrated if necessary, then */
  330. /* > copied to AF and factored. */
  331. /* > \endverbatim */
  332. /* > */
  333. /* > \param[in] TRANS */
  334. /* > \verbatim */
  335. /* > TRANS is CHARACTER*1 */
  336. /* > Specifies the form of the system of equations: */
  337. /* > = 'N': A * X = B (No transpose) */
  338. /* > = 'T': A**T * X = B (Transpose) */
  339. /* > = 'C': A**H * X = B (Transpose) */
  340. /* > \endverbatim */
  341. /* > */
  342. /* > \param[in] N */
  343. /* > \verbatim */
  344. /* > N is INTEGER */
  345. /* > The number of linear equations, i.e., the order of the */
  346. /* > matrix A. N >= 0. */
  347. /* > \endverbatim */
  348. /* > */
  349. /* > \param[in] NRHS */
  350. /* > \verbatim */
  351. /* > NRHS is INTEGER */
  352. /* > The number of right hand sides, i.e., the number of columns */
  353. /* > of the matrices B and X. NRHS >= 0. */
  354. /* > \endverbatim */
  355. /* > */
  356. /* > \param[in,out] A */
  357. /* > \verbatim */
  358. /* > A is REAL array, dimension (LDA,N) */
  359. /* > On entry, the N-by-N matrix A. If FACT = 'F' and EQUED is */
  360. /* > not 'N', then A must have been equilibrated by the scaling */
  361. /* > factors in R and/or C. A is not modified if FACT = 'F' or */
  362. /* > 'N', or if FACT = 'E' and EQUED = 'N' on exit. */
  363. /* > */
  364. /* > On exit, if EQUED .ne. 'N', A is scaled as follows: */
  365. /* > EQUED = 'R': A := diag(R) * A */
  366. /* > EQUED = 'C': A := A * diag(C) */
  367. /* > EQUED = 'B': A := diag(R) * A * diag(C). */
  368. /* > \endverbatim */
  369. /* > */
  370. /* > \param[in] LDA */
  371. /* > \verbatim */
  372. /* > LDA is INTEGER */
  373. /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
  374. /* > \endverbatim */
  375. /* > */
  376. /* > \param[in,out] AF */
  377. /* > \verbatim */
  378. /* > AF is REAL array, dimension (LDAF,N) */
  379. /* > If FACT = 'F', then AF is an input argument and on entry */
  380. /* > contains the factors L and U from the factorization */
  381. /* > A = P*L*U as computed by SGETRF. If EQUED .ne. 'N', then */
  382. /* > AF is the factored form of the equilibrated matrix A. */
  383. /* > */
  384. /* > If FACT = 'N', then AF is an output argument and on exit */
  385. /* > returns the factors L and U from the factorization A = P*L*U */
  386. /* > of the original matrix A. */
  387. /* > */
  388. /* > If FACT = 'E', then AF is an output argument and on exit */
  389. /* > returns the factors L and U from the factorization A = P*L*U */
  390. /* > of the equilibrated matrix A (see the description of A for */
  391. /* > the form of the equilibrated matrix). */
  392. /* > \endverbatim */
  393. /* > */
  394. /* > \param[in] LDAF */
  395. /* > \verbatim */
  396. /* > LDAF is INTEGER */
  397. /* > The leading dimension of the array AF. LDAF >= f2cmax(1,N). */
  398. /* > \endverbatim */
  399. /* > */
  400. /* > \param[in,out] IPIV */
  401. /* > \verbatim */
  402. /* > IPIV is INTEGER array, dimension (N) */
  403. /* > If FACT = 'F', then IPIV is an input argument and on entry */
  404. /* > contains the pivot indices from the factorization A = P*L*U */
  405. /* > as computed by SGETRF; row i of the matrix was interchanged */
  406. /* > with row IPIV(i). */
  407. /* > */
  408. /* > If FACT = 'N', then IPIV is an output argument and on exit */
  409. /* > contains the pivot indices from the factorization A = P*L*U */
  410. /* > of the original matrix A. */
  411. /* > */
  412. /* > If FACT = 'E', then IPIV is an output argument and on exit */
  413. /* > contains the pivot indices from the factorization A = P*L*U */
  414. /* > of the equilibrated matrix A. */
  415. /* > \endverbatim */
  416. /* > */
  417. /* > \param[in,out] EQUED */
  418. /* > \verbatim */
  419. /* > EQUED is CHARACTER*1 */
  420. /* > Specifies the form of equilibration that was done. */
  421. /* > = 'N': No equilibration (always true if FACT = 'N'). */
  422. /* > = 'R': Row equilibration, i.e., A has been premultiplied by */
  423. /* > diag(R). */
  424. /* > = 'C': Column equilibration, i.e., A has been postmultiplied */
  425. /* > by diag(C). */
  426. /* > = 'B': Both row and column equilibration, i.e., A has been */
  427. /* > replaced by diag(R) * A * diag(C). */
  428. /* > EQUED is an input argument if FACT = 'F'; otherwise, it is an */
  429. /* > output argument. */
  430. /* > \endverbatim */
  431. /* > */
  432. /* > \param[in,out] R */
  433. /* > \verbatim */
  434. /* > R is REAL array, dimension (N) */
  435. /* > The row scale factors for A. If EQUED = 'R' or 'B', A is */
  436. /* > multiplied on the left by diag(R); if EQUED = 'N' or 'C', R */
  437. /* > is not accessed. R is an input argument if FACT = 'F'; */
  438. /* > otherwise, R is an output argument. If FACT = 'F' and */
  439. /* > EQUED = 'R' or 'B', each element of R must be positive. */
  440. /* > \endverbatim */
  441. /* > */
  442. /* > \param[in,out] C */
  443. /* > \verbatim */
  444. /* > C is REAL array, dimension (N) */
  445. /* > The column scale factors for A. If EQUED = 'C' or 'B', A is */
  446. /* > multiplied on the right by diag(C); if EQUED = 'N' or 'R', C */
  447. /* > is not accessed. C is an input argument if FACT = 'F'; */
  448. /* > otherwise, C is an output argument. If FACT = 'F' and */
  449. /* > EQUED = 'C' or 'B', each element of C must be positive. */
  450. /* > \endverbatim */
  451. /* > */
  452. /* > \param[in,out] B */
  453. /* > \verbatim */
  454. /* > B is REAL array, dimension (LDB,NRHS) */
  455. /* > On entry, the N-by-NRHS right hand side matrix B. */
  456. /* > On exit, */
  457. /* > if EQUED = 'N', B is not modified; */
  458. /* > if TRANS = 'N' and EQUED = 'R' or 'B', B is overwritten by */
  459. /* > diag(R)*B; */
  460. /* > if TRANS = 'T' or 'C' and EQUED = 'C' or 'B', B is */
  461. /* > overwritten by diag(C)*B. */
  462. /* > \endverbatim */
  463. /* > */
  464. /* > \param[in] LDB */
  465. /* > \verbatim */
  466. /* > LDB is INTEGER */
  467. /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */
  468. /* > \endverbatim */
  469. /* > */
  470. /* > \param[out] X */
  471. /* > \verbatim */
  472. /* > X is REAL array, dimension (LDX,NRHS) */
  473. /* > If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X */
  474. /* > to the original system of equations. Note that A and B are */
  475. /* > modified on exit if EQUED .ne. 'N', and the solution to the */
  476. /* > equilibrated system is inv(diag(C))*X if TRANS = 'N' and */
  477. /* > EQUED = 'C' or 'B', or inv(diag(R))*X if TRANS = 'T' or 'C' */
  478. /* > and EQUED = 'R' or 'B'. */
  479. /* > \endverbatim */
  480. /* > */
  481. /* > \param[in] LDX */
  482. /* > \verbatim */
  483. /* > LDX is INTEGER */
  484. /* > The leading dimension of the array X. LDX >= f2cmax(1,N). */
  485. /* > \endverbatim */
  486. /* > */
  487. /* > \param[out] RCOND */
  488. /* > \verbatim */
  489. /* > RCOND is REAL */
  490. /* > The estimate of the reciprocal condition number of the matrix */
  491. /* > A after equilibration (if done). If RCOND is less than the */
  492. /* > machine precision (in particular, if RCOND = 0), the matrix */
  493. /* > is singular to working precision. This condition is */
  494. /* > indicated by a return code of INFO > 0. */
  495. /* > \endverbatim */
  496. /* > */
  497. /* > \param[out] FERR */
  498. /* > \verbatim */
  499. /* > FERR is REAL array, dimension (NRHS) */
  500. /* > The estimated forward error bound for each solution vector */
  501. /* > X(j) (the j-th column of the solution matrix X). */
  502. /* > If XTRUE is the true solution corresponding to X(j), FERR(j) */
  503. /* > is an estimated upper bound for the magnitude of the largest */
  504. /* > element in (X(j) - XTRUE) divided by the magnitude of the */
  505. /* > largest element in X(j). The estimate is as reliable as */
  506. /* > the estimate for RCOND, and is almost always a slight */
  507. /* > overestimate of the true error. */
  508. /* > \endverbatim */
  509. /* > */
  510. /* > \param[out] BERR */
  511. /* > \verbatim */
  512. /* > BERR is REAL array, dimension (NRHS) */
  513. /* > The componentwise relative backward error of each solution */
  514. /* > vector X(j) (i.e., the smallest relative change in */
  515. /* > any element of A or B that makes X(j) an exact solution). */
  516. /* > \endverbatim */
  517. /* > */
  518. /* > \param[out] WORK */
  519. /* > \verbatim */
  520. /* > WORK is REAL array, dimension (4*N) */
  521. /* > On exit, WORK(1) contains the reciprocal pivot growth */
  522. /* > factor norm(A)/norm(U). The "f2cmax absolute element" norm is */
  523. /* > used. If WORK(1) is much less than 1, then the stability */
  524. /* > of the LU factorization of the (equilibrated) matrix A */
  525. /* > could be poor. This also means that the solution X, condition */
  526. /* > estimator RCOND, and forward error bound FERR could be */
  527. /* > unreliable. If factorization fails with 0<INFO<=N, then */
  528. /* > WORK(1) contains the reciprocal pivot growth factor for the */
  529. /* > leading INFO columns of A. */
  530. /* > \endverbatim */
  531. /* > */
  532. /* > \param[out] IWORK */
  533. /* > \verbatim */
  534. /* > IWORK is INTEGER array, dimension (N) */
  535. /* > \endverbatim */
  536. /* > */
  537. /* > \param[out] INFO */
  538. /* > \verbatim */
  539. /* > INFO is INTEGER */
  540. /* > = 0: successful exit */
  541. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  542. /* > > 0: if INFO = i, and i is */
  543. /* > <= N: U(i,i) is exactly zero. The factorization has */
  544. /* > been completed, but the factor U is exactly */
  545. /* > singular, so the solution and error bounds */
  546. /* > could not be computed. RCOND = 0 is returned. */
  547. /* > = N+1: U is nonsingular, but RCOND is less than machine */
  548. /* > precision, meaning that the matrix is singular */
  549. /* > to working precision. Nevertheless, the */
  550. /* > solution and error bounds are computed because */
  551. /* > there are a number of situations where the */
  552. /* > computed solution can be more accurate than the */
  553. /* > value of RCOND would suggest. */
  554. /* > \endverbatim */
  555. /* Authors: */
  556. /* ======== */
  557. /* > \author Univ. of Tennessee */
  558. /* > \author Univ. of California Berkeley */
  559. /* > \author Univ. of Colorado Denver */
  560. /* > \author NAG Ltd. */
  561. /* > \date April 2012 */
  562. /* > \ingroup realGEsolve */
  563. /* ===================================================================== */
  564. /* Subroutine */ void sgesvx_(char *fact, char *trans, integer *n, integer *
  565. nrhs, real *a, integer *lda, real *af, integer *ldaf, integer *ipiv,
  566. char *equed, real *r__, real *c__, real *b, integer *ldb, real *x,
  567. integer *ldx, real *rcond, real *ferr, real *berr, real *work,
  568. integer *iwork, integer *info)
  569. {
  570. /* System generated locals */
  571. integer a_dim1, a_offset, af_dim1, af_offset, b_dim1, b_offset, x_dim1,
  572. x_offset, i__1, i__2;
  573. real r__1, r__2;
  574. /* Local variables */
  575. real amax;
  576. char norm[1];
  577. integer i__, j;
  578. extern logical lsame_(char *, char *);
  579. real rcmin, rcmax, anorm;
  580. logical equil;
  581. real colcnd;
  582. extern real slamch_(char *), slange_(char *, integer *, integer *,
  583. real *, integer *, real *);
  584. logical nofact;
  585. extern /* Subroutine */ void slaqge_(integer *, integer *, real *, integer
  586. *, real *, real *, real *, real *, real *, char *);
  587. extern int xerbla_(char *, integer *, ftnlen);
  588. extern void sgecon_(char *, integer *,
  589. real *, integer *, real *, real *, real *, integer *, integer *);
  590. real bignum;
  591. integer infequ;
  592. logical colequ;
  593. extern /* Subroutine */ void sgeequ_(integer *, integer *, real *, integer
  594. *, real *, real *, real *, real *, real *, integer *), sgerfs_(
  595. char *, integer *, integer *, real *, integer *, real *, integer *
  596. , integer *, real *, integer *, real *, integer *, real *, real *,
  597. real *, integer *, integer *);
  598. extern int sgetrf_(integer *,
  599. integer *, real *, integer *, integer *, integer *);
  600. real rowcnd;
  601. extern /* Subroutine */ void slacpy_(char *, integer *, integer *, real *,
  602. integer *, real *, integer *);
  603. logical notran;
  604. extern real slantr_(char *, char *, char *, integer *, integer *, real *,
  605. integer *, real *);
  606. extern /* Subroutine */ int sgetrs_(char *, integer *, integer *, real *,
  607. integer *, integer *, real *, integer *, integer *);
  608. real smlnum;
  609. logical rowequ;
  610. real rpvgrw;
  611. /* -- LAPACK driver routine (version 3.7.0) -- */
  612. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  613. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  614. /* April 2012 */
  615. /* ===================================================================== */
  616. /* Parameter adjustments */
  617. a_dim1 = *lda;
  618. a_offset = 1 + a_dim1 * 1;
  619. a -= a_offset;
  620. af_dim1 = *ldaf;
  621. af_offset = 1 + af_dim1 * 1;
  622. af -= af_offset;
  623. --ipiv;
  624. --r__;
  625. --c__;
  626. b_dim1 = *ldb;
  627. b_offset = 1 + b_dim1 * 1;
  628. b -= b_offset;
  629. x_dim1 = *ldx;
  630. x_offset = 1 + x_dim1 * 1;
  631. x -= x_offset;
  632. --ferr;
  633. --berr;
  634. --work;
  635. --iwork;
  636. /* Function Body */
  637. *info = 0;
  638. nofact = lsame_(fact, "N");
  639. equil = lsame_(fact, "E");
  640. notran = lsame_(trans, "N");
  641. if (nofact || equil) {
  642. *(unsigned char *)equed = 'N';
  643. rowequ = FALSE_;
  644. colequ = FALSE_;
  645. } else {
  646. rowequ = lsame_(equed, "R") || lsame_(equed,
  647. "B");
  648. colequ = lsame_(equed, "C") || lsame_(equed,
  649. "B");
  650. smlnum = slamch_("Safe minimum");
  651. bignum = 1.f / smlnum;
  652. }
  653. /* Test the input parameters. */
  654. if (! nofact && ! equil && ! lsame_(fact, "F")) {
  655. *info = -1;
  656. } else if (! notran && ! lsame_(trans, "T") && !
  657. lsame_(trans, "C")) {
  658. *info = -2;
  659. } else if (*n < 0) {
  660. *info = -3;
  661. } else if (*nrhs < 0) {
  662. *info = -4;
  663. } else if (*lda < f2cmax(1,*n)) {
  664. *info = -6;
  665. } else if (*ldaf < f2cmax(1,*n)) {
  666. *info = -8;
  667. } else if (lsame_(fact, "F") && ! (rowequ || colequ
  668. || lsame_(equed, "N"))) {
  669. *info = -10;
  670. } else {
  671. if (rowequ) {
  672. rcmin = bignum;
  673. rcmax = 0.f;
  674. i__1 = *n;
  675. for (j = 1; j <= i__1; ++j) {
  676. /* Computing MIN */
  677. r__1 = rcmin, r__2 = r__[j];
  678. rcmin = f2cmin(r__1,r__2);
  679. /* Computing MAX */
  680. r__1 = rcmax, r__2 = r__[j];
  681. rcmax = f2cmax(r__1,r__2);
  682. /* L10: */
  683. }
  684. if (rcmin <= 0.f) {
  685. *info = -11;
  686. } else if (*n > 0) {
  687. rowcnd = f2cmax(rcmin,smlnum) / f2cmin(rcmax,bignum);
  688. } else {
  689. rowcnd = 1.f;
  690. }
  691. }
  692. if (colequ && *info == 0) {
  693. rcmin = bignum;
  694. rcmax = 0.f;
  695. i__1 = *n;
  696. for (j = 1; j <= i__1; ++j) {
  697. /* Computing MIN */
  698. r__1 = rcmin, r__2 = c__[j];
  699. rcmin = f2cmin(r__1,r__2);
  700. /* Computing MAX */
  701. r__1 = rcmax, r__2 = c__[j];
  702. rcmax = f2cmax(r__1,r__2);
  703. /* L20: */
  704. }
  705. if (rcmin <= 0.f) {
  706. *info = -12;
  707. } else if (*n > 0) {
  708. colcnd = f2cmax(rcmin,smlnum) / f2cmin(rcmax,bignum);
  709. } else {
  710. colcnd = 1.f;
  711. }
  712. }
  713. if (*info == 0) {
  714. if (*ldb < f2cmax(1,*n)) {
  715. *info = -14;
  716. } else if (*ldx < f2cmax(1,*n)) {
  717. *info = -16;
  718. }
  719. }
  720. }
  721. if (*info != 0) {
  722. i__1 = -(*info);
  723. xerbla_("SGESVX", &i__1, (ftnlen)6);
  724. return;
  725. }
  726. if (equil) {
  727. /* Compute row and column scalings to equilibrate the matrix A. */
  728. sgeequ_(n, n, &a[a_offset], lda, &r__[1], &c__[1], &rowcnd, &colcnd, &
  729. amax, &infequ);
  730. if (infequ == 0) {
  731. /* Equilibrate the matrix. */
  732. slaqge_(n, n, &a[a_offset], lda, &r__[1], &c__[1], &rowcnd, &
  733. colcnd, &amax, equed);
  734. rowequ = lsame_(equed, "R") || lsame_(equed,
  735. "B");
  736. colequ = lsame_(equed, "C") || lsame_(equed,
  737. "B");
  738. }
  739. }
  740. /* Scale the right hand side. */
  741. if (notran) {
  742. if (rowequ) {
  743. i__1 = *nrhs;
  744. for (j = 1; j <= i__1; ++j) {
  745. i__2 = *n;
  746. for (i__ = 1; i__ <= i__2; ++i__) {
  747. b[i__ + j * b_dim1] = r__[i__] * b[i__ + j * b_dim1];
  748. /* L30: */
  749. }
  750. /* L40: */
  751. }
  752. }
  753. } else if (colequ) {
  754. i__1 = *nrhs;
  755. for (j = 1; j <= i__1; ++j) {
  756. i__2 = *n;
  757. for (i__ = 1; i__ <= i__2; ++i__) {
  758. b[i__ + j * b_dim1] = c__[i__] * b[i__ + j * b_dim1];
  759. /* L50: */
  760. }
  761. /* L60: */
  762. }
  763. }
  764. if (nofact || equil) {
  765. /* Compute the LU factorization of A. */
  766. slacpy_("Full", n, n, &a[a_offset], lda, &af[af_offset], ldaf);
  767. sgetrf_(n, n, &af[af_offset], ldaf, &ipiv[1], info);
  768. /* Return if INFO is non-zero. */
  769. if (*info > 0) {
  770. /* Compute the reciprocal pivot growth factor of the */
  771. /* leading rank-deficient INFO columns of A. */
  772. rpvgrw = slantr_("M", "U", "N", info, info, &af[af_offset], ldaf,
  773. &work[1]);
  774. if (rpvgrw == 0.f) {
  775. rpvgrw = 1.f;
  776. } else {
  777. rpvgrw = slange_("M", n, info, &a[a_offset], lda, &work[1]) / rpvgrw;
  778. }
  779. work[1] = rpvgrw;
  780. *rcond = 0.f;
  781. return;
  782. }
  783. }
  784. /* Compute the norm of the matrix A and the */
  785. /* reciprocal pivot growth factor RPVGRW. */
  786. if (notran) {
  787. *(unsigned char *)norm = '1';
  788. } else {
  789. *(unsigned char *)norm = 'I';
  790. }
  791. anorm = slange_(norm, n, n, &a[a_offset], lda, &work[1]);
  792. rpvgrw = slantr_("M", "U", "N", n, n, &af[af_offset], ldaf, &work[1]);
  793. if (rpvgrw == 0.f) {
  794. rpvgrw = 1.f;
  795. } else {
  796. rpvgrw = slange_("M", n, n, &a[a_offset], lda, &work[1]) /
  797. rpvgrw;
  798. }
  799. /* Compute the reciprocal of the condition number of A. */
  800. sgecon_(norm, n, &af[af_offset], ldaf, &anorm, rcond, &work[1], &iwork[1],
  801. info);
  802. /* Compute the solution matrix X. */
  803. slacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx);
  804. sgetrs_(trans, n, nrhs, &af[af_offset], ldaf, &ipiv[1], &x[x_offset], ldx,
  805. info);
  806. /* Use iterative refinement to improve the computed solution and */
  807. /* compute error bounds and backward error estimates for it. */
  808. sgerfs_(trans, n, nrhs, &a[a_offset], lda, &af[af_offset], ldaf, &ipiv[1],
  809. &b[b_offset], ldb, &x[x_offset], ldx, &ferr[1], &berr[1], &work[
  810. 1], &iwork[1], info);
  811. /* Transform the solution matrix X to a solution of the original */
  812. /* system. */
  813. if (notran) {
  814. if (colequ) {
  815. i__1 = *nrhs;
  816. for (j = 1; j <= i__1; ++j) {
  817. i__2 = *n;
  818. for (i__ = 1; i__ <= i__2; ++i__) {
  819. x[i__ + j * x_dim1] = c__[i__] * x[i__ + j * x_dim1];
  820. /* L70: */
  821. }
  822. /* L80: */
  823. }
  824. i__1 = *nrhs;
  825. for (j = 1; j <= i__1; ++j) {
  826. ferr[j] /= colcnd;
  827. /* L90: */
  828. }
  829. }
  830. } else if (rowequ) {
  831. i__1 = *nrhs;
  832. for (j = 1; j <= i__1; ++j) {
  833. i__2 = *n;
  834. for (i__ = 1; i__ <= i__2; ++i__) {
  835. x[i__ + j * x_dim1] = r__[i__] * x[i__ + j * x_dim1];
  836. /* L100: */
  837. }
  838. /* L110: */
  839. }
  840. i__1 = *nrhs;
  841. for (j = 1; j <= i__1; ++j) {
  842. ferr[j] /= rowcnd;
  843. /* L120: */
  844. }
  845. }
  846. /* Set INFO = N+1 if the matrix is singular to working precision. */
  847. if (*rcond < slamch_("Epsilon")) {
  848. *info = *n + 1;
  849. }
  850. work[1] = rpvgrw;
  851. return;
  852. /* End of SGESVX */
  853. } /* sgesvx_ */