]>
git.proxmox.com Git - ceph.git/blob - 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)
6 #include "test_autodiff.hpp"
8 BOOST_AUTO_TEST_SUITE(test_autodiff_5
)
10 BOOST_AUTO_TEST_CASE_TEMPLATE(binomial_hpp
, T
, all_float_types
) {
11 using boost::multiprecision::min
;
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};
20 for (auto i
: boost::irange(test_constants::n_samples
)) {
22 auto n
= n_sampler
.next();
23 auto r
= n
== 0 ? 0 : (min
)(r_sampler
.next(), n
- 1);
25 // This is a hard function to test for type float due to a specialization of
26 // boost::math::binomial_coefficient
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
);
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
)) {
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());
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
;
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
)) {
56 auto n
= n_sampler
.next();
57 auto x
= x_sampler
.next();
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());
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());
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());
71 /*/usr/include/boost/math/special_functions/chebyshev.hpp:164:40: error:
73 boost::math::differentiation::autodiff_v1::detail::fvar<double, 3> to
75 BOOST_CHECK_EQUAL(boost::math::chebyshev_clenshaw_recurrence(c.data(),c.size(),make_fvar<T,m>(0.20))
77 boost::math::chebyshev_clenshaw_recurrence(c.data(),c.size(),static_cast<T>(0.20)));*/
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()));
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
)) {
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());
102 BOOST_AUTO_TEST_CASE_TEMPLATE(digamma_hpp
, T
, all_float_types
) {
104 using boost::math::nextafter
;
105 using std::nextafter
;
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
)) {
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());
120 BOOST_AUTO_TEST_SUITE_END()