Specializing numeric_limits For AutoDiffScalar

This commit is contained in:
Mmanu Chaturvedi 2017-05-23 17:12:36 -04:00
parent 26e8f9171e
commit 2971503fed
2 changed files with 21 additions and 0 deletions

View File

@ -683,4 +683,11 @@ template<typename DerType> struct NumTraits<AutoDiffScalar<DerType> >
}
namespace std {
template <typename T>
class numeric_limits<Eigen::AutoDiffScalar<T> >
: public numeric_limits<typename T::Scalar> {};
} // namespace std
#endif // EIGEN_AUTODIFF_SCALAR_H

View File

@ -72,6 +72,19 @@ template<typename Scalar> void check_hyperbolic_functions()
VERIFY_IS_APPROX(res3.derivatives().x(), Scalar(0.339540557256150));
}
template <typename Scalar>
void check_limits_specialization()
{
typedef Eigen::Matrix<Scalar, 1, 1> Deriv;
typedef Eigen::AutoDiffScalar<Deriv> AD;
typedef std::numeric_limits<AD> A;
typedef std::numeric_limits<Scalar> B;
bool res = std::is_base_of<B, A>::value;
VERIFY_IS_EQUAL(res, true);
}
void test_autodiff_scalar()
{
for(int i = 0; i < g_repeat; i++) {
@ -79,5 +92,6 @@ void test_autodiff_scalar()
CALL_SUBTEST_2( check_atan2<double>() );
CALL_SUBTEST_3( check_hyperbolic_functions<float>() );
CALL_SUBTEST_4( check_hyperbolic_functions<double>() );
CALL_SUBTEST_5( check_limits_specialization<double>());
}
}