test_ibeta_inv.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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_inv.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 function inverses
  18. // ibeta_inv and ibetac_inv. There are three sets of tests:
  19. // 1) Spot tests which compare our results with selected values
  20. // computed using the online special function calculator at
  21. // functions.wolfram.com,
  22. // 2) TODO!!!! Accuracy tests use values generated with NTL::RR at
  23. // 1000-bit precision and our generic versions of these functions.
  24. // 3) Round trip sanity checks, use the test data for the forward
  25. // functions, and verify that we can get (approximately) back
  26. // where we started.
  27. //
  28. // Note that when this file is first run on a new platform many of
  29. // these tests will fail: the default accuracy is 1 epsilon which
  30. // is too tight for most platforms. In this situation you will
  31. // need to cast a human eye over the error rates reported and make
  32. // a judgement as to whether they are acceptable. Either way please
  33. // report the results to the Boost mailing list. Acceptable rates of
  34. // error are marked up below as a series of regular expressions that
  35. // identify the compiler/stdlib/platform/data-type/test-data/test-function
  36. // along with the maximum expected peek and RMS mean errors for that
  37. // test.
  38. //
  39. void expected_results()
  40. {
  41. //
  42. // Define the max and mean errors expected for
  43. // various compilers and platforms.
  44. //
  45. // Note that permitted max errors are really pretty high
  46. // at around 10000eps. The reason for this is that even
  47. // if the forward function is off by 1eps, it's enough to
  48. // throw out the inverse by ~7000eps. In other words the
  49. // forward function may flatline, so that many x-values
  50. // all map to about the same p. Trying to invert in this
  51. // region is almost futile.
  52. //
  53. const char* largest_type;
  54. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  55. if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
  56. {
  57. largest_type = "(long\\s+)?double";
  58. }
  59. else
  60. {
  61. largest_type = "long double";
  62. }
  63. #else
  64. largest_type = "(long\\s+)?double";
  65. #endif
  66. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  67. //
  68. // Linux etc,
  69. // Extended exponent range of long double
  70. // causes more extreme test cases to be executed:
  71. //
  72. if(std::numeric_limits<long double>::digits == 64)
  73. {
  74. add_expected_result(
  75. ".*", // compiler
  76. ".*", // stdlib
  77. ".*", // platform
  78. "double", // test type(s)
  79. ".*", // test data group
  80. ".*", 20, 10); // test function
  81. add_expected_result(
  82. ".*", // compiler
  83. ".*", // stdlib
  84. ".*", // platform
  85. "long double", // test type(s)
  86. ".*", // test data group
  87. ".*", 200000, 100000); // test function
  88. add_expected_result(
  89. ".*", // compiler
  90. ".*", // stdlib
  91. ".*", // platform
  92. "real_concept", // test type(s)
  93. ".*", // test data group
  94. ".*", 5000000L, 500000); // test function
  95. }
  96. #endif
  97. //
  98. // MinGW,
  99. // Extended exponent range of long double
  100. // causes more extreme test cases to be executed:
  101. //
  102. add_expected_result(
  103. "GNU.*", // compiler
  104. ".*", // stdlib
  105. "Win32.*", // platform
  106. "double", // test type(s)
  107. ".*", // test data group
  108. ".*", 10, 10); // test function
  109. add_expected_result(
  110. "GNU.*", // compiler
  111. ".*", // stdlib
  112. "Win32.*", // platform
  113. largest_type, // test type(s)
  114. ".*", // test data group
  115. ".*", 300000, 20000); // test function
  116. //
  117. // HP-UX and Solaris:
  118. // Extended exponent range of long double
  119. // causes more extreme test cases to be executed:
  120. //
  121. add_expected_result(
  122. ".*", // compiler
  123. ".*", // stdlib
  124. "HP-UX|Sun Solaris", // platform
  125. "long double", // test type(s)
  126. ".*", // test data group
  127. ".*", 200000, 100000); // test function
  128. //
  129. // HP Tru64:
  130. // Extended exponent range of long double
  131. // causes more extreme test cases to be executed:
  132. //
  133. add_expected_result(
  134. "HP Tru64.*", // compiler
  135. ".*", // stdlib
  136. ".*", // platform
  137. "long double", // test type(s)
  138. ".*", // test data group
  139. ".*", 200000, 100000); // test function
  140. //
  141. // Catch all cases come last:
  142. //
  143. add_expected_result(
  144. ".*", // compiler
  145. ".*", // stdlib
  146. ".*", // platform
  147. largest_type, // test type(s)
  148. ".*", // test data group
  149. ".*", 10000, 1000); // test function
  150. add_expected_result(
  151. ".*", // compiler
  152. ".*", // stdlib
  153. ".*", // platform
  154. "real_concept", // test type(s)
  155. ".*", // test data group
  156. ".*", 500000, 500000); // test function
  157. //
  158. // Finish off by printing out the compiler/stdlib/platform names,
  159. // we do this to make it easier to mark up expected error rates.
  160. //
  161. std::cout << "Tests run with " << BOOST_COMPILER << ", "
  162. << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
  163. }
  164. BOOST_AUTO_TEST_CASE( test_main )
  165. {
  166. BOOST_MATH_CONTROL_FP;
  167. expected_results();
  168. #ifdef TEST_GSL
  169. gsl_set_error_handler_off();
  170. #endif
  171. #ifdef TEST_FLOAT
  172. test_spots(0.0F);
  173. #endif
  174. #ifdef TEST_DOUBLE
  175. test_spots(0.0);
  176. #endif
  177. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  178. #ifdef TEST_LDOUBLE
  179. test_spots(0.0L);
  180. #endif
  181. #ifdef TEST_REAL_CONCEPT
  182. test_spots(boost::math::concepts::real_concept(0.1));
  183. #endif
  184. #endif
  185. #ifdef TEST_FLOAT
  186. test_beta(0.1F, "float");
  187. #endif
  188. #ifdef TEST_DOUBLE
  189. test_beta(0.1, "double");
  190. #endif
  191. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  192. #ifdef TEST_LDOUBLE
  193. test_beta(0.1L, "long double");
  194. #endif
  195. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  196. #ifdef TEST_REAL_CONCEPT
  197. test_beta(boost::math::concepts::real_concept(0.1), "real_concept");
  198. #endif
  199. #endif
  200. #else
  201. std::cout << "<note>The long double tests have been disabled on this platform "
  202. "either because the long double overloads of the usual math functions are "
  203. "not available at all, or because they are too inaccurate for these tests "
  204. "to pass.</note>" << std::endl;
  205. #endif
  206. }