kdtree.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:pytorch-nec 作者: mjacar 项目源码 文件源码
def search_nn_dist(self, point, distance, best=None):
        """
        Search the n nearest nodes of the given point which are within given
        distance
        point must be a location, not a node. A list containing the n nearest
        nodes to the point within the distance will be returned.
        """

        if best is None:
            best = []

        # consider the current node
        if self.dist(point) < distance:
            best.append(self)

        # sort the children, nearer one first (is this really necessairy?)
        children = sorted(self.children, key=lambda c_p1: c_p1[0].dist(point))

        for child, p in children:
            # check if child node needs to be recursed
            if self.axis_dist(point, self.axis) < math.pow(distance, 2):
                child.search_nn_dist(point, distance, best)

        return best
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号