混合 cython 和涡轮齿轮 2.1
是否可以集成 Cython 和 TG2?我有一个计算(用 python 编写),它是大量数值计算,并且从重写为 C 或 cython 中受益匪浅。
Is it possible to integrate Cython and TG2? I have one computation (written in python) which is heavily numerical and would largly benefit from rewriting into C or cython.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的问题没有额外的特异性,并且不知道“集成”到底是什么意思,我所能提供的就是 cython 提供了一种相当简单的方法(通常是戏剧性的)通过静态类型或调用来加速用 python 编写的某些代码外部 C/C++ 库。如果只有一个数值计算可以用 cython 编写,然后从 TG2 中调用,那么这是使用 cython 的良好候选者。不过,你的里程会有所不同,具体取决于有多少内容可以用转换为纯 C 的东西编写,而不是严重依赖于 Python C-API 的东西。
一些(实际上是许多)数值计算也适用于 numpy 擅长的类型计算,因此如果您还没有尝试过,那可能是另一种选择。
一般来说,如果您想要详细的答案,您应该在问题中提供同等数量的细节。
Without you having additionally specificity in your question and not knowing what exactly you mean by 'integrate', all I can offer is that cython provides a fairly simple way of (often dramatically) speeding up certain code written in python either via static typing or calling external c/c++ libraries. If there is only a single numerical calculation that can be written in cython and then called from within TG2, then this is a good candidate for using cython. Your mileage will vary though depending on how much of it can be written in something that translates to pure C, versus something that relies heavily on the Python C-API.
Some (many actually) numerical calculations are also amenable to the type computations that
numpy
excels at, so if you haven't tried it, that may be another option.In general though if you want a detailed answer, you should put an equivalent amount of detail in the question.