Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions include/eigenpy/details.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,38 @@

#define GET_PY_ARRAY_TYPE(array) PyArray_ObjectType(reinterpret_cast<PyObject *>(array), 0)

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::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));
};

template<class MatType>
struct referent_size<Eigen::EigenBase<MatType> >
{
BOOST_STATIC_CONSTANT(
std::size_t, value = sizeof(MatType));
};

}}}

namespace eigenpy
{
template <typename SCALAR> struct NumpyEquivalentType {};
Expand Down
55 changes: 48 additions & 7 deletions include/eigenpy/details/rvalue_from_python_data.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* Copyright 2018-2020, INRIA
*/

#ifndef __eigenpy_details_rvalue_from_python_data_hpp__
#define __eigenpy_details_rvalue_from_python_data_hpp__

Expand All @@ -10,44 +14,81 @@ namespace boost
{
namespace converter
{

/// \brief Template specialization of rvalue_from_python_data
template<typename Derived>
struct rvalue_from_python_data<Eigen::MatrixBase<Derived> const & >
: rvalue_from_python_storage<Eigen::MatrixBase<Derived> const & >
: rvalue_from_python_storage<Derived const & >
{
typedef Eigen::MatrixBase<Derived> const & T;

# if (!defined(__MWERKS__) || __MWERKS__ >= 0x3000) \
&& (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= 245) \
&& (!defined(__DECCXX_VER) || __DECCXX_VER > 60590014) \
&& !defined(BOOST_PYTHON_SYNOPSIS) /* Synopsis' OpenCXX has trouble parsing this */
// This must always be a POD struct with m_data its first member.
BOOST_STATIC_ASSERT(BOOST_PYTHON_OFFSETOF(rvalue_from_python_storage<T>,stage1) == 0);
# endif

// The usual constructor
rvalue_from_python_data(rvalue_from_python_stage1_data const & _stage1)
{
this->stage1 = _stage1;
}

// This constructor just sets m_convertible -- used by
// implicitly_convertible<> to perform the final step of the
// conversion, where the construct() function is already known.
rvalue_from_python_data(void* convertible)
{
this->stage1.convertible = convertible;
}

// Destroys any object constructed in the storage.
~rvalue_from_python_data()
{
if (this->stage1.convertible == this->storage.bytes)
static_cast<Derived *>((void *)this->storage.bytes)->~Derived();
}
};

/// \brief Template specialization of rvalue_from_python_data
template<typename Derived>
struct rvalue_from_python_data<Eigen::EigenBase<Derived> const & >
: rvalue_from_python_storage<Derived const & >
{
typedef Eigen::MatrixBase<Derived> const & T;

# if (!defined(__MWERKS__) || __MWERKS__ >= 0x3000) \
&& (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= 245) \
&& (!defined(__DECCXX_VER) || __DECCXX_VER > 60590014) \
&& !defined(BOOST_PYTHON_SYNOPSIS) /* Synopsis' OpenCXX has trouble parsing this */
// This must always be a POD struct with m_data its first member.
BOOST_STATIC_ASSERT(BOOST_PYTHON_OFFSETOF(rvalue_from_python_storage<T>,stage1) == 0);
# endif

// The usual constructor
rvalue_from_python_data(rvalue_from_python_stage1_data const & _stage1)
{
this->stage1 = _stage1;
}

// This constructor just sets m_convertible -- used by
// implicitly_convertible<> to perform the final step of the
// conversion, where the construct() function is already known.
rvalue_from_python_data(void* convertible)
{
this->stage1.convertible = convertible;
}

// Destroys any object constructed in the storage.
~rvalue_from_python_data()
{
if (this->stage1.convertible == this->storage.bytes)
static_cast<Derived *>((void *)this->storage.bytes)->~Derived();
}
};

}
}
} // namespace boost::python::converter
Expand Down
13 changes: 7 additions & 6 deletions include/eigenpy/utils/is-approx.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2020 INRIA
*/
* Copyright 2020 INRIA
*/

#ifndef __eigenpy_utils_scalar_is_approx_hpp__
#define __eigenpy_utils_scalar_is_approx_hpp__
Expand All @@ -10,15 +10,16 @@
namespace eigenpy
{
template<typename MatrixType1, typename MatrixType2>
inline EIGEN_DONT_INLINE bool is_approx(const MatrixType1 & mat1,
const MatrixType2 & mat2,
inline EIGEN_DONT_INLINE bool is_approx(const Eigen::MatrixBase<MatrixType1> & mat1,
const Eigen::MatrixBase<MatrixType2> & mat2,
const typename MatrixType1::Scalar & prec)
{
return mat1.derived().isApprox(mat2.derived(),prec);
return mat1.isApprox(mat2,prec);
}

template<typename MatrixType1, typename MatrixType2>
inline bool is_approx(const MatrixType1 & mat1, const MatrixType2 & mat2)
inline EIGEN_DONT_INLINE bool is_approx(const Eigen::MatrixBase<MatrixType1> & mat1,
const Eigen::MatrixBase<MatrixType2> & mat2)
{
return is_approx(mat1,mat2,Eigen::NumTraits<typename MatrixType1::Scalar>::dummy_precision());
}
Expand Down
6 changes: 4 additions & 2 deletions python/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ BOOST_PYTHON_MODULE(eigenpy)

{
using namespace Eigen;
bp::def("is_approx",(bool (*)(const MatrixXd &, const MatrixXd &, const double &))&is_approx<MatrixXd,MatrixXd>,

bp::def("is_approx",(bool (*)(const Eigen::MatrixBase<MatrixXd> &, const Eigen::MatrixBase<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::def("is_approx",(bool (*)(const Eigen::MatrixBase<MatrixXd> &, const Eigen::MatrixBase<MatrixXd> &))&is_approx<MatrixXd,MatrixXd>,
bp::args("A","B"),
"Returns True if A is approximately equal to B.");
}
Expand Down