Hi Stefan,<br>
<br>
Thanks very much.<br>
<br>
> make that<br>
>float f = boost::python::extract<float>(rlt);<br>>Would that work ?<br clear="all">It works if arg_op = plus or minus. ( here process(boost::python::object arg_op)).<br>
But it didn't work if arg_op = vectorPlus. It seems that arg_op can't accept a c++ float pointer.<br>
<br>
Acctually the real vectorPlus() used in my code has been optimized for
speed and kindof unfriendly readable. I listed the simple version of
vectorPlus() which had the same idea and problem. For speed reason, I
can't use plus(p1[i],p2[i]) instead of vectorPlus(p1,p2,length).So I
hope vectorPlus can work.<br>
<br>
---------------------c extension-----------------<br>
vectorPlus(float* p1, float* p2,int point_len)// plus for two vectors.<br>
{<br>
float sum = 0;<br>
for (int i=0;i<point_len;i++)<br>
{<br>
sum += *(p1+i) + *(p2+i);<br>
} <br>
return (sum);<br>
}<br>
<br>
boost::python::object op;<br>
<br>
void process(boost::python::object arg_op){<br>
...<br>
op = arg_op;<br>
...<br>
float * a = {1,2};<br>
float * b = {3,4};<br>
<br>
boost::python::object rlt = op(a,b,2); // can't accept float* parameters.<br>
float * f = boost::python::extract<float> (rlt);<br>
printf("%f \n",*f);<br>
...<br>
}<br>
----------------------result --------------------<br>
>>> import hello<br>
>>> hello.process(hello.vectorPlus)<br>
Traceback (most recent call last):<br>
File "<stdin>", line 1, in ?<br>
TypeError: No to_python (by-value) converter found for C++ type: float*<br>
>>><br>
<br>
<br>-- <br>Qinfeng(Javen) Shi <br><br>Research School of Information Sciences and Engineering<br>Australian National University<br>Locked Bag 8001<br>Canberra ACT 2601<br><br><br>