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

core: add helpers in Register

parent 94e47a4f
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,25 @@ namespace eigenpy {
struct EIGENPY_DLLAPI Register {
static PyArray_Descr *getPyArrayDescr(PyTypeObject *py_type_ptr);
static PyArray_Descr *getPyArrayDescrFromTypeNum(const int type_num);
template <typename Scalar>
static PyArray_Descr *getPyArrayDescrFromScalarType() {
if (!isNumpyNativeType<Scalar>()) {
const std::type_info &info = typeid(Scalar);
if (instance().type_to_py_type_bindings.find(&info) !=
instance().type_to_py_type_bindings.end()) {
PyTypeObject *py_type = instance().type_to_py_type_bindings[&info];
return instance().py_array_descr_bindings[py_type];
} else
return nullptr;
} else {
PyArray_Descr *new_descr =
call_PyArray_DescrFromType(NumpyEquivalentType<Scalar>::type_code);
return new_descr;
}
}
template <typename Scalar>
static bool isRegistered() {
return isRegistered(Register::getPyType<Scalar>());
......
......@@ -14,6 +14,17 @@ PyArray_Descr* Register::getPyArrayDescr(PyTypeObject* py_type_ptr) {
return NULL;
}
PyArray_Descr* Register::getPyArrayDescrFromTypeNum(const int type_num) {
if (type_num >= NPY_USERDEF) {
for (const auto& elt : instance().py_array_code_bindings) {
if (elt.second == type_num)
return instance().py_array_descr_bindings[elt.first];
}
return nullptr;
} else
return PyArray_DescrFromType(type_num);
}
bool Register::isRegistered(PyTypeObject* py_type_ptr) {
if (getPyArrayDescr(py_type_ptr) != NULL)
return true;
......
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