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