scipy/scipy — pull request #3841 by argriffing (2014-07-30 01:38:19+00:00)
Title: WIP: several x ckdtree query_pairs speedup

Instead of making a set of pairs and converting it to an ndarray, make the array directly.

But this is a horrible hack so comments or suggestions are appreciated!

```python
from __future__ import print_function
from time import time as perf_counter
import sys
import numpy as np
import scipy
from scipy.spatial import cKDTree

print(sys.version)
print('numpy version:', np.__version__)
print('scipy version:', scipy.__version__)

npoints = 1000000
print('npoints:', npoints)

print('making some points and building the tree...')
t0 = perf_counter()
np.random.seed(0)
data = np.random.random((npoints, 2))
tree = cKDTree(data)
t1 = perf_counter()
print(t1 - t0)

pairs = tree.query_pairs(.002)
print(len(pairs))
t2 = perf_counter()
print(t2 - t1)

pairs_b = np.array(list(pairs))
t3 = perf_counter()
print(t3 - t2)

pairs_c = np.fromiter(pairs, dtype=np.dtype([("a", int), ("b", int)]))
t4 = perf_counter()
print(t4 - t3)

pairs_d = tree.query_pairs_array(.002)
print(pairs_d.shape)
t5 = perf_counter()
print(t5 - t4)

print('checking that the sets are the same...')
other_pairs = set(tuple(row) for row in pairs_d)
diff_a = pairs - other_pairs
diff_b = other_pairs - pairs
if pairs == other_pairs:
print('they are the same!')
else:
print('they are different :( :( :(')

print('garbage collecting...')
```

```
2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2]
numpy version: 1.10.0.dev-2ad5388
scipy version: 0.15.0.dev-c2375ee
npoints: 1000000
making some points and building the tree...
0.232572078705
6271234
2.88389992714
5.57017302513
2.22471213341
(6271234, 2)
1.0884988308
checking that the sets are the same...
they are the same!
garbage collecting...
```