Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23247

Cython : How can we properly call add, sub, mul & divide operator?

$
0
0

In .pxd file, I wrote

    _Point operator+(const _Point other) const    _Point operator -(const _Point other) const    bool operator==(const _Point other) const

In .pyx file, I wrote

def __eq__(self, Point other):    cdef _Point* selfptr = self.c_point.get()    cdef _Point* otherptr = other.c_point.get()    return selfptr[0] == otherptr[0]

But it comes to operators like __add__ , I cannot do the same thing like ==.

def __add__(self, Point other):    cdef _Point * selfptr = self.c_point.get()    cdef _Point * otherptr = other.c_point.get()    return selfptr[0] + otherptr[0]

Error Message

× python setup.py egg_info did not run successfully.│ exit code: 1╰─> [27 lines of output]          Error compiling Cython file:          ------------------------------------------------------------          ...                  return not self.__eq__(other)              def __add__(self, Point other):                  cdef _Point * selfptr = self.c_point.get()                  cdef _Point * otherptr = other.c_point.get()                  return selfptr[0] + otherptr[0]                                    ^          ------------------------------------------------------------          src/Geometry/Point/Point.pyx:170:26: Cannot convert '_Point' to Python object

How can I fix this? Thank you


Viewing all articles
Browse latest Browse all 23247

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>