Instant
From The FEniCS project
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 beeing 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 sum function is about three times faster than the corresponding sum function in numpy (see also the file test9.py that comes with the package).
[edit]
Main authors
Martin Alnæs, Kent-Andre Mardal and Magne Westlie
[edit]
License
Instant is licensed under the BSD license.
[edit]
Dependencies and requirements
Instant depends on SWIG.

