延长蟒蛇/ numpy的最佳途径performancewise [英] best way to extend python / numpy performancewise

查看:175
本文介绍了延长蟒蛇/ numpy的最佳途径performancewise的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于有多种方式来编写Python的二进制模块,我是跳那些有经验,如果我想提高code的一些细分的性能尽可能可以在最好的办法忠告

As there are multitude of ways to write binary modules for python, i was hopping those of you with experience could advice on the best approach if i wish to improve the performance of some segments of the code as much as possible.

据我所知,人们可以使用Python / numpy的C-API编写扩展,或者换一些已经写纯C / C ++ / Fortran函数必须从蟒蛇code调用。

As i understand, one can either write an extension using the python/numpy C-api, or wrap some already written pure C/C++/Fortran function to be called from the python code.

当然,就像用Cython工具是最容易的方式,但我认为手写的code给出更好的控制,并提供更好的性能。

Naturally, tools like Cython are the easiest way to go, but i assume that writing the code by hand gives better control and provide better performance.

的问题,它可以是一般的,是要使用的方法。写C或C ++的扩展?包装外部C / C ++函数或使用回调Python函数?

The question, and it may be to general, is which approach to use. Write a C or C++ extension? wrap external C/C++ functions or use callback to python functions?

我写这个问题在Langtangen的Python脚本为计算科学里有几种方法比较Python和C之间的接口读取章10后。

I write this question after reading chapter 10 in Langtangen's "Python scripting for computational science" where there is a comparison of several methods to interface between python and C.

推荐答案

我会说这取决于你的技能/经验和你的项目。
如果这是非常ponctual,你在C / C的profficient ++,你已经编写Python包装,然后编​​写您自己的扩展和接口了。

I would say it depends on your skills/experience and your project. If this is very ponctual and you are profficient in C/C++ and you have already written python wrapper, then write your own extension and interface it.

如果您打算在其他项目,numpy的工作,然后去了numpy的C-API,它的广泛而有据可查的,但它也是相当多的文件要处理的。
至少我有很多的困难,处理它,但后来我又位于C吸。

If you are going to work with Numpy on other project, then go for the Numpy C-API, it's extensive and rather well documented but it is also quite a lot of documentation to process. At least I had a lot of difficulty processing it, but then again I suck at C.

如果你真的不知道去用Cython,远耗时少,性能在大多数情况下非常好。 (我的选择)
从我的角度来看,你需要一个良好的C codeR比用Cython做得更好的2 previous实施,这将是更多的配合物和费时。
所以,你是伟大的C codeR?

If you're not really sure go Cython, far less time consuming and the performance are in most cases very good. (my choice) From my point of view you need to be a good C coder to do better than Cython with the 2 previous implementation, and it will be much more complexe and time consuming. So are you a great C coder ?

此外,它可能是值得你寻找到pycuda或一些其他的东西,GPGPU如果您正在寻找的表现,这取决于你的课程硬件。

Also it might be worth your while to look into pycuda or some other GPGPU stuff if you're looking for performance, depending on your hardware of course.

这篇关于延长蟒蛇/ numpy的最佳途径performancewise的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆