Esempio n. 1
0
def sample_radius(rounds=1, verbose=0):
    if verbose > 0:
        print 'Initializing SDM'
    sdm.initialize()
    dimension = sdm.get_dimension()
    v = []
    for i in xrange(rounds):
        if verbose > 0:
            print 'Round #%d' % (i+1)
        addr = Bitstring()
        
        dist = sdm.distance(addr)

        if verbose > 0:
            print '  Processing results'
        w = [0]*(dimension+1)
        for d in dist:
            w[d] += 1
        u = [0]*(dimension+1)
        for d, n in enumerate(w):
            for j in range(d, dimension+1):
                u[j] += n
        v.append(u)
    sdm.free()
    return v
Esempio n. 2
0
 def test_mean_distance(self, qty=10):
     sdm.initialize()
     for i in range(qty):
         a = Bitstring()
         arr = array(sdm.thread_distance(a))
         self.assertTrue(abs(arr.mean()-500) <= 1.5)
     sdm.free()
Esempio n. 3
0
 def test_initialize_free(self, qty=5):
     m0 = self._memused()
     for i in range(qty):
         sdm.initialize()
         sdm.free()
     m1 = self._memused()
     self.assertTrue(m1 < 40000)
Esempio n. 4
0
 def test_mean_distance(self, qty=10):
     sdm.initialize()
     for i in range(qty):
         a = Bitstring()
         arr = array(sdm.thread_distance(a))
         self.assertTrue(abs(arr.mean() - 500) <= 1.5)
     sdm.free()
Esempio n. 5
0
def sample_radius(rounds=1, verbose=0):
    if verbose > 0:
        print 'Initializing SDM'
    sdm.initialize()
    dimension = sdm.get_dimension()
    v = []
    for i in xrange(rounds):
        if verbose > 0:
            print 'Round #%d' % (i + 1)
        addr = Bitstring()

        dist = sdm.distance(addr)

        if verbose > 0:
            print '  Processing results'
        w = [0] * (dimension + 1)
        for d in dist:
            w[d] += 1
        u = [0] * (dimension + 1)
        for d, n in enumerate(w):
            for j in range(d, dimension + 1):
                u[j] += n
        v.append(u)
    sdm.free()
    return v
Esempio n. 6
0
 def test_distance(self, qty=10):
     sdm.initialize()
     for i in range(qty):
         a = Bitstring()
         d1 = sdm.distance(a)
         d2 = sdm.thread_distance(a)
         self.assertEqual(d1, d2)
     sdm.free()
Esempio n. 7
0
def sample():
    print 'Initializing SDM'
    sdm.initialize()
    dimension = sdm.get_dimension()
    addr = Bitstring()
    dist = sdm.distance(addr)
    sdm.free()
    return dist
Esempio n. 8
0
 def test_writeread(self, qty=10):
     sdm.initialize()
     for i in range(qty):
         a = Bitstring()
         sdm.thread_write(a, a)
         b = sdm.thread_read(a)
         self.assertEqual(a.distance_to(b), 0)
     sdm.free()
Esempio n. 9
0
 def test_radius_count(self, qty=10):
     sdm.initialize()
     for i in range(qty):
         a = Bitstring()
         cnt1 = sdm.radius_count(a)
         cnt2 = sdm.thread_radius_count(a)
         self.assertEqual(cnt1, cnt2)
     sdm.free()
Esempio n. 10
0
def sample():
    print 'Initializing SDM'
    sdm.initialize()
    dimension = sdm.get_dimension()
    addr = Bitstring()
    dist = sdm.distance(addr)
    sdm.free()
    return dist
Esempio n. 11
0
 def test_writeread(self, qty=10):
     sdm.initialize()
     for i in range(qty):
         a = Bitstring()
         sdm.thread_write(a, a)
         b = sdm.thread_read(a)
         self.assertEqual(a.distance_to(b), 0)
     sdm.free()
Esempio n. 12
0
 def test_radius_count_intersect(self, qty=10):
     sdm.initialize()
     for i in range(qty):
         a = Bitstring()
         b = Bitstring()
         cnt1 = sdm.thread_radius_count_intersect(a, b)
         cnt2 = sdm.thread_radius_count_intersect(a, b)
         self.assertEqual(cnt1, cnt2)
     sdm.free()
Esempio n. 13
0
 def test_writereadnear(self, distance=50, qty=10):
     sdm.initialize()
     for i in range(qty):
         a = Bitstring()
         sdm.thread_write(a, a)
         b = a.copy()
         b.bitrandomswap(distance)
         c = sdm.thread_read(b)
         self.assertEqual(a.distance_to(c), 0)
     sdm.free()
Esempio n. 14
0
 def test_writereadnear(self, distance=50, qty=10):
     sdm.initialize()
     for i in range(qty):
         a = Bitstring()
         sdm.thread_write(a, a)
         b = a.copy()
         b.bitrandomswap(distance)
         c = sdm.thread_read(b)
         self.assertEqual(a.distance_to(c), 0)
     sdm.free()
Esempio n. 15
0
 def test_saveload(self):
     a = Bitstring()
     #sdm.initialize()
     sdm.thread_write(a, a)
     self.assertEqual(a.distance_to(sdm.thread_read(a)), 0)
     self.assertEqual(sdm.save_to_file('_test.sdm'), 0)
     sdm.free()
     sdm.initialize()
     self.assertTrue(a.distance_to(sdm.read(a)) > 0)
     sdm.free()
     self.assertEqual(sdm.initialize_from_file('_test.sdm'), 0)
     self.assertEqual(a.distance_to(sdm.thread_read(a)), 0)
Esempio n. 16
0
def scan_for_distances(numwrites=1):
    import time, cPickle;

    #Configure execution
    numwrites_string = '_x_at_x_'+str(numwrites)+'_writes'

    sdm.initialize()
    v = sdm.Bitstring()
    for i in range(numwrites):
        sdm.thread_write(v,v)
    for i in range (1000,2000,1000):
        print 'Registering '+str(i)+' new items in SDM'
        #add 1000 itens to memory
        mem_write_x_at_x(1000)
        print 'Computing the distances to these items'
        a = sdm_utils.critical_distance2(0, sdm.get_dimension(), 1, v, iterated_reading=6, read=sdm.thread_read_cubed,debug=0)
        #save new distance values in a
        picklename = 'N=256_iter_read=2_'+str(i)+'saved items'+numwrites_string+'_DrK_cubed.cPickle'
        cPickle.dump(a, open (picklename, 'wb'))
        print 'saved '+picklename
    sdm.free()
Esempio n. 17
0
 def tearDown(self):
     sdm.free()
Esempio n. 18
0
>>>>>>> FETCH_HEAD

    def test_mean_distance(self, qty=10):
        sdm.initialize()
        for i in range(qty):
            a = Bitstring()
<<<<<<< HEAD
            arr = array(sdm.thread_distance(a))
=======
            arr = array(sdm.distance(a))
<<<<<<< HEAD
>>>>>>> FETCH_HEAD
=======
>>>>>>> FETCH_HEAD
            self.assertTrue(abs(arr.mean()-500) <= 1.5)
        sdm.free()

    def test_writeread(self, qty=10):
        sdm.initialize()
        for i in range(qty):
            a = Bitstring()
            sdm.thread_write(a, a)
            b = sdm.thread_read(a)
            self.assertEqual(a.distance_to(b), 0)
        sdm.free()

    def test_writereadnear(self, distance=50, qty=10):
        sdm.initialize()
        for i in range(qty):
            a = Bitstring()
            sdm.thread_write(a, a)