From f3cc1cb4d8c83771ad080de44946efe73c4f8fc7 Mon Sep 17 00:00:00 2001 From: Justin Carpentier <justin.carpentier@inria.fr> Date: Tue, 25 Feb 2020 14:27:24 +0100 Subject: [PATCH] core: check whether memory is aligned or not for Eigen::Ref --- include/eigenpy/eigen-allocator.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/eigenpy/eigen-allocator.hpp b/include/eigenpy/eigen-allocator.hpp index 5197ea78..bd3093cf 100644 --- a/include/eigenpy/eigen-allocator.hpp +++ b/include/eigenpy/eigen-allocator.hpp @@ -9,6 +9,8 @@ #include "eigenpy/map.hpp" #include "eigenpy/scalar-conversion.hpp" +#include <boost/align/is_aligned.hpp> + namespace eigenpy { @@ -228,6 +230,12 @@ namespace eigenpy need_to_allocate |= false; else need_to_allocate |= true; + if(Options != Eigen::Unaligned) // we need to check whether the memory is correctly aligned and composed of a continuous segment + { + void * data_ptr = PyArray_DATA(pyArray); + if(!PyArray_ISONESEGMENT(pyArray) || !boost::alignment::is_aligned(data_ptr,Options)) + need_to_allocate |= true; + } void * raw_ptr = storage->storage.bytes; if(need_to_allocate) -- GitLab