Mantid
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
Mantid::PythonInterface::NDArray Class Reference

Thin object wrapper around a numpy array. More...

#include <NDArray.h>

Inheritance diagram for Mantid::PythonInterface::NDArray:

Public Member Functions

NDArray astype (char dtype, bool copy=true) const
 Casts (and copies if necessary) the array to the given data type. More...
 
 BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS (NDArray, boost::python::object)
 
void * get_data () const
 This returns char so stride math works properly on it. More...
 
int get_nd () const
 
Py_intptr_t const * get_shape () const
 
char get_typecode () const
 See https://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html. More...
 
 NDArray (const boost::python::object &obj)
 Construction from a plain object. More...
 

Static Public Member Functions

static bool check (const boost::python::object &obj)
 Check if a python object points to an array type object. More...
 

Detailed Description

Thin object wrapper around a numpy array.

This is intended to take the place of boost::python::numeric::array, which is a dated wrapper containing a bug when used with Python 3 - https://github.com/boostorg/python/issues/75.

Only minimal functionality has been ported here.

Definition at line 31 of file NDArray.h.

Constructor & Destructor Documentation

◆ NDArray()

Mantid::PythonInterface::NDArray::NDArray ( const boost::python::object &  obj)

Construction from a plain object.

Assumes the array is actually a a numpy array

Parameters
objA wrapper around a Python object pointing to a numpy array

Definition at line 56 of file NDArray.cpp.

Member Function Documentation

◆ astype()

NDArray Mantid::PythonInterface::NDArray::astype ( char  dtype,
bool  copy = true 
) const

Casts (and copies if necessary) the array to the given data type.

Parameters
dtypeCharacter code for the numpy data types (https://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html)
copyIf true then the return array is always a copy otherwise the returned array will only be copied if necessary
Returns
A numpy array with values of the requested type

Definition at line 89 of file NDArray.cpp.

References dtype().

◆ BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS()

Mantid::PythonInterface::NDArray::BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS ( NDArray  ,
boost::python::object   
)

◆ check()

bool Mantid::PythonInterface::NDArray::check ( const boost::python::object &  obj)
static

Check if a python object points to an array type object.

Parameters
objA pointer to an arbitrary python object
Returns
True if the underlying object is an NDArray, false otherwise

Definition at line 49 of file NDArray.cpp.

References obj.

Referenced by createFunctionDomain1DHistogram(), createFunctionDomain1DVector(), Mantid::PythonInterface::Converters::PyObjectToMatrix::PyObjectToMatrix(), and Mantid::PythonInterface::Registry::SequenceTypeHandler< ContainerType >::set().

◆ get_data()

void * Mantid::PythonInterface::NDArray::get_data ( ) const

This returns char so stride math works properly on it.

It's pretty much expected that the user will have to reinterpret_cast it.

Returns
The array's raw data pointer

Definition at line 73 of file NDArray.cpp.

◆ get_nd()

int Mantid::PythonInterface::NDArray::get_nd ( ) const
Returns
Return the number of dimensions of the array

Definition at line 66 of file NDArray.cpp.

◆ get_shape()

Py_intptr_t const * Mantid::PythonInterface::NDArray::get_shape ( ) const
Returns
Return the shape of the array

Definition at line 61 of file NDArray.cpp.

◆ get_typecode()

char Mantid::PythonInterface::NDArray::get_typecode ( ) const

See https://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html.

Returns
The character code for the dtype of the array

Definition at line 79 of file NDArray.cpp.


The documentation for this class was generated from the following files: