Source

hack2 / pypyembed / test / test_example.py

import numpy
from embed import export_function

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

def test_basics():
    assert adder(1, 2) == 3
    assert adder(1.2, 3.4) == 4.6

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

def test_returning_numarray():
    assert returning_numarray(100)[13] == 13

@export_function
def returning_numarray_multidim(a, b):
    import numpy
    return numpy.arange(a * b).reshape(a, b)

def test_returning_numarray_multidim():
    assert (returning_numarray_multidim(2, 5)[1] == [5, 6, 7, 8, 9]).all()

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

def test_passing_numarray():
    assert passing_numarray(numpy.arange(100)) == 50 * 99

@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

def test_passing_numarray_multidim():
    assert passing_numarray_multidim(numpy.arange(100).reshape(10, 10)) == 50 * 99
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.