18 if (type_num >= NPY_USERDEF) {
20 if (elt.second == type_num)
25 return PyArray_DescrFromType(type_num);
45 const int type_size,
const int alignement, PyArray_GetItemFunc* getitem,
46 PyArray_SetItemFunc* setitem, PyArray_NonzeroFunc* nonzero,
47 PyArray_CopySwapFunc* copyswap, PyArray_CopySwapNFunc* copyswapn,
48 PyArray_DotFunc* dotfunc, PyArray_FillFunc*
fill,
49 PyArray_FillWithScalarFunc* fillwithscalar) {
50 bp::tuple tp_bases_extended(
51 bp::make_tuple(bp::handle<>(bp::borrowed(&PyGenericArrType_Type))));
53 bp::tuple(bp::handle<>(bp::borrowed(py_type_ptr->tp_bases)));
55 Py_INCREF(tp_bases_extended.ptr());
56 py_type_ptr->tp_bases = tp_bases_extended.ptr();
58 py_type_ptr->tp_flags &= ~Py_TPFLAGS_READY;
60 if (PyType_Ready(py_type_ptr) <
63 throw std::invalid_argument(
"PyType_Ready fails to initialize input type.");
69 descr.typeobj = py_type_ptr;
71 descr.byteorder =
'=';
73 descr.elsize = type_size;
75 NPY_NEEDS_PYAPI | NPY_USE_GETITEM | NPY_USE_SETITEM | NPY_NEEDS_INIT;
82 PyArray_ArrFuncs* funcs_ptr =
new PyArray_ArrFuncs;
83 PyArray_ArrFuncs& funcs = *funcs_ptr;
86 funcs.getitem = getitem;
87 funcs.setitem = setitem;
88 funcs.nonzero = nonzero;
89 funcs.copyswap = copyswap;
90 funcs.copyswapn = copyswapn;
91 funcs.dotfunc = dotfunc;
93 funcs.fillwithscalar = fillwithscalar;
97 assert(code >= 0 &&
"The return code should be positive");
100 if (PyDict_SetItemString(py_type_ptr->tp_dict,
"dtype",
101 (PyObject*)new_descr) < 0) {
102 throw std::invalid_argument(
"PyDict_SetItemString fails.");
106 std::make_pair(type_info_ptr, py_type_ptr));