Classes | Public Types | Public Member Functions | Private Member Functions
boost::numpy::ndarray Class Reference

A boost.python "object manager" (subclass of object) for numpy.ndarray. More...

#include <ndarray.hpp>

Inheritance diagram for boost::numpy::ndarray:
Inheritance graph
[legend]

List of all members.

Classes

struct  array_struct
 An internal struct that's byte-compatible with PyArrayObject. More...

Public Types

enum  bitflag {
  NONE = 0x0, C_CONTIGUOUS = 0x1, F_CONTIGUOUS = 0x2, V_CONTIGUOUS = 0x1|0x2,
  ALIGNED = 0x4, WRITEABLE = 0x8, BEHAVED = 0x4|0x8, CARRAY_RO = 0x1|0x4,
  CARRAY = 0x1|0x4|0x8, CARRAY_MIS = 0x1|0x8, FARRAY_RO = 0x2|0x4, FARRAY = 0x2|0x4|0x8,
  FARRAY_MIS = 0x2|0x8, UPDATE_ALL = 0x1|0x2|0x4, VARRAY = 0x1|0x2|0x8, ALL = 0x1|0x2|0x4|0x8
}
 Enum to represent (some) of Numpy's internal flags. More...

Public Member Functions

ndarray astype (dtype const &dt) const
 Copy the array, cast to a specified type.
 BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS (ndarray, object)
ndarray copy () const
 Copy the scalar (deep for all non-object fields).
python::object get_base () const
 Return the object that owns the array's data, or None if the array owns its own data.
char * get_data () const
 Return the array's raw data pointer.
dtype get_dtype () const
 Return the array's data-type descriptor object.
bitflag const get_flags () const
 Return the array flags.
int const get_nd () const
 Return the number of array dimensions.
Py_intptr_t const * get_shape () const
 Return the shape of the array as an array of integers (length == get_nd()).
Py_intptr_t const * get_strides () const
 Return the stride of the array as an array of integers (length == get_nd()).
ndarray reshape (python::tuple const &shape) const
 Equivalent to self.reshape(*shape) in Python.
python::object scalarize () const
 If the array contains only a single element, return it as an array scalar; otherwise return the array.
void set_base (object const &base)
 Set the object that owns the array's data. Use with care.
int const shape (int n) const
 Return the size of the nth dimension.
ndarray squeeze () const
 Eliminate any unit-sized dimensions.
int const strides (int n) const
 Return the stride of the nth dimension.
ndarray transpose () const
 Reverse the dimensions of the array.
ndarray view (dtype const &dt) const
 Return a view of the scalar with the given dtype.

Private Member Functions

array_structget_struct () const
 Return the held Python object as an array_struct.

Detailed Description

A boost.python "object manager" (subclass of object) for numpy.ndarray.

Todo:
This could have a lot more functionality (like boost::python::numeric::array). Right now all that exists is what was needed to move raw data between C++ and Python.

Definition at line 32 of file ndarray.hpp.


Member Enumeration Documentation

Enum to represent (some) of Numpy's internal flags.

These don't match the actual Numpy flag values; we can't get those without including numpy/arrayobject.h or copying them directly. That's very unfortunate.

Todo:
I'm torn about whether this should be an enum. It's very convenient to not make these simple integer values for overloading purposes, but the need to define every possible combination and custom bitwise operators is ugly.
Enumerator:
NONE 
C_CONTIGUOUS 
F_CONTIGUOUS 
V_CONTIGUOUS 
ALIGNED 
WRITEABLE 
BEHAVED 
CARRAY_RO 
CARRAY 
CARRAY_MIS 
FARRAY_RO 
FARRAY 
FARRAY_MIS 
UPDATE_ALL 
VARRAY 
ALL 

Definition at line 69 of file ndarray.hpp.


Member Function Documentation

Copy the array, cast to a specified type.

Definition at line 150 of file src/ndarray.cpp.

Copy the scalar (deep for all non-object fields).

Reimplemented in boost::numpy::matrix.

Definition at line 156 of file src/ndarray.cpp.

python::object boost::numpy::ndarray::get_base ( ) const

Return the object that owns the array's data, or None if the array owns its own data.

Definition at line 167 of file src/ndarray.cpp.

char* boost::numpy::ndarray::get_data ( ) const [inline]

Return the array's raw data pointer.

This returns char so stride math works properly on it. It's pretty much expected that the user will have to reinterpret_cast it.

Definition at line 101 of file ndarray.hpp.

Return the array's data-type descriptor object.

Definition at line 162 of file src/ndarray.cpp.

Return the array flags.

Definition at line 187 of file src/ndarray.cpp.

int const boost::numpy::ndarray::get_nd ( ) const [inline]

Return the number of array dimensions.

Definition at line 119 of file ndarray.hpp.

Py_intptr_t const* boost::numpy::ndarray::get_shape ( ) const [inline]

Return the shape of the array as an array of integers (length == get_nd()).

Definition at line 113 of file ndarray.hpp.

Py_intptr_t const* boost::numpy::ndarray::get_strides ( ) const [inline]

Return the stride of the array as an array of integers (length == get_nd()).

Definition at line 116 of file ndarray.hpp.

array_struct* boost::numpy::ndarray::get_struct ( ) const [inline, private]

Return the held Python object as an array_struct.

Definition at line 55 of file ndarray.hpp.

ndarray boost::numpy::ndarray::reshape ( python::tuple const &  shape) const

Equivalent to self.reshape(*shape) in Python.

Definition at line 204 of file src/ndarray.cpp.

python::object boost::numpy::ndarray::scalarize ( ) const

If the array contains only a single element, return it as an array scalar; otherwise return the array.

Definition at line 210 of file src/ndarray.cpp.

void boost::numpy::ndarray::set_base ( object const &  base)

Set the object that owns the array's data. Use with care.

Definition at line 173 of file src/ndarray.cpp.

int const boost::numpy::ndarray::shape ( int  n) const [inline]

Return the size of the nth dimension.

Definition at line 90 of file ndarray.hpp.

Eliminate any unit-sized dimensions.

Definition at line 198 of file src/ndarray.cpp.

int const boost::numpy::ndarray::strides ( int  n) const [inline]

Return the stride of the nth dimension.

Definition at line 93 of file ndarray.hpp.

Reverse the dimensions of the array.

Reimplemented in boost::numpy::matrix.

Definition at line 192 of file src/ndarray.cpp.

ndarray boost::numpy::ndarray::view ( dtype const &  dt) const

Return a view of the scalar with the given dtype.

Reimplemented in boost::numpy::matrix.

Definition at line 144 of file src/ndarray.cpp.


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


boost_numpy
Author(s): Jim Bosch, Ankit Daftery
autogenerated on Fri Aug 28 2015 10:10:40