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.1.5.tar.gz
(23.3 kB
view hashes)
Built Distributions
Close
Hashes for numba_kdtree-0.1.5-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c1e15e9e2629b2402f34e96eff2feb402f76510ffec769238ed0e3791b6beaa |
|
MD5 | d132d3f4c494812ac741fb21b7111686 |
|
BLAKE2b-256 | 842339ee3f7883bb85c856266bcfe4a9aa87dae8d157f9be2f0731b2ff245580 |
Close
Hashes for numba_kdtree-0.1.5-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bab7d4ae2fa284f16027771a7a5b7f37aff4303d731cd1734bbc1329040c4b34 |
|
MD5 | 69b5fe5f219217bf1c9b69059606d2ab |
|
BLAKE2b-256 | ef6e02f1ea720153eaffaf20d2105f762bf9240e9834c68c5140005fac6498b2 |
Close
Hashes for numba_kdtree-0.1.5-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a7257abc8c50e5179f5c420d94ecb95962d5a26b8b3ef9a51fb7509da419879 |
|
MD5 | e48cf8f3671e48a13eab2281df6df34b |
|
BLAKE2b-256 | 16bd68efc8f11bb556f79f2c02a084bc1e2a67e23f0ded63cc6eb973f7547ced |
Close
Hashes for numba_kdtree-0.1.5-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73003f4156b4f652de93ee237523c5a046bb029c813e782c4b405c5defa3c8f5 |
|
MD5 | 453dd552c3d634e776af1fdbd682ff41 |
|
BLAKE2b-256 | d2e8940441eb1525d210b37f771450236677ffcb945bd987d968ae426fceb725 |