14#include <boost/python/extract.hpp>
18#define PY_ARRAY_UNIQUE_SYMBOL API_ARRAY_API
19#define NO_IMPORT_ARRAY
20#include <numpy/arrayobject.h>
29enum DataField { XValues = 0, YValues = 1, EValues = 2, DxValues = 3 };
40PyArrayObject *cloneArray(
const MatrixWorkspace &
workspace, DataField field,
const size_t start,
const size_t endp1) {
41 const npy_intp numHist(endp1 - start);
45 using ArrayAccessFn =
const MantidVec &(MatrixWorkspace::*)(
const size_t)
const;
46 ArrayAccessFn dataAccesor;
51 if (field == XValues) {
54 }
else if (field == DxValues) {
64 npy_intp arrayDims[2] = {numHist, stride};
66 reinterpret_cast<PyArrayObject *
>(PyArray_NewFromDescr(&PyArray_Type, PyArray_DescrFromType(NPY_DOUBLE),
69 nullptr,
nullptr, 0,
nullptr));
70 auto *dest =
reinterpret_cast<double *
>(PyArray_DATA(nparray));
73 for (npy_intp i = 0; i < numHist; ++i) {
75 std::copy(src.begin(), src.end(), std::next(dest, i * stride));
89 return reinterpret_cast<PyObject *
>(cloneArray(self, XValues, 0, self.
getNumberHistograms()));
97 return reinterpret_cast<PyObject *
>(cloneArray(self, YValues, 0, self.
getNumberHistograms()));
106 return reinterpret_cast<PyObject *
>(cloneArray(self, EValues, 0, self.
getNumberHistograms()));
115 return reinterpret_cast<PyObject *
>(cloneArray(self, DxValues, 0, self.
getNumberHistograms()));
IPeaksWorkspace_sptr workspace
#define PARALLEL_FOR_IF(condition)
Empty definitions - to enable set your complier to enable openMP.
tagPyArrayObject PyArrayObject
Base MatrixWorkspace Abstract Class.
const MantidVec & readE(std::size_t const index) const
Deprecated, use e() instead.
const MantidVec & readDx(size_t const index) const
Deprecated, use dx() instead.
virtual std::size_t getNumberHistograms() const =0
Returns the number of histograms in the workspace.
const MantidVec & readY(std::size_t const index) const
Deprecated, use y() instead.
const MantidVec & readX(std::size_t const index) const
Deprecated, use x() instead.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::enable_if< std::is_pointer< Arg >::value, bool >::type threadSafe(Arg workspace)
Thread-safety check Checks the workspace to ensure it is suitable for multithreaded access.
PyObject * cloneE(const API::MatrixWorkspace &self)
Create a numpy array from the E values of the given workspace reference.
PyObject * cloneY(const API::MatrixWorkspace &self)
Create a numpy array from the Y values of the given workspace reference.
PyObject * cloneDx(const API::MatrixWorkspace &self)
Create a numpy array from the E values of the given workspace reference.
PyObject * cloneX(const API::MatrixWorkspace &self)
{ Create a numpy array from the X values of the given workspace reference
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces