aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Mmanu Chaturvedi <mmanu.chaturvedi@kitware.com>2017-05-23 17:12:36 -0400
committerGravatar Mmanu Chaturvedi <mmanu.chaturvedi@kitware.com>2017-05-23 17:12:36 -0400
commit2971503fed85add086cb163d24ee5d402d631aab (patch)
tree7e0e309f5aa16c22fb1b5e8be0bbe295bfd97dbc
parent26e8f9171eb07e188af45d7583b03c5be40a5f48 (diff)
Specializing numeric_limits For AutoDiffScalar
-rwxr-xr-xunsupported/Eigen/src/AutoDiff/AutoDiffScalar.h7
-rw-r--r--unsupported/test/autodiff_scalar.cpp14
2 files changed, 21 insertions, 0 deletions
diff --git a/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h b/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h
index d2808860c..279fe5cd3 100755
--- a/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h
+++ b/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h
@@ -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
diff --git a/unsupported/test/autodiff_scalar.cpp b/unsupported/test/autodiff_scalar.cpp
index 4df2f5c57..3a78d6b8d 100644
--- a/unsupported/test/autodiff_scalar.cpp
+++ b/unsupported/test/autodiff_scalar.cpp
@@ -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>());
}
}