13#include <boost/python/list.hpp>
14#define PY_ARRAY_UNIQUE_SYMBOL CORE_ARRAY_API
15#define NO_IMPORT_ARRAY
16#include <numpy/arrayobject.h>
27template <
typename T>
void capsule_cleanup(PyObject *capsule) {
28 auto *memory =
static_cast<T *
>(PyCapsule_GetPointer(capsule, NULL));
55#if NPY_API_VERSION >= 0x00000007
56 PyArray_CLEARFLAGS(arr, NPY_ARRAY_WRITEABLE);
58 arr->flags &= ~NPY_WRITEABLE;
78template <
typename ElementType>
82 auto *nparray = (
PyArrayObject *)PyArray_SimpleNewFromData(ndims, dims, datatype,
83 static_cast<void *
>(
const_cast<ElementType *
>(carray)));
86 PyObject *capsule = PyCapsule_New(
const_cast<ElementType *
>(carray), NULL, capsule_cleanup<ElementType>);
91 markReadOnly(nparray);
92 return reinterpret_cast<PyObject *
>(nparray);
98#define INSTANTIATE_WRAPNUMPY(ElementType) \
99 template DLLExport PyObject *wrapWithNDArray<ElementType>(const ElementType *, const int ndims, Py_intptr_t *dims, \
100 const NumpyWrapMode mode, const OwnershipMode oMode);
tagPyArrayObject PyArrayObject
#define INSTANTIATE_WRAPNUMPY(ElementType)
PyObject * wrapWithNDArray(const ElementType *, const int ndims, Py_intptr_t *dims, const NumpyWrapMode mode, const OwnershipMode oMode=OwnershipMode::Cpp)
Defines the wrapWithNDArray specialization for C array types.
NumpyWrapMode
Enum defining wrapping type for conversion to numpy.
OwnershipMode
Enum defining transfer of ownership when converting to numpy array.
Defines a mapping between C++ type given by the template parameter and numpy type enum NPY_TYPES.