22 return PyObject_CallMethod(obj,
const_cast<char *
>(meth),
const_cast<char *
>(
""));
28 return PyObject_CallMethod(obj,
const_cast<char *
>(meth),
const_cast<char *
>(
"O"), arg1);
34 if (PyObject_IsTrue(value) == 1) {
58 }
else if (dtype ==
"u4") {
59 return "unsigned int";
60 }
else if (dtype ==
"i8") {
62 }
else if (dtype ==
"u8") {
64 }
else if (dtype ==
"f4") {
66 }
else if (dtype ==
"f8") {
69 PyErr_SetString(PyExc_RuntimeError, (
"Object not convertible: Python object has unknown data-type '" + dtype +
"'.").c_str());
80 auto pyinterface = PyObject_GetAttrString(obj,
"__array_interface__");
82 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: __array_interface__ does not exist.");
85 if (!PyDict_Check(pyinterface)) {
86 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: __array_interface__ is not a dictionary.");
98 auto pydata = PyDict_GetItemString(obj,
"data");
100 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: __array_interface__['data'] does not exist.");
103 return PyLong_AsLong(PyTuple_GetItem(pydata, 0));
112 auto pytypestr = PyDict_GetItemString(obj,
"typestr");
114 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: __array_interface__['typestr'] does not exist.");
118 const auto length = typestr.length();
120 PyErr_SetString(PyExc_RuntimeError,
121 (
"Object not convertible: __array_interface__['typestr'] returned '" + typestr +
"' with invalid length unequal 3.").c_str());
133 const auto length = typestr.size();
134 const auto dtypesizestr = typestr.substr(length - 1, length);
135 return std::stoi(dtypesizestr);
144 const auto endianess = typestr.substr(1, 2);
146 const auto byteswap =
"<";
148 const auto byteswap =
">";
150 if (!endianess.compare(byteswap)) {
151 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: Endianess of __array_interface__['typestr'] does not match endianess of ROOT.");
#define CPyCppyy_PyText_AsString
PyObject * BoolNot(PyObject *value)
TClass * GetTClass(const CPyCppyy::CPPInstance *pyobj)
unsigned long long GetDataPointerFromArrayInterface(PyObject *obj)
Get data pointer from Numpy array interface and perform error handling.
unsigned int GetDatatypeSizeFromTypestr(const std::string &typestr)
Get size of data type in bytes from Numpy type string.
std::string GetCppTypeFromNumpyType(const std::string &dtype)
Convert Numpy data-type string to the according C++ data-type string.
std::string GetTypestrFromArrayInterface(PyObject *obj)
Get type string from Numpy array interface and perform error handling.
bool CheckEndianessFromTypestr(const std::string &typestr)
Check whether endianess in type string matches the endianess of ROOT.
PyObject * CallPyObjMethod(PyObject *obj, const char *meth)
Set of helper functions that are invoked from the C++ implementation of pythonizations.
PyObject * GetArrayInterface(PyObject *obj)
Get Numpy array interface and perform error handling.
Cppyy::TCppType_t ObjectIsA(bool check_smart=true) const
TClass instances represent classes, structs and namespaces in the ROOT type system.
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
RPY_EXPORTED std::string GetScopedFinalName(TCppType_t type)