mirror of
https://github.com/boostorg/math.git
synced 2026-01-19 04:22:09 +00:00
Remove lexical_cast<> dependencies.
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
#define BOOST_MATH_DIFFERENTIATION_AUTODIFF_HPP
|
||||
|
||||
#include <boost/cstdfloat.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
#include <boost/math/special_functions.hpp>
|
||||
#include <boost/math/tools/config.hpp>
|
||||
@@ -142,8 +141,6 @@ class fvar {
|
||||
template <typename RealType2>
|
||||
fvar(RealType2 const& ca); // Supports any RealType2 for which static_cast<root_type>(ca) compiles.
|
||||
|
||||
explicit fvar(char const* ca); // Converts a char const* string to RealType by boost::lexical_cast
|
||||
|
||||
// r = cr | RealType& | Assignment operator.
|
||||
fvar& operator=(fvar const&) = default;
|
||||
|
||||
@@ -684,10 +681,6 @@ template <typename RealType, size_t Order>
|
||||
template <typename RealType2>
|
||||
fvar<RealType, Order>::fvar(RealType2 const& ca) : v{{static_cast<RealType>(ca)}} {}
|
||||
|
||||
template <typename RealType, size_t Order>
|
||||
fvar<RealType, Order>::fvar(char const* ca_str)
|
||||
: v{{static_cast<RealType>(boost::lexical_cast<promote<root_type, double>>(ca_str))}} {}
|
||||
|
||||
/*
|
||||
template<typename RealType, size_t Order>
|
||||
fvar<RealType,Order>& fvar<RealType,Order>::operator=(root_type const& ca)
|
||||
|
||||
@@ -83,64 +83,6 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(multiprecision, T, multiprecision_float_types) {
|
||||
}
|
||||
#endif
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(airy_hpp, T, all_float_types) {
|
||||
using boost::multiprecision::min;
|
||||
using std::min;
|
||||
|
||||
using test_constants = test_constants_t<T>;
|
||||
static constexpr auto m = test_constants::order;
|
||||
|
||||
test_detail::RandomSample<T> x_sampler(-100, 100);
|
||||
for (auto i : boost::irange(test_constants::n_samples)) {
|
||||
const auto &x = x_sampler.next();
|
||||
{
|
||||
auto autodiff_v = boost::math::airy_ai(make_fvar<T, m>(x));
|
||||
auto anchor_v = boost::math::airy_ai(x);
|
||||
BOOST_CHECK_CLOSE(autodiff_v.derivative(0u), anchor_v,
|
||||
1e4 * test_constants::pct_epsilon());
|
||||
}
|
||||
|
||||
{
|
||||
auto autodiff_v = boost::math::airy_ai_prime(make_fvar<T, m>(x));
|
||||
auto anchor_v = boost::math::airy_ai_prime(x);
|
||||
BOOST_CHECK_CLOSE(autodiff_v.derivative(0u), anchor_v,
|
||||
1e4 * test_constants::pct_epsilon());
|
||||
}
|
||||
|
||||
{
|
||||
auto x_ = (min)(x, T(26));
|
||||
auto autodiff_v = boost::math::airy_bi(make_fvar<T, m>(x_));
|
||||
auto anchor_v = boost::math::airy_bi(x_);
|
||||
BOOST_CHECK_CLOSE(autodiff_v.derivative(0u), anchor_v,
|
||||
1e4 * test_constants::pct_epsilon());
|
||||
}
|
||||
|
||||
{
|
||||
auto x_ = ((min))(x, T(26));
|
||||
auto autodiff_v = boost::math::airy_bi_prime(make_fvar<T, m>(x_));
|
||||
auto anchor_v = boost::math::airy_bi_prime(x_);
|
||||
BOOST_CHECK_CLOSE(autodiff_v.derivative(0u), anchor_v,
|
||||
1e4 * test_constants::pct_epsilon());
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
{
|
||||
auto autodiff_v = boost::math::airy_ai_zero<autodiff_fvar<T, m>>(i);
|
||||
auto anchor_v = boost::math::airy_ai_zero<T>(i);
|
||||
BOOST_CHECK_CLOSE(autodiff_v.derivative(0u), anchor_v,
|
||||
1e4 * test_constants::pct_epsilon());
|
||||
}
|
||||
|
||||
{
|
||||
auto autodiff_v = boost::math::airy_bi_zero<autodiff_fvar<T, m>>(i);
|
||||
auto anchor_v = boost::math::airy_bi_zero<T>(i);
|
||||
BOOST_CHECK_CLOSE(autodiff_v.derivative(0u), anchor_v,
|
||||
1e4 * test_constants::pct_epsilon());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(acosh_hpp, T, all_float_types) {
|
||||
using boost::math::acosh;
|
||||
using test_constants = test_constants_t<T>;
|
||||
@@ -249,306 +191,4 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(bernoulli_hpp, T, all_float_types) {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(kbhat): Something in here is very slow with boost::multiprecision
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(bessel_hpp, T, bin_float_types) {
|
||||
using boost::math::fpclassify;
|
||||
using boost::math::nextafter;
|
||||
using boost::math::signbit;
|
||||
using boost::math::tools::max;
|
||||
using boost::multiprecision::fabs;
|
||||
using boost::multiprecision::fpclassify;
|
||||
using boost::multiprecision::signbit;
|
||||
using detail::fabs;
|
||||
using std::fabs;
|
||||
using std::max;
|
||||
using std::nextafter;
|
||||
|
||||
using test_constants = test_constants_t<T>;
|
||||
static constexpr auto m = test_constants::order;
|
||||
test_detail::RandomSample<T> v_sampler{-20, 20};
|
||||
test_detail::RandomSample<T> x_sampler{
|
||||
-boost::math::tools::log_max_value<T>() + 1,
|
||||
boost::math::tools::log_max_value<T>() - 1};
|
||||
for (auto i : boost::irange(test_constants::n_samples)) {
|
||||
auto v = v_sampler.next();
|
||||
auto x = x_sampler.next();
|
||||
v = ((fpclassify(v) == FP_ZERO) ? 1 : -1) *
|
||||
(max)(v, (nextafter)(T(0), ((std::numeric_limits<T>::max))()));
|
||||
if (signbit(x)) {
|
||||
v = static_cast<T>(boost::math::itrunc(v));
|
||||
}
|
||||
|
||||
try {
|
||||
auto autodiff_v =
|
||||
boost::math::cyl_bessel_i(make_fvar<T, m>(v), make_fvar<T, m>(x));
|
||||
auto anchor_v = boost::math::cyl_bessel_i(v, x);
|
||||
BOOST_WARN_CLOSE(autodiff_v.derivative(0u), anchor_v,
|
||||
1e4 * test_constants::pct_epsilon());
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(
|
||||
boost::math::cyl_bessel_i(make_fvar<T, m>(v), make_fvar<T, m>(x)),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(boost::math::cyl_bessel_i(v, x),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
} catch (...) {
|
||||
std::cout << "Inputs: v: " << v << " x: " << x << std::endl;
|
||||
std::rethrow_exception(std::current_exception());
|
||||
}
|
||||
|
||||
{
|
||||
auto x_j = fabs(x) + 1;
|
||||
try {
|
||||
auto autodiff_v =
|
||||
boost::math::cyl_bessel_j(make_fvar<T, m>(v), make_fvar<T, m>(x_j));
|
||||
auto anchor_v = boost::math::cyl_bessel_j(v, x_j);
|
||||
BOOST_WARN_CLOSE(autodiff_v.derivative(0u), anchor_v,
|
||||
1e4 * test_constants::pct_epsilon());
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(
|
||||
boost::math::cyl_bessel_j(make_fvar<T, m>(v), make_fvar<T, m>(x_j)),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(boost::math::cyl_bessel_j(v, x_j),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
} catch (...) {
|
||||
std::cout << "Inputs: v: " << v << " x: " << x_j << std::endl;
|
||||
std::rethrow_exception(std::current_exception());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
auto autodiff_v =
|
||||
boost::math::cyl_bessel_j_zero(make_fvar<T, m>(v), i + 1);
|
||||
auto anchor_v = boost::math::cyl_bessel_j_zero(v, i + 1);
|
||||
BOOST_WARN_CLOSE(autodiff_v.derivative(0u), anchor_v,
|
||||
1e4 * test_constants::pct_epsilon());
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(
|
||||
boost::math::cyl_bessel_j_zero(make_fvar<T, m>(v), i + 1),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(boost::math::cyl_bessel_j_zero(v, i + 1),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
} catch (...) {
|
||||
std::cout << "Inputs: v: " << v << " i: " << (i + 1) << std::endl;
|
||||
std::rethrow_exception(std::current_exception());
|
||||
}
|
||||
|
||||
{
|
||||
auto x_k = fabs(x) + 1;
|
||||
try {
|
||||
auto autodiff_v =
|
||||
boost::math::cyl_bessel_k(make_fvar<T, m>(v), make_fvar<T, m>(x_k));
|
||||
auto anchor_v = boost::math::cyl_bessel_k(v, x_k);
|
||||
BOOST_WARN_CLOSE(autodiff_v.derivative(0u), anchor_v,
|
||||
1e4 * test_constants::pct_epsilon());
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(
|
||||
boost::math::cyl_bessel_k(make_fvar<T, m>(v), make_fvar<T, m>(x_k)),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(boost::math::cyl_bessel_k(v, x_k),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
} catch (...) {
|
||||
std::cout << "Inputs: v: " << v << " x: " << x_k << std::endl;
|
||||
std::rethrow_exception(std::current_exception());
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto x_neumann = fabs(x) + 1;
|
||||
try {
|
||||
auto autodiff_v = boost::math::cyl_neumann(make_fvar<T, m>(v),
|
||||
make_fvar<T, m>(x_neumann));
|
||||
auto anchor_v = boost::math::cyl_neumann(v, x_neumann);
|
||||
BOOST_WARN_CLOSE(autodiff_v.derivative(0u), anchor_v,
|
||||
1e4 * test_constants::pct_epsilon());
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::cyl_neumann(make_fvar<T, m>(v),
|
||||
make_fvar<T, m>(x_neumann)),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(boost::math::cyl_neumann(v, x_neumann),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
} catch (...) {
|
||||
std::cout << "Inputs: v: " << v << " x: " << x_neumann << std::endl;
|
||||
std::rethrow_exception(std::current_exception());
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
try {
|
||||
auto autodiff_v =
|
||||
boost::math::cyl_neumann_zero(make_fvar<T, m>(v), i + 1);
|
||||
auto anchor_v = boost::math::cyl_neumann_zero(v, i + 1);
|
||||
BOOST_WARN_CLOSE(autodiff_v.derivative(0u), anchor_v,
|
||||
1e4 * test_constants::pct_epsilon());
|
||||
} catch (std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(
|
||||
boost::math::cyl_neumann_zero((make_fvar<T, m>)(v), i + 1),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(boost::math::cyl_neumann_zero(v, i + 1),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
} catch (...) {
|
||||
std::cout << "Inputs: v: " << v << " i: " << (i + 1) << std::endl;
|
||||
std::rethrow_exception(std::current_exception());
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto i_ = static_cast<unsigned>(i);
|
||||
try {
|
||||
auto autodiff_v = boost::math::sph_bessel<autodiff_fvar<T, m>>(
|
||||
i_, make_fvar<T, m>(fabs(v)));
|
||||
auto anchor_v = boost::math::sph_bessel<T>(i_, fabs(v));
|
||||
BOOST_WARN_CLOSE(autodiff_v.derivative(0u), anchor_v,
|
||||
1e4 * test_constants::pct_epsilon());
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(
|
||||
(boost::math::sph_bessel<
|
||||
autodiff_fvar<T, m>>)(i_, (make_fvar<T, m>)(fabs(v))),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(boost::math::sph_bessel<T>(i_, fabs(v)),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
} catch (...) {
|
||||
std::cout << "Inputs: i: " << i_ << " v: " << (fabs(v)) << std::endl;
|
||||
std::rethrow_exception(std::current_exception());
|
||||
}
|
||||
|
||||
{
|
||||
auto v_ =
|
||||
(max)(T(fabs(v)),
|
||||
nextafter(T(fabs(v)), 2 * (std::numeric_limits<T>::min)()));
|
||||
try {
|
||||
auto autodiff_v = boost::math::sph_neumann<autodiff_fvar<T, m>>(
|
||||
i_, make_fvar<T, m>(v_));
|
||||
auto anchor_v = boost::math::sph_neumann<T>(i_, v_);
|
||||
BOOST_WARN_CLOSE(autodiff_v.derivative(0u), anchor_v,
|
||||
1e4 * test_constants::pct_epsilon());
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(((boost::math::sph_neumann<autodiff_fvar<T, m>>(
|
||||
i_, make_fvar<T, m>(v_)))),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(((boost::math::sph_neumann<T>(i_, v_))),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
} catch (...) {
|
||||
std::cout << "Inputs: i: " << i_ << " v: " << v_ << std::endl;
|
||||
std::rethrow_exception(std::current_exception());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
auto autodiff_v = boost::math::cyl_bessel_i_prime(make_fvar<T, m>(v),
|
||||
make_fvar<T, m>(x));
|
||||
auto anchor_v = boost::math::cyl_bessel_i_prime(v, x);
|
||||
BOOST_WARN_CLOSE(autodiff_v.derivative(0u), anchor_v,
|
||||
1e4 * test_constants::pct_epsilon());
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::cyl_bessel_i_prime((make_fvar<T, m>)(v),
|
||||
(make_fvar<T, m>)(x)),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(boost::math::cyl_bessel_i_prime(v, x),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
} catch (...) {
|
||||
std::cout << "Inputs: v: " << v << " x: " << x << std::endl;
|
||||
std::rethrow_exception(std::current_exception());
|
||||
}
|
||||
|
||||
{
|
||||
auto x_j = fabs(x) + 1;
|
||||
try {
|
||||
auto autodiff_v = boost::math::cyl_bessel_j_prime(
|
||||
make_fvar<T, m>(v), make_fvar<T, m>(x_j));
|
||||
auto anchor_v = boost::math::cyl_bessel_j_prime(v, x_j);
|
||||
BOOST_WARN_CLOSE(autodiff_v.derivative(0u), anchor_v,
|
||||
1e4 * test_constants::pct_epsilon());
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::cyl_bessel_j_prime(
|
||||
(make_fvar<T, m>)(v), (make_fvar<T, m>)(x_j)),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(boost::math::cyl_bessel_j_prime(v, x_j),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
} catch (...) {
|
||||
std::cout << "Inputs: v: " << v << " x_k: " << x_j << std::endl;
|
||||
std::rethrow_exception(std::current_exception());
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto x_k = fabs(x) + 1;
|
||||
try {
|
||||
auto autodiff_v = boost::math::cyl_bessel_k_prime(
|
||||
make_fvar<T, m>(v), make_fvar<T, m>(x_k));
|
||||
auto anchor_v = boost::math::cyl_bessel_k_prime(v, x_k);
|
||||
BOOST_WARN_CLOSE(autodiff_v.derivative(0u), anchor_v,
|
||||
1e4 * test_constants::pct_epsilon());
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::cyl_bessel_k_prime(
|
||||
(make_fvar<T, m>)(v), (make_fvar<T, m>)(x_k)),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(boost::math::cyl_bessel_k_prime(v, x_k),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
} catch (...) {
|
||||
std::cout << "Inputs: v: " << v << " x: " << x_k << std::endl;
|
||||
std::rethrow_exception(std::current_exception());
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto x_neumann = fabs(x) + 1;
|
||||
try {
|
||||
auto autodiff_v = boost::math::cyl_neumann_prime(
|
||||
make_fvar<T, m>(v), make_fvar<T, m>(x_neumann));
|
||||
auto anchor_v = boost::math::cyl_neumann_prime(v, x_neumann);
|
||||
BOOST_WARN_CLOSE(autodiff_v.derivative(0u), anchor_v,
|
||||
1e4 * test_constants::pct_epsilon());
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(
|
||||
boost::math::cyl_neumann_prime((make_fvar<T, m>)(v),
|
||||
(make_fvar<T, m>)(x_neumann)),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(boost::math::cyl_neumann_prime(v, x_neumann),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
} catch (...) {
|
||||
std::cout << "Inputs: v: " << v << " x: " << x_neumann << std::endl;
|
||||
std::rethrow_exception(std::current_exception());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
auto autodiff_v = boost::math::sph_bessel_prime<autodiff_fvar<T, m>>(
|
||||
i_, make_fvar<T, m>(fabs(v) + 1));
|
||||
auto anchor_v = boost::math::sph_bessel_prime<T>(i_, fabs(v) + 1);
|
||||
BOOST_WARN_CLOSE(autodiff_v.derivative(0u), anchor_v,
|
||||
1e4 * test_constants::pct_epsilon());
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(
|
||||
(boost::math::sph_neumann<
|
||||
autodiff_fvar<T, m>>)(i_, (make_fvar<T, m>)(fabs(v) + 1)),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW((boost::math::sph_neumann<T>)(i_, fabs(v) + 1),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
} catch (...) {
|
||||
std::cout << "Inputs: i: " << i_ << " v: " << (fabs(v) + 1)
|
||||
<< std::endl;
|
||||
std::rethrow_exception(std::current_exception());
|
||||
}
|
||||
|
||||
try {
|
||||
auto autodiff_v = boost::math::sph_neumann_prime<autodiff_fvar<T, m>>(
|
||||
i_, make_fvar<T, m>(fabs(v) + 1));
|
||||
auto anchor_v = boost::math::sph_neumann_prime<T>(i_, fabs(v) + 1);
|
||||
BOOST_WARN_CLOSE(autodiff_v.derivative(0u), anchor_v,
|
||||
1e4 * test_constants::pct_epsilon());
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(
|
||||
(boost::math::sph_neumann_prime<
|
||||
autodiff_fvar<T, m>>)(i_, (make_fvar<T, m>)(fabs(v) + 1)),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW((boost::math::sph_neumann_prime<T>)(i_, fabs(v) + 1),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
} catch (...) {
|
||||
std::cout << "Inputs: i: " << i << " v: " << (fabs(v) + 1) << std::endl;
|
||||
std::rethrow_exception(std::current_exception());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
@@ -7,257 +7,6 @@
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(test_autodiff_5)
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(beta_hpp, T, bin_float_types) {
|
||||
using bmp::fabs;
|
||||
using detail::fabs;
|
||||
using std::fabs;
|
||||
|
||||
using test_constants = test_constants_t<T>;
|
||||
static constexpr auto m = test_constants::order;
|
||||
test_detail::RandomSample<T> a_sampler{-2000, 2000};
|
||||
test_detail::RandomSample<T> b_sampler{-2000, 2000};
|
||||
test_detail::RandomSample<T> z_sampler{0, 1};
|
||||
for (auto i : boost::irange(test_constants::n_samples)) {
|
||||
std::ignore = i;
|
||||
auto a = a_sampler.next();
|
||||
auto b = b_sampler.next();
|
||||
auto z = z_sampler.next();
|
||||
{
|
||||
auto a_ = fabs(a) + 1;
|
||||
auto b_ = fabs(b) + 1;
|
||||
try {
|
||||
auto autodiff_v = boost::math::beta(
|
||||
make_fvar<T, m>(a_), make_fvar<T, m>(b_), make_fvar<T, m>(z));
|
||||
auto anchor_v = boost::math::beta(a_, b_, z);
|
||||
BOOST_CHECK(isNearZero(autodiff_v.derivative(0u) - anchor_v));
|
||||
} catch (const boost::math::evaluation_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::beta(make_fvar<T, m>(a_),
|
||||
make_fvar<T, m>(b_),
|
||||
make_fvar<T, m>(z)),
|
||||
boost::wrapexcept<boost::math::evaluation_error>);
|
||||
BOOST_CHECK_THROW(boost::math::beta(a_, b_, z),
|
||||
boost::wrapexcept<boost::math::evaluation_error>);
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::beta(make_fvar<T, m>(a_),
|
||||
make_fvar<T, m>(b_),
|
||||
make_fvar<T, m>(z)),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(boost::math::beta(a_, b_, z),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
}
|
||||
|
||||
try {
|
||||
auto autodiff_v = boost::math::betac(
|
||||
make_fvar<T, m>(a_), make_fvar<T, m>(b_), make_fvar<T, m>(z));
|
||||
auto anchor_v = boost::math::betac(a_, b_, z);
|
||||
BOOST_TEST_WARN(isNearZero(autodiff_v.derivative(0u) - anchor_v));
|
||||
} catch (const boost::math::evaluation_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::betac(make_fvar<T, m>(a_),
|
||||
make_fvar<T, m>(b_),
|
||||
make_fvar<T, m>(z)),
|
||||
boost::wrapexcept<boost::math::evaluation_error>);
|
||||
BOOST_CHECK_THROW(boost::math::betac(a_, b_, z),
|
||||
boost::wrapexcept<boost::math::evaluation_error>);
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::betac(make_fvar<T, m>(a_),
|
||||
make_fvar<T, m>(b_),
|
||||
make_fvar<T, m>(z)),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(boost::math::betac(a_, b_, z),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
}
|
||||
|
||||
try {
|
||||
auto autodiff_v =
|
||||
boost::math::ibeta(make_fvar<T, m>(a_ - 1), make_fvar<T, m>(b_ - 1),
|
||||
make_fvar<T, m>(z));
|
||||
auto anchor_v = boost::math::ibeta(a_ - 1, b_ - 1, z);
|
||||
BOOST_TEST_WARN(isNearZero(autodiff_v.derivative(0u) - anchor_v));
|
||||
} catch (const boost::math::evaluation_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::ibeta(make_fvar<T, m>(a_ - 1),
|
||||
make_fvar<T, m>(b_ - 1),
|
||||
make_fvar<T, m>(z)),
|
||||
boost::wrapexcept<boost::math::evaluation_error>);
|
||||
BOOST_CHECK_THROW(boost::math::ibeta(a_ - 1, b_ - 1, z),
|
||||
boost::wrapexcept<boost::math::evaluation_error>);
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::ibeta(make_fvar<T, m>(a_ - 1),
|
||||
make_fvar<T, m>(b_ - 1),
|
||||
make_fvar<T, m>(z)),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(boost::math::ibeta(a_ - 1, b_ - 1, z),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
}
|
||||
|
||||
try {
|
||||
auto autodiff_v =
|
||||
boost::math::ibetac(make_fvar<T, m>(a_ - 1),
|
||||
make_fvar<T, m>(b_ - 1), make_fvar<T, m>(z));
|
||||
auto anchor_v = boost::math::ibetac(a_ - 1, b_ - 1, z);
|
||||
BOOST_TEST_WARN(isNearZero(autodiff_v.derivative(0u) - anchor_v));
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::ibetac(make_fvar<T, m>(a_ - 1),
|
||||
make_fvar<T, m>(b_ - 1),
|
||||
make_fvar<T, m>(z)),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(boost::math::ibetac(a_ - 1, b_ - 1, z),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
}
|
||||
|
||||
try {
|
||||
auto autodiff_v = boost::math::ibeta_derivative(
|
||||
make_fvar<T, m>(a_), make_fvar<T, m>(b_), make_fvar<T, m>(z));
|
||||
auto anchor_v = boost::math::ibeta_derivative(a_, b_, z);
|
||||
BOOST_CHECK(isNearZero(autodiff_v.derivative(0u) - anchor_v));
|
||||
} catch (const boost::math::evaluation_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::ibeta_derivative(make_fvar<T, m>(a_),
|
||||
make_fvar<T, m>(b_),
|
||||
make_fvar<T, m>(z)),
|
||||
boost::wrapexcept<boost::math::evaluation_error>);
|
||||
BOOST_CHECK_THROW(boost::math::ibeta_derivative(a_, b_, z),
|
||||
boost::wrapexcept<boost::math::evaluation_error>);
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::ibeta_derivative(make_fvar<T, m>(a_),
|
||||
make_fvar<T, m>(b_),
|
||||
make_fvar<T, m>(z)),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(boost::math::ibeta_derivative(a_, b_, z),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
}
|
||||
|
||||
{
|
||||
try {
|
||||
auto autodiff_v = boost::math::ibeta_inv(
|
||||
make_fvar<T, m>(a_), make_fvar<T, m>(b_), make_fvar<T, m>(z));
|
||||
auto anchor_v = boost::math::ibeta_inv<T>(a_, b_, z);
|
||||
BOOST_TEST_WARN(isNearZero(autodiff_v.derivative(0u) - anchor_v));
|
||||
} catch (const boost::math::evaluation_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::ibeta_derivative(make_fvar<T, m>(a_),
|
||||
make_fvar<T, m>(b_),
|
||||
make_fvar<T, m>(z)),
|
||||
boost::wrapexcept<boost::math::evaluation_error>);
|
||||
BOOST_CHECK_THROW(boost::math::ibeta_derivative(a_, b_, z),
|
||||
boost::wrapexcept<boost::math::evaluation_error>);
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::ibeta_derivative(make_fvar<T, m>(a_),
|
||||
make_fvar<T, m>(b_),
|
||||
make_fvar<T, m>(z)),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(boost::math::ibeta_derivative(a_, b_, z),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
}
|
||||
|
||||
try {
|
||||
auto autodiff_v = boost::math::ibetac_inv<autodiff_fvar<T, m>>(
|
||||
make_fvar<T, m>(a_), make_fvar<T, m>(b_), make_fvar<T, m>(z));
|
||||
auto anchor_v = boost::math::ibetac_inv<T>(a_, b_, z);
|
||||
BOOST_TEST_WARN(isNearZero(autodiff_v.derivative(0u) - anchor_v));
|
||||
} catch (const boost::math::evaluation_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::ibeta_derivative(make_fvar<T, m>(a_),
|
||||
make_fvar<T, m>(b_),
|
||||
make_fvar<T, m>(z)),
|
||||
boost::wrapexcept<boost::math::evaluation_error>);
|
||||
BOOST_CHECK_THROW(boost::math::ibeta_derivative(a_, b_, z),
|
||||
boost::wrapexcept<boost::math::evaluation_error>);
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::ibeta_derivative(make_fvar<T, m>(a_),
|
||||
make_fvar<T, m>(b_),
|
||||
make_fvar<T, m>(z)),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(boost::math::ibeta_derivative(a_, b_, z),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
}
|
||||
}
|
||||
{
|
||||
auto b_norm = b_sampler.normalize(fabs(b));
|
||||
try {
|
||||
auto autodiff_v = boost::math::ibeta_inva(
|
||||
make_fvar<T, m>(a_), make_fvar<T, m>(b_norm), make_fvar<T, m>(z));
|
||||
auto anchor_v = boost::math::ibeta_inva(a_, b_norm, z);
|
||||
BOOST_TEST_WARN(isNearZero(autodiff_v.derivative(0u) - anchor_v));
|
||||
} catch (const boost::math::evaluation_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::ibeta_inva(make_fvar<T, m>(a_),
|
||||
make_fvar<T, m>(b_norm),
|
||||
make_fvar<T, m>(z)),
|
||||
boost::wrapexcept<boost::math::evaluation_error>);
|
||||
BOOST_CHECK_THROW(boost::math::ibeta_inva(a_, b_norm, z),
|
||||
boost::wrapexcept<boost::math::evaluation_error>);
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::ibeta_inva(make_fvar<T, m>(a_),
|
||||
make_fvar<T, m>(b_norm),
|
||||
make_fvar<T, m>(z)),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(boost::math::ibeta_inva(a_, b_norm, z),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
}
|
||||
|
||||
try {
|
||||
auto autodiff_v = boost::math::ibetac_inva(
|
||||
make_fvar<T, m>(a_), make_fvar<T, m>(b_norm), make_fvar<T, m>(z));
|
||||
auto anchor_v = boost::math::ibetac_inva(a_, b_norm, z);
|
||||
BOOST_TEST_WARN(isNearZero(autodiff_v.derivative(0u) - anchor_v));
|
||||
} catch (const boost::math::evaluation_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::ibetac_inva(make_fvar<T, m>(a_),
|
||||
make_fvar<T, m>(b_norm),
|
||||
make_fvar<T, m>(z)),
|
||||
boost::wrapexcept<boost::math::evaluation_error>);
|
||||
BOOST_CHECK_THROW(boost::math::ibetac_inva(a_, b_norm, z),
|
||||
boost::wrapexcept<boost::math::evaluation_error>);
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::ibetac_inva(make_fvar<T, m>(a_),
|
||||
make_fvar<T, m>(b_norm),
|
||||
make_fvar<T, m>(z)),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(boost::math::ibetac_inva(a_, b_norm, z),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
}
|
||||
|
||||
try {
|
||||
auto autodiff_v = boost::math::ibeta_invb(
|
||||
make_fvar<T, m>(a_), make_fvar<T, m>(b_norm), make_fvar<T, m>(z));
|
||||
auto anchor_v = boost::math::ibeta_invb(a_, b_norm, z);
|
||||
BOOST_TEST_WARN(isNearZero(autodiff_v.derivative(0u) - anchor_v));
|
||||
} catch (const boost::math::evaluation_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::ibeta_invb(make_fvar<T, m>(a_),
|
||||
make_fvar<T, m>(b_norm),
|
||||
make_fvar<T, m>(z)),
|
||||
boost::wrapexcept<boost::math::evaluation_error>);
|
||||
BOOST_CHECK_THROW(boost::math::ibeta_invb(a_, b_norm, z),
|
||||
boost::wrapexcept<boost::math::evaluation_error>);
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::ibeta_invb(make_fvar<T, m>(a_),
|
||||
make_fvar<T, m>(b_norm),
|
||||
make_fvar<T, m>(z)),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(boost::math::ibeta_invb(a_, b_norm, z),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
}
|
||||
|
||||
try {
|
||||
auto autodiff_v = boost::math::ibetac_invb(
|
||||
make_fvar<T, m>(a_), make_fvar<T, m>(b_norm), make_fvar<T, m>(z));
|
||||
auto anchor_v = boost::math::ibetac_invb(a_, b_norm, z);
|
||||
BOOST_TEST_WARN(isNearZero(autodiff_v.derivative(0u) - anchor_v));
|
||||
} catch (const boost::math::evaluation_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::ibetac_invb(make_fvar<T, m>(a_),
|
||||
make_fvar<T, m>(b_norm),
|
||||
make_fvar<T, m>(z)),
|
||||
boost::wrapexcept<boost::math::evaluation_error>);
|
||||
BOOST_CHECK_THROW(boost::math::ibetac_invb(a_, b_norm, z),
|
||||
boost::wrapexcept<boost::math::evaluation_error>);
|
||||
} catch (const std::overflow_error &) {
|
||||
BOOST_CHECK_THROW(boost::math::ibetac_invb(make_fvar<T, m>(a_),
|
||||
make_fvar<T, m>(b_norm),
|
||||
make_fvar<T, m>(z)),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
BOOST_CHECK_THROW(boost::math::ibetac_invb(a_, b_norm, z),
|
||||
boost::wrapexcept<std::overflow_error>);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(binomial_hpp, T, all_float_types) {
|
||||
using boost::multiprecision::min;
|
||||
using std::fabs;
|
||||
|
||||
@@ -23,60 +23,6 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(expm1_hpp, T, all_float_types) {
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(factorials_hpp, T, all_float_types) {
|
||||
using test_constants = test_constants_t<T>;
|
||||
static constexpr auto m = test_constants::order;
|
||||
test_detail::RandomSample<T> x_sampler{0, 28};
|
||||
for (auto i :
|
||||
boost::irange(static_cast<unsigned>(test_constants::n_samples))) {
|
||||
{
|
||||
auto fact_i = boost::math::factorial<T>(i);
|
||||
auto autodiff_v = boost::math::factorial<autodiff_fvar<T, m>>(i);
|
||||
BOOST_CHECK_CLOSE(autodiff_v.derivative(0u), fact_i,
|
||||
50 * test_constants::pct_epsilon());
|
||||
}
|
||||
|
||||
{
|
||||
auto fact_i = boost::math::unchecked_factorial<T>(i);
|
||||
auto autodiff_v =
|
||||
boost::math::unchecked_factorial<autodiff_fvar<T, m>>(i);
|
||||
BOOST_CHECK_CLOSE(autodiff_v.derivative(0u), fact_i,
|
||||
50 * test_constants::pct_epsilon());
|
||||
}
|
||||
|
||||
{
|
||||
auto fact_i = boost::math::unchecked_factorial<T>(i);
|
||||
auto autodiff_v =
|
||||
boost::math::unchecked_factorial<autodiff_fvar<T, m>>(i);
|
||||
BOOST_CHECK_CLOSE(autodiff_v.derivative(0u), fact_i,
|
||||
50 * test_constants::pct_epsilon());
|
||||
}
|
||||
|
||||
{
|
||||
auto fact_i = boost::math::double_factorial<T>(i);
|
||||
auto autodiff_v = boost::math::double_factorial<autodiff_fvar<T, m>>(i);
|
||||
BOOST_CHECK_CLOSE(autodiff_v.derivative(0u), fact_i,
|
||||
50 * test_constants::pct_epsilon());
|
||||
}
|
||||
|
||||
auto x = x_sampler.next();
|
||||
{
|
||||
auto fact_i = boost::math::rising_factorial<T>(x, static_cast<int>(i));
|
||||
auto autodiff_v = make_fvar<T, m>(fact_i);
|
||||
BOOST_CHECK_CLOSE(autodiff_v.derivative(0u), fact_i,
|
||||
50 * test_constants::pct_epsilon());
|
||||
}
|
||||
|
||||
{
|
||||
auto fact_i =
|
||||
boost::math::falling_factorial<T>(x, test_constants::n_samples - i);
|
||||
auto autodiff_v = make_fvar<T, m>(fact_i);
|
||||
BOOST_CHECK_CLOSE(autodiff_v.derivative(0u), fact_i,
|
||||
50 * test_constants::pct_epsilon());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(fpclassify_hpp, T, all_float_types) {
|
||||
using boost::math::fpclassify;
|
||||
using boost::math::isfinite;
|
||||
|
||||
@@ -295,7 +295,6 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(next_hpp, T, all_float_types) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(owens_t_hpp, T, bin_float_types) {
|
||||
BOOST_MATH_STD_USING;
|
||||
using test_constants = test_constants_t<T>;
|
||||
@@ -312,7 +311,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(owens_t_hpp, T, bin_float_types) {
|
||||
BOOST_CHECK(isNearZero(autodiff_v.derivative(0u) - anchor_v));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(pow_hpp, T, all_float_types) {
|
||||
using test_constants = test_constants_t<T>;
|
||||
@@ -504,19 +503,4 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(trigamma_hpp, T, all_float_types) {
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(zeta_hpp, T, all_float_types) {
|
||||
using test_constants = test_constants_t<T>;
|
||||
static constexpr auto m = test_constants::order;
|
||||
test_detail::RandomSample<T> x_sampler{-30, 30};
|
||||
for (auto i : boost::irange(test_constants::n_samples)) {
|
||||
std::ignore = i;
|
||||
auto x = x_sampler.next();
|
||||
BOOST_WARN(
|
||||
isNearZero(boost::math::zeta(make_fvar<T, m>(x)).derivative(0u) -
|
||||
boost::math::zeta(x)));
|
||||
BOOST_CHECK_CLOSE(boost::math::zeta(make_fvar<T, m>(x)).derivative(0u),
|
||||
boost::math::zeta(x), 50 * test_constants::pct_epsilon());
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
Reference in New Issue
Block a user