我试图用签名来包装一个c++函数vector < unsigned long > Optimized_Eratosthenes_sieve(unsigned long max)
使用Cython。我有一个包含函数的文件sieve.h,一个静态库sieve.a和my设置.py具体如下:
^{pr2}$
在我的筛子.pyx我正在尝试:from libcpp.vector cimport vector
cdef extern from "sieve.h":
vector[unsigned long] Optimized_Eratosthenes_sieve(unsigned long max)
def OES(unsigned long a):
return Optimized_Eratosthenes_sieve(a) # this is were the error occurs
但我得到了这个“无法将'vector'转换为Python对象”的错误。我错过什么了吗?在
解决方案:我必须从OES函数返回一个python对象:def OES(unsigned long a):
cdef vector[unsigned long] aa
cdef int N
b = []
aa = Optimized_Eratosthenes_sieve(a)
N=aa.size()
for i in range(N):
b.append(aa[i]) # creates the list from the vector
return b