Is there a way to pass a python function ptr to a c++ method from a python script?

L

liam_herron

I have a core c++ library that is exposed to python through the
boost_python framework.
I would like to write the core of a Newton's method solver in C++ and
be able to write the
functions that are evaluated to be in python. Does anyone have any
ideas on this?
 
P

Paul McGuire

liam_herron said:
I have a core c++ library that is exposed to python through the
boost_python framework.
I would like to write the core of a Newton's method solver in C++ and
be able to write the
functions that are evaluated to be in python. Does anyone have any
ideas on this?

My suggestion would be to prototype in all-Python first. This will let you
work out the kinks of your call/callback interfaces. Then see if the
Newton's method part is a bottleneck worth converting to C++. My suspicion
is that the performance (for all but trivial functions) will be in the
function you are solving for, not in the Newton's metod. So be sure to test
with a function that you feel is representative of those you want to solve
for, not just a simple parabola.

Then, stop thinking in C++. "Function pointer"? A function in Python is
an object, a callable. You should be able to just treat it like one.

-- Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top