text
stringlengths
0
828
# does not contains the query.
stack_node = deque([root_id])
stack_look = deque()
while stack_node or stack_look:
if stack_node:
node_id = stack_node.pop()
look_node = False
else:
node_id = stack_look.pop()
look_node = True
point, region, axis, active, left, right = get_properties(node_id)
# Should consider this node?
# As it is within a region that does not contains the query, maybe
# there is no chance to find a closer node in this region
if look_node:
inside_region = True
for i in range(k):
inside_region &= interval_condition(query[i], region[i][0],
region[i][1], dist)
if not inside_region:
continue
# Update the distance only if the node is active.
if active:
node_distance = dist_fun(query, point)
if nearest_node_id is None or dist > node_distance:
nearest_node_id = node_id
dist = node_distance
if query[axis] < point[axis]:
side_node = left
side_look = right
else:
side_node = right
side_look = left
if side_node is not None:
stack_node.append(side_node)
if side_look is not None:
stack_look.append(side_look)
return nearest_node_id, dist"
4592,"def deactivate(self, node_id):
""""""Deactivate the node identified by node_id.
Deactivates the node corresponding to node_id, which means that
it can never be the output of a nearest_point query.
Note:
The node is not removed from the tree, its data is steel available.
Args:
node_id (int): The node identifier (given to the user after
its insertion).
""""""
node = self.node_list[node_id]
self.node_list[node_id] = node._replace(active=False)"
4593,"def insert(self, point, data=None):
""""""Insert a new node in the tree.
Args:
point (:obj:`tuple` of float or int): Stores the position of the
node.
data (:obj, optional): The information stored by the node.
Returns:
int: The identifier of the new node.
Example:
>>> tree = Tree(4, 800)
>>> point = (3, 7)
>>> data = {'name': Fresnel, 'label': blue, 'speed': 98.2}
>>> node_id = tree.insert(point, data)
""""""
assert len(point) == self.k
if self.size == 0:
if self.region is None:
self.region = [[-math.inf, math.inf]] * self.k
axis = 0
return self.new_node(point, self.region, axis, data)
# Iteratively descends to one leaf
current_id = 0
while True:
parent_node = self.node_list[current_id]
axis = parent_node.axis
if point[axis] < parent_node.point[axis]:
next_id, left = parent_node.left, True
else:
next_id, left = parent_node.right, False
if next_id is None: