diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ae903e993f537a699d830929198f7b175e0a680..86250e5a6dfab92c94e6355b317f0a258c23a7a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,13 +55,8 @@ ENDIF(WIN32) # ---------------------------------------------------- # --- OPTIONS --------------------------------------- # ---------------------------------------------------- -OPTION (EIGEN_NUMPY_ALIGNED "Directly aligned data between Numpy and Eigen" OFF) OPTION (BUILD_UNIT_TESTS "Build the unitary tests" ON) -IF(EIGEN_NUMPY_ALIGNED) - ADD_DEFINITIONS(-DEIGENPY_ALIGNED) -ENDIF(EIGEN_NUMPY_ALIGNED) - # ---------------------------------------------------- # --- DEPENDANCIES ----------------------------------- # ---------------------------------------------------- @@ -103,6 +98,7 @@ SET(HEADERS registration.hpp angle-axis.hpp quaternion.hpp + stride.hpp ref.hpp ) @@ -157,13 +153,9 @@ ADD_SUBDIRECTORY(python) # ---------------------------------------------------- ADD_SUBDIRECTORY(unittest) -IF(EIGEN_NUMPY_ALIGNED) - PKG_CONFIG_APPEND_CFLAGS("-DEIGENPY_ALIGNED") -ENDIF(EIGEN_NUMPY_ALIGNED) - PKG_CONFIG_APPEND_LIBS(${PROJECT_NAME}) -PKG_CONFIG_APPEND_CFLAGS("-I${PYTHON_INCLUDE_DIRS}") -PKG_CONFIG_APPEND_CFLAGS("-I${NUMPY_INCLUDE_DIRS}") +PKG_CONFIG_APPEND_CFLAGS("-isystem ${PYTHON_INCLUDE_DIRS}") +PKG_CONFIG_APPEND_CFLAGS("-isystem ${NUMPY_INCLUDE_DIRS}") PKG_CONFIG_APPEND_BOOST_LIBS(${BOOST_COMPONENTS}) SETUP_PROJECT_FINALIZE() diff --git a/src/details.hpp b/src/details.hpp index 6fe8295d21b6b1109963cf1ef6d0dc217012300d..f99467fc6593eb6fc61e2f0010bd8b7c26a0a43f 100644 --- a/src/details.hpp +++ b/src/details.hpp @@ -85,6 +85,7 @@ namespace eigenpy } }; +#if EIGEN_VERSION_AT_LEAST(3,2,0) template<typename MatType> struct EigenObjectAllocator< eigenpy::Ref<MatType> > { @@ -101,6 +102,7 @@ namespace eigenpy MapNumpy<MatType>::map(pyArray) = mat; } }; +#endif /* --- TO PYTHON -------------------------------------------------------------- */ template<typename MatType> diff --git a/src/eigenpy.hpp b/src/eigenpy.hpp index 9fcecc7ce29815f09f02791c2228e889ee26e886..8ecf798f9a43a5eaf4266f647f66ef37a140b7de 100644 --- a/src/eigenpy.hpp +++ b/src/eigenpy.hpp @@ -19,12 +19,20 @@ #include "eigenpy/fwd.hpp" #include "eigenpy/deprecated.hh" +#if EIGEN_VERSION_AT_LEAST(3,2,0) #include "eigenpy/ref.hpp" #define ENABLE_SPECIFIC_MATRIX_TYPE(TYPE) \ enableEigenPySpecific<TYPE>(); \ enableEigenPySpecific< eigenpy::Ref<TYPE> >(); +#else + +#define ENABLE_SPECIFIC_MATRIX_TYPE(TYPE) \ + enableEigenPySpecific<TYPE>(); + +#endif + namespace eigenpy { /* Enable Eigen-Numpy serialization for a set of standard MatrixBase instance. */ diff --git a/src/fwd.hpp b/src/fwd.hpp index d5d1f2e66ab8acb55b36771a1c0c3b989fced430..5f00431f6f8d93ba7d6663c3c8dc2a54b4b3d869 100644 --- a/src/fwd.hpp +++ b/src/fwd.hpp @@ -28,9 +28,14 @@ #include <numpy/noprefix.h> #ifdef NPY_ALIGNED -#define EIGENPY_DEFAULT_ALIGNMENT_VALUE Eigen::Aligned16 +#if EIGEN_VERSION_AT_LEAST(3,2,90) + #define EIGENPY_DEFAULT_ALIGNMENT_VALUE Eigen::Aligned16 #else -#define EIGENPY_DEFAULT_ALIGNMENT_VALUE Eigen::Unaligned + #define EIGENPY_DEFAULT_ALIGNMENT_VALUE Eigen::Aligned +#endif +#else + #define EIGENPY_DEFAULT_ALIGNMENT_VALUE Eigen::Unaligned #endif #endif // ifndef __eigenpy_fwd_hpp__ + diff --git a/src/map.hpp b/src/map.hpp index 2a2fb4b27f72126db743c4e1ee94756125857660..c7414355db270b60f4b7a203fbd9685ea378e95c 100644 --- a/src/map.hpp +++ b/src/map.hpp @@ -17,6 +17,7 @@ #include "eigenpy/fwd.hpp" #include <numpy/arrayobject.h> #include "eigenpy/exception.hpp" +#include "eigenpy/stride.hpp" namespace eigenpy { diff --git a/src/ref.hpp b/src/ref.hpp index 641228e1862ac20c3bec6225fe0b2169f7db6df8..367bf0f8ae83af557db3ebd16ea6eacb4fd07216 100644 --- a/src/ref.hpp +++ b/src/ref.hpp @@ -18,27 +18,17 @@ #define __eigenpy_ref_hpp__ #include "eigenpy/fwd.hpp" +#include "eigenpy/stride.hpp" // For old Eigen versions, EIGEN_DEVICE_FUNC is not defined. // We must define it just in the scope of this file. -#if not EIGEN_VERSION_AT_LEAST(3,2,91) +#if not EIGEN_VERSION_AT_LEAST(3,2,90) #define EIGEN_DEVICE_FUNC #endif namespace eigenpy { - template<typename MatType, int IsVectorAtCompileTime = MatType::IsVectorAtCompileTime> - struct StrideType - { - typedef Eigen::Stride<Eigen::Dynamic,Eigen::Dynamic> type; - }; - - template<typename MatType> - struct StrideType<MatType,1> - { - typedef Eigen::InnerStride<Eigen::Dynamic> type; - }; - + template<typename PlainObjectType> struct Ref : Eigen::Ref<PlainObjectType,EIGENPY_DEFAULT_ALIGNMENT_VALUE,typename StrideType<PlainObjectType>::type> { @@ -58,7 +48,7 @@ namespace eigenpy typedef typename Base::CoeffReturnType CoeffReturnType; /*!< \brief The return type for coefficient access. \details Depending on whether the object allows direct coefficient access (e.g. for a MatrixXd), this type is either 'const Scalar&' or simply 'Scalar' for objects that do not allow direct coefficient access. */ typedef typename Eigen::internal::ref_selector<Base>::type Nested; typedef typename Eigen::internal::traits<Base>::StorageKind StorageKind; -#if EIGEN_VERSION_AT_LEAST(3,2,91) +#if EIGEN_VERSION_AT_LEAST(3,2,90) typedef typename Eigen::internal::traits<Base>::StorageIndex StorageIndex; #else typedef typename Eigen::internal::traits<Base>::Index StorageIndex; @@ -104,7 +94,7 @@ namespace eigenpy }; // struct Ref<PlainObjectType> } -#if not EIGEN_VERSION_AT_LEAST(3,2,91) +#if not EIGEN_VERSION_AT_LEAST(3,2,90) #undef EIGEN_DEVICE_FUNC #endif diff --git a/src/solvers/preconditioners.cpp b/src/solvers/preconditioners.cpp index fb2f2e35a519b1ac4d3d788f5ba36aa99dd7f226..1854170f72fd67855aad03049b8755391ce08ff1 100644 --- a/src/solvers/preconditioners.cpp +++ b/src/solvers/preconditioners.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2017, Justin Carpentier, LAAS-CNRS + * Copyright 2017-2018, Justin Carpentier, LAAS-CNRS * * This file is part of eigenpy. * eigenpy is free software: you can redistribute it and/or @@ -14,12 +14,16 @@ * with eigenpy. If not, see <http://www.gnu.org/licenses/>. */ +#include <Eigen/Core> + +#if EIGEN_VERSION_AT_LEAST(3,2,0) #include "eigenpy/solvers/preconditioners.hpp" #include "eigenpy/solvers/BasicPreconditioners.hpp" //#include "eigenpy/solvers/BFGSPreconditioners.hpp" namespace eigenpy { + void exposePreconditioners() { using namespace Eigen; @@ -32,4 +36,8 @@ namespace eigenpy // LimitedBFGSPreconditionerBaseVisitor< LimitedBFGSPreconditioner<double,Eigen::Dynamic,Eigen::Upper|Eigen::Lower> >::expose("LimitedBFGSPreconditioner"); } + } // namespace eigenpy + +#endif + diff --git a/src/solvers/solvers.cpp b/src/solvers/solvers.cpp index d0d7103ff29dfd7ec872d324655d3fd513c9338a..8a30217ddd9fb2854049f9f501afb0e356272cef 100644 --- a/src/solvers/solvers.cpp +++ b/src/solvers/solvers.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2017, Justin Carpentier, LAAS-CNRS + * Copyright 2017-2018, Justin Carpentier, LAAS-CNRS * * This file is part of eigenpy. * eigenpy is free software: you can redistribute it and/or @@ -14,6 +14,10 @@ * with eigenpy. If not, see <http://www.gnu.org/licenses/>. */ +#include <Eigen/Core> + +#if EIGEN_VERSION_AT_LEAST(3,2,0) + #include "eigenpy/solvers/solvers.hpp" #include "eigenpy/solvers/ConjugateGradient.hpp" @@ -43,3 +47,6 @@ namespace eigenpy ; } } // namespace eigenpy + +#endif + diff --git a/src/stride.hpp b/src/stride.hpp new file mode 100644 index 0000000000000000000000000000000000000000..438b818aaf6e319b33185355ca833fa6dc21417d --- /dev/null +++ b/src/stride.hpp @@ -0,0 +1,37 @@ +/* + * Copyright 2018, Justin Carpentier <jcarpent@laas.fr>, LAAS-CNRS + * + * This file is part of eigenpy. + * eigenpy is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * eigenpy is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. You should + * have received a copy of the GNU Lesser General Public License along + * with eigenpy. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __eigenpy_stride_hpp__ +#define __eigenpy_stride_hpp__ + +#include <Eigen/Core> + +namespace eigenpy +{ + template<typename MatType, int IsVectorAtCompileTime = MatType::IsVectorAtCompileTime> + struct StrideType + { + typedef Eigen::Stride<Eigen::Dynamic,Eigen::Dynamic> type; + }; + + template<typename MatType> + struct StrideType<MatType,1> + { + typedef Eigen::InnerStride<Eigen::Dynamic> type; + }; +} + +#endif // ifndef __eigenpy_stride_hpp__ diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 8b0a15c8e797fe03b9f4e25cf95299208dd87603..76a817fd5fe55e856ec54ab765096940f080aa11 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -40,5 +40,7 @@ ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND}) ADD_LIB_UNIT_TEST(matrix "eigen3") ADD_LIB_UNIT_TEST(geometry "eigen3") -ADD_LIB_UNIT_TEST(ref "eigen3") +IF(NOT ${EIGEN3_VERSION} VERSION_LESS "3.2.0") + ADD_LIB_UNIT_TEST(ref "eigen3") +ENDIF()