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

core: add initEigenObject runner

parent a4678029
No related branches found
No related tags found
No related merge requests found
...@@ -172,6 +172,39 @@ namespace eigenpy ...@@ -172,6 +172,39 @@ namespace eigenpy
bp::object NumpyArrayObject; PyTypeObject * NumpyArrayType; bp::object NumpyArrayObject; PyTypeObject * NumpyArrayType;
}; };
template<typename MatType, bool IsVectorAtCompileTime = MatType::IsVectorAtCompileTime>
struct initEigenObject
{
static MatType * run(PyArrayObject * pyArray, void * storage)
{
assert(PyArray_NDIM(pyArray) == 2);
const int rows = (int)PyArray_DIMS(pyArray)[0];
const int cols = (int)PyArray_DIMS(pyArray)[1];
return new (storage) MatType(rows,cols);
}
};
template<typename MatType>
struct initEigenObject<MatType,true>
{
static MatType * run(PyArrayObject * pyArray, void * storage)
{
if(PyArray_NDIM(pyArray) == 1)
{
const int rows_or_cols = (int)PyArray_DIMS(pyArray)[0];
return new (storage) MatType(rows_or_cols);
}
else
{
const int rows = (int)PyArray_DIMS(pyArray)[0];
const int cols = (int)PyArray_DIMS(pyArray)[1];
return new (storage) MatType(rows,cols);
}
}
};
template<typename MatType> template<typename MatType>
struct EigenObjectAllocator struct EigenObjectAllocator
...@@ -181,10 +214,7 @@ namespace eigenpy ...@@ -181,10 +214,7 @@ namespace eigenpy
static void allocate(PyArrayObject * pyArray, void * storage) static void allocate(PyArrayObject * pyArray, void * storage)
{ {
const int rows = (int)PyArray_DIMS(pyArray)[0]; Type * mat_ptr = initEigenObject<Type>::run(pyArray,storage);
const int cols = (int)PyArray_DIMS(pyArray)[1];
Type * mat_ptr = new (storage) Type(rows,cols);
if(NumpyEquivalentType<Scalar>::type_code == GET_PY_ARRAY_TYPE(pyArray)) if(NumpyEquivalentType<Scalar>::type_code == GET_PY_ARRAY_TYPE(pyArray))
{ {
......
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