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.

sgbsvx.c 33 kB

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