2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-19 04:22:09 +00:00

Collected autodiff fixes

This commit is contained in:
Matt Borland
2023-05-30 17:25:48 +02:00
parent c249bfebce
commit 6d37555ccc
7 changed files with 166 additions and 160 deletions

View File

@@ -1491,7 +1491,7 @@ fvar<RealType, Order> sqrt(fvar<RealType, Order> const& cr) {
BOOST_IF_CONSTEXPR (order == 0)
return fvar<RealType, Order>(*derivatives);
else {
root_type numerator = 0.5;
root_type numerator = root_type(0.5);
root_type powers = 1;
#ifndef BOOST_NO_CXX17_IF_CONSTEXPR
derivatives[1] = numerator / *derivatives;

View File

@@ -31,16 +31,24 @@
#include <cstdlib>
#include <random>
#if __has_include(<stdfloat>)
# include <stdfloat>
#endif
namespace mp11 = boost::mp11;
namespace bmp = boost::multiprecision;
namespace diff = boost::math::differentiation::autodiff_v1::detail;
#if defined(BOOST_USE_VALGRIND) || defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
using bin_float_types = mp11::mp_list<float>;
#elif defined(__STDCPP_FLOAT32_T__) && defined(__STDCPP_FLOAT64_T__)
using bin_float_types = mp11::mp_list<std::float32_t, std::float64_t, long double>;
#else
using bin_float_types = mp11::mp_list<float, double, long double>;
#endif
// cpp_dec_float_50 cannot be used with close_at_tolerance
/*using multiprecision_float_types =
mp_list<bmp::cpp_dec_float_50, bmp::cpp_bin_float_50>;*/

View File

@@ -22,7 +22,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(constructors, T, all_float_types) {
}
}
// Single variable
const T cx = 10.0;
const T cx = 10;
const auto x = make_fvar<T, m>(cx);
for (auto i : boost::irange(m + 1)) {
if (i == 0u) {
@@ -44,16 +44,16 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(constructors, T, all_float_types) {
}
}
// Second independent variable
const T cy = 100.0;
const T cy = 100;
const auto y = make_fvar<T, m, n>(cy);
for (auto i : boost::irange(m + 1)) {
for (auto j : boost::irange(n + 1)) {
if (i == 0 && j == 0) {
BOOST_CHECK_EQUAL(y.derivative(i, j), cy);
} else if (i == 0 && j == 1) {
BOOST_CHECK_EQUAL(y.derivative(i, j), 1.0);
BOOST_CHECK_EQUAL(y.derivative(i, j), static_cast<T>(1.0));
} else {
BOOST_CHECK_EQUAL(y.derivative(i, j), 0.0);
BOOST_CHECK_EQUAL(y.derivative(i, j), static_cast<T>(0.0));
}
}
}
@@ -64,16 +64,16 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(implicit_constructors, T, all_float_types) {
const autodiff_fvar<T, m> x = 3;
const autodiff_fvar<T, m> one = uncast_return(x);
const autodiff_fvar<T, m> two_and_a_half = 2.5;
BOOST_CHECK_EQUAL(static_cast<T>(x), 3.0);
BOOST_CHECK_EQUAL(static_cast<T>(one), 1.0);
BOOST_CHECK_EQUAL(static_cast<T>(two_and_a_half), 2.5);
BOOST_CHECK_EQUAL(static_cast<T>(x), static_cast<T>(3.0));
BOOST_CHECK_EQUAL(static_cast<T>(one), static_cast<T>(1.0));
BOOST_CHECK_EQUAL(static_cast<T>(two_and_a_half), static_cast<T>(2.5));
}
BOOST_AUTO_TEST_CASE_TEMPLATE(assignment, T, all_float_types) {
constexpr std::size_t m = 3;
constexpr std::size_t n = 4;
const T cx = 10.0;
const T cy = 10.0;
const T cx = 10;
const T cy = 10;
autodiff_fvar<T, m, n>
empty; // Uninitialized variable<> may have non-zero values.
// Single variable
@@ -132,7 +132,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(ostream, T, all_float_types) {
BOOST_AUTO_TEST_CASE_TEMPLATE(addition_assignment, T, all_float_types) {
constexpr std::size_t m = 3;
constexpr std::size_t n = 4;
const T cx = 10.0;
const T cx = 10;
auto sum = autodiff_fvar<T, m, n>(); // zero-initialized
// Single variable
const auto x = make_fvar<T, m>(cx);
@@ -142,14 +142,14 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(addition_assignment, T, all_float_types) {
if (i == 0 && j == 0) {
BOOST_CHECK_EQUAL(sum.derivative(i, j), cx);
} else if (i == 1 && j == 0) {
BOOST_CHECK_EQUAL(sum.derivative(i, j), 1.0);
BOOST_CHECK_EQUAL(sum.derivative(i, j), T(1));
} else {
BOOST_CHECK_EQUAL(sum.derivative(i, j), 0.0);
BOOST_CHECK_EQUAL(sum.derivative(i, j), T(0));
}
}
}
// Arithmetic constant
const T cy = 11.0;
const T cy = 11;
sum = 0;
sum += cy;
for (auto i : boost::irange(m + 1)) {
@@ -157,7 +157,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(addition_assignment, T, all_float_types) {
if (i == 0 && j == 0) {
BOOST_CHECK_EQUAL(sum.derivative(i, j), cy);
} else {
BOOST_CHECK_EQUAL(sum.derivative(i, j), 0.0);
BOOST_CHECK_EQUAL(sum.derivative(i, j), T(0));
}
}
}
@@ -166,7 +166,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(addition_assignment, T, all_float_types) {
BOOST_AUTO_TEST_CASE_TEMPLATE(subtraction_assignment, T, all_float_types) {
constexpr std::size_t m = 3;
constexpr std::size_t n = 4;
const T cx = 10.0;
const T cx = 10;
auto sum = autodiff_fvar<T, m, n>(); // zero-initialized
// Single variable
const auto x = make_fvar<T, m>(cx);
@@ -176,14 +176,14 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(subtraction_assignment, T, all_float_types) {
if (i == 0 && j == 0) {
BOOST_CHECK_EQUAL(sum.derivative(i, j), -cx);
} else if (i == 1 && j == 0) {
BOOST_CHECK_EQUAL(sum.derivative(i, j), -1.0);
BOOST_CHECK_EQUAL(sum.derivative(i, j), T(-1));
} else {
BOOST_CHECK_EQUAL(sum.derivative(i, j), 0.0);
BOOST_CHECK_EQUAL(sum.derivative(i, j), T(0));
}
}
}
// Arithmetic constant
const T cy = 11.0;
const T cy = 11;
sum = 0;
sum -= cy;
for (auto i : boost::irange(m + 1)) {
@@ -191,7 +191,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(subtraction_assignment, T, all_float_types) {
if (i == 0 && j == 0) {
BOOST_CHECK_EQUAL(sum.derivative(i, j), -cy);
} else {
BOOST_CHECK_EQUAL(sum.derivative(i, j), 0.0);
BOOST_CHECK_EQUAL(sum.derivative(i, j), T(0));
}
}
}
@@ -202,7 +202,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(multiplication_assignment, T, all_float_types) {
// extra lines.
constexpr std::size_t m = 3;
constexpr std::size_t n = 4;
const T cx = 10.0;
const T cx = 10;
auto product = autodiff_fvar<T, m, n>(1); // unit constant
// Single variable
auto x = make_fvar<T, m>(cx);
@@ -212,14 +212,14 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(multiplication_assignment, T, all_float_types) {
if (i == 0 && j == 0) {
BOOST_CHECK_EQUAL(product.derivative(i, j), cx);
} else if (i == 1 && j == 0) {
BOOST_CHECK_EQUAL(product.derivative(i, j), 1.0);
BOOST_CHECK_EQUAL(product.derivative(i, j), T(1));
} else {
BOOST_CHECK_EQUAL(product.derivative(i, j), 0.0);
BOOST_CHECK_EQUAL(product.derivative(i, j), T(0));
}
}
}
// Arithmetic constant
const T cy = 11.0;
const T cy = 11;
product = 1;
product *= cy;
for (auto i : boost::irange(m + 1)) {
@@ -227,12 +227,12 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(multiplication_assignment, T, all_float_types) {
if (i == 0 && j == 0) {
BOOST_CHECK_EQUAL(product.derivative(i, j), cy);
} else {
BOOST_CHECK_EQUAL(product.derivative(i, j), 0.0);
BOOST_CHECK_EQUAL(product.derivative(i, j), T(0));
}
}
}
// 0 * inf = nan
x = make_fvar<T, m>(0.0);
x = make_fvar<T, m>(T(0.0));
x *= std::numeric_limits<T>::infinity();
// std::cout << "x = " << x << std::endl;
for (auto i : boost::irange(m + 1)) {
@@ -251,7 +251,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(multiplication_assignment, T, all_float_types) {
BOOST_AUTO_TEST_CASE_TEMPLATE(division_assignment, T, all_float_types) {
constexpr std::size_t m = 3;
constexpr std::size_t n = 4;
const T cx = 16.0;
const T cx = 16;
auto quotient = autodiff_fvar<T, m, n>(1); // unit constant
// Single variable
const auto x = make_fvar<T, m>(cx);
@@ -262,11 +262,11 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(division_assignment, T, all_float_types) {
BOOST_CHECK_EQUAL(quotient.derivative(3, 0), -6 / pow(cx, 4));
for (auto i : boost::irange(m + 1)) {
for (auto j : boost::irange(std::size_t(1), n + 1)) {
BOOST_CHECK_EQUAL(quotient.derivative(i, j), 0.0);
BOOST_CHECK_EQUAL(quotient.derivative(i, j), T(0));
}
}
// Arithmetic constant
const T cy = 32.0;
const T cy = 32;
quotient = 1;
quotient /= cy;
for (auto i : boost::irange(m + 1)) {
@@ -274,7 +274,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(division_assignment, T, all_float_types) {
if (i == 0 && j == 0) {
BOOST_CHECK_EQUAL(quotient.derivative(i, j), 1 / cy);
} else {
BOOST_CHECK_EQUAL(quotient.derivative(i, j), 0.0);
BOOST_CHECK_EQUAL(quotient.derivative(i, j), T(0));
}
}
}
@@ -283,7 +283,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(division_assignment, T, all_float_types) {
BOOST_AUTO_TEST_CASE_TEMPLATE(unary_signs, T, all_float_types) {
constexpr std::size_t m = 3;
constexpr std::size_t n = 4;
const T cx = 16.0;
const T cx = 16;
autodiff_fvar<T, m, n> lhs;
// Single variable
const auto x = make_fvar<T, m>(cx);
@@ -293,9 +293,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(unary_signs, T, all_float_types) {
if (i == 0 && j == 0) {
BOOST_CHECK_EQUAL(lhs.derivative(i, j), -cx);
} else if (i == 1 && j == 0) {
BOOST_CHECK_EQUAL(lhs.derivative(i, j), -1.0);
BOOST_CHECK_EQUAL(lhs.derivative(i, j), T(-1));
} else {
BOOST_CHECK_EQUAL(lhs.derivative(i, j), 0.0);
BOOST_CHECK_EQUAL(lhs.derivative(i, j), T(0));
}
}
}
@@ -305,9 +305,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(unary_signs, T, all_float_types) {
if (i == 0 && j == 0) {
BOOST_CHECK_EQUAL(lhs.derivative(i, j), cx);
} else if (i == 1 && j == 0) {
BOOST_CHECK_EQUAL(lhs.derivative(i, j), 1.0);
BOOST_CHECK_EQUAL(lhs.derivative(i, j), T(1));
} else {
BOOST_CHECK_EQUAL(lhs.derivative(i, j), 0.0);
BOOST_CHECK_EQUAL(lhs.derivative(i, j), T(0));
}
}
}
@@ -324,7 +324,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(cast_double, T, all_float_types) {
}
BOOST_AUTO_TEST_CASE_TEMPLATE(int_double_casting, T, all_float_types) {
const T ca = 3.0;
const T ca = 3;
const auto x0 = make_fvar<T, 0>(ca);
BOOST_CHECK_EQUAL(static_cast<T>(x0), ca);
const auto x1 = make_fvar<T, 1>(ca);
@@ -334,8 +334,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(int_double_casting, T, all_float_types) {
}
BOOST_AUTO_TEST_CASE_TEMPLATE(scalar_addition, T, all_float_types) {
const T ca = 3.0;
const T cb = 4.0;
const T ca = 3;
const T cb = 4;
const auto sum0 = autodiff_fvar<T, 0>(ca) + autodiff_fvar<T, 0>(cb);
BOOST_CHECK_EQUAL(ca + cb, static_cast<T>(sum0));
const auto sum1 = autodiff_fvar<T, 0>(ca) + cb;
@@ -346,7 +346,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(scalar_addition, T, all_float_types) {
BOOST_AUTO_TEST_CASE_TEMPLATE(power8, T, all_float_types) {
constexpr std::size_t n = 8u;
const T ca = 3.0;
const T ca = 3;
auto x = make_fvar<T, n>(ca);
// Test operator*=()
x *= x;
@@ -366,10 +366,10 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(power8, T, all_float_types) {
x = x * x * x * x * x * x * x * x;
for (auto i : boost::irange(n + 1)) {
BOOST_CHECK_CLOSE(
x.derivative(i),
power_factorial /
static_cast<T>(x.derivative(i)),
static_cast<T>(power_factorial /
boost::math::factorial<T>(static_cast<unsigned>(n - i)) *
pow(ca, n - i),
pow(ca, n - i)),
std::numeric_limits<T>::epsilon());
}
}
@@ -377,14 +377,14 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(power8, T, all_float_types) {
BOOST_AUTO_TEST_CASE_TEMPLATE(dim1_multiplication, T, all_float_types) {
constexpr std::size_t m = 2;
constexpr std::size_t n = 3;
const T cy = 4.0;
const T cy = 4;
auto y0 = make_fvar<T, m>(cy);
auto y = make_fvar<T, n>(cy);
y *= y0;
BOOST_CHECK_EQUAL(y.derivative(0), cy * cy);
BOOST_CHECK_EQUAL(y.derivative(1), 2 * cy);
BOOST_CHECK_EQUAL(y.derivative(2), 2.0);
BOOST_CHECK_EQUAL(y.derivative(3), 0.0);
BOOST_CHECK_EQUAL(y.derivative(2), T(2));
BOOST_CHECK_EQUAL(y.derivative(3), T(0));
y = y * cy;
BOOST_CHECK_EQUAL(y.derivative(0), cy * cy * cy);
BOOST_CHECK_EQUAL(y.derivative(1), 2 * cy * cy);
@@ -395,21 +395,21 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(dim1_multiplication, T, all_float_types) {
BOOST_AUTO_TEST_CASE_TEMPLATE(dim1and2_multiplication, T, all_float_types) {
constexpr std::size_t m = 2;
constexpr std::size_t n = 3;
const T cx = 3.0;
const T cy = 4.0;
const T cx = 3;
const T cy = 4;
auto x = make_fvar<T, m>(cx);
auto y = make_fvar<T, m, n>(cy);
y *= x;
BOOST_CHECK_EQUAL(y.derivative(0, 0), cx * cy);
BOOST_CHECK_EQUAL(y.derivative(0, 1), cx);
BOOST_CHECK_EQUAL(y.derivative(1, 0), cy);
BOOST_CHECK_EQUAL(y.derivative(1, 1), 1.0);
BOOST_CHECK_EQUAL(y.derivative(1, 1), T(1));
for (auto i : boost::irange(std::size_t(1), m)) {
for (auto j : boost::irange(std::size_t(1), n)) {
if (i == 1 && j == 1) {
BOOST_CHECK_EQUAL(y.derivative(i, j), 1.0);
BOOST_CHECK_EQUAL(y.derivative(i, j), T(1));
} else {
BOOST_CHECK_EQUAL(y.derivative(i, j), 0.0);
BOOST_CHECK_EQUAL(y.derivative(i, j), T(0));
}
}
}
@@ -418,89 +418,89 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(dim1and2_multiplication, T, all_float_types) {
BOOST_AUTO_TEST_CASE_TEMPLATE(dim2_addition, T, all_float_types) {
constexpr std::size_t m = 2;
constexpr std::size_t n = 3;
const T cx = 3.0;
const T cx = 3;
const auto x = make_fvar<T, m>(cx);
BOOST_CHECK_EQUAL(x.derivative(0), cx);
BOOST_CHECK_EQUAL(x.derivative(1), 1.0);
BOOST_CHECK_EQUAL(x.derivative(1), T(1));
BOOST_CHECK_EQUAL(x.derivative(2), 0.0);
const T cy = 4.0;
const T cy = 4;
const auto y = make_fvar<T, m, n>(cy);
BOOST_CHECK_EQUAL(static_cast<T>(y.derivative(0)), cy);
BOOST_CHECK_EQUAL(static_cast<T>(y.derivative(1)),
0.0); // partial of y w.r.t. x.
BOOST_CHECK_EQUAL(y.derivative(0, 0), cy);
BOOST_CHECK_EQUAL(y.derivative(0, 1), 1.0);
BOOST_CHECK_EQUAL(y.derivative(0, 1), T(1));
BOOST_CHECK_EQUAL(y.derivative(1, 0), 0.0);
BOOST_CHECK_EQUAL(y.derivative(1, 1), 0.0);
const auto z = x + y;
BOOST_CHECK_EQUAL(z.derivative(0, 0), cx + cy);
BOOST_CHECK_EQUAL(z.derivative(0, 1), 1.0);
BOOST_CHECK_EQUAL(z.derivative(1, 0), 1.0);
BOOST_CHECK_EQUAL(z.derivative(0, 1), T(1));
BOOST_CHECK_EQUAL(z.derivative(1, 0), T(1));
BOOST_CHECK_EQUAL(z.derivative(1, 1), 0.0);
// The following 4 are unnecessarily more expensive than the previous 4.
BOOST_CHECK_EQUAL(z.derivative(0).derivative(0), cx + cy);
BOOST_CHECK_EQUAL(z.derivative(0).derivative(1), 1.0);
BOOST_CHECK_EQUAL(z.derivative(1).derivative(0), 1.0);
BOOST_CHECK_EQUAL(z.derivative(0).derivative(1), T(1));
BOOST_CHECK_EQUAL(z.derivative(1).derivative(0), T(1));
BOOST_CHECK_EQUAL(z.derivative(1).derivative(1), 0.0);
}
BOOST_AUTO_TEST_CASE_TEMPLATE(dim2_multiplication, T, all_float_types) {
constexpr std::size_t m = 3;
constexpr std::size_t n = 4;
const T cx = 6.0;
const T cx = 6;
const auto x = make_fvar<T, m>(cx);
const T cy = 5.0;
const T cy = 5;
const auto y = make_fvar<T, 0, n>(cy);
const auto z = x * x * y * y * y;
BOOST_CHECK_EQUAL(z.derivative(0, 0), cx * cx * cy * cy * cy); // x^2 * y^3
BOOST_CHECK_EQUAL(z.derivative(0, 1), cx * cx * 3 * cy * cy); // x^2 * 3y^2
BOOST_CHECK_EQUAL(z.derivative(0, 2), cx * cx * 6 * cy); // x^2 * 6y
BOOST_CHECK_EQUAL(z.derivative(0, 3), cx * cx * 6); // x^2 * 6
BOOST_CHECK_EQUAL(z.derivative(0, 4), 0.0); // x^2 * 0
BOOST_CHECK_EQUAL(z.derivative(0, 4), T(0)); // x^2 * 0
BOOST_CHECK_EQUAL(z.derivative(1, 0), 2 * cx * cy * cy * cy); // 2x * y^3
BOOST_CHECK_EQUAL(z.derivative(1, 1), 2 * cx * 3 * cy * cy); // 2x * 3y^2
BOOST_CHECK_EQUAL(z.derivative(1, 2), 2 * cx * 6 * cy); // 2x * 6y
BOOST_CHECK_EQUAL(z.derivative(1, 3), 2 * cx * 6); // 2x * 6
BOOST_CHECK_EQUAL(z.derivative(1, 4), 0.0); // 2x * 0
BOOST_CHECK_EQUAL(z.derivative(1, 4), T(0)); // 2x * 0
BOOST_CHECK_EQUAL(z.derivative(2, 0), 2 * cy * cy * cy); // 2 * y^3
BOOST_CHECK_EQUAL(z.derivative(2, 1), 2 * 3 * cy * cy); // 2 * 3y^2
BOOST_CHECK_EQUAL(z.derivative(2, 2), 2 * 6 * cy); // 2 * 6y
BOOST_CHECK_EQUAL(z.derivative(2, 3), 2 * 6); // 2 * 6
BOOST_CHECK_EQUAL(z.derivative(2, 4), 0.0); // 2 * 0
BOOST_CHECK_EQUAL(z.derivative(3, 0), 0.0); // 0 * y^3
BOOST_CHECK_EQUAL(z.derivative(3, 1), 0.0); // 0 * 3y^2
BOOST_CHECK_EQUAL(z.derivative(3, 2), 0.0); // 0 * 6y
BOOST_CHECK_EQUAL(z.derivative(3, 3), 0.0); // 0 * 6
BOOST_CHECK_EQUAL(z.derivative(3, 4), 0.0); // 0 * 0
BOOST_CHECK_EQUAL(z.derivative(2, 4), T(0)); // 2 * 0
BOOST_CHECK_EQUAL(z.derivative(3, 0), T(0)); // 0 * y^3
BOOST_CHECK_EQUAL(z.derivative(3, 1), T(0)); // 0 * 3y^2
BOOST_CHECK_EQUAL(z.derivative(3, 2), T(0)); // 0 * 6y
BOOST_CHECK_EQUAL(z.derivative(3, 3), T(0)); // 0 * 6
BOOST_CHECK_EQUAL(z.derivative(3, 4), T(0)); // 0 * 0
}
BOOST_AUTO_TEST_CASE_TEMPLATE(dim2_multiplication_and_subtraction, T,
all_float_types) {
constexpr std::size_t m = 3;
constexpr std::size_t n = 4;
const T cx = 6.0;
const T cx = 6;
const auto x = make_fvar<T, m>(cx);
const T cy = 5.0;
const T cy = 5;
const auto y = make_fvar<T, 0, n>(cy);
const auto z = x * x - y * y;
BOOST_CHECK_EQUAL(z.derivative(0, 0), cx * cx - cy * cy);
BOOST_CHECK_EQUAL(z.derivative(0, 1), -2 * cy);
BOOST_CHECK_EQUAL(z.derivative(0, 2), -2.0);
BOOST_CHECK_EQUAL(z.derivative(0, 3), 0.0);
BOOST_CHECK_EQUAL(z.derivative(0, 4), 0.0);
BOOST_CHECK_EQUAL(z.derivative(0, 2), T(-2));
BOOST_CHECK_EQUAL(z.derivative(0, 3), T(0));
BOOST_CHECK_EQUAL(z.derivative(0, 4), T(0));
BOOST_CHECK_EQUAL(z.derivative(1, 0), 2 * cx);
BOOST_CHECK_EQUAL(z.derivative(2, 0), 2.0);
BOOST_CHECK_EQUAL(z.derivative(2, 0), T(2));
for (auto i : boost::irange(std::size_t(1), m + 1)) {
for (auto j : boost::irange(std::size_t(1), n + 1)) {
BOOST_CHECK_EQUAL(z.derivative(i, j), 0.0);
BOOST_CHECK_EQUAL(z.derivative(i, j), T(0));
}
}
}
BOOST_AUTO_TEST_CASE_TEMPLATE(inverse, T, all_float_types) {
constexpr std::size_t m = 3;
const T cx = 4.0;
const T cx = 4;
const auto x = make_fvar<T, m>(cx);
const auto xinv = x.inverse();
BOOST_CHECK_EQUAL(xinv.derivative(0), 1 / cx);
@@ -519,9 +519,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(inverse, T, all_float_types) {
BOOST_AUTO_TEST_CASE_TEMPLATE(division, T, all_float_types) {
constexpr std::size_t m = 3;
constexpr std::size_t n = 4;
const T cx = 16.0;
const T cx = 16;
auto x = make_fvar<T, m>(cx);
const T cy = 4.0;
const T cy = 4;
auto y = make_fvar<T, 1, n>(cy);
auto z = x * x / (y * y);
BOOST_CHECK_EQUAL(z.derivative(0, 0), cx * cx / (cy * cy)); // x^2 * y^-2
@@ -581,8 +581,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(division, T, all_float_types) {
BOOST_AUTO_TEST_CASE_TEMPLATE(equality, T, all_float_types) {
constexpr std::size_t m = 3;
constexpr std::size_t n = 4;
const T cx = 10.0;
const T cy = 10.0;
const T cx = 10;
const T cy = 10;
const auto x = make_fvar<T, m>(cx);
const auto y = make_fvar<T, 0, n>(cy);
BOOST_CHECK_EQUAL(x, y);
@@ -595,8 +595,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(equality, T, all_float_types) {
BOOST_AUTO_TEST_CASE_TEMPLATE(inequality, T, all_float_types) {
constexpr std::size_t m = 3;
constexpr std::size_t n = 4;
const T cx = 10.0;
const T cy = 11.0;
const T cx = 10;
const T cy = 11;
const auto x = make_fvar<T, m>(cx);
const auto y = make_fvar<T, 0, n>(cy);
BOOST_CHECK_NE(x, y);
@@ -609,8 +609,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(inequality, T, all_float_types) {
BOOST_AUTO_TEST_CASE_TEMPLATE(less_than_or_equal_to, T, all_float_types) {
constexpr std::size_t m = 3;
constexpr std::size_t n = 4;
const T cx = 10.0;
const T cy = 11.0;
const T cx = 10;
const T cy = 11;
const auto x = make_fvar<T, m>(cx);
const auto y = make_fvar<T, 0, n>(cy);
BOOST_CHECK_LE(x, y);
@@ -627,8 +627,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(less_than_or_equal_to, T, all_float_types) {
BOOST_AUTO_TEST_CASE_TEMPLATE(greater_than_or_equal_to, T, all_float_types) {
constexpr std::size_t m = 3;
constexpr std::size_t n = 4;
const T cx = 11.0;
const T cy = 10.0;
const T cx = 11;
const T cy = 10;
const auto x = make_fvar<T, m>(cx);
const auto y = make_fvar<T, 0, n>(cy);
BOOST_CHECK_GE(x, y);
@@ -647,28 +647,28 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(fabs_test, T, all_float_types) {
using detail::fabs;
using std::fabs;
constexpr std::size_t m = 3;
const T cx = 11.0;
const T cx = 11;
const auto x = make_fvar<T, m>(cx);
auto a = fabs(x);
BOOST_CHECK_EQUAL(a.derivative(0), fabs(cx));
BOOST_CHECK_EQUAL(a.derivative(1), 1.0);
BOOST_CHECK_EQUAL(a.derivative(2), 0.0);
BOOST_CHECK_EQUAL(a.derivative(3), 0.0);
BOOST_CHECK_EQUAL(a.derivative(1), T(1));
BOOST_CHECK_EQUAL(a.derivative(2), T(0));
BOOST_CHECK_EQUAL(a.derivative(3), T(0));
a = fabs(-x);
BOOST_CHECK_EQUAL(a.derivative(0), fabs(cx));
BOOST_CHECK_EQUAL(a.derivative(1), 1.0); // fabs(-x) = fabs(x)
BOOST_CHECK_EQUAL(a.derivative(2), 0.0);
BOOST_CHECK_EQUAL(a.derivative(3), 0.0);
BOOST_CHECK_EQUAL(a.derivative(1), T(1)); // fabs(-x) = fabs(x)
BOOST_CHECK_EQUAL(a.derivative(2), T(0));
BOOST_CHECK_EQUAL(a.derivative(3), T(0));
const auto xneg = make_fvar<T, m>(-cx);
a = fabs(xneg);
BOOST_CHECK_EQUAL(a.derivative(0), fabs(cx));
BOOST_CHECK_EQUAL(a.derivative(1), -1.0);
BOOST_CHECK_EQUAL(a.derivative(2), 0.0);
BOOST_CHECK_EQUAL(a.derivative(3), 0.0);
BOOST_CHECK_EQUAL(a.derivative(1), -T(1));
BOOST_CHECK_EQUAL(a.derivative(2), T(0));
BOOST_CHECK_EQUAL(a.derivative(3), T(0));
const auto zero = make_fvar<T, m>(0);
a = fabs(zero);
for (auto i : boost::irange(m + 1)) {
BOOST_CHECK_EQUAL(a.derivative(i), 0.0);
BOOST_CHECK_EQUAL(a.derivative(i), T(0));
}
}
@@ -678,7 +678,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(ceil_and_floor, T, all_float_types) {
using std::ceil;
using std::floor;
constexpr std::size_t m = 3;
T tests[]{-1.5, 0.0, 1.5};
T tests[]{T(-1.5), T(0.0), T(1.5)};
for (T &test : tests) {
const auto x = make_fvar<T, m>(test);
auto c = ceil(x);
@@ -686,8 +686,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(ceil_and_floor, T, all_float_types) {
BOOST_CHECK_EQUAL(c.derivative(0), ceil(test));
BOOST_CHECK_EQUAL(f.derivative(0), floor(test));
for (auto i : boost::irange(std::size_t(1), m + 1)) {
BOOST_CHECK_EQUAL(c.derivative(i), 0.0);
BOOST_CHECK_EQUAL(f.derivative(i), 0.0);
BOOST_CHECK_EQUAL(c.derivative(i), T(0));
BOOST_CHECK_EQUAL(f.derivative(i), T(0));
}
}
}

View File

@@ -15,9 +15,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(one_over_one_plus_x_squared, T, all_float_types) {
f *= f;
f += T(1);
f = f.inverse();
BOOST_CHECK_EQUAL(f.derivative(0u), 0.5);
BOOST_CHECK_EQUAL(f.derivative(1u), -0.5);
BOOST_CHECK_EQUAL(f.derivative(2u), 0.5);
BOOST_CHECK_EQUAL(f.derivative(0u), T(0.5));
BOOST_CHECK_EQUAL(f.derivative(1u), T(-0.5));
BOOST_CHECK_EQUAL(f.derivative(2u), T(0.5));
BOOST_CHECK_EQUAL(f.derivative(3u), 0);
BOOST_CHECK_EQUAL(f.derivative(4u), -3);
}
@@ -25,14 +25,14 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(one_over_one_plus_x_squared, T, all_float_types) {
BOOST_AUTO_TEST_CASE_TEMPLATE(exp_test, T, all_float_types) {
using std::exp;
constexpr std::size_t m = 4;
const T cx = 2.0;
const T cx = 2;
const auto x = make_fvar<T, m>(cx);
auto y = exp(x);
for (auto i : boost::irange(m + 1)) {
// std::cout.precision(100);
// std::cout << "y.derivative("<<i<<") = " << y.derivative(i) << ",
// std::exp(cx) = " << std::exp(cx) << std::endl;
BOOST_CHECK_CLOSE_FRACTION(y.derivative(i), exp(cx),
BOOST_CHECK_CLOSE_FRACTION(static_cast<T>(y.derivative(i)), static_cast<T>(exp(cx)),
std::numeric_limits<T>::epsilon());
}
}
@@ -43,8 +43,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(pow, T, bin_float_types) {
using std::pow;
constexpr std::size_t m = 5;
constexpr std::size_t n = 4;
const T cx = 2.0;
const T cy = 3.0;
const T cx = 2;
const T cy = 3;
const auto x = make_fvar<T, m>(cx);
const auto y = make_fvar<T, m, n>(cy);
auto z0 = pow(x, cy);
@@ -98,13 +98,11 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(pow, T, bin_float_types) {
}
BOOST_AUTO_TEST_CASE_TEMPLATE(pow0, T, bin_float_types) {
const T eps = 201 * std::numeric_limits<T>::epsilon(); // percent
using std::pow;
constexpr std::size_t m = 5;
constexpr std::size_t n = 4;
const T cx = 0.0;
const T cx = 0;
{
const T cy = 3.0;
const T cy = 3;
const auto x = make_fvar<T, m>(cx);
auto z0 = pow(x, cy);
BOOST_CHECK_EQUAL(z0.derivative(0u), pow(cx, cy));
@@ -116,7 +114,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(pow0, T, bin_float_types) {
BOOST_CHECK_EQUAL(z0.derivative(5u), 0u);
}
{
const T cy = 3.5;
const T cy = T(3.5);
const auto x = make_fvar<T, m>(cx);
auto z0 = pow(x, cy);
BOOST_CHECK_EQUAL(z0.derivative(0u), pow(cx, cy));
@@ -138,7 +136,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(pow2, T, bin_float_types) {
constexpr std::size_t m = 5;
constexpr std::size_t n = 5;
const T cx = 2;
const T cy = 5 / 2.0;
const T cy = 5 / T(2);
const auto x = make_fvar<T, m>(cx);
const auto y = make_fvar<T, 0, n>(cy);
const auto z = pow(x, y);
@@ -244,22 +242,22 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(sqrt_test, T, all_float_types) {
using std::pow;
using std::sqrt;
constexpr std::size_t m = 5;
const T cx = 4.0;
const T cx = 4;
auto x = make_fvar<T, m>(cx);
auto y = sqrt(x);
BOOST_CHECK_CLOSE_FRACTION(y.derivative(0u), sqrt(cx),
BOOST_CHECK_CLOSE_FRACTION(y.derivative(0u), static_cast<T>(sqrt(cx)),
std::numeric_limits<T>::epsilon());
BOOST_CHECK_CLOSE_FRACTION(y.derivative(1u), 0.5 * pow(cx, -0.5),
BOOST_CHECK_CLOSE_FRACTION(y.derivative(1u), static_cast<T>(0.5 * pow(cx, T(-0.5))),
std::numeric_limits<T>::epsilon());
BOOST_CHECK_CLOSE_FRACTION(y.derivative(2u), -0.5 * 0.5 * pow(cx, -1.5),
BOOST_CHECK_CLOSE_FRACTION(y.derivative(2u), static_cast<T>(-0.5 * 0.5 * pow(cx, -1.5)),
std::numeric_limits<T>::epsilon());
BOOST_CHECK_CLOSE_FRACTION(y.derivative(3u), 0.5 * 0.5 * 1.5 * pow(cx, -2.5),
BOOST_CHECK_CLOSE_FRACTION(y.derivative(3u), static_cast<T>(0.5 * 0.5 * 1.5 * pow(cx, -2.5)),
std::numeric_limits<T>::epsilon());
BOOST_CHECK_CLOSE_FRACTION(y.derivative(4u),
-0.5 * 0.5 * 1.5 * 2.5 * pow(cx, -3.5),
static_cast<T>(-0.5 * 0.5 * 1.5 * 2.5 * pow(cx, -3.5)),
std::numeric_limits<T>::epsilon());
BOOST_CHECK_CLOSE_FRACTION(y.derivative(5u),
0.5 * 0.5 * 1.5 * 2.5 * 3.5 * pow(cx, -4.5),
static_cast<T>(0.5 * 0.5 * 1.5 * 2.5 * 3.5 * pow(cx, -4.5)),
std::numeric_limits<T>::epsilon());
x = make_fvar<T, m>(0);
y = sqrt(x);
@@ -275,7 +273,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(log_test, T, all_float_types) {
using std::log;
using std::pow;
constexpr std::size_t m = 5;
const T cx = 2.0;
const T cx = 2;
auto x = make_fvar<T, m>(cx);
auto y = log(x);
BOOST_CHECK_CLOSE_FRACTION(y.derivative(0u), log(cx),
@@ -306,8 +304,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(ylogx, T, all_float_types) {
const T eps = (std::numeric_limits<T>::digits > 100 ? 300 : 100) * std::numeric_limits<T>::epsilon(); // percent
constexpr std::size_t m = 5;
constexpr std::size_t n = 4;
const T cx = 2.0;
const T cy = 3.0;
const T cx = 2;
const T cy = 3;
const auto x = make_fvar<T, m>(cx);
const auto y = make_fvar<T, m, n>(cy);
auto z = y * log(x);
@@ -342,7 +340,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(frexp_test, T, all_float_types) {
using std::exp2;
using std::frexp;
constexpr std::size_t m = 3;
const T cx = 3.5;
const T cx = T(3.5);
const auto x = make_fvar<T, m>(cx);
int exp, testexp;
auto y = frexp(x, &exp);
@@ -357,7 +355,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(ldexp_test, T, all_float_types) {
BOOST_MATH_STD_USING
using boost::multiprecision::ldexp;
constexpr auto m = 3u;
const T cx = 3.5;
const T cx = T(3.5);
const auto x = make_fvar<T, m>(cx);
constexpr auto exponent = 3;
auto y = ldexp(x, exponent);
@@ -401,18 +399,18 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(acos_test, T, bin_float_types) {
using std::pow;
using std::sqrt;
constexpr std::size_t m = 5;
const T cx = 0.5;
const T cx = T(0.5);
auto x = make_fvar<T, m>(cx);
auto y = acos(x);
BOOST_CHECK_CLOSE(y.derivative(0u), acos(cx), eps);
BOOST_CHECK_CLOSE(y.derivative(1u), -1 / sqrt(1 - cx * cx), eps);
BOOST_CHECK_CLOSE(y.derivative(2u), -cx / pow(1 - cx * cx, 1.5), eps);
BOOST_CHECK_CLOSE(y.derivative(2u), static_cast<T>(-cx / pow(1 - cx * cx, 1.5)), eps);
BOOST_CHECK_CLOSE(y.derivative(3u),
-(2 * cx * cx + 1) / pow(1 - cx * cx, 2.5), eps);
static_cast<T>(-(2 * cx * cx + 1) / pow(1 - cx * cx, 2.5)), eps);
BOOST_CHECK_CLOSE(y.derivative(4u),
-3 * cx * (2 * cx * cx + 3) / pow(1 - cx * cx, 3.5), eps);
static_cast<T>(-3 * cx * (2 * cx * cx + 3) / pow(1 - cx * cx, 3.5)), eps);
BOOST_CHECK_CLOSE(y.derivative(5u),
-(24 * (cx * cx + 3) * cx * cx + 9) / pow(1 - cx * cx, 4.5),
static_cast<T>(-(24 * (cx * cx + 3) * cx * cx + 9) / pow(1 - cx * cx, 4.5)),
eps);
}
@@ -445,18 +443,18 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(asin_test, T, bin_float_types) {
using std::pow;
using std::sqrt;
constexpr std::size_t m = 5;
const T cx = 0.5;
const T cx = T(0.5);
auto x = make_fvar<T, m>(cx);
auto y = asin(x);
BOOST_CHECK_CLOSE(y.derivative(0u), asin(static_cast<T>(x)), eps);
BOOST_CHECK_CLOSE(y.derivative(1u), 1 / sqrt(1 - cx * cx), eps);
BOOST_CHECK_CLOSE(y.derivative(2u), cx / pow(1 - cx * cx, 1.5), eps);
BOOST_CHECK_CLOSE(y.derivative(3u), (2 * cx * cx + 1) / pow(1 - cx * cx, 2.5),
BOOST_CHECK_CLOSE(y.derivative(2u), cx / pow(1 - cx * cx, T(1.5)), eps);
BOOST_CHECK_CLOSE(y.derivative(3u), (2 * cx * cx + 1) / pow(1 - cx * cx, T(2.5)),
eps);
BOOST_CHECK_CLOSE(y.derivative(4u),
3 * cx * (2 * cx * cx + 3) / pow(1 - cx * cx, 3.5), eps);
3 * cx * (2 * cx * cx + 3) / pow(1 - cx * cx, T(3.5)), eps);
BOOST_CHECK_CLOSE(y.derivative(5u),
(24 * (cx * cx + 3) * cx * cx + 9) / pow(1 - cx * cx, 4.5),
(24 * (cx * cx + 3) * cx * cx + 9) / pow(1 - cx * cx, T(4.5)),
eps);
}
@@ -477,7 +475,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(asin_derivative, T, bin_float_types) {
using std::pow;
using std::sqrt;
constexpr std::size_t m = 4;
const T cx(0.5);
const T cx = T(0.5);
auto x = make_fvar<T, m>(cx);
auto y = T(1) - x * x;
BOOST_CHECK_EQUAL(y.derivative(0u), 1 - cx * cx);
@@ -488,19 +486,19 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(asin_derivative, T, bin_float_types) {
y = sqrt(y);
BOOST_CHECK_EQUAL(y.derivative(0u), sqrt(1 - cx * cx));
BOOST_CHECK_CLOSE(y.derivative(1u), -cx / sqrt(1 - cx * cx), eps);
BOOST_CHECK_CLOSE(y.derivative(2u), -1 / pow(1 - cx * cx, 1.5), eps);
BOOST_CHECK_CLOSE(y.derivative(3u), -3 * cx / pow(1 - cx * cx, 2.5), eps);
BOOST_CHECK_CLOSE(y.derivative(2u), -1 / pow(1 - cx * cx, T(1.5)), eps);
BOOST_CHECK_CLOSE(y.derivative(3u), -3 * cx / pow(1 - cx * cx, T(2.5)), eps);
BOOST_CHECK_CLOSE(y.derivative(4u),
-(12 * cx * cx + 3) / pow(1 - cx * cx, 3.5), eps);
-(12 * cx * cx + 3) / pow(1 - cx * cx, T(3.5)), eps);
y = y.inverse(); // asin'(x) = 1 / sqrt(1-x*x).
BOOST_CHECK_CLOSE(y.derivative(0u), 1 / sqrt(1 - cx * cx), eps);
BOOST_CHECK_CLOSE(y.derivative(1u), cx / pow(1 - cx * cx, 1.5), eps);
BOOST_CHECK_CLOSE(y.derivative(2u), (2 * cx * cx + 1) / pow(1 - cx * cx, 2.5),
BOOST_CHECK_CLOSE(y.derivative(1u), cx / pow(1 - cx * cx, T(1.5)), eps);
BOOST_CHECK_CLOSE(y.derivative(2u), (2 * cx * cx + 1) / pow(1 - cx * cx, T(2.5)),
eps);
BOOST_CHECK_CLOSE(y.derivative(3u),
3 * cx * (2 * cx * cx + 3) / pow(1 - cx * cx, 3.5), eps);
3 * cx * (2 * cx * cx + 3) / pow(1 - cx * cx, T(3.5)), eps);
BOOST_CHECK_CLOSE(y.derivative(4u),
(24 * (cx * cx + 3) * cx * cx + 9) / pow(1 - cx * cx, 4.5),
(24 * (cx * cx + 3) * cx * cx + 9) / pow(1 - cx * cx, T(4.5)),
eps);
}

View File

@@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(atan_test, T, all_float_types) {
BOOST_MATH_STD_USING
using namespace boost;
const T cx = 1.0;
const T cx = 1;
constexpr unsigned m = 5;
const auto x = make_fvar<T, m>(cx);
auto y = atan(x);
@@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(erf_test, T, all_float_types) {
using boost::math::erf;
const T eps = 300 * 100 * boost::math::tools::epsilon<T>(); // percent
const T cx = 1.0;
const T cx = 1;
constexpr unsigned m = 5;
const auto x = make_fvar<T, m>(cx);
auto y = erf(x);
@@ -158,8 +158,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(tan_test, T, bin_float_types) {
BOOST_AUTO_TEST_CASE_TEMPLATE(fmod_test, T, bin_float_types) {
BOOST_MATH_STD_USING
constexpr unsigned m = 3;
const T cx = 3.25;
const T cy = 0.5;
const T cx = T(3.25);
const T cy = T(0.5);
auto x = make_fvar<T, m>(cx);
auto y = fmod(x, autodiff_fvar<T, m>(cy));
BOOST_CHECK_EQUAL(y.derivative(0u), T(0.25));
@@ -171,7 +171,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(fmod_test, T, bin_float_types) {
BOOST_AUTO_TEST_CASE_TEMPLATE(round_and_trunc, T, all_float_types) {
BOOST_MATH_STD_USING
constexpr unsigned m = 3;
const T cx = 3.25;
const T cx = T(3.25);
auto x = make_fvar<T, m>(cx);
auto y = round(x);
BOOST_CHECK_EQUAL(y.derivative(0u), round(cx));
@@ -189,7 +189,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(iround_and_itrunc, T, all_float_types) {
BOOST_MATH_STD_USING
using namespace boost::math;
constexpr unsigned m = 3;
const T cx = 3.25;
const T cx = T(3.25);
auto x = make_fvar<T, m>(cx);
int y = iround(x);
BOOST_CHECK_EQUAL(y, iround(cx));
@@ -308,7 +308,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(tgamma2_test, T, all_float_types) {
//const T eps = 5000 * boost::math::tools::epsilon<T>(); // ok for non-multiprecision
const T eps = 500000 * boost::math::tools::epsilon<T>(); // percent
constexpr unsigned m = 10;
const T cx = -1.5;
const T cx = T(-1.5);
// Mathematica: N[Table[D[Gamma[x],{x,n}] /. x->-3/2, {n, 0, 10}], 52]
std::array<T, m + 1> answers{
{BOOST_MATH_TEST_VALUE(T, 2.363271801207354703064223311121526910396732608163183)

View File

@@ -49,7 +49,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(equality, T, all_float_types) {
constexpr std::size_t m = 3;
// check zeros
{
auto x = make_fvar<T, m>(0.0);
auto x = make_fvar<T, m>(T(0));
auto y = T(-0.0);
BOOST_CHECK_EQUAL(x.derivative(0u), y);
}
@@ -162,7 +162,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(atan_hpp, T, all_float_types) {
auto autodiff_v = atan(make_fvar<T, m>(x));
auto anchor_v = atan(x);
BOOST_CHECK_CLOSE(autodiff_v.derivative(0u), anchor_v,
1e3 * test_constants::pct_epsilon());
T(1e3) * test_constants::pct_epsilon());
}
}

View File

@@ -24,11 +24,11 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(ellint_1_hpp, T, all_float_types) {
auto phi = phi_sampler.next();
BOOST_CHECK_CLOSE(boost::math::ellint_1(make_fvar<T, m>(k)).derivative(0u),
boost::math::ellint_1(k),
2.5e3 * test_constants::pct_epsilon());
T(2.5e3) * test_constants::pct_epsilon());
BOOST_CHECK_CLOSE(
boost::math::ellint_1(make_fvar<T, m>(k), make_fvar<T, m>(phi))
.derivative(0u),
boost::math::ellint_1(k, phi), 1e4 * test_constants::pct_epsilon());
boost::math::ellint_1(k, phi), T(1e4) * test_constants::pct_epsilon());
}
}
@@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(ellint_2_hpp, T, all_float_types) {
BOOST_CHECK_CLOSE(
boost::math::ellint_2(make_fvar<T, m>(k), make_fvar<T, m>(phi))
.derivative(0u),
boost::math::ellint_2(k, phi), 2.5e3 * test_constants::pct_epsilon());
boost::math::ellint_2(k, phi), T(2.5e3) * test_constants::pct_epsilon());
}
}
@@ -78,7 +78,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(ellint_3_hpp, T, all_float_types) {
make_fvar<T, m>(phi))
.derivative(0u),
boost::math::ellint_3(k, n, phi),
2.5e3 * test_constants::pct_epsilon());
T(2.5e3) * test_constants::pct_epsilon());
}
}
@@ -94,7 +94,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(ellint_d_hpp, T, all_float_types) {
auto phi = phi_sampler.next();
BOOST_CHECK_CLOSE(boost::math::ellint_d(make_fvar<T, m>(k)).derivative(0u),
boost::math::ellint_d(k),
2.5e3 * test_constants::pct_epsilon());
T(2.5e3) * test_constants::pct_epsilon());
BOOST_CHECK_CLOSE(
boost::math::ellint_d(make_fvar<T, m>(k), make_fvar<T, m>(phi))
.derivative(0u),
@@ -126,7 +126,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(ellint_rf_hpp, T, all_float_types) {
boost::math::ellint_rf(make_fvar<T, m>(x), make_fvar<T, m>(y),
make_fvar<T, m>(z))
.derivative(0u),
boost::math::ellint_rf(x, y, z), 2.5e3 * test_constants::pct_epsilon());
boost::math::ellint_rf(x, y, z), T(2.5e3) * test_constants::pct_epsilon());
}
}
@@ -157,7 +157,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(ellint_rc_hpp, T, all_float_types) {
BOOST_CHECK_CLOSE(
boost::math::ellint_rc(make_fvar<T, m>(x), make_fvar<T, m>(y))
.derivative(0u),
boost::math::ellint_rc(x, y), 2.5e3 * test_constants::pct_epsilon());
boost::math::ellint_rc(x, y), T(2.5e3) * test_constants::pct_epsilon());
}
}
@@ -216,7 +216,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(ellint_rd_hpp, T, all_float_types) {
boost::math::ellint_rd(make_fvar<T, m>(x), make_fvar<T, m>(y),
make_fvar<T, m>(z))
.derivative(0u),
boost::math::ellint_rd(x, y, z), 2.5e3 * test_constants::pct_epsilon());
boost::math::ellint_rd(x, y, z), T(2.5e3) * test_constants::pct_epsilon());
}
}