Skip to content
Snippets Groups Projects
Commit 201f6b4b authored by jcarpent's avatar jcarpent
Browse files

[C++][Cmake] Add option to make eigen and numpy objects aligned

parent a1ea4c28
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,15 @@ IF(APPLE) ...@@ -23,6 +23,15 @@ IF(APPLE)
SET(CMAKE_MACOSX_RPATH TRUE) SET(CMAKE_MACOSX_RPATH TRUE)
ENDIF(APPLE) ENDIF(APPLE)
# ----------------------------------------------------
# --- OPTIONS ---------------------------------------
# ----------------------------------------------------
OPTION (EIGEN_NUMPY_ALIGNED "Directly aligned data between Numpy and Eigen" OFF)
IF(EIGEN_NUMPY_ALIGNED)
ADD_DEFINITIONS(-DEIGENPY_ALIGNED)
ENDIF(EIGEN_NUMPY_ALIGNED)
# ---------------------------------------------------- # ----------------------------------------------------
# --- DEPENDANCIES ----------------------------------- # --- DEPENDANCIES -----------------------------------
# ---------------------------------------------------- # ----------------------------------------------------
...@@ -102,6 +111,9 @@ ADD_LIBRARY(geometry SHARED unittest/geometry.cpp) ...@@ -102,6 +111,9 @@ ADD_LIBRARY(geometry SHARED unittest/geometry.cpp)
TARGET_LINK_LIBRARIES(geometry ${Boost_LIBRARIES} ${PROJECT_NAME}) TARGET_LINK_LIBRARIES(geometry ${Boost_LIBRARIES} ${PROJECT_NAME})
SET_TARGET_PROPERTIES(geometry PROPERTIES PREFIX "") SET_TARGET_PROPERTIES(geometry PROPERTIES PREFIX "")
IF(EIGEN_NUMPY_ALIGNED)
PKG_CONFIG_APPEND_CFLAGS("-DEIGENPY_ALIGNED")
ENDIF(EIGEN_NUMPY_ALIGNED)
PKG_CONFIG_APPEND_CFLAGS("-I${PYTHON_INCLUDE_DIRS}") PKG_CONFIG_APPEND_CFLAGS("-I${PYTHON_INCLUDE_DIRS}")
PKG_CONFIG_APPEND_CFLAGS("-I${NUMPY_INCLUDE_DIRS}") PKG_CONFIG_APPEND_CFLAGS("-I${NUMPY_INCLUDE_DIRS}")
PKG_CONFIG_APPEND_LIBS("boost_python") PKG_CONFIG_APPEND_LIBS("boost_python")
......
...@@ -190,20 +190,26 @@ namespace eigenpy ...@@ -190,20 +190,26 @@ namespace eigenpy
void enableEigenPySpecific() void enableEigenPySpecific()
{ {
import_array(); import_array();
#ifdef EIGEN_DONT_VECTORIZE #ifdef EIGEN_DONT_VECTORIZE
boost::python::to_python_converter<MatType, boost::python::to_python_converter<MatType,
eigenpy::EigenToPy<MatType,MatType> >(); eigenpy::EigenToPy<MatType,MatType> >();
eigenpy::EigenFromPy<MatType,MatType>(); eigenpy::EigenFromPy<MatType,MatType>();
#else #else
typedef typename eigenpy::UnalignedEquivalent<MatType>::type MatTypeDontAlign;
boost::python::to_python_converter<MatType, boost::python::to_python_converter<MatType,
eigenpy::EigenToPy<MatType,MatType> >(); eigenpy::EigenToPy<MatType,MatType> >();
eigenpy::EigenFromPy<MatType,MatType>();
typedef typename eigenpy::UnalignedEquivalent<MatType>::type MatTypeDontAlign;
#ifndef EIGENPY_ALIGNED
boost::python::to_python_converter<MatTypeDontAlign, boost::python::to_python_converter<MatTypeDontAlign,
eigenpy::EigenToPy<MatTypeDontAlign,MatTypeDontAlign> >(); eigenpy::EigenToPy<MatTypeDontAlign,MatTypeDontAlign> >();
eigenpy::EigenFromPy<MatTypeDontAlign,MatTypeDontAlign>(); eigenpy::EigenFromPy<MatTypeDontAlign,MatTypeDontAlign>();
#endif #endif
#endif
} }
......
...@@ -27,11 +27,15 @@ namespace eigenpy ...@@ -27,11 +27,15 @@ namespace eigenpy
{ {
typedef Eigen::MatrixBase<D> MatType; typedef Eigen::MatrixBase<D> MatType;
typedef Eigen::Matrix<typename D::Scalar, typedef Eigen::Matrix<typename D::Scalar,
D::RowsAtCompileTime, D::RowsAtCompileTime,
D::ColsAtCompileTime, D::ColsAtCompileTime,
D::Options | Eigen::DontAlign, #ifndef EIGENPY_ALIGNED
D::MaxRowsAtCompileTime, D::Options | Eigen::DontAlign,
D::MaxColsAtCompileTime> type; #else
D::Options,
#endif
D::MaxRowsAtCompileTime,
D::MaxColsAtCompileTime> type;
}; };
} // namespace eigenpy } // namespace eigenpy
......
...@@ -39,7 +39,11 @@ namespace eigenpy ...@@ -39,7 +39,11 @@ namespace eigenpy
template<> template<>
struct UnalignedEquivalent<Eigen::Quaterniond> struct UnalignedEquivalent<Eigen::Quaterniond>
{ {
typedef Eigen::Quaternion<double,Eigen::DontAlign> type; #ifndef EIGENPY_ALIGNED
typedef Eigen::Quaternion<Eigen::Quaterniond::Scalar,Eigen::DontAlign> type;
#else
typedef Eigen::Quaterniond type;
#endif
}; };
namespace bp = boost::python; namespace bp = boost::python;
...@@ -51,10 +55,15 @@ namespace eigenpy ...@@ -51,10 +55,15 @@ namespace eigenpy
typedef Eigen::QuaternionBase<Quaternion> QuaternionBase; typedef Eigen::QuaternionBase<Quaternion> QuaternionBase;
typedef typename eigenpy::UnalignedEquivalent<Quaternion>::type QuaternionUnaligned; typedef typename eigenpy::UnalignedEquivalent<Quaternion>::type QuaternionUnaligned;
typedef typename QuaternionUnaligned::Scalar Scalar; typedef typename QuaternionBase::Scalar Scalar;
typedef Eigen::Matrix<Scalar,3,1,Eigen::DontAlign> Vector3;
typedef typename QuaternionUnaligned::Coefficients Coefficients; typedef typename QuaternionUnaligned::Coefficients Coefficients;
#ifndef EIGENPY_ALIGNED
typedef Eigen::Matrix<Scalar,3,1,Eigen::DontAlign> Vector3;
typedef Eigen::Matrix<Scalar,3,3,Eigen::DontAlign> Matrix3; typedef Eigen::Matrix<Scalar,3,3,Eigen::DontAlign> Matrix3;
#else
typedef Eigen::Matrix<Scalar,3,1,0> Vector3;
typedef Eigen::Matrix<Scalar,3,3,0> Matrix3;
#endif
typedef Eigen::AngleAxis<Scalar> AngleAxisUnaligned; typedef Eigen::AngleAxis<Scalar> AngleAxisUnaligned;
...@@ -169,8 +178,10 @@ namespace eigenpy ...@@ -169,8 +178,10 @@ namespace eigenpy
bp::init<>()) bp::init<>())
.def(QuaternionVisitor<Quaternion>()) .def(QuaternionVisitor<Quaternion>())
; ;
#ifndef EIGENPY_ALIGNED
bp::to_python_converter< Quaternion,QuaternionVisitor<Quaternion> >(); bp::to_python_converter< Quaternion,QuaternionVisitor<Quaternion> >();
#endif
} }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment