我使用的是我在网上找到的以下代码
def c_int_binary_search(seq,t):
# do a little type checking in Python
assert(type(t) == type(1))
assert(type(seq) == type([]))
# now the C code
code = """
#line 29 "binary_search.py"
int val, m, min = 0;
int max = seq.length() - 1;
PyObject *py_val;
for(;;)
{
if (max < min )
{
return_val = Py::new_reference_to(Py::Int(-1));
break;
}
m = (min + max) /2;
val = py_to_int(PyList_GetItem(seq.ptr(),m),"val");
if (val < t)
min = m + 1;
else if (val > t)
max = m - 1;
else
{
return_val = Py::new_reference_to(Py::Int(m));
break;
}
}
"""
return inline(code,['seq','t'])从documentation of scipy
当我尝试执行此脚本时,会出现以下错误
binary_search.py: In function ‘PyObject* compiled_func(PyObject*, PyObject*)’:
binary_search.py:36:38: error: ‘Py’ has not been declared我想知道有没有人能在这方面指导我。我已经安装了PyCXX。我正在使用Ubuntu。
非常感谢。
发布于 2011-07-21 01:55:06
该示例已过时,Py名称空间在最近的版本中不存在。
一些发行版将示例(应该保持最新)与scipy一起发布。在我的机器上,有这个:
/usr/lib64/python2.7/site-packages/scipy/weave/examples/binary_search.py如果你没有这样的东西,你可以从SciPy repository下载。
https://stackoverflow.com/questions/6764512
复制相似问题