test_in.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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>, 10> i0_data = { {
  18. { { SC_(0.0), SC_(0.0), SC_(1.0) } },
  19. { { SC_(0.0), SC_(1.0), SC_(1.26606587775200833559824462521471753760767031135496220680814) } },
  20. { { SC_(0.0), SC_(-2.0), SC_(2.27958530233606726743720444081153335328584110278545905407084) } },
  21. { { SC_(0.0), SC_(4.0), SC_(11.3019219521363304963562701832171024974126165944353377060065) } },
  22. { { SC_(0.0), SC_(-7.0), SC_(168.593908510289698857326627187500840376522679234531714193194) } },
  23. { { SC_(0.0), T(1) / 1024, SC_(1.00000023841859331241759166109699567801556273303717896447683) } },
  24. { { SC_(0.0), T(SC_(1.0)) / (1024 * 1024), SC_(1.00000000000022737367544324498417583090700894607432256476338) } },
  25. { { SC_(0.0), SC_(-1.0), SC_(1.26606587775200833559824462521471753760767031135496220680814) } },
  26. { { SC_(0.0), SC_(100.0), SC_(1.07375170713107382351972085760349466128840319332527279540154e42) } },
  27. { { SC_(0.0), SC_(200.0), SC_(2.03968717340972461954167312677945962233267573614834337894328e85) } },
  28. } };
  29. static const boost::array<boost::array<T, 3>, 10> i1_data = { {
  30. { { SC_(1.0), SC_(0.0), SC_(0.0) } },
  31. { { SC_(1.0), SC_(1.0), SC_(0.565159103992485027207696027609863307328899621621092009480294) } },
  32. { { SC_(1.0), SC_(-2.0), SC_(-1.59063685463732906338225442499966624795447815949553664713229) } },
  33. { { SC_(1.0), SC_(4.0), SC_(9.75946515370444990947519256731268090005597033325296730692753) } },
  34. { { SC_(1.0), SC_(-8.0), SC_(-399.873136782560098219083086145822754889628443904067647306574) } },
  35. { { SC_(1.0), T(SC_(1.0)) / 1024, SC_(0.000488281308207663226432087816784315537514225208473395063575150) } },
  36. { { SC_(1.0), T(SC_(1.0)) / (1024 * 1024), SC_(4.76837158203179210108624277276025646653133998635956784292029E-7) } },
  37. { { SC_(1.0), SC_(-10.0), SC_(-2670.98830370125465434103196677215254914574515378753771310849) } },
  38. { { SC_(1.0), SC_(100.0), SC_(1.06836939033816248120614576322429526544612284405623226965918e42) } },
  39. { { SC_(1.0), SC_(200.0), SC_(2.03458154933206270342742797713906950389661161681122964159220e85) } },
  40. } };
  41. static const boost::array<boost::array<T, 3>, 11> in_data = { {
  42. { { SC_(-2.0), SC_(0.0), SC_(0.0) } },
  43. { { SC_(2.0), T(SC_(1.0)) / (1024 * 1024), SC_(1.13686837721624646204093977095674566928522671779753217215467e-13) } },
  44. { { SC_(5.0), SC_(10.0), SC_(777.188286403259959907293484802339632852674154572666041953297) } },
  45. { { SC_(-5.0), SC_(100.0), SC_(9.47009387303558124618275555002161742321578485033007130107740e41) } },
  46. { { SC_(-5.0), SC_(-1.0), SC_(-0.000271463155956971875181073905153777342383564426758143634974124) } },
  47. { { SC_(10.0), SC_(20.0), SC_(3.54020020901952109905289138244985607057267103782948493874391e6) } },
  48. { { SC_(10.0), SC_(-5.0), SC_(0.00458004441917605126118647027872016953192323139337073320016447) } },
  49. { { SC_(1e+02), SC_(9.0), SC_(2.74306601746058997093587654668959071522869282506446891736820e-93) } },
  50. { { SC_(1e+02), SC_(80.0), SC_(4.65194832850610205318128191404145885093970505338730540776711e8) } },
  51. { { SC_(-100.0), SC_(-200.0), SC_(4.35275044972702191438729017441198257508190719030765213981307e74) } },
  52. { { SC_(10.0), SC_(1e-100), SC_(2.69114445546737213403880070546737213403880070546737213403880e-1010) } },
  53. } };
  54. int main()
  55. {
  56. #include "bessel_i_int_data.ipp"
  57. add_data(i0_data);
  58. add_data(i1_data);
  59. add_data(in_data);
  60. add_data(bessel_i_int_data);
  61. unsigned data_total = data.size();
  62. screen_data([](const std::vector<double>& v){ return boost::math::cyl_bessel_i(static_cast<int>(v[0]), v[1]); }, [](const std::vector<double>& v){ return v[2]; });
  63. #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
  64. screen_data([](const std::vector<double>& v){ return std::tr1::cyl_bessel_i(static_cast<int>(v[0]), v[1]); }, [](const std::vector<double>& v){ return v[2]; });
  65. #endif
  66. #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES)
  67. screen_data([](const std::vector<double>& v){ return gsl_sf_bessel_In(static_cast<int>(v[0]), v[1]); }, [](const std::vector<double>& v){ return v[2]; });
  68. #endif
  69. #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES)
  70. screen_data([](const std::vector<double>& v){ return bessel_i(v[1], static_cast<int>(v[0]), 1); }, [](const std::vector<double>& v){ return v[2]; });
  71. #endif
  72. unsigned data_used = data.size();
  73. std::string function = "cyl_bessel_i (integer order)[br](" + boost::lexical_cast<std::string>(data_used) + "/" + boost::lexical_cast<std::string>(data_total) + " tests selected)";
  74. std::string function_short = "cyl_bessel_i (integer order)";
  75. double time;
  76. time = exec_timed_test([](const std::vector<double>& v){ return boost::math::cyl_bessel_i(static_cast<int>(v[0]), v[1]); });
  77. std::cout << time << std::endl;
  78. #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_LIBSTDCXX))
  79. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name());
  80. #endif
  81. report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name());
  82. //
  83. // Boost again, but with promotion to long double turned off:
  84. //
  85. #if !defined(COMPILER_COMPARISON_TABLES)
  86. if(sizeof(long double) != sizeof(double))
  87. {
  88. time = exec_timed_test([](const std::vector<double>& v){ return boost::math::cyl_bessel_i(static_cast<int>(v[0]), v[1], boost::math::policies::make_policy(boost::math::policies::promote_double<false>())); });
  89. std::cout << time << std::endl;
  90. #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_LIBSTDCXX))
  91. 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>");
  92. #endif
  93. 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>");
  94. }
  95. #endif
  96. #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
  97. time = exec_timed_test([](const std::vector<double>& v){ return std::tr1::cyl_bessel_i(static_cast<int>(v[0]), v[1]); });
  98. std::cout << time << std::endl;
  99. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "tr1/cmath");
  100. #endif
  101. #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES)
  102. time = exec_timed_test([](const std::vector<double>& v){ return gsl_sf_bessel_In(static_cast<int>(v[0]), v[1]); });
  103. std::cout << time << std::endl;
  104. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "GSL " GSL_VERSION);
  105. #endif
  106. #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES)
  107. time = exec_timed_test([](const std::vector<double>& v){ return bessel_i(v[1], static_cast<int>(v[0]), 1); });
  108. std::cout << time << std::endl;
  109. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "Rmath " R_VERSION_STRING);
  110. #endif
  111. return 0;
  112. }