【发布时间】:2014-01-15 07:56:28
【问题描述】:
我正在编写一个 python 类,我想使用 cython 早期输入来加速执行。
当我尝试 cython 编译以下内容时,我收到错误 "Syntax error in C variable declaration":
import numpy as np
cimport numpy as np
class MyClass:
def __init__( self, np.ndarray[double, ndim=1] Redges ):
self.Redges = Redges
cdef double self.var1
错误涉及涉及self.var1 的最后一行的语法。我不能直接输入类属性吗?我是否总是必须将其分解为两个步骤,例如,
cdef double var1
self.var1 = var1
完整的错误回溯是,
test.pyx:7:24:
Syntax error in C variable declaration
Traceback (most recent call last):
File "setup.py", line 9, in <module>
ext_modules = cythonize('test.pyx'), # accepts a glob pattern
File "/usr/lib/python2.7/dist-packages/Cython/Build/Dependencies.py", line 713, in cythonize
cythonize_one(*args[1:])
File "/usr/lib/python2.7/dist-packages/Cython/Build/Dependencies.py", line 780, in cythonize_one
raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: calc_iliev_sphere.pyx
【问题讨论】:
-
这不是完整的回溯。