[C++-sig] simple numarray question

Neal Becker ndbecker2 at verizon.net
Thu Mar 25 01:19:38 CET 2004


I'm trying out numarray with boost::python.  numarray-0.9, python-2.3.3.
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;
}

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





More information about the Cplusplus-sig mailing list