Unverified Commit a6af5709 authored by Justin Carpentier's avatar Justin Carpentier Committed by GitHub
Browse files

Merge pull request #151 from jcarpent/devel

Fix issues when compiling in Release mode
parents d86ce438 4ba344d1
......@@ -17,95 +17,6 @@
#include "eigenpy/map.hpp"
#include "eigenpy/exception.hpp"
namespace boost { namespace python { namespace detail {
template<class MatType>
struct referent_size<Eigen::MatrixBase<MatType>&>
{
BOOST_STATIC_CONSTANT(
std::size_t, value = sizeof(MatType));
};
template<class MatType>
struct referent_size<Eigen::EigenBase<MatType>&>
{
BOOST_STATIC_CONSTANT(
std::size_t, value = sizeof(MatType));
};
}}}
namespace boost { namespace python { namespace converter {
template<class MatType>
struct implicit<Eigen::MatrixBase<MatType>,MatType>
{
typedef Eigen::MatrixBase<MatType> Source;
typedef MatType Target;
static void* convertible(PyObject* obj)
{
// Find a converter which can produce a Source instance from
// obj. The user has told us that Source can be converted to
// Target, and instantiating construct() below, ensures that
// at compile-time.
return implicit_rvalue_convertible_from_python(obj, registered<Source>::converters)
? obj : 0;
}
static void construct(PyObject* obj, rvalue_from_python_stage1_data* data)
{
void* storage = ((rvalue_from_python_storage<Target>*)data)->storage.bytes;
arg_from_python<Source> get_source(obj);
bool convertible = get_source.convertible();
BOOST_VERIFY(convertible);
new (storage) Target(get_source().derived());
// record successful construction
data->convertible = storage;
}
};
template<class MatType>
struct implicit<MatType,Eigen::MatrixBase<MatType> >
{
typedef MatType Source;
typedef Eigen::MatrixBase<MatType> Target;
static void* convertible(PyObject* obj)
{
// Find a converter which can produce a Source instance from
// obj. The user has told us that Source can be converted to
// Target, and instantiating construct() below, ensures that
// at compile-time.
return implicit_rvalue_convertible_from_python(obj, registered<Source>::converters)
? obj : 0;
}
static void construct(PyObject* obj, rvalue_from_python_stage1_data* data)
{
void* storage = reinterpret_cast<rvalue_from_python_storage<Target>*>
(reinterpret_cast<void*>(data))->storage.bytes;
arg_from_python<Source> get_source(obj);
bool convertible = get_source.convertible();
BOOST_VERIFY(convertible);
new (storage) Source(get_source());
// record successful construction
data->convertible = storage;
}
};
template<class MatType>
struct implicit<MatType,Eigen::EigenBase<MatType> > : implicit<MatType,Eigen::MatrixBase<MatType> >
{};
}}} // namespace boost::python::converter
#define GET_PY_ARRAY_TYPE(array) PyArray_ObjectType(reinterpret_cast<PyObject *>(array), 0)
namespace eigenpy
......@@ -692,12 +603,39 @@ namespace eigenpy
// Add also conversion to Eigen::MatrixBase<MatType>
typedef Eigen::MatrixBase<MatType> MatrixBase;
// bp::implicitly_convertible<MatTypeBase,MatType>();
bp::implicitly_convertible<MatType,MatrixBase>();
EigenFromPy<MatrixBase>::registration();
// Add also conversion to Eigen::EigenBase<MatType>
typedef Eigen::EigenBase<MatType> EigenBase;
bp::implicitly_convertible<MatType,EigenBase>();
EigenFromPy<EigenBase>::registration();
}
};
template<typename MatType>
struct EigenFromPy< Eigen::MatrixBase<MatType> > : EigenFromPy<MatType>
{
typedef EigenFromPy<MatType> EigenFromPyDerived;
typedef Eigen::MatrixBase<MatType> Base;
static void registration()
{
bp::converter::registry::push_back
(reinterpret_cast<void *(*)(_object *)>(&EigenFromPy::convertible),
&EigenFromPy::construct,bp::type_id<Base>());
}
};
template<typename MatType>
struct EigenFromPy< Eigen::EigenBase<MatType> > : EigenFromPy<MatType>
{
typedef EigenFromPy<MatType> EigenFromPyDerived;
typedef Eigen::EigenBase<MatType> Base;
static void registration()
{
bp::converter::registry::push_back
(reinterpret_cast<void *(*)(_object *)>(&EigenFromPy::convertible),
&EigenFromPy::construct,bp::type_id<Base>());
}
};
......
......@@ -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());
}
}
......
<?xml version="1.0"?>
<package format="2">
<name>eigenpy</name>
<version>1.6.13</version>
<version>2.0.0</version>
<description>Bindings between Numpy and Eigen using Boost.Python</description>
<maintainer email="justin.carpentier@inria.fr">Justin Carpentier</maintainer>
<maintainer email="wolfgang.merkt@ed.ac.uk">Wolfgang Merkt</maintainer>
......
......@@ -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();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment