@@ -258,21 +258,23 @@ cdef class BoruvkaAlgorithm (object):
258258 cdef np.int64_t component1
259259 cdef np.int64_t component2
260260
261- cdef np.int64_t leaf_size = node1_info.idx_end - node1_info.idx_start
261+ cdef np.int64_t leaf_size = max (node1_info.idx_end - node1_info.idx_start,
262+ node2_info.idx_end - node2_info.idx_start)
262263
263264 node_dist = min_dist_dual(node1_info.radius, node2_info.radius,
264265 node1, node2, (< np.double_t [:num_nodes, :num_nodes:1 ]>
265266 (< np.double_t * > self ._centroid_distances.data)))
266267
267- if node_dist < self .bounds[node1]:
268- if self .component_of_node[node1] == self .component_of_node[node2] and \
269- self .component_of_node[node1] >= 0 :
270- return 0
271- else :
272- return 0
273-
268+ # Case 1: Query point is outside the bound or query point is
269+ # in the same component as reference points.
270+ # In either case, trim this line on inquiry.
271+ if node_dist > self .bounds[node1] or (self .component_of_node[node1] == self .component_of_node[node2]
272+ and self .component_of_node[node1] >= 0 ):
273+ pass
274274
275- if node1_info.is_leaf and node2_info.is_leaf:
275+ # Case 2: Both nodes are leaves; do the all to all computations
276+ # to find the nearest neighbour among them.
277+ elif node1_info.is_leaf and node2_info.is_leaf:
276278
277279 point_indices1 = idx_array[node1_info.idx_start:node1_info.idx_end]
278280 point_indices2 = idx_array[node2_info.idx_start:node2_info.idx_end]
@@ -296,10 +298,12 @@ cdef class BoruvkaAlgorithm (object):
296298 self .candidate_neighbor[component1] = q
297299 self .candidate_point[component1] = p
298300
301+ # Case 3a: Node1 is a leaf or smaller than Node2; descend Node2 and continue
299302 elif node1_info.is_leaf or (not node2_info.is_leaf
300303 and node2_info.radius > node1_info.radius):
301304 self .dual_tree_traversal(node1, 2 * node2 + 1 )
302305 self .dual_tree_traversal(node1, 2 * node2 + 2 )
306+ # Case 3b: Node2 is a leaf or smaller than Node1; descend Node1 and continue
303307 else :
304308 self .dual_tree_traversal(2 * node1 + 1 , node2)
305309 self .dual_tree_traversal(2 * node1 + 2 , node2)
0 commit comments