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.

dpbsvx.c 32 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. /* f2c.h -- Standard Fortran to C header file */
  2. /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
  3. - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
  4. #ifndef F2C_INCLUDE
  5. #define F2C_INCLUDE
  6. #include <math.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <complex.h>
  11. #ifdef complex
  12. #undef complex
  13. #endif
  14. #ifdef I
  15. #undef I
  16. #endif
  17. #if defined(_WIN64)
  18. typedef long long BLASLONG;
  19. typedef unsigned long long BLASULONG;
  20. #else
  21. typedef long BLASLONG;
  22. typedef unsigned long BLASULONG;
  23. #endif
  24. #ifdef LAPACK_ILP64
  25. typedef BLASLONG blasint;
  26. #if defined(_WIN64)
  27. #define blasabs(x) llabs(x)
  28. #else
  29. #define blasabs(x) labs(x)
  30. #endif
  31. #else
  32. typedef int blasint;
  33. #define blasabs(x) abs(x)
  34. #endif
  35. typedef blasint integer;
  36. typedef unsigned int uinteger;
  37. typedef char *address;
  38. typedef short int shortint;
  39. typedef float real;
  40. typedef double doublereal;
  41. typedef struct { real r, i; } complex;
  42. typedef struct { doublereal r, i; } doublecomplex;
  43. static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
  44. static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
  45. static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
  46. static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
  47. #define pCf(z) (*_pCf(z))
  48. #define pCd(z) (*_pCd(z))
  49. typedef int logical;
  50. typedef short int shortlogical;
  51. typedef char logical1;
  52. typedef char integer1;
  53. #define TRUE_ (1)
  54. #define FALSE_ (0)
  55. /* Extern is for use with -E */
  56. #ifndef Extern
  57. #define Extern extern
  58. #endif
  59. /* I/O stuff */
  60. typedef int flag;
  61. typedef int ftnlen;
  62. typedef int ftnint;
  63. /*external read, write*/
  64. typedef struct
  65. { flag cierr;
  66. ftnint ciunit;
  67. flag ciend;
  68. char *cifmt;
  69. ftnint cirec;
  70. } cilist;
  71. /*internal read, write*/
  72. typedef struct
  73. { flag icierr;
  74. char *iciunit;
  75. flag iciend;
  76. char *icifmt;
  77. ftnint icirlen;
  78. ftnint icirnum;
  79. } icilist;
  80. /*open*/
  81. typedef struct
  82. { flag oerr;
  83. ftnint ounit;
  84. char *ofnm;
  85. ftnlen ofnmlen;
  86. char *osta;
  87. char *oacc;
  88. char *ofm;
  89. ftnint orl;
  90. char *oblnk;
  91. } olist;
  92. /*close*/
  93. typedef struct
  94. { flag cerr;
  95. ftnint cunit;
  96. char *csta;
  97. } cllist;
  98. /*rewind, backspace, endfile*/
  99. typedef struct
  100. { flag aerr;
  101. ftnint aunit;
  102. } alist;
  103. /* inquire */
  104. typedef struct
  105. { flag inerr;
  106. ftnint inunit;
  107. char *infile;
  108. ftnlen infilen;
  109. ftnint *inex; /*parameters in standard's order*/
  110. ftnint *inopen;
  111. ftnint *innum;
  112. ftnint *innamed;
  113. char *inname;
  114. ftnlen innamlen;
  115. char *inacc;
  116. ftnlen inacclen;
  117. char *inseq;
  118. ftnlen inseqlen;
  119. char *indir;
  120. ftnlen indirlen;
  121. char *infmt;
  122. ftnlen infmtlen;
  123. char *inform;
  124. ftnint informlen;
  125. char *inunf;
  126. ftnlen inunflen;
  127. ftnint *inrecl;
  128. ftnint *innrec;
  129. char *inblank;
  130. ftnlen inblanklen;
  131. } inlist;
  132. #define VOID void
  133. union Multitype { /* for multiple entry points */
  134. integer1 g;
  135. shortint h;
  136. integer i;
  137. /* longint j; */
  138. real r;
  139. doublereal d;
  140. complex c;
  141. doublecomplex z;
  142. };
  143. typedef union Multitype Multitype;
  144. struct Vardesc { /* for Namelist */
  145. char *name;
  146. char *addr;
  147. ftnlen *dims;
  148. int type;
  149. };
  150. typedef struct Vardesc Vardesc;
  151. struct Namelist {
  152. char *name;
  153. Vardesc **vars;
  154. int nvars;
  155. };
  156. typedef struct Namelist Namelist;
  157. #define abs(x) ((x) >= 0 ? (x) : -(x))
  158. #define dabs(x) (fabs(x))
  159. #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
  160. #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
  161. #define dmin(a,b) (f2cmin(a,b))
  162. #define dmax(a,b) (f2cmax(a,b))
  163. #define bit_test(a,b) ((a) >> (b) & 1)
  164. #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
  165. #define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
  166. #define abort_() { sig_die("Fortran abort routine called", 1); }
  167. #define c_abs(z) (cabsf(Cf(z)))
  168. #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
  169. #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
  170. #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
  171. #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
  172. #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
  173. #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
  174. //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
  175. #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
  176. #define d_abs(x) (fabs(*(x)))
  177. #define d_acos(x) (acos(*(x)))
  178. #define d_asin(x) (asin(*(x)))
  179. #define d_atan(x) (atan(*(x)))
  180. #define d_atn2(x, y) (atan2(*(x),*(y)))
  181. #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
  182. #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
  183. #define d_cos(x) (cos(*(x)))
  184. #define d_cosh(x) (cosh(*(x)))
  185. #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
  186. #define d_exp(x) (exp(*(x)))
  187. #define d_imag(z) (cimag(Cd(z)))
  188. #define r_imag(z) (cimag(Cf(z)))
  189. #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  190. #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
  191. #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  192. #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
  193. #define d_log(x) (log(*(x)))
  194. #define d_mod(x, y) (fmod(*(x), *(y)))
  195. #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
  196. #define d_nint(x) u_nint(*(x))
  197. #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
  198. #define d_sign(a,b) u_sign(*(a),*(b))
  199. #define r_sign(a,b) u_sign(*(a),*(b))
  200. #define d_sin(x) (sin(*(x)))
  201. #define d_sinh(x) (sinh(*(x)))
  202. #define d_sqrt(x) (sqrt(*(x)))
  203. #define d_tan(x) (tan(*(x)))
  204. #define d_tanh(x) (tanh(*(x)))
  205. #define i_abs(x) abs(*(x))
  206. #define i_dnnt(x) ((integer)u_nint(*(x)))
  207. #define i_len(s, n) (n)
  208. #define i_nint(x) ((integer)u_nint(*(x)))
  209. #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
  210. #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
  211. #define pow_si(B,E) spow_ui(*(B),*(E))
  212. #define pow_ri(B,E) spow_ui(*(B),*(E))
  213. #define pow_di(B,E) dpow_ui(*(B),*(E))
  214. #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
  215. #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
  216. #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
  217. #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
  218. #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
  219. #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
  220. #define sig_die(s, kill) { exit(1); }
  221. #define s_stop(s, n) {exit(0);}
  222. static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
  223. #define z_abs(z) (cabs(Cd(z)))
  224. #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
  225. #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
  226. #define myexit_() break;
  227. #define mycycle() continue;
  228. #define myceiling(w) {ceil(w)}
  229. #define myhuge(w) {HUGE_VAL}
  230. //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
  231. #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
  232. /* procedure parameter types for -A and -C++ */
  233. #define F2C_proc_par_types 1
  234. #ifdef __cplusplus
  235. typedef logical (*L_fp)(...);
  236. #else
  237. typedef logical (*L_fp)();
  238. #endif
  239. static float spow_ui(float x, integer n) {
  240. float pow=1.0; unsigned long int u;
  241. if(n != 0) {
  242. if(n < 0) n = -n, x = 1/x;
  243. for(u = n; ; ) {
  244. if(u & 01) pow *= x;
  245. if(u >>= 1) x *= x;
  246. else break;
  247. }
  248. }
  249. return pow;
  250. }
  251. static double dpow_ui(double x, integer n) {
  252. double pow=1.0; unsigned long int u;
  253. if(n != 0) {
  254. if(n < 0) n = -n, x = 1/x;
  255. for(u = n; ; ) {
  256. if(u & 01) pow *= x;
  257. if(u >>= 1) x *= x;
  258. else break;
  259. }
  260. }
  261. return pow;
  262. }
  263. static _Complex float cpow_ui(_Complex float x, integer n) {
  264. _Complex float pow=1.0; unsigned long int u;
  265. if(n != 0) {
  266. if(n < 0) n = -n, x = 1/x;
  267. for(u = n; ; ) {
  268. if(u & 01) pow *= x;
  269. if(u >>= 1) x *= x;
  270. else break;
  271. }
  272. }
  273. return pow;
  274. }
  275. static _Complex double zpow_ui(_Complex double x, integer n) {
  276. _Complex double pow=1.0; unsigned long int u;
  277. if(n != 0) {
  278. if(n < 0) n = -n, x = 1/x;
  279. for(u = n; ; ) {
  280. if(u & 01) pow *= x;
  281. if(u >>= 1) x *= x;
  282. else break;
  283. }
  284. }
  285. return pow;
  286. }
  287. static integer pow_ii(integer x, integer n) {
  288. integer pow; unsigned long int u;
  289. if (n <= 0) {
  290. if (n == 0 || x == 1) pow = 1;
  291. else if (x != -1) pow = x == 0 ? 1/x : 0;
  292. else n = -n;
  293. }
  294. if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
  295. u = n;
  296. for(pow = 1; ; ) {
  297. if(u & 01) pow *= x;
  298. if(u >>= 1) x *= x;
  299. else break;
  300. }
  301. }
  302. return pow;
  303. }
  304. static integer dmaxloc_(double *w, integer s, integer e, integer *n)
  305. {
  306. double m; integer i, mi;
  307. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  308. if (w[i-1]>m) mi=i ,m=w[i-1];
  309. return mi-s+1;
  310. }
  311. static integer smaxloc_(float *w, integer s, integer e, integer *n)
  312. {
  313. float m; integer i, mi;
  314. for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
  315. if (w[i-1]>m) mi=i ,m=w[i-1];
  316. return mi-s+1;
  317. }
  318. static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  319. integer n = *n_, incx = *incx_, incy = *incy_, i;
  320. _Complex float zdotc = 0.0;
  321. if (incx == 1 && incy == 1) {
  322. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  323. zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
  324. }
  325. } else {
  326. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  327. zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
  328. }
  329. }
  330. pCf(z) = zdotc;
  331. }
  332. static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  333. integer n = *n_, incx = *incx_, incy = *incy_, i;
  334. _Complex double zdotc = 0.0;
  335. if (incx == 1 && incy == 1) {
  336. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  337. zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
  338. }
  339. } else {
  340. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  341. zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
  342. }
  343. }
  344. pCd(z) = zdotc;
  345. }
  346. static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
  347. integer n = *n_, incx = *incx_, incy = *incy_, i;
  348. _Complex float zdotc = 0.0;
  349. if (incx == 1 && incy == 1) {
  350. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  351. zdotc += Cf(&x[i]) * Cf(&y[i]);
  352. }
  353. } else {
  354. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  355. zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
  356. }
  357. }
  358. pCf(z) = zdotc;
  359. }
  360. static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
  361. integer n = *n_, incx = *incx_, incy = *incy_, i;
  362. _Complex double zdotc = 0.0;
  363. if (incx == 1 && incy == 1) {
  364. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  365. zdotc += Cd(&x[i]) * Cd(&y[i]);
  366. }
  367. } else {
  368. for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
  369. zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
  370. }
  371. }
  372. pCd(z) = zdotc;
  373. }
  374. #endif
  375. /* -- translated by f2c (version 20000121).
  376. You must link the resulting object file with the libraries:
  377. -lf2c -lm (in that order)
  378. */
  379. /* Table of constant values */
  380. static integer c__1 = 1;
  381. /* > \brief <b> DPBSVX computes the solution to system of linear equations A * X = B for OTHER matrices</b> */
  382. /* =========== DOCUMENTATION =========== */
  383. /* Online html documentation available at */
  384. /* http://www.netlib.org/lapack/explore-html/ */
  385. /* > \htmlonly */
  386. /* > Download DPBSVX + dependencies */
  387. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dpbsvx.
  388. f"> */
  389. /* > [TGZ]</a> */
  390. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dpbsvx.
  391. f"> */
  392. /* > [ZIP]</a> */
  393. /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dpbsvx.
  394. f"> */
  395. /* > [TXT]</a> */
  396. /* > \endhtmlonly */
  397. /* Definition: */
  398. /* =========== */
  399. /* SUBROUTINE DPBSVX( FACT, UPLO, N, KD, NRHS, AB, LDAB, AFB, LDAFB, */
  400. /* EQUED, S, B, LDB, X, LDX, RCOND, FERR, BERR, */
  401. /* WORK, IWORK, INFO ) */
  402. /* CHARACTER EQUED, FACT, UPLO */
  403. /* INTEGER INFO, KD, LDAB, LDAFB, LDB, LDX, N, NRHS */
  404. /* DOUBLE PRECISION RCOND */
  405. /* INTEGER IWORK( * ) */
  406. /* DOUBLE PRECISION AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ), */
  407. /* $ BERR( * ), FERR( * ), S( * ), WORK( * ), */
  408. /* $ X( LDX, * ) */
  409. /* > \par Purpose: */
  410. /* ============= */
  411. /* > */
  412. /* > \verbatim */
  413. /* > */
  414. /* > DPBSVX uses the Cholesky factorization A = U**T*U or A = L*L**T to */
  415. /* > compute the solution to a real system of linear equations */
  416. /* > A * X = B, */
  417. /* > where A is an N-by-N symmetric positive definite band matrix and X */
  418. /* > and B are N-by-NRHS matrices. */
  419. /* > */
  420. /* > Error bounds on the solution and a condition estimate are also */
  421. /* > provided. */
  422. /* > \endverbatim */
  423. /* > \par Description: */
  424. /* ================= */
  425. /* > */
  426. /* > \verbatim */
  427. /* > */
  428. /* > The following steps are performed: */
  429. /* > */
  430. /* > 1. If FACT = 'E', real scaling factors are computed to equilibrate */
  431. /* > the system: */
  432. /* > diag(S) * A * diag(S) * inv(diag(S)) * X = diag(S) * B */
  433. /* > Whether or not the system will be equilibrated depends on the */
  434. /* > scaling of the matrix A, but if equilibration is used, A is */
  435. /* > overwritten by diag(S)*A*diag(S) and B by diag(S)*B. */
  436. /* > */
  437. /* > 2. If FACT = 'N' or 'E', the Cholesky decomposition is used to */
  438. /* > factor the matrix A (after equilibration if FACT = 'E') as */
  439. /* > A = U**T * U, if UPLO = 'U', or */
  440. /* > A = L * L**T, if UPLO = 'L', */
  441. /* > where U is an upper triangular band matrix, and L is a lower */
  442. /* > triangular band matrix. */
  443. /* > */
  444. /* > 3. If the leading i-by-i principal minor is not positive definite, */
  445. /* > then the routine returns with INFO = i. Otherwise, the factored */
  446. /* > form of A is used to estimate the condition number of the matrix */
  447. /* > A. If the reciprocal of the condition number is less than machine */
  448. /* > precision, INFO = N+1 is returned as a warning, but the routine */
  449. /* > still goes on to solve for X and compute error bounds as */
  450. /* > described below. */
  451. /* > */
  452. /* > 4. The system of equations is solved for X using the factored form */
  453. /* > of A. */
  454. /* > */
  455. /* > 5. Iterative refinement is applied to improve the computed solution */
  456. /* > matrix and calculate error bounds and backward error estimates */
  457. /* > for it. */
  458. /* > */
  459. /* > 6. If equilibration was used, the matrix X is premultiplied by */
  460. /* > diag(S) so that it solves the original system before */
  461. /* > equilibration. */
  462. /* > \endverbatim */
  463. /* Arguments: */
  464. /* ========== */
  465. /* > \param[in] FACT */
  466. /* > \verbatim */
  467. /* > FACT is CHARACTER*1 */
  468. /* > Specifies whether or not the factored form of the matrix A is */
  469. /* > supplied on entry, and if not, whether the matrix A should be */
  470. /* > equilibrated before it is factored. */
  471. /* > = 'F': On entry, AFB contains the factored form of A. */
  472. /* > If EQUED = 'Y', the matrix A has been equilibrated */
  473. /* > with scaling factors given by S. AB and AFB will not */
  474. /* > be modified. */
  475. /* > = 'N': The matrix A will be copied to AFB and factored. */
  476. /* > = 'E': The matrix A will be equilibrated if necessary, then */
  477. /* > copied to AFB and factored. */
  478. /* > \endverbatim */
  479. /* > */
  480. /* > \param[in] UPLO */
  481. /* > \verbatim */
  482. /* > UPLO is CHARACTER*1 */
  483. /* > = 'U': Upper triangle of A is stored; */
  484. /* > = 'L': Lower triangle of A is stored. */
  485. /* > \endverbatim */
  486. /* > */
  487. /* > \param[in] N */
  488. /* > \verbatim */
  489. /* > N is INTEGER */
  490. /* > The number of linear equations, i.e., the order of the */
  491. /* > matrix A. N >= 0. */
  492. /* > \endverbatim */
  493. /* > */
  494. /* > \param[in] KD */
  495. /* > \verbatim */
  496. /* > KD is INTEGER */
  497. /* > The number of superdiagonals of the matrix A if UPLO = 'U', */
  498. /* > or the number of subdiagonals if UPLO = 'L'. KD >= 0. */
  499. /* > \endverbatim */
  500. /* > */
  501. /* > \param[in] NRHS */
  502. /* > \verbatim */
  503. /* > NRHS is INTEGER */
  504. /* > The number of right-hand sides, i.e., the number of columns */
  505. /* > of the matrices B and X. NRHS >= 0. */
  506. /* > \endverbatim */
  507. /* > */
  508. /* > \param[in,out] AB */
  509. /* > \verbatim */
  510. /* > AB is DOUBLE PRECISION array, dimension (LDAB,N) */
  511. /* > On entry, the upper or lower triangle of the symmetric band */
  512. /* > matrix A, stored in the first KD+1 rows of the array, except */
  513. /* > if FACT = 'F' and EQUED = 'Y', then A must contain the */
  514. /* > equilibrated matrix diag(S)*A*diag(S). The j-th column of A */
  515. /* > is stored in the j-th column of the array AB as follows: */
  516. /* > if UPLO = 'U', AB(KD+1+i-j,j) = A(i,j) for f2cmax(1,j-KD)<=i<=j; */
  517. /* > if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=f2cmin(N,j+KD). */
  518. /* > See below for further details. */
  519. /* > */
  520. /* > On exit, if FACT = 'E' and EQUED = 'Y', A is overwritten by */
  521. /* > diag(S)*A*diag(S). */
  522. /* > \endverbatim */
  523. /* > */
  524. /* > \param[in] LDAB */
  525. /* > \verbatim */
  526. /* > LDAB is INTEGER */
  527. /* > The leading dimension of the array A. LDAB >= KD+1. */
  528. /* > \endverbatim */
  529. /* > */
  530. /* > \param[in,out] AFB */
  531. /* > \verbatim */
  532. /* > AFB is DOUBLE PRECISION array, dimension (LDAFB,N) */
  533. /* > If FACT = 'F', then AFB is an input argument and on entry */
  534. /* > contains the triangular factor U or L from the Cholesky */
  535. /* > factorization A = U**T*U or A = L*L**T of the band matrix */
  536. /* > A, in the same storage format as A (see AB). If EQUED = 'Y', */
  537. /* > then AFB is the factored form of the equilibrated matrix A. */
  538. /* > */
  539. /* > If FACT = 'N', then AFB is an output argument and on exit */
  540. /* > returns the triangular factor U or L from the Cholesky */
  541. /* > factorization A = U**T*U or A = L*L**T. */
  542. /* > */
  543. /* > If FACT = 'E', then AFB is an output argument and on exit */
  544. /* > returns the triangular factor U or L from the Cholesky */
  545. /* > factorization A = U**T*U or A = L*L**T of the equilibrated */
  546. /* > matrix A (see the description of A for the form of the */
  547. /* > equilibrated matrix). */
  548. /* > \endverbatim */
  549. /* > */
  550. /* > \param[in] LDAFB */
  551. /* > \verbatim */
  552. /* > LDAFB is INTEGER */
  553. /* > The leading dimension of the array AFB. LDAFB >= KD+1. */
  554. /* > \endverbatim */
  555. /* > */
  556. /* > \param[in,out] EQUED */
  557. /* > \verbatim */
  558. /* > EQUED is CHARACTER*1 */
  559. /* > Specifies the form of equilibration that was done. */
  560. /* > = 'N': No equilibration (always true if FACT = 'N'). */
  561. /* > = 'Y': Equilibration was done, i.e., A has been replaced by */
  562. /* > diag(S) * A * diag(S). */
  563. /* > EQUED is an input argument if FACT = 'F'; otherwise, it is an */
  564. /* > output argument. */
  565. /* > \endverbatim */
  566. /* > */
  567. /* > \param[in,out] S */
  568. /* > \verbatim */
  569. /* > S is DOUBLE PRECISION array, dimension (N) */
  570. /* > The scale factors for A; not accessed if EQUED = 'N'. S is */
  571. /* > an input argument if FACT = 'F'; otherwise, S is an output */
  572. /* > argument. If FACT = 'F' and EQUED = 'Y', each element of S */
  573. /* > must be positive. */
  574. /* > \endverbatim */
  575. /* > */
  576. /* > \param[in,out] B */
  577. /* > \verbatim */
  578. /* > B is DOUBLE PRECISION array, dimension (LDB,NRHS) */
  579. /* > On entry, the N-by-NRHS right hand side matrix B. */
  580. /* > On exit, if EQUED = 'N', B is not modified; if EQUED = 'Y', */
  581. /* > B is overwritten by diag(S) * B. */
  582. /* > \endverbatim */
  583. /* > */
  584. /* > \param[in] LDB */
  585. /* > \verbatim */
  586. /* > LDB is INTEGER */
  587. /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */
  588. /* > \endverbatim */
  589. /* > */
  590. /* > \param[out] X */
  591. /* > \verbatim */
  592. /* > X is DOUBLE PRECISION array, dimension (LDX,NRHS) */
  593. /* > If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X to */
  594. /* > the original system of equations. Note that if EQUED = 'Y', */
  595. /* > A and B are modified on exit, and the solution to the */
  596. /* > equilibrated system is inv(diag(S))*X. */
  597. /* > \endverbatim */
  598. /* > */
  599. /* > \param[in] LDX */
  600. /* > \verbatim */
  601. /* > LDX is INTEGER */
  602. /* > The leading dimension of the array X. LDX >= f2cmax(1,N). */
  603. /* > \endverbatim */
  604. /* > */
  605. /* > \param[out] RCOND */
  606. /* > \verbatim */
  607. /* > RCOND is DOUBLE PRECISION */
  608. /* > The estimate of the reciprocal condition number of the matrix */
  609. /* > A after equilibration (if done). If RCOND is less than the */
  610. /* > machine precision (in particular, if RCOND = 0), the matrix */
  611. /* > is singular to working precision. This condition is */
  612. /* > indicated by a return code of INFO > 0. */
  613. /* > \endverbatim */
  614. /* > */
  615. /* > \param[out] FERR */
  616. /* > \verbatim */
  617. /* > FERR is DOUBLE PRECISION array, dimension (NRHS) */
  618. /* > The estimated forward error bound for each solution vector */
  619. /* > X(j) (the j-th column of the solution matrix X). */
  620. /* > If XTRUE is the true solution corresponding to X(j), FERR(j) */
  621. /* > is an estimated upper bound for the magnitude of the largest */
  622. /* > element in (X(j) - XTRUE) divided by the magnitude of the */
  623. /* > largest element in X(j). The estimate is as reliable as */
  624. /* > the estimate for RCOND, and is almost always a slight */
  625. /* > overestimate of the true error. */
  626. /* > \endverbatim */
  627. /* > */
  628. /* > \param[out] BERR */
  629. /* > \verbatim */
  630. /* > BERR is DOUBLE PRECISION array, dimension (NRHS) */
  631. /* > The componentwise relative backward error of each solution */
  632. /* > vector X(j) (i.e., the smallest relative change in */
  633. /* > any element of A or B that makes X(j) an exact solution). */
  634. /* > \endverbatim */
  635. /* > */
  636. /* > \param[out] WORK */
  637. /* > \verbatim */
  638. /* > WORK is DOUBLE PRECISION array, dimension (3*N) */
  639. /* > \endverbatim */
  640. /* > */
  641. /* > \param[out] IWORK */
  642. /* > \verbatim */
  643. /* > IWORK is INTEGER array, dimension (N) */
  644. /* > \endverbatim */
  645. /* > */
  646. /* > \param[out] INFO */
  647. /* > \verbatim */
  648. /* > INFO is INTEGER */
  649. /* > = 0: successful exit */
  650. /* > < 0: if INFO = -i, the i-th argument had an illegal value */
  651. /* > > 0: if INFO = i, and i is */
  652. /* > <= N: the leading minor of order i of A is */
  653. /* > not positive definite, so the factorization */
  654. /* > could not be completed, and the solution has not */
  655. /* > been computed. RCOND = 0 is returned. */
  656. /* > = N+1: U is nonsingular, but RCOND is less than machine */
  657. /* > precision, meaning that the matrix is singular */
  658. /* > to working precision. Nevertheless, the */
  659. /* > solution and error bounds are computed because */
  660. /* > there are a number of situations where the */
  661. /* > computed solution can be more accurate than the */
  662. /* > value of RCOND would suggest. */
  663. /* > \endverbatim */
  664. /* Authors: */
  665. /* ======== */
  666. /* > \author Univ. of Tennessee */
  667. /* > \author Univ. of California Berkeley */
  668. /* > \author Univ. of Colorado Denver */
  669. /* > \author NAG Ltd. */
  670. /* > \date April 2012 */
  671. /* > \ingroup doubleOTHERsolve */
  672. /* > \par Further Details: */
  673. /* ===================== */
  674. /* > */
  675. /* > \verbatim */
  676. /* > */
  677. /* > The band storage scheme is illustrated by the following example, when */
  678. /* > N = 6, KD = 2, and UPLO = 'U': */
  679. /* > */
  680. /* > Two-dimensional storage of the symmetric matrix A: */
  681. /* > */
  682. /* > a11 a12 a13 */
  683. /* > a22 a23 a24 */
  684. /* > a33 a34 a35 */
  685. /* > a44 a45 a46 */
  686. /* > a55 a56 */
  687. /* > (aij=conjg(aji)) a66 */
  688. /* > */
  689. /* > Band storage of the upper triangle of A: */
  690. /* > */
  691. /* > * * a13 a24 a35 a46 */
  692. /* > * a12 a23 a34 a45 a56 */
  693. /* > a11 a22 a33 a44 a55 a66 */
  694. /* > */
  695. /* > Similarly, if UPLO = 'L' the format of A is as follows: */
  696. /* > */
  697. /* > a11 a22 a33 a44 a55 a66 */
  698. /* > a21 a32 a43 a54 a65 * */
  699. /* > a31 a42 a53 a64 * * */
  700. /* > */
  701. /* > Array elements marked * are not used by the routine. */
  702. /* > \endverbatim */
  703. /* > */
  704. /* ===================================================================== */
  705. /* Subroutine */ int dpbsvx_(char *fact, char *uplo, integer *n, integer *kd,
  706. integer *nrhs, doublereal *ab, integer *ldab, doublereal *afb,
  707. integer *ldafb, char *equed, doublereal *s, doublereal *b, integer *
  708. ldb, doublereal *x, integer *ldx, doublereal *rcond, doublereal *ferr,
  709. doublereal *berr, doublereal *work, integer *iwork, integer *info)
  710. {
  711. /* System generated locals */
  712. integer ab_dim1, ab_offset, afb_dim1, afb_offset, b_dim1, b_offset,
  713. x_dim1, x_offset, i__1, i__2;
  714. doublereal d__1, d__2;
  715. /* Local variables */
  716. doublereal amax, smin, smax;
  717. integer i__, j;
  718. extern logical lsame_(char *, char *);
  719. doublereal scond, anorm;
  720. extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
  721. doublereal *, integer *);
  722. logical equil, rcequ, upper;
  723. integer j1, j2;
  724. extern doublereal dlamch_(char *), dlansb_(char *, char *,
  725. integer *, integer *, doublereal *, integer *, doublereal *);
  726. extern /* Subroutine */ int dpbcon_(char *, integer *, integer *,
  727. doublereal *, integer *, doublereal *, doublereal *, doublereal *,
  728. integer *, integer *), dlaqsb_(char *, integer *,
  729. integer *, doublereal *, integer *, doublereal *, doublereal *,
  730. doublereal *, char *);
  731. logical nofact;
  732. extern /* Subroutine */ int dlacpy_(char *, integer *, integer *,
  733. doublereal *, integer *, doublereal *, integer *),
  734. xerbla_(char *, integer *, ftnlen), dpbequ_(char *, integer *,
  735. integer *, doublereal *, integer *, doublereal *, doublereal *,
  736. doublereal *, integer *);
  737. doublereal bignum;
  738. extern /* Subroutine */ int dpbrfs_(char *, integer *, integer *, integer
  739. *, doublereal *, integer *, doublereal *, integer *, doublereal *,
  740. integer *, doublereal *, integer *, doublereal *, doublereal *,
  741. doublereal *, integer *, integer *), dpbtrf_(char *,
  742. integer *, integer *, doublereal *, integer *, integer *);
  743. integer infequ;
  744. extern /* Subroutine */ int dpbtrs_(char *, integer *, integer *, integer
  745. *, doublereal *, integer *, doublereal *, integer *, integer *);
  746. doublereal smlnum;
  747. /* -- LAPACK driver routine (version 3.7.0) -- */
  748. /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
  749. /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
  750. /* April 2012 */
  751. /* ===================================================================== */
  752. /* Parameter adjustments */
  753. ab_dim1 = *ldab;
  754. ab_offset = 1 + ab_dim1 * 1;
  755. ab -= ab_offset;
  756. afb_dim1 = *ldafb;
  757. afb_offset = 1 + afb_dim1 * 1;
  758. afb -= afb_offset;
  759. --s;
  760. b_dim1 = *ldb;
  761. b_offset = 1 + b_dim1 * 1;
  762. b -= b_offset;
  763. x_dim1 = *ldx;
  764. x_offset = 1 + x_dim1 * 1;
  765. x -= x_offset;
  766. --ferr;
  767. --berr;
  768. --work;
  769. --iwork;
  770. /* Function Body */
  771. *info = 0;
  772. nofact = lsame_(fact, "N");
  773. equil = lsame_(fact, "E");
  774. upper = lsame_(uplo, "U");
  775. if (nofact || equil) {
  776. *(unsigned char *)equed = 'N';
  777. rcequ = FALSE_;
  778. } else {
  779. rcequ = lsame_(equed, "Y");
  780. smlnum = dlamch_("Safe minimum");
  781. bignum = 1. / smlnum;
  782. }
  783. /* Test the input parameters. */
  784. if (! nofact && ! equil && ! lsame_(fact, "F")) {
  785. *info = -1;
  786. } else if (! upper && ! lsame_(uplo, "L")) {
  787. *info = -2;
  788. } else if (*n < 0) {
  789. *info = -3;
  790. } else if (*kd < 0) {
  791. *info = -4;
  792. } else if (*nrhs < 0) {
  793. *info = -5;
  794. } else if (*ldab < *kd + 1) {
  795. *info = -7;
  796. } else if (*ldafb < *kd + 1) {
  797. *info = -9;
  798. } else if (lsame_(fact, "F") && ! (rcequ || lsame_(
  799. equed, "N"))) {
  800. *info = -10;
  801. } else {
  802. if (rcequ) {
  803. smin = bignum;
  804. smax = 0.;
  805. i__1 = *n;
  806. for (j = 1; j <= i__1; ++j) {
  807. /* Computing MIN */
  808. d__1 = smin, d__2 = s[j];
  809. smin = f2cmin(d__1,d__2);
  810. /* Computing MAX */
  811. d__1 = smax, d__2 = s[j];
  812. smax = f2cmax(d__1,d__2);
  813. /* L10: */
  814. }
  815. if (smin <= 0.) {
  816. *info = -11;
  817. } else if (*n > 0) {
  818. scond = f2cmax(smin,smlnum) / f2cmin(smax,bignum);
  819. } else {
  820. scond = 1.;
  821. }
  822. }
  823. if (*info == 0) {
  824. if (*ldb < f2cmax(1,*n)) {
  825. *info = -13;
  826. } else if (*ldx < f2cmax(1,*n)) {
  827. *info = -15;
  828. }
  829. }
  830. }
  831. if (*info != 0) {
  832. i__1 = -(*info);
  833. xerbla_("DPBSVX", &i__1, (ftnlen)6);
  834. return 0;
  835. }
  836. if (equil) {
  837. /* Compute row and column scalings to equilibrate the matrix A. */
  838. dpbequ_(uplo, n, kd, &ab[ab_offset], ldab, &s[1], &scond, &amax, &
  839. infequ);
  840. if (infequ == 0) {
  841. /* Equilibrate the matrix. */
  842. dlaqsb_(uplo, n, kd, &ab[ab_offset], ldab, &s[1], &scond, &amax,
  843. equed);
  844. rcequ = lsame_(equed, "Y");
  845. }
  846. }
  847. /* Scale the right-hand side. */
  848. if (rcequ) {
  849. i__1 = *nrhs;
  850. for (j = 1; j <= i__1; ++j) {
  851. i__2 = *n;
  852. for (i__ = 1; i__ <= i__2; ++i__) {
  853. b[i__ + j * b_dim1] = s[i__] * b[i__ + j * b_dim1];
  854. /* L20: */
  855. }
  856. /* L30: */
  857. }
  858. }
  859. if (nofact || equil) {
  860. /* Compute the Cholesky factorization A = U**T *U or A = L*L**T. */
  861. if (upper) {
  862. i__1 = *n;
  863. for (j = 1; j <= i__1; ++j) {
  864. /* Computing MAX */
  865. i__2 = j - *kd;
  866. j1 = f2cmax(i__2,1);
  867. i__2 = j - j1 + 1;
  868. dcopy_(&i__2, &ab[*kd + 1 - j + j1 + j * ab_dim1], &c__1, &
  869. afb[*kd + 1 - j + j1 + j * afb_dim1], &c__1);
  870. /* L40: */
  871. }
  872. } else {
  873. i__1 = *n;
  874. for (j = 1; j <= i__1; ++j) {
  875. /* Computing MIN */
  876. i__2 = j + *kd;
  877. j2 = f2cmin(i__2,*n);
  878. i__2 = j2 - j + 1;
  879. dcopy_(&i__2, &ab[j * ab_dim1 + 1], &c__1, &afb[j * afb_dim1
  880. + 1], &c__1);
  881. /* L50: */
  882. }
  883. }
  884. dpbtrf_(uplo, n, kd, &afb[afb_offset], ldafb, info);
  885. /* Return if INFO is non-zero. */
  886. if (*info > 0) {
  887. *rcond = 0.;
  888. return 0;
  889. }
  890. }
  891. /* Compute the norm of the matrix A. */
  892. anorm = dlansb_("1", uplo, n, kd, &ab[ab_offset], ldab, &work[1]);
  893. /* Compute the reciprocal of the condition number of A. */
  894. dpbcon_(uplo, n, kd, &afb[afb_offset], ldafb, &anorm, rcond, &work[1], &
  895. iwork[1], info);
  896. /* Compute the solution matrix X. */
  897. dlacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx);
  898. dpbtrs_(uplo, n, kd, nrhs, &afb[afb_offset], ldafb, &x[x_offset], ldx,
  899. info);
  900. /* Use iterative refinement to improve the computed solution and */
  901. /* compute error bounds and backward error estimates for it. */
  902. dpbrfs_(uplo, n, kd, nrhs, &ab[ab_offset], ldab, &afb[afb_offset], ldafb,
  903. &b[b_offset], ldb, &x[x_offset], ldx, &ferr[1], &berr[1], &work[1]
  904. , &iwork[1], info);
  905. /* Transform the solution matrix X to a solution of the original */
  906. /* system. */
  907. if (rcequ) {
  908. i__1 = *nrhs;
  909. for (j = 1; j <= i__1; ++j) {
  910. i__2 = *n;
  911. for (i__ = 1; i__ <= i__2; ++i__) {
  912. x[i__ + j * x_dim1] = s[i__] * x[i__ + j * x_dim1];
  913. /* L60: */
  914. }
  915. /* L70: */
  916. }
  917. i__1 = *nrhs;
  918. for (j = 1; j <= i__1; ++j) {
  919. ferr[j] /= scond;
  920. /* L80: */
  921. }
  922. }
  923. /* Set INFO = N+1 if the matrix is singular to working precision. */
  924. if (*rcond < dlamch_("Epsilon")) {
  925. *info = *n + 1;
  926. }
  927. return 0;
  928. /* End of DPBSVX */
  929. } /* dpbsvx_ */