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