generated from cubao/pybind11-rdp
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add nanaflann KdTree, use identical interface to `scipy.spatial.cKDTr…
…ee` (#8) * benchmark N points * sync code * add nanokdtree * nanokdtree * kdtree * not ready * kdtree works * update * update * bind search * test kdtree * integrated python part * not ready * not ready * same interface * fix# * fix * ready to release * rename to nanoflann kdtree * update headers * add scipy
- Loading branch information
1 parent
ae04f23
commit 27080f0
Showing
15 changed files
with
505 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from _pybind11_fast_crossing import * # noqa | ||
from _pybind11_fast_crossing import __version__ # noqa |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import numpy as np | ||
from _pybind11_fast_crossing import KdTree as _KdTree | ||
|
||
|
||
class KDTree: | ||
def __init__(self, data: np.ndarray, leafsize: int = 10, *args, **kwargs): | ||
data = np.asarray(data, dtype=np.float64) | ||
self.tree: _KdTree = _KdTree(data) | ||
self.tree.set_leafsize(leafsize) | ||
|
||
@staticmethod | ||
def vec3(arr: np.ndarray): | ||
return np.r_[arr, 0.0] if len(arr) == 2 else np.asarray(arr, dtype=np.float64) | ||
|
||
def count_neighbors(self, *args, **kwargs): | ||
raise NotImplementedError | ||
|
||
def query(self, x, k=1, *args, **kwargs): | ||
x = np.asarray(x, dtype=np.float64) | ||
if x.ndim == 1: | ||
xyz = self.vec3(x) | ||
ii, dd = self.tree.nearest(xyz, k=k) | ||
return dd, ii | ||
if isinstance(k, (int, np.integer)): | ||
ret_ii, ret_dd = [], [] | ||
for xyz in x: | ||
xyz = self.vec3(xyz) | ||
if k == 1: | ||
ii, dd = self.tree.nearest(xyz) | ||
else: | ||
ii, dd = self.tree.nearest(xyz, k=k) | ||
ii = ii.tolist() | ||
dd = dd.tolist() | ||
ret_ii.append(ii) | ||
ret_dd.append(dd) | ||
return ret_dd, ret_ii | ||
K = max(k) | ||
ret_ii, ret_dd = [], [] | ||
for xyz in x: | ||
xyz = self.vec3(xyz) | ||
ii, dd = self.tree.nearest(xyz, k=K) | ||
ii = [ii[kk - 1] for kk in k] | ||
dd = [dd[kk - 1] for kk in k] | ||
ret_ii.append(ii) | ||
ret_dd.append(dd) | ||
return ret_dd, ret_ii | ||
|
||
def query_ball_point( | ||
self, | ||
x, | ||
r, | ||
p=2.0, | ||
eps=0, | ||
workers=1, | ||
return_sorted=None, | ||
return_length=False, | ||
*args, | ||
**kwargs, | ||
): | ||
""" | ||
https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.cKDTree.query_ball_point.html#scipy.spatial.cKDTree.query_ball_point | ||
""" | ||
x = np.asarray(x, dtype=np.float64) | ||
if return_sorted is None: | ||
# If None, does not sort single point queries, but does sort | ||
# multi-point queries which was the behavior before this option was | ||
# added. | ||
return_sorted = x.ndim != 1 | ||
if x.ndim == 1: | ||
xyz = self.vec3(x) | ||
ii, dd = self.tree.nearest( | ||
xyz, | ||
radius=r, | ||
return_squared_l2=True, | ||
sorted=return_sorted, | ||
) | ||
if return_length: | ||
return len(ii) | ||
return ii.tolist() | ||
if return_sorted is None: | ||
return_sorted = True | ||
if isinstance(r, (int, float, np.number)): | ||
r = [r] * len(x) | ||
ret_ii = [] | ||
for pp, rr in zip(x, r): # noqa | ||
xyz = self.vec3(pp) | ||
ii, dd = self.tree.nearest( | ||
xyz, | ||
radius=rr, | ||
return_squared_l2=True, | ||
sorted=return_sorted, | ||
) | ||
ret_ii.append(ii.tolist()) | ||
if return_length: | ||
ret_ii = [len(ii) for ii in ret_ii] | ||
return ret_ii | ||
|
||
def query_ball_tree(self, *args, **kwargs): | ||
raise NotImplementedError | ||
|
||
def query_pairs(self, *args, **kwargs): | ||
raise NotImplementedError | ||
|
||
def query_distance_matrix(self, *args, **kwargs): | ||
raise NotImplementedError | ||
|
||
|
||
# create alias | ||
cKDTree = KDTree |
Submodule headers
updated
17 files
+2 −0 | include/README.md | |
+44 −0 | include/cubao/densify_polyline.hpp | |
+226 −0 | include/cubao/point_in_polygon.hpp | |
+15 −0 | include/cubao/polyline_ruler.hpp | |
+12 −0 | include/cubao/pybind11_polyline_ruler.hpp | |
+20 −10 | include/mapbox/geojson_impl.hpp | |
+262 −0 | include/mapbox/geojsonvt.hpp | |
+321 −0 | include/mapbox/geojsonvt/clip.hpp | |
+120 −0 | include/mapbox/geojsonvt/convert.hpp | |
+84 −0 | include/mapbox/geojsonvt/simplify.hpp | |
+209 −0 | include/mapbox/geojsonvt/tile.hpp | |
+195 −0 | include/mapbox/geojsonvt/types.hpp | |
+46 −0 | include/mapbox/geojsonvt/wrap.hpp | |
+2,466 −0 | include/tinycolormap.hpp | |
+12 −8 | include/utils.cmake | |
+22 −0 | include/version.h.dummy.in | |
+1 −0 | include/version.h.in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
import subprocess | ||
import sys | ||
|
||
from setuptools import Extension, setup | ||
from setuptools import Extension, find_packages, setup | ||
from setuptools.command.build_ext import build_ext | ||
|
||
# Convert distutils Windows platform specifiers to CMake -A arguments | ||
|
@@ -124,16 +124,17 @@ def build_extension(self, ext): | |
# logic and declaration, and simpler if you include description/version in a file. | ||
setup( | ||
name="fast_crossing", | ||
version="0.0.4", | ||
version="0.0.5", | ||
author="tzx", | ||
author_email="[email protected]", | ||
url="https://github.com/cubao/fast-crossing", | ||
url="https://fast-crossing.readthedocs.io", | ||
description="fast crossing", | ||
long_description=open("README.md", encoding="utf-8").read(), | ||
long_description_content_type="text/markdown", | ||
packages=find_packages(), | ||
ext_modules=[CMakeExtension("fast_crossing")], | ||
cmdclass={"build_ext": CMakeBuild}, | ||
zip_safe=False, | ||
install_requires=["numpy"], | ||
extras_require={"test": ["pytest>=6.0"]}, | ||
extras_require={"test": ["pytest>=6.0", "scipy"]}, | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.