Sto provando a usare Boost.Python come wrapper per una funzione C++ che riceve un puntatore, modifica i dati (gestiti su lato Python come array numpy per esempio) e restituisce. Come faccio a ottenere Python Numpy e Boost.Python per collaborare e per darmi il puntatore raw all'interno della funzione?Come passare un puntatore raw a Boost.Python?
#include <boost/python.hpp>
namespace
{
char const *greet(double *p)
{
*p = 2.;
return "hello world";
}
}
BOOST_PYTHON_MODULE(module)
{
boost::python::def("greet", &greet);
}
In Python quando provo,
import numpy as np
a = np.empty([2], dtype=np.double)
raw_ptr = a.data
print cmod.greet(raw_ptr)
ottengo l'errore,
Boost.Python.ArgumentError: Python argument types in
<...>.module.greet(buffer)
did not match C++ signature:
greet(double*)
Sì, ho provato anche questo. Viene quindi visualizzato il messaggio di errore Boost.Python.ArgumentError: tipi di argomenti Python in <...> .module.greet (LP_c_double) non corrisponde alla firma C++: greet (double *) – rych