开发者

port only a single method of class to C?

开发者 https://www.devze.com 2023-04-10 05:26 出处:网络
I have a class with few methods and I\'m happy with the performance of all of them except one method. We want to port that to C++. However we don\'t want to spend too much time porting the whole class

I have a class with few methods and I'm happy with the performance of all of them except one method. We want to port that to C++. However we don't want to spend too much time porting the whole class to C++, just that single method. Is thi开发者_Python百科s possible? How should I do it? Should it be in a blank class? Not in a class? What I want is to try to use the C version and if failed (other OS, missing pyd), load the Python version. Thank you.


Depending on the complexity of your code, you could look into using Weave, which is part of SciPy. It allows you to embed C/C++ code in your python module. There's a tutorial here.

Another option you could look at is Boost::Python, which may be a bit more complex to use.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号