Skip to content

Commit 10c3427

Browse files
committed
Fix bug in distances array casting.
1 parent 9b46a13 commit 10c3427

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

hdbscan/_hdbscan_boruvka.pyx

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -258,23 +258,19 @@ cdef class BoruvkaAlgorithm (object):
258258
cdef np.int64_t component1
259259
cdef np.int64_t component2
260260

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)
263-
264261
node_dist = min_dist_dual(node1_info.radius, node2_info.radius,
265262
node1, node2, (<np.double_t [:num_nodes, :num_nodes:1]>
266263
(<np.double_t *> self._centroid_distances.data)))
267264

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
265+
if node_dist < self.bounds[node1]:
266+
if self.component_of_node[node1] == self.component_of_node[node2] and \
267+
self.component_of_node[node1] >= 0:
268+
return 0
269+
else:
270+
return 0
271+
274272

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:
273+
if node1_info.is_leaf and node2_info.is_leaf:
278274

279275
point_indices1 = idx_array[node1_info.idx_start:node1_info.idx_end]
280276
point_indices2 = idx_array[node2_info.idx_start:node2_info.idx_end]
@@ -283,7 +279,7 @@ cdef class BoruvkaAlgorithm (object):
283279
points2 = self._data[point_indices2]
284280

285281
distances_arr = self.dist.pairwise(points1, points2)
286-
distances = (<np.double_t [:leaf_size, :leaf_size:1]> (<np.double_t *> distances_arr.data))
282+
distances = (<np.double_t [:points1.shape[0], :points2.shape[0]:1]> (<np.double_t *> distances_arr.data))
287283

288284
for i in range(point_indices1.shape[0]):
289285
for j in range(point_indices2.shape[0]):
@@ -298,12 +294,10 @@ cdef class BoruvkaAlgorithm (object):
298294
self.candidate_neighbor[component1] = q
299295
self.candidate_point[component1] = p
300296

301-
# Case 3a: Node1 is a leaf or smaller than Node2; descend Node2 and continue
302297
elif node1_info.is_leaf or (not node2_info.is_leaf
303298
and node2_info.radius > node1_info.radius):
304299
self.dual_tree_traversal(node1, 2 * node2 + 1)
305300
self.dual_tree_traversal(node1, 2 * node2 + 2)
306-
# Case 3b: Node2 is a leaf or smaller than Node1; descend Node1 and continue
307301
else:
308302
self.dual_tree_traversal(2 * node1 + 1, node2)
309303
self.dual_tree_traversal(2 * node1 + 2, node2)

0 commit comments

Comments
 (0)