test_iv.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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> iv_data = { {
  18. { { SC_(2.25), T(1) / (1024 * 1024), SC_(2.34379212133481347189068464680335815256364262507955635911656e-15) } },
  19. { { SC_(5.5), SC_(3.125), SC_(0.0583514045989371500460946536220735787163510569634133670181210) } },
  20. { { T(-5) + T(1) / 1024, SC_(2.125), SC_(0.0267920938009571023702933210070984416052633027166975342895062) } },
  21. { { SC_(-5.5), SC_(10.0), SC_(597.577606961369169607937419869926705730305175364662688426534) } },
  22. { { SC_(-5.5), SC_(100.0), SC_(9.22362906144706871737354069133813819358704200689067071415379e41) } },
  23. { { T(-10486074) / (1024 * 1024), T(1) / 1024, SC_(1.41474005665181350367684623930576333542989766867888186478185e35) } },
  24. { { T(-10486074) / (1024 * 1024), SC_(50.0), SC_(1.07153277202900671531087024688681954238311679648319534644743e20) } },
  25. { { T(144794) / 1024, SC_(100.0), SC_(2066.27694757392660413922181531984160871678224178890247540320) } },
  26. { { T(144794) / 1024, SC_(200.0), SC_(2.23699739472246928794922868978337381373643889659337595319774e64) } },
  27. { { T(-144794) / 1024, SC_(100.0), SC_(2066.27694672763190927440969155740243346136463461655104698748) } },
  28. } };
  29. static const boost::array<boost::array<T, 3>, 5> iv_large_data = { {
  30. // Bug report https://svn.boost.org/trac/boost/ticket/5560:
  31. { { SC_(-1.0), static_cast<T>(ldexp(0.5, -512)), SC_(1.86458518280005168582274132886573345934411788365010172356788e-155) } },
  32. { { SC_(1.0), static_cast<T>(ldexp(0.5, -512)), SC_(1.86458518280005168582274132886573345934411788365010172356788e-155) } },
  33. { { SC_(-1.125), static_cast<T>(ldexp(0.5, -512)), SC_(-1.34963720853101363690381585556234820027343435206156667634081e173) } },
  34. { { SC_(1.125), static_cast<T>(ldexp(0.5, -512)), SC_(8.02269390325932403421158766283366891170783955777638875887348e-175) } },
  35. { { SC_(0.5), static_cast<T>(ldexp(0.5, -683)), SC_(8.90597649117647254543282704099383321071493400182381039079219e-104) } },
  36. } };
  37. int main()
  38. {
  39. #include "bessel_i_data.ipp"
  40. add_data(iv_data);
  41. add_data(iv_large_data);
  42. add_data(bessel_i_data);
  43. unsigned data_total = data.size();
  44. std::cout << "Screening boost data:\n";
  45. screen_data([](const std::vector<double>& v){ return boost::math::cyl_bessel_i(v[0], v[1]); }, [](const std::vector<double>& v){ return v[2]; });
  46. #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
  47. std::cout << "Screening libstdc++ data:\n";
  48. screen_data([](const std::vector<double>& v){ return std::tr1::cyl_bessel_i(v[0], v[1]); }, [](const std::vector<double>& v){ return v[2]; });
  49. #endif
  50. #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES)
  51. std::cout << "Screening GSL data:\n";
  52. screen_data([](const std::vector<double>& v){ return gsl_sf_bessel_Inu(v[0], v[1]); }, [](const std::vector<double>& v){ return v[2]; });
  53. #endif
  54. #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES)
  55. std::cout << "Screening GSL data:\n";
  56. screen_data([](const std::vector<double>& v){ return bessel_i(v[1], v[0], 1); }, [](const std::vector<double>& v){ return v[2]; });
  57. #endif
  58. unsigned data_used = data.size();
  59. std::string function = "cyl_bessel_i[br](" + boost::lexical_cast<std::string>(data_used) + "/" + boost::lexical_cast<std::string>(data_total) + " tests selected)";
  60. std::string function_short = "cyl_bessel_i";
  61. double time;
  62. time = exec_timed_test([](const std::vector<double>& v){ return boost::math::cyl_bessel_i(v[0], v[1]); });
  63. std::cout << time << std::endl;
  64. #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_LIBSTDCXX))
  65. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name());
  66. #endif
  67. report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name());
  68. //
  69. // Boost again, but with promotion to long double turned off:
  70. //
  71. #if !defined(COMPILER_COMPARISON_TABLES)
  72. if(sizeof(long double) != sizeof(double))
  73. {
  74. time = exec_timed_test([](const std::vector<double>& v){ return boost::math::cyl_bessel_i(v[0], v[1], boost::math::policies::make_policy(boost::math::policies::promote_double<false>())); });
  75. std::cout << time << std::endl;
  76. #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_LIBSTDCXX))
  77. 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>");
  78. #endif
  79. 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>");
  80. }
  81. #endif
  82. #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
  83. time = exec_timed_test([](const std::vector<double>& v){ return std::tr1::cyl_bessel_i(v[0], v[1]); });
  84. std::cout << time << std::endl;
  85. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "tr1/cmath");
  86. #endif
  87. #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES)
  88. time = exec_timed_test([](const std::vector<double>& v){ return gsl_sf_bessel_Inu(v[0], v[1]); });
  89. std::cout << time << std::endl;
  90. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "GSL " GSL_VERSION);
  91. #endif
  92. #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES)
  93. time = exec_timed_test([](const std::vector<double>& v){ return bessel_i(v[1], v[0], 1); });
  94. std::cout << time << std::endl;
  95. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "Rmath " R_VERSION_STRING);
  96. #endif
  97. return 0;
  98. }