在哪里可以将#Define放入Ipython Cython Cell中?

发布于 2025-02-09 14:39:19 字数 1217 浏览 1 评论 0原文

如果我用单元格制作笔记本

%load_ext cython

%%cython -a

cimport numpy as cnp

第二个输出

In file included from /home/ignoring_gravity/.venv/lib/python3.9/site-packages/numpy/core/include/numpy/ndarraytypes.h:1960,
                 from /home/ignoring_gravity/.venv/lib/python3.9/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                 from /home/ignoring_gravity/.venv/lib/python3.9/site-packages/numpy/core/include/numpy/arrayobject.h:5,
                 from /home/ignoring_gravity/.cache/ipython/cython/_cython_magic_7ec32efe76f8c3e83109f4fadb9a4e1f.c:765:
/home/ignoring_gravity/.venv/lib/python3.9/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
   17 | #warning "Using deprecated NumPy API, disable it with " \
      |  ^~~~~~~

我的问题是 - 我应该在哪里放置#define npy_no_deprecated_api npy_1_1_7_api_api_version?如果我将第二个单元更改为

%%cython -a

#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
cimport numpy as cnp

,那么它仍然会发出相同的警告

If I make a notebook with cells

%load_ext cython

and

%%cython -a

cimport numpy as cnp

then the second one outputs

In file included from /home/ignoring_gravity/.venv/lib/python3.9/site-packages/numpy/core/include/numpy/ndarraytypes.h:1960,
                 from /home/ignoring_gravity/.venv/lib/python3.9/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                 from /home/ignoring_gravity/.venv/lib/python3.9/site-packages/numpy/core/include/numpy/arrayobject.h:5,
                 from /home/ignoring_gravity/.cache/ipython/cython/_cython_magic_7ec32efe76f8c3e83109f4fadb9a4e1f.c:765:
/home/ignoring_gravity/.venv/lib/python3.9/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
   17 | #warning "Using deprecated NumPy API, disable it with " \
      |  ^~~~~~~

My question is - where should I put#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION? If I change the second cell to

%%cython -a

#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
cimport numpy as cnp

then it still gives the same warning

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉世弥音 2025-02-16 14:39:19

Cython-Magic并没有定义或取消宏观的争论,但是可以通过添加以下行来做:

%%cython -a
# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION

cimport numpy as cnp

但是,在使用Cython 3.0之前,使用了弃用的numpy-api,摆脱了此警告,可能会/可能会导致问题。因此,对于Cython的版本< = 3.0,应该遵循 @Davidw的建议并忽略警告。

另请参见 certhon的文档。

Cython-magic doesn't have arguments to define or un-define a macro, but one could do by adding the following line:

%%cython -a
# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION

cimport numpy as cnp

However, until Cython 3.0, the deprecated numpy-API was used and getting rid of this warning would/could lead to issues. Thus, for Cython's versions <= 3.0 one should follow @DavidW's advice and ignore the warning.

See also a related note in the Cython's documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文