Instant

This is a relatively new package (called pyinstant at sourceforge) that builds on top of SWIG to make it easy to inline C and C++ code in Python very much like weave. However, Instant builds extension modules on the fly with specific module names and specific method names. In this repsect it is more more like f2py in its behavior. The extension modules are built on-the fly (as long as the SWIG is installed). They can then be imported. Here is an example of using Instant with NumPy arrays (adapted from the test2 included in the Instant distribution):

various checks */

PyArrayObject* a=(PyArrayObject*) a_;

PyArrayObject* b=(PyArrayObject*) b_;

PyArrayObject* ret;

ret = (PyArrayObject*) PyArray_FromDims (1, dims, NPY_DOUBLE) ; int i;

double *retj = (double *)ret->data; for (i = 0; i < n; i + +) {

*retj++ = *((double *)aj) + *((double *)bj); aj += a->strides[0]; bj += b->strides[0];

import Instant, numpy ext = Instant.Instant()

ext. create.extension(code=s, headers=["numpy/arrayobj ect.h"] , import test2b_ext a = numpy.arange(1000) b = numpy.arange(1000) d = test2b_ext.add(a,b)

Except perhaps for the dependence on SWIG, Instant is a straightforward utility for writing extension modules.

16.7.5 PyInline

This is a much older module that allows automatic building of extension modules so that C-code can be included with Python code. It's latest release (version 0.03) was in 2001, and it appears that it is not being updated.

16.7.6 PyFort

PyFort is a nice tool for wrapping Fortran and Fortran-like C-code into Python with support for Numeric arrays. It was written by Paul Dubois, a distinguished computer scientist and the very first maintainer of Numeric (now retired). It is worth mentioning in the hopes that somebody will update PyFort to work with NumPy arrays as well which now support either Fortran or C-style contiguous arrays.

0 0

Post a comment