hyp_1f1_reg_big_data.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // (C) Copyright John Maddock 2006.
  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. #define BOOST_MATH_MAX_SERIES_ITERATION_POLICY 10000000
  6. #include <boost/math/special_functions/hypergeometric_1f1.hpp>
  7. #include <boost/math/special_functions/hypergeometric_pfq.hpp>
  8. #include <boost/math/constants/constants.hpp>
  9. #include <boost/lexical_cast.hpp>
  10. #include <fstream>
  11. #include <map>
  12. #include <boost/math/tools/test_data.hpp>
  13. #include <boost/random.hpp>
  14. #define BOOST_MATH_USE_MPFR
  15. #include "mp_t.hpp"
  16. #include <boost/multiprecision/mpfr.hpp>
  17. using namespace boost::math::tools;
  18. using namespace boost::math;
  19. using namespace std;
  20. using namespace boost::multiprecision;
  21. struct hypergeometric_1f1_gen
  22. {
  23. mp_t operator()(mp_t a1, mp_t a2, mp_t z)
  24. {
  25. mp_t result;
  26. try {
  27. result = (mp_t)boost::math::hypergeometric_pFq_precision({ mpfr_float(a1) }, { mpfr_float(mpfr_float(a2)) }, mpfr_float(z), 50, 25.0) / boost::multiprecision::tgamma(a2);
  28. std::cout << a1 << " " << a2 << " " << z << " " << result << std::endl;
  29. }
  30. catch (...)
  31. {
  32. throw std::domain_error("");
  33. }
  34. if (fabs(result) > (std::numeric_limits<double>::max)())
  35. {
  36. std::cout << "Rejecting over large value\n";
  37. throw std::domain_error("");
  38. }
  39. return result;
  40. }
  41. };
  42. int main(int, char* [])
  43. {
  44. parameter_info<mp_t> arg1, arg2, arg3;
  45. test_data<mp_t> data;
  46. std::cout << "Welcome.\n"
  47. "This program will generate spot tests for 1F1 (Yeh!!):\n";
  48. std::string line;
  49. //bool cont;
  50. std::vector<mp_t> v;
  51. random_ns::mt19937 rnd;
  52. random_ns::uniform_real_distribution<float> ur_a(0, 1);
  53. mp_t p = ur_a(rnd);
  54. p *= 1e6;
  55. v.push_back(p);
  56. v.push_back(-p);
  57. p = ur_a(rnd);
  58. p *= 1e5;
  59. v.push_back(p);
  60. v.push_back(-p);
  61. p = ur_a(rnd);
  62. p *= 1e4;
  63. v.push_back(p);
  64. v.push_back(-p);
  65. p = ur_a(rnd);
  66. p *= 1e3;
  67. v.push_back(p);
  68. v.push_back(-p);
  69. p = ur_a(rnd);
  70. p *= 1e2;
  71. v.push_back(p);
  72. v.push_back(-p);
  73. p = ur_a(rnd);
  74. p *= 1e-5;
  75. v.push_back(p);
  76. v.push_back(-p);
  77. p = ur_a(rnd);
  78. p *= 1e-12;
  79. v.push_back(p);
  80. v.push_back(-p);
  81. p = ur_a(rnd);
  82. p *= 1e-30;
  83. v.push_back(p);
  84. v.push_back(-p);
  85. for (unsigned i = 0; i < v.size(); ++i)
  86. {
  87. for (unsigned j = 0; j < v.size(); ++j)
  88. {
  89. for (unsigned k = 0; k < v.size(); ++k)
  90. {
  91. std::cout << i << " " << j << " " << k << std::endl;
  92. std::cout << v[i] << " " << (v[j] * 3) / 2 << " " << (v[j] * 5) / 4 << std::endl;
  93. arg1 = make_single_param(v[i]);
  94. arg2 = make_single_param(mp_t((v[j] * 3) / 2));
  95. arg3 = make_single_param(mp_t((v[k] * 5) / 4));
  96. data.insert(hypergeometric_1f1_gen(), arg1, arg2, arg3);
  97. }
  98. }
  99. }
  100. std::cout << "Enter name of test data file [default=hypergeometric_1f1.ipp]";
  101. std::getline(std::cin, line);
  102. boost::algorithm::trim(line);
  103. if(line == "")
  104. line = "hypergeometric_1f1.ipp";
  105. std::ofstream ofs(line.c_str());
  106. ofs << std::scientific << std::setprecision(40);
  107. write_code(ofs, data, line.c_str());
  108. return 0;
  109. }