comparation of Python with other languages

Fernando Pérez fperez528 at yahoo.com
Sun Jan 20 15:58:59 EST 2002


Stephane SOPPERA wrote:

> 
> You can choose languages such as python or java if you're only working on
> _small_ pictures (memory problems) and if your image computations are not to
> complicated (python and java are slower).

Well, see A. Martelli's post for more details, but basically you have a 
limited view of python's approach to problems. Yes, raw python will never 
compete with raw C/C++ for speed, that's obvious. But since typically most 
numerically intensive programs in fact consist of a small core where 
performance is critical and a large array of supporting code, the 'python 
way' is: code in python, identify *exactly* what parts really require speed, 
and then rewrite only those in C/C++.

And if you use the brand new weave module 
(http://www.scipy.org/site_content/weave) you can do things like:

def in_place_mult(num,mat):
    """In-place multiplication of a matrix by a scalar.
    """
    nrow,ncol = mat.shape
    code = \
"""
for(int i=0;i<nrow;++i)
    for(int j=0;j<ncol;++j)
        mat(i,j) *= num;

"""
    weave.inline(code,['num','mat','nrow','ncol'],
                 type_factories = blitz_type_factories)

This is toy code just to show you how you can get, right inside of python, 
C/C++ code for the parts you need.

You'll be hard pressed to find an easier blend of flexibility, speed of 
development and speed of execution than that formed by Python+(C/C++) with 
the weave tools. And if you need to use fortran libraries, a similar solution 
to weave is f2py: http://cens.ioc.ee/projects/f2py2e.

I do scientific computing for a living, and these days all I use for new code 
is python, looking at C libraries and snippets of code only when I know that 
I need it.

Regards,

f.



More information about the Python-list mailing list