As I am pretty new in the cython business, I would like to know how to get rid of most of the python commands (cython -a flags this inline as pretty far away from pure C)
诀窍是如果你能调用你的函数nogil
cpdef inline int c_rate2recs_2(int maxNN,int idx) nogil:
cdef int out=idx%maxNN
return out
诀窍是如果你能调用你的函数
nogil
那么不管你看到什么黄色,实际上并不是去Python的。例如,这可能是一个错误情况,也可能只是其他类型的轻微检查。在
cpdef
的情况下,不仅生成了一个纯C函数,而且还为从Python范围调用创建了Python别名。这不会影响速度。在在本例中,针对手动内联循环的一些计时没有显示出减速,删除
inline
对时间也没有任何影响。我想一个更难优化的案例可能会表现出不同的特征,但关键在于轮廓。在最后,可以使用compiler directives来加速和删除一些错误检查。在
相关问题 更多 >
编程相关推荐