Skip to content

Commit 0c4870a

Browse files
committed
Merge pull request #6 from jcarpent/devel
Enable alignment between Eigen matrix and Numpy matrix
2 parents 5b9029e + d7ed369 commit 0c4870a

File tree

9 files changed

+127
-19
lines changed

9 files changed

+127
-19
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ build/
22
release/
33
_build/
44
_release/
5-
*~
5+
*~
6+
Xcode/

CMakeLists.txt

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
#
2-
# Copyright 2014 CNRS
2+
# Copyright (c) 2015 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/>.
315
#
416

517
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
@@ -23,6 +35,15 @@ IF(APPLE)
2335
SET(CMAKE_MACOSX_RPATH TRUE)
2436
ENDIF(APPLE)
2537

38+
# ----------------------------------------------------
39+
# --- OPTIONS ---------------------------------------
40+
# ----------------------------------------------------
41+
OPTION (EIGEN_NUMPY_ALIGNED "Directly aligned data between Numpy and Eigen" OFF)
42+
43+
IF(EIGEN_NUMPY_ALIGNED)
44+
ADD_DEFINITIONS(-DEIGENPY_ALIGNED)
45+
ENDIF(EIGEN_NUMPY_ALIGNED)
46+
2647
# ----------------------------------------------------
2748
# --- DEPENDANCIES -----------------------------------
2849
# ----------------------------------------------------
@@ -102,6 +123,9 @@ ADD_LIBRARY(geometry SHARED unittest/geometry.cpp)
102123
TARGET_LINK_LIBRARIES(geometry ${Boost_LIBRARIES} ${PROJECT_NAME})
103124
SET_TARGET_PROPERTIES(geometry PROPERTIES PREFIX "")
104125

126+
IF(EIGEN_NUMPY_ALIGNED)
127+
PKG_CONFIG_APPEND_CFLAGS("-DEIGENPY_ALIGNED")
128+
ENDIF(EIGEN_NUMPY_ALIGNED)
105129
PKG_CONFIG_APPEND_CFLAGS("-I${PYTHON_INCLUDE_DIRS}")
106130
PKG_CONFIG_APPEND_CFLAGS("-I${NUMPY_INCLUDE_DIRS}")
107131
PKG_CONFIG_APPEND_LIBS("boost_python")

src/details.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2015 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+
117
#include "eigenpy/details.hpp"
218

319
namespace eigenpy

src/details.hpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ namespace eigenpy
108108
{
109109
static MatType & construct(void*storage,int /*r*/,int c)
110110
{
111-
return * new(storage) MatType(c);
111+
return * new(storage) MatType(R,c);
112112
}
113113
};
114114

@@ -117,7 +117,7 @@ namespace eigenpy
117117
{
118118
static MatType & construct(void*storage,int r,int /*c*/)
119119
{
120-
return * new(storage) MatType(r);
120+
return * new(storage) MatType(r,C);
121121
}
122122
};
123123

@@ -168,7 +168,6 @@ namespace eigenpy
168168
static void construct(PyObject* pyObj,
169169
bp::converter::rvalue_from_python_stage1_data* memory)
170170
{
171-
typedef typename MatType::Scalar T;
172171
using namespace Eigen;
173172

174173
PyArrayObject * pyArray = reinterpret_cast<PyArrayObject*>(pyObj);
@@ -191,20 +190,26 @@ namespace eigenpy
191190
void enableEigenPySpecific()
192191
{
193192
import_array();
194-
195-
#ifdef EIGEN_DONT_VECTORIZE
193+
194+
#ifdef EIGEN_DONT_VECTORIZE
195+
196196
boost::python::to_python_converter<MatType,
197-
eigenpy::EigenToPy<MatType,MatType> >();
197+
eigenpy::EigenToPy<MatType,MatType> >();
198198
eigenpy::EigenFromPy<MatType,MatType>();
199-
#else
200-
typedef typename eigenpy::UnalignedEquivalent<MatType>::type MatTypeDontAlign;
199+
#else
201200

202201
boost::python::to_python_converter<MatType,
203202
eigenpy::EigenToPy<MatType,MatType> >();
203+
eigenpy::EigenFromPy<MatType,MatType>();
204+
205+
typedef typename eigenpy::UnalignedEquivalent<MatType>::type MatTypeDontAlign;
206+
#ifndef EIGENPY_ALIGNED
204207
boost::python::to_python_converter<MatTypeDontAlign,
205208
eigenpy::EigenToPy<MatTypeDontAlign,MatTypeDontAlign> >();
206209
eigenpy::EigenFromPy<MatTypeDontAlign,MatTypeDontAlign>();
207210
#endif
211+
#endif
212+
208213

209214
}
210215

src/eigenpy.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2015 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+
117
#include "eigenpy/eigenpy.hpp"
218

319
namespace eigenpy

src/exception.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2015 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+
117
#include <eigenpy/exception.hpp>
218

319

src/fwd.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ namespace eigenpy
2727
{
2828
typedef Eigen::MatrixBase<D> MatType;
2929
typedef Eigen::Matrix<typename D::Scalar,
30-
D::RowsAtCompileTime,
31-
D::ColsAtCompileTime,
32-
D::Options | Eigen::DontAlign,
33-
D::MaxRowsAtCompileTime,
34-
D::MaxColsAtCompileTime> type;
30+
D::RowsAtCompileTime,
31+
D::ColsAtCompileTime,
32+
#ifndef EIGENPY_ALIGNED
33+
D::Options | Eigen::DontAlign,
34+
#else
35+
D::Options,
36+
#endif
37+
D::MaxRowsAtCompileTime,
38+
D::MaxColsAtCompileTime> type;
3539
};
3640

3741
} // namespace eigenpy

src/quaternion.hpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ namespace eigenpy
3939
template<>
4040
struct UnalignedEquivalent<Eigen::Quaterniond>
4141
{
42-
typedef Eigen::Quaternion<double,Eigen::DontAlign> type;
42+
#ifndef EIGENPY_ALIGNED
43+
typedef Eigen::Quaternion<Eigen::Quaterniond::Scalar,Eigen::DontAlign> type;
44+
#else
45+
typedef Eigen::Quaterniond type;
46+
#endif
4347
};
4448

4549
namespace bp = boost::python;
@@ -51,10 +55,15 @@ namespace eigenpy
5155
typedef Eigen::QuaternionBase<Quaternion> QuaternionBase;
5256
typedef typename eigenpy::UnalignedEquivalent<Quaternion>::type QuaternionUnaligned;
5357

54-
typedef typename QuaternionUnaligned::Scalar Scalar;
55-
typedef Eigen::Matrix<Scalar,3,1,Eigen::DontAlign> Vector3;
58+
typedef typename QuaternionBase::Scalar Scalar;
5659
typedef typename QuaternionUnaligned::Coefficients Coefficients;
60+
#ifndef EIGENPY_ALIGNED
61+
typedef Eigen::Matrix<Scalar,3,1,Eigen::DontAlign> Vector3;
5762
typedef Eigen::Matrix<Scalar,3,3,Eigen::DontAlign> Matrix3;
63+
#else
64+
typedef Eigen::Matrix<Scalar,3,1,0> Vector3;
65+
typedef Eigen::Matrix<Scalar,3,3,0> Matrix3;
66+
#endif
5867

5968
typedef Eigen::AngleAxis<Scalar> AngleAxisUnaligned;
6069

@@ -169,8 +178,10 @@ namespace eigenpy
169178
bp::init<>())
170179
.def(QuaternionVisitor<Quaternion>())
171180
;
172-
181+
182+
#ifndef EIGENPY_ALIGNED
173183
bp::to_python_converter< Quaternion,QuaternionVisitor<Quaternion> >();
184+
#endif
174185
}
175186

176187
};

unittest/geometry.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright (c) 2015 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+
*/
116

217
#include "eigenpy/eigenpy.hpp"
318
#include "eigenpy/geometry.hpp"

0 commit comments

Comments
 (0)