Skip to content

Commit f3cc1cb

Browse files
committed
core: check whether memory is aligned or not for Eigen::Ref
1 parent 3b5e181 commit f3cc1cb

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

include/eigenpy/eigen-allocator.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "eigenpy/map.hpp"
1010
#include "eigenpy/scalar-conversion.hpp"
1111

12+
#include <boost/align/is_aligned.hpp>
13+
1214
namespace eigenpy
1315
{
1416

@@ -228,6 +230,12 @@ namespace eigenpy
228230
need_to_allocate |= false;
229231
else
230232
need_to_allocate |= true;
233+
if(Options != Eigen::Unaligned) // we need to check whether the memory is correctly aligned and composed of a continuous segment
234+
{
235+
void * data_ptr = PyArray_DATA(pyArray);
236+
if(!PyArray_ISONESEGMENT(pyArray) || !boost::alignment::is_aligned(data_ptr,Options))
237+
need_to_allocate |= true;
238+
}
231239

232240
void * raw_ptr = storage->storage.bytes;
233241
if(need_to_allocate)

0 commit comments

Comments
 (0)