Cython 没有为函数生成 __code__ 属性
我试图在我的 Cython 代码上使用 line_profiler 并询问 这个问题,我现在意识到这个问题不清楚。问题是我从 Cython 导入的函数没有任何 __code__
属性。
Cython cpdef、cdef 或 def 函数是否应该具有此属性?有什么想法为什么我的没有吗?
这是我的 cython_agri.pyx 文件:
# cython: linetrace=True
cimport cython
import numpy as np
from datetime import timedelta, datetime
@cython.binding(True)
cpdef list read_static_binary_data(data_row: list, read_point: int, binary_data: object, tlg_dict: dict, dt: np.dtype,
start_date: datetime):
"""Function to obtain the position and time data """
cdef int nr_d = 3
cdef float ten_minus_seven = pow(10, -7)
....
return [data_row, nr_dlvs, nr_d - 1]
这是我的 setup.py
import setuptools
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
from Cython.Compiler.Options import get_directive_defaults
directive_defaults = get_directive_defaults()
directive_defaults['linetrace'] = True
directive_defaults['binding'] = True
extensions = [
Extension("pyAgriculture", ["pyAgriculture\cython_agri.pyx"], define_macros=[('CYTHON_TRACE', '1')])
]
setup(ext_modules=cythonize(extensions, language_level="3"))
我使用以下命令编译代码:py pyAgriculture\setup.py build_ext --inplace
。
I'm trying to use a line_profiler on my Cython code and asked this question, I now realize that the question was not clear. The problem is that the function that I import from Cython hasn't got any __code__
attribute.
Should Cython cpdef
, cdef
or def
functions have this attribute? Any ideas why mine hasn't got one?
This is my cython_agri.pyx file:
# cython: linetrace=True
cimport cython
import numpy as np
from datetime import timedelta, datetime
@cython.binding(True)
cpdef list read_static_binary_data(data_row: list, read_point: int, binary_data: object, tlg_dict: dict, dt: np.dtype,
start_date: datetime):
"""Function to obtain the position and time data """
cdef int nr_d = 3
cdef float ten_minus_seven = pow(10, -7)
....
return [data_row, nr_dlvs, nr_d - 1]
This is my setup.py
import setuptools
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
from Cython.Compiler.Options import get_directive_defaults
directive_defaults = get_directive_defaults()
directive_defaults['linetrace'] = True
directive_defaults['binding'] = True
extensions = [
Extension("pyAgriculture", ["pyAgriculture\cython_agri.pyx"], define_macros=[('CYTHON_TRACE', '1')])
]
setup(ext_modules=cythonize(extensions, language_level="3"))
I compile the code using this command: py pyAgriculture\setup.py build_ext --inplace
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论