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.2.tar.gz
(22.1 kB
view hashes)
Built Distributions
Close
Hashes for numba_kdtree-0.0.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c19353575669001125b30d6a833f3334f2cb5914454b326133c526a24b895af |
|
MD5 | 8e1e80dd1f3c6473e23d1451fd8de8a8 |
|
BLAKE2b-256 | 9ae424c7312af9c1b636b666aa59fea7a88c8af34033ba7e5375475351e4ae9d |
Close
Hashes for numba_kdtree-0.0.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d63fad59b5200a2b36b357cb701c744a58b460c34731024a814d6743184c82d8 |
|
MD5 | b357e4b5063b2cb58f367542832f552f |
|
BLAKE2b-256 | 1ce7e8f9b5071b6d016d88fe28a80cddfe4ad6f1f0cb87b42383d8c5a579c8c9 |
Close
Hashes for numba_kdtree-0.0.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b867c6f947c95825de4968ee622e4a91b6aeac5952df097c688f9b5867df5607 |
|
MD5 | ec13414bb1b200db7e367b6c0016d558 |
|
BLAKE2b-256 | 2f3556eff513bc1ac8e68293ffd4036c056466ca0b6d6c7b63d825a6c39f26b2 |
Close
Hashes for numba_kdtree-0.0.2-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0f9e8a7d8457d0c640fe2263ccd3bc468209488e49cb6c53bad82b450ab7007 |
|
MD5 | 731eedc10770053c2946613eecf3f4fa |
|
BLAKE2b-256 | b23dfe6ee85d5c9c6daf24f5dce2546844a089d2a6f03aa7ce98304cb64b9d0c |