[SciPy-dev] Low-level code integration discussion at scipy'03?

Pat Miller patmiller at llnl.gov
Tue Sep 2 16:55:02 CDT 2003

I've been working on inline compilation that grabs values out of Python
and slams them into C.  This is basically a rework of ideas that Eric
had for weave.  Part of the win is noticing variables that exist in
Python and importing them.  So,

from compilation import inline
def f(x,y):
    z = 0.0
	printf("x: %g and y: %g\n",x,y);
         z = x+y;
    return z

print f(11.1,22.2) # Will print 33.3

This is pretty clean since in notices that X, Y, and Z are double and builds
the extension appropriately.

* * * * *  Now we jump into vaporware * * * * *

Suppose we had

def mm(A,x,Z):
   "A is a matrix, x is a column vector, Z is just some double"
        Z = MAX(x)

where libmystuff.so contains all the nifty stuff you want to interface too
(not python libs, just the FORTRAN).

The code generator (once, ala weave) builds an extension that gets
builds the code you want with a shell that is called from python.

        CALL MYMATMULT(...)

and in C

PyObject* somegenerated_name(PyObject* self, PyObject* args) {
    double* A = << get base pointer >>
    int DIM1_A = << get size info >>
    double Z = ....
    _GENERATED(A,DIM1,..., & Z);
   << Code to flush Z back into python >>

   return Py_None;

Patrick Miller | (925) 423-0309 | http://www.llnl.gov/CASC/people/pmiller

When I was a boy I was told that anybody could become President. Now I'm
beginning to believe it. -- Clarence Darrow, lawyer and author (1857-1938)

More information about the Scipy-dev mailing list