def within(self, x, ctrs, kdtree=None):
"""Checks which cubes `x` falls within. Uses a K-D Tree to
accelerate the search if provided."""
if kdtree is None:
# If no KDTree is provided, execute a brute-force search
# over all cubes.
nctrs = len(ctrs)
within = np.array([max(abs(ctrs[i] - x)) <= self.hside
for i in range(nctrs)], dtype='bool')
idxs = np.arange(nctrs)[within]
else:
# If a KDTree is provided, find all points within r (`hside`).
idxs = kdtree.query_ball_point(x, self.hside, p=np.inf, eps=0)
return idxs
评论列表
文章目录