[C++-sig] Retrieving lvalues using custom converters (numpy 1-D converters attached)
Neal Becker
ndbecker2 at gmail.com
Thu Oct 2 13:41:04 CEST 2008
This is very interesting! But how do I use it?
What I tried:
your numpy.h (but comment out)
#ifndef IN_FILE_IMPORTING_ARRAY
#define NO_IMPORT_ARRAY
#endif
#define PY_ARRAY_UNIQUE_SYMBOL Wicket_Numpy
My code:
,----[ /home/nbecker/numpy.new/num.cc ]
| #include "numpy.h"
| #include <boost/python/module.hpp>
| #include <boost/python/def.hpp>
| #include <numeric>
|
| namespace ublas=boost::numeric::ublas;
| using namespace boost::python;
|
| double do_sum (ublas::vector<double> const& u) {
| return std::accumulate (u.begin(), u.end(), 0.0);
| }
|
| BOOST_PYTHON_MODULE (num) {
| import_array();
| numpy::register_ublas_from_python_converters();
| numpy::register_default_ublas_to_python();
| def ("do_sum", &do_sum);
| }
`----
,----[ /home/nbecker/numpy.new/test_num.py ]
| from num import *
| from numpy import *
|
| u = array (xrange(10), dtype=float64)
| v = do_sum (u)
`----
Seems the converters didn't work:
ArgumentError: Python argument types in
num.do_sum(numpy.ndarray)
did not match C++ signature:
do_sum(boost::numeric::ublas::vector<double, boost::numeric::ublas::unbounded_array<double, std::allocator<double> > >)
More information about the Cplusplus-sig
mailing list