Skip to content

Commit

Permalink
CHG: Make vendored Numpy api compatable with Numpy v2
Browse files Browse the repository at this point in the history
  • Loading branch information
RUrlus committed Jun 12, 2024
1 parent ea0eada commit 33b1620
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions include/carma_bits/numpyapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,21 @@ struct npy_api {
API_PyArray_Free = 165,
API_PyArray_Size = 59,
API_PyArray_NewCopy = 85,
API_PyArray_CopyInto = 82,
API_PyArray_CopyInto = 50,
API_PyArray_NewLikeArray = 277,
API_PyArray_NewFromDescr = 94,
API_PyDataMem_NEW = 288,
API_PyDataMem_FREE = 289,
};

static npy_api lookup() {
py::module m = py::module::import("numpy.core.multiarray");
pybind11::module_ m = pybind11::detail::import_numpy_core_submodule("multiarray");
auto c = m.attr("_ARRAY_API");
#if PY_MAJOR_VERSION >= 3
void **api_ptr = reinterpret_cast<void **>(PyCapsule_GetPointer(c.ptr(), nullptr));
#else
void **api_ptr = reinterpret_cast<void **>(PyCObject_AsVoidPtr(c.ptr()));
#endif
void** api_ptr = (void**)PyCapsule_GetPointer(c.ptr(), nullptr);
if (api_ptr == nullptr) {
pybind11::raise_from(PyExc_SystemError, "FAILURE obtaining numpy _ARRAY_API pointer.");
throw pybind11::error_already_set();
}
npy_api api;
#define DECL_NPY_API(Func) api.Func##_ = (decltype(api.Func##_)) api_ptr[API_##Func];
DECL_NPY_API(PyArray_Free);
Expand Down

0 comments on commit 33b1620

Please sign in to comment.