def test_semantics_floor_division(): # See Brian2 github issues #815 and #661 G = NeuronGroup(11, '''a : integer b : integer x : 1 y : 1 fvalue : 1 ivalue : integer''', dtype={ 'a': np.int32, 'b': np.int64, 'x': np.float, 'y': np.double }) int_values = np.arange(-5, 6) float_values = np.arange(-5.0, 6.0, dtype=np.double) G.ivalue = int_values G.fvalue = float_values with catch_logs() as l: G.run_regularly(''' a = ivalue//3 b = ivalue//3 x = fvalue//3 y = fvalue//3 ''') run(defaultclock.dt) # XXX: brian2 test adapted here for 1 warning assert len(l) == 1 assert_equal(G.a[:], int_values // 3) assert_equal(G.b[:], int_values // 3) assert_allclose(G.x[:], float_values // 3) assert_allclose(G.y[:], float_values // 3)
def test_aliasing_in_statements(): ''' Test an issue around variables aliasing other variables (#259) ''' if prefs.codegen.target != 'numpy': raise SkipTest('numpy-only test') runner_code = '''x_1 = x_0 x_0 = -1''' g = NeuronGroup(1, model='''x_0 : 1 x_1 : 1 ''') g.run_regularly(runner_code) net = Network(g) net.run(defaultclock.dt) assert_equal(g.x_0_[:], np.array([-1])) assert_equal(g.x_1_[:], np.array([0]))