hyp_1f1_data.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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/constants/constants.hpp>
  8. #include <boost/lexical_cast.hpp>
  9. #include <fstream>
  10. #include <map>
  11. #include <boost/math/tools/test_data.hpp>
  12. #include <boost/random.hpp>
  13. #include "mp_t.hpp"
  14. using namespace boost::math::tools;
  15. using namespace boost::math;
  16. using namespace std;
  17. struct hypergeometric_1f1_gen
  18. {
  19. mp_t operator()(mp_t a1, mp_t a2, mp_t z)
  20. {
  21. std::cout << a1 << " " << a2 << " " << z << std::endl;
  22. mp_t result = boost::math::detail::hypergeometric_1f1_generic_series(a1, a2, z, boost::math::policies::policy<>());
  23. std::cout << a1 << " " << a2 << " " << z << " " << result << std::endl;
  24. return result;
  25. }
  26. };
  27. struct hypergeometric_1f1_gen_2
  28. {
  29. mp_t operator()(mp_t a1, mp_t a2, mp_t z)
  30. {
  31. mp_t result = boost::math::detail::hypergeometric_1f1_generic_series(a1, a2, z, boost::math::policies::policy<>());
  32. std::cout << a1 << " " << a2 << " " << z << " " << result << std::endl;
  33. if (fabs(result) > (std::numeric_limits<double>::max)())
  34. {
  35. std::cout << "Discarding result as too large\n";
  36. throw std::domain_error("");
  37. }
  38. if (static_cast<double>(result) == 1)
  39. {
  40. std::cout << "Discarding result as unity\n";
  41. throw std::domain_error(""); // uninteresting result.
  42. }
  43. return result;
  44. }
  45. };
  46. int main(int, char* [])
  47. {
  48. parameter_info<mp_t> arg1, arg2, arg3;
  49. test_data<mp_t> data;
  50. std::cout << "Welcome.\n"
  51. "This program will generate spot tests for 2F0:\n";
  52. std::string line;
  53. bool cont;
  54. #if 1
  55. std::vector<mp_t> v;
  56. random_ns::mt19937 rnd;
  57. random_ns::uniform_real_distribution<float> ur_a(0, 1);
  58. mp_t p = ur_a(rnd);
  59. p *= 1e6;
  60. v.push_back(p);
  61. v.push_back(-p);
  62. p = ur_a(rnd);
  63. p *= 1e5;
  64. v.push_back(p);
  65. v.push_back(-p);
  66. p = ur_a(rnd);
  67. p *= 1e4;
  68. v.push_back(p);
  69. v.push_back(-p);
  70. p = ur_a(rnd);
  71. p *= 1e3;
  72. v.push_back(p);
  73. v.push_back(-p);
  74. p = ur_a(rnd);
  75. p *= 1e2;
  76. v.push_back(p);
  77. v.push_back(-p);
  78. p = ur_a(rnd);
  79. p *= 1e-5;
  80. v.push_back(p);
  81. v.push_back(-p);
  82. p = ur_a(rnd);
  83. p *= 1e-12;
  84. v.push_back(p);
  85. v.push_back(-p);
  86. p = ur_a(rnd);
  87. p *= 1e-30;
  88. v.push_back(p);
  89. v.push_back(-p);
  90. for (unsigned i = 0; i < v.size(); ++i)
  91. {
  92. for (unsigned j = 0; j < v.size(); ++j)
  93. {
  94. for (unsigned k = 0; k < v.size(); ++k)
  95. {
  96. arg1 = make_single_param(v[i]);
  97. arg2 = make_single_param(v[j] * 3 / 2);
  98. arg3 = make_single_param(v[k] * 5 / 4);
  99. data.insert(hypergeometric_1f1_gen_2(), arg1, arg2, arg3);
  100. }
  101. }
  102. }
  103. #else
  104. do {
  105. get_user_parameter_info(arg1, "a1");
  106. get_user_parameter_info(arg2, "a2");
  107. get_user_parameter_info(arg3, "z");
  108. data.insert(hypergeometric_1f1_gen(), arg1, arg2, arg3);
  109. std::cout << "Any more data [y/n]?";
  110. std::getline(std::cin, line);
  111. boost::algorithm::trim(line);
  112. cont = (line == "y");
  113. } while (cont);
  114. #endif
  115. std::cout << "Enter name of test data file [default=hypergeometric_1f1.ipp]";
  116. std::getline(std::cin, line);
  117. boost::algorithm::trim(line);
  118. if(line == "")
  119. line = "hypergeometric_1f1.ipp";
  120. std::ofstream ofs(line.c_str());
  121. ofs << std::scientific << std::setprecision(40);
  122. write_code(ofs, data, line.c_str());
  123. return 0;
  124. }