Kautenja / nes-py

A Python3 NES emulator and OpenAI Gym interface
MIT License
235 stars 63 forks source link

fix: compatibility for pypy interpreter #78

Closed dman82499 closed 3 years ago

dman82499 commented 3 years ago

Added support for pypy 3.7

The pypy (https://www.pypy.org/#!) interpreter throws an error (Line 72 TypeError: Can't multiply a ctypes type by a non-integer) when running the nes_env.py file, mostly due to some slight differences in the pypy numpy implementation. This is a quick one line fix for this issue, that should not break functionality in any of the other interpreters. It is simply an int cast, and numpy.prod() will always return an int, so nothing should break.

Kautenja commented 3 years ago

Thanks for the PR! Your change has been released in version 8.1.8.

Kautenja commented 3 years ago

Also just a heads up, when I speed test pypy3 (python3.7 spec) against python3.9, it's actually somewhat slower:

➜  nes-py git:(master) python3 speedtest.py            
100%|██████████████████████████████████████| 5000/5000 [00:07<00:00, 665.91it/s]
➜  nes-py git:(master) pypy3 speedtest.py  
100%|██████████████████████████████████████| 5000/5000 [00:08<00:00, 611.40it/s]
➜  nes-py git:(master) 
dman82499 commented 2 years ago

yeah, it just depends on what code the interpreter is running. pypy tends to run faster only when it parses loads of pure python code. When just nes-py is run, it will be slower. However, if you do some intermediate operations in between frames that uses a lot of pure python for loops (as what used to be the case in my project), it will run faster.

Kautenja commented 2 years ago

Oh that makes sense. Thanks for clarifying!