Skip to content

Commit

Permalink
Modify find_closest_points()
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeqfu committed Jan 31, 2023
1 parent c268c3e commit 117d5c3
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pyhelpers/geom.py
Expand Up @@ -3,6 +3,7 @@
import collections.abc
import copy
import functools
import os
import typing

import numpy as np
Expand Down Expand Up @@ -846,7 +847,8 @@ def find_closest_points(pts, ref_pts, k=1, unique=False, as_geom=False, ret_idx=
pts_, ref_pts_ = map(functools.partial(get_coordinates_as_array, unique=unique), [pts, ref_pts])

ref_ckd_tree = ckdtree.cKDTree(ref_pts_, **kwargs)
distances, indices = ref_ckd_tree.query(x=pts_, k=k) # returns (distance, index)
n_workers = os.cpu_count() - 1
distances, indices = ref_ckd_tree.query(x=pts_, k=k, workers=n_workers) # returns (distance, index)

closest_points_ = [ref_pts_[i] for i in indices]
if as_geom:
Expand Down

0 comments on commit 117d5c3

Please sign in to comment.