From 4119d80e71e73c4a780bcecff29b8a26b19e2c24 Mon Sep 17 00:00:00 2001 From: Justin Carpentier <justin.carpentier@inria.fr> Date: Thu, 30 Jan 2020 18:59:15 +0100 Subject: [PATCH] python: fix issue when calling is_approx There is a shift in memory that I cannot understand in release mode --- include/eigenpy/utils/is-approx.hpp | 14 ++++++++++---- python/main.cpp | 27 +++++++++------------------ 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/include/eigenpy/utils/is-approx.hpp b/include/eigenpy/utils/is-approx.hpp index 2c1d24f2..7f82ffde 100644 --- a/include/eigenpy/utils/is-approx.hpp +++ b/include/eigenpy/utils/is-approx.hpp @@ -10,11 +10,17 @@ namespace eigenpy { template<typename MatrixType1, typename MatrixType2> - inline bool is_approx(const Eigen::MatrixBase<MatrixType1> & mat1, - const Eigen::MatrixBase<MatrixType2> & mat2, - const typename MatrixType1::Scalar & prec = Eigen::NumTraits<typename MatrixType1::Scalar>::dummy_precision()) + inline EIGEN_DONT_INLINE bool is_approx(const MatrixType1 & mat1, + const MatrixType2 & mat2, + const typename MatrixType1::Scalar & prec) { - return mat1.isApprox(mat2,prec); + return mat1.derived().isApprox(mat2.derived(),prec); + } + + template<typename MatrixType1, typename MatrixType2> + inline bool is_approx(const MatrixType1 & mat1, const MatrixType2 & mat2) + { + return is_approx(mat1,mat2,Eigen::NumTraits<typename MatrixType1::Scalar>::dummy_precision()); } } diff --git a/python/main.cpp b/python/main.cpp index be723739..925d9cff 100644 --- a/python/main.cpp +++ b/python/main.cpp @@ -17,24 +17,8 @@ #include <boost/python/scope.hpp> -#define DEFINE_IS_APPROX(MatType) \ - BOOST_PYTHON_FUNCTION_OVERLOADS(is_approx_overload##MatType,eigenpy::is_approx,2,3) - -#define EXPOSE_IS_APPROX(MatType) \ - bp::def("is_approx", \ - (bool (*)(const Eigen::MatrixBase<MatType> &, \ - const Eigen::MatrixBase<MatType> &, \ - const MatType::Scalar &))eigenpy::is_approx<MatType,MatType>, \ - is_approx_overload##MatType(bp::args("A","B","prec"), \ - "Returns True if A is approximately equal to B, within the precision determined by prec.")) - - using namespace eigenpy; -DEFINE_IS_APPROX(MatrixXd) -DEFINE_IS_APPROX(MatrixXf) - - BOOST_PYTHON_MODULE(eigenpy) { namespace bp = boost::python; @@ -62,8 +46,15 @@ BOOST_PYTHON_MODULE(eigenpy) { using namespace Eigen; - EXPOSE_IS_APPROX(MatrixXd); - EXPOSE_IS_APPROX(MatrixXf); + bp::def("is_approx",(bool (*)(const MatrixXd &, const MatrixXd &, const double &))&is_approx<MatrixXd,MatrixXd>, + bp::args("A","B","prec"), + "Returns True if A is approximately equal to B, within the precision determined by prec."); + bp::def("is_approx",(bool (*)(const MatrixXd &, const MatrixXd &))&is_approx<MatrixXd,MatrixXd>, + bp::args("A","B"), + "Returns True if A is approximately equal to B.."); + +// EXPOSE_IS_APPROX(MatrixXd); +// EXPOSE_IS_APPROX(MatrixXf); } exposeDecompositions(); -- GitLab