The Instant C/C++ in Python

Local
Documentation
Download
Global
Python
NumPy
Numarray
SWIG
Simula Research Laboratory
# Instant inlining of C/C++ code in Python ## News Release 0.9 (3/01/07): Port to Windows with mingw pluss some added functionality and clean up. Release 0.8 (5/10/06): Added support for NumPy and Numarray. Release 0.7 (12/09/06): Added functionality for the use of pkg-config files. Release 0.6 (17/07/06): Cleanup of the user interface. Release 0.5 (10/03/06): Instant uses SWIG directors for cross language inheritance. Release 0.4 (03/01/05): Added md5sums to avoid unnecessary compilation. Release 0.3 (27/11/05): Instant supports Numeric arrays. ## Appetizer Instant is a Python module that allows for instant inlining of C and C++ code in Python. It is a small Python module built on top of SWIG and Distutils. Example of use:
    from Instant import inline

    add_func = inline("double add(double a, double b){ return a+b; }")

    print "The sum of 3 and 4.5 is ", add_func(3, 4.5)
Example with NumPy arrays converted to C double arrays:
    from Instant import inline_with_numpy

    c_code = """
    double sum (int n1, double* array1){
      double tmp = 0.0;
      for (int i=0; i<n1; i++) {
          tmp += array1[i];
      }
      return tmp;
    }
    """

    sum_func = inline_with_numpy(c_code, arrays = [['n1', 'array1']])

    a = numpy.arange(10000000); a = numpy.sin(a)

    sum1 = sum_func(a)
On my machine, the above example is about twice as fast as using the sum function implemented in NumPy. This comparison is of course not fair, since there are no safety checks in the above example. The comparison is implemented in the file test9.py that comes with the Instant package. The old package Numeric is about as slow as NumPy (test2.py), while the same example with Numarray is about as fast as with Instant (test10.py). ## Requirement Instant requires Python and SWIG. It has only been tested with Python 2.3 and 2.4 and SWIG 1.3.24 or newer. It only runs on Unix systems. ## Related Projects The weave module in SciPy The PyInline module The PyRex module