Home | Trees | Index | Help |
|
---|
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 | |
---|---|
This is a small wrapper around the create_extension function in Instant. | |
This function returns list of include files, flags, libraries and library directories obtain from a pkgconfig file. | |
This is a short wrapper around the create_extention function in Instant. | |
This is a short wrapper around the create_extention function in Instant. | |
This is a short wrapper around the create_extention function in Instant. | |
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:
|
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
|
Home | Trees | Index | Help |
|
---|
Generated by Epydoc 2.1 on Tue Jan 30 13:30:03 2007 | http://epydoc.sf.net |