Esempio n. 1
0
$ python test/test_sim_npy.py test_ensemble.TestEnsemble.test_lifrate

"""

from nengo_ocl.tricky_imports import unittest
from nengo.tests.helpers import NengoTestLoader
from nengo.tests.helpers import load_nengo_tests
import nengo.tests.test_simulator
from nengo_ocl import sim_npy

# -- these TestSimulator and TestNonlinear are handled differently because
# NengoTestLoader only picks up subclasses of SimulatorTestCase. TestSimulat
# and TestNonlinear in nengo do not inherit from SimulatorTestCase.  The
# semantics of SimulatorTestCase can be understood as being "These should pass
# for ANY Simulator". TestSimulator and TestNonlinear are stricter tests of
# the reference simulator's API, which we also attempt to pass, because we can
# so why not.

class TestSimulator(nengo.tests.test_simulator.TestSimulator):
    Simulator = sim_npy.Simulator


class TestNonlinear(nengo.tests.test_simulator.TestNonlinear):
    Simulator = sim_npy.Simulator


load_tests = load_nengo_tests(sim_npy.Simulator)

if __name__ == '__main__':
   unittest.main(testLoader=NengoTestLoader(sim_npy.Simulator))
Esempio n. 2
0
            def __init__(self, my_fn):
                self.fn = my_fn

        F = Foo(my_fn=lambda x: x[0] ** 2)
        b = F.fn
        self._test_fn(b, 1)

        def bar(fn):
            return fn

        c = bar(lambda x: x[0] ** 2)
        self._test_fn(c, 1)

        def egg(fn1, fn2):
            return fn1

        # this shouldn't convert to OCL b/c it has two lambdas on one line
        d = egg(lambda x: x[0] ** 2, lambda y: y[0] ** 3)
        try:
            self._test_fn(d, 1)
            assert False, (
                "This should fail because we don't support conversion"
                "to OCL with multiple lambda functions in a source line"
            )
        except NotImplementedError:
            pass


if __name__ == "__main__":
    unittest.main()
Esempio n. 3
0
    def test_one_short_segment_many_longer_dots(self):
        for ND in 2, 20, 100:
            self.check_from_shapes(0.5,
                                   0.6,
                                   0.7,
                                   A_shapes=[(2000, ii + 1)
                                             for ii in range(ND)],
                                   X_shapes=[(ii + 1, 1) for ii in range(ND)],
                                   A_js=[range(ND)],
                                   X_js=[range(ND)])


class TestManyDots(unittest.TestCase, ShapeCheckMixin):
    def check_from_shapes(self, *args, **kwargs):
        return check_from_shapes(plan_many_dots, *args, **kwargs)


class TestReduce(unittest.TestCase, ShapeCheckMixin):
    def check_from_shapes(self, *args, **kwargs):
        return check_from_shapes(plan_reduce, *args, **kwargs)


class TestRef(unittest.TestCase, ShapeCheckMixin):
    def check_from_shapes(self, *args, **kwargs):
        return check_from_shapes(plan_ref, *args, **kwargs)


if __name__ == '__main__':

    unittest.main()
Esempio n. 4
0
"""
Black-box testing of the sim_npy Simulator.

TestCase classes are added automatically from
nengo.tests.helpers.simulator_test_cases, but
you can still run individual test files like this:

    nosetests -sv test/test_sim_npy.py:TestSimulator.test_simple_direct_mode

"""

from nengo_ocl.tricky_imports import unittest
from nengo.tests.helpers import NengoTestLoader
from nengo.tests.helpers import load_nengo_tests
from nengo_ocl import sim_npy

from nengo.tests.test_simulator import TestSimulator, TestNonlinear

TestSimulator.Simulator = sim_npy.Simulator
TestNonlinear.Simulator = sim_npy.Simulator

load_tests = load_nengo_tests(sim_npy.Simulator)

if __name__ == '__main__':
    unittest.main(testLoader=NengoTestLoader(sim_npy.Simulator))
Esempio n. 5
0
you can still run individual test files like this:

$ python test/test_sim_ocl.py test_ensemble.TestEnsemble.test_lifrate

"""

from nengo_ocl.tricky_imports import unittest
from nengo.tests.helpers import NengoTestLoader
from nengo.tests.helpers import load_nengo_tests
from nengo_ocl import sim_ocl

import pyopencl as cl

ctx = cl.create_some_context()

def Ocl2Simulator(*args, **kwargs):
    kwargs['context'] = ctx
    return sim_ocl.Simulator(*args, **kwargs)

# -- see comments in test_sim_npy.py for why these two
#    classes are treated differently.
from nengo.tests.test_simulator import TestSimulator, TestNonlinear
TestSimulator.Simulator = staticmethod(Ocl2Simulator)
TestNonlinear.Simulator = staticmethod(Ocl2Simulator)

load_tests = load_nengo_tests(Ocl2Simulator)


if __name__ == '__main__':
   unittest.main(testLoader=NengoTestLoader(Ocl2Simulator))
Esempio n. 6
0
TestCase classes are added automatically from
nengo.tests.helpers.simulator_test_cases, but
you can still run individual test files like this:

    nosetests -sv test/test_sim_ocl.py:TestSimulator.test_simple_direct_mode

"""

from nengo_ocl.tricky_imports import unittest
from nengo.tests.helpers import NengoTestLoader
from nengo.tests.helpers import load_nengo_tests
from nengo_ocl import sim_ocl

import pyopencl as cl

ctx = cl.create_some_context()

def Ocl2Simulator(*args, **kwargs):
    kwargs['context'] = ctx
    return sim_ocl.Simulator(*args, **kwargs)

from nengo.tests.test_simulator import TestSimulator, TestNonlinear
TestSimulator.Simulator = staticmethod(Ocl2Simulator)
TestNonlinear.Simulator = staticmethod(Ocl2Simulator)

load_tests = load_nengo_tests(Ocl2Simulator)


if __name__ == '__main__':
   unittest.main(testLoader=NengoTestLoader(Ocl2Simulator))