I've posted two tutorials about generating Python bindings using SWIG and numpy.i:
These describe a lot of the programming I do. Using SWIG, I can write code which is completely free from any Python/C constructs and easily generate usable bindings. The second tutorial shows automatic memory deallocation when the Python arrays are deleted. This makes my code truly "pythonic".
On the Python side of things, a wealth of libraries (Matplotlib, PIL, VTK, etc...) allows me to load various datasets (from databases, various microscopy image formats, synthetic data...), test the code and display useful data. Also if needed, I can use my code in a native application.
Some simple GCC optimisations have really made my code fly:
- native CPU optimisation enabled by -march=native
- auto-vectorisation, enabled at -O3 (and detailed by -ftree-vectorizer-verbose=2)
- OpenMP multithreading enabled by -fopenmp requires a bit more work but is well worth the trouble (more about this here).
My first baby step was to adapt SWIG's example.fact() to SIP. Result code is here.
EDIT: As a second baby step, I wrote a C++ example. Result code is here.
Next step will be to convert numpy.i to SIP. Maybe start with IN_ARRAY1, try and stress the binding code and compare to SWIG.
Stay tuned! And of course, if you want to share your own experience with SWIG / SIP / Cython, I'd love to hear about it.
No comments:
Post a Comment