numpycpp
 All Classes Namespaces Files Functions Typedefs Pages
Namespaces | Classes | Typedefs | Enumerations | Functions
boost::python::numpy Namespace Reference

Everything of this library can be found in this namespace. More...

Namespaces

 mw_py_impl
 Some implementation details are in here.
 

Classes

class  arraytbase
 This is the base class from which type specific variants are derived. More...
 
class  arrayt
 This class defines operators () and [] to allow for direct memory access to array elements of type T. More...
 

Typedefs

typedef Py_ssize_t ssize_t
 Synonymous for Py_ssize_t.
 

Enumerations

enum  { MAX_DIM = 32 }
 Equal to NPY_MAX_DIMS. Provided so that the numpy headers don't have to be included.
 

Functions

void importNumpyAndRegisterTypes ()
 Initializes things. More...
 
object zeros (int rank, const Py_ssize_t *dims, int type)
 Creates a new ndarray filled with zeros. More...
 
object empty (int rank, const Py_ssize_t *dims, int type)
 Create a new ndarray with uninitialized memory. More...
 
int getItemtype (const object &arr)
 Obtain numpy's data type number from an boost-python object which should hold a ndarray. More...
 
template<class T >
bool isCompatibleType (int id)
 Determines if a numpy data type identified by the type number id is binary compatible with the c-type given by T. More...
 
template<class T >
int getItemtype ()
 Obtain numpy's data type number from template parameter T. More...
 
template<class T , int rank>
static object copy (const int *dims, const T *src, const int *strides)
 Copy contents of n-dimensional non-contiguous arrays. More...
 
template<class T , int rank>
static void copy (T *dst, const int *dims, const int *strides, const object &pyarr)
 Copy contents of n-dimensional non-contiguous arrays. Inverse variant. More...
 

Detailed Description

Everything of this library can be found in this namespace.

Hint: you can use something like

namespace py = boost::python;

namespace np = boost::python::numpy;

for convenience.

Function Documentation

template<class T , int rank>
static object boost::python::numpy::copy ( const int *  dims,
const T *  src,
const int *  strides 
)
static

Copy contents of n-dimensional non-contiguous arrays.

Parameters
[in]dims- Number of items to copy along each dimension
[in]src- Pointer to the source memory
[in]strides- How far to move in (source) memory if the corresponding index is increased by one. Strides are given in number of items, not in bytes.
Returns
ndarray wrapped in an instance of boost::python::object.

Definition at line 499 of file numpy.hpp.

template<class T , int rank>
static void boost::python::numpy::copy ( T *  dst,
const int *  dims,
const int *  strides,
const object &  pyarr 
)
static

Copy contents of n-dimensional non-contiguous arrays. Inverse variant.

Parameters
[out]dst- Pointer to destination memory.
[in]dims- Number of items to copy along each dimension
[in]strides- How far to move in (destination) memory if the corresponding index is increased by one. Strides are given in number of items, not in bytes.
[in]pyarr- Must contain an instance of ndarray.

Definition at line 524 of file numpy.hpp.

object boost::python::numpy::empty ( int  rank,
const Py_ssize_t *  dims,
int  type 
)

Create a new ndarray with uninitialized memory.

The type parameter specifies the numpy data type number. You can use getItemtype<T>() to obtain one.

Definition at line 232 of file numpy.cpp.

template<class T >
int boost::python::numpy::getItemtype ( )

Obtain numpy's data type number from template parameter T.

By default, basic types are mapped to NPY_FLOAT32, NPY_FLOAT64, NPY_INT, NPY_LONG, NPY_LONGLONG, NPY_SHORT, NPY_BYTE, NPY_BOOL, NPY_UINT, NPY_ULONG, NPY_USHORT, NPY_UBYTE, NPY_ULONGLONG. PyObject* is mapped to NPY_OBJECT.

See Also
getItemtype(const object &arr);

Definition at line 169 of file numpy.hpp.

int boost::python::numpy::getItemtype ( const object &  arr)

Obtain numpy's data type number from an boost-python object which should hold a ndarray.

Returns the result of PyArray_TYPE() if arr is derived from ndarray, and -1 otherwise.

See Also
getItemtype<T>()

Definition at line 241 of file numpy.cpp.

void boost::python::numpy::importNumpyAndRegisterTypes ( )

Initializes things.

It calls

import_array1();

py::numeric::array::set_module_and_type("numpy", "ndarray");

And it registers several converter routines in boost python for automatic conversion of <arrayt>, <arraytbase> and scalar types.

Definition at line 196 of file numpy.cpp.

template<class T >
bool boost::python::numpy::isCompatibleType ( int  id)

Determines if a numpy data type identified by the type number id is binary compatible with the c-type given by T.

This function is specialized for basic number types: various sizes of integers, and float and double. This is a many to one correspondence. For instance depending on the platform, numpy types 'int' and 'long' which have different type numbers are both 8 bytes in length and therefore both correspond to the long type in c++!

See Also
getItemtype<T>()

Definition at line 340 of file numpy.cpp.

object boost::python::numpy::zeros ( int  rank,
const Py_ssize_t *  dims,
int  type 
)

Creates a new ndarray filled with zeros.

The type parameter specifies the numpy data type number. You can use getItemtype<T>() to obtain one.

Definition at line 224 of file numpy.cpp.