2017-01-19 33 views
0

私はCythonを学ぶためにCythonのチュートリアルのいくつかの例を再現してみてください。Cythonでこの警告が表示されるのはなぜですか?

http://docs.cython.org/en/latest/src/tutorial/external.html

私は2つの次の警告は、関連はないと思います。したがって、2 qestions:

(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. 
+0

_「次の2つの警告は関連していないと思いますので、2つの疑問があります:「_質問1つで質問してください –

答えて

1

異なる部分は、C関数を呼び出す異なる方法を示しています。

Cython .pxdヘッダーが提供される一部の機能については、from libc.math import sinを使用できます。すべてのライブラリについて、.hヘッダーと再宣言というより長めのメソッドを使用できます。

ただし、同じ機能の2つの定義が同じでも、2つの定義が作成されるため、2つを混在させることはできません。

+0

私は理解しています。 2番目の問題はそれに関連していますか? – michael

+0

非常に多分:-) '以前に 'cpdef'として宣言された関数 'sin'は多重定義された名前に関するものです。とにかく自分で試してみるべきです。もう一つの注意点:Cythonプログラミングを繰り返しテストしたいのであれば、Jupyterのノートブックhttp://docs.cython.org/ja/latest/src/quickstart/build.html?highlight=ipython#using-theを使用してテストすることができます-ipython-notebook –

+0

cpdef extern double sin(double x)は動作します。 – michael

関連する問題