A faster Python?, Python compiler, Dylan,...

eric eric at enthought.com
Thu Apr 4 09:37:32 EST 2002


> > For this particular example, weave.inline is a perfect solution.  The C++
code
> > is pretty readable:
> >
> > from scipy import *
> >
> > def foo(a):
> >     code = """
> >            for (int i = 0; i < _Na(0);i++) {
> >                if (a(i,i) > 30) a(i,i) += a(i,i+1);
> >                else             a(i,0) *= 2.0; }
> >            """
> >     weave.inline(code,'a',compiler='gcc',
> >                  type_converters = weave.converters.blitz)
> >
> > a = rand(3,3)*60
> > print 'before:', a
> > foo(a)
> > print 'after:', a
> >
>
> Great, I am becoming even more impressed. However, the main criticism
> remains: You have to code your function twice, first in Python for
> prototyping, then in C. But I agree that weave saves you a lot of
> work.

If this is the only criticism, than we're doing quite well. :-)  The alternative
to Python right now if you need speed is to write your entire program (or
extension) in C/C++.  Of course, then the complaint becomes "Man, it sure does
run fast, but I sure wish C had dynamic typing and didn't have all this memory
management stuff." ;-) When I need to write things in C/C++, I generally
prototype them in Python first anyway.

That said, I just saw another project similar to weave come across the line on
python-dev called Pyrex.  very cool.  It allows C typing in Python code and then
compiles the code to an extension module.  It may be exactly what you are
looking for.  Lets hope it moves forward quickly.


With all these people working on the problem, I'm betting some sort of
accelerated Python is a reality in 1-2 years.  It may not be a full
implementation, but it'll likely accelerate scientific codes. So, take a look at
Pysco, Pyrex, and weave, choose the one you like, and pitch in!  We all know
that a faster Python is desired.  It even looks very possible.  The problem is
making it a reality.

http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/
http://homepages.ulb.ac.be/~arigo/psyco/
http://www.scipy.org/site_content/weave

see ya,

eric










More information about the Python-list mailing list