test_bessel_i_prime.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // Copyright (c) 2013 Anton Bikineev
  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_bessel_i_prime.hpp"
  7. //
  8. // DESCRIPTION:
  9. // ~~~~~~~~~~~~
  10. //
  11. // This file tests the bessel I functions derivatives. There are two sets of tests, spot
  12. // tests which compare our results with selected values computed
  13. // using the online special function calculator at
  14. // functions.wolfram.com, while the bulk of the accuracy tests
  15. // use values generated with Boost.Multiprecision at 50 precision
  16. // and our generic versions of these functions.
  17. //
  18. // Note that when this file is first run on a new platform many of
  19. // these tests will fail: the default accuracy is 1 epsilon which
  20. // is too tight for most platforms. In this situation you will
  21. // need to cast a human eye over the error rates reported and make
  22. // a judgement as to whether they are acceptable. Either way please
  23. // report the results to the Boost mailing list. Acceptable rates of
  24. // error are marked up below as a series of regular expressions that
  25. // identify the compiler/stdlib/platform/data-type/test-data/test-function
  26. // along with the maximum expected peek and RMS mean errors for that
  27. // test.
  28. //
  29. void expected_results()
  30. {
  31. //
  32. // Define the max and mean errors expected for
  33. // various compilers and platforms.
  34. //
  35. const char* largest_type;
  36. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  37. if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
  38. {
  39. largest_type = "(long\\s+)?double";
  40. }
  41. else
  42. {
  43. largest_type = "long double";
  44. }
  45. #else
  46. largest_type = "(long\\s+)?double";
  47. #endif
  48. //
  49. // Mac OS has higher error rates, why?
  50. //
  51. add_expected_result(
  52. ".*", // compiler
  53. ".*", // stdlib
  54. "Mac OS", // platform
  55. largest_type, // test type(s)
  56. ".*", // test data group
  57. ".*", 3500, 1500); // test function
  58. //
  59. // G++ on Linux, results vary a bit by processor type,
  60. // on Itanium results are *much* better than listed here,
  61. // but x86 appears to have much less accurate std::pow
  62. // that throws off the results for tgamma(long double)
  63. // which then impacts on the Bessel functions:
  64. //
  65. add_expected_result(
  66. ".*", // compiler
  67. ".*", // stdlib
  68. "linux", // platform
  69. largest_type, // test type(s)
  70. ".*Random.*", // test data group
  71. ".*", 600, 200); // test function
  72. add_expected_result(
  73. "GNU.*", // compiler
  74. ".*", // stdlib
  75. "Win32.*", // platform
  76. largest_type, // test type(s)
  77. ".*Random.*", // test data group
  78. ".*", 500, 200); // test function
  79. add_expected_result(
  80. "GNU.*", // compiler
  81. ".*", // stdlib
  82. "Win32.*", // platform
  83. largest_type, // test type(s)
  84. ".*", // test data group
  85. ".*", 3500, 1000); // test function
  86. add_expected_result(
  87. ".*", // compiler
  88. ".*", // stdlib
  89. ".*", // platform
  90. largest_type, // test type(s)
  91. ".*I'v.*Mathworld.*", // test data group
  92. ".*", 4000, 2000); // test function
  93. add_expected_result(
  94. ".*", // compiler
  95. ".*", // stdlib
  96. ".*Solaris.*", // platform
  97. largest_type, // test type(s)
  98. ".*", // test data group
  99. ".*", 900, 300); // test function
  100. add_expected_result(
  101. ".*", // compiler
  102. ".*", // stdlib
  103. ".*", // platform
  104. largest_type, // test type(s)
  105. ".*", // test data group
  106. ".*", 40, 25); // test function
  107. //
  108. // Set error rates a little higher for real_concept -
  109. // now that we use a series approximation for small z
  110. // that relies on tgamma the error rates are a little
  111. // higher only when a Lanczos approximation is not available.
  112. // All other types are unaffected.
  113. //
  114. add_expected_result(
  115. ".*", // compiler
  116. ".*", // stdlib
  117. ".*", // platform
  118. "real_concept", // test type(s)
  119. ".*I'v.*Mathworld.*", // test data group
  120. ".*", 4000, 2000); // test function
  121. add_expected_result(
  122. ".*", // compiler
  123. ".*", // stdlib
  124. ".*Solaris.*", // platform
  125. "real_concept", // test type(s)
  126. ".*", // test data group
  127. ".*", 800, 400); // test function
  128. add_expected_result(
  129. ".*", // compiler
  130. ".*", // stdlib
  131. ".*", // platform
  132. "real_concept", // test type(s)
  133. ".*", // test data group
  134. ".*", 600, 200); // test function
  135. add_expected_result(
  136. ".*", // compiler
  137. ".*", // stdlib
  138. ".*", // platform
  139. "double", // test type(s)
  140. ".*", // test data group
  141. ".*", 2, 1); // test function
  142. //
  143. // Finish off by printing out the compiler/stdlib/platform names,
  144. // we do this to make it easier to mark up expected error rates.
  145. //
  146. std::cout << "Tests run with " << BOOST_COMPILER << ", "
  147. << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
  148. }
  149. BOOST_AUTO_TEST_CASE( test_main )
  150. {
  151. #ifdef TEST_GSL
  152. gsl_set_error_handler_off();
  153. #endif
  154. expected_results();
  155. BOOST_MATH_CONTROL_FP;
  156. #ifndef BOOST_MATH_BUGGY_LARGE_FLOAT_CONSTANTS
  157. test_bessel(0.1F, "float");
  158. #endif
  159. test_bessel(0.1, "double");
  160. #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
  161. test_bessel(0.1L, "long double");
  162. #ifndef BOOST_MATH_NO_REAL_CONCEPT_TESTS
  163. test_bessel(boost::math::concepts::real_concept(0.1), "real_concept");
  164. #endif
  165. #else
  166. std::cout << "<note>The long double tests have been disabled on this platform "
  167. "either because the long double overloads of the usual math functions are "
  168. "not available at all, or because they are too inaccurate for these tests "
  169. "to pass.</note>" << std::endl;
  170. #endif
  171. }