Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ SET(HEADERS
src/map.hpp
src/geometry.hpp
src/memory.hpp
src/registration.hpp
src/angle-axis.hpp
src/quaternion.hpp
)
Expand Down
31 changes: 8 additions & 23 deletions src/details.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <iostream>

#include "eigenpy/eigenpy.hpp"
#include "eigenpy/registration.hpp"
#include "eigenpy/exception.hpp"
#include "eigenpy/map.hpp"

Expand Down Expand Up @@ -190,7 +191,7 @@ namespace eigenpy
typename MapNumpy<EquivalentEigenType>::EigenMap numpyMap = MapNumpy<EquivalentEigenType>::map(pyArray);

void* storage = ((bp::converter::rvalue_from_python_storage<MatType>*)
(memory))->storage.bytes;
((void*)memory))->storage.bytes;
assert( (numpyMap.rows()<INT_MAX) && (numpyMap.cols()<INT_MAX)
&& "Map range larger than int ... can never happen." );
int r=(int)numpyMap.rows(),c=(int)numpyMap.cols();
Expand All @@ -201,32 +202,16 @@ namespace eigenpy
eigenMatrix = numpyMap;
}
};

#define numpy_import_array() {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); } }

template<typename MatType,typename EigenEquivalentType>
void enableEigenPySpecific()
{
import_array();

#ifdef EIGEN_DONT_VECTORIZE

boost::python::to_python_converter<MatType,
eigenpy::EigenToPy<MatType,MatType> >();
eigenpy::EigenFromPy<MatType,MatType>();
#else

boost::python::to_python_converter<MatType,
eigenpy::EigenToPy<MatType,MatType> >();
eigenpy::EigenFromPy<MatType,MatType>();
if(check_registration<MatType>()) return;
numpy_import_array();

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


boost::python::to_python_converter<MatType,EigenToPy<MatType,MatType> >();
EigenFromPy<MatType,MatType>();
}

} // namespace eigenpy
Expand Down
7 changes: 5 additions & 2 deletions src/exception.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 LAAS-CNRS
* Copyright (c) 2015-2016 LAAS-CNRS
*
* This file is part of eigenpy.
* eigenpy is free software: you can redistribute it and/or
Expand All @@ -14,7 +14,8 @@
* with eigenpy. If not, see <http://www.gnu.org/licenses/>.
*/

#include <eigenpy/exception.hpp>
#include "eigenpy/exception.hpp"
#include "eigenpy/registration.hpp"


namespace eigenpy
Expand All @@ -30,6 +31,8 @@ namespace eigenpy

void Exception::registerException()
{
if(check_registration<eigenpy::Exception>()) return;

pyType = boost::python::class_<eigenpy::Exception>
("Exception",boost::python::init<std::string>())
.add_property("message", &eigenpy::Exception::copyMessage)
Expand Down
4 changes: 2 additions & 2 deletions src/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ namespace boost { namespace python { namespace objects { \
Holder* holder = Derived::construct(&instance->storage, (PyObject*)instance, x); \
holder->install(raw_result); \
\
size_t holder_offset = reinterpret_cast<size_t>(holder) \
- reinterpret_cast<size_t>(&instance->storage) \
Py_ssize_t holder_offset = reinterpret_cast<Py_ssize_t>(holder) \
- reinterpret_cast<Py_ssize_t>(&instance->storage) \
+ offsetof(instance_t, storage); \
Py_SIZE(instance) = holder_offset; \
\
Expand Down
45 changes: 45 additions & 0 deletions src/registration.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2016, Justin Carpentier, 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_registration_hpp__
#define __eigenpy_registration_hpp__

#include <boost/python.hpp>

namespace eigenpy
{
///
/// \brief Check at runtime the registration of the type T inside the boost python registry.
///
/// \tparam T The type to check the registration.
///
/// \returns true if the type T is already registered.
///
template<typename T>
inline bool check_registration()
{
namespace bp = boost::python;

const bp::type_info info = bp::type_id<T>();
const bp::converter::registration* reg = bp::converter::registry::query(info);
if (reg == NULL) return false;
else if ((*reg).m_to_python == NULL) return false;

return true;
}
}

#endif // ifndef __eigenpy_registration_hpp__