raysect / source

The main source repository for the Raysect project.
http://www.raysect.org
BSD 3-Clause "New" or "Revised" License
86 stars 23 forks source link

Cython 3.0 incompatible issue #425

Open munechika-koyo opened 1 year ago

munechika-koyo commented 1 year ago

Hello,

I found that runtime error about vector multiplication calculation like:

>>> from raysect.core.math import Vector3D
>>> Vector(1, 2, 3) * 2.0
Vector3D(2.0, 4.0, 6.0)

>>> 2.0 * Vector3D(1, 2, 3)
TypeError: unsupported operand type(s) for *: 'int' and 'raysect.core.math.vector.Vector3D'

This error cannot be seen if I compile raysect by cython < 3.0.0. So, I suppose the issue is caused by cython 3.0 incompatibility.

munechika-koyo commented 1 year ago

when checking the docs (https://cython.readthedocs.io/en/latest/src/userguide/special_methods.html), I noticed that parameters of __mul__ method had been changed. (__mul__(x, y)-> __mul__(self, other)) This seems to cause the issue.

And we should implement __rmul__() reverse method.

vsnever commented 1 year ago

Hi, Yes, this applies to all binary arithmetic methods. As pointed out by @jacklovell in #373, there is a directive c_api_binop_methods=True that allows the old implementation to continue working. I was going to fix Raysect incompatibility with Cython 3.0, but haven't found the time yet. I will try to look in the near future, because this also affects Cherab.

munechika-koyo commented 1 year ago

Thank you for your prompt reply. I could not noticed that issue. I am also trying to fix all binary arithmetic methods at least and going to push the PR, so please consider it if you are welcome.

vsnever commented 1 year ago

I am also trying to fix all binary arithmetic methods at least and going to push the PR, so please consider it if you are welcome.

Thank you very much! The fix you proposed is fine with me. Let's wait for a response from @CnlPepper.