diff --git a/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h b/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h index 98e0e3b73..2db4d8c3b 100755 --- a/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h +++ b/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h @@ -562,6 +562,15 @@ inline AutoDiffScalar::type::Plain typedef AutoDiffScalar::type::PlainObject> ADS; return (x > y ? ADS(x) : ADS(y)); } +template +inline AutoDiffScalar::type::PlainObject> (min)(const AutoDiffScalar& x, const AutoDiffScalar& y) { + return (x.value() < y.value() ? x : y); +} +template +inline AutoDiffScalar::type::PlainObject> (max)(const AutoDiffScalar& x, const AutoDiffScalar& y) { + return (x.value() >= y.value() ? x : y); +} + EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(abs, using std::abs; diff --git a/unsupported/test/autodiff.cpp b/unsupported/test/autodiff.cpp index 83f336d68..118cf2ec7 100644 --- a/unsupported/test/autodiff.cpp +++ b/unsupported/test/autodiff.cpp @@ -245,6 +245,17 @@ void bug_1260() { A*v; } +// check a compilation issue with numext::max +double bug_1261() { + typedef AutoDiffScalar AD; + typedef Matrix VectorAD; + + VectorAD v; + const AD maxVal = v.maxCoeff(); + const AD minVal = v.minCoeff(); + return maxVal.value() + minVal.value(); +} + void test_autodiff() { for(int i = 0; i < g_repeat; i++) { @@ -257,5 +268,6 @@ void test_autodiff() bug_1222(); bug_1223(); bug_1260(); + bug_1261(); }