Benjamin
Benjamin

Reputation: 11860

Difference between scipy.spatial.KDTree and scipy.spatial.cKDTree

What is the difference between these two algorithms?

Upvotes: 50

Views: 14607

Answers (4)

agf
agf

Reputation: 176930

From SciPy 1.6 on, cKDTree and KDTree are identical, and you should prefer KDTree if you aren't worried about pre-1.6 compatibility.

Before SciPy 1.6, cKDTree was a subset of KDTree, implemented in C++ wrapped in Cython, so therefore faster.

Upvotes: 57

divenex
divenex

Reputation: 17236

Update 2022: cKDTree is deprecated

The current (v1.8) SciPy documentation states that scipy.spatial.cKDTree is now deprecated and was replaced by the functionally-identical scipy.spatial.KDTree.

Here is the note:

cKDTree is functionally identical to KDTree. Prior to SciPy v1.6.0, cKDTree had better performance and slightly different functionality but now the two names exist only for backward-compatibility reasons. If compatibility with SciPy < 1.6 is not a concern, prefer KDTree.

Upvotes: 6

Atsushi Sakai
Atsushi Sakai

Reputation: 1014

Currently, both have almost same APIs, and cKDTree is faster than KDTree. So, In the near future, SciPy developers are planning to remove KDTree, and cKDTree will be renamed to KDTree in a backwards-compatible way.

Ref: Detailed SciPy Roadmap — SciPy v1.6.0.dev Reference Guide https://docs.scipy.org/doc/scipy/reference/roadmap-detailed.html#spatial

Upvotes: 2

Newmu
Newmu

Reputation: 1960

In a use case (5D nearest neighbor look ups in a KDTree with approximately 100K points) cKDTree is around 12x faster than KDTree.

Upvotes: 17

Related Questions