【发布时间】:2014-11-07 13:18:32
【问题描述】:
我有一个 cython 模块保存为foo.pyx,如下所示:
cdef double sum(double[:] memview):
cdef total = 0
for i in range(len(memview):
total += memview[i]
return total
然后我用 !cython -a foo.pyx 编译。
我想在cython 单元格魔术中测试此功能,如下所示:
In [1]: %%cython
...: import foo
...: cimport numpy as np
...: import numpy as np
...: def get_sum():
...: cdef double[:] to_sum = np.array([1.0,2.0,3.0])
...: cdef double sum = foo.sum(to_sum)
...: return sum
但是当我尝试get_sum() 我得到:
AttributeError: 'module' object has no attribute 'sum'
我在这里做错了什么?
【问题讨论】: