如果我有结构
cdef struct Interval:
unsigned int start
unsigned int end
unsigned int index
我可以像
那样给它赋值i.start = 1
但是我可以一次性设置所有值(开始,结束,索引)吗?
答案 0 :(得分:2)
我实际上在文档中找不到这个,但是cython确实支持c
中的struct初始化
%%cython
def f():
cdef Interval i = [1, 1, 3]
return i.index
c代码生成为:
struct __pyx_t_46_cython_magic_f52bf70efc56b7361a3a2e15f913f262_Interval __pyx_t_1;
/* "_cython_magic_f52bf70efc56b7361a3a2e15f913f262.pyx":14
*
* def f():
* cdef Interval i = [1, 1, 3] # <<<<<<<<<<<<<<
* return i.index
*/
__pyx_t_1.start = 1;
__pyx_t_1.end = 1;
__pyx_t_1.index = 3;