test_kv.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #ifdef _MSC_VER
  6. # pragma warning (disable : 4224)
  7. #endif
  8. #include <boost/math/special_functions/bessel.hpp>
  9. #include <boost/array.hpp>
  10. #include <boost/lexical_cast.hpp>
  11. #include "../../test/table_type.hpp"
  12. #include "table_helper.hpp"
  13. #include "performance.hpp"
  14. #include <iostream>
  15. typedef double T;
  16. #define SC_(x) static_cast<double>(x)
  17. static const boost::array<boost::array<T, 3>, 11> kv_data = { {
  18. { { SC_(0.5), SC_(0.875), SC_(0.558532231646608646115729767013630967055657943463362504577189) } },
  19. { { SC_(0.5), SC_(1.125), SC_(0.383621010650189547146769320487006220295290256657827220786527) } },
  20. { { SC_(2.25), T(std::ldexp(1.0, -30)), SC_(5.62397392719283271332307799146649700147907612095185712015604e20) } },
  21. { { SC_(5.5), T(3217) / 1024, SC_(1.30623288775012596319554857587765179889689223531159532808379) } },
  22. { { SC_(-5.5), SC_(10.0), SC_(0.0000733045300798502164644836879577484533096239574909573072142667) } },
  23. { { SC_(-5.5), SC_(100.0), SC_(5.41274555306792267322084448693957747924412508020839543293369e-45) } },
  24. { { T(10240) / 1024, T(1) / 1024, SC_(2.35522579263922076203415803966825431039900000000993410734978e38) } },
  25. { { T(10240) / 1024, SC_(10.0), SC_(0.00161425530039067002345725193091329085443750382929208307802221) } },
  26. { { T(144793) / 1024, SC_(100.0), SC_(1.39565245860302528069481472855619216759142225046370312329416e-6) } },
  27. { { T(144793) / 1024, SC_(200.0), SC_(9.11950412043225432171915100042647230802198254567007382956336e-68) } },
  28. { { T(-144793) / 1024, SC_(50.0), SC_(1.30185229717525025165362673848737761549946548375142378172956e42) } },
  29. } };
  30. static const boost::array<boost::array<T, 3>, 5> kv_large_data = { {
  31. // Bug report https://svn.boost.org/trac/boost/ticket/5560:
  32. { { SC_(-1.0), static_cast<T>(ldexp(0.5, -512)), SC_(2.68156158598851941991480499964116922549587316411847867554471e154) } },
  33. { { SC_(1.0), static_cast<T>(ldexp(0.5, -512)), SC_(2.68156158598851941991480499964116922549587316411847867554471e154) } },
  34. { { SC_(-1.125), static_cast<T>(ldexp(0.5, -512)), SC_(5.53984048006472105611199242328122729730752165907526178753978e173) } },
  35. { { SC_(1.125), static_cast<T>(ldexp(0.5, -512)), SC_(5.53984048006472105611199242328122729730752165907526178753978e173) } },
  36. { { SC_(0.5), static_cast<T>(ldexp(0.5, -683)), SC_(1.12284149973980088540335945247019177715948513804063794284101e103) } },
  37. } };
  38. int main()
  39. {
  40. #include "bessel_k_data.ipp"
  41. add_data(kv_data);
  42. add_data(kv_large_data);
  43. add_data(bessel_k_data);
  44. unsigned data_total = data.size();
  45. std::cout << "Screening boost data:\n";
  46. screen_data([](const std::vector<double>& v){ return boost::math::cyl_bessel_k(v[0], v[1]); }, [](const std::vector<double>& v){ return v[2]; });
  47. #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
  48. std::cout << "Screening libstdc++ data:\n";
  49. screen_data([](const std::vector<double>& v){ return std::tr1::cyl_bessel_k(v[0], v[1]); }, [](const std::vector<double>& v){ return v[2]; });
  50. #endif
  51. #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES)
  52. std::cout << "Screening libstdc++ data:\n";
  53. screen_data([](const std::vector<double>& v){ return gsl_sf_bessel_Knu(v[0], v[1]); }, [](const std::vector<double>& v){ return v[2]; });
  54. #endif
  55. #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES)
  56. std::cout << "Screening libstdc++ data:\n";
  57. screen_data([](const std::vector<double>& v){ return bessel_k(v[1], v[0], 1); }, [](const std::vector<double>& v){ return v[2]; });
  58. #endif
  59. unsigned data_used = data.size();
  60. std::string function = "cyl_bessel_k[br](" + boost::lexical_cast<std::string>(data_used) + "/" + boost::lexical_cast<std::string>(data_total) + " tests selected)";
  61. std::string function_short = "cyl_bessel_k";
  62. double time;
  63. time = exec_timed_test([](const std::vector<double>& v){ return boost::math::cyl_bessel_k(v[0], v[1]); });
  64. std::cout << time << std::endl;
  65. #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_LIBSTDCXX))
  66. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name());
  67. #endif
  68. report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name());
  69. //
  70. // Boost again, but with promotion to long double turned off:
  71. //
  72. #if !defined(COMPILER_COMPARISON_TABLES)
  73. if(sizeof(long double) != sizeof(double))
  74. {
  75. time = exec_timed_test([](const std::vector<double>& v){ return boost::math::cyl_bessel_k(v[0], v[1], boost::math::policies::make_policy(boost::math::policies::promote_double<false>())); });
  76. std::cout << time << std::endl;
  77. #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_LIBSTDCXX))
  78. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name() + "[br]promote_double<false>");
  79. #endif
  80. report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name() + "[br]promote_double<false>");
  81. }
  82. #endif
  83. #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
  84. time = exec_timed_test([](const std::vector<double>& v){ return std::tr1::cyl_bessel_k(v[0], v[1]); });
  85. std::cout << time << std::endl;
  86. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "tr1/cmath");
  87. #endif
  88. #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES)
  89. time = exec_timed_test([](const std::vector<double>& v){ return gsl_sf_bessel_Knu(v[0], v[1]); });
  90. std::cout << time << std::endl;
  91. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "GSL " GSL_VERSION);
  92. #endif
  93. #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES)
  94. time = exec_timed_test([](const std::vector<double>& v){ return bessel_k(v[1], v[0], 1); });
  95. std::cout << time << std::endl;
  96. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "Rmath " R_VERSION_STRING);
  97. #endif
  98. return 0;
  99. }