次のダミーの Cython コードを検討してください。
#!python
#cython: boundscheck=False
#cython: wraparound=False
#cython: initializedcheck=False
#cython: cdivision=True
#cython: nonecheck=False
import numpy as np
# iterator function
cdef double[:] f(double[:] data):
data[0] *= 1.01
data[1] *= 1.02
return data
# looping function
cdef double[:] _call_me(int bignumber, double[:] data):
cdef int ii
for ii in range(bignumber):
data = f(data)
return data
# helper function to allow calls from Python
def call_me(bignumber):
cdef double[:] data = np.ones(2)
return _call_me(bignumber, data)
ここで、これに対してcython -aを実行すると、return ステートメントが黄色で表示されます。非常にパフォーマンスが重要なプログラムで同様のことを行っていますが、プロファイリングによると、コードの速度が本当に低下しています。では、なぜ cython はこれらの return ステートメントに python を必要とするのでしょうか? 注釈付きファイルはヒントを提供します。
PyErr_SetString(PyExc_TypeError,"Memoryview return value is not initialized");
驚くべきことに、 cython の「Memoryview return value is not initialized」をGoogle 検索しても結果はゼロです。