Mantid
Loading...
Searching...
No Matches
NumpyFunctions.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8
9// See
10// http://docs.scipy.org/doc/numpy/reference/c-api.array.html#PY_ARRAY_UNIQUE_SYMBOL
11#define PY_ARRAY_UNIQUE_SYMBOL CORE_ARRAY_API
12#define NO_IMPORT_ARRAY
13#include <numpy/arrayobject.h>
14
16
17PyObject *func_PyArray_IterNew(PyArrayObject *arr) { return PyArray_IterNew(reinterpret_cast<PyObject *>(arr)); }
18
19PyArrayObject *func_PyArray_NewFromDescr(int datatype, int ndims, Py_intptr_t *dims) {
20 return reinterpret_cast<PyArrayObject *>(PyArray_NewFromDescr(&PyArray_Type, PyArray_DescrFromType(datatype),
21 ndims, // rank
22 dims, // Length in each dimension
23 nullptr, nullptr, 0, nullptr));
24}
25
26PyArrayObject *func_PyArray_NewFromDescr(const char *datadescr, int ndims, Py_intptr_t *dims) {
27 // convert the string description to an actual description
28 PyArray_Descr *descr = func_PyArray_Descr(datadescr);
29
30 // create the array
31 auto *nparray = reinterpret_cast<PyArrayObject *>(PyArray_NewFromDescr(&PyArray_Type, descr, ndims, // rank
32 dims, // Length in each dimension
33 nullptr, nullptr, 0, nullptr));
34
35 return nparray;
36}
37
38PyArray_Descr *func_PyArray_Descr(const char *datadescr) {
39 PyObject *data_type = Py_BuildValue("s", datadescr);
40 PyArray_Descr *descr;
41 PyArray_DescrConverter(data_type, &descr);
42 Py_XDECREF(data_type); // function above incremented reference count
43
44 return descr;
45}
46} // namespace Mantid::PythonInterface::Converters::Impl
tagPyArrayObject PyArrayObject
_PyArray_Descr PyArray_Descr
MANTID_PYTHONINTERFACE_CORE_DLL PyArrayObject * func_PyArray_NewFromDescr(int datatype, int ndims, Py_intptr_t *dims)
equivalent to macro PyArray_NewFromDescr
MANTID_PYTHONINTERFACE_CORE_DLL PyArray_Descr * func_PyArray_Descr(const char *datadescr)
MANTID_PYTHONINTERFACE_CORE_DLL PyObject * func_PyArray_IterNew(PyArrayObject *arr)
equivalent to macro PyArray_IterNew