test_yn.cpp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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<typename table_type<T>::type, 3>, 9> y0_data = { {
  18. { { SC_(0.0), SC_(1.0), SC_(0.0882569642156769579829267660235151628278175230906755467110438) } },
  19. { { SC_(0.0), SC_(2.0), SC_(0.510375672649745119596606592727157873268139227085846135571839) } },
  20. { { SC_(0.0), SC_(4.0), SC_(-0.0169407393250649919036351344471532182404925898980149027169321) } },
  21. { { SC_(0.0), SC_(8.0), SC_(0.223521489387566220527323400498620359274814930781423577578334) } },
  22. { { SC_(0.0), SC_(1e-05), SC_(-7.40316028370197013259676050746759072070960287586102867247159) } },
  23. { { SC_(0.0), SC_(1e-10), SC_(-14.7325162726972420426916696426209144888762342592762415255386) } },
  24. { { SC_(0.0), SC_(1e-20), SC_(-29.3912282502857968601858410375186700783698345615477536431464) } },
  25. { { SC_(0.0), SC_(1e+03), SC_(0.00471591797762281339977326146566525500985900489680197718528000) } },
  26. { { SC_(0.0), SC_(1e+05), SC_(0.00184676615886506410434074102431546125884886798090392516843524) } }
  27. } };
  28. static const boost::array<boost::array<typename table_type<T>::type, 3>, 9> y1_data = { {
  29. { { SC_(1.0), SC_(1.0), SC_(-0.781212821300288716547150000047964820549906390716444607843833) } },
  30. { { SC_(1.0), SC_(2.0), SC_(-0.107032431540937546888370772277476636687480898235053860525795) } },
  31. { { SC_(1.0), SC_(4.0), SC_(0.397925710557100005253979972450791852271189181622908340876586) } },
  32. { { SC_(1.0), SC_(8.0), SC_(-0.158060461731247494255555266187483550327344049526705737651263) } },
  33. { { SC_(1.0), SC_(1e-10), SC_(-6.36619772367581343150789184284462611709080831190542841855708e9) } },
  34. { { SC_(1.0), SC_(1e-20), SC_(-6.36619772367581343075535053490057448139324059868649274367256e19) } },
  35. { { SC_(1.0), SC_(1e+01), SC_(0.249015424206953883923283474663222803260416543069658461246944) } },
  36. { { SC_(1.0), SC_(1e+03), SC_(-0.0247843312923517789148623560971412909386318548648705287583490) } },
  37. { { SC_(1.0), SC_(1e+05), SC_(0.00171921035008825630099494523539897102954509504993494957572726) } }
  38. } };
  39. static const boost::array<boost::array<typename table_type<T>::type, 3>, 10> yn_data = { {
  40. { { SC_(2.0), SC_(1e-20), SC_(-1.27323954473516268615107010698011489627570899691226996904849e40) } },
  41. { { SC_(5.0), SC_(10.0), SC_(0.135403047689362303197029014762241709088405766746419538495983) } },
  42. { { SC_(-5.0), SC_(1e+06), SC_(0.000331052088322609048503535570014688967096938338061796192422114) } },
  43. { { SC_(10.0), SC_(10.0), SC_(-0.359814152183402722051986577343560609358382147846904467526222) } },
  44. { { SC_(10.0), SC_(1e-10), SC_(-1.18280490494334933900960937719565669877576135140014365217993e108) } },
  45. { { SC_(-10.0), SC_(1e+06), SC_(0.000725951969295187086245251366365393653610914686201194434805730) } },
  46. { { SC_(1e+02), SC_(5.0), SC_(-5.08486391602022287993091563093082035595081274976837280338134e115) } },
  47. { { SC_(1e+03), SC_(1e+05), SC_(0.00217254919137684037092834146629212647764581965821326561261181) } },
  48. { { SC_(-1e+03), SC_(7e+02), SC_(-1.88753109980945889960843803284345261796244752396992106755091e77) } },
  49. { { SC_(-25.0), SC_(8.0), SC_(3.45113613777297661997458045843868931827873456761831907587263e8) } }
  50. } };
  51. int main()
  52. {
  53. #include "bessel_y01_data.ipp"
  54. #include "bessel_yn_data.ipp"
  55. add_data(y0_data);
  56. add_data(y1_data);
  57. add_data(yn_data);
  58. add_data(bessel_y01_data);
  59. add_data(bessel_yn_data);
  60. unsigned data_total = data.size();
  61. screen_data([](const std::vector<double>& v){ return boost::math::cyl_neumann(static_cast<int>(v[0]), v[1]); }, [](const std::vector<double>& v){ return v[2]; });
  62. #if defined(TEST_C99) && !defined(COMPILER_COMPARISON_TABLES)
  63. screen_data([](const std::vector<double>& v){ return ::yn(static_cast<int>(v[0]), v[1]); }, [](const std::vector<double>& v){ return v[2]; });
  64. #endif
  65. #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
  66. screen_data([](const std::vector<double>& v){ return std::tr1::cyl_neumann(static_cast<int>(v[0]), v[1]); }, [](const std::vector<double>& v){ return v[2]; });
  67. #endif
  68. #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES)
  69. screen_data([](const std::vector<double>& v){ return gsl_sf_bessel_Yn(static_cast<int>(v[0]), v[1]); }, [](const std::vector<double>& v){ return v[2]; });
  70. #endif
  71. #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES)
  72. screen_data([](const std::vector<double>& v){ return bessel_y(v[1], static_cast<int>(v[0])); }, [](const std::vector<double>& v){ return v[2]; });
  73. #endif
  74. unsigned data_used = data.size();
  75. std::string function = "cyl_neumann (integer order)[br](" + boost::lexical_cast<std::string>(data_used) + "/" + boost::lexical_cast<std::string>(data_total) + " tests selected)";
  76. std::string function_short = "cyl_neumann (integer order)";
  77. double time;
  78. time = exec_timed_test([](const std::vector<double>& v){ return boost::math::cyl_neumann(static_cast<int>(v[0]), v[1]); });
  79. std::cout << time << std::endl;
  80. #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_C99) || defined(TEST_LIBSTDCXX))
  81. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name());
  82. #endif
  83. report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name());
  84. //
  85. // Boost again, but with promotion to long double turned off:
  86. //
  87. #if !defined(COMPILER_COMPARISON_TABLES)
  88. if(sizeof(long double) != sizeof(double))
  89. {
  90. time = exec_timed_test([](const std::vector<double>& v){ return boost::math::cyl_neumann(static_cast<int>(v[0]), v[1], boost::math::policies::make_policy(boost::math::policies::promote_double<false>())); });
  91. std::cout << time << std::endl;
  92. #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_C99) || defined(TEST_LIBSTDCXX))
  93. 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>");
  94. #endif
  95. 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>");
  96. }
  97. #endif
  98. #if defined(TEST_C99) && !defined(COMPILER_COMPARISON_TABLES)
  99. time = exec_timed_test([](const std::vector<double>& v){ return ::yn(static_cast<int>(v[0]), v[1]); });
  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, "math.h");
  102. #endif
  103. #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
  104. time = exec_timed_test([](const std::vector<double>& v){ return std::tr1::cyl_neumann(static_cast<int>(v[0]), v[1]); });
  105. std::cout << time << std::endl;
  106. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "tr1/cmath");
  107. #endif
  108. #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES)
  109. time = exec_timed_test([](const std::vector<double>& v){ return gsl_sf_bessel_Yn(static_cast<int>(v[0]), v[1]); });
  110. std::cout << time << std::endl;
  111. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "GSL " GSL_VERSION);
  112. #endif
  113. #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES)
  114. time = exec_timed_test([](const std::vector<double>& v){ return bessel_y(v[1], static_cast<int>(v[0])); });
  115. std::cout << time << std::endl;
  116. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "Rmath " R_VERSION_STRING);
  117. #endif
  118. return 0;
  119. }