test_ellint_1.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/ellint_1.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>, 19> data1 = { {
  18. { { SC_(0.0), SC_(0.0), SC_(0.0) } },
  19. { { SC_(-10.0), SC_(0.0), SC_(-10.0) } },
  20. { { SC_(-1.0), SC_(-1.0), SC_(-1.2261911708835170708130609674719067527242483502207) } },
  21. { { SC_(-4.0), SC_(0.875), SC_(-5.3190556182262405182189463092940736859067548232647) } },
  22. { { SC_(8.0), SC_(-0.625), SC_(9.0419973860310100524448893214394562615252527557062) } },
  23. { { SC_(1e-05), SC_(0.875), SC_(0.000010000000000127604166668510945638036143355898993088) } },
  24. { { SC_(1e+05), T(10) / 1024, SC_(100002.38431454899771096037307519328741455615271038) } },
  25. { { SC_(1e-20), SC_(1.0), SC_(1.0000000000000000000000000000000000000000166666667e-20) } },
  26. { { SC_(1e-20), SC_(1e-20), SC_(1.000000000000000e-20) } },
  27. { { SC_(1e+20), T(400) / 1024, SC_(1.0418143796499216839719289963154558027005142709763e20) } },
  28. { { SC_(1e+50), SC_(0.875), SC_(1.3913251718238765549409892714295358043696028445944e50) } },
  29. { { SC_(2.0), SC_(0.5), SC_(2.1765877052210673672479877957388515321497888026770) } },
  30. { { SC_(4.0), SC_(0.5), SC_(4.2543274975235836861894752787874633017836785640477) } },
  31. { { SC_(6.0), SC_(0.5), SC_(6.4588766202317746302999080620490579800463614807916) } },
  32. { { SC_(10.0), SC_(0.5), SC_(10.697409951222544858346795279378531495869386960090) } },
  33. { { SC_(-2.0), SC_(0.5), SC_(-2.1765877052210673672479877957388515321497888026770) } },
  34. { { SC_(-4.0), SC_(0.5), SC_(-4.2543274975235836861894752787874633017836785640477) } },
  35. { { SC_(-6.0), SC_(0.5), SC_(-6.4588766202317746302999080620490579800463614807916) } },
  36. { { SC_(-10.0), SC_(0.5), SC_(-10.697409951222544858346795279378531495869386960090) } },
  37. } };
  38. int main()
  39. {
  40. #include "ellint_f_data.ipp"
  41. add_data(data1);
  42. add_data(ellint_f_data);
  43. unsigned data_total = data.size();
  44. screen_data([](const std::vector<double>& v){ return boost::math::ellint_1(v[1], v[0]); }, [](const std::vector<double>& v){ return v[2]; });
  45. #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
  46. screen_data([](const std::vector<double>& v){ return std::tr1::ellint_1(v[1], v[0]); }, [](const std::vector<double>& v){ return v[2]; });
  47. #endif
  48. #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES)
  49. screen_data([](const std::vector<double>& v){ return gsl_sf_ellint_F(v[0], v[1], GSL_PREC_DOUBLE); }, [](const std::vector<double>& v){ return v[2]; });
  50. #endif
  51. unsigned data_used = data.size();
  52. std::string function = "ellint_1[br](" + boost::lexical_cast<std::string>(data_used) + "/" + boost::lexical_cast<std::string>(data_total) + " tests selected)";
  53. std::string function_short = "ellint_1";
  54. double time;
  55. time = exec_timed_test([](const std::vector<double>& v){ return boost::math::ellint_1(v[1], v[0]); });
  56. std::cout << time << std::endl;
  57. #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_LIBSTDCXX))
  58. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name());
  59. #endif
  60. report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name());
  61. //
  62. // Boost again, but with promotion to long double turned off:
  63. //
  64. #if !defined(COMPILER_COMPARISON_TABLES)
  65. if(sizeof(long double) != sizeof(double))
  66. {
  67. time = exec_timed_test([](const std::vector<double>& v){ return boost::math::ellint_1(v[1], v[0], boost::math::policies::make_policy(boost::math::policies::promote_double<false>())); });
  68. std::cout << time << std::endl;
  69. #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_LIBSTDCXX))
  70. 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>");
  71. #endif
  72. 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>");
  73. }
  74. #endif
  75. #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
  76. time = exec_timed_test([](const std::vector<double>& v){ return std::tr1::ellint_1(v[1], v[0]); });
  77. std::cout << time << std::endl;
  78. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "tr1/cmath");
  79. #endif
  80. #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES)
  81. time = exec_timed_test([](const std::vector<double>& v){ return gsl_sf_ellint_F(v[0], v[1], GSL_PREC_DOUBLE); });
  82. std::cout << time << std::endl;
  83. report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "GSL " GSL_VERSION);
  84. #endif
  85. return 0;
  86. }