[SciPy-Dev] Enhancements to scipy.spatial.cKDTree

Ralf Gommers ralf.gommers at googlemail.com
Sat Jul 14 07:17:52 EDT 2012


On Sat, Jul 14, 2012 at 7:54 AM, Sturla Molden <sturla at molden.no> wrote:

>
> I am more or less finished with cleaning up Patrick's cKDTree code.
>
> Here are the main changes I have made so far to Patrick's cKDTree
> rewrite/additions:
>
> - Integer sizes are correct for 32 and 64 bit (it was totally confused)
> and npy_intp are used consistently.
> - np.float64_t instead of double
> - All variables are properly declared (many were left undeclared).
> - All for loops with a range are Cython loops (none of Patrick's loops
> were correct...).
> - Python exceptions propagate correctly through cdef functions.
> - Memory leaks are prevented with try/finally.
> - MemoryError is raised on malloc or realloc failure (Cython handles
> "raise MemoryError" correctly).
> - PyArray_DATA is used for future compatibility with NumPy.
> - Made sure the common case of Euclidian distance is processed faster.
>
> I believe it should be more or less OK, but it needs testing before it's
> worthy of a pull request to SciPy master.
>
> The code is here:
>
> https://github.com/sturlamolden/scipy/blob/master/scipy/spatial/ckdtree.pyx
>

I took your edits and committed them as a diff to Patricks last commit.
Then I added a few style fixes:
https://github.com/rgommers/scipy/tree/fixes-sturla. The best way to get
this in would be for Patrick to add these commits to his branch so they
show up in his PR (after finding a bug, see below).

I did some testing (python 2.6, 32-bit, OS X 10.6), I get one test failure
with Sturla's edits. Patrick's branch given me no failures.

 ======================================================================
FAIL: test_kdtree.test_count_neighbors_compiled.test_multiple_radius
----------------------------------------------------------------------
Traceback (most recent call last):
  File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/nose-1.1.2-py2.6.egg/nose/case.py",
line 197, in runTest
    self.test(*self.arg)
  File "/Users/rgommers/Code/scipy/scipy/spatial/tests/test_kdtree.py",
line 496, in test_multiple_radius
    assert_equal(self.T1.count_neighbors(self.T2, r), result)
  File "/Users/rgommers/Code/numpy/numpy/testing/utils.py", line 313, in
assert_equal
    raise AssertionError(msg)
AssertionError:
Items are not equal:
 ACTUAL: 6
 DESIRED: 54

The actual and desired numbers change due to random numbers without a seed
being used, but it fails consistently. The missing seed is no real problem
here, because the code simply does the same twice; it only tests if the "r"
input to count_neighbors is correctly vectorized.

Ralf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20120714/89e68257/attachment.html>


More information about the SciPy-Dev mailing list