[SciPy-dev] Thoughts on weave improvements

Pat Miller pnmiller at pacbell.net
Fri Feb 8 13:38:00 CST 2002

I was talking with Eric a lot this week at Python 10
and we had some thoughts on further improvements to
the weave module.  One thing that I want to add is
to blend in some of the bytecode compiler work I
started under PyCOD (compile on demand) that
builds C++ accelerated extension functions from Python

def foo(a,b):
    return a+b+10

handle, fastFoo = pycod.compile(foo,[IntType,IntType])

This would write and wrap a C++ function of the form

long foo(long a, long b) {
    return a + b + 10;

and an interface function
PyObject* fooWrap(...) {

The compiler in PyCOD was set up sort of like weave.inline to cache
precompiled results (though Eric's scheme is much more robust).

As you can see, this had a somewhat different flavor than inline.
Whereas weave.inline inlined expressions, pyCOD accellerated functions
(given input types).

We did it because we had Python callbacks in C++ code we wanted
accellerated.  I think that these techniques are important to
bring to scipy or else many parts of it are only toys.

def f(x):
     <some hairy, expensive python code>

print integrate.quad(f,0,1)

It might be better if the integration routine, using its knowledge that
the argument to x must be a PyFloat (C++ double) could use a C++ 
accelerated function instead of slow callbacks to Python.  Not important
for a quick numeric integration, but crucial for using Python as a
true C/FORTRAN replacement.


More information about the Scipy-dev mailing list