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.0.tar.gz
(22.1 kB
view hashes)
Built Distributions
Close
Hashes for numba_kdtree-0.1.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5397313fd27156c10097499e222c37f687840c38f0e1eac88ee380e19d98dc7 |
|
MD5 | 832b8fde455d08e0ca1e94ba90e59368 |
|
BLAKE2b-256 | b60d3fb29268041c315de687d6cac0091ab6a9838c5d53c007084d4fc3a18cd9 |
Close
Hashes for numba_kdtree-0.1.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e810d2806eb12779f2efcf92c862a38a5c91b1585f605a6129a6022e4e97cc19 |
|
MD5 | 9ad5459e560a8819c32a99d07010c1a2 |
|
BLAKE2b-256 | 6286ff5638cdc77bce55a52a89e51893127a641a6a8ce16f1eb03666dc2d9e86 |
Close
Hashes for numba_kdtree-0.1.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9d2e439e3630b8daea1ac17b57aa00509475381f100164d8e25dc952bdc9496 |
|
MD5 | 5239d490ec764060411a85c364ef41ea |
|
BLAKE2b-256 | e8e8184fe0e77b403614f3b414ad584108a004634dbc74360ce852e82e7bbf67 |
Close
Hashes for numba_kdtree-0.1.0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97d79bd262d4aec67815d26a6ac83c64641827ecbfad68298c78db8594420940 |
|
MD5 | 4303bdd10b50ca8c5df5af69dcb85248 |
|
BLAKE2b-256 | 95e55fa2b1d1d38fd05a28cc6b836d6cfae0b23ae0d21d816cce7f0ed9ad498f |