def test_1(self): G = Group(5, 'V = I; I') Z = np.ones(5) DenseConnection(Z, G('I'), 1) DenseConnection(Z, G('I'), 2) G.run() assert np_equal(3 * np.ones(5), G('V'))
def test_1(self): G = Group(5, 'V = I; I') Z = np.ones(5) DenseConnection(Z, G('I'), 1) DenseConnection(Z, G('I'), 2) G.run() assert np_equal(3*np.ones(5),G('V'))
def test_Group_asarray(self): G = Group((5,5), dtype=[('U', float), ('V', int)], fill=1) A = G.asarray() assert A.shape == (5,5) assert A.dtype == np.dtype([('U', float), ('V', int)]) assert A['U'].sum() == 25 assert A['V'].sum() == 25
def test_Group_asarray(self): G = Group((5, 5), dtype=[('U', float), ('V', int)], fill=1) A = G.asarray() assert A.shape == (5, 5) assert A.dtype == np.dtype([('U', float), ('V', int)]) assert A['U'].sum() == 25 assert A['V'].sum() == 25
def test_2(self): net = Network() A = Group(1, "V = B['V']") B = Group(1, "V = A['V']") A[...] = 1 B[...] = 2 net.append(A) net.append(B) net.run(n=1) assert A['V'][0] == 2 and B['V'][0] == 1
class GroupReshape(unittest.TestCase): def setUp(self): self.Z = Group((5,5), dtype=[('x',float), ('y',float)]) def test_reshape(self): Z = self.Z.reshape((25,)) assert Z.x.base is self.Z.x assert Z.y.base is self.Z.y
class GroupSubGroup(unittest.TestCase): def setUp(self): self.Z = Group((5,5), dtype=[('x',float), ('y',float)]) def test_subgroup_1(self): S = self.Z.subgroup('x') assert S.base is self.Z def test_subgroup_2(self): S = self.Z('x') assert S.base is self.Z def test_subgroup_connections(self): src = np.ones((3,3)) dst = Group((3,3), '''U = A+B+V; V = C+D+Z; Z = E A;B;C;D;E''') SparseConnection(src,dst('A'),np.ones((1,1))) SparseConnection(src,dst('B'),np.ones((1,1))) SparseConnection(src,dst('C'),np.ones((1,1))) SparseConnection(src,dst('D'),np.ones((1,1))) SparseConnection(src,dst('E'),np.ones((1,1))) Z = dst('U') links = [] for c in Z.connections: links.append(c.target_name) assert 'A' in links assert 'B' in links assert 'C' in links assert 'D' in links assert 'E' in links
class GroupSubGroup(unittest.TestCase): def setUp(self): self.Z = Group((5, 5), dtype=[('x', float), ('y', float)]) def test_subgroup_1(self): S = self.Z.subgroup('x') assert S.base is self.Z def test_subgroup_2(self): S = self.Z('x') assert S.base is self.Z def test_subgroup_connections(self): src = np.ones((3, 3)) dst = Group((3, 3), '''U = A+B+V; V = C+D+Z; Z = E A;B;C;D;E''') SparseConnection(src, dst('A'), np.ones((1, 1))) SparseConnection(src, dst('B'), np.ones((1, 1))) SparseConnection(src, dst('C'), np.ones((1, 1))) SparseConnection(src, dst('D'), np.ones((1, 1))) SparseConnection(src, dst('E'), np.ones((1, 1))) Z = dst('U') links = [] for c in Z.connections: links.append(c.target_name) assert 'A' in links assert 'B' in links assert 'C' in links assert 'D' in links assert 'E' in links
class GroupReshape(unittest.TestCase): def setUp(self): self.Z = Group((5, 5), dtype=[('x', float), ('y', float)]) def test_reshape(self): Z = self.Z.reshape((25, )) assert Z.x.base is self.Z.x assert Z.y.base is self.Z.y
def test_3(self): net = Network(Clock(0.0, 1.0, 0.001)) src = Group((1, ), 'dV/dt=1') src[...] = 1 dst = Group((1, ), 'I') dst[...] = 0 kernel = np.ones(1) C = DenseConnection(src('V'), dst('I'), kernel) net.append(src) net.append(dst) V, I = [], [] @net.clock.every(0.1, order=-1) def do(t): V.append(src['V'][0]) I.append(dst['I'][0]) net.run(time=1.0, dt=0.1) assert np_equal( np.array(V), [1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0]) assert np_equal( np.array(I), [0.0, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9])
def test_subgroup_connections(self): src = np.ones((3, 3)) dst = Group((3, 3), '''U = A+B+V; V = C+D+Z; Z = E A;B;C;D;E''') SparseConnection(src, dst('A'), np.ones((1, 1))) SparseConnection(src, dst('B'), np.ones((1, 1))) SparseConnection(src, dst('C'), np.ones((1, 1))) SparseConnection(src, dst('D'), np.ones((1, 1))) SparseConnection(src, dst('E'), np.ones((1, 1))) Z = dst('U') links = [] for c in Z.connections: links.append(c.target_name) assert 'A' in links assert 'B' in links assert 'C' in links assert 'D' in links assert 'E' in links
def test_1(self): A = Group(1, "V = B['V']") A[...] = 1 B = Group(1, "V = A['V']") B[...] = 2 A.setup() B.setup() A.evaluate(dt=1, update=False) B.evaluate(dt=1, update=False) A.update() B.update() assert A['V'][0] == 2 and B['V'][0] == 1
def setUp(self): self.Z = Group((3, 3))
def setUp(self): self.Z = Group((5, 5), dtype=[('U', float), ('V', int)])
class GroupMask(unittest.TestCase): def setUp(self): self.Z = Group((3,3)) def test_mask_true(self): self.Z.mask = True self.Z[...] = 1 self.Z.setup() assert np_equal(self.Z.f0,np.ones((3,3))) def test_mask_1(self): self.Z.mask = 1 self.Z[...] = 1 self.Z.setup() assert np_equal(self.Z.f0,np.ones((3,3))) def test_mask_false(self): self.Z.mask = False self.Z[...] = 1 self.Z.setup() assert np_equal(self.Z.f0,np.zeros((3,3))) def test_mask_0(self): self.Z.mask = 0 self.Z[...] = 1 self.Z.setup() assert np_equal(self.Z.f0,np.zeros((3,3))) def test_mask_shape_0(self): self.Z.mask = np.zeros((3,3)) self.Z[...] = 1 self.Z.setup() assert np_equal(self.Z.f0,np.zeros((3,3))) def test_mask_shape_1(self): self.Z.mask = np.ones((3,3)) self.Z[...] = 1 self.Z.setup() assert np_equal(self.Z.f0,np.ones((3,3))) def test_mask_shape_2(self): mask = np.ones((3,3)) mask[1,1] = 0 self.Z.mask = mask self.Z[...] = 1 self.Z.setup() assert np_equal(self.Z.f0,mask)
def setUp(self): self.Z = Group((5, 5), dtype=[('x', float), ('y', float)])
def setUp(self): self.Z = Group((5, 5), dtype=[('U', np.double), ('V', np.int32)])
def setUp(self): self.Z = Group((5,5), dtype=[('x',float), ('y',float)])
def setUp(self): self.Z = Group()
def setUp(self): self.Z = Group((3, 5), fill=1.2)
class GroupMask(unittest.TestCase): def setUp(self): self.Z = Group((3, 3)) def test_mask_true(self): self.Z.mask = True self.Z[...] = 1 self.Z.setup() assert np_equal(self.Z.f0, np.ones((3, 3))) def test_mask_1(self): self.Z.mask = 1 self.Z[...] = 1 self.Z.setup() assert np_equal(self.Z.f0, np.ones((3, 3))) def test_mask_false(self): self.Z.mask = False self.Z[...] = 1 self.Z.setup() assert np_equal(self.Z.f0, np.zeros((3, 3))) def test_mask_0(self): self.Z.mask = 0 self.Z[...] = 1 self.Z.setup() assert np_equal(self.Z.f0, np.zeros((3, 3))) def test_mask_shape_0(self): self.Z.mask = np.zeros((3, 3)) self.Z[...] = 1 self.Z.setup() assert np_equal(self.Z.f0, np.zeros((3, 3))) def test_mask_shape_1(self): self.Z.mask = np.ones((3, 3)) self.Z[...] = 1 self.Z.setup() assert np_equal(self.Z.f0, np.ones((3, 3))) def test_mask_shape_2(self): mask = np.ones((3, 3)) mask[1, 1] = 0 self.Z.mask = mask self.Z[...] = 1 self.Z.setup() assert np_equal(self.Z.f0, mask)
def setUp(self): self.Z = Group((3,3))