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.0.1.tar.gz (22.5 kB view details)

Uploaded Source

Built Distributions

numba_kdtree-0.0.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (513.0 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

numba_kdtree-0.0.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (512.0 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

numba_kdtree-0.0.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (514.9 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

numba_kdtree-0.0.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (512.7 kB view details)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

File details

Details for the file numba-kdtree-0.0.1.tar.gz.

File metadata

  • Download URL: numba-kdtree-0.0.1.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for numba-kdtree-0.0.1.tar.gz
Algorithm Hash digest
SHA256 b6395d495781b22a02a07fa476dc1fd35f510775b868287b6655ce22a1a74451
MD5 60c363d8be0ce4fe29c0ad7707222d50
BLAKE2b-256 97f2e768808bbc74b447628d026aa466e63dc52029a073971b5046f8acc09660

See more details on using hashes here.

File details

Details for the file numba_kdtree-0.0.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

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

See more details on using hashes here.

File details

Details for the file numba_kdtree-0.0.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

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

See more details on using hashes here.

File details

Details for the file numba_kdtree-0.0.1-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

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

See more details on using hashes here.

File details

Details for the file numba_kdtree-0.0.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

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

See more details on using hashes here.

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