在哪里可以将#Define放入Ipython Cython Cell中?
如果我用单元格制作笔记本
%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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Cython-Magic并没有定义或取消宏观的争论,但是可以通过添加以下行来做:
但是,在使用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:
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.