I have a new project called PyEigen, a wrapper for the C++ linear algebra library Eigen. I just submitted the first batch of code and progress is good, at least so far.
I’m hoping for an initial release within a month or so.
The whole thing started when I profiled my shooter project and found that matrix calculations take up a huge amount of time. Apparently NumPy isn’t really fast enough for 3D games, and I couldn’t find any replacements. While otherwise looking good, euclid and vectypes are pure Python so they aren’t going to make performance any better. cgkit is C++ with a Python wrapper so looking better already, but… it’s using Boost.Python, which apparently isn’t very fast. Also, it’s lacking SSE instrumentation and other optimizations included in Eigen. So I decided to wrap Eigen.
As I already found out, Boost.Python is slow and looked too complex for such a simple library anyway. I tried Cython next, but its C++ support is (still) very limited and the lack of support for C++ references destroyed any hope of wrapping Eigen, which relies heavily on them. My final option before resorting to manual wrapping using the Python C API was SWIG, but I had problems getting even a simple wrapper to compile. Besides, I don’t really like how SWIG generates function wrappers and a separate Python module that calls those wrappers instead of generating a Python C module directly.
So I was left with only the final option: Python C API. I feared it at first because I’ve never worked with it and it seemed really complex. It is complex, but not nearly as bad as I though, especially as Eigen has such a simple API. For Bullet, I’m sure I’ll use Cython or some other wrapper generator, but for Eigen the Python C API is just fine.
Anyway, since there doesn’t seem to be anything like this out there, I decided to make it an open source project so hopefully other people in the same situation won’t have to jump through the same hoops as I did. I’ll post progress reports, releases and especially benchmarks against the other options as soon as I have them.
http://launchpad.net/pyeigenI h
Tags: boost.python, C++, cython, linear algebra, numpy, pyeigen, Python, swig