Skip to main content

Numba-Kdtree - a fast KDTree implementation for numba

numba-kdtree provides a fast KDTree implementation for numba CPU functions based on scipys ckdtree.

The provided KDTree class is usable from both python and numba nopython functions calling directly into C code for performance critical sections utilizing a ctypes-like interface.

Once the KDTree class is compiled by numba, it is just as fast as the original scipy version.

Note: Currently only a basic subset of the original ckdtree interface is implemented.

Installation

Using pip

pip install numba-kdtree

From source

git clone https://github.com/mortacious/numba-kdtree.git
cd numba-kdtree
python -m pip install

Usage

import numpy as np
from numba_kdtree import KDTree
data = np.random.random(3_000_000).reshape(-1, 3)
kdtree = KDTree(data, leafsize=10)

# compute the nearest neighbors of the first 100 points
distances, indices = kdtree.query(data[:100], k=30)

# compute all points in a 0.5 radius around the first 100 points and return it's sorted indices
indices = kdtree.query_radius(data[:100], r=0.5, return_sorted=True)

The KDTree can be freely passed into a numba nopython function or constructed directly within it:

import numpy as np
from numba import njit
from numba_kdtree import KDTree

def numba_function_with_kdtree(kdtree, data):
    for i in range(data.shape[0]):
        distances, indices = kdtree.query(data[i], k=30)
        #<Use the computed neighbors
        
data = np.random.random(3_000_000).reshape(-1, 3)
kdtree = KDTree(data, leafsize=10)

numba_function_with_kdtree(kdtree)
import numpy as np
from numba import njit
from numba_kdtree import KDTree

def numba_function_constructing_kdtree(kdtree, data):
    kdtree = KDTree(data, leafsize=10)
    for i in range(data.shape[0]):
        distances, indices = kdtree.query(data[i], k=30)
        #<Use the computed neighbors
        
data = np.random.random(10_000_000).reshape(-1, 10)

numba_function_constructing_kdtree(data)

Additionally, the KDTree object can also be serialized via pickle:

import pickle

data = np.random.random(3_000_000).reshape(-1, 3)
kdtree = KDTree(data, leafsize=10) 

# pass the tree through pickle
# Note: This also copies the data array preserving it's integrity
serialized_tree = pickle.dumps(kdtree)

# The copied data array is now owned by the restored tree
restored_kdtree = pickle.loads(serialized_tree)

k = 10
# query the old tree
dd, ii, nn = kdtree.query_parallel(data[:100], k=k)

# query the new tree
dd_r, ii_r, nn_r = restored_kdtree.query_parallel(data[:100], k=k)

TODOs

  • Implement the full scipy ckdtree interface

Metadata

Release files for numba-kdtree 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for numba-kdtree 0.6.0
File Size Uploaded
numba_kdtree-0.6.0.tar.gz 31.7 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for numba-kdtree 0.6.0
File
numba_kdtree-0.6.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
numba_kdtree-0.6.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details
numba_kdtree-0.6.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
numba_kdtree-0.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
numba_kdtree-0.6.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
numba_kdtree-0.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
numba_kdtree-0.6.0-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
numba_kdtree-0.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
numba_kdtree-0.6.0-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
numba_kdtree-0.6.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details

Total release size: 2.7 MB

Release files / numba_kdtree-0.6.0.tar.gz

Download URL numba_kdtree-0.6.0.tar.gz
Size 31.7 kB
Tags Source
SHA-256 checksum
How to use checksums
53ba8bb82cc820b06b771018698468cad5a9356bc9d8bfd7df7332c1887bd251
BLAKE2b-256 checksum
How to use checksums
4862d99cb142b118144635fae85368e2e586c52e4ec9d49d38aaf2176cd0ddcf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release files / numba_kdtree-0.6.0-cp313-cp313-win_amd64.whl

Download URL numba_kdtree-0.6.0-cp313-cp313-win_amd64.whl
Size 46.2 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
ede5d08abaa069a4fe24059ef278118ae2afecaf23ab57fc6858cc334e81cf6c
BLAKE2b-256 checksum
How to use checksums
0248559aa77dbfbc738f3f2997f6452303a274294031f17577d19f7d1b134005
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.13

Release files / numba_kdtree-0.6.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL numba_kdtree-0.6.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 481.3 kB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
a2b31ffd14cfa5a50f3107ca6ecdac3bc1892cc3cc8208e053ff41aaf8687476
BLAKE2b-256 checksum
How to use checksums
3f052a24018fe50f4e593b6795eb8040728f013af37606326e1a7a42861dd823
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release files / numba_kdtree-0.6.0-cp312-cp312-win_amd64.whl

Download URL numba_kdtree-0.6.0-cp312-cp312-win_amd64.whl
Size 46.2 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
c3537d4bd35934ff9716e4161d715e2036ddaa03080a83ea22b8365a89860b3c
BLAKE2b-256 checksum
How to use checksums
a09c2f93702257f79fdb7dd3f3a55ac87bdd5a69d651df3829a835582b3ec4e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.13

Release files / numba_kdtree-0.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL numba_kdtree-0.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 481.3 kB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
93f8bb9cf5965b5b6a24e0b9f665df4837cfecf025d9e87d25b3d0b59e96a9fe
BLAKE2b-256 checksum
How to use checksums
3af357c096b81ba13cc6bdd4f2d2e827da7f1c41b25c3c53e76e97e402b611d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release files / numba_kdtree-0.6.0-cp311-cp311-win_amd64.whl

Download URL numba_kdtree-0.6.0-cp311-cp311-win_amd64.whl
Size 46.2 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
029f1cfa815fa5e58a8ee47f02c0926f3d54ef44ab50cb68884e5928b22a1e63
BLAKE2b-256 checksum
How to use checksums
da25902e307bff7faa716a59eda062a861173428df02989b640adbea6a838c25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.13

Release files / numba_kdtree-0.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL numba_kdtree-0.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 481.1 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
4fe41e287392a901b90c8ab341cd21ff6285571f1175a368860a966a20b425f3
BLAKE2b-256 checksum
How to use checksums
426dc2d892b8fc5f74603bb467330652983af5269c0d4d8f0b0ec57a1710a8d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release files / numba_kdtree-0.6.0-cp310-cp310-win_amd64.whl

Download URL numba_kdtree-0.6.0-cp310-cp310-win_amd64.whl
Size 46.2 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
49b7d13f92d859e022c06c91ab38c04c6bba1ad891aaaa1646199600ccb57913
BLAKE2b-256 checksum
How to use checksums
a20f92deda143a75f9ace20ab435dfdc22360cdc4aeb8fa892351f6370515336
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.13

Release files / numba_kdtree-0.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL numba_kdtree-0.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 481.1 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
b2b62bb23c0db17c908e5bf1968b71340411ef062d9e961bdc58f20fe57572c9
BLAKE2b-256 checksum
How to use checksums
7ce053604ec230c656e50971260c5ee7836082219b8abdfd99974c1d60dff9a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release files / numba_kdtree-0.6.0-cp39-cp39-win_amd64.whl

Download URL numba_kdtree-0.6.0-cp39-cp39-win_amd64.whl
Size 46.2 kB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
1f7c221f502fb06016e3a76c49a4243f6426e93f289eaba805f62e9151b331c0
BLAKE2b-256 checksum
How to use checksums
f3c8d2411728e4cc7373ff2e8fe9fd10009901f9b499b9181a4b17ccf1bffc91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.13

Release files / numba_kdtree-0.6.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL numba_kdtree-0.6.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 481.1 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
a668a123a552bd8cbd4d31c57b149c5ba9721247736e65dde02c731164e9a455
BLAKE2b-256 checksum
How to use checksums
01849aeff3848f2ab9e65c07701ae1d48d2d377dd7f31508d770b714276c9284
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release history Release notifications | RSS feed

This release

0.6.0 This release

11 release files

0.4.0

11 release files

0.3.0

11 release files

0.2.2

11 release files

0.2.1

1 release file

0.2.0

1 release file

0.1.8

11 release files

0.1.7

8 release files

0.1.6

8 release files

0.1.5

5 release files

0.1.4

9 release files

0.1.3

9 release files

0.1.2

9 release files

0.1.1

9 release files

0.1.0

5 release files

0.0.2

5 release files

0.0.1

5 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page