예제 #1
0
 def test_really_simple0(self):
     A = numpy.zeros((3, ))
     B = numpy.zeros((3, 5))
     D = DistanceMatrix(B, Space())
     D.set_source(A)
     assert_arrays_almost_equal(D.as_array(), numpy.zeros((5, ), float),
                                1e-12)
예제 #2
0
    def __init__(self,
                 projection,
                 weights=0.0,
                 delays=None,
                 allow_self_connections=True,
                 space=Space(),
                 safe=True):

        Connector.__init__(self, weights, delays, space, safe)
        if isinstance(projection.rng, random.NativeRNG):
            raise Exception("Use of NativeRNG not implemented.")
        else:
            self.rng = projection.rng

        self.N = projection.pre.size
        idx = numpy.arange(self.N * rank(), self.N * (rank() + 1))
        self.M = num_processes() * self.N
        self.local = numpy.ones(self.N, bool)
        self.local_long = numpy.zeros(self.M, bool)
        self.local_long[idx] = True
        self.weights_generator = WeightGenerator(weights, self.local_long,
                                                 projection, safe)
        self.delays_generator = DelayGenerator(delays, self.local_long, safe)
        self.probas_generator = ProbaGenerator(
            random.RandomDistribution('uniform', (0, 1), rng=self.rng),
            self.local_long)
        self.distance_matrix = DistanceMatrix(projection.pre.positions,
                                              self.space, self.local)
        self.projection = projection
        self.candidates = projection.pre.all_cells
        self.allow_self_connections = allow_self_connections
예제 #3
0
 def test_extract_with_simple_d_expr(self):
     B = numpy.zeros((3, 5))
     dist = DistanceMatrix(B, Space())
     gen = ConnectionAttributeGenerator(source="d*d",
                                        local_mask=None,
                                        safe=False)
     dist.set_source(numpy.zeros((3, )))
     assert_arrays_almost_equal(gen.extract(5, dist, sub_mask=None),
                                numpy.zeros((5, ), float), 1e-12)
     dist.set_source(numpy.array([1, 0, 0]))
     assert_arrays_almost_equal(gen.extract(5, dist, sub_mask=None),
                                numpy.ones((5, ), float), 1e-12)
     dist.set_source(numpy.array([2, 0, 0]))
     assert_arrays_almost_equal(gen.extract(5, dist, sub_mask=None),
                                4 * numpy.ones((5, ), float), 1e-12)