12#include "MantidPythonInterface/core/DllConfig.h"
14#include <boost/python/list.hpp>
15#define PY_ARRAY_UNIQUE_SYMBOL CORE_ARRAY_API
16#define NO_IMPORT_ARRAY
17#include <numpy/arrayobject.h>
28template <
typename T>
void capsule_cleanup(PyObject *capsule) {
29 auto *memory =
static_cast<T *
>(PyCapsule_GetPointer(capsule, NULL));
56#if NPY_API_VERSION >= 0x00000007
57 PyArray_CLEARFLAGS(arr, NPY_ARRAY_WRITEABLE);
59 arr->flags &= ~NPY_WRITEABLE;
79template <
typename ElementType>
84 PyArray_SimpleNewFromData(ndims, dims, datatype,
static_cast<void *
>(
const_cast<ElementType *
>(carray))));
87 PyObject *capsule = PyCapsule_New(
const_cast<ElementType *
>(carray), NULL, capsule_cleanup<ElementType>);
88 PyArray_SetBaseObject(
reinterpret_cast<PyArrayObject *
>(nparray), capsule);
92 markReadOnly(nparray);
93 return reinterpret_cast<PyObject *
>(nparray);
99#define INSTANTIATE_WRAPNUMPY(ElementType) \
100 template MANTID_PYTHONINTERFACE_CORE_DLL PyObject *wrapWithNDArray<ElementType>( \
101 const ElementType *, const int ndims, Py_intptr_t *dims, 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.