Source

hack2 / pypyembed / example.py


import numpy
from embed import export_function

@export_function
def f(a, b):
    return a + b

@export_function
def returning_numarray(size):
    import numpy
    return numpy.arange(size)

print returning_numarray(100)

@export_function
def passing_numarray_multidim(a):
    s = 0
    for i in range(a.shape[0]):
        for j in range(a.shape[1]):
            s += a[i, j]
    return s

print passing_numarray_multidim(numpy.arange(100).reshape(10, 10))