[C++-sig] Re: simple numarray question

David Abrahams dave at boost-consulting.com
Thu Mar 25 23:13:05 CET 2004


Neal Becker <ndbecker2 at verizon.net> writes:

> I'm trying out numarray with boost::python.  numarray-0.9,
> python-2.3.3.

Which compiler?

> Any clues what's wrong with this simple test (I'm trying to print out
> #elements in the array)
>
> #include <boost/python.hpp>
> #include <boost/python/numeric.hpp>
> #include <boost/python/tuple.hpp>
> #include <iostream>
>
> using namespace boost;
> using namespace boost::python;
>
> // sets the first element in a 1d numeric array
> void set_first_element(numeric::array& y, double value)
> {
>   //  y[python::make_tuple(0,0)] = value;
>   y[0] = value;
>   std::clog << y.nelements() << std::endl;

I suggest pruning out parts of this function until you are able to
pinpoint the error.  For example:

         y.nelements();
then:
         y[0] = value;

then:
        y[0];

> }
>
> BOOST_PYTHON_MODULE(Test3)
> {
>   def("f", set_first_element);
> }
>
> from numarray import *
>>>> from Test3 import *
>>>> x=array([1.2, 3.4])
>>>> f(x, 2.8)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: No registered converter was able to produce a C++ rvalue of type
> long from this Python object of type builtin_function_or_method

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list