[C++-sig] Retrieving lvalues using custom converters (numpy 1-D converters attached)
Neal Becker
ndbecker2 at gmail.com
Thu Oct 2 14:35:05 CEST 2008
OK, got it! But, I needed to add simple_const_iter for const_iterator. Then, this works:
,----[ /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,
| numpy::detail::numpy_storage_array<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);
| }
`----
More information about the Cplusplus-sig
mailing list