Skip to content

Commit cfba28b

Browse files
committed
[Core] Introduce dedicated struct for allocation
1 parent cd37a2f commit cfba28b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/details.hpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ namespace eigenpy
9898

9999
/* --- FROM PYTHON ------------------------------------------------------------ */
100100

101+
template<typename MatType>
102+
struct EigenObjectAllocator
103+
{
104+
static void allocate(PyArrayObject * pyArray, void * storage)
105+
{
106+
typename MapNumpy<MatType>::EigenMap numpyMap = MapNumpy<MatType>::map(pyArray);
107+
new(storage) MatType(numpyMap);
108+
}
109+
};
110+
101111
template<typename MatType>
102112
struct EigenFromPy
103113
{
@@ -159,14 +169,13 @@ namespace eigenpy
159169
using namespace Eigen;
160170

161171
PyArrayObject * pyArray = reinterpret_cast<PyArrayObject*>(pyObj);
162-
typename MapNumpy<MatType>::EigenMap numpyMap = MapNumpy<MatType>::map(pyArray);
163-
assert( (numpyMap.rows()<INT_MAX) && (numpyMap.cols()<INT_MAX)
164-
&& "Map range larger than int ... can never happen." );
172+
assert((PyArray_DIMS(pyArray)[0]<INT_MAX) && (PyArray_DIMS(pyArray)[1]<INT_MAX));
165173

166174
void* storage = ((bp::converter::rvalue_from_python_storage<MatType>*)
167175
((void*)memory))->storage.bytes;
168176

169-
new(storage) MatType(numpyMap);
177+
EigenObjectAllocator<MatType>::allocate(pyArray,storage);
178+
170179
memory->convertible = storage;
171180
}
172181
};

0 commit comments

Comments
 (0)