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

user types: given type should inherit from np.generic

parent 9154c86d
No related branches found
No related tags found
No related merge requests found
/* /*
* Copyright 2020 INRIA * Copyright 2020-2021 INRIA
*/ */
#include "eigenpy/register.hpp" #include "eigenpy/register.hpp"
...@@ -43,6 +43,20 @@ namespace eigenpy ...@@ -43,6 +43,20 @@ namespace eigenpy
PyArray_CopySwapNFunc * copyswapn, PyArray_CopySwapNFunc * copyswapn,
PyArray_DotFunc * dotfunc) PyArray_DotFunc * dotfunc)
{ {
namespace bp = boost::python;
bp::list bases(bp::handle<>(bp::borrowed(py_type_ptr->tp_bases)));
bases.append((bp::handle<>(bp::borrowed(&PyGenericArrType_Type))));
bp::tuple tp_bases_extended(bases);
Py_INCREF(tp_bases_extended.ptr());
py_type_ptr->tp_bases = tp_bases_extended.ptr();
py_type_ptr->tp_flags &= ~Py_TPFLAGS_READY; // to force the rebuild
if(PyType_Ready(py_type_ptr) < 0) // Force rebuilding of the __bases__ and mro
{
throw std::invalid_argument("PyType_Ready fails to initialize input type.");
}
PyArray_Descr * descr_ptr = new PyArray_Descr(*call_PyArray_DescrFromType(NPY_OBJECT)); PyArray_Descr * descr_ptr = new PyArray_Descr(*call_PyArray_DescrFromType(NPY_OBJECT));
PyArray_Descr & descr = *descr_ptr; PyArray_Descr & descr = *descr_ptr;
descr.typeobj = py_type_ptr; descr.typeobj = py_type_ptr;
......
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