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
diff --git a/include/ceres/jet.h b/include/ceres/jet.h
index c10c7d8..93cdd72 100644
--- a/include/ceres/jet.h
+++ b/include/ceres/jet.h
@@ -878,11 +878,13 @@
};
};
+#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 <typename BinaryOp, typename T, int N>
struct ScalarBinaryOpTraits<ceres::Jet<T, N>, T, BinaryOp> {
typedef ceres::Jet<T, N> ReturnType;
@@ -891,6 +893,7 @@
struct ScalarBinaryOpTraits<T, ceres::Jet<T, N>, BinaryOp> {
typedef ceres::Jet<T, N> 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 d8eedbc..8576eb1 100644
--- a/internal/ceres/jet_test.cc
+++ b/internal/ceres/jet_test.cc
@@ -577,6 +577,8 @@
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 @@
ExpectJetsClose(r3(0), r3(0));
ExpectJetsClose(r4(1), r4(1));
}
+#endif // EIGEN_VERSION_AT_LEAST(3, 3, 0)
} // namespace internal
} // namespace ceres