Commit 201f6b4b authored by jcarpent's avatar jcarpent
Browse files

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

parent a1ea4c28
......@@ -23,6 +23,15 @@ IF(APPLE)
SET(CMAKE_MACOSX_RPATH TRUE)
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 -----------------------------------
# ----------------------------------------------------
......@@ -102,6 +111,9 @@ ADD_LIBRARY(geometry SHARED unittest/geometry.cpp)
TARGET_LINK_LIBRARIES(geometry ${Boost_LIBRARIES} ${PROJECT_NAME})
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${NUMPY_INCLUDE_DIRS}")
PKG_CONFIG_APPEND_LIBS("boost_python")
......
......@@ -190,20 +190,26 @@ namespace eigenpy
void enableEigenPySpecific()
{
import_array();
#ifdef EIGEN_DONT_VECTORIZE
#ifdef EIGEN_DONT_VECTORIZE
boost::python::to_python_converter<MatType,
eigenpy::EigenToPy<MatType,MatType> >();
eigenpy::EigenToPy<MatType,MatType> >();
eigenpy::EigenFromPy<MatType,MatType>();
#else
typedef typename eigenpy::UnalignedEquivalent<MatType>::type MatTypeDontAlign;
#else
boost::python::to_python_converter<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,
eigenpy::EigenToPy<MatTypeDontAlign,MatTypeDontAlign> >();
eigenpy::EigenFromPy<MatTypeDontAlign,MatTypeDontAlign>();
#endif
#endif
}
......
......@@ -27,11 +27,15 @@ namespace eigenpy
{
typedef Eigen::MatrixBase<D> MatType;
typedef Eigen::Matrix<typename D::Scalar,
D::RowsAtCompileTime,
D::ColsAtCompileTime,
D::Options | Eigen::DontAlign,
D::MaxRowsAtCompileTime,
D::MaxColsAtCompileTime> type;
D::RowsAtCompileTime,
D::ColsAtCompileTime,
#ifndef EIGENPY_ALIGNED
D::Options | Eigen::DontAlign,
#else
D::Options,
#endif
D::MaxRowsAtCompileTime,
D::MaxColsAtCompileTime> type;
};
} // namespace eigenpy
......
......@@ -39,7 +39,11 @@ namespace eigenpy
template<>
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;
......@@ -51,10 +55,15 @@ namespace eigenpy
typedef Eigen::QuaternionBase<Quaternion> QuaternionBase;
typedef typename eigenpy::UnalignedEquivalent<Quaternion>::type QuaternionUnaligned;
typedef typename QuaternionUnaligned::Scalar Scalar;
typedef Eigen::Matrix<Scalar,3,1,Eigen::DontAlign> Vector3;
typedef typename QuaternionBase::Scalar Scalar;
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;
#else
typedef Eigen::Matrix<Scalar,3,1,0> Vector3;
typedef Eigen::Matrix<Scalar,3,3,0> Matrix3;
#endif
typedef Eigen::AngleAxis<Scalar> AngleAxisUnaligned;
......@@ -169,8 +178,10 @@ namespace eigenpy
bp::init<>())
.def(QuaternionVisitor<Quaternion>())
;
#ifndef EIGENPY_ALIGNED
bp::to_python_converter< Quaternion,QuaternionVisitor<Quaternion> >();
#endif
}
};
......
Markdown is supported
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