Instant 0.8 review
DownloadInstant is a Python module that allows for instant inlining of C and C++ code in Python
|
|
Instant is a Python module that allows for instant inlining of C and C++ code in Python. Instant is a small Python module built on top of SWIG.
Example of use:
>>> c_code = """
double sum(double a, double b){
return a+b;
}
"""
>>> import Instant
>>> ext = Instant.Instant()
>>>
>>> # create the wrapper code, compile and link it to a shared library
>>> ext.create_extension(code=c_code, module='test1_ext')
>>>
>>> # use the C code
>>> from test1_ext import sum
>>> print sum(3.7, 4.8)
8.5
Example with NumPy arrays converted to C double arrays:
>>> import Instant
>>> import Numeric
>>> import sys
>>> import time
>>>
>>> ext = Instant.Instant()
>>>
>>> c_code = """
/* add function for vectors with all safety checks removed ..*/
void add(int n1, double* array1, int n2, double* array2, int n3, double* array3){
for (int i=0; i>>"""
>>>
>>> ext.create_extension(code=c_code, headers=["arrayobject.h"],
>>> include_dirs=[sys.prefix + "/include/python" + sys.version[:3] + "/Numeric"],
>>> init_code='import_array();', module='test3_ext',
>>> arrays = [['n1', 'array1'],['n2', 'array2'],['n3', 'array3']])
>>>
>>> from test3_ext import add
>>> a = Numeric.arange(10000); a = Numeric.sin(a)
>>> b = Numeric.arange(10000); b = Numeric.cos(b)
>>> c = Numeric.arange(10000); c = Numeric.cos(c)
>>>
>>>add(a,b,c)
Instant 0.8 search tags