Python & C and Numerical Analyzes

Fernando Perez fperez528 at yahoo.com
Wed May 7 12:39:30 EDT 2003


erhan at uzem.itu.edu.tr wrote:

> My Problem is simple and short.
> I wanna use Python Language for a project that contains very compclex
> numerical analyzes and computations.In another project written in C
> language, this numerical analyzes and computations take a long time as 45
> min- 1 hour.I plan that use LAPACK(Linear Algebra Package) for Python and
> PySC and BLAS and QuadraPACK. But I am not sure that it is good choice.
> 
> In your opinion, is Python Language good and fast for this project.

Yes, with care.  Look at http://scipy.org, in particular look for weave. 
Judicious use of Scipy (which wraps lapack and will build using atlas if
present in your system) with inlined C for critical loops, is IMHO the way
to go for modern scientific computing.

In short:

- write as much of your code as possible using vectorized Numeric
operations.

- profile carefully

- go back to those inevitable python loops over numeric arrays and inline
them with C/blitz (weave.inline makes this trivially easy)

- if you still have problems, look at using weave.accelerate for potentially
costly temporaries, or rewrite also those with inlined C.

With reasonably well-structured code, this should give you very close to
pure C performance, with massively easier development, and excellent
flexibility/modularity (courtesy of python).

Here's the canonical paper on this topic:
http://www.python.org/workshops/1997-10/proceedings/beazley.html

best,

f.




More information about the Python-list mailing list