numpycpp
|
This is a thin wrapper library around numpy. It depends on boost::python for reference counting and automatic type conversions.
All members are defined in the namespace boost::python::numpy.
The class arrayt<T>, templated by the element type, allow fast direct access to memory.
The initialization routine importNumpyAndRegisterTypes registers converters for most basic scalar types. Moreover converters for the base class arraybase as well as arrayt are registered. Therefore you can wrap, for instance,
directly by
Examples can be found in demo.cpp and demo.py. What does not work is automatic conversion to boost::python::object
, since arraytbase is not derived from object. For instance
will give an error. Construct py::object() explicitly instead.
You probably just want to incorporate numpy.hpp and numpy.cpp into your project. Or build a library by yourself. It is possible to use (sym) links for that but beware that stupid editors like kdevelop might break the link by deleting the link and then rewriting a new copy of the file to disk ...
The library wraps only parts that allow access to data. No manipulation routines such as resizing are currently implemented.
I think it might be better to put everything into a single header to enable users to write their own specialized converters easily. It would make the library more easy to use since there would be no object file to compile. But it would come at the cost of inclusion of the numpy headers, thus polluting the global name space with the c-api of numpy ...
Thanks to Austin Bingham for his comprehensive introduction to boost python converters https://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters/