diff --git a/gtsam/base/Manifold.h b/gtsam/base/Manifold.h index fa509252d..fb926c630 100644 --- a/gtsam/base/Manifold.h +++ b/gtsam/base/Manifold.h @@ -242,41 +242,6 @@ struct DefaultChart { // Fixed size Eigen::Matrix type -namespace internal { - -template -struct Reshape { - //TODO replace this with Eigen's reshape function as soon as available. (There is a PR already pending : https://bitbucket.org/eigen/eigen/pull-request/41/reshape/diff) - typedef Eigen::Map > ReshapedType; - static inline ReshapedType reshape(const Eigen::Matrix & in) { - return in.data(); - } -}; - -template -struct Reshape { - typedef const Eigen::Matrix & ReshapedType; - static inline ReshapedType reshape(const Eigen::Matrix & in) { - return in; - } -}; - -template -struct Reshape { - typedef typename Eigen::Matrix::ConstTransposeReturnType ReshapedType; - static inline ReshapedType reshape(const Eigen::Matrix & in) { - return in.transpose(); - } -}; - -template -inline typename Reshape::ReshapedType reshape(const Eigen::Matrix & m){ - BOOST_STATIC_ASSERT(InM * InN == OutM * OutN); - return Reshape::reshape(m); -} - -} - template struct DefaultChart > { /** @@ -288,10 +253,10 @@ struct DefaultChart > { typedef Eigen::Matrix::value, 1> vector;BOOST_STATIC_ASSERT_MSG((M!=Eigen::Dynamic && N!=Eigen::Dynamic), "DefaultChart has not been implemented yet for dynamically sized matrices"); static vector local(const T& origin, const T& other) { - return internal::reshape(other) - internal::reshape(origin); + return reshape(other) - reshape(origin); } static T retract(const T& origin, const vector& d) { - return origin + internal::reshape(d); + return origin + reshape(d); } static int getDimension(const T&origin) { return origin.rows() * origin.cols(); diff --git a/gtsam/base/Matrix.h b/gtsam/base/Matrix.h index 1094306a9..eaa57c810 100644 --- a/gtsam/base/Matrix.h +++ b/gtsam/base/Matrix.h @@ -293,6 +293,40 @@ void zeroBelowDiagonal(MATRIX& A, size_t cols=0) { */ inline Matrix trans(const Matrix& A) { return A.transpose(); } +/// Reshape functor +template +struct Reshape { + //TODO replace this with Eigen's reshape function as soon as available. (There is a PR already pending : https://bitbucket.org/eigen/eigen/pull-request/41/reshape/diff) + typedef Eigen::Map > ReshapedType; + static inline ReshapedType reshape(const Eigen::Matrix & in) { + return in.data(); + } +}; + +/// Reshape specialization that does nothing as shape stays the same +template +struct Reshape { + typedef const Eigen::Matrix & ReshapedType; + static inline ReshapedType reshape(const Eigen::Matrix & in) { + return in; + } +}; + +/// Reshape specialization that does transpose +template +struct Reshape { + typedef typename Eigen::Matrix::ConstTransposeReturnType ReshapedType; + static inline ReshapedType reshape(const Eigen::Matrix & in) { + return in.transpose(); + } +}; + +template +inline typename Reshape::ReshapedType reshape(const Eigen::Matrix & m){ + BOOST_STATIC_ASSERT(InM * InN == OutM * OutN); + return Reshape::reshape(m); +} + /** * solve AX=B via in-place Lu factorization and backsubstitution * After calling, A contains LU, B the solved RHS vectors