У меня проблема с пониманием Cython и pxd.Я нашел этот код в Интернете, но не работает.Не могли бы вы объяснить, почему?
Ошибка при компиляции:
предупреждение: test.pyx: 1: 0: переопределение метода cdef с помощью метода def.
test.pxd: 6: 14: метод C 'foo' объявлен, но не определен
Я нашел этот пример здесь: https://cython.readthedocs.io/en/latest/src/tutorial/pure.html
Я сделал ошибку в компиляции?
compile.py:
import os
import sysconfig
from distutils.core import setup
from Cython.Build import cythonize
fichier = "test.pyx"
setup(
ext_modules = cythonize(fichier)
)
test.pyx:
def myfunction(x, y=2):
a = x - y
return a + x * y
def _helper(a):
return a + 1
class A:
def __init__(self, b=0):
self.a = 3
self.b = b
def foo(self, x):
print(x + _helper(1.0))
test.pxd:
cpdef int myfunction(int x, int y=*)
cdef double _helper(double a)
cdef class A:
cdef public int a, b
cpdef foo(self, double x)