num_util: helper functions for boost::python::numeric arrays

Background (release 2a, 2007/Jan/31) (works with numpy version: 1.0.2.dev2885)

The Boost Python Library includes a class that wraps the Numeric, numarray or NumPy array type. The class includes a subset of array methods, implemented by callbacks into python. By using callbacks, the class can support all three array classes without having to work through a particular C-API.

In contrast, num_util uses the boost::python::numeric::array type and directly wraps the NumPy C-API (limiting it to use with NumPy array module). num_util.h defines a number of functions that make it easier to create NumPy arrays from C++ and check for errors in type, rank, dimension etc. for arrays passed from Python.

Basic Example

The file simpletest.cpp shows some of the basic functionality of both boost::python and numeric_util. When called with simpletest.py it produces this output.

Changes from release 1, 2003/April/3

Download and caveats

We wrote num_util to help move our own code from cxx to boost. We use it frequently, but I'm posting it as a source of simple examples for using boost and NumPy, not as a piece of production code (for example, I've never tested complex array creation). Bug fixes and improvements are welcome.

Acknowledgements