Skip to content
Snippets Groups Projects
Verified Commit 0deef658 authored by Justin Carpentier's avatar Justin Carpentier
Browse files

core: add alignment support

parent 2a6d963f
No related branches found
No related tags found
No related merge requests found
#
# Copyright (c) 2014-2019 CNRS Copyright (c) 2018-2022 INRIA
# Copyright (c) 2014-2019 CNRS Copyright (c) 2018-2023 INRIA
#
cmake_minimum_required(VERSION 3.1)
......@@ -130,6 +130,7 @@ set(${PROJECT_NAME}_HEADERS
${${PROJECT_NAME}_UTILS_HEADERS}
${${PROJECT_NAME}_SOLVERS_HEADERS}
${${PROJECT_NAME}_DECOMPOSITIONS_HEADERS}
include/eigenpy/alignment.hpp
include/eigenpy/computation-info.hpp
include/eigenpy/eigenpy.hpp
include/eigenpy/exception.hpp
......
/*
* Copyright 2023, INRIA
*/
#ifndef __eigenpy_alignment_hpp__
#define __eigenpy_alignment_hpp__
#include <boost/python/detail/referent_storage.hpp>
#include <boost/python/converter/arg_from_python.hpp>
#include <boost/python/converter/rvalue_from_python_data.hpp>
#include <boost/type_traits/aligned_storage.hpp>
namespace eigenpy {
template <std::size_t size, std::size_t alignment = EIGENPY_DEFAULT_ALIGN_BYTES>
struct aligned_storage {
union type {
typename ::boost::aligned_storage<size, alignment>::type data;
char bytes[size];
};
};
} // namespace eigenpy
namespace boost {
namespace python {
namespace detail {
template <typename Scalar, int Rows, int Cols, int Options, int MaxRows,
int MaxCols>
struct referent_storage<
Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> &> {
typedef Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> T;
typedef
typename eigenpy::aligned_storage<referent_size<T &>::value>::type type;
};
template <typename Scalar, int Rows, int Cols, int Options, int MaxRows,
int MaxCols>
struct referent_storage<
const Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> &> {
typedef Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> T;
typedef
typename eigenpy::aligned_storage<referent_size<T &>::value>::type type;
};
template <typename Scalar, int Options>
struct referent_storage<Eigen::Quaternion<Scalar, Options> &> {
typedef Eigen::Quaternion<Scalar, Options> T;
typedef
typename eigenpy::aligned_storage<referent_size<T &>::value>::type type;
};
template <typename Scalar, int Options>
struct referent_storage<const Eigen::Quaternion<Scalar, Options> &> {
typedef Eigen::Quaternion<Scalar, Options> T;
typedef
typename eigenpy::aligned_storage<referent_size<T &>::value>::type type;
};
} // namespace detail
} // namespace python
} // namespace boost
namespace eigenpy {
template <class T>
struct call_destructor {
static void run(void *bytes) {
typedef typename boost::remove_const<
typename boost::remove_reference<T>::type>::type T_;
static_cast<T_ *>((void *)bytes)->~T_();
}
};
template <class T>
struct rvalue_from_python_data
: ::boost::python::converter::rvalue_from_python_storage<T> {
#if (!defined(__MWERKS__) || __MWERKS__ >= 0x3000) && \
(!defined(__EDG_VERSION__) || __EDG_VERSION__ >= 245) && \
(!defined(__DECCXX_VER) || __DECCXX_VER > 60590014) && \
!defined(BOOST_PYTHON_SYNOPSIS) /* Synopsis' OpenCXX has trouble parsing \
this */
// This must always be a POD struct with m_data its first member.
BOOST_STATIC_ASSERT(
BOOST_PYTHON_OFFSETOF(
::boost::python::converter::rvalue_from_python_storage<T>, stage1) ==
0);
#endif
// The usual constructor
rvalue_from_python_data(
::boost::python::converter::rvalue_from_python_stage1_data const
&_stage1) {
this->stage1 = _stage1;
}
// This constructor just sets m_convertible -- used by
// implicitly_convertible<> to perform the final step of the
// conversion, where the construct() function is already known.
rvalue_from_python_data(void *convertible) {
this->stage1.convertible = convertible;
}
// Destroys any object constructed in the storage.
~rvalue_from_python_data() {
if (this->stage1.convertible == this->storage.bytes) {
void *storage = reinterpret_cast<void *>(this->storage.bytes);
call_destructor<T>::run(storage);
}
}
};
} // namespace eigenpy
#endif // __eigenpy_alignment_hpp__
......@@ -47,4 +47,6 @@ template <typename MatType,
struct EigenFromPy;
} // namespace eigenpy
#include "eigenpy/alignment.hpp"
#endif // ifndef __eigenpy_fwd_hpp__
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment