Skip to content

Commit a6af570

Browse files
authored
Merge pull request #151 from jcarpent/devel
Fix issues when compiling in Release mode
2 parents d86ce43 + 4ba344d commit a6af570

File tree

4 files changed

+51
-116
lines changed

4 files changed

+51
-116
lines changed

include/eigenpy/details.hpp

Lines changed: 31 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -17,95 +17,6 @@
1717
#include "eigenpy/map.hpp"
1818
#include "eigenpy/exception.hpp"
1919

20-
namespace boost { namespace python { namespace detail {
21-
22-
template<class MatType>
23-
struct referent_size<Eigen::MatrixBase<MatType>&>
24-
{
25-
BOOST_STATIC_CONSTANT(
26-
std::size_t, value = sizeof(MatType));
27-
};
28-
29-
template<class MatType>
30-
struct referent_size<Eigen::EigenBase<MatType>&>
31-
{
32-
BOOST_STATIC_CONSTANT(
33-
std::size_t, value = sizeof(MatType));
34-
};
35-
36-
}}}
37-
38-
namespace boost { namespace python { namespace converter {
39-
40-
template<class MatType>
41-
struct implicit<Eigen::MatrixBase<MatType>,MatType>
42-
{
43-
typedef Eigen::MatrixBase<MatType> Source;
44-
typedef MatType Target;
45-
46-
static void* convertible(PyObject* obj)
47-
{
48-
// Find a converter which can produce a Source instance from
49-
// obj. The user has told us that Source can be converted to
50-
// Target, and instantiating construct() below, ensures that
51-
// at compile-time.
52-
return implicit_rvalue_convertible_from_python(obj, registered<Source>::converters)
53-
? obj : 0;
54-
}
55-
56-
static void construct(PyObject* obj, rvalue_from_python_stage1_data* data)
57-
{
58-
void* storage = ((rvalue_from_python_storage<Target>*)data)->storage.bytes;
59-
60-
arg_from_python<Source> get_source(obj);
61-
bool convertible = get_source.convertible();
62-
BOOST_VERIFY(convertible);
63-
64-
new (storage) Target(get_source().derived());
65-
66-
// record successful construction
67-
data->convertible = storage;
68-
}
69-
};
70-
71-
template<class MatType>
72-
struct implicit<MatType,Eigen::MatrixBase<MatType> >
73-
{
74-
typedef MatType Source;
75-
typedef Eigen::MatrixBase<MatType> Target;
76-
77-
static void* convertible(PyObject* obj)
78-
{
79-
// Find a converter which can produce a Source instance from
80-
// obj. The user has told us that Source can be converted to
81-
// Target, and instantiating construct() below, ensures that
82-
// at compile-time.
83-
return implicit_rvalue_convertible_from_python(obj, registered<Source>::converters)
84-
? obj : 0;
85-
}
86-
87-
static void construct(PyObject* obj, rvalue_from_python_stage1_data* data)
88-
{
89-
void* storage = reinterpret_cast<rvalue_from_python_storage<Target>*>
90-
(reinterpret_cast<void*>(data))->storage.bytes;
91-
92-
arg_from_python<Source> get_source(obj);
93-
bool convertible = get_source.convertible();
94-
BOOST_VERIFY(convertible);
95-
96-
new (storage) Source(get_source());
97-
98-
// record successful construction
99-
data->convertible = storage;
100-
}
101-
};
102-
103-
template<class MatType>
104-
struct implicit<MatType,Eigen::EigenBase<MatType> > : implicit<MatType,Eigen::MatrixBase<MatType> >
105-
{};
106-
107-
}}} // namespace boost::python::converter
108-
10920
#define GET_PY_ARRAY_TYPE(array) PyArray_ObjectType(reinterpret_cast<PyObject *>(array), 0)
11021

11122
namespace eigenpy
@@ -692,12 +603,39 @@ namespace eigenpy
692603

693604
// Add also conversion to Eigen::MatrixBase<MatType>
694605
typedef Eigen::MatrixBase<MatType> MatrixBase;
695-
// bp::implicitly_convertible<MatTypeBase,MatType>();
696-
bp::implicitly_convertible<MatType,MatrixBase>();
697-
606+
EigenFromPy<MatrixBase>::registration();
607+
698608
// Add also conversion to Eigen::EigenBase<MatType>
699609
typedef Eigen::EigenBase<MatType> EigenBase;
700-
bp::implicitly_convertible<MatType,EigenBase>();
610+
EigenFromPy<EigenBase>::registration();
611+
}
612+
};
613+
614+
template<typename MatType>
615+
struct EigenFromPy< Eigen::MatrixBase<MatType> > : EigenFromPy<MatType>
616+
{
617+
typedef EigenFromPy<MatType> EigenFromPyDerived;
618+
typedef Eigen::MatrixBase<MatType> Base;
619+
620+
static void registration()
621+
{
622+
bp::converter::registry::push_back
623+
(reinterpret_cast<void *(*)(_object *)>(&EigenFromPy::convertible),
624+
&EigenFromPy::construct,bp::type_id<Base>());
625+
}
626+
};
627+
628+
template<typename MatType>
629+
struct EigenFromPy< Eigen::EigenBase<MatType> > : EigenFromPy<MatType>
630+
{
631+
typedef EigenFromPy<MatType> EigenFromPyDerived;
632+
typedef Eigen::EigenBase<MatType> Base;
633+
634+
static void registration()
635+
{
636+
bp::converter::registry::push_back
637+
(reinterpret_cast<void *(*)(_object *)>(&EigenFromPy::convertible),
638+
&EigenFromPy::construct,bp::type_id<Base>());
701639
}
702640
};
703641

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

package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<package format="2">
33
<name>eigenpy</name>
4-
<version>1.6.13</version>
4+
<version>2.0.0</version>
55
<description>Bindings between Numpy and Eigen using Boost.Python</description>
66
<maintainer email="[email protected]">Justin Carpentier</maintainer>
77
<maintainer email="[email protected]">Wolfgang Merkt</maintainer>

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)