2
__cinit__
또는 __add__
에 과부하가 걸릴 수 있습니까? 이 같은 뭔가 :Cython 오버로드 특수 메서드?
cdef class Vector(Base):
cdef double x, y, z
def __cinit__(self, double all):
self.x = self.y = self.z = all
def __cinit__(self, double x, double y, double z):
self.x = x
self.y = y
self.z = z
def __str__(self):
return "Vector(%s, %s, %s)" % (self.x, self.y, self.z)
def __add__(self, Vector other):
return Vector(
self.x + other.x,
self.y + other.y,
self.z + other.z,
)
def __add__(self, object other):
other = <double>other
return Vector(
self.x + other.x,
self.y + other.y,
self.z + other.z,
)
이 Vector(0) + Vector(2, 4, 7)
호출은 오버로드 된 방법으로 인식되지 __add__(self, Vector other)
것 같아 있도록 플로트가 여기에 필요하다는 것을 알려줍니다. 특별한 방법이 cdef
로 정의하지 않아야 만 cdef
-fed 기능에 과부하가 될 수 있기 때문에
이 있습니까?