test_ibeta.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. // (C) Copyright John Maddock 2006.
  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. #include <pch_light.hpp>
  6. #include "test_ibeta.hpp"
  7. #if !defined(TEST_FLOAT) && !defined(TEST_DOUBLE) && !defined(TEST_LDOUBLE) && !defined(TEST_REAL_CONCEPT)
  8. # define TEST_FLOAT
  9. # define TEST_DOUBLE
  10. # define TEST_LDOUBLE
  11. # define TEST_REAL_CONCEPT
  12. #endif
  13. //
  14. // DESCRIPTION:
  15. // ~~~~~~~~~~~~
  16. //
  17. // This file tests the incomplete beta functions beta,
  18. // betac, ibeta and ibetac. There are two sets of tests, spot
  19. // tests which compare our results with selected values computed
  20. // using the online special function calculator at
  21. // functions.wolfram.com, while the bulk of the accuracy tests
  22. // use values generated with NTL::RR at 1000-bit precision
  23. // and our generic versions of these functions.
  24. //
  25. // Note that when this file is first run on a new platform many of
  26. // these tests will fail: the default accuracy is 1 epsilon which
  27. // is too tight for most platforms. In this situation you will
  28. // need to cast a human eye over the error rates reported and make
  29. // a judgement as to whether they are acceptable. Either way please
  30. // report the results to the Boost mailing list. Acceptable rates of
  31. // error are marked up below as a series of regular expressions that
  32. // identify the compiler/stdlib/platform/data-type/test-data/test-function
  33. // along with the maximum expected peek and RMS mean errors for that
  34. // test.
  35. //
  36. void expected_results()
  37. {
  38. //
  39. // Define the max and mean errors expected for
  40. // various compilers and platforms.
  41. //
  42. const char* largest_type;
  43. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  44. if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
  45. {
  46. largest_type = "(long\\s+)?double";
  47. }
  48. else
  49. {
  50. largest_type = "long double";
  51. }
  52. #else
  53. largest_type = "(long\\s+)?double";
  54. #endif
  55. //
  56. // Darwin: just one special case for real_concept:
  57. //
  58. add_expected_result(
  59. "[^|]*", // compiler
  60. "[^|]*", // stdlib
  61. "Mac OS", // platform
  62. "real_concept", // test type(s)
  63. "(?i).*large.*", // test data group
  64. ".*", 400000, 50000); // test function
  65. //
  66. // Linux - results depend quite a bit on the
  67. // processor type, and how good the std::pow
  68. // function is for that processor.
  69. //
  70. add_expected_result(
  71. "[^|]*", // compiler
  72. "[^|]*", // stdlib
  73. "linux", // platform
  74. largest_type, // test type(s)
  75. "(?i).*small.*", // test data group
  76. ".*", 350, 100); // test function
  77. add_expected_result(
  78. "[^|]*", // compiler
  79. "[^|]*", // stdlib
  80. "linux", // platform
  81. largest_type, // test type(s)
  82. "(?i).*medium.*", // test data group
  83. ".*", 300, 80); // test function
  84. //
  85. // Deficiencies in pow function really kick in here for
  86. // large arguments. Note also that the tests here get
  87. // *very* extreme due to the increased exponent range
  88. // of 80-bit long doubles. Also effect Mac OS.
  89. //
  90. add_expected_result(
  91. "[^|]*", // compiler
  92. "[^|]*", // stdlib
  93. "linux|Mac OS", // platform
  94. largest_type, // test type(s)
  95. "(?i).*large.*", // test data group
  96. ".*", 200000, 10000); // test function
  97. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  98. add_expected_result(
  99. "[^|]*", // compiler
  100. "[^|]*", // stdlib
  101. "linux|Mac OS|Sun.*", // platform
  102. "double", // test type(s)
  103. "(?i).*large.*", // test data group
  104. ".*", 40, 20); // test function
  105. #endif
  106. add_expected_result(
  107. "[^|]*", // compiler
  108. "[^|]*", // stdlib
  109. "linux|Mac OS", // platform
  110. "real_concept", // test type(s)
  111. "(?i).*medium.*", // test data group
  112. ".*", 350, 100); // test function
  113. //
  114. // HP-UX:
  115. //
  116. // Large value tests include some with *very* extreme
  117. // results, thanks to the large exponent range of
  118. // 128-bit long doubles.
  119. //
  120. add_expected_result(
  121. "[^|]*", // compiler
  122. "[^|]*", // stdlib
  123. "HP-UX", // platform
  124. largest_type, // test type(s)
  125. "(?i).*large.*", // test data group
  126. ".*", 200000, 10000); // test function
  127. //
  128. // Tru64:
  129. //
  130. add_expected_result(
  131. ".*Tru64.*", // compiler
  132. ".*", // stdlib
  133. ".*", // platform
  134. largest_type, // test type(s)
  135. "(?i).*large.*", // test data group
  136. ".*", 130000, 10000); // test function
  137. //
  138. // Sun OS:
  139. //
  140. add_expected_result(
  141. "[^|]*", // compiler
  142. "[^|]*", // stdlib
  143. "Sun.*", // platform
  144. largest_type, // test type(s)
  145. "(?i).*large.*", // test data group
  146. ".*", 130000, 10000); // test function
  147. add_expected_result(
  148. "[^|]*", // compiler
  149. "[^|]*", // stdlib
  150. "Sun.*", // platform
  151. largest_type, // test type(s)
  152. "(?i).*small.*", // test data group
  153. ".*", 130, 30); // test function
  154. add_expected_result(
  155. "[^|]*", // compiler
  156. "[^|]*", // stdlib
  157. "Sun.*", // platform
  158. largest_type, // test type(s)
  159. "(?i).*medium.*", // test data group
  160. ".*", 250, 40); // test function
  161. add_expected_result(
  162. "[^|]*", // compiler
  163. "[^|]*", // stdlib
  164. "Sun.*", // platform
  165. "real_concept", // test type(s)
  166. "(?i).*medium.*", // test data group
  167. ".*", 250, 40); // test function
  168. add_expected_result(
  169. "[^|]*", // compiler
  170. "[^|]*", // stdlib
  171. "Sun.*", // platform
  172. "real_concept", // test type(s)
  173. "(?i).*small.*", // test data group
  174. ".*", 130, 30); // test function
  175. //
  176. // MinGW:
  177. //
  178. add_expected_result(
  179. "GNU[^|]*", // compiler
  180. "[^|]*", // stdlib
  181. "Win32[^|]*", // platform
  182. "real_concept", // test type(s)
  183. "(?i).*medium.*", // test data group
  184. ".*", 400, 50); // test function
  185. add_expected_result(
  186. "GNU.*", // compiler
  187. ".*", // stdlib
  188. "Win32.*", // platform
  189. "double", // test type(s)
  190. "(?i).*large.*", // test data group
  191. ".*", 20, 10); // test function
  192. add_expected_result(
  193. "GNU.*", // compiler
  194. ".*", // stdlib
  195. "Win32.*", // platform
  196. largest_type, // test type(s)
  197. "(?i).*large.*", // test data group
  198. ".*", 200000, 10000); // test function
  199. #ifdef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  200. //
  201. // No long doubles:
  202. //
  203. add_expected_result(
  204. "[^|]*", // compiler
  205. "[^|]*", // stdlib
  206. BOOST_PLATFORM, // platform
  207. largest_type, // test type(s)
  208. "(?i).*large.*", // test data group
  209. ".*", 13000, 500); // test function
  210. #endif
  211. //
  212. // Catch all cases come last:
  213. //
  214. add_expected_result(
  215. "[^|]*", // compiler
  216. "[^|]*", // stdlib
  217. "[^|]*", // platform
  218. largest_type, // test type(s)
  219. "(?i).*small.*", // test data group
  220. ".*", 90, 25); // test function
  221. add_expected_result(
  222. "[^|]*", // compiler
  223. "[^|]*", // stdlib
  224. "[^|]*", // platform
  225. largest_type, // test type(s)
  226. "(?i).*medium.*", // test data group
  227. ".*", 350, 50); // test function
  228. add_expected_result(
  229. "[^|]*", // compiler
  230. "[^|]*", // stdlib
  231. "[^|]*", // platform
  232. largest_type, // test type(s)
  233. "(?i).*large.*", // test data group
  234. ".*", 5000, 500); // test function
  235. add_expected_result(
  236. "[^|]*", // compiler
  237. "[^|]*", // stdlib
  238. "[^|]*", // platform
  239. "real_concept", // test type(s)
  240. "(?i).*small.*", // test data group
  241. ".*", 90, 25); // test function
  242. add_expected_result(
  243. "[^|]*", // compiler
  244. "[^|]*", // stdlib
  245. "[^|]*", // platform
  246. "real_concept", // test type(s)
  247. "(?i).*medium.*", // test data group
  248. ".*", 250, 50); // test function
  249. add_expected_result(
  250. "[^|]*", // compiler
  251. "[^|]*", // stdlib
  252. "[^|]*", // platform
  253. "real_concept", // test type(s)
  254. "(?i).*large.*", // test data group
  255. ".*", 200000, 50000); // test function
  256. // catch all default is 2eps for all types:
  257. add_expected_result(
  258. "[^|]*", // compiler
  259. "[^|]*", // stdlib
  260. "[^|]*", // platform
  261. "[^|]*", // test type(s)
  262. "[^|]*", // test data group
  263. ".*", 2, 2); // test function
  264. //
  265. // Finish off by printing out the compiler/stdlib/platform names,
  266. // we do this to make it easier to mark up expected error rates.
  267. //
  268. std::cout << "Tests run with " << BOOST_COMPILER << ", "
  269. << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
  270. }
  271. BOOST_AUTO_TEST_CASE( test_main )
  272. {
  273. expected_results();
  274. BOOST_MATH_CONTROL_FP;
  275. #ifdef TEST_GSL
  276. gsl_set_error_handler_off();
  277. #endif
  278. #ifdef TEST_FLOAT
  279. test_spots(0.0F);
  280. #endif
  281. #ifdef TEST_DOUBLE
  282. test_spots(0.0);
  283. #endif
  284. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  285. #ifdef TEST_LDOUBLE
  286. test_spots(0.0L);
  287. #endif
  288. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
  289. #ifdef TEST_REAL_CONCEPT
  290. test_spots(boost::math::concepts::real_concept(0.1));
  291. #endif
  292. #endif
  293. #endif
  294. #ifdef TEST_FLOAT
  295. test_beta(0.1F, "float");
  296. #endif
  297. #ifdef TEST_DOUBLE
  298. test_beta(0.1, "double");
  299. #endif
  300. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  301. #ifdef TEST_LDOUBLE
  302. test_beta(0.1L, "long double");
  303. #endif
  304. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  305. #ifdef TEST_REAL_CONCEPT
  306. test_beta(boost::math::concepts::real_concept(0.1), "real_concept");
  307. #endif
  308. #endif
  309. #else
  310. std::cout << "<note>The long double tests have been disabled on this platform "
  311. "either because the long double overloads of the usual math functions are "
  312. "not available at all, or because they are too inaccurate for these tests "
  313. "to pass.</note>" << std::endl;
  314. #endif
  315. }