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++) {
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 std::stringstream prefix;
75 auto address = (
void*)
gInterpreter->Calc(
"new " + klassname +
"(reinterpret_cast<" + cppdtype +
"*>(" + prefix.str() + data +
")," +
size +
")");
85 if (PyObject_SetAttrString(pyobj,
"__adopted__", obj)) {
86 PyErr_SetString(PyExc_RuntimeError,
"Object not convertible: Failed to set Python object as attribute __adopted__.");
91 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.
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
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.