A kdtree implementation for numba.
Project description
Numba-kdtree
A simple KD-Tree for numba using a ctypes wrapper around the scipy ckdtree
implementation.
The KD-Tree is usable in both python and numba nopython functions.
Once the query functions are compiled by numba, the implementation 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 setup.py 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)
# query the nearest neighbors of the first 100 points
distances, indices = kdtree.query(data[:100], k=30)
# query all points in a radius around the first 100 points
indices = kdtree.query_radius(data[:100], r=0.5, return_sorted=True)
The KDTree
can also be used from within numba functions
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[0], 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, data[:10000])
TODOs
- Implement all scipy
ckdtree
functions - Fix the parallel query functions
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
numba-kdtree-0.0.1.tar.gz
(22.5 kB
view hashes)
Built Distributions
Close
Hashes for numba_kdtree-0.0.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28baf4d595599355e5eaa30a8a915ac803d402db9db16bcaa8bf50da831f6cbd |
|
MD5 | d124d55e7f0b32e1a184e2b2074f28bc |
|
BLAKE2b-256 | 2eef5d0d09744b189cf72a68fc45e3737a2716ac6161563fc894d31f35a70459 |
Close
Hashes for numba_kdtree-0.0.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44d90ae46d2b7fbe2c5b424a20c5b92957152e64543d78e97616c4a039b4cd4d |
|
MD5 | 539c28c86d425fa4b30a9bd47407b702 |
|
BLAKE2b-256 | 4569ae7131f84e8df215bd57d8c9174d866d2f21cebed7eeecadd32518764ce0 |
Close
Hashes for numba_kdtree-0.0.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d5b94ce8fe8bad4ec3a6615a7047f16d2224da326827669ce5243a394d3e195 |
|
MD5 | 9ac627fafaee6181ab2ac5efd7b98366 |
|
BLAKE2b-256 | b241151e6cc47538f3368826e41d7a831a7a1fa96834ce475f0df8c8851bc23c |
Close
Hashes for numba_kdtree-0.0.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d354c1a0c7e475ffb12417484ec5ada2f7f4bdc40308ddbb840c03ee1688820d |
|
MD5 | 5e09c9502c6b5331793ced09ebb3d715 |
|
BLAKE2b-256 | bbb46a52e78ca6ea14055d5ec6b6df84cd54930b27f59d420da72a23729030b7 |