bindings.hpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. // Copyright John Maddock 2015.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_MATH_BINDINGS
  6. #define BOOST_MATH_BINDINGS
  7. #define ERROR_REPORTING_MODE
  8. #include <stdexcept>
  9. #if TEST_CXX17_CMATH
  10. #include <cmath>
  11. #define TEST_LIBRARY_NAME "<cmath>"
  12. #define LOG1P_FUNCTION_TO_TEST std::log1p
  13. #define EXPM1_FUNCTION_TO_TEST std::expm1
  14. #define CBRT_FUNCTION_TO_TEST std::cbrt
  15. #define ERF_FUNCTION_TO_TEST std::erf
  16. #define ERFC_FUNCTION_TO_TEST std::erfc
  17. #define LGAMMA_FUNCTION_TO_TEST std::lgamma
  18. #define TGAMMA_FUNCTION_TO_TEST std::tgamma
  19. #define BESSEL_I_FUNCTION_TO_TEST std::cyl_bessel_i
  20. #define BESSEL_IN_FUNCTION_TO_TEST std::cyl_bessel_i
  21. #define BESSEL_J_FUNCTION_TO_TEST std::cyl_bessel_j
  22. #define BESSEL_JN_FUNCTION_TO_TEST std::cyl_bessel_j
  23. #define BESSEL_JS_FUNCTION_TO_TEST std::sph_bessel
  24. #define BESSEL_K_FUNCTION_TO_TEST std::cyl_bessel_k
  25. #define BESSEL_KN_FUNCTION_TO_TEST std::cyl_bessel_k
  26. #define BESSEL_Y_FUNCTION_TO_TEST std::cyl_neumann
  27. #define BESSEL_YN_FUNCTION_TO_TEST std::cyl_neumann
  28. #define BESSEL_YS_FUNCTION_TO_TEST std::sph_neumann
  29. #define BETA_FUNCTION_TO_TEST std::beta
  30. #define ELLINT_1_FUNCTION_TO_TEST std::ellint_1
  31. #define ELLINT_1C_FUNCTION_TO_TEST std::comp_ellint_1
  32. #define ELLINT_2_FUNCTION_TO_TEST std::ellint_2
  33. #define ELLINT_2C_FUNCTION_TO_TEST std::comp_ellint_2
  34. #define ELLINT_3_FUNCTION_TO_TEST std::ellint_3
  35. #define ELLINT_3C_FUNCTION_TO_TEST std::comp_ellint_3
  36. #define EI_FUNCTION_TO_TEST std::expint
  37. #define LAGUERRE_FUNCTION_TO_TEST std::laguerre
  38. #define ASSOC_LAGUERRE_FUNCTION_TO_TEST std::assoc_laguerre
  39. inline long double legendre_p_binder(int i, long double d)
  40. {
  41. if(i < 0)
  42. throw std::domain_error("order parameters less than 0 not supported in TR1");
  43. return std::legendre(i, d);
  44. }
  45. inline long double assoc_legendre_p_binder(int i, int j, long double d)
  46. {
  47. if((i < 0) || (j < 0))
  48. throw std::domain_error("order parameters less than 0 not supported in TR1");
  49. return std::assoc_legendre(i, j, d);
  50. }
  51. #define LEGENDRE_P_FUNCTION_TO_TEST legendre_p_binder
  52. #define LEGENDRE_PA_FUNCTION_TO_TEST assoc_legendre_p_binder
  53. #define ZETA_FUNCTION_TO_TEST std::riemann_zeta
  54. #define TYPE_TO_TEST long double
  55. #elif defined(TEST_C99)
  56. #include <math.h>
  57. #define TEST_LIBRARY_NAME "<math.h>"
  58. #ifdef _MSC_VER
  59. #define LOG1P_FUNCTION_TO_TEST ::log1p
  60. #define EXPM1_FUNCTION_TO_TEST ::expm1
  61. #define CBRT_FUNCTION_TO_TEST ::cbrt
  62. #define ERF_FUNCTION_TO_TEST ::erf
  63. #define ERFC_FUNCTION_TO_TEST ::erfc
  64. #define LGAMMA_FUNCTION_TO_TEST ::lgamma
  65. #define TGAMMA_FUNCTION_TO_TEST ::tgamma
  66. #define BESSEL_JN_FUNCTION_TO_TEST ::jn
  67. #define BESSEL_YN_FUNCTION_TO_TEST ::yn
  68. #define TYPE_TO_TEST double
  69. #else
  70. #define LOG1P_FUNCTION_TO_TEST ::log1pl
  71. #define EXPM1_FUNCTION_TO_TEST ::expm1l
  72. #define CBRT_FUNCTION_TO_TEST ::cbrtl
  73. #define ERF_FUNCTION_TO_TEST ::erfl
  74. #define ERFC_FUNCTION_TO_TEST ::erfcl
  75. #define LGAMMA_FUNCTION_TO_TEST ::lgammal
  76. #define TGAMMA_FUNCTION_TO_TEST ::tgammal
  77. //#define BESSEL_JN_FUNCTION_TO_TEST ::jnl
  78. //#define BESSEL_JN_FUNCTION_TO_TEST ::ynl
  79. #define TYPE_TO_TEST long double
  80. #endif
  81. #elif defined(TEST_GSL)
  82. #include <stdexcept>
  83. #include <gsl/gsl_sf.h>
  84. #include <gsl/gsl_errno.h>
  85. #include <gsl/gsl_version.h>
  86. #define TEST_LIBRARY_NAME "GSL " GSL_VERSION
  87. void gsl_handler(const char * reason, const char * file, int line, int gsl_errno)
  88. {
  89. if(gsl_errno == GSL_ERANGE) return; // handle zero or infinity in our test code.
  90. throw std::domain_error(reason);
  91. }
  92. struct gsl_error_handler_setter
  93. {
  94. gsl_error_handler_t * old_handler;
  95. gsl_error_handler_setter()
  96. {
  97. old_handler = gsl_set_error_handler(gsl_handler);
  98. }
  99. ~gsl_error_handler_setter()
  100. {
  101. gsl_set_error_handler(old_handler);
  102. }
  103. };
  104. static const gsl_error_handler_setter handler;
  105. inline double gsl_bessel_ys(unsigned i, double d)
  106. {
  107. return gsl_sf_bessel_yl(i, d);
  108. }
  109. inline double gsl_bessel_js(unsigned i, double d)
  110. {
  111. return gsl_sf_bessel_jl(i, d);
  112. }
  113. //#define CBRT_FUNCTION_TO_TEST boost::cbrt
  114. #define ERF_FUNCTION_TO_TEST gsl_sf_erf
  115. #define ERFC_FUNCTION_TO_TEST gsl_sf_erfc
  116. //#define ERF_INV_FUNCTION_TO_TEST boost::math::erf_inv
  117. //#define ERFC_INV_FUNCTION_TO_TEST boost::math::erfc_inv
  118. #define LGAMMA_FUNCTION_TO_TEST gsl_sf_lngamma
  119. #define TGAMMA_FUNCTION_TO_TEST gsl_sf_gamma
  120. //#define TGAMMA1PM1_FUNCTION_TO_TEST boost::math::tgamma1pm1
  121. #define BESSEL_I_FUNCTION_TO_TEST gsl_sf_bessel_Inu
  122. #define BESSEL_IN_FUNCTION_TO_TEST gsl_sf_bessel_In
  123. //#define BESSEL_IP_FUNCTION_TO_TEST boost::math::cyl_bessel_i_prime
  124. //#define BESSEL_IPN_FUNCTION_TO_TEST boost::math::cyl_bessel_i_prime
  125. #define BESSEL_J_FUNCTION_TO_TEST gsl_sf_bessel_Jnu
  126. #define BESSEL_JN_FUNCTION_TO_TEST gsl_sf_bessel_Jn
  127. #define BESSEL_JS_FUNCTION_TO_TEST gsl_bessel_js
  128. //#define BESSEL_JP_FUNCTION_TO_TEST boost::math::cyl_bessel_j_prime
  129. //#define BESSEL_JPN_FUNCTION_TO_TEST boost::math::cyl_bessel_j_prime
  130. //#define BESSEL_JPS_FUNCTION_TO_TEST boost::math::sph_bessel_prime
  131. #define BESSEL_K_FUNCTION_TO_TEST gsl_sf_bessel_Knu
  132. #define BESSEL_KN_FUNCTION_TO_TEST gsl_sf_bessel_Kn
  133. //#define BESSEL_KP_FUNCTION_TO_TEST boost::math::cyl_bessel_k_prime
  134. //#define BESSEL_KPN_FUNCTION_TO_TEST boost::math::cyl_bessel_k_prime
  135. #define BESSEL_Y_FUNCTION_TO_TEST gsl_sf_bessel_Ynu
  136. #define BESSEL_YN_FUNCTION_TO_TEST gsl_sf_bessel_Yn
  137. #define BESSEL_YS_FUNCTION_TO_TEST gsl_bessel_ys
  138. //#define BESSEL_YP_FUNCTION_TO_TEST boost::math::cyl_neumann_prime
  139. //#define BESSEL_YNP_FUNCTION_TO_TEST boost::math::cyl_neumann_prime
  140. //#define BESSEL_YSP_FUNCTION_TO_TEST boost::math::sph_neumann_prime
  141. #define BETA_FUNCTION_TO_TEST gsl_sf_beta
  142. //#define BINOMIAL_FUNCTION_TO_TEST boost::math::binomial_coefficient<T>
  143. inline double RC(double a, double b)
  144. {
  145. return gsl_sf_ellint_RC(a, b, GSL_PREC_DOUBLE);
  146. }
  147. inline double RD(double a, double b, double c)
  148. {
  149. return gsl_sf_ellint_RD(a, b, c, GSL_PREC_DOUBLE);
  150. }
  151. inline double RF(double a, double b, double c)
  152. {
  153. return gsl_sf_ellint_RF(a, b, c, GSL_PREC_DOUBLE);
  154. }
  155. inline double RJ(double a, double b, double c, double d)
  156. {
  157. return gsl_sf_ellint_RJ(a, b, c, d, GSL_PREC_DOUBLE);
  158. }
  159. #define ELLINT_RC_FUNCTION_TO_TEST RC
  160. #define ELLINT_RD_FUNCTION_TO_TEST RD
  161. #define ELLINT_RF_FUNCTION_TO_TEST RF
  162. //#define ELLINT_RG_FUNCTION_TO_TEST boost::math::ellint_rg
  163. #define ELLINT_RJ_FUNCTION_TO_TEST RJ
  164. #define DIGAMMA_FUNCTION_TO_TEST gsl_sf_psi
  165. inline double ellintK(double a) { return gsl_sf_ellint_Kcomp(a, GSL_PREC_DOUBLE); }
  166. inline double ellintE(double a) { return gsl_sf_ellint_Ecomp(a, GSL_PREC_DOUBLE); }
  167. inline double ellintP(double a, double b) { return gsl_sf_ellint_Pcomp(a, -b, GSL_PREC_DOUBLE); }
  168. inline double ellintF(double a, double b) { return gsl_sf_ellint_F(b, a, GSL_PREC_DOUBLE); }
  169. inline double ellintE2(double a, double b) { return gsl_sf_ellint_E(b, a, GSL_PREC_DOUBLE); }
  170. inline double ellintP3(double a, double b, double c) { return gsl_sf_ellint_P(c, a, -b, GSL_PREC_DOUBLE); }
  171. inline double ellintD2(double a, double b) { return gsl_sf_ellint_D(b, a, GSL_PREC_DOUBLE); }
  172. #define ELLINT_1_FUNCTION_TO_TEST ellintF
  173. #define ELLINT_1C_FUNCTION_TO_TEST ellintK
  174. #define ELLINT_2_FUNCTION_TO_TEST ellintE2
  175. #define ELLINT_2C_FUNCTION_TO_TEST ellintE
  176. #define ELLINT_3_FUNCTION_TO_TEST ellintP3
  177. #define ELLINT_3C_FUNCTION_TO_TEST ellintP
  178. #define ELLINT_D2_FUNCTION_TO_TEST ellintD2
  179. //#define ELLINT_D1_FUNCTION_TO_TEST boost::math::ellint_d
  180. #define EI_FUNCTION_TO_TEST gsl_sf_expint_Ei
  181. #define EN_FUNCTION_TO_TEST gsl_sf_expint_En
  182. //#define HERMITE_FUNCTION_TO_TEST boost::math::hermite
  183. //#define HEUMAN_LAMBDA_FUNCTION_TO_TEST boost::math::heuman_lambda
  184. //#define BETA_INC_FUNCTION_TO_TEST boost::math::beta
  185. //#define BETAC_INC_FUNCTION_TO_TEST boost::math::betac
  186. #define IBETA_FUNCTION_TO_TEST gsl_sf_beta_inc
  187. //#define IBETAC_FUNCTION_TO_TEST boost::math::ibetac
  188. //#define IBETA_INV_FUNCTION_TO_TEST boost::math::ibeta_inv
  189. //#define IBETAC_INV_FUNCTION_TO_TEST boost::math::ibetac_inv
  190. //#define IBETA_INVA_FUNCTION_TO_TEST boost::math::ibeta_inva
  191. //#define IBETAC_INVA_FUNCTION_TO_TEST boost::math::ibetac_inva
  192. //#define IBETA_INVB_FUNCTION_TO_TEST boost::math::ibeta_invb
  193. //#define IBETAC_INVB_FUNCTION_TO_TEST boost::math::ibetac_invb
  194. #define IGAMMA_FUNCTION_TO_TEST gsl_sf_gamma_inc
  195. //#define IGAMMAL_FUNCTION_TO_TEST boost::math::tgamma_lower
  196. #define GAMMAP_FUNCTION_TO_TEST gsl_sf_gamma_inc_P
  197. #define GAMMAQ_FUNCTION_TO_TEST gsl_sf_gamma_inc_Q
  198. //#define GAMMAP_INV_FUNCTION_TO_TEST boost::math::gamma_p_inv
  199. //#define GAMMAQ_INV_FUNCTION_TO_TEST boost::math::gamma_q_inv
  200. //#define GAMMAP_INVA_FUNCTION_TO_TEST boost::math::gamma_p_inva
  201. //#define GAMMAQ_INVA_FUNCTION_TO_TEST boost::math::gamma_q_inva
  202. inline double sn(double k, double u)
  203. {
  204. double s, c, d;
  205. gsl_sf_elljac_e(u, k * k, &s, &c, &d);
  206. return s;
  207. }
  208. inline double cn(double k, double u)
  209. {
  210. double s, c, d;
  211. gsl_sf_elljac_e(u, k * k, &s, &c, &d);
  212. return c;
  213. }
  214. inline double dn(double k, double u)
  215. {
  216. double s, c, d;
  217. gsl_sf_elljac_e(u, k * k, &s, &c, &d);
  218. return d;
  219. }
  220. #define SN_FUNCTION_TO_TEST sn
  221. #define CN_FUNCTION_TO_TEST cn
  222. #define DN_FUNCTION_TO_TEST dn
  223. //#define JACOBI_ZETA_FUNCTION_TO_TEST boost::math::jacobi_zeta
  224. inline double laguerre(unsigned n, unsigned m, double x){ return gsl_sf_laguerre_n(n, m, x); }
  225. inline double laguerre_0(unsigned n, double x){ return gsl_sf_laguerre_n(n, 0, x); }
  226. #define LAGUERRE_FUNCTION_TO_TEST laguerre_0
  227. #define ASSOC_LAGUERRE_FUNCTION_TO_TEST laguerre
  228. inline double legendre_q(unsigned n, double x) { return gsl_sf_legendre_Ql(n, x); }
  229. #define LEGENDRE_P_FUNCTION_TO_TEST gsl_sf_legendre_Pl
  230. #define LEGENDRE_Q_FUNCTION_TO_TEST legendre_q
  231. #define LEGENDRE_PA_FUNCTION_TO_TEST gsl_sf_legendre_Plm
  232. #define POLYGAMMA_FUNCTION_TO_TEST gsl_sf_psi_n
  233. //#define TGAMMA_RATIO_FUNCTION_TO_TEST boost::math::tgamma_ratio
  234. //#define TGAMMA_DELTA_RATIO_FUNCTION_TO_TEST boost::math::tgamma_delta_ratio
  235. //#define SIN_PI_RATIO_FUNCTION_TO_TEST boost::math::sin_pi
  236. //#define COS_PI_RATIO_FUNCTION_TO_TEST boost::math::cos_pi
  237. #define TRIGAMMA_RATIO_FUNCTION_TO_TEST gsl_sf_psi_1
  238. #define ZETA_FUNCTION_TO_TEST gsl_sf_zeta
  239. #define TYPE_TO_TEST double
  240. #elif defined(TEST_RMATH)
  241. #define MATHLIB_STANDALONE
  242. #include <Rmath.h>
  243. #undef trunc
  244. #define TEST_LIBRARY_NAME "Rmath " R_VERSION_STRING
  245. #define LOG1P_FUNCTION_TO_TEST log1p
  246. #define EXPM1_FUNCTION_TO_TEST expm1
  247. //#define CBRT_FUNCTION_TO_TEST boost::math::cbrt
  248. //#define ERF_FUNCTION_TO_TEST boost::math::erf
  249. //#define ERFC_FUNCTION_TO_TEST boost::math::erfc
  250. //#define ERF_INV_FUNCTION_TO_TEST boost::math::erf_inv
  251. //#define ERFC_INV_FUNCTION_TO_TEST boost::math::erfc_inv
  252. #define LGAMMA_FUNCTION_TO_TEST lgammafn
  253. #define TGAMMA_FUNCTION_TO_TEST gammafn
  254. //#define TGAMMA1PM1_FUNCTION_TO_TEST boost::math::tgamma1pm1
  255. inline double I(double n, double x)
  256. {
  257. if (x < 0)
  258. throw std::domain_error("Unsupported domain");
  259. return bessel_i(x, n, 1);
  260. }
  261. inline double K(double n, double x) { return bessel_k(x, n, 1); }
  262. inline double J(double n, double x)
  263. {
  264. if (x < 0)
  265. throw std::domain_error("Unsupported domain");
  266. return bessel_j(x, n);
  267. }
  268. inline double Y(double n, double x) { return bessel_y(x, n); }
  269. #define BESSEL_I_FUNCTION_TO_TEST I
  270. #define BESSEL_IN_FUNCTION_TO_TEST I
  271. //#define BESSEL_IP_FUNCTION_TO_TEST boost::math::cyl_bessel_i_prime
  272. //#define BESSEL_IPN_FUNCTION_TO_TEST boost::math::cyl_bessel_i_prime
  273. #define BESSEL_J_FUNCTION_TO_TEST J
  274. #define BESSEL_JN_FUNCTION_TO_TEST J
  275. //#define BESSEL_JS_FUNCTION_TO_TEST boost::math::sph_bessel
  276. //#define BESSEL_JP_FUNCTION_TO_TEST boost::math::cyl_bessel_j_prime
  277. //#define BESSEL_JPN_FUNCTION_TO_TEST boost::math::cyl_bessel_j_prime
  278. //#define BESSEL_JPS_FUNCTION_TO_TEST boost::math::sph_bessel_prime
  279. #define BESSEL_K_FUNCTION_TO_TEST K
  280. #define BESSEL_KN_FUNCTION_TO_TEST K
  281. //#define BESSEL_KP_FUNCTION_TO_TEST boost::math::cyl_bessel_k_prime
  282. //#define BESSEL_KPN_FUNCTION_TO_TEST boost::math::cyl_bessel_k_prime
  283. #define BESSEL_Y_FUNCTION_TO_TEST Y
  284. #define BESSEL_YN_FUNCTION_TO_TEST Y
  285. //#define BESSEL_YS_FUNCTION_TO_TEST boost::math::sph_neumann
  286. //#define BESSEL_YP_FUNCTION_TO_TEST boost::math::cyl_neumann_prime
  287. //#define BESSEL_YNP_FUNCTION_TO_TEST boost::math::cyl_neumann_prime
  288. //#define BESSEL_YSP_FUNCTION_TO_TEST boost::math::sph_neumann_prime
  289. #define BETA_FUNCTION_TO_TEST beta
  290. //#define BINOMIAL_FUNCTION_TO_TEST boost::math::binomial_coefficient<T>
  291. //#define ELLINT_RC_FUNCTION_TO_TEST boost::math::ellint_rc
  292. //#define ELLINT_RD_FUNCTION_TO_TEST boost::math::ellint_rd
  293. //#define ELLINT_RF_FUNCTION_TO_TEST boost::math::ellint_rf
  294. //#define ELLINT_RG_FUNCTION_TO_TEST boost::math::ellint_rg
  295. //#define ELLINT_RJ_FUNCTION_TO_TEST boost::math::ellint_rj
  296. #define DIGAMMA_FUNCTION_TO_TEST digamma
  297. //#define ELLINT_1_FUNCTION_TO_TEST boost::math::ellint_1
  298. //#define ELLINT_1C_FUNCTION_TO_TEST boost::math::ellint_1
  299. //#define ELLINT_2_FUNCTION_TO_TEST boost::math::ellint_2
  300. //#define ELLINT_2C_FUNCTION_TO_TEST boost::math::ellint_2
  301. //#define ELLINT_3_FUNCTION_TO_TEST boost::math::ellint_3
  302. //#define ELLINT_3C_FUNCTION_TO_TEST boost::math::ellint_3
  303. //#define ELLINT_D2_FUNCTION_TO_TEST boost::math::ellint_d
  304. //#define ELLINT_D1_FUNCTION_TO_TEST boost::math::ellint_d
  305. //#define EI_FUNCTION_TO_TEST boost::math::expint
  306. //#define EN_FUNCTION_TO_TEST boost::math::expint
  307. //#define HERMITE_FUNCTION_TO_TEST boost::math::hermite
  308. //#define HEUMAN_LAMBDA_FUNCTION_TO_TEST boost::math::heuman_lambda
  309. inline double ibeta(double a, double b, double x) { return pbeta(x, a, b, 1, 0); }
  310. inline double ibetac(double a, double b, double x) { return pbeta(x, a, b, 0, 0); }
  311. inline double ibeta_inv(double a, double b, double x) { return qbeta(x, a, b, 1, 0); }
  312. inline double ibetac_inv(double a, double b, double x) { return qbeta(x, a, b, 0, 0); }
  313. //#define BETA_INC_FUNCTION_TO_TEST boost::math::beta
  314. //#define BETAC_INC_FUNCTION_TO_TEST boost::math::betac
  315. #define IBETA_FUNCTION_TO_TEST ibeta
  316. #define IBETAC_FUNCTION_TO_TEST ibetac
  317. #define IBETA_INV_FUNCTION_TO_TEST ibeta_inv
  318. #define IBETAC_INV_FUNCTION_TO_TEST ibetac_inv
  319. //#define IBETA_INVA_FUNCTION_TO_TEST boost::math::ibeta_inva
  320. //#define IBETAC_INVA_FUNCTION_TO_TEST boost::math::ibetac_inva
  321. //#define IBETA_INVB_FUNCTION_TO_TEST boost::math::ibeta_invb
  322. //#define IBETAC_INVB_FUNCTION_TO_TEST boost::math::ibetac_invb
  323. inline double gamma_p(double a, double x) { return pgamma(x, a, 1.0, 1, 0); }
  324. inline double gamma_q(double a, double x) { return pgamma(x, a, 1.0, 0, 0); }
  325. inline double gamma_p_inv(double a, double x) { return qgamma(x, a, 1.0, 1, 0); }
  326. inline double gamma_q_inv(double a, double x) { return qgamma(x, a, 1.0, 0, 0); }
  327. //#define IGAMMA_FUNCTION_TO_TEST boost::math::tgamma
  328. //#define IGAMMAL_FUNCTION_TO_TEST boost::math::tgamma_lower
  329. #define GAMMAP_FUNCTION_TO_TEST gamma_p
  330. #define GAMMAQ_FUNCTION_TO_TEST gamma_q
  331. #define GAMMAP_INV_FUNCTION_TO_TEST gamma_p_inv
  332. #define GAMMAQ_INV_FUNCTION_TO_TEST gamma_q_inv
  333. //#define GAMMAP_INVA_FUNCTION_TO_TEST boost::math::gamma_p_inva
  334. //#define GAMMAQ_INVA_FUNCTION_TO_TEST boost::math::gamma_q_inva
  335. //#define SN_FUNCTION_TO_TEST boost::math::jacobi_sn
  336. //#define CN_FUNCTION_TO_TEST boost::math::jacobi_cn
  337. //#define DN_FUNCTION_TO_TEST boost::math::jacobi_dn
  338. //#define JACOBI_ZETA_FUNCTION_TO_TEST boost::math::jacobi_zeta
  339. //#define LAGUERRE_FUNCTION_TO_TEST boost::math::laguerre
  340. //#define ASSOC_LAGUERRE_FUNCTION_TO_TEST boost::math::laguerre
  341. //#define LEGENDRE_P_FUNCTION_TO_TEST boost::math::legendre_p
  342. //#define LEGENDRE_Q_FUNCTION_TO_TEST boost::math::legendre_q
  343. //#define LEGENDRE_PA_FUNCTION_TO_TEST boost::math::legendre_p
  344. inline double polygamma(int n, double x)
  345. {
  346. if (x < 0)
  347. throw std::domain_error("Outside supported domain");
  348. return psigamma(x, n);
  349. }
  350. #define POLYGAMMA_FUNCTION_TO_TEST polygamma
  351. //#define TGAMMA_RATIO_FUNCTION_TO_TEST boost::math::tgamma_ratio
  352. //#define TGAMMA_DELTA_RATIO_FUNCTION_TO_TEST boost::math::tgamma_delta_ratio
  353. //#define SIN_PI_RATIO_FUNCTION_TO_TEST sinpi
  354. //#define COS_PI_RATIO_FUNCTION_TO_TEST cospi
  355. #define TRIGAMMA_RATIO_FUNCTION_TO_TEST trigamma
  356. //#define ZETA_FUNCTION_TO_TEST boost::math::zeta
  357. //#define SQRT1PM1_FUNCTION_TO_TEST boost::math::sqrt1pm1
  358. //#define POWM1_FUNCTION_TO_TEST boost::math::powm1
  359. //#define OWENS_T_FUNCTION_TO_TEST boost::math::owens_t
  360. //#define SPHERICAL_HARMONIC_R_FUNCTION_TO_TEST boost::math::spherical_harmonic_r
  361. //#define SPHERICAL_HARMONIC_I_FUNCTION_TO_TEST boost::math::spherical_harmonic_i
  362. template <class T> T do_nc_beta_cdf(T a, T b, T nc, T x){ return pnbeta(x, a, b, nc, 1, 0); }
  363. template <class T> T do_nc_beta_ccdf(T a, T b, T nc, T x){ return pnbeta(x, a, b, nc, 0, 0); }
  364. template <class T> T do_nc_chi_squared_cdf(T df, T nc, T x){ return pnchisq(x, df, nc, 1, 0); }
  365. template <class T> T do_nc_chi_squared_ccdf(T df, T nc, T x){ return pnchisq(x, df, nc, 0, 0); }
  366. template <class T> T do_nc_t_cdf(T df, T nc, T x){ return pnt(x, df, nc, 1, 0); }
  367. template <class T> T do_nc_t_ccdf(T df, T nc, T x){ return pnt(x, df, nc, 0, 0); }
  368. #define NC_BETA_CDF_FUNCTION_TO_TEST do_nc_beta_cdf
  369. #define NC_BETA_CCDF_FUNCTION_TO_TEST do_nc_beta_ccdf
  370. #define NC_CHI_SQUARED_CDF_FUNCTION_TO_TEST do_nc_chi_squared_cdf
  371. #define NC_CHI_SQUARED_CCDF_FUNCTION_TO_TEST do_nc_chi_squared_ccdf
  372. #define NC_T_CDF_FUNCTION_TO_TEST do_nc_t_cdf
  373. #define NC_T_CCDF_FUNCTION_TO_TEST do_nc_t_ccdf
  374. #define TYPE_TO_TEST double
  375. #elif defined(TEST_CEPHES)
  376. #define TEST_LIBRARY_NAME "Cephes"
  377. #define TYPE_TO_TEST double
  378. extern "C" {
  379. double log1p(double) throw();
  380. double expm1(double) throw();
  381. double cbrt(double) throw();
  382. double erf(double) throw();
  383. double erfc(double) throw();
  384. double gamma(double) throw();
  385. double lgam(double) throw();
  386. double iv(double, double) throw();
  387. double jv(double, double) throw();
  388. double jn(int, double) throw();
  389. double kn(int, double) throw();
  390. double yn(int, double) throw();
  391. double beta(double, double)throw();
  392. double psi(double);
  393. double ellik(double, double);
  394. double ellpk(double);
  395. double ellie(double, double);
  396. double ellpe(double);
  397. double ei(double);
  398. // Can't get any sensible values from Cephes expn???
  399. //double expn(double, double);
  400. double incbet(double, double, double);
  401. double incbi(double, double, double);
  402. double igam(double, double);
  403. double igamc(double, double);
  404. double igami(double, double);
  405. double ellpj(double u, double m, double *sn, double *cn, double *dn, double *phi);
  406. double zetac(double);
  407. }
  408. inline double ellint_1(double k, double phi) { return ellik(phi, k * k); }
  409. inline double ellint_2(double k, double phi) { return ellie(phi, k * k); }
  410. inline double ellint_1(double k) { return ellpk(k * k); }
  411. inline double ellint_2(double k) { return ellpe(k * k); }
  412. inline double sn(double k, double u)
  413. {
  414. double sn, cn, dn, phi;
  415. ellpj(u, k * k, &sn, &cn, &dn, &phi);
  416. return sn;
  417. }
  418. inline double cn(double k, double u)
  419. {
  420. double sn, cn, dn, phi;
  421. ellpj(u, k * k, &sn, &cn, &dn, &phi);
  422. return cn;
  423. }
  424. inline double dn(double k, double u)
  425. {
  426. double sn, cn, dn, phi;
  427. ellpj(u, k * k, &sn, &cn, &dn, &phi);
  428. return dn;
  429. }
  430. #define LOG1P_FUNCTION_TO_TEST log1p
  431. #define EXPM1_FUNCTION_TO_TEST expm1
  432. #define CBRT_FUNCTION_TO_TEST cbrt
  433. #define ERF_FUNCTION_TO_TEST erf
  434. #define ERFC_FUNCTION_TO_TEST erfc
  435. //#define ERF_INV_FUNCTION_TO_TEST boost::math::erf_inv
  436. //#define ERFC_INV_FUNCTION_TO_TEST boost::math::erfc_inv
  437. #define LGAMMA_FUNCTION_TO_TEST lgam
  438. #define TGAMMA_FUNCTION_TO_TEST gamma
  439. //#define TGAMMA1PM1_FUNCTION_TO_TEST boost::math::tgamma1pm1
  440. #define BESSEL_I_FUNCTION_TO_TEST iv
  441. #define BESSEL_IN_FUNCTION_TO_TEST iv
  442. //#define BESSEL_IP_FUNCTION_TO_TEST boost::math::cyl_bessel_i_prime
  443. //#define BESSEL_IPN_FUNCTION_TO_TEST boost::math::cyl_bessel_i_prime
  444. #define BESSEL_J_FUNCTION_TO_TEST jv
  445. #define BESSEL_JN_FUNCTION_TO_TEST jn
  446. //#define BESSEL_JS_FUNCTION_TO_TEST boost::math::sph_bessel
  447. //#define BESSEL_JP_FUNCTION_TO_TEST boost::math::cyl_bessel_j_prime
  448. //#define BESSEL_JPN_FUNCTION_TO_TEST boost::math::cyl_bessel_j_prime
  449. //#define BESSEL_JPS_FUNCTION_TO_TEST boost::math::sph_bessel_prime
  450. //#define BESSEL_K_FUNCTION_TO_TEST boost::math::cyl_bessel_k
  451. #define BESSEL_KN_FUNCTION_TO_TEST kn
  452. //#define BESSEL_KP_FUNCTION_TO_TEST boost::math::cyl_bessel_k_prime
  453. //#define BESSEL_KPN_FUNCTION_TO_TEST boost::math::cyl_bessel_k_prime
  454. //#define BESSEL_Y_FUNCTION_TO_TEST boost::math::cyl_neumann
  455. #define BESSEL_YN_FUNCTION_TO_TEST yn
  456. //#define BESSEL_YS_FUNCTION_TO_TEST boost::math::sph_neumann
  457. //#define BESSEL_YP_FUNCTION_TO_TEST boost::math::cyl_neumann_prime
  458. //#define BESSEL_YNP_FUNCTION_TO_TEST boost::math::cyl_neumann_prime
  459. //#define BESSEL_YSP_FUNCTION_TO_TEST boost::math::sph_neumann_prime
  460. #define BETA_FUNCTION_TO_TEST beta
  461. //#define BINOMIAL_FUNCTION_TO_TEST boost::math::binomial_coefficient<T>
  462. //#define ELLINT_RC_FUNCTION_TO_TEST boost::math::ellint_rc
  463. //#define ELLINT_RD_FUNCTION_TO_TEST boost::math::ellint_rd
  464. //#define ELLINT_RF_FUNCTION_TO_TEST boost::math::ellint_rf
  465. //#define ELLINT_RG_FUNCTION_TO_TEST boost::math::ellint_rg
  466. //#define ELLINT_RJ_FUNCTION_TO_TEST boost::math::ellint_rj
  467. #define DIGAMMA_FUNCTION_TO_TEST psi
  468. #define ELLINT_1_FUNCTION_TO_TEST ellint_1
  469. // Can't seem to get sensible answers from Cephes complete elliptic integrals???
  470. //#define ELLINT_1C_FUNCTION_TO_TEST ellint_1
  471. #define ELLINT_2_FUNCTION_TO_TEST ellint_2
  472. //#define ELLINT_2C_FUNCTION_TO_TEST ellint_2
  473. //#define ELLINT_3_FUNCTION_TO_TEST boost::math::ellint_3
  474. //#define ELLINT_3C_FUNCTION_TO_TEST boost::math::ellint_3
  475. //#define ELLINT_D2_FUNCTION_TO_TEST boost::math::ellint_d
  476. //#define ELLINT_D1_FUNCTION_TO_TEST boost::math::ellint_d
  477. #define EI_FUNCTION_TO_TEST ei
  478. //#define EN_FUNCTION_TO_TEST expn
  479. //#define HERMITE_FUNCTION_TO_TEST boost::math::hermite
  480. //#define HEUMAN_LAMBDA_FUNCTION_TO_TEST boost::math::heuman_lambda
  481. //#define BETA_INC_FUNCTION_TO_TEST incbet
  482. //#define BETAC_INC_FUNCTION_TO_TEST boost::math::betac
  483. #define IBETA_FUNCTION_TO_TEST incbet
  484. //#define IBETAC_FUNCTION_TO_TEST boost::math::ibetac
  485. #define IBETA_INV_FUNCTION_TO_TEST incbi
  486. //#define IBETAC_INV_FUNCTION_TO_TEST boost::math::ibetac_inv
  487. //#define IBETA_INVA_FUNCTION_TO_TEST boost::math::ibeta_inva
  488. //#define IBETAC_INVA_FUNCTION_TO_TEST boost::math::ibetac_inva
  489. //#define IBETA_INVB_FUNCTION_TO_TEST boost::math::ibeta_invb
  490. //#define IBETAC_INVB_FUNCTION_TO_TEST boost::math::ibetac_invb
  491. //#define IGAMMA_FUNCTION_TO_TEST boost::math::tgamma
  492. //#define IGAMMAL_FUNCTION_TO_TEST boost::math::tgamma_lower
  493. #define GAMMAP_FUNCTION_TO_TEST igam
  494. #define GAMMAQ_FUNCTION_TO_TEST igamc
  495. //#define GAMMAP_INV_FUNCTION_TO_TEST boost::math::gamma_p_inv
  496. #define GAMMAQ_INV_FUNCTION_TO_TEST igami
  497. //#define GAMMAP_INVA_FUNCTION_TO_TEST boost::math::gamma_p_inva
  498. //#define GAMMAQ_INVA_FUNCTION_TO_TEST boost::math::gamma_q_inva
  499. #define SN_FUNCTION_TO_TEST sn
  500. #define CN_FUNCTION_TO_TEST cn
  501. #define DN_FUNCTION_TO_TEST dn
  502. #define ZETA_FUNCTION_TO_TEST zetac
  503. #else
  504. #include <boost/math/distributions/non_central_beta.hpp>
  505. #include <boost/math/distributions/non_central_chi_squared.hpp>
  506. #include <boost/math/distributions/non_central_t.hpp>
  507. #define TEST_LIBRARY_NAME "boost"
  508. #define LOG1P_FUNCTION_TO_TEST boost::math::log1p
  509. #define EXPM1_FUNCTION_TO_TEST boost::math::expm1
  510. #define CBRT_FUNCTION_TO_TEST boost::math::cbrt
  511. #define ERF_FUNCTION_TO_TEST boost::math::erf
  512. #define ERFC_FUNCTION_TO_TEST boost::math::erfc
  513. #define ERF_INV_FUNCTION_TO_TEST boost::math::erf_inv
  514. #define ERFC_INV_FUNCTION_TO_TEST boost::math::erfc_inv
  515. #define LGAMMA_FUNCTION_TO_TEST boost::math::lgamma
  516. #define TGAMMA_FUNCTION_TO_TEST boost::math::tgamma
  517. #define TGAMMA1PM1_FUNCTION_TO_TEST boost::math::tgamma1pm1
  518. #define BESSEL_I_FUNCTION_TO_TEST boost::math::cyl_bessel_i
  519. #define BESSEL_IN_FUNCTION_TO_TEST boost::math::cyl_bessel_i
  520. #define BESSEL_IP_FUNCTION_TO_TEST boost::math::cyl_bessel_i_prime
  521. #define BESSEL_IPN_FUNCTION_TO_TEST boost::math::cyl_bessel_i_prime
  522. #define BESSEL_J_FUNCTION_TO_TEST boost::math::cyl_bessel_j
  523. #define BESSEL_JN_FUNCTION_TO_TEST boost::math::cyl_bessel_j
  524. #define BESSEL_JS_FUNCTION_TO_TEST boost::math::sph_bessel
  525. #define BESSEL_JP_FUNCTION_TO_TEST boost::math::cyl_bessel_j_prime
  526. #define BESSEL_JPN_FUNCTION_TO_TEST boost::math::cyl_bessel_j_prime
  527. #define BESSEL_JPS_FUNCTION_TO_TEST boost::math::sph_bessel_prime
  528. #define BESSEL_K_FUNCTION_TO_TEST boost::math::cyl_bessel_k
  529. #define BESSEL_KN_FUNCTION_TO_TEST boost::math::cyl_bessel_k
  530. #define BESSEL_KP_FUNCTION_TO_TEST boost::math::cyl_bessel_k_prime
  531. #define BESSEL_KPN_FUNCTION_TO_TEST boost::math::cyl_bessel_k_prime
  532. #define BESSEL_Y_FUNCTION_TO_TEST boost::math::cyl_neumann
  533. #define BESSEL_YN_FUNCTION_TO_TEST boost::math::cyl_neumann
  534. #define BESSEL_YS_FUNCTION_TO_TEST boost::math::sph_neumann
  535. #define BESSEL_YP_FUNCTION_TO_TEST boost::math::cyl_neumann_prime
  536. #define BESSEL_YNP_FUNCTION_TO_TEST boost::math::cyl_neumann_prime
  537. #define BESSEL_YSP_FUNCTION_TO_TEST boost::math::sph_neumann_prime
  538. #define BETA_FUNCTION_TO_TEST boost::math::beta
  539. #define BINOMIAL_FUNCTION_TO_TEST boost::math::binomial_coefficient<T>
  540. #define ELLINT_RC_FUNCTION_TO_TEST boost::math::ellint_rc
  541. #define ELLINT_RD_FUNCTION_TO_TEST boost::math::ellint_rd
  542. #define ELLINT_RF_FUNCTION_TO_TEST boost::math::ellint_rf
  543. #define ELLINT_RG_FUNCTION_TO_TEST boost::math::ellint_rg
  544. #define ELLINT_RJ_FUNCTION_TO_TEST boost::math::ellint_rj
  545. #define DIGAMMA_FUNCTION_TO_TEST boost::math::digamma
  546. #define ELLINT_1_FUNCTION_TO_TEST boost::math::ellint_1
  547. #define ELLINT_1C_FUNCTION_TO_TEST boost::math::ellint_1
  548. #define ELLINT_2_FUNCTION_TO_TEST boost::math::ellint_2
  549. #define ELLINT_2C_FUNCTION_TO_TEST boost::math::ellint_2
  550. #define ELLINT_3_FUNCTION_TO_TEST boost::math::ellint_3
  551. #define ELLINT_3C_FUNCTION_TO_TEST boost::math::ellint_3
  552. #define ELLINT_D2_FUNCTION_TO_TEST boost::math::ellint_d
  553. #define ELLINT_D1_FUNCTION_TO_TEST boost::math::ellint_d
  554. #define EI_FUNCTION_TO_TEST boost::math::expint
  555. #define EN_FUNCTION_TO_TEST boost::math::expint
  556. #define HERMITE_FUNCTION_TO_TEST boost::math::hermite
  557. #define HEUMAN_LAMBDA_FUNCTION_TO_TEST boost::math::heuman_lambda
  558. #define BETA_INC_FUNCTION_TO_TEST boost::math::beta
  559. #define BETAC_INC_FUNCTION_TO_TEST boost::math::betac
  560. #define IBETA_FUNCTION_TO_TEST boost::math::ibeta
  561. #define IBETAC_FUNCTION_TO_TEST boost::math::ibetac
  562. #define IBETA_INV_FUNCTION_TO_TEST boost::math::ibeta_inv
  563. #define IBETAC_INV_FUNCTION_TO_TEST boost::math::ibetac_inv
  564. #define IBETA_INVA_FUNCTION_TO_TEST boost::math::ibeta_inva
  565. #define IBETAC_INVA_FUNCTION_TO_TEST boost::math::ibetac_inva
  566. #define IBETA_INVB_FUNCTION_TO_TEST boost::math::ibeta_invb
  567. #define IBETAC_INVB_FUNCTION_TO_TEST boost::math::ibetac_invb
  568. #define IGAMMA_FUNCTION_TO_TEST boost::math::tgamma
  569. #define IGAMMAL_FUNCTION_TO_TEST boost::math::tgamma_lower
  570. #define GAMMAP_FUNCTION_TO_TEST boost::math::gamma_p
  571. #define GAMMAQ_FUNCTION_TO_TEST boost::math::gamma_q
  572. #define GAMMAP_INV_FUNCTION_TO_TEST boost::math::gamma_p_inv
  573. #define GAMMAQ_INV_FUNCTION_TO_TEST boost::math::gamma_q_inv
  574. #define GAMMAP_INVA_FUNCTION_TO_TEST boost::math::gamma_p_inva
  575. #define GAMMAQ_INVA_FUNCTION_TO_TEST boost::math::gamma_q_inva
  576. #define SN_FUNCTION_TO_TEST boost::math::jacobi_sn
  577. #define CN_FUNCTION_TO_TEST boost::math::jacobi_cn
  578. #define DN_FUNCTION_TO_TEST boost::math::jacobi_dn
  579. #define JACOBI_ZETA_FUNCTION_TO_TEST boost::math::jacobi_zeta
  580. #define LAGUERRE_FUNCTION_TO_TEST boost::math::laguerre
  581. #define ASSOC_LAGUERRE_FUNCTION_TO_TEST boost::math::laguerre
  582. #define LEGENDRE_P_FUNCTION_TO_TEST boost::math::legendre_p
  583. #define LEGENDRE_Q_FUNCTION_TO_TEST boost::math::legendre_q
  584. #define LEGENDRE_PA_FUNCTION_TO_TEST boost::math::legendre_p
  585. #define POLYGAMMA_FUNCTION_TO_TEST boost::math::polygamma
  586. #define TGAMMA_RATIO_FUNCTION_TO_TEST boost::math::tgamma_ratio
  587. #define TGAMMA_DELTA_RATIO_FUNCTION_TO_TEST boost::math::tgamma_delta_ratio
  588. #define SIN_PI_RATIO_FUNCTION_TO_TEST boost::math::sin_pi
  589. #define COS_PI_RATIO_FUNCTION_TO_TEST boost::math::cos_pi
  590. #define TRIGAMMA_RATIO_FUNCTION_TO_TEST boost::math::trigamma
  591. #define ZETA_FUNCTION_TO_TEST boost::math::zeta
  592. #define SQRT1PM1_FUNCTION_TO_TEST boost::math::sqrt1pm1
  593. #define POWM1_FUNCTION_TO_TEST boost::math::powm1
  594. #define OWENS_T_FUNCTION_TO_TEST boost::math::owens_t
  595. #define SPHERICAL_HARMONIC_R_FUNCTION_TO_TEST boost::math::spherical_harmonic_r
  596. #define SPHERICAL_HARMONIC_I_FUNCTION_TO_TEST boost::math::spherical_harmonic_i
  597. template <class T> T do_nc_beta_cdf(T a, T b, T nc, T x){ return cdf(boost::math::non_central_beta_distribution<T>(a, b, nc), x); }
  598. template <class T> T do_nc_beta_ccdf(T a, T b, T nc, T x){ return cdf(complement(boost::math::non_central_beta_distribution<T>(a, b, nc), x)); }
  599. template <class T> T do_nc_chi_squared_cdf(T df, T nc, T x){ return cdf(boost::math::non_central_chi_squared_distribution<T>(df, nc), x); }
  600. template <class T> T do_nc_chi_squared_ccdf(T df, T nc, T x){ return cdf(complement(boost::math::non_central_chi_squared_distribution<T>(df, nc), x)); }
  601. template <class T> T do_nc_t_cdf(T df, T nc, T x){ return cdf(boost::math::non_central_t_distribution<T>(df, nc), x); }
  602. template <class T> T do_nc_t_ccdf(T df, T nc, T x){ return cdf(complement(boost::math::non_central_t_distribution<T>(df, nc), x)); }
  603. #define NC_BETA_CDF_FUNCTION_TO_TEST do_nc_beta_cdf
  604. #define NC_BETA_CCDF_FUNCTION_TO_TEST do_nc_beta_ccdf
  605. #define NC_CHI_SQUARED_CDF_FUNCTION_TO_TEST do_nc_chi_squared_cdf
  606. #define NC_CHI_SQUARED_CCDF_FUNCTION_TO_TEST do_nc_chi_squared_ccdf
  607. #define NC_T_CDF_FUNCTION_TO_TEST do_nc_t_cdf
  608. #define NC_T_CCDF_FUNCTION_TO_TEST do_nc_t_ccdf
  609. #endif
  610. #if defined(TYPE_TO_TEST) && !defined(NAME_OF_TYPE_TO_TEST)
  611. #define NAME_OF_TYPE_TO_TEST BOOST_STRINGIZE(TYPE_TO_TEST)
  612. #endif
  613. //
  614. // This include has to come at the end after all the setup is done:
  615. //
  616. #include "handle_test_result.hpp"
  617. #endif