Example #1
0
def test_math_functions(func, needs_c99_support):
    '''
    Test that math functions give the same result, regardless of whether used
    directly or in generated Python or C++ code.
    '''
    if not get_device() == RuntimeDevice or prefs.codegen.target != 'numpy':
        if needs_c99_support and not compiler_supports_c99():
            pytest.skip('Support for function "{}" needs a compiler with C99 '
                        'support.')
    test_array = np.array([-1, -0.5, 0, 0.5, 1])

    with catch_logs() as _:  # Let's suppress warnings about illegal values
        # Calculate the result directly
        numpy_result = func(test_array)

        # Calculate the result in a somewhat complicated way by using a
        # subexpression in a NeuronGroup
        if func.__name__ == 'absolute':
            # we want to use the name abs instead of absolute
            func_name = 'abs'
        else:
            func_name = func.__name__
        G = NeuronGroup(
            len(test_array), '''func = {func}(variable) : 1
                           variable : 1'''.format(func=func_name))
        G.variable = test_array
        mon = StateMonitor(G, 'func', record=True)
        net = Network(G, mon)
        net.run(defaultclock.dt)

        assert_allclose(
            numpy_result,
            mon.func_.flatten(),
            err_msg='Function %s did not return the correct values' %
            func.__name__)
Example #2
0
def test_compiler_c99():
    # On a user's computer, we do not know whether the compiler actually
    # has C99 support, so we just check whether the test does not raise an
    # error
    c99_support = compiler_supports_c99()
    # On our Azure test server we know that the compilers support C99
    if os.environ.get('AGENT_OS', ''):
        assert c99_support
Example #3
0
def test_compiler_c99():
    # On a user's computer, we do not know whether the compiler actually
    # has C99 support, so we just check whether the test does not raise an
    # error

    # The compiler check previously created spurious '-.o' files (see #1348)
    if os.path.exists('-.o'):
        os.remove('-.o')
    c99_support = compiler_supports_c99()
    assert not os.path.exists('-.o')
    # On our Azure test server we know that the compilers support C99
    if os.environ.get('AGENT_OS', ''):
        assert c99_support