Skip to content

Commit 4119d80

Browse files
committed
python: fix issue when calling is_approx
There is a shift in memory that I cannot understand in release mode
1 parent fb2badc commit 4119d80

File tree

2 files changed

+19
-22
lines changed

2 files changed

+19
-22
lines changed

include/eigenpy/utils/is-approx.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@
1010
namespace eigenpy
1111
{
1212
template<typename MatrixType1, typename MatrixType2>
13-
inline bool is_approx(const Eigen::MatrixBase<MatrixType1> & mat1,
14-
const Eigen::MatrixBase<MatrixType2> & mat2,
15-
const typename MatrixType1::Scalar & prec = Eigen::NumTraits<typename MatrixType1::Scalar>::dummy_precision())
13+
inline EIGEN_DONT_INLINE bool is_approx(const MatrixType1 & mat1,
14+
const MatrixType2 & mat2,
15+
const typename MatrixType1::Scalar & prec)
1616
{
17-
return mat1.isApprox(mat2,prec);
17+
return mat1.derived().isApprox(mat2.derived(),prec);
18+
}
19+
20+
template<typename MatrixType1, typename MatrixType2>
21+
inline bool is_approx(const MatrixType1 & mat1, const MatrixType2 & mat2)
22+
{
23+
return is_approx(mat1,mat2,Eigen::NumTraits<typename MatrixType1::Scalar>::dummy_precision());
1824
}
1925
}
2026

python/main.cpp

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,8 @@
1717

1818
#include <boost/python/scope.hpp>
1919

20-
#define DEFINE_IS_APPROX(MatType) \
21-
BOOST_PYTHON_FUNCTION_OVERLOADS(is_approx_overload##MatType,eigenpy::is_approx,2,3)
22-
23-
#define EXPOSE_IS_APPROX(MatType) \
24-
bp::def("is_approx", \
25-
(bool (*)(const Eigen::MatrixBase<MatType> &, \
26-
const Eigen::MatrixBase<MatType> &, \
27-
const MatType::Scalar &))eigenpy::is_approx<MatType,MatType>, \
28-
is_approx_overload##MatType(bp::args("A","B","prec"), \
29-
"Returns True if A is approximately equal to B, within the precision determined by prec."))
30-
31-
3220
using namespace eigenpy;
3321

34-
DEFINE_IS_APPROX(MatrixXd)
35-
DEFINE_IS_APPROX(MatrixXf)
36-
37-
3822
BOOST_PYTHON_MODULE(eigenpy)
3923
{
4024
namespace bp = boost::python;
@@ -62,8 +46,15 @@ BOOST_PYTHON_MODULE(eigenpy)
6246

6347
{
6448
using namespace Eigen;
65-
EXPOSE_IS_APPROX(MatrixXd);
66-
EXPOSE_IS_APPROX(MatrixXf);
49+
bp::def("is_approx",(bool (*)(const MatrixXd &, const MatrixXd &, const double &))&is_approx<MatrixXd,MatrixXd>,
50+
bp::args("A","B","prec"),
51+
"Returns True if A is approximately equal to B, within the precision determined by prec.");
52+
bp::def("is_approx",(bool (*)(const MatrixXd &, const MatrixXd &))&is_approx<MatrixXd,MatrixXd>,
53+
bp::args("A","B"),
54+
"Returns True if A is approximately equal to B..");
55+
56+
// EXPOSE_IS_APPROX(MatrixXd);
57+
// EXPOSE_IS_APPROX(MatrixXf);
6758
}
6859

6960
exposeDecompositions();

0 commit comments

Comments
 (0)