Skip to main content

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


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.4.0.tar.gz (30.7 kB view hashes)

Uploaded Source

Built Distributions

numba_kdtree-0.4.0-cp311-cp311-win_amd64.whl (45.6 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

numba_kdtree-0.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (480.6 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

numba_kdtree-0.4.0-cp310-cp310-win_amd64.whl (45.6 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

numba_kdtree-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (480.6 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

numba_kdtree-0.4.0-cp39-cp39-win_amd64.whl (45.6 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

numba_kdtree-0.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (480.6 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

numba_kdtree-0.4.0-cp38-cp38-win_amd64.whl (45.6 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

numba_kdtree-0.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (480.6 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

numba_kdtree-0.4.0-cp37-cp37m-win_amd64.whl (45.5 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

numba_kdtree-0.4.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (480.5 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page