test_jv.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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>, 21> jv_data = { {
  18. //SC_(-2.4), {{ SC_(0.0), std::numeric_limits<T>::infinity() }},
  19. { { T(22.5), T(0.0), SC_(0.0) } },
  20. { { T(2457.0) / 1024, T(1.0) / 1024, SC_(3.80739920118603335646474073457326714709615200130620574875292e-9) } },
  21. { { SC_(5.5), T(3217) / 1024, SC_(0.0281933076257506091621579544064767140470089107926550720453038) } },
  22. { { SC_(-5.5), T(3217) / 1024, SC_(-2.55820064470647911823175836997490971806135336759164272675969) } },
  23. { { SC_(-5.5), SC_(1e+04), SC_(2.449843111985605522111159013846599118397e-03) } },
  24. { { SC_(5.5), SC_(1e+04), SC_(0.00759343502722670361395585198154817047185480147294665270646578) } },
  25. { { SC_(5.5), SC_(1e+06), SC_(-0.000747424248595630177396350688505919533097973148718960064663632) } },
  26. { { SC_(5.125), SC_(1e+06), SC_(-0.000776600124835704280633640911329691642748783663198207360238214) } },
  27. { { SC_(5.875), SC_(1e+06), SC_(-0.000466322721115193071631008581529503095819705088484386434589780) } },
  28. { { SC_(0.5), SC_(101.0), SC_(0.0358874487875643822020496677692429287863419555699447066226409) } },
  29. { { SC_(-5.5), SC_(1e+04), SC_(0.00244984311198560552211115901384659911839737686676766460822577) } },
  30. { { SC_(-5.5), SC_(1e+06), SC_(0.000279243200433579511095229508894156656558211060453622750659554) } },
  31. { { SC_(-0.5), SC_(101.0), SC_(0.0708184798097594268482290389188138201440114881159344944791454) } },
  32. { { T(-10486074) / (1024 * 1024), T(1) / 1024, SC_(1.41474013160494695750009004222225969090304185981836460288562e35) } },
  33. { { T(-10486074) / (1024 * 1024), SC_(15.0), SC_(-0.0902239288885423309568944543848111461724911781719692852541489) } },
  34. { { T(10486074) / (1024 * 1024), SC_(1e+02), SC_(-0.0547064914615137807616774867984047583596945624129838091326863) } },
  35. { { T(10486074) / (1024 * 1024), SC_(2e+04), SC_(-0.00556783614400875611650958980796060611309029233226596737701688) } },
  36. { { T(-10486074) / (1024 * 1024), SC_(1e+02), SC_(-0.0547613660316806551338637153942604550779513947674222863858713) } },
  37. // Bug report https://svn.boost.org/trac/boost/ticket/4812:
  38. { { SC_(1.5), T(8034) / 1024, SC_(0.0339477646369710610146236955872928005087352629422508823945264) } },
  39. { { SC_(8.5), boost::math::constants::pi<T>() * 4, SC_(0.0436807946352780974532519564114026730332781693877984686758680) } },
  40. { { SC_(-8.5), boost::math::constants::pi<T>() * 4, SC_(-0.257086543428224355151772807588810984369026142375675714560864) } },
  41. } };
  42. int main()
  43. {
  44. #include "bessel_j_data.ipp"
  45. #include "bessel_j_large_data.ipp"
  46. add_data(jv_data);
  47. add_data(bessel_j_data);
  48. add_data(bessel_j_large_data);
  49. unsigned data_total = data.size();
  50. std::cout << "Screening boost data:\n";
  51. screen_data([](const std::vector<double>& v){ return boost::math::cyl_bessel_j(v[0], v[1]); }, [](const std::vector<double>& v){ return v[2]; });
  52. #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
  53. std::cout << "Screening libstdc++ data:\n";
  54. screen_data([](const std::vector<double>& v){ return std::tr1::cyl_bessel_j(v[0], v[1]); }, [](const std::vector<double>& v){ return v[2]; });
  55. #endif
  56. #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES)
  57. std::cout << "Screening libstdc++ data:\n";
  58. screen_data([](const std::vector<double>& v){ return gsl_sf_bessel_Jnu(v[0], v[1]); }, [](const std::vector<double>& v){ return v[2]; });
  59. #endif
  60. #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES)
  61. std::cout << "Screening libstdc++ data:\n";
  62. screen_data([](const std::vector<double>& v){ return bessel_j(v[1], v[0]); }, [](const std::vector<double>& v){ return v[2]; });
  63. #endif
  64. unsigned data_used = data.size();
  65. std::string function = "cyl_bessel_j[br](" + boost::lexical_cast<std::string>(data_used) + "/" + boost::lexical_cast<std::string>(data_total) + " tests selected)";
  66. std::string function_short = "cyl_bessel_j";
  67. double time;
  68. time = exec_timed_test([](const std::vector<double>& v){ return boost::math::cyl_bessel_j(v[0], v[1]); });
  69. std::cout << time << std::endl;
  70. #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_LIBSTDCXX))
  71. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name());
  72. #endif
  73. report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name());
  74. //
  75. // Boost again, but with promotion to long double turned off:
  76. //
  77. #if !defined(COMPILER_COMPARISON_TABLES)
  78. if(sizeof(long double) != sizeof(double))
  79. {
  80. time = exec_timed_test([](const std::vector<double>& v){ return boost::math::cyl_bessel_j(v[0], v[1], boost::math::policies::make_policy(boost::math::policies::promote_double<false>())); });
  81. std::cout << time << std::endl;
  82. #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_LIBSTDCXX))
  83. 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>");
  84. #endif
  85. 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>");
  86. }
  87. #endif
  88. #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
  89. time = exec_timed_test([](const std::vector<double>& v){ return std::tr1::cyl_bessel_j(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, "tr1/cmath");
  92. #endif
  93. #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES)
  94. time = exec_timed_test([](const std::vector<double>& v){ return gsl_sf_bessel_Jnu(v[0], v[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, "GSL " GSL_VERSION);
  97. #endif
  98. #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES)
  99. time = exec_timed_test([](const std::vector<double>& v){ return bessel_j(v[1], v[0]); });
  100. std::cout << time << std::endl;
  101. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "Rmath " R_VERSION_STRING);
  102. #endif
  103. return 0;
  104. }