diff --git a/gtsam/base/Manifold.h b/gtsam/base/Manifold.h index 901960001..9dadaf9e6 100644 --- a/gtsam/base/Manifold.h +++ b/gtsam/base/Manifold.h @@ -114,28 +114,15 @@ template struct is_manifold > : public boost::true_type { }; -// TODO: Could be more sophisticated using Eigen traits and SFINAE? - -template -struct dimension > : public Dynamic { -}; - -template -struct dimension > : public Dynamic { -}; - -template -struct dimension > : public Dynamic { +template +struct dimension > : public boost::integral_constant { + //TODO after switch to c++11 : the above should should be extracted to a constexpr function + // for readability and to reduce code duplication }; template -struct dimension > : public boost::integral_constant< - int, M * N> { -}; - -template -struct zero > : public boost::integral_constant< - int, M * N> { +struct zero > { BOOST_STATIC_ASSERT_MSG((M!=Eigen::Dynamic && N!=Eigen::Dynamic), "traits::zero is only supported for fixed-size matrices"); static Eigen::Matrix value() { @@ -143,6 +130,11 @@ struct zero > : public boost::integral_cons } }; +template +struct identity > : public zero > { +}; + + template struct is_chart: public boost::false_type { }; diff --git a/gtsam/base/Matrix.cpp b/gtsam/base/Matrix.cpp index dd17c00ef..1469e265d 100644 --- a/gtsam/base/Matrix.cpp +++ b/gtsam/base/Matrix.cpp @@ -667,7 +667,7 @@ Matrix expm(const Matrix& A, size_t K) { /* ************************************************************************* */ Matrix Cayley(const Matrix& A) { - size_t n = A.cols(); + Matrix::Index n = A.cols(); assert(A.rows() == n); // original diff --git a/tests/testManifold.cpp b/tests/testManifold.cpp index 55a5f5af0..b7ebfc4c8 100644 --- a/tests/testManifold.cpp +++ b/tests/testManifold.cpp @@ -108,6 +108,20 @@ TEST(Manifold, _zero) { Cal3Bundler cal(0, 0, 0); EXPECT(assert_equal(cal, traits::zero::value())); EXPECT(assert_equal(Camera(Pose3(), cal), traits::zero::value())); + EXPECT(assert_equal(Point2(), traits::zero::value())); + EXPECT(assert_equal(Matrix(Matrix24::Zero().eval()), Matrix(traits::zero::value()))); + EXPECT_DOUBLES_EQUAL(0.0, traits::zero::value(), 0.0); +} + +/* ************************************************************************* */ +// identity +TEST(Manifold, _identity) { + EXPECT(assert_equal(Pose3(), traits::identity::value())); + EXPECT(assert_equal(Cal3Bundler(), traits::identity::value())); + EXPECT(assert_equal(Camera(), traits::identity::value())); + EXPECT(assert_equal(Point2(), traits::identity::value())); + EXPECT(assert_equal(Matrix(Matrix24::Zero()), Matrix(traits::identity::value()))); + EXPECT_DOUBLES_EQUAL(0.0, traits::identity::value(), 0.0); } /* ************************************************************************* */