Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Cython问题,can';不要在类变量上使用cdef_Python_C_Python 3.x_Cython_Cythonize - Fatal编程技术网

Python Cython问题,can';不要在类变量上使用cdef

Python Cython问题,can';不要在类变量上使用cdef,python,c,python-3.x,cython,cythonize,Python,C,Python 3.x,Cython,Cythonize,我正在尝试使用Cython将python类转换为C,以提高时间复杂度。我最常用的变量是init方法中定义的类变量,因此我想将它们定义为cdef double。我已经尝试了我能找到的一切,但什么都没有让我转换代码。似乎这应该是解决问题的方法: class Wall(object): cdef double min_x, max_x, a, b, c def __init__(self, start, stop): self.min_x = min(start[0], stop[0])

我正在尝试使用Cython将python类转换为C,以提高时间复杂度。我最常用的变量是init方法中定义的类变量,因此我想将它们定义为cdef double。我已经尝试了我能找到的一切,但什么都没有让我转换代码。似乎这应该是解决问题的方法:

class Wall(object):

cdef double min_x, max_x, a, b, c

def __init__(self, start, stop):
    self.min_x = min(start[0], stop[0])
    self.max_x = max(start[0], stop[0])
    self.a = (stop[1]-start[1])/(stop[0]-start[0])
    self.b = -1
    self.c = start[1]-self.a*start[0]
但我得到了以下错误:

我做错了什么


您好,Jakob

您需要公开类变量,并为类提供一个C声明。试试这个:

cdef class Wall(object):

    cdef public double min_x, max_x, a, b, c

    def __init__(self, start, loop):
        ...

我投票认为这是一个打字错误,因为它应该是
cdef类墙
,也就是说
cdef
被遗忘了。
cdef class Wall(object):

    cdef public double min_x, max_x, a, b, c

    def __init__(self, start, loop):
        ...