Cython 没有为函数生成 __code__ 属性

发布于 2025-01-11 17:38:40 字数 1499 浏览 1 评论 0原文

我试图在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文