~mrol-dev/mrol/trunk

« back to all changes in this revision

Viewing changes to test/speed_test.py

  • Committer: Vikas Dhiman
  • Date: 2012-11-16 19:59:46 UTC
  • Revision ID: vikasdhi@buffalo.edu-20121116195946-fwfdqevt3h3eqoyg
Manually added julians changes after merge failed. "Added function to save point cloud in the .ply format"; "Got speed_test working again after API changes.

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