mirror of
https://github.com/boostorg/math.git
synced 2026-01-19 04:22:09 +00:00
added tests for c++23 <stdfloat>
This commit is contained in:
@@ -411,7 +411,7 @@ private:
|
||||
void make_rvar_from_expr(const expression<RealType, DerivativeOrder, E> &expr)
|
||||
{
|
||||
make_multi_node<detail::count_rvars<E, DerivativeOrder>>();
|
||||
expr.template propagatex<0>(node_, inner_t(1.0));
|
||||
expr.template propagatex<0>(node_, inner_t(static_cast<RealType>(1.0)));
|
||||
}
|
||||
RealType get_item_impl(std::true_type) const
|
||||
{
|
||||
@@ -429,7 +429,7 @@ public:
|
||||
make_leaf_node();
|
||||
}
|
||||
rvar(const RealType value)
|
||||
: value_(inner_t{value})
|
||||
: value_(inner_t{static_cast<RealType>(value)})
|
||||
{
|
||||
make_leaf_node();
|
||||
}
|
||||
@@ -458,6 +458,16 @@ public:
|
||||
value_ = expr.evaluate();
|
||||
make_rvar_from_expr(expr);
|
||||
}
|
||||
|
||||
template<typename T,
|
||||
typename = typename std::enable_if<std::is_same<T, double>::value
|
||||
&& !std::is_same<RealType, double>::value>::type>
|
||||
rvar(T v)
|
||||
: value_(inner_t{static_cast<RealType>(v)})
|
||||
{
|
||||
make_leaf_node();
|
||||
}
|
||||
|
||||
template<class E>
|
||||
rvar &operator=(const expression<RealType, DerivativeOrder, E> &expr)
|
||||
{
|
||||
@@ -560,7 +570,7 @@ public:
|
||||
gradient_tape<RealType, DerivativeOrder, BOOST_MATH_BUFFER_SIZE> &tape
|
||||
= get_active_tape<RealType, DerivativeOrder>();
|
||||
auto it = tape.find(node_);
|
||||
it->update_adjoint_v(inner_t(1.0));
|
||||
it->update_adjoint_v(inner_t(static_cast<RealType>(1.0)));
|
||||
while (it != tape.begin()) {
|
||||
it->backward();
|
||||
--it;
|
||||
|
||||
@@ -39,13 +39,13 @@ struct add_expr : public abstract_binary_expression<RealType,
|
||||
const inner_t & /*r*/,
|
||||
const inner_t & /*v*/)
|
||||
{
|
||||
return inner_t(1.0);
|
||||
return inner_t(static_cast<RealType>(1.0));
|
||||
}
|
||||
static const inner_t right_derivative(const inner_t & /*l*/,
|
||||
const inner_t & /*r*/,
|
||||
const inner_t & /*v*/)
|
||||
{
|
||||
return inner_t(1.0);
|
||||
return inner_t(static_cast<RealType>(1.0));
|
||||
}
|
||||
};
|
||||
template<typename RealType, size_t DerivativeOrder, typename ARG>
|
||||
@@ -70,7 +70,7 @@ struct add_const_expr
|
||||
const inner_t & /*v*/,
|
||||
const RealType & /*constant*/)
|
||||
{
|
||||
return inner_t(1.0);
|
||||
return inner_t(static_cast<RealType>(1.0));
|
||||
}
|
||||
};
|
||||
/****************************************************************************************************************/
|
||||
@@ -164,13 +164,13 @@ struct sub_expr : public abstract_binary_expression<RealType,
|
||||
const inner_t & /*r*/,
|
||||
const inner_t & /*v*/)
|
||||
{
|
||||
return inner_t(1.0);
|
||||
return inner_t(static_cast<RealType>(1.0));
|
||||
}
|
||||
static const inner_t right_derivative(const inner_t & /*l*/,
|
||||
const inner_t & /*r*/,
|
||||
const inner_t & /*v*/)
|
||||
{
|
||||
return inner_t(-1.0);
|
||||
return inner_t(static_cast<RealType>(-1.0));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -50,7 +50,8 @@ struct fabs_expr : public abstract_unary_expression<RealType, DerivativeOrder, A
|
||||
const inner_t & /*v*/,
|
||||
const RealType & /*constant*/)
|
||||
{
|
||||
return argv > 0.0 ? inner_t{1.0} : inner_t{-1.0};
|
||||
return argv > 0.0 ? inner_t{static_cast<RealType>(1.0)}
|
||||
: inner_t{static_cast<RealType>(-1.0)};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -10,6 +10,11 @@
|
||||
#define BOOST_MP_NO_QUAD
|
||||
#define BOOST_MATH_DISABLE_FLOAT128
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
#include <version> // always safe
|
||||
|
||||
#if __has_include(<stdfloat>)
|
||||
#include <stdfloat>
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <boost/math/differentiation/autodiff_reverse.hpp>
|
||||
|
||||
@@ -33,8 +33,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(addition, T, all_float_types)
|
||||
gradient_tape<T, 1>& tape = get_active_tape<T, 1>();
|
||||
tape.zero_grad();
|
||||
test_rvar_p_rvar.backward();
|
||||
BOOST_REQUIRE_EQUAL(x1.adjoint(), 1.0);
|
||||
BOOST_REQUIRE_EQUAL(x2.adjoint(), 1.0);
|
||||
BOOST_REQUIRE_EQUAL(x1.adjoint(), T(1.0));
|
||||
BOOST_REQUIRE_EQUAL(x2.adjoint(), T(1.0));
|
||||
|
||||
tape.zero_grad();
|
||||
rvar<T, 1> z = x1 + x1 + x1 + x1 + x1;
|
||||
@@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(addition, T, all_float_types)
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(multiplication, T, all_float_types)
|
||||
{
|
||||
RandomSample<T> rng{-100, 100};
|
||||
RandomSample<T> rng{T(-100), T(100)};
|
||||
T x1_v = rng.next();
|
||||
T x2_v = rng.next();
|
||||
T test_rvar_p_rvar_v = x1_v * x2_v;
|
||||
@@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(multiplication, T, all_float_types)
|
||||
auto z = x1 * x1 * x1 * x1 * x1;
|
||||
rvar<T, 1> zz(z);
|
||||
zz.backward();
|
||||
BOOST_REQUIRE_CLOSE(x1.adjoint(), 5 * x1_v * x1_v * x1_v * x1_v, boost_close_tol<T>());
|
||||
BOOST_REQUIRE_CLOSE(x1.adjoint(), T(5) * x1_v * x1_v * x1_v * x1_v, boost_close_tol<T>());
|
||||
tape.clear();
|
||||
}
|
||||
|
||||
@@ -278,8 +278,8 @@ std::vector<std::vector<std::vector<std::vector<T>>>> df_4_a(T x, T y)
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(first_derivative, T, all_float_types)
|
||||
{
|
||||
//RandomSample<T> rng{-1, 1};
|
||||
T x = 1.1224; //rng.next();
|
||||
T y = 5.213414; //rng.next();
|
||||
T x(1.1224); //rng.next();
|
||||
T y(5.213414); //rng.next();
|
||||
|
||||
rvar<T, 1> x_ad = x;
|
||||
rvar<T, 1> y_ad = y;
|
||||
|
||||
@@ -9,7 +9,7 @@ BOOST_AUTO_TEST_SUITE(explicit_rvar_constructors)
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(rvar_constructors_and_utils, T, all_float_types)
|
||||
{
|
||||
RandomSample<T> rng{-100, 100};
|
||||
RandomSample<T> rng{T(-100), T(100)};
|
||||
/* raw constructors */
|
||||
T x_value = rng.next();
|
||||
rdiff::rvar<T, 1> x0(x_value);
|
||||
@@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(rvar_constructors_and_utils, T, all_float_types)
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(make_rvar_constructors, T, all_float_types)
|
||||
{
|
||||
RandomSample<T> rng{-100, 100};
|
||||
RandomSample<T> rng{T(-100), T(100)};
|
||||
T x_value = rng.next();
|
||||
|
||||
rdiff::rvar<T,1> x1 = rdiff::make_rvar<T,1>(x_value);
|
||||
@@ -226,9 +226,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(inplace_multiplication, T, all_float_types)
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(inplace_division, T, all_float_types)
|
||||
{
|
||||
using namespace rdiff;
|
||||
RandomSample<T> rng{-1, 1};
|
||||
RandomSample<T> rng{T(-1), T(1)};
|
||||
T x1_v = rng.next();
|
||||
T x2_v = rng.next() + 1e-2;
|
||||
T x2_v = rng.next() + T(1e-2);
|
||||
|
||||
T expected = x1_v / x2_v;
|
||||
|
||||
@@ -255,8 +255,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(inplace_division, T, all_float_types)
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(test_rvar_ostream_output, T, all_float_types)
|
||||
{
|
||||
using namespace rdiff;
|
||||
rvar<T, 1> x = T{2.0};
|
||||
rvar<T, 1> y = T{3.0};
|
||||
rvar<T, 1> x = static_cast<T>(2.0);
|
||||
rvar<T, 1> y = static_cast<T>(3.0);
|
||||
|
||||
rvar<T, 1> z = x * y;
|
||||
z.backward();
|
||||
|
||||
Reference in New Issue
Block a user