31 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: Invalid Python object.");
37 if (pyinterface == NULL)
46 auto pyshape = PyDict_GetItemString(pyinterface,
"shape");
48 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: __array_interface__['shape'] does not exist.");
52 for (
int i = 0; i < PyTuple_Size(pyshape); i++) {
53 if (size == 0) size = 1;
54 size *= PyLong_AsLong(PyTuple_GetItem(pyshape, i));
59 if (typestr.compare(
"") == 0)
64 const auto dtype = typestr.substr(1, typestr.size());
66 if (cppdtype.compare(
"") == 0)
70 const std::string klassname =
"ROOT::VecOps::RVec<" + cppdtype +
">";
71 auto address = (
void*)
gInterpreter->Calc(
"new " + klassname +
"(reinterpret_cast<" + cppdtype +
"*>(" + data +
")," + size +
")");
81 if (PyObject_SetAttrString(pyobj,
"__adopted__", obj)) {
82 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: Failed to set Python object as attribute __adopted__.");
87 Py_DECREF(pyinterface);
unsigned long long GetDataPointerFromArrayInterface(PyObject *obj)
Get data pointer from Numpy array interface and perform error handling.
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 * GetArrayInterface(PyObject *obj)
Get Numpy array interface and perform error handling.
PyObject * BindCppObject(Cppyy::TCppObject_t object, Cppyy::TCppType_t klass, const unsigned flags=0)
RPY_EXPORTED TCppScope_t GetScope(const std::string &scope_name)
PyObject * AsRVec(PyObject *self, PyObject *obj)
Adopt memory of a Python object with array interface using an RVec.