9#include <boost/python/detail/prefix.hpp>
10#include <boost/python/tuple.hpp>
11#define PY_ARRAY_UNIQUE_SYMBOL CORE_ARRAY_API
12#include <numpy/arrayobject.h>
23 if (!Py_IsInitialized()) {
24 throw std::runtime_error(
"Library requires an active Python interpreter.\n"
25 "Call Py_Initialize at an appropriate point in the application.");
28 if (_import_array() < 0) {
30 PyErr_SetString(PyExc_ImportError,
"numpy.core.multiarray failed to import");
90 auto callable = object(handle<>(PyObject_GetAttrString(this->ptr(),
const_cast<char *
>(
"astype"))));
92 auto kwargs = object(handle<>(Py_BuildValue(
const_cast<char *
>(
"{s:c,s:i}"),
"dtype",
dtype,
"copy", copy ? 1 : 0)));
93 return NDArray(boost::python::detail::new_reference(PyObject_Call(callable.ptr(), args.ptr(), kwargs.ptr())));
110bool object_manager_traits<Mantid::PythonInterface::NDArray>::check(PyObject *
obj) {
111 return ::PyObject_IsInstance(
obj, (PyObject *)ndarrayType());
121python::detail::new_reference object_manager_traits<Mantid::PythonInterface::NDArray>::adopt(PyObject *
obj) {
122 return python::detail::new_reference(python::pytype_check(ndarrayType(),
obj));
129PyTypeObject
const *object_manager_traits<Mantid::PythonInterface::NDArray>::get_pytype() {
return ndarrayType(); }
tagPyArrayObject PyArrayObject
std::string dtype(Mantid::Kernel::PropertyWithValue< HeldType > &self)
double obj
the value of the quadratic function
Thin object wrapper around a numpy array.
static bool check(const boost::python::object &obj)
Check if a python object points to an array type object.
Py_intptr_t const * get_shape() const
char get_typecode() const
See https://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html.
void * get_data() const
This returns char so stride math works properly on it.
NDArray(const boost::python::object &obj)
Construction from a plain object.
NDArray astype(char dtype, bool copy=true) const
Casts (and copies if necessary) the array to the given data type.
MANTID_PYTHONINTERFACE_CORE_DLL void importNumpy()
Initialize the numpy array api for this DLL.
MANTID_PYTHONINTERFACE_CORE_DLL PyTypeObject * ndarrayType()
Return the type object for a numpy.NDArray.