Skip to content

Commit ad33b43

Browse files
committed
Fix bugs and fix up tests
1 parent 543bc23 commit ad33b43

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

fast_hdbscan/cluster_trees.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -474,14 +474,14 @@ def cluster_tree_from_condensed_tree(condensed_tree):
474474
condensed_tree.child_size[mask])
475475

476476

477-
#@numba.njit()
477+
@numba.njit()
478478
def unselect_below_node(node, cluster_tree, selected_clusters):
479479
for child in cluster_tree.child[cluster_tree.parent == node]:
480480
unselect_below_node(child, cluster_tree, selected_clusters)
481481
selected_clusters[child] = False
482482

483483

484-
#@numba.njit(fastmath=True)
484+
@numba.njit(fastmath=True)
485485
def eom_recursion(node, cluster_tree, node_scores, node_sizes, selected_clusters, max_cluster_size):
486486
current_score = node_scores[node]
487487
current_size = node_sizes[node]
@@ -500,11 +500,14 @@ def eom_recursion(node, cluster_tree, node_scores, node_sizes, selected_clusters
500500
return current_score
501501

502502

503-
#@numba.njit()
503+
@numba.njit()
504504
def extract_eom_clusters(condensed_tree, cluster_tree, max_cluster_size=np.inf, allow_single_cluster=False):
505505
node_scores = score_condensed_tree_nodes(condensed_tree)
506-
node_sizes = {node: size for node, size in zip(cluster_tree.child, cluster_tree.child_size.astype(np.float32))}
507-
node_sizes[cluster_tree.parent.min()] = np.float32(cluster_tree.parent.min() - 1)
506+
if len(cluster_tree.parent) > 0:
507+
node_sizes = {node: size for node, size in zip(cluster_tree.child, cluster_tree.child_size.astype(np.float32))}
508+
node_sizes[cluster_tree.parent.min()] = np.float32(cluster_tree.parent.min() - 1)
509+
else:
510+
node_sizes = {-1: np.float32(0.0)}
508511
selected_clusters = {node: False for node in node_scores}
509512

510513
if len(cluster_tree.parent) == 0:

fast_hdbscan/tests/test_hdbscan.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ def test_fhdbscan_allow_single_cluster_with_epsilon():
154154
cluster_selection_epsilon=0.0,
155155
).fit(no_structure)
156156
unique_labels, counts = np.unique(c.labels_, return_counts=True)
157-
assert len(unique_labels) == 8
158-
assert counts[unique_labels == -1] == 68
157+
assert len(unique_labels) == 9
158+
assert counts[unique_labels == -1] == 62
159159

160160
# An epsilon of 0.2 will produce 2 noise points and 2 labels
161161
# Allow single cluster does not prevent applying the epsilon threshold.

0 commit comments

Comments
 (0)