5 #ifndef __pinocchio_math_matrix_hpp__ 6 #define __pinocchio_math_matrix_hpp__ 8 #include "pinocchio/macros.hpp" 9 #include "pinocchio/math/fwd.hpp" 12 #include <boost/type_traits.hpp> 17 template<
typename Derived>
18 inline bool hasNaN(
const Eigen::DenseBase<Derived> & m)
20 return !((m.derived().array()==m.derived().array()).all());
23 template<
typename M1,
typename M2>
26 #if EIGEN_VERSION_AT_LEAST(3,2,90) 27 typedef typename Eigen::Product<M1,M2> type;
29 typedef typename Eigen::ProductReturnType<M1,M2>::Type type;
33 template<
typename Scalar,
typename Matrix>
36 #if EIGEN_VERSION_AT_LEAST(3,3,0) 37 typedef Eigen::CwiseBinaryOp<EIGEN_CAT(EIGEN_CAT(Eigen::internal::scalar_,product),_op)<Scalar,typename Eigen::internal::traits<Matrix>::Scalar>,
38 const typename Eigen::internal::plain_constant_type<Matrix,Scalar>::type,
const Matrix> type;
39 #elif EIGEN_VERSION_AT_LEAST(3,2,90) 40 typedef Eigen::CwiseUnaryOp<Eigen::internal::scalar_multiple_op<Scalar>,
const Matrix> type;
42 typedef const Eigen::CwiseUnaryOp<Eigen::internal::scalar_multiple_op<Scalar>,
const Matrix> type;
46 template<
typename Matrix,
typename Scalar>
49 #if EIGEN_VERSION_AT_LEAST(3,3,0) 50 typedef Eigen::CwiseBinaryOp<EIGEN_CAT(EIGEN_CAT(Eigen::internal::scalar_,product),_op)<typename Eigen::internal::traits<Matrix>::Scalar,Scalar>,
51 const Matrix,
const typename Eigen::internal::plain_constant_type<Matrix,Scalar>::type> type;
52 #elif EIGEN_VERSION_AT_LEAST(3,2,90) 53 typedef Eigen::CwiseUnaryOp<Eigen::internal::scalar_multiple_op<Scalar>,
const Matrix> type;
55 typedef const Eigen::CwiseUnaryOp<Eigen::internal::scalar_multiple_op<Scalar>,
const Matrix> type;
61 template<typename MatrixLike, bool value = boost::is_floating_point<typename MatrixLike::Scalar>::value>
64 typedef typename MatrixLike::Scalar Scalar;
65 typedef typename MatrixLike::RealScalar RealScalar;
67 static bool run(
const Eigen::MatrixBase<MatrixLike> & mat,
68 const RealScalar & prec =
69 Eigen::NumTraits< Scalar >::dummy_precision())
71 return mat.isUnitary(prec);
75 template<
typename MatrixLike>
76 struct isUnitaryAlgo<MatrixLike,false>
78 typedef typename MatrixLike::Scalar Scalar;
79 typedef typename MatrixLike::RealScalar RealScalar;
81 static bool run(
const Eigen::MatrixBase<MatrixLike> & ,
82 const RealScalar & prec =
83 Eigen::NumTraits< Scalar >::dummy_precision())
85 PINOCCHIO_UNUSED_VARIABLE(prec);
99 template<
typename MatrixLike>
100 inline bool isUnitary(
const Eigen::MatrixBase<MatrixLike> & mat,
101 const typename MatrixLike::RealScalar & prec =
102 Eigen::NumTraits< typename MatrixLike::Scalar >::dummy_precision())
104 return internal::isUnitaryAlgo<MatrixLike>::run(mat,prec);
109 template<typename VectorLike, bool value = boost::is_floating_point<typename VectorLike::Scalar>::value>
110 struct isNormalizedAlgo
112 typedef typename VectorLike::Scalar Scalar;
113 typedef typename VectorLike::RealScalar RealScalar;
115 static bool run(
const Eigen::MatrixBase<VectorLike> & vec,
116 const RealScalar & prec =
117 Eigen::NumTraits<RealScalar>::dummy_precision())
119 return math::fabs(vec.norm() - RealScalar(1)) <= prec;
123 template<
typename VectorLike>
124 struct isNormalizedAlgo<VectorLike,false>
126 typedef typename VectorLike::Scalar Scalar;
127 typedef typename VectorLike::RealScalar RealScalar;
129 static bool run(
const Eigen::MatrixBase<VectorLike> & ,
130 const RealScalar & prec =
131 Eigen::NumTraits<RealScalar>::dummy_precision())
133 PINOCCHIO_UNUSED_VARIABLE(prec);
147 template<
typename VectorLike>
149 const typename VectorLike::RealScalar & prec =
150 Eigen::NumTraits< typename VectorLike::Scalar >::dummy_precision())
152 EIGEN_STATIC_ASSERT_VECTOR_ONLY(VectorLike);
153 return internal::isNormalizedAlgo<VectorLike>::run(vec,prec);
158 template<
typename Scalar>
159 struct CallCorrectMatrixInverseAccordingToScalar
161 template<
typename MatrixIn,
typename MatrixOut>
162 static void run(
const Eigen::MatrixBase<MatrixIn> & m_in,
163 const Eigen::MatrixBase<MatrixOut> & dest)
165 MatrixOut & dest_ = PINOCCHIO_EIGEN_CONST_CAST(MatrixOut,dest);
166 dest_.noalias() = m_in.inverse();
172 template<
typename MatrixIn,
typename MatrixOut>
173 inline void inverse(
const Eigen::MatrixBase<MatrixIn> & m_in,
174 const Eigen::MatrixBase<MatrixOut> & dest)
176 MatrixOut & dest_ = PINOCCHIO_EIGEN_CONST_CAST(MatrixOut,dest);
177 internal::CallCorrectMatrixInverseAccordingToScalar<typename MatrixIn::Scalar>::run(m_in,dest_);
182 #endif //#ifndef __pinocchio_math_matrix_hpp__
bool isUnitary(const Eigen::MatrixBase< MatrixLike > &mat, const typename MatrixLike::RealScalar &prec=Eigen::NumTraits< typename MatrixLike::Scalar >::dummy_precision())
Check whether the input matrix is Unitary within the given precision.
bool isNormalized(const Eigen::MatrixBase< VectorLike > &vec, const typename VectorLike::RealScalar &prec=Eigen::NumTraits< typename VectorLike::Scalar >::dummy_precision())
Check whether the input vector is Normalized within the given precision.
Main pinocchio namespace.