1 ///////////////////////////////////////////////////////////////
2 // Copyright 2011 John Maddock. Distributed under the Boost
3 // Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
6 #define BOOST_MATH_MAX_ROOT_ITERATION_POLICY 750
7 #define BOOST_MATH_PROMOTE_DOUBLE_POLICY false
9 #if !defined(TEST_MPFR) && !defined(TEST_MPREAL) && !defined(TEST_MPF) && !defined(TEST_MPREAL) && !defined(TEST_CPP_DEC_FLOAT) && !defined(TEST_MPFR_CLASS) && !defined(TEST_FLOAT) && !defined(TEST_CPP_BIN_FLOAT)
12 #define TEST_CPP_DEC_FLOAT
13 #define TEST_CPP_BIN_FLOAT
14 //# define TEST_MPFR_CLASS
15 //# define TEST_MPREAL
20 #include "arithmetic_backend.hpp"
22 #ifdef TEST_MPFR_CLASS
23 #include <boost/math/bindings/mpfr.hpp>
26 #include <boost/multiprecision/mpfr.hpp>
29 #include <boost/math/bindings/mpreal.hpp>
32 #include <boost/multiprecision/gmp.hpp>
34 #ifdef TEST_CPP_DEC_FLOAT
35 #include <boost/multiprecision/cpp_dec_float.hpp>
37 #ifdef TEST_CPP_BIN_FLOAT
38 #include <boost/multiprecision/cpp_bin_float.hpp>
39 #include <boost/multiprecision/mpfr.hpp>
41 #include <boost/math/special_functions/bessel.hpp>
42 #include <boost/math/tools/rational.hpp>
43 #include <boost/math/distributions/non_central_t.hpp>
44 #include <libs/math/test/table_type.hpp>
45 #include <boost/chrono.hpp>
46 #include <boost/array.hpp>
47 #include <boost/thread.hpp>
52 template <class Clock>
55 typedef typename Clock::duration duration;
58 m_start = Clock::now();
62 return Clock::now() - m_start;
66 m_start = Clock::now();
70 typename Clock::time_point m_start;
80 #include "libs/math/test/bessel_i_int_data.ipp"
81 #include "libs/math/test/bessel_i_data.ipp"
85 for (unsigned i = 0; i < bessel_i_int_data.size(); ++i)
87 r += boost::math::cyl_bessel_i(Real(bessel_i_int_data[i][0]), Real(bessel_i_int_data[i][1]));
89 for (unsigned i = 0; i < bessel_i_data.size(); ++i)
91 r += boost::math::cyl_bessel_i(Real(bessel_i_data[i][0]), Real(bessel_i_data[i][1]));
94 #include "libs/math/test/bessel_j_int_data.ipp"
95 for (unsigned i = 0; i < bessel_j_int_data.size(); ++i)
97 r += boost::math::cyl_bessel_j(Real(bessel_j_int_data[i][0]), Real(bessel_j_int_data[i][1]));
100 #include "libs/math/test/bessel_j_data.ipp"
101 for (unsigned i = 0; i < bessel_j_data.size(); ++i)
103 r += boost::math::cyl_bessel_j(Real(bessel_j_data[i][0]), Real(bessel_j_data[i][1]));
106 #include "libs/math/test/bessel_j_large_data.ipp"
107 for (unsigned i = 0; i < bessel_j_large_data.size(); ++i)
109 r += boost::math::cyl_bessel_j(Real(bessel_j_large_data[i][0]), Real(bessel_j_large_data[i][1]));
112 #include "libs/math/test/sph_bessel_data.ipp"
113 for (unsigned i = 0; i < sph_bessel_data.size(); ++i)
115 r += boost::math::sph_bessel(static_cast<unsigned>(sph_bessel_data[i][0]), Real(sph_bessel_data[i][1]));
120 catch (const std::exception& e)
122 std::cout << e.what() << std::endl;
127 template <class Real>
128 Real test_polynomial()
130 static const unsigned t[] = {
131 2, 3, 4, 5, 6, 7, 8};
133 for (Real k = 2; k < 1000; ++k)
134 result += boost::math::tools::evaluate_polynomial(t, k);
139 template <class Real>
143 #include "libs/math/test/nct.ipp"
146 for (unsigned i = 0; i < nct.size(); ++i)
150 result += quantile(boost::math::non_central_t_distribution<Real>(nct[i][0], nct[i][1]), nct[i][3]);
151 result += cdf(boost::math::non_central_t_distribution<Real>(nct[i][0], nct[i][1]), nct[i][2]);
153 catch (const std::exception&)
159 extern unsigned allocation_count;
161 template <class Real>
162 void basic_allocation_test(const char* name, Real x)
164 static const unsigned a[] = {2, 3, 4, 5, 6, 7, 8};
165 allocation_count = 0;
166 Real result = (((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0];
167 std::cout << "Allocation count for type " << name << " = " << allocation_count << std::endl;
170 template <class Real>
171 void poly_allocation_test(const char* name, Real x)
173 static const unsigned a[] = {2, 3, 4, 5, 6, 7, 8};
174 allocation_count = 0;
175 Real result = boost::math::tools::evaluate_polynomial(a, x);
176 std::cout << "Allocation count for type " << name << " = " << allocation_count << std::endl;
179 template <class Real>
180 void time_proc(const char* name, Real (*proc)(), unsigned threads = 1)
184 static Real total = 0;
185 allocation_count = 0;
186 boost::chrono::duration<double> time;
187 stopwatch<boost::chrono::high_resolution_clock> c;
190 std::cout << "Time for " << name << " = " << time << std::endl;
191 std::cout << "Total allocations for " << name << " = " << allocation_count << std::endl;
193 for (unsigned thread_count = 1; thread_count < threads; ++thread_count)
196 boost::thread_group g;
197 for (unsigned i = 0; i <= thread_count; ++i)
198 g.create_thread(proc);
201 std::cout << "Time for " << name << " (" << (thread_count + 1) << " threads) = " << time << std::endl;
202 std::cout << "Total allocations for " << name << " = " << allocation_count << std::endl;
205 catch (const std::exception& e)
207 std::cout << e.what() << std::endl;
211 using namespace boost::multiprecision;