beta_data.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include <boost/math/special_functions/gamma.hpp>
  6. #include <boost/math/constants/constants.hpp>
  7. #include <boost/math/tools/test_data.hpp>
  8. #include <fstream>
  9. #include "mp_t.hpp"
  10. using namespace boost::math::tools;
  11. struct beta_data_generator
  12. {
  13. mp_t operator()(mp_t a, mp_t b)
  14. {
  15. if(a < b)
  16. throw std::domain_error("");
  17. // very naively calculate spots:
  18. mp_t g1, g2, g3;
  19. int s1, s2, s3;
  20. g1 = boost::math::lgamma(a, &s1);
  21. g2 = boost::math::lgamma(b, &s2);
  22. g3 = boost::math::lgamma(a+b, &s3);
  23. g1 += g2 - g3;
  24. g1 = exp(g1);
  25. g1 *= s1 * s2 * s3;
  26. return g1;
  27. }
  28. };
  29. int main()
  30. {
  31. parameter_info<mp_t> arg1, arg2;
  32. test_data<mp_t> data;
  33. std::cout << "Welcome.\n"
  34. "This program will generate spot tests for the beta function:\n"
  35. " beta(a, b)\n\n";
  36. bool cont;
  37. std::string line;
  38. do{
  39. get_user_parameter_info(arg1, "a");
  40. get_user_parameter_info(arg2, "b");
  41. data.insert(beta_data_generator(), arg1, arg2);
  42. std::cout << "Any more data [y/n]?";
  43. std::getline(std::cin, line);
  44. boost::algorithm::trim(line);
  45. cont = (line == "y");
  46. }while(cont);
  47. std::cout << "Enter name of test data file [default=beta_data.ipp]";
  48. std::getline(std::cin, line);
  49. boost::algorithm::trim(line);
  50. if(line == "")
  51. line = "beta_data.ipp";
  52. std::ofstream ofs(line.c_str());
  53. ofs << std::scientific << std::setprecision(40);
  54. write_code(ofs, data, "beta_data");
  55. return 0;
  56. }