Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Finished cKDTree benchmark

  • Loading branch information...
commit 6d4fd65ba627bd6b3f3efb93921f15344442e535 1 parent 40b2a47
@patvarilly authored
Showing with 93 additions and 0 deletions.
  1. +93 −0 scipy/spatial/benchmarks/bench_ckdtree.py
View
93 scipy/spatial/benchmarks/bench_ckdtree.py
@@ -84,5 +84,98 @@ def bench_query_ball_point(self):
sys.stdout.flush()
print ''
+
+class TestQueryPairs(TestCase):
+ def bench_query_pairs(self):
+ print
+ print ' Query pairs kd-tree'
+ print '=================================================================='
+ print ' dim | # points | probe radius | KDTree | cKDTree | flat cKDTree'
+
+ for (m, n, repeat) in [(3,1000,30),
+ (8,1000,30),
+ (16,1000,30)]:
+ for probe_radius in (0.2, 0.5):
+ print '%4s | %8s | %11.1f ' % (m, n, probe_radius),
+ sys.stdout.flush()
+
+ data = np.concatenate((np.random.randn(n//2,m),
+ np.random.randn(n-n//2,m)+np.ones(m)))
+
+ T1 = KDTree(data)
+ T2 = cKDTree(data)
+ T3 = cKDTree(data,leafsize=n)
+ print '| %6.3fs ' % (measure('T1.query_pairs(probe_radius)', 1) / 1),
+ sys.stdout.flush()
+ print '| %6.3fs' % (measure('T2.query_pairs(probe_radius)', repeat) / repeat),
+ sys.stdout.flush()
+ print '| %6.3fs' % (measure('T3.query_pairs(probe_radius)', repeat) / repeat),
+ sys.stdout.flush()
+ print ''
+
+
+class TestSparseDistanceMatrix(TestCase):
+ def bench_sparse_distance_matrix(self):
+ print
+ print ' Sparse distance matrix kd-tree'
+ print '===================================================================='
+ print ' dim | # points T1 | # points T2 | probe radius | KDTree | cKDTree'
+
+ for (m, n1, n2, repeat) in [(3,1000,1000,30),
+ (8,1000,1000,30),
+ (16,1000,1000,30)]:
+
+ data1 = np.concatenate((np.random.randn(n1//2,m),
+ np.random.randn(n1-n1//2,m)+np.ones(m)))
+ data2 = np.concatenate((np.random.randn(n2//2,m),
+ np.random.randn(n2-n2//2,m)+np.ones(m)))
+
+ T1 = KDTree(data1)
+ T2 = KDTree(data2)
+ cT1 = cKDTree(data1)
+ cT2 = cKDTree(data2)
+
+ for probe_radius in (0.2, 0.5):
+ print '%4s | %11s | %11s | %11.1f ' % (m, n1, n2, probe_radius),
+ sys.stdout.flush()
+
+ print '| %6.3fs ' % (measure('T1.sparse_distance_matrix(T2, probe_radius)', 1) / 1),
+ sys.stdout.flush()
+ print '| %6.3fs ' % (measure('cT1.sparse_distance_matrix(cT2, probe_radius)', repeat) / repeat),
+ sys.stdout.flush()
+ print ''
+
+
+class TestCountNeighbors(TestCase):
+ def bench_count_neighbors(self):
+ print
+ print ' Count neighbors kd-tree'
+ print '===================================================================='
+ print ' dim | # points T1 | # points T2 | probe radius | KDTree | cKDTree'
+
+ for (m, n1, n2, repeat) in [(3,1000,1000,30),
+ (8,1000,1000,30),
+ (16,1000,1000,30)]:
+
+ data1 = np.concatenate((np.random.randn(n1//2,m),
+ np.random.randn(n1-n1//2,m)+np.ones(m)))
+ data2 = np.concatenate((np.random.randn(n2//2,m),
+ np.random.randn(n2-n2//2,m)+np.ones(m)))
+
+ T1 = KDTree(data1)
+ T2 = KDTree(data2)
+ cT1 = cKDTree(data1)
+ cT2 = cKDTree(data2)
+
+ for probe_radius in (0.2, 0.5):
+ print '%4s | %11s | %11s | %11.1f ' % (m, n1, n2, probe_radius),
+ sys.stdout.flush()
+
+ print '| %6.3fs ' % (measure('T1.count_neighbors(T2, probe_radius)', 1) / 1),
+ sys.stdout.flush()
+ print '| %6.3fs ' % (measure('cT1.count_neighbors(cT2, probe_radius)', repeat) / repeat),
+ sys.stdout.flush()
+ print ''
+
if __name__ == "__main__":
run_module_suite()

0 comments on commit 6d4fd65

Please sign in to comment.
Something went wrong with that request. Please try again.