【发布时间】:2017-01-20 03:02:04
【问题描述】:
我尝试重现 Cython 教程中的一些示例来学习 Cython:
http://docs.cython.org/en/latest/src/tutorial/external.html
我认为以下两个警告不相关。因此有两个问题:
(1)
使用这个作为输入
python setup.py build_ext --inplace -c mingw32
from libc.math cimport sin
cdef extern from "math.h":
cdef double sin(double x)
cpdef double f(double x):
return sin(x*x)
cpdef test(double x):
return f(x)
我明白了:
D:\python\cython>python setup.py build_ext --inplace -c mingw32
Compiling primes.pyx because it changed.
[1/1] Cythonizing primes.pyx
warning: primes.pyx:4:19: Function signature does not match previous declaration
running build_ext
building 'primes' extension
C:\MinGW\bin\gcc.exe -mdll -O -Wall -IC:\Python34\include -IC:\Python34\include -c primes.c -o build\temp.win32-3.4\Release\primes.o
writing build\temp.win32-3.4\Release\primes.def
C:\MinGW\bin\gcc.exe -shared -s build\temp.win32-3.4\Release\primes.o build\temp.win32-3.4\Release\primes.def -LC:\Python34\libs -LC:\Python34\PCbuild -lpython34 -lmsvcr100 -o D:\python\cython\primes.pyd
D:\python\cython>
为什么会出现警告“函数签名与之前的声明不匹配”?
(2)
当我声明时
cdef extern from "math.h":
cpdef double sin(double x)
我收到了额外的警告
warning: primes.pyx:4:20: Function 'sin' previously declared as 'cpdef'
但是,它的给出方式与链接页面的“外部声明”一章中的示例完全相同。在导入模块的python模块中,sin在包下是不知道的。问题出在哪里?
教程中的描述是:
Note that you can easily export an external C function from your Cython module by declaring it as cpdef. This generates a Python wrapper for it and adds it to the module dict.
【问题讨论】:
-
“我认为以下两个警告不相关。因此两个问题:”每个问题一个问题
标签: cython