def test_connect_with_scalar_weights_and_delays(self): connections = numpy.array([ [0, 1, 1, 0], [1, 1, 0, 1], [0, 0, 1, 0], ]) C = connectors.ArrayConnector(connections, safe=False) syn = sim.StaticSynapse(weight=5.0, delay=0.5) prj = sim.Projection(self.p1, self.p2, C, syn) self.assertEqual(prj.get(["weight", "delay"], format='list', gather=False), # use gather False because we are faking the MPI [(1, 0, 5.0, 0.5), (0, 2, 5.0, 0.5), (2, 2, 5.0, 0.5)])
def test_connect_with_random_weights_parallel_safe(self): rd_w = random.RandomDistribution(rng=MockRNG(delta=1.0, parallel_safe=True)) rd_d = random.RandomDistribution(rng=MockRNG(start=1.0, delta=0.1, parallel_safe=True)) syn = sim.StaticSynapse(weight=rd_w, delay=rd_d) connections = numpy.array([ [0, 1, 1, 0], [1, 1, 0, 1], [0, 0, 1, 0], ]) C = connectors.ArrayConnector(connections, safe=False) prj = sim.Projection(self.p1, self.p2, C, syn) self.assertEqual(prj.get(["weight", "delay"], format='list', gather=False), # use gather False because we are faking the MPI [(1, 0, 0.0, 1.0), (0, 2, 3.0, 1.3), (2, 2, 4.0, 1.4000000000000001)]) # better to do an "almost-equal" check
def test_connect_with_scalar_weights_and_delays(self, sim=sim): connections = np.array([ [0, 1, 1, 0], [1, 1, 0, 1], [0, 0, 1, 0], ], dtype=bool) C = connectors.ArrayConnector(connections, safe=False) syn = sim.StaticSynapse(weight=5.0, delay=0.5) prj = sim.Projection(self.p1, self.p2, C, syn) self.assertEqual(prj.get(["weight", "delay"], format='list'), [(1, 0, 5.0, 0.5), (0, 1, 5.0, 0.5), (1, 1, 5.0, 0.5), (0, 2, 5.0, 0.5), (2, 2, 5.0, 0.5), (1, 3, 5.0, 0.5)])
def test_connect_with_random_weights_parallel_safe(self, sim=sim): rd_w = random.RandomDistribution( 'uniform', (0, 1), rng=MockRNG(delta=1.0, parallel_safe=True)) rd_d = random.RandomDistribution('uniform', (0, 1), rng=MockRNG( start=1.0, delta=0.1, parallel_safe=True)) syn = sim.StaticSynapse(weight=rd_w, delay=rd_d) connections = np.array([ [0, 1, 1, 0], [1, 1, 0, 1], [0, 0, 1, 0], ], dtype=bool) C = connectors.ArrayConnector(connections, safe=False) prj = sim.Projection(self.p1, self.p2, C, syn) rec = prj.get(["weight", "delay"], format='list') assert_array_almost_equal([tuple(r) for r in rec], [(1, 0, 0.0, 1.0), (0, 1, 1.0, 1.1), (1, 1, 2.0, 1.2), (0, 2, 3.0, 1.3), (2, 2, 4.0, 1.4), (1, 3, 5.0, 1.5)])