| 346 | }; |
| 347 | |
| 348 | static npy_api lookup() { |
| 349 | module_ m = detail::import_numpy_core_submodule("multiarray"); |
| 350 | auto c = m.attr("_ARRAY_API"); |
| 351 | void **api_ptr = (void **) PyCapsule_GetPointer(c.ptr(), nullptr); |
| 352 | if (api_ptr == nullptr) { |
| 353 | raise_from(PyExc_SystemError, "FAILURE obtaining numpy _ARRAY_API pointer."); |
| 354 | throw error_already_set(); |
| 355 | } |
| 356 | npy_api api; |
| 357 | #define DECL_NPY_API(Func) api.Func##_ = (decltype(api.Func##_)) api_ptr[API_##Func]; |
| 358 | DECL_NPY_API(PyArray_GetNDArrayCFeatureVersion); |
| 359 | api.PyArray_RUNTIME_VERSION_ = api.PyArray_GetNDArrayCFeatureVersion_(); |
| 360 | if (api.PyArray_RUNTIME_VERSION_ < 0x7) { |
| 361 | pybind11_fail("pybind11 numpy support requires numpy >= 1.7.0"); |
| 362 | } |
| 363 | DECL_NPY_API(PyArray_Type); |
| 364 | DECL_NPY_API(PyVoidArrType_Type); |
| 365 | DECL_NPY_API(PyArrayDescr_Type); |
| 366 | DECL_NPY_API(PyArray_DescrFromType); |
| 367 | DECL_NPY_API(PyArray_TypeObjectFromType); |
| 368 | DECL_NPY_API(PyArray_DescrFromScalar); |
| 369 | DECL_NPY_API(PyArray_Scalar); |
| 370 | DECL_NPY_API(PyArray_ScalarAsCtype); |
| 371 | DECL_NPY_API(PyArray_FromAny); |
| 372 | DECL_NPY_API(PyArray_Resize); |
| 373 | DECL_NPY_API(PyArray_CopyInto); |
| 374 | DECL_NPY_API(PyArray_NewCopy); |
| 375 | DECL_NPY_API(PyArray_NewFromDescr); |
| 376 | DECL_NPY_API(PyArray_DescrNewFromType); |
| 377 | DECL_NPY_API(PyArray_Newshape); |
| 378 | DECL_NPY_API(PyArray_Squeeze); |
| 379 | DECL_NPY_API(PyArray_View); |
| 380 | DECL_NPY_API(PyArray_DescrConverter); |
| 381 | DECL_NPY_API(PyArray_EquivTypes); |
| 382 | DECL_NPY_API(PyArray_SetBaseObject); |
| 383 | |
| 384 | #undef DECL_NPY_API |
| 385 | return api; |
| 386 | } |
| 387 | }; |
| 388 | |
| 389 | template <typename T> |
nothing calls this directly
no test coverage detected