Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
run test_classify on autodiff type
  • Loading branch information
ryanelandt committed Aug 21, 2023
commit 4f191e2752e7d62de3be66af6f6c6ba31c8b7744
51 changes: 0 additions & 51 deletions test/test_autodiff_7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,55 +23,4 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(expm1_hpp, T, all_float_types) {
}
}

BOOST_AUTO_TEST_CASE_TEMPLATE(fpclassify_hpp, T, all_float_types) {
using boost::math::fpclassify;
using boost::math::isfinite;
using boost::math::isinf;
using boost::math::isnan;
using boost::math::isnormal;
using boost::multiprecision::fpclassify;
using boost::multiprecision::isfinite;
using boost::multiprecision::isinf;
using boost::multiprecision::isnan;
using boost::multiprecision::isnormal;

using test_constants = test_constants_t<T>;
static constexpr auto m = test_constants::order;
test_detail::RandomSample<T> x_sampler{-1000, 1000};
for (auto i : boost::irange(test_constants::n_samples)) {
std::ignore = i;

BOOST_CHECK_EQUAL(fpclassify(make_fvar<T, m>(0)), FP_ZERO);
BOOST_CHECK_EQUAL(fpclassify(make_fvar<T, m>(10)), FP_NORMAL);
BOOST_CHECK_EQUAL(
fpclassify(make_fvar<T, m>(std::numeric_limits<T>::infinity())),
FP_INFINITE);
BOOST_CHECK_EQUAL(
fpclassify(make_fvar<T, m>(std::numeric_limits<T>::quiet_NaN())),
FP_NAN);
if (std::numeric_limits<T>::has_denorm != std::denorm_absent) {
BOOST_CHECK_EQUAL(
fpclassify(make_fvar<T, m>(std::numeric_limits<T>::denorm_min())),
FP_SUBNORMAL);
} else {
#if 0
// TODO: use when the following gets merged:
// https://github.com/boostorg/multiprecision/pull/562
BOOST_CHECK(make_fvar<T, m>(std::numeric_limits<T>::denorm_min() == make_fvar<T, m>((std::numeric_limits<T>::min)());
#else
// Temporary fix to work irrespective of the above PR
BOOST_CHECK(
(make_fvar<T, m>(0) <= make_fvar<T, m>(std::numeric_limits<T>::denorm_min())) &&
(make_fvar<T, m>(std::numeric_limits<T>::denorm_min()) <= make_fvar<T, m>((std::numeric_limits<T>::min)()))
);
#endif
}

BOOST_CHECK(isfinite(make_fvar<T, m>(0)));
BOOST_CHECK(isnormal(make_fvar<T, m>((std::numeric_limits<T>::min)())));
BOOST_CHECK(isinf(make_fvar<T, m>(std::numeric_limits<T>::infinity())));
BOOST_CHECK(isnan(make_fvar<T, m>(std::numeric_limits<T>::quiet_NaN())));
}
}

BOOST_AUTO_TEST_SUITE_END()
15 changes: 15 additions & 0 deletions test/test_classify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <iostream>
#include <iomanip>

#include "test_autodiff.hpp"

#ifdef _MSC_VER
#pragma warning(disable: 4127 4146) // conditional expression is constant
#endif
Expand Down Expand Up @@ -256,6 +258,9 @@ void test_classify(T t, const char* type)
#endif
}


BOOST_AUTO_TEST_SUITE(test_fpclassify)

BOOST_AUTO_TEST_CASE( test_main )
{
BOOST_MATH_CONTROL_FP;
Expand Down Expand Up @@ -288,6 +293,16 @@ BOOST_AUTO_TEST_CASE( test_main )
test_classify(unsigned(0), "unsigned");
}

BOOST_AUTO_TEST_CASE_TEMPLATE(fpclassify_autodiff, T, all_float_types) {
test_classify(boost::math::differentiation::make_fvar<T, 1>(0), "autodiff float");
test_classify(boost::math::differentiation::make_fvar<T, 2>(0), "autodiff float");
test_classify(boost::math::differentiation::make_fvar<T, 3>(0), "autodiff float");
test_classify(boost::math::differentiation::make_fvar<T, 7>(0), "autodiff float");
test_classify(boost::math::differentiation::make_fvar<T, 12>(0), "autodiff float");
}

BOOST_AUTO_TEST_SUITE_END()

/*
Autorun "i:\Boost-sandbox\math_toolkit\libs\math\test\MSVC80\debug\test_classify.exe"
Running 1 test case...
Expand Down