如何在 Pyrex 中定义初始化的 C 数组?
我想在 Pyrex 中定义初始化的 C 数组,例如相当于:
unsigned char a[8] = {0,1,2,3,4,5,6,7};
Pyrex 中的等效项是什么?
只是数组
cdef unsigned char a[8]
但是我怎样才能用我的值初始化它呢?
I want to define initialized C-array in Pyrex, e.g. equivalent of:
unsigned char a[8] = {0,1,2,3,4,5,6,7};
What will be equivalent in Pyrex?
Just array is
cdef unsigned char a[8]
But how can I made it initialized with my values?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Pyrex 的后继者 Cython 中,一年多来就添加了此功能来修复此功能请求,例如,现在 Cython 中可以进行以下操作:
但是,Pyrex 的开发进展要慢得多(这就是为什么 Cython 几年前被开发人员分叉以求更快的操作),所以我怀疑它是否采用了此功能(尽管您可以尝试,尤其是如果您使用 Pyrex 的最新版本,0.9.8.6)。
如果 Pyrex 没有给您提供您想要的功能,我可以建议改用 Cython 吗?大多数 Pyrex 代码应该可以在 Cython 中顺利重新编译,并且您确实可以通过这种方式获得额外的功能。
In Cython, Pyrex's successor, this feature was added over a year a go to fix this feature request, so for example the following works in Cython now:
However, Pyrex's development is proceeding much more slowly (which is why Cython was forked years ago by developers rarin' for faster action), so I doubt it's picked up this feature (though you can try, esp. if you're using the very latest release of Pyrex, 0.9.8.6).
If Pyrex isn't giving you the features you want, may I suggest switching to Cython instead? Most Pyrex code should just recompile smoothly in Cython, and you do get the extra features this way.