From c1ebbfc79b889e2bc5af26d807741fb3891b064a Mon Sep 17 00:00:00 2001 From: Alex Stewart Date: Mon, 13 Feb 2017 16:12:09 +0000 Subject: [PATCH] Require Eigen >= 3.3 to define ScalarBinaryOpTraits in Jet. - ScalarBinaryOpTraits was introduced in Eigen 3.3, and thus breaks compilation of Ceres for Eigen versions < 3.3. - Reported as issue #252 by AustinDeric: https://github.com/ceres-solver/ceres-solver/issues/252 Change-Id: Ie9b7dace17709c348b18b297f2d5306b054ce4b0 --- include/ceres/jet.h | 5 ++++- internal/ceres/jet_test.cc | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/ceres/jet.h b/include/ceres/jet.h index c10c7d8c7..93cdd7238 100644 --- a/include/ceres/jet.h +++ b/include/ceres/jet.h @@ -878,11 +878,13 @@ struct NumTraits > { }; }; +#if EIGEN_VERSION_AT_LEAST(3, 3, 0) // Specifying the return type of binary operations between Jets and scalar types // allows you to perform matrix/array operations with Eigen matrices and arrays // such as addition, subtraction, multiplication, and division where one Eigen // matrix/array is of type Jet and the other is a scalar type. This improves -// performance by using the optimized scalar-to-Jet binary operations. +// performance by using the optimized scalar-to-Jet binary operations but +// is only available on Eigen versions >= 3.3 template struct ScalarBinaryOpTraits, T, BinaryOp> { typedef ceres::Jet ReturnType; @@ -891,6 +893,7 @@ template struct ScalarBinaryOpTraits, BinaryOp> { typedef ceres::Jet ReturnType; }; +#endif // EIGEN_VERSION_AT_LEAST(3, 3, 0) } // namespace Eigen diff --git a/internal/ceres/jet_test.cc b/internal/ceres/jet_test.cc index d8eedbc14..8576eb1ff 100644 --- a/internal/ceres/jet_test.cc +++ b/internal/ceres/jet_test.cc @@ -577,6 +577,8 @@ TEST(JetTraitsTest, ClassificationFinite) { EXPECT_FALSE(IsNaN(a)); } +// ScalarBinaryOpTraits is only supported on Eigen versions >= 3.3 +#if EIGEN_VERSION_AT_LEAST(3, 3, 0) TEST(JetTraitsTest, MatrixScalarUnaryOps) { const J x = MakeJet(2.3, -2.7, 1e-3); const J y = MakeJet(1.7, 0.5, 1e+2); @@ -654,6 +656,7 @@ TEST(JetTraitsTest, ArrayScalarBinaryOps) { ExpectJetsClose(r3(0), r3(0)); ExpectJetsClose(r4(1), r4(1)); } +#endif // EIGEN_VERSION_AT_LEAST(3, 3, 0) } // namespace internal } // namespace ceres