test_yv.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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> yv_data = { {
  18. //SC_(2.25), {{ SC_(1.0) / 1024, SC_(-1.01759203636941035147948317764932151601257765988969544340275e7) }},
  19. { { SC_(0.5), T(1) / (1024 * 1024), SC_(-817.033790261762580469303126467917092806755460418223776544122) } },
  20. { { SC_(5.5), SC_(3.125), SC_(-2.61489440328417468776474188539366752698192046890955453259866) } },
  21. { { SC_(-5.5), SC_(3.125), SC_(-0.0274994493896489729948109971802244976377957234563871795364056) } },
  22. { { SC_(-5.5), SC_(1e+04), SC_(-0.00759343502722670361395585198154817047185480147294665270646578) } },
  23. { { T(-10486074) / (1024 * 1024), T(1) / 1024, SC_(-1.50382374389531766117868938966858995093408410498915220070230e38) } },
  24. { { T(-10486074) / (1024 * 1024), SC_(1e+02), SC_(0.0583041891319026009955779707640455341990844522293730214223545) } },
  25. { { SC_(141.75), SC_(1e+02), SC_(-5.38829231428696507293191118661269920130838607482708483122068e9) } },
  26. { { SC_(141.75), SC_(2e+04), SC_(-0.00376577888677186194728129112270988602876597726657372330194186) } },
  27. { { SC_(-141.75), SC_(1e+02), SC_(-3.81009803444766877495905954105669819951653361036342457919021e9) } },
  28. { { SC_(8.5), boost::math::constants::pi<T>() * 4, SC_(0.257086543428224355151772807588810984369026142375675714560864) } },
  29. { { SC_(-8.5), boost::math::constants::pi<T>() * 4, SC_(0.0436807946352780974532519564114026730332781693877984686758680) } },
  30. } };
  31. static const boost::array<boost::array<T, 3>, 7> yv_large_data = { {
  32. // Bug report https://svn.boost.org/trac/boost/ticket/5560:
  33. { { SC_(0.5), static_cast<T>(std::ldexp(0.5, -683)), SC_(-7.14823099969225685526188875418476476336424046896822867989728e102) } },
  34. { { SC_(-0.5), static_cast<T>(std::ldexp(0.5, -683)), SC_(8.90597649117647254543282704099383321071493400182381039079219e-104) } },
  35. { { SC_(0.0), static_cast<T>(std::ldexp(1.0, -53)), SC_(-23.4611779112897561252987257324561640034037313549011724328997) } },
  36. { { SC_(1.0), static_cast<T>(std::ldexp(1.0, -53)), SC_(-5.73416113922265864550047623401604244038331542638719289100990e15) } },
  37. { { SC_(2.0), static_cast<T>(std::ldexp(1.0, -53)), SC_(-1.03297463879542177245046832533417970379386617249046560049244e32) } },
  38. { { SC_(3.0), static_cast<T>(std::ldexp(1.0, -53)), SC_(-3.72168335868978735639260528876490232745489151562358712422544e48) } },
  39. { { SC_(10.0), static_cast<T>(std::ldexp(1.0, -53)), SC_(-4.15729476804920974669173904282420477878640623992500096231384e167) } },
  40. } };
  41. int main()
  42. {
  43. #include "bessel_yv_data.ipp"
  44. add_data(yv_data);
  45. add_data(yv_large_data);
  46. add_data(bessel_yv_data);
  47. unsigned data_total = data.size();
  48. std::cout << "Screening boost data:\n";
  49. screen_data([](const std::vector<double>& v){ return boost::math::cyl_neumann(v[0], v[1]); }, [](const std::vector<double>& v){ return v[2]; });
  50. #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
  51. std::cout << "Screening libstdc++ data:\n";
  52. screen_data([](const std::vector<double>& v){ return std::tr1::cyl_neumann(v[0], v[1]); }, [](const std::vector<double>& v){ return v[2]; });
  53. #endif
  54. #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES)
  55. std::cout << "Screening GSL data:\n";
  56. screen_data([](const std::vector<double>& v){ return gsl_sf_bessel_Ynu(v[0], v[1]); }, [](const std::vector<double>& v){ return v[2]; });
  57. #endif
  58. #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES)
  59. std::cout << "Screening Rmath data:\n";
  60. screen_data([](const std::vector<double>& v){ return bessel_y(v[1], v[0]); }, [](const std::vector<double>& v){ return v[2]; });
  61. #endif
  62. unsigned data_used = data.size();
  63. std::string function = "cyl_neumann[br](" + boost::lexical_cast<std::string>(data_used) + "/" + boost::lexical_cast<std::string>(data_total) + " tests selected)";
  64. std::string function_short = "cyl_neumann";
  65. double time;
  66. time = exec_timed_test([](const std::vector<double>& v){ return boost::math::cyl_neumann(v[0], v[1]); });
  67. std::cout << time << std::endl;
  68. #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_LIBSTDCXX))
  69. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name());
  70. #endif
  71. report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name());
  72. //
  73. // Boost again, but with promotion to long double turned off:
  74. //
  75. #if !defined(COMPILER_COMPARISON_TABLES)
  76. if(sizeof(long double) != sizeof(double))
  77. {
  78. time = exec_timed_test([](const std::vector<double>& v){ return boost::math::cyl_neumann(v[0], v[1], boost::math::policies::make_policy(boost::math::policies::promote_double<false>())); });
  79. std::cout << time << std::endl;
  80. #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || 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() + "[br]promote_double<false>");
  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() + "[br]promote_double<false>");
  84. }
  85. #endif
  86. #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
  87. time = exec_timed_test([](const std::vector<double>& v){ return std::tr1::cyl_neumann(v[0], v[1]); });
  88. std::cout << time << std::endl;
  89. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "tr1/cmath");
  90. #endif
  91. #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES)
  92. time = exec_timed_test([](const std::vector<double>& v){ return gsl_sf_bessel_Ynu(v[0], v[1]); });
  93. std::cout << time << std::endl;
  94. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "GSL " GSL_VERSION);
  95. #endif
  96. #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES)
  97. time = exec_timed_test([](const std::vector<double>& v){ return bessel_y(v[1], v[0]); });
  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, "Rmath " R_VERSION_STRING);
  100. #endif
  101. return 0;
  102. }