Friday, December 29, 2006

A wish: Compile functions with shedskin

I have a wish. I wish to be able to compile a function in a module with Shed Skin at run time, much like it is done in weave and f2py2e. When I first though about it, it seemed a simple task:
  1. write a decorator that would allow the function to read its arguments from stdin and write what ever it returns to stdout.
  2. save the decorated function to a file, and compile it with shed skin
  3. call the resulting executable with os.popen, passing the arguments and receiving the output of the function.
It "would" be easy if there was a way to get the code of the function into a file at runtime.... As far as I know there is no way to do this.

I any case I am still sticking to my wish, hoping for suggestions of how to make it happen.

According to Mark Dufour, Shed Skin's developer, there is somebody working on using boost.python to wrap SS generated C++ code. That would be something very nice, but not as much as having a @skinner decorator.

Monday, December 11, 2006

Trying out the latest release of shedskin

It had been moths since I had tried Shed skin for the last time. It hadn't impressed me the last time due to its limitations to the python code supported.

I was prompted to try it again after the december release due to large list of improvements announced.

So I decided to apply a couple of routines for calculateing primes that I ofen use to test the performance of python against Compiled languages like C, FORTRAN, etc.

I was very suprised with the simplicity of the whole process:

$ ss primes
$ make run

That was all it took for a 30 times faster C++ version!! Compare that to Pyrex, weave, swig et al.

The only modification I had to make to my script was removing the
if __name__=='__main__':

from the end of the script.

Great tool!


After a long time and extensiv considerations, I decided to put up a blog about my experiences with Python in science. Tune in for some interesting reports!