]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/test/test_autodiff_5.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / math / test / test_autodiff_5.cpp
1 // Copyright Matthew Pulver 2018 - 2019.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // https://www.boost.org/LICENSE_1_0.txt)
5
6 #include "test_autodiff.hpp"
7
8 BOOST_AUTO_TEST_SUITE(test_autodiff_5)
9
10 BOOST_AUTO_TEST_CASE_TEMPLATE(binomial_hpp, T, all_float_types) {
11 using boost::multiprecision::min;
12 using std::fabs;
13 using std::min;
14
15 using test_constants = test_constants_t<T>;
16 static constexpr auto m = test_constants::order;
17 test_detail::RandomSample<unsigned> n_sampler{0u, 30u};
18 test_detail::RandomSample<unsigned> r_sampler{0u, 30u};
19
20 for (auto i : boost::irange(test_constants::n_samples)) {
21 std::ignore = i;
22 auto n = n_sampler.next();
23 auto r = n == 0 ? 0 : (min)(r_sampler.next(), n - 1);
24
25 // This is a hard function to test for type float due to a specialization of
26 // boost::math::binomial_coefficient
27 auto autodiff_v =
28 std::is_same<T, float>::value
29 ? make_fvar<T, m>(boost::math::binomial_coefficient<T>(n, r))
30 : boost::math::binomial_coefficient<T>(n, r);
31 auto anchor_v = boost::math::binomial_coefficient<T>(n, r);
32 BOOST_CHECK_EQUAL(autodiff_v.derivative(0u), anchor_v);
33 }
34 }
35
36 BOOST_AUTO_TEST_CASE_TEMPLATE(cbrt_hpp, T, all_float_types) {
37 using test_constants = test_constants_t<T>;
38 static constexpr auto m = test_constants::order;
39 test_detail::RandomSample<T> x_sampler{-2000, 2000};
40 for (auto i : boost::irange(test_constants::n_samples)) {
41 std::ignore = i;
42 auto x = x_sampler.next();
43 BOOST_CHECK_CLOSE(boost::math::cbrt(make_fvar<T, m>(x)).derivative(0u),
44 boost::math::cbrt(x), 50 * test_constants::pct_epsilon());
45 }
46 }
47
48 BOOST_AUTO_TEST_CASE_TEMPLATE(chebyshev_hpp, T, all_float_types) {
49 using test_constants = test_constants_t<T>;
50 static constexpr auto m = test_constants::order;
51 {
52 test_detail::RandomSample<unsigned> n_sampler{0u, 10u};
53 test_detail::RandomSample<T> x_sampler{-2, 2};
54 for (auto i : boost::irange(test_constants::n_samples)) {
55 std::ignore = i;
56 auto n = n_sampler.next();
57 auto x = x_sampler.next();
58 BOOST_CHECK_CLOSE(
59 boost::math::chebyshev_t(n, make_fvar<T, m>(x)).derivative(0u),
60 boost::math::chebyshev_t(n, x), 40 * test_constants::pct_epsilon());
61
62 BOOST_CHECK_CLOSE(
63 boost::math::chebyshev_u(n, make_fvar<T, m>(x)).derivative(0u),
64 boost::math::chebyshev_u(n, x), 40 * test_constants::pct_epsilon());
65
66 BOOST_CHECK_CLOSE(
67 boost::math::chebyshev_t_prime(n, make_fvar<T, m>(x)).derivative(0u),
68 boost::math::chebyshev_t_prime(n, x),
69 40 * test_constants::pct_epsilon());
70
71 /*/usr/include/boost/math/special_functions/chebyshev.hpp:164:40: error:
72 cannot convert
73 boost::math::differentiation::autodiff_v1::detail::fvar<double, 3> to
74 double in return
75 BOOST_CHECK_EQUAL(boost::math::chebyshev_clenshaw_recurrence(c.data(),c.size(),make_fvar<T,m>(0.20))
76 ,
77 boost::math::chebyshev_clenshaw_recurrence(c.data(),c.size(),static_cast<T>(0.20)));*/
78 /*try {
79 std::array<T, 4> c0{{14.2, -13.7, 82.3, 96}};
80 BOOST_CHECK_CLOSE(boost::math::chebyshev_clenshaw_recurrence(c0.data(),
81 c0.size(), make_fvar<T,m>(x)),
82 boost::math::chebyshev_clenshaw_recurrence(c0.data(),
83 c0.size(), x), 10*test_constants::pct_epsilon()); } catch (...) {
84 std::rethrow_exception(std::exception_ptr(std::current_exception()));
85 }*/
86 }
87 }
88 }
89
90 BOOST_AUTO_TEST_CASE_TEMPLATE(cospi_hpp, T, all_float_types) {
91 using test_constants = test_constants_t<T>;
92 static constexpr auto m = test_constants::order;
93 test_detail::RandomSample<T> x_sampler{-2000, 2000};
94 for (auto i : boost::irange(test_constants::n_samples)) {
95 std::ignore = i;
96 auto x = x_sampler.next();
97 BOOST_CHECK_CLOSE(boost::math::cos_pi(make_fvar<T, m>(x)).derivative(0u),
98 boost::math::cos_pi(x), test_constants::pct_epsilon());
99 }
100 }
101
102 BOOST_AUTO_TEST_CASE_TEMPLATE(digamma_hpp, T, all_float_types) {
103
104 using boost::math::nextafter;
105 using std::nextafter;
106
107 using test_constants = test_constants_t<T>;
108 static constexpr auto m = test_constants::order;
109 test_detail::RandomSample<T> x_sampler{-1, 2000};
110 for (auto i : boost::irange(test_constants::n_samples)) {
111 std::ignore = i;
112 auto x = nextafter(x_sampler.next(), ((std::numeric_limits<T>::max))());
113 auto autodiff_v = boost::math::digamma(make_fvar<T, m>(x));
114 auto anchor_v = boost::math::digamma(x);
115 BOOST_CHECK_CLOSE(autodiff_v.derivative(0u), anchor_v,
116 1e4 * test_constants::pct_epsilon());
117 }
118 }
119
120 BOOST_AUTO_TEST_SUITE_END()