5 #ifndef __eigenpy_register_hpp__ 6 #define __eigenpy_register_hpp__ 21 static PyArray_Descr *getPyArrayDescr(PyTypeObject *py_type_ptr);
23 template <
typename Scalar>
25 return isRegistered(Register::getPyType<Scalar>());
28 static bool isRegistered(PyTypeObject *py_type_ptr);
30 static int getTypeCode(PyTypeObject *py_type_ptr);
32 template <
typename Scalar>
34 if (!isNumpyNativeType<Scalar>()) {
35 const PyTypeObject *const_py_type_ptr =
36 bp::converter::registered_pytype<Scalar>::get_pytype();
37 if (const_py_type_ptr == NULL) {
39 ss <<
"The type " <<
typeid(Scalar).
name()
40 <<
" does not have a registered converter inside Boot.Python." 42 throw std::invalid_argument(ss.str());
44 PyTypeObject *py_type_ptr =
const_cast<PyTypeObject *
>(const_py_type_ptr);
47 PyArray_Descr *new_descr =
49 return new_descr->typeobj;
53 template <
typename Scalar>
55 if (!isNumpyNativeType<Scalar>()) {
56 return getPyArrayDescr(getPyType<Scalar>());
62 template <
typename Scalar>
64 if (isNumpyNativeType<Scalar>())
67 const std::type_info &info =
typeid(Scalar);
68 if (instance().type_to_py_type_bindings.find(&info) !=
69 instance().type_to_py_type_bindings.end()) {
70 PyTypeObject *py_type = instance().type_to_py_type_bindings[&info];
71 int code = instance().py_array_code_bindings[py_type];
80 PyTypeObject *py_type_ptr,
const std::type_info *type_info_ptr,
81 const int type_size,
const int alignment, PyArray_GetItemFunc *getitem,
82 PyArray_SetItemFunc *setitem, PyArray_NonzeroFunc *nonzero,
83 PyArray_CopySwapFunc *copyswap, PyArray_CopySwapNFunc *copyswapn,
84 PyArray_DotFunc *dotfunc, PyArray_FillFunc *
fill,
85 PyArray_FillWithScalarFunc *fillwithscalar);
93 bool operator()(
const PyTypeObject *
a,
const PyTypeObject *b)
const {
94 return std::string(a->tp_name) < std::string(b->tp_name);
99 bool operator()(
const std::type_info *
a,
const std::type_info *b)
const {
100 return std::string(a->name()) < std::string(b->name());
104 typedef std::map<const std::type_info *, PyTypeObject *, Compare_TypeInfo>
108 typedef std::map<PyTypeObject *, PyArray_Descr *, Compare_PyTypeObject>
112 typedef std::map<PyTypeObject *, int, Compare_PyTypeObject>
MapCode;
118 #endif // __eigenpy_register_hpp__ static PyArray_Descr * getPyArrayDescr()
MapCode py_array_code_bindings
bool operator()(const PyTypeObject *a, const PyTypeObject *b) const
bool operator()(const std::type_info *a, const std::type_info *b) const
Structure collecting all the types registers in Numpy via EigenPy.
MapDescr py_array_descr_bindings
std::map< const std::type_info *, PyTypeObject *, Compare_TypeInfo > MapInfo
static PyTypeObject * getPyType()
static bool isRegistered()
std::map< PyTypeObject *, int, Compare_PyTypeObject > MapCode
std::map< PyTypeObject *, PyArray_Descr *, Compare_PyTypeObject > MapDescr
MapInfo type_to_py_type_bindings
int registerNewType(PyTypeObject *py_type_ptr=NULL)
PyArray_Descr * call_PyArray_DescrFromType(int typenum)
void fill(Eigen::Ref< MatType > mat, const typename MatType::Scalar &value)