def test_writeread3(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)
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) b = a.copy() b.bitrandomswap(distance) c = sdm.thread_read(b) self.assertEqual(a.distance_to(c), 0) sdm.free()
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)
def h(): import sdm import sdm_utils #import numpy as NP a = b = arange (0,1000) sdm.initialize_from_file("/Users/AL/Desktop/mem10000_n1000_10000x_at_x.sdm") v = sdm.Bitstring() sdm.thread_write(v,v) print ("computing distances") #for i in range (0,999,250): #a = sdm_utils.critical_distance2(0, 10, 1, v) #b = sdm_utils.critical_distance2(0, 10, 1, v) heatmap (a,b)
def scan_for_distances(): import time, cPickle; sdm.initialize() v = sdm.Bitstring() for i in range (0,10,1): sdm.thread_write(v,v) import pylab for i in range (1000,51000,1000): print 'Computing distances for '+str(i)+' items registered' #add 1000 itens to memory mem_write_x_at_x(1000) a = sdm_utils.critical_distance2(0, 1000, 1, v, read=sdm.thread_read_chada) #get new distance values in a #save a cPickle.dump(a, open (str(i)+'10writes_Chada_Read.cPickle', 'wb')) print 'saved '+str(i)+'.cPickle'
def linhares_critical1(): #cd /Users/AL/Dropbox/0. AL Current Work/3. To Submit/Dr K/AL/python/ import sdm import sdm_utils import time start=time.clock() #sdm.initialize() sdm.initialize_from_file("/Users/AL/Desktop/mem45000_n1000_10000x_at_x.sdm") mem_write_x_at_x(5000) v = sdm.Bitstring() sdm.thread_write(v,v) print ("computing distances graph") print (time.clock()-start, "seconds") a = sdm_utils.critical_distance2(0, 1000, 1, v) print (time.clock()-start) print "saving file" sdm.save_to_file("/Users/AL/Desktop/mem50000_n1000_10000x_at_x.sdm") import pylab pylab.plot(a) pylab.show()
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()
def mem_write_x_at_random(count=10): for i in range (count): b=sdm.Bitstring() c=sdm.Bitstring() sdm.thread_write(b,c)
#!/usr/bin/env python import sdm import time print 'Initializing..', sdm.initialize() print 'done!' #print 'Running count..' #start = time.time() #for i in range(300): # a = sdm.Bitstring() # print i, sdm.thread_radius_count(a) #print 'Time:', time.time()-start print 'Running write..' start = time.time() for i in range(300): a = sdm.Bitstring() print i, sdm.thread_write(a, a) print 'Time:', time.time()-start
#!/usr/bin/env python import sdm import time print 'Initializing..', sdm.initialize() print 'done!' #print 'Running count..' #start = time.time() #for i in range(300): # a = sdm.Bitstring() # print i, sdm.thread_radius_count(a) #print 'Time:', time.time()-start print 'Running write..' start = time.time() for i in range(300): a = sdm.Bitstring() print i, sdm.thread_write(a, a) print 'Time:', time.time() - start
def mem_write_x_at_x(count=1): for i in range (count): b=sdm.Bitstring() sdm.thread_write(b,b)