]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/reporting/performance/test_jn.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / math / reporting / performance / test_jn.cpp
1 // Copyright John Maddock 2015.
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 #ifdef _MSC_VER
7 # pragma warning (disable : 4224)
8 #endif
9
10 #include <boost/math/special_functions/bessel.hpp>
11 #include <boost/array.hpp>
12 #include <boost/lexical_cast.hpp>
13 #include "../../test/table_type.hpp"
14 #include "table_helper.hpp"
15 #include "performance.hpp"
16 #include <iostream>
17
18 typedef double T;
19 #define SC_(x) static_cast<double>(x)
20 static const boost::array<boost::array<typename table_type<T>::type, 3>, 8> j0_data = { {
21 { { SC_(0.0), SC_(0.0), SC_(1.0) } },
22 { { SC_(0.0), SC_(1.0), SC_(0.7651976865579665514497175261026632209093) } },
23 { { SC_(0.0), SC_(-2.0), SC_(0.2238907791412356680518274546499486258252) } },
24 { { SC_(0.0), SC_(4.0), SC_(-0.3971498098638473722865907684516980419756) } },
25 { { SC_(0.0), SC_(-8.0), SC_(0.1716508071375539060908694078519720010684) } },
26 { { SC_(0.0), SC_(1e-05), SC_(0.999999999975000000000156249999999565972) } },
27 { { SC_(0.0), SC_(1e-10), SC_(0.999999999999999999997500000000000000000) } },
28 { { SC_(0.0), SC_(-1e+01), SC_(-0.2459357644513483351977608624853287538296) } },
29 } };
30 static const boost::array<boost::array<T, 3>, 6> j0_tricky = { {
31 // Big numbers make the accuracy of std::sin the limiting factor:
32 { { SC_(0.0), SC_(1e+03), SC_(0.02478668615242017456133073111569370878617) } },
33 { { SC_(0.0), SC_(1e+05), SC_(-0.001719201116235972192570601477073201747532) } },
34 // test at the roots:
35 { { SC_(0.0), T(2521642.0) / (1024 * 1024), SC_(1.80208819970046790002973759410972422387259992955354630042138e-7) } },
36 { { SC_(0.0), T(5788221.0) / (1024 * 1024), SC_(-1.37774249380686777043369399806210229535671843632174587432454e-7) } },
37 { { SC_(0.0), T(9074091.0) / (1024 * 1024), SC_(1.03553057441100845081018471279571355857520645127532785991335e-7) } },
38 { { SC_(0.0), T(12364320.0) / (1024 * 1024), SC_(-3.53017140778223781420794006033810387155048392363051866610931e-9) } }
39 } };
40
41 static const boost::array<boost::array<typename table_type<T>::type, 3>, 8> j1_data = { {
42 { { SC_(1.0), SC_(0.0), SC_(0.0) } },
43 { { SC_(1.0), SC_(1.0), SC_(0.4400505857449335159596822037189149131274) } },
44 { { SC_(1.0), SC_(-2.0), SC_(-0.5767248077568733872024482422691370869203) } },
45 { { SC_(1.0), SC_(4.0), SC_(-6.604332802354913614318542080327502872742e-02) } },
46 { { SC_(1.0), SC_(-8.0), SC_(-0.2346363468539146243812766515904546115488) } },
47 { { SC_(1.0), SC_(1e-05), SC_(4.999999999937500000000260416666666124132e-06) } },
48 { { SC_(1.0), SC_(1e-10), SC_(4.999999999999999999993750000000000000000e-11) } },
49 { { SC_(1.0), SC_(-1e+01), SC_(-4.347274616886143666974876802585928830627e-02) } },
50 } };
51 static const boost::array<boost::array<T, 3>, 5> j1_tricky = { {
52 // Big numbers make the accuracy of std::sin the limiting factor:
53 { { SC_(1.0), SC_(1e+03), SC_(4.728311907089523917576071901216916285418e-03) } },
54 { { SC_(1.0), SC_(1e+05), SC_(1.846757562882567716362123967114215743694e-03) } },
55 // test zeros:
56 { { SC_(1.0), T(4017834) / (1024 * 1024), SC_(3.53149033321258645807835062770856949751958513973522222203044e-7) } },
57 { { SC_(1.0), T(7356375) / (1024 * 1024), SC_(-2.31227973111067286051984021150135526024117175836722748404342e-7) } },
58 { { SC_(1.0), T(10667654) / (1024 * 1024), SC_(1.24591331097191900488116495350277530373473085499043086981229e-7) } },
59 } };
60
61 static const boost::array<boost::array<typename table_type<T>::type, 3>, 17> jn_data = { {
62 // This first one is a modified test case from https://svn.boost.org/trac/boost/ticket/2733
63 { { SC_(-1.0), SC_(1.25), SC_(-0.510623260319880467069474837274910375352924050139633057168856) } },
64 { { SC_(2.0), SC_(0.0), SC_(0.0) } },
65 { { SC_(-2.0), SC_(0.0), SC_(0.0) } },
66 { { SC_(2.0), SC_(1e-02), SC_(1.249989583365885362413250958437642113452e-05) } },
67 { { SC_(5.0), SC_(10.0), SC_(-0.2340615281867936404436949416457777864635) } },
68 { { SC_(5.0), SC_(-10.0), SC_(0.2340615281867936404436949416457777864635) } },
69 { { SC_(-5.0), SC_(1e+06), SC_(7.259643842453285052375779970433848914846e-04) } },
70 { { SC_(5.0), SC_(1e+06), SC_(-0.000725964384245328505237577997043384891484649290328285235308619) } },
71 { { SC_(-5.0), SC_(-1.0), SC_(2.497577302112344313750655409880451981584e-04) } },
72 { { SC_(10.0), SC_(10.0), SC_(0.2074861066333588576972787235187534280327) } },
73 { { SC_(10.0), SC_(-10.0), SC_(0.2074861066333588576972787235187534280327) } },
74 { { SC_(10.0), SC_(-5.0), SC_(1.467802647310474131107532232606627020895e-03) } },
75 { { SC_(-10.0), SC_(1e+06), SC_(-3.310793117604488741264958559035744460210e-04) } },
76 { { SC_(10.0), SC_(1e+06), SC_(-0.000331079311760448874126495855903574446020957243277028930713243) } },
77 { { SC_(1e+02), SC_(8e+01), SC_(4.606553064823477354141298259169874909670e-06) } },
78 { { SC_(1e+03), SC_(1e+05), SC_(1.283178112502480365195139312635384057363e-03) } },
79 { { SC_(10.0), SC_(1e-100), SC_(2.69114445546737213403880070546737213403880070546737213403880e-1010) } },
80 } };
81
82
83 int main()
84 {
85 #include "bessel_j_int_data.ipp"
86
87 add_data(j0_data);
88 add_data(j0_tricky);
89 add_data(j1_data);
90 add_data(j1_tricky);
91 add_data(jn_data);
92 add_data(bessel_j_int_data);
93
94 unsigned data_total = data.size();
95
96 screen_data([](const std::vector<double>& v){ return boost::math::cyl_bessel_j(static_cast<int>(v[0]), v[1]); }, [](const std::vector<double>& v){ return v[2]; });
97
98
99 #if defined(TEST_C99) && !defined(COMPILER_COMPARISON_TABLES)
100 screen_data([](const std::vector<double>& v){ return ::jn(static_cast<int>(v[0]), v[1]); }, [](const std::vector<double>& v){ return v[2]; });
101 #endif
102 #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
103 screen_data([](const std::vector<double>& v){ return std::tr1::cyl_bessel_j(static_cast<int>(v[0]), v[1]); }, [](const std::vector<double>& v){ return v[2]; });
104 #endif
105 #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES)
106 screen_data([](const std::vector<double>& v){ return gsl_sf_bessel_Jn(static_cast<int>(v[0]), v[1]); }, [](const std::vector<double>& v){ return v[2]; });
107 #endif
108 #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES)
109 screen_data([](const std::vector<double>& v){ return bessel_j(v[1], static_cast<int>(v[0])); }, [](const std::vector<double>& v){ return v[2]; });
110 #endif
111
112 unsigned data_used = data.size();
113 std::string function = "cyl_bessel_j (integer order)[br](" + boost::lexical_cast<std::string>(data_used) + "/" + boost::lexical_cast<std::string>(data_total) + " tests selected)";
114 std::string function_short = "cyl_bessel_j (integer order)";
115
116 double time;
117
118 time = exec_timed_test([](const std::vector<double>& v){ return boost::math::cyl_bessel_j(static_cast<int>(v[0]), v[1]); });
119 std::cout << time << std::endl;
120 #if defined(COMPILER_COMPARISON_TABLES)
121 report_execution_time(time, std::string("Compiler Option Comparison on ") + platform_name(), "boost::math::cyl_bessel_j (integer orders)", get_compiler_options_name());
122 #else
123 #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_C99) || defined(TEST_LIBSTDCXX))
124 report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name());
125 #endif
126 report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name());
127 #endif
128 //
129 // Boost again, but with promotion to long double turned off:
130 //
131 #if !defined(COMPILER_COMPARISON_TABLES)
132 if(sizeof(long double) != sizeof(double))
133 {
134 time = exec_timed_test([](const std::vector<double>& v){ return boost::math::cyl_bessel_j(static_cast<int>(v[0]), v[1], boost::math::policies::make_policy(boost::math::policies::promote_double<false>())); });
135 std::cout << time << std::endl;
136 #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_C99) || defined(TEST_LIBSTDCXX))
137 report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name() + "[br]promote_double<false>");
138 #endif
139 report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name() + "[br]promote_double<false>");
140 }
141 #endif
142
143
144 #if defined(TEST_C99) && !defined(COMPILER_COMPARISON_TABLES)
145 time = exec_timed_test([](const std::vector<double>& v){ return ::jn(static_cast<int>(v[0]), v[1]); });
146 std::cout << time << std::endl;
147 report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "math.h");
148 #endif
149 #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
150 time = exec_timed_test([](const std::vector<double>& v){ return std::tr1::cyl_bessel_j(static_cast<int>(v[0]), v[1]); });
151 std::cout << time << std::endl;
152 report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "tr1/cmath");
153 #endif
154 #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES)
155 time = exec_timed_test([](const std::vector<double>& v){ return gsl_sf_bessel_Jn(static_cast<int>(v[0]), v[1]); });
156 std::cout << time << std::endl;
157 report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "GSL " GSL_VERSION);
158 #endif
159 #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES)
160 time = exec_timed_test([](const std::vector<double>& v){ return bessel_j(v[1], static_cast<int>(v[0])); });
161 std::cout << time << std::endl;
162 report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "Rmath " R_VERSION_STRING);
163 #endif
164
165
166 return 0;
167 }
168