Skip to content

Commit 2509447

Browse files
authored
Merge pull request #23 from jcarpent/devel
Fix compatibility with Eigen 3.0.5 and 3.2.x
2 parents 32b3ae6 + 412720a commit 2509447

File tree

10 files changed

+83
-31
lines changed

10 files changed

+83
-31
lines changed

CMakeLists.txt

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,8 @@ ENDIF(WIN32)
5555
# ----------------------------------------------------
5656
# --- OPTIONS ---------------------------------------
5757
# ----------------------------------------------------
58-
OPTION (EIGEN_NUMPY_ALIGNED "Directly aligned data between Numpy and Eigen" OFF)
5958
OPTION (BUILD_UNIT_TESTS "Build the unitary tests" ON)
6059

61-
IF(EIGEN_NUMPY_ALIGNED)
62-
ADD_DEFINITIONS(-DEIGENPY_ALIGNED)
63-
ENDIF(EIGEN_NUMPY_ALIGNED)
64-
6560
# ----------------------------------------------------
6661
# --- DEPENDANCIES -----------------------------------
6762
# ----------------------------------------------------
@@ -103,6 +98,7 @@ SET(HEADERS
10398
registration.hpp
10499
angle-axis.hpp
105100
quaternion.hpp
101+
stride.hpp
106102
ref.hpp
107103
)
108104

@@ -157,13 +153,9 @@ ADD_SUBDIRECTORY(python)
157153
# ----------------------------------------------------
158154
ADD_SUBDIRECTORY(unittest)
159155

160-
IF(EIGEN_NUMPY_ALIGNED)
161-
PKG_CONFIG_APPEND_CFLAGS("-DEIGENPY_ALIGNED")
162-
ENDIF(EIGEN_NUMPY_ALIGNED)
163-
164156
PKG_CONFIG_APPEND_LIBS(${PROJECT_NAME})
165-
PKG_CONFIG_APPEND_CFLAGS("-I${PYTHON_INCLUDE_DIRS}")
166-
PKG_CONFIG_APPEND_CFLAGS("-I${NUMPY_INCLUDE_DIRS}")
157+
PKG_CONFIG_APPEND_CFLAGS("-isystem ${PYTHON_INCLUDE_DIRS}")
158+
PKG_CONFIG_APPEND_CFLAGS("-isystem ${NUMPY_INCLUDE_DIRS}")
167159
PKG_CONFIG_APPEND_BOOST_LIBS(${BOOST_COMPONENTS})
168160

169161
SETUP_PROJECT_FINALIZE()

src/details.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ namespace eigenpy
8585
}
8686
};
8787

88+
#if EIGEN_VERSION_AT_LEAST(3,2,0)
8889
template<typename MatType>
8990
struct EigenObjectAllocator< eigenpy::Ref<MatType> >
9091
{
@@ -101,6 +102,7 @@ namespace eigenpy
101102
MapNumpy<MatType>::map(pyArray) = mat;
102103
}
103104
};
105+
#endif
104106

105107
/* --- TO PYTHON -------------------------------------------------------------- */
106108
template<typename MatType>

src/eigenpy.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,20 @@
1919

2020
#include "eigenpy/fwd.hpp"
2121
#include "eigenpy/deprecated.hh"
22+
#if EIGEN_VERSION_AT_LEAST(3,2,0)
2223
#include "eigenpy/ref.hpp"
2324

2425
#define ENABLE_SPECIFIC_MATRIX_TYPE(TYPE) \
2526
enableEigenPySpecific<TYPE>(); \
2627
enableEigenPySpecific< eigenpy::Ref<TYPE> >();
2728

29+
#else
30+
31+
#define ENABLE_SPECIFIC_MATRIX_TYPE(TYPE) \
32+
enableEigenPySpecific<TYPE>();
33+
34+
#endif
35+
2836
namespace eigenpy
2937
{
3038
/* Enable Eigen-Numpy serialization for a set of standard MatrixBase instance. */

src/fwd.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@
2828
#include <numpy/noprefix.h>
2929

3030
#ifdef NPY_ALIGNED
31-
#define EIGENPY_DEFAULT_ALIGNMENT_VALUE Eigen::Aligned16
31+
#if EIGEN_VERSION_AT_LEAST(3,2,90)
32+
#define EIGENPY_DEFAULT_ALIGNMENT_VALUE Eigen::Aligned16
3233
#else
33-
#define EIGENPY_DEFAULT_ALIGNMENT_VALUE Eigen::Unaligned
34+
#define EIGENPY_DEFAULT_ALIGNMENT_VALUE Eigen::Aligned
35+
#endif
36+
#else
37+
#define EIGENPY_DEFAULT_ALIGNMENT_VALUE Eigen::Unaligned
3438
#endif
3539

3640
#endif // ifndef __eigenpy_fwd_hpp__
41+

src/map.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "eigenpy/fwd.hpp"
1818
#include <numpy/arrayobject.h>
1919
#include "eigenpy/exception.hpp"
20+
#include "eigenpy/stride.hpp"
2021

2122
namespace eigenpy
2223
{

src/ref.hpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,17 @@
1818
#define __eigenpy_ref_hpp__
1919

2020
#include "eigenpy/fwd.hpp"
21+
#include "eigenpy/stride.hpp"
2122

2223
// For old Eigen versions, EIGEN_DEVICE_FUNC is not defined.
2324
// We must define it just in the scope of this file.
24-
#if not EIGEN_VERSION_AT_LEAST(3,2,91)
25+
#if not EIGEN_VERSION_AT_LEAST(3,2,90)
2526
#define EIGEN_DEVICE_FUNC
2627
#endif
2728

2829
namespace eigenpy
2930
{
30-
template<typename MatType, int IsVectorAtCompileTime = MatType::IsVectorAtCompileTime>
31-
struct StrideType
32-
{
33-
typedef Eigen::Stride<Eigen::Dynamic,Eigen::Dynamic> type;
34-
};
35-
36-
template<typename MatType>
37-
struct StrideType<MatType,1>
38-
{
39-
typedef Eigen::InnerStride<Eigen::Dynamic> type;
40-
};
41-
31+
4232
template<typename PlainObjectType>
4333
struct Ref : Eigen::Ref<PlainObjectType,EIGENPY_DEFAULT_ALIGNMENT_VALUE,typename StrideType<PlainObjectType>::type>
4434
{
@@ -58,7 +48,7 @@ namespace eigenpy
5848
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. */
5949
typedef typename Eigen::internal::ref_selector<Base>::type Nested;
6050
typedef typename Eigen::internal::traits<Base>::StorageKind StorageKind;
61-
#if EIGEN_VERSION_AT_LEAST(3,2,91)
51+
#if EIGEN_VERSION_AT_LEAST(3,2,90)
6252
typedef typename Eigen::internal::traits<Base>::StorageIndex StorageIndex;
6353
#else
6454
typedef typename Eigen::internal::traits<Base>::Index StorageIndex;
@@ -104,7 +94,7 @@ namespace eigenpy
10494
}; // struct Ref<PlainObjectType>
10595
}
10696

107-
#if not EIGEN_VERSION_AT_LEAST(3,2,91)
97+
#if not EIGEN_VERSION_AT_LEAST(3,2,90)
10898
#undef EIGEN_DEVICE_FUNC
10999
#endif
110100

src/solvers/preconditioners.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017, Justin Carpentier, LAAS-CNRS
2+
* Copyright 2017-2018, Justin Carpentier, LAAS-CNRS
33
*
44
* This file is part of eigenpy.
55
* eigenpy is free software: you can redistribute it and/or
@@ -14,12 +14,16 @@
1414
* with eigenpy. If not, see <http://www.gnu.org/licenses/>.
1515
*/
1616

17+
#include <Eigen/Core>
18+
19+
#if EIGEN_VERSION_AT_LEAST(3,2,0)
1720
#include "eigenpy/solvers/preconditioners.hpp"
1821
#include "eigenpy/solvers/BasicPreconditioners.hpp"
1922
//#include "eigenpy/solvers/BFGSPreconditioners.hpp"
2023

2124
namespace eigenpy
2225
{
26+
2327
void exposePreconditioners()
2428
{
2529
using namespace Eigen;
@@ -32,4 +36,8 @@ namespace eigenpy
3236
// LimitedBFGSPreconditionerBaseVisitor< LimitedBFGSPreconditioner<double,Eigen::Dynamic,Eigen::Upper|Eigen::Lower> >::expose("LimitedBFGSPreconditioner");
3337

3438
}
39+
3540
} // namespace eigenpy
41+
42+
#endif
43+

src/solvers/solvers.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017, Justin Carpentier, LAAS-CNRS
2+
* Copyright 2017-2018, Justin Carpentier, LAAS-CNRS
33
*
44
* This file is part of eigenpy.
55
* eigenpy is free software: you can redistribute it and/or
@@ -14,6 +14,10 @@
1414
* with eigenpy. If not, see <http://www.gnu.org/licenses/>.
1515
*/
1616

17+
#include <Eigen/Core>
18+
19+
#if EIGEN_VERSION_AT_LEAST(3,2,0)
20+
1721
#include "eigenpy/solvers/solvers.hpp"
1822
#include "eigenpy/solvers/ConjugateGradient.hpp"
1923

@@ -43,3 +47,6 @@ namespace eigenpy
4347
;
4448
}
4549
} // namespace eigenpy
50+
51+
#endif
52+

src/stride.hpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2018, Justin Carpentier <[email protected]>, LAAS-CNRS
3+
*
4+
* This file is part of eigenpy.
5+
* eigenpy is free software: you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public License
7+
* as published by the Free Software Foundation, either version 3 of
8+
* the License, or (at your option) any later version.
9+
* eigenpy is distributed in the hope that it will be
10+
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
11+
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details. You should
13+
* have received a copy of the GNU Lesser General Public License along
14+
* with eigenpy. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
#ifndef __eigenpy_stride_hpp__
18+
#define __eigenpy_stride_hpp__
19+
20+
#include <Eigen/Core>
21+
22+
namespace eigenpy
23+
{
24+
template<typename MatType, int IsVectorAtCompileTime = MatType::IsVectorAtCompileTime>
25+
struct StrideType
26+
{
27+
typedef Eigen::Stride<Eigen::Dynamic,Eigen::Dynamic> type;
28+
};
29+
30+
template<typename MatType>
31+
struct StrideType<MatType,1>
32+
{
33+
typedef Eigen::InnerStride<Eigen::Dynamic> type;
34+
};
35+
}
36+
37+
#endif // ifndef __eigenpy_stride_hpp__

unittest/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,7 @@ ADD_CUSTOM_TARGET(check COMMAND ${CMAKE_CTEST_COMMAND})
4040

4141
ADD_LIB_UNIT_TEST(matrix "eigen3")
4242
ADD_LIB_UNIT_TEST(geometry "eigen3")
43-
ADD_LIB_UNIT_TEST(ref "eigen3")
43+
IF(NOT ${EIGEN3_VERSION} VERSION_LESS "3.2.0")
44+
ADD_LIB_UNIT_TEST(ref "eigen3")
45+
ENDIF()
4446

0 commit comments

Comments
 (0)