test_ibeta_derivative.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. #if defined(__GNUC__)
  6. #pragma GCC diagnostic push
  7. #pragma GCC diagnostic ignored "-Wliteral-range"
  8. #endif
  9. #include <pch_light.hpp>
  10. #include "test_ibeta_derivative.hpp"
  11. #if !defined(TEST_FLOAT) && !defined(TEST_DOUBLE) && !defined(TEST_LDOUBLE) && !defined(TEST_REAL_CONCEPT)
  12. # define TEST_FLOAT
  13. # define TEST_DOUBLE
  14. # define TEST_LDOUBLE
  15. # define TEST_REAL_CONCEPT
  16. #endif
  17. //
  18. // DESCRIPTION:
  19. // ~~~~~~~~~~~~
  20. //
  21. // This file tests the incomplete beta functions beta,
  22. // betac, ibeta and ibetac. There are two sets of tests, spot
  23. // tests which compare our results with selected values computed
  24. // using the online special function calculator at
  25. // functions.wolfram.com, while the bulk of the accuracy tests
  26. // use values generated with NTL::RR at 1000-bit precision
  27. // and our generic versions of these functions.
  28. //
  29. // Note that when this file is first run on a new platform many of
  30. // these tests will fail: the default accuracy is 1 epsilon which
  31. // is too tight for most platforms. In this situation you will
  32. // need to cast a human eye over the error rates reported and make
  33. // a judgement as to whether they are acceptable. Either way please
  34. // report the results to the Boost mailing list. Acceptable rates of
  35. // error are marked up below as a series of regular expressions that
  36. // identify the compiler/stdlib/platform/data-type/test-data/test-function
  37. // along with the maximum expected peek and RMS mean errors for that
  38. // test.
  39. //
  40. void expected_results()
  41. {
  42. //
  43. // Define the max and mean errors expected for
  44. // various compilers and platforms.
  45. //
  46. const char* largest_type;
  47. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  48. if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
  49. {
  50. largest_type = "(long\\s+)?double|real_concept";
  51. }
  52. else
  53. {
  54. largest_type = "long double|real_concept";
  55. }
  56. #else
  57. largest_type = "(long\\s+)?double";
  58. #endif
  59. if(std::numeric_limits<long double>::max_exponent > std::numeric_limits<double>::max_exponent)
  60. {
  61. add_expected_result(
  62. "[^|]*", // compiler
  63. "[^|]*", // stdlib
  64. "[^|]*", // platform
  65. largest_type, // test type(s)
  66. "[^|]*Medium.*", // test data group
  67. ".*", 200000, 7000); // test function
  68. add_expected_result(
  69. "[^|]*", // compiler
  70. "[^|]*", // stdlib
  71. "[^|]*", // platform
  72. "real_concept", // test type(s)
  73. "[^|]*Large.*", // test data group
  74. ".*", 300000, 10000); // test function
  75. add_expected_result(
  76. "[^|]*", // compiler
  77. "[^|]*", // stdlib
  78. "[^|]*", // platform
  79. largest_type, // test type(s)
  80. "[^|]*Large.*", // test data group
  81. ".*", 80000, 5000); // test function
  82. add_expected_result(
  83. "[^|]*", // compiler
  84. "[^|]*", // stdlib
  85. "[^|]*", // platform
  86. largest_type, // test type(s)
  87. "[^|]*Integer.*", // test data group
  88. ".*", 30000, 1500); // test function
  89. add_expected_result(
  90. "[^|]*", // compiler
  91. "[^|]*", // stdlib
  92. "[^|]*", // platform
  93. "double", // test type(s)
  94. "[^|]*Large.*", // test data group
  95. ".*", 3300, 200); // test function
  96. add_expected_result(
  97. "[^|]*", // compiler
  98. "[^|]*", // stdlib
  99. "[^|]*", // platform
  100. "double", // test type(s)
  101. "[^|]*", // test data group
  102. ".*", 200, 50); // test function
  103. }
  104. // catch all default is 2eps for all types:
  105. add_expected_result(
  106. "[^|]*", // compiler
  107. "[^|]*", // stdlib
  108. "[^|]*", // platform
  109. "real_concept", // test type(s)
  110. "[^|]*large.*", // test data group
  111. ".*", 200000, 6000); // test function
  112. add_expected_result(
  113. "[^|]*", // compiler
  114. "[^|]*", // stdlib
  115. "[^|]*", // platform
  116. largest_type, // test type(s)
  117. "[^|]*large.*", // test data group
  118. ".*", 3300, 200); // test function
  119. add_expected_result(
  120. "[^|]*", // compiler
  121. "[^|]*", // stdlib
  122. "[^|]*", // platform
  123. largest_type, // test type(s)
  124. "[^|]*", // test data group
  125. ".*", 300, 100); // test function
  126. //
  127. // Finish off by printing out the compiler/stdlib/platform names,
  128. // we do this to make it easier to mark up expected error rates.
  129. //
  130. std::cout << "Tests run with " << BOOST_COMPILER << ", "
  131. << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
  132. }
  133. BOOST_AUTO_TEST_CASE( test_main )
  134. {
  135. expected_results();
  136. BOOST_MATH_CONTROL_FP;
  137. #ifdef TEST_GSL
  138. gsl_set_error_handler_off();
  139. #endif
  140. #ifdef TEST_FLOAT
  141. test_spots(0.0F);
  142. #endif
  143. #ifdef TEST_DOUBLE
  144. test_spots(0.0);
  145. #endif
  146. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  147. #ifdef TEST_LDOUBLE
  148. test_spots(0.0L);
  149. #endif
  150. #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
  151. #ifdef TEST_REAL_CONCEPT
  152. test_spots(boost::math::concepts::real_concept(0.1));
  153. #endif
  154. #endif
  155. #endif
  156. #ifdef TEST_FLOAT
  157. test_beta(0.1F, "float");
  158. #endif
  159. #ifdef TEST_DOUBLE
  160. test_beta(0.1, "double");
  161. #endif
  162. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  163. #ifdef TEST_LDOUBLE
  164. test_beta(0.1L, "long double");
  165. #endif
  166. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  167. #ifdef TEST_REAL_CONCEPT
  168. test_beta(boost::math::concepts::real_concept(0.1), "real_concept");
  169. #endif
  170. #endif
  171. #else
  172. std::cout << "<note>The long double tests have been disabled on this platform "
  173. "either because the long double overloads of the usual math functions are "
  174. "not available at all, or because they are too inaccurate for these tests "
  175. "to pass.</note>" << std::endl;
  176. #endif
  177. }
  178. #if defined(__GNUC__)
  179. #pragma GCC diagnostic pop
  180. #endif