]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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<T, 3>, 9> k0_data = { { | |
21 | { { SC_(0.0), SC_(1.0), SC_(0.421024438240708333335627379212609036136219748226660472298970) } }, | |
22 | { { SC_(0.0), SC_(2.0), SC_(0.113893872749533435652719574932481832998326624388808882892530) } }, | |
23 | { { SC_(0.0), SC_(4.0), SC_(0.0111596760858530242697451959798334892250090238884743405382553) } }, | |
24 | { { SC_(0.0), SC_(8.0), SC_(0.000146470705222815387096584408698677921967305368833759024089154) } }, | |
25 | { { SC_(0.0), T(std::ldexp(1.0, -15)), SC_(10.5131392267382037062459525561594822400447325776672021972753) } }, | |
26 | { { SC_(0.0), T(std::ldexp(1.0, -30)), SC_(20.9103469324567717360787328239372191382743831365906131108531) } }, | |
27 | { { SC_(0.0), T(std::ldexp(1.0, -60)), SC_(41.7047623492551310138446473188663682295952219631968830346918) } }, | |
28 | { { SC_(0.0), SC_(50.0), SC_(3.41016774978949551392067551235295223184502537762334808993276e-23) } }, | |
29 | { { SC_(0.0), SC_(100.0), SC_(4.65662822917590201893900528948388635580753948544211387402671e-45) } }, | |
30 | } }; | |
31 | static const boost::array<boost::array<T, 3>, 9> k1_data = { { | |
32 | { { SC_(1.0), SC_(1.0), SC_(0.601907230197234574737540001535617339261586889968106456017768) } }, | |
33 | { { SC_(1.0), SC_(2.0), SC_(0.139865881816522427284598807035411023887234584841515530384442) } }, | |
34 | { { SC_(1.0), SC_(4.0), SC_(0.0124834988872684314703841799808060684838415849886258457917076) } }, | |
35 | { { SC_(1.0), SC_(8.0), SC_(0.000155369211805001133916862450622474621117065122872616157079566) } }, | |
36 | { { SC_(1.0), T(std::ldexp(1.0, -15)), SC_(32767.9998319528316432647441316539139725104728341577594326513) } }, | |
37 | { { SC_(1.0), T(std::ldexp(1.0, -30)), SC_(1.07374182399999999003003028572687332810353799544215073362305e9) } }, | |
38 | { { SC_(1.0), T(std::ldexp(1.0, -60)), SC_(1.15292150460684697599999999999999998169660198868126604634036e18) } }, | |
39 | { { SC_(1.0), SC_(50.0), SC_(3.44410222671755561259185303591267155099677251348256880221927e-23) } }, | |
40 | { { SC_(1.0), SC_(100.0), SC_(4.67985373563690928656254424202433530797494354694335352937465e-45) } }, | |
41 | } }; | |
42 | static const boost::array<boost::array<T, 3>, 9> kn_data = { { | |
43 | { { SC_(2.0), T(std::ldexp(1.0, -30)), SC_(2.30584300921369395150000000000000000234841952009593636868109e18) } }, | |
44 | { { SC_(5.0), SC_(10.0), SC_(0.0000575418499853122792763740236992723196597629124356739596921536) } }, | |
45 | { { SC_(-5.0), SC_(100.0), SC_(5.27325611329294989461777188449044716451716555009882448801072e-45) } }, | |
46 | { { SC_(10.0), SC_(10.0), SC_(0.00161425530039067002345725193091329085443750382929208307802221) } }, | |
47 | { { SC_(10.0), T(std::ldexp(1.0, -30)), SC_(3.78470202927236255215249281534478864916684072926050665209083e98) } }, | |
48 | { { SC_(-10.0), SC_(1.0), SC_(1.80713289901029454691597861302340015908245782948536080022119e8) } }, | |
49 | { { SC_(100.0), SC_(5.0), SC_(7.03986019306167654653386616796116726248616158936088056952477e115) } }, | |
50 | { { SC_(100.0), SC_(80.0), SC_(8.39287107246490782848985384895907681748152272748337807033319e-12) } }, | |
51 | { { SC_(-1000.0), SC_(700.0), SC_(6.51561979144735818903553852606383312984409361984128221539405e-31) } }, | |
52 | } }; | |
53 | ||
54 | int main() | |
55 | { | |
56 | #include "bessel_k_int_data.ipp" | |
57 | ||
58 | add_data(k0_data); | |
59 | add_data(k1_data); | |
60 | add_data(kn_data); | |
61 | add_data(bessel_k_int_data); | |
62 | ||
63 | unsigned data_total = data.size(); | |
64 | ||
65 | screen_data([](const std::vector<double>& v){ return boost::math::cyl_bessel_k(static_cast<int>(v[0]), v[1]); }, [](const std::vector<double>& v){ return v[2]; }); | |
66 | ||
67 | #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES) | |
68 | screen_data([](const std::vector<double>& v){ return std::tr1::cyl_bessel_k(static_cast<int>(v[0]), v[1]); }, [](const std::vector<double>& v){ return v[2]; }); | |
69 | #endif | |
70 | #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES) | |
71 | screen_data([](const std::vector<double>& v){ return gsl_sf_bessel_Kn(static_cast<int>(v[0]), v[1]); }, [](const std::vector<double>& v){ return v[2]; }); | |
72 | #endif | |
73 | #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES) | |
74 | screen_data([](const std::vector<double>& v){ return bessel_k(v[1], static_cast<int>(v[0]), 1); }, [](const std::vector<double>& v){ return v[2]; }); | |
75 | #endif | |
76 | ||
77 | unsigned data_used = data.size(); | |
78 | std::string function = "cyl_bessel_k (integer order)[br](" + boost::lexical_cast<std::string>(data_used) + "/" + boost::lexical_cast<std::string>(data_total) + " tests selected)"; | |
79 | std::string function_short = "cyl_bessel_k (integer order)"; | |
80 | ||
81 | double time; | |
82 | ||
83 | time = exec_timed_test([](const std::vector<double>& v){ return boost::math::cyl_bessel_k(static_cast<int>(v[0]), v[1]); }); | |
84 | std::cout << time << std::endl; | |
85 | #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_LIBSTDCXX)) | |
86 | report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name()); | |
87 | #endif | |
88 | report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name()); | |
89 | // | |
90 | // Boost again, but with promotion to long double turned off: | |
91 | // | |
92 | #if !defined(COMPILER_COMPARISON_TABLES) | |
93 | if(sizeof(long double) != sizeof(double)) | |
94 | { | |
95 | time = exec_timed_test([](const std::vector<double>& v){ return boost::math::cyl_bessel_k(static_cast<int>(v[0]), v[1], boost::math::policies::make_policy(boost::math::policies::promote_double<false>())); }); | |
96 | std::cout << time << std::endl; | |
97 | #if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH) || defined(TEST_LIBSTDCXX)) | |
98 | 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>"); | |
99 | #endif | |
100 | 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>"); | |
101 | } | |
102 | #endif | |
103 | ||
104 | ||
105 | #if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES) | |
106 | time = exec_timed_test([](const std::vector<double>& v){ return std::tr1::cyl_bessel_k(static_cast<int>(v[0]), v[1]); }); | |
107 | std::cout << time << std::endl; | |
108 | report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "tr1/cmath"); | |
109 | #endif | |
110 | #if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES) | |
111 | time = exec_timed_test([](const std::vector<double>& v){ return gsl_sf_bessel_Kn(static_cast<int>(v[0]), v[1]); }); | |
112 | std::cout << time << std::endl; | |
113 | report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "GSL " GSL_VERSION); | |
114 | #endif | |
115 | #if defined(TEST_RMATH) && !defined(COMPILER_COMPARISON_TABLES) | |
116 | time = exec_timed_test([](const std::vector<double>& v){ return bessel_k(v[1], static_cast<int>(v[0]), 1); }); | |
117 | std::cout << time << std::endl; | |
118 | report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "Rmath " R_VERSION_STRING); | |
119 | #endif | |
120 | ||
121 | return 0; | |
122 | } | |
123 |