Module Instant
[show private | hide private]
[frames | no frames]

Module Instant

By using the class Instant a Python extension module can be created at runtime. For the user, it behaves somewhat like an inline module, except you have to import the module manually.

The code can be either C or C++, but like when programming C or C++, it has to be inside a function or a similar C/C++ construct.

A simple example: (see test1.py)
>>> 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)

Classes
Instant  

Function Summary
  create_extension(**args)
This is a small wrapper around the create_extension function in Instant.
  header_and_libs_from_pkgconfig(*packages)
This function returns list of include files, flags, libraries and library directories obtain from a pkgconfig file.
  inline(c_code)
This is a short wrapper around the create_extention function in Instant.
  inline_with_numarray(c_code, **args_dict)
This is a short wrapper around the create_extention function in Instant.
  inline_with_numeric(c_code, **args_dict)
This is a short wrapper around the create_extention function in Instant.
  inline_with_numpy(c_code, **args_dict)
This is a short wrapper around the create_extention function in Instant.
  list2str(list)

Variable Summary
int VERBOSE = 0                                                                     

Function Details

create_extension(**args)

This is a small wrapper around the create_extension function in Instant.

Call this function to instantly create an extension module. SWIG is used to generate code that can be compiled and used as an ordinary Python module.

Arguments:

  • code:
    • A Python string containing C or C++ function, class, ....
  • module:
    • The name you want for the module (Default is 'instant_swig_module'.). String.
  • swigopts:
    • Options to swig, for instance -lpointers.i to include the SWIG pointers.i library. String.
  • init_code:
    • Code that should be executed when the Instant extension is imported. String.
  • system_headers:
    • A list of system header files required by the Instant code.
  • local_headers:
    • A list of local header files required by the Instant code.
  • wrap_headers:
    • A list of local header files that will be wrapped by SWIG.
  • include_dirs:
    • A list of directories to search for header files.
  • sources:
    • A list of source files to compile and link with the extension.
  • cppargs:
    • Flags like -D, -U, etc. String.
  • libraries:
    • A list of libraries needed by the Instant extension.
  • library_dirs:
    • A list of directories to search for libraries (-l).
  • object_files:
    • If you want to compile the files yourself. NOT YET SUPPORTED.
  • arrays:
    • A list of the C arrays to be made from NumPy arrays.

header_and_libs_from_pkgconfig(*packages)

This function returns list of include files, flags, libraries and library directories obtain from a pkgconfig file. The usage is: (includes, flags, libraries, libdirs) = header_and_libs_from_pkgconfig(list_of_packages)

inline(c_code)

This is a short wrapper around the create_extention function in Instant.

It creates an extension module given that the input is a valid C function. It is only possible to inline one C function each time.

Usage:
>>> 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)

inline_with_numarray(c_code, **args_dict)

This is a short wrapper around the create_extention function in Instant.

It creates an extension module given that the input is a valid C function. It is only possible to inline one C function each time. The difference between this function and the inline function is that C-arrays can be used. The following example illustrates that.

Usage:
>>> import numarray 
>>> import time
>>> from Instant import inline_with_numarray
>>> 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_numarray(c_code,  arrays = [['n1', 'array1']])
>>> a = numarray.arange(10000000); a = numarray.sin(a)
>>> sum_func(a)

inline_with_numeric(c_code, **args_dict)

This is a short wrapper around the create_extention function in Instant.

It creates an extension module given that the input is a valid C function. It is only possible to inline one C function each time. The difference between this function and the inline function is that C-arrays can be used. The following example illustrates that.

Usage:
>>> import numpy 
>>> import time
>>> from Instant import inline_with_numeric
>>> 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_numeric(c_code,  arrays = [['n1', 'array1']])
>>> a = numpy.arange(10000000); a = numpy.sin(a)
>>> sum_func(a)

inline_with_numpy(c_code, **args_dict)

This is a short wrapper around the create_extention function in Instant.

It creates an extension module given that the input is a valid C function. It is only possible to inline one C function each time. The difference between this function and the inline function is that C-arrays can be used. The following example illustrates that.

Usage:
>>> import numpy
>>> import time
>>> 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)
>>> sum_func(a)

Variable Details

VERBOSE

Type:
int
Value:
0                                                                     

Generated by Epydoc 2.1 on Tue Jan 30 13:30:03 2007 http://epydoc.sf.net