strawlab/python-pcl — pull request #35 by larsmans (2014-07-08 15:12:54+00:00)
Title: optimize k-NN searches (no Python code in loops)

Body of `_nearest_k` is entirely white in `cython -a` output.

Performance:

```python
>>> import numpy as np
>>> import pcl
>>> rng = np.random.RandomState(42)
>>> p1 = pcl.PointCloud(rng.randn(100000, 3).astype(np.float32))
>>> p2 = pcl.PointCloud(rng.randn(4000, 3).astype(np.float32))
>>> kd = pcl.KdTreeFLANN(p1)
>>> %timeit kd.nearest_k_search_for_cloud(p2)
100 loops, best of 3: 14.2 ms per loop
>>> %timeit kd.nearest_k_search_for_cloud(p2, 3)
100 loops, best of 3: 15.4 ms per loop
>>> %timeit kd.nearest_k_search_for_cloud(p2, 30)
10 loops, best of 3: 28.3 ms per loop
```

Previously:

```python
>>> %timeit kd.nearest_k_search_for_cloud(p2)
10 loops, best of 3: 42.9 ms per loop
>>> %timeit kd.nearest_k_search_for_cloud(p2, 3)
10 loops, best of 3: 43.5 ms per loop
>>> %timeit kd.nearest_k_search_for_cloud(p2, 30)
10 loops, best of 3: 57.5 ms per loop
```