~mrol-dev/mrol/trunk

« back to all changes in this revision

Viewing changes to test/speed_test.py

  • Committer: Vikas Dhiman
  • Date: 2012-11-14 00:20:26 UTC
  • Revision ID: vikasdhi@buffalo.du-20121114002026-e4rbu85n6ekroafk
Removed unnecessary term from compile.sh

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
        self.npts = 100000
29
29
        self.high = 50
30
30
        self.M = np.random.randint(0, self.high, (self.mpts, 3)).astype(np.int16)
31
 
        self.P = np.zeros((self.npts, 4), dtype=np.int16)
32
 
        self.P[:, :3] = np.random.randint(0, self.high, (self.npts, 3)).astype(np.int16)
 
31
        self.P = np.random.randint(0, self.high, (self.npts, 3)).astype(np.int16)
33
32
        
34
33
        self.testpose = (-2., 42., 80., 0.2, 0.1, 2.6)
35
34
        self.testposeinv = poseutil.inverse(self.testpose)
36
 
        self.Pxformed = poseutil.transformPoints(self.P[:, :3], self.testpose)[0]
 
35
        self.Pxformed = poseutil.transformPoints(self.P, self.testpose)[0]
37
36
        
38
37
        self.ol = occupiedlist.OccupiedList(self.resolution, use_bloom=False)
39
38
        self.ol.add_points(self.M)
48
47
        self.maparray[self.M[:, 0], self.M[:, 1], self.M[:, 2]] = True
49
48
 
50
49
        # set up packed arrays map
51
 
        ids = np.zeros((len(self.M), 4), dtype=np.int16)
52
 
        ids[:, :3] = self.M
53
 
        occupiedlist._pack(ids)
 
50
        ids = occupiedlist._pack(self.M)
54
51
        self.mapvoxels_int16 = dict.fromkeys(ids, 1)
55
52
        self.mapset = set(ids)
56
53
        #self.mapvoxels_int16 = collections.defaultdict(int)
59
56
 
60
57
        # bloom map
61
58
        self.bloom = occupiedlist.BloomFilter(self.mpts)
62
 
        self.bloom.add_voxel_ids(ids)
 
59
        self.bloom.add_voxel_ids(occupiedlist._pack(self.M))
63
60
 
64
61
        # dictionary of dictionaries
65
62
        #D = dict.fromkeys(self.mpts[:,0], dict())
102
99
        return sum(dists < 1)
103
100
 
104
101
    def bench_lookup_bloom(self):
105
 
        occupiedlist._pack(self.P)
106
 
        overlaps = self.bloom.contains(self.P)
 
102
        #PV = occupiedlist.pointstovoxels(self.P, 1)
 
103
        #ids = occupiedlist._pack(PV)
 
104
        ids = occupiedlist._pack(self.P)
 
105
        overlaps = self.bloom.contains(ids)
 
106
 
 
107
        #return len(overlap)
107
108
        return np.sum(overlaps)
108
109
 
109
110
    def bench_lookup_dense_array(self):
112
113
    def bench_lookup_set_intersection(self):
113
114
        '''If many points fall in the same voxel this will return only overlap 
114
115
        of one for all those points.'''
115
 
        occupiedlist._pack(self.P)
116
 
        overlap = self.mapset.intersection(self.P)
 
116
        Pset = occupiedlist._pack(self.P)
 
117
        overlap = self.mapset.intersection(Pset)
117
118
        return len(overlap)
118
119
 
119
120
    def bench_lookup_hashtable(self):
120
 
        occupiedlist._pack(self.P)
121
 
        overlap = sum(ID in self.mapvoxels_int16 for ID in self.P)
 
121
        ids = occupiedlist._pack(self.P)
 
122
        overlap = sum(ID in self.mapvoxels_int16 for ID in ids)
122
123
        return overlap
123
124
 
124
125
    def bench_rotate_translate_quantise(self):
150
151
        funcs = dir(self)
151
152
        funcs = [getattr(self, func) for func in funcs if func.startswith('bench_')]
152
153
 
153
 
        self.setUp()
154
154
        expected_overlap = self.bench_lookup_dense_array()
155
155
        overlaps = []
156
156
        results = []
162
162
 
163
163
            exec_times = []
164
164
            for i in range(runs):
165
 
                print 'Setting up', name, '...',
166
 
                self.setUp() # rerun setup each time
167
 
                print 'Running'
168
165
                start = time.time()
169
166
                if profile:
170
167
                    cProfile.runctx('func()', globals(), locals(), 'speed_test.profile')
204
201
 
205
202
if __name__ == '__main__':
206
203
    st = SpeedTest()
 
204
    st.setUp()
207
205
    st.test_map_query()